1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 20:38:08 +01:00

Fix non-ascii workspace rename via menu

As pointed out in the comments in

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=304480

it's not possible to rename workspaces with non-ascii characters -- more
precisely characters which require deadkeys with your particular keyboard.

According to the investigation made by Rodolfo Peñas:

http://lists.windowmaker.org/dev/msg02529.html

the fundamental issue behind this bug is the fact that XLookupString can't
handle deadkeys.

So either we do something radical or live with the bug.

However -- as Rodolfo also pointed out -- renaming the workspaces via the
Clip works with non-ascii chars. The reason is that the Clip uses a input dialog
function from WINGs to handle the renaming.

So instead of doing the low-level handling of text inside the menu in order
to rename workspaces, just fire up the same WINGs input dialog to handle it.
It works and the old function editEntry() can be removed.

Furthermore, it makes the whole set of functions in src/wtext.c useless, and
they are removed in the next patch.

Overall, 600 lines of code are gone now.

Signed-off-by: Carlos R. Mafra <crmafra@gmail.com>
This commit is contained in:
Carlos R. Mafra
2012-01-16 05:31:06 +00:00
parent 918d0b5af1
commit fd07e032df

View File

@@ -42,6 +42,7 @@
#include "text.h"
#include "xinerama.h"
#include "workspace.h"
#include "dialog.h"
/****** Global Variables ******/
@@ -1146,86 +1147,6 @@ void wMenuSetEnabled(WMenu * menu, int index, int enable)
paintEntry(menu->brother, index, index == menu->selected_entry);
}
/* ====================================================================== */
static void editEntry(WMenu * menu, WMenuEntry * entry)
{
WTextInput *text;
XEvent event;
WObjDescriptor *desc;
char *t;
int done = 0;
Window old_focus;
int old_revert;
menu->flags.editing = 1;
text = wTextCreate(menu->menu, 1, menu->entry_height * entry->order,
menu->menu->width - 2, menu->entry_height - 1);
wTextPutText(text, entry->text);
XGetInputFocus(dpy, &old_focus, &old_revert);
XSetInputFocus(dpy, text->core->window, RevertToNone, CurrentTime);
if (XGrabKeyboard(dpy, text->core->window, True, GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess) {
wwarning(_("could not grab keyboard"));
wTextDestroy(text);
wSetFocusTo(menu->frame->screen_ptr, menu->frame->screen_ptr->focused_window);
return;
}
while (!done && !text->done) {
XSync(dpy, 0);
XAllowEvents(dpy, AsyncKeyboard | AsyncPointer, CurrentTime);
XSync(dpy, 0);
WMNextEvent(dpy, &event);
if (XFindContext(dpy, event.xany.window, wWinContext, (XPointer *) & desc) == XCNOENT)
desc = NULL;
if ((desc != NULL) && (desc->handle_anything != NULL)) {
(*desc->handle_anything) (desc, &event);
} else {
switch (event.type) {
case ButtonPress:
XAllowEvents(dpy, ReplayPointer, CurrentTime);
done = 1;
default:
WMHandleEvent(&event);
break;
}
}
}
XSetInputFocus(dpy, old_focus, old_revert, CurrentTime);
wSetFocusTo(menu->frame->screen_ptr, menu->frame->screen_ptr->focused_window);
t = wTextGetText(text);
/* if !t, the user has canceled editing */
if (t) {
if (entry->text)
wfree(entry->text);
entry->text = wstrdup(t);
menu->flags.realized = 0;
}
wTextDestroy(text);
XUngrabKeyboard(dpy, CurrentTime);
if (t && menu->on_edit)
(*menu->on_edit) (menu, entry);
menu->flags.editing = 0;
if (!menu->flags.realized)
wMenuRealize(menu);
}
static void selectEntry(WMenu * menu, int entry_no)
{
@@ -1832,7 +1753,21 @@ static void menuMouseDown(WObjDescriptor * desc, XEvent * event)
entry = menu->entries[entry_no];
if (!close_on_exit && (bev->state & ControlMask) && smenu && entry->flags.editable) {
editEntry(smenu, entry);
char buffer[128];
char *name;
int number = entry_no - 2; /* Entries "New" and "Destroy Last" appear before workspaces */
name = wstrdup(scr->workspaces[number]->name);
snprintf(buffer, sizeof(buffer), _("Type the name for workspace %i:"), number + 1);
wMenuUnmap(scr->root_menu);
if (wInputDialog(scr, _("Rename Workspace"), buffer, &name))
wWorkspaceRename(scr, number, name);
if (name)
wfree(name);
goto byebye;
} else if (bev->state & ControlMask) {
goto byebye;