On Tue, 10 Jan 2012 at  0:34:53 +0100, Rodolfo kix Garcia wrote:
> 
> Why we can change the name using right click on the Clip. Why? because
> the clip is using the functions of WINGs. Can we change the menu
> functions to WINGs?... probably yes, but I don't know. Probably the full
> code of menu should be re-written.
>
> Can somebody put more light here? Ideas?

I've just finished a dirty hack to deal with this using WINGs.

I mimicked what happens when you use the Clip, so when you left-click
the menu entry holding the Ctrl key, the same input dialog appears
asking for the new name. Surprisingly, the overall patch removes 
~60 lines of code (because you can get rid of editEntry).

Right now the dialog appears under the menu (because both appear 
in the middle of the screen). Perhaps it will not be difficult to
make the dialog appear shifted to the right or left, but I haven't
looked at that now. I just wanted a proof of concept.

What do people think about changing this behavior? Instead of
editing the menu entry directly and facing the deadkey limitations of
XLookupString() like Rodolfo pointed out or getting an input dialog 
like a rename via the Clip? 

I tend to choose the one that works in all cäsés.

But I might be missing something too. Comments?

---
 src/menu.c |   97 ++++++++++--------------------------------------------------
 1 files changed, 16 insertions(+), 81 deletions(-)

diff --git a/src/menu.c b/src/menu.c
index 11e6a7f..dca8347 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -32,6 +32,8 @@
 #include <unistd.h>
 #include <ctype.h>
 
+
+#include "dock.h"
 #include "WindowMaker.h"
 #include "wcore.h"
 #include "framewin.h"
@@ -42,6 +44,7 @@
 #include "text.h"
 #include "xinerama.h"
 #include "workspace.h"
+#include "dialog.h"
 
 /****** Global Variables ******/
 
@@ -1146,86 +1149,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 +1755,19 @@ 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 wks_no = entry_no - 2;
+
+                       name = wstrdup(scr->workspaces[wks_no]->name);
+                       snprintf(buffer, sizeof(buffer), _("Type the name for 
workspace %i:"), wks_no + 1);
+
+                       if (wInputDialog(scr, _("Rename Workspace"), buffer, 
&name))
+                               wWorkspaceRename(scr, wks_no, name);
+
+                       if (name)
+                               wfree(name);
+
                        goto byebye;
                } else if (bev->state & ControlMask) {
                        goto byebye;
-- 
1.7.3.4


-- 
To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.

Reply via email to