Re: Bug#304480: wmaker: Can't enter non english letters in dialog boxes

2012-01-17 Thread SJS
begin  quoting Rodolfo kix Garcia as of Mon, Jan 16, 2012 at 09:04:45AM +0100:
 On 16/01/12 08:31, Rodolfo kix Garcia wrote:
[chop]
  snprintf(buffer, DOCK_NAME_LEN -1, _(Type the name for workspace %i:), 
  wks_no + 1);
 
 buffer[DOCK_NAME_LEN -1] = '/0';
 
 Can help too.

Surely \0 is meant and not /0.

And stylistically, I assert that it's clearer to write

   buffer[DOCK_NAME_LEN - 1]

than

   buffer[DOCK_NAME_LEN -1]

...but that's just a pet peeve of mine, since I read -1 as being one less
than zero, so -1 might as well be 5, or x.  I can't be the only one who
does this...

-Stewart


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


Re: Bug#304480: wmaker: Can't enter non english letters in dialog boxes

2012-01-17 Thread Carlos R. Mafra
On Mon, 16 Jan 2012 at 17:48:41 +, SJS wrote:
 
 And stylistically, I assert that it's clearer to write
 
buffer[DOCK_NAME_LEN - 1]
 
 than
 
buffer[DOCK_NAME_LEN -1]
 
 ...but that's just a pet peeve of mine, since I read -1 as being one less
 than zero, so -1 might as well be 5, or x.  I can't be the only one who
 does this...

Definitely. BTW, wmaker-crm follows the linux kernel coding style:

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/CodingStyle;h=2b90d328b3ba5595c4f3a0e6bdc7c236346f550c;hb=HEAD

and for this case, see line 206.


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


Re: Bug#304480: wmaker: Can't enter non english letters in dialog boxes

2012-01-17 Thread Rodolfo kix Garcia
On 17/01/12 18:45, Carlos R. Mafra wrote:

 On Mon, 16 Jan 2012 at 17:48:41 +, SJS wrote:

 And stylistically, I assert that it's clearer to write

buffer[DOCK_NAME_LEN - 1]

 than

buffer[DOCK_NAME_LEN -1]

 ...but that's just a pet peeve of mine, since I read -1 as being one less
 than zero, so -1 might as well be 5, or x.  I can't be the only one who
 does this...
 
 Definitely. BTW, wmaker-crm follows the linux kernel coding style:
 
 http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/CodingStyle;h=2b90d328b3ba5595c4f3a0e6bdc7c236346f550c;hb=HEAD
 
 and for this case, see line 206.


Ok, ok, is wrong, but... who make patches, make mistakes :-)

If I remember, this code is not included in any place.

Thanks for the link Carlos.

Cheers.

PS. Today is not my day :-)
-- 
||// //\\// Rodolfo kix Garcia
||\\// //\\ http://www.kix.es/


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


Re: Bug#304480: wmaker: Can't enter non english letters in dialog boxes

2012-01-17 Thread Carlos R. Mafra
On Tue, 17 Jan 2012 at 19:01:52 +0100, Rodolfo kix Garcia wrote:
 
 Ok, ok, is wrong, but... who make patches, make mistakes :-)

Right, but that particular bit was clearly written directly in
the email and everyone can filter this kind of irrelevant lapse.
The important thing is to discuss.

Your remark made me go back to the code and review it to be
sure there was no buffer overflow. Please continue to do so.


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


Re: Bug#304480: wmaker: Can't enter non english letters in dialog boxes

2012-01-16 Thread Rodolfo kix Garcia
On 16/01/12 08:31, Rodolfo kix Garcia wrote:

 On 16/01/12 06:56, Carlos R. Mafra wrote:
 
 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?
 
 
 IMO the new code is better than the current code, and we remove low-level 
 code (X11 functions like XGrab,...) , therefore I like this change.
 

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

 But I might be missing something too. Comments?

 [snip]
 +char buffer[128];
 
 
 I don't like this things, I prefer char buffer[DOCK_NAME_LEN] and set 
 DOCK_NAME_LEN in dock.h Probably we should find if this length is used in 
 other places in the code.
 
 +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);
 
 
 probably this is wrong, Is too early and I wake up 5 seconds ago but probably 
 if the buffer length is 128 we have a buffer overflow. Correct:
 
 snprintf(buffer, sizeof(buffer) -1, _(Type the name for workspace %i:), 
 wks_no + 1);
 
 Or using the previous stuff:
 
 snprintf(buffer, DOCK_NAME_LEN -1, _(Type the name for workspace %i:), 
 wks_no + 1);

buffer[DOCK_NAME_LEN -1] = '/0';

Can help too.

 +
 +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;
 
 
 byebye: :-)
 
 Cheers,
 kix



-- 
||// //\\// Rodolfo kix Garcia
||\\// //\\ http://www.kix.es/


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


Re: Bug#304480: wmaker: Can't enter non english letters in dialog boxes

2012-01-16 Thread Rodolfo kix Garcia

On Mon, 16 Jan 2012 12:51:50 +, Carlos R. Mafra wrote:

On Mon, 16 Jan 2012 at  8:31:33 +0100, Rodolfo kix Garcia wrote:


[snip]
 +  char buffer[128];


I don't like this things, I prefer char buffer[DOCK_NAME_LEN] and 
set
DOCK_NAME_LEN in dock.h Probably we should find if this length is 
used

in other places in the code.

 +  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);



probably this is wrong, Is too early and I wake up 5 seconds ago but
probably if the buffer length is 128 we have a buffer overflow.
Correct:


No, there's no possible buffer overflow there. The user can't modify
'buffer' because it holds the fixed string Type the name for 
workspace X

where X is a (small) number.



 +
 +  if (wInputDialog(scr, _(Rename Workspace), buffer, 
name))
 +  wWorkspaceRename(scr, wks_no, name);


'name' is the user input, but checking it properly should be done 
inside

wWorkspaceRename(), and it probably is (I haven't looked).


Yes, I see. Then, I am agree with the patch.

Cheers.

PS. I will try to take the coffee first, then email.

--
||// //\\// Rodolfo kix Garcia
||\\// //\\ http://www.kix.es/


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


Re: Bug#304480: wmaker: Can't enter non english letters in dialog boxes

2012-01-15 Thread Carlos R. Mafra
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 -