On 19/01/12 01:48, Carlos R. Mafra wrote: > On Thu, 19 Jan 2012 at 0:46:26 +0100, Rodolfo kix Garcia wrote: >> > > [...] > > I skipped your (a bit confusing) motivation. > >> Subject: [PATCH 1/2] WPrefs.app: Removing duplicated code >> Subject: [PATCH 2/2] WINGs: Removed proplist-compat.h >> >> Comments are welcome. I hope the patches could be applied :-? > > The second patch is fine, the first is wrong (as you already noticed). > > There is something good in the first patch, which is the removal > of the duplication on captureShortcut(). If you make a patch > doing only that part, it's ok. And while at it, rename it to > capture_shortcut(). > > [ BTW, the only reason there is a space after * in the functions > arguments, > > char *captureShortcut(Display * dpy, _Panel * panel, int convertCase) > > is that I screwed up when using 'indent' some years ago. Whenever > someone touches a line like that feel free to take the opportunity > to turn it into: > > char *captureShortcut(Display *dpy, _Panel *panel, int convertCase) ]
[snip] > >From 7a03b45993d8127de8de6c3b108dee05d85c7588 Mon Sep 17 00:00:00 2001 From: Rodolfo García Peñas (kix) <[email protected]> Date: Tue, 17 Jan 2012 21:43:58 +0100 Subject: [PATCH] WPrefs: Removed duplicated function captureShortcut The function captureShortcut is used in the files KeyboardShortcuts.c and Menu.c, but the function is implemented in both files. The only difference is that the funcion in KeyboardShortcuts.c is used with a upCase function. To solve the problem, then the new function includes a new paramenter (like boolean) to run the upCase function or not. --- WPrefs.app/KeyboardShortcuts.c | 7 +++-- WPrefs.app/Menu.c | 56 ++------------------------------------- 2 files changed, 7 insertions(+), 56 deletions(-) diff --git a/WPrefs.app/KeyboardShortcuts.c b/WPrefs.app/KeyboardShortcuts.c index 1d70854..ad8a039 100644 --- a/WPrefs.app/KeyboardShortcuts.c +++ b/WPrefs.app/KeyboardShortcuts.c @@ -230,7 +230,7 @@ static void XConvertCase(register KeySym sym, KeySym * lower, KeySym * upper) } #endif -static char *captureShortcut(Display * dpy, _Panel * panel) +char *capture_shortcut(Display *dpy, _Panel *panel, int convertCase) { XEvent ev; KeySym ksym, lksym, uksym; @@ -243,7 +243,8 @@ static char *captureShortcut(Display * dpy, _Panel * panel) if (ev.type == KeyPress && ev.xkey.keycode != 0) { ksym = XKeycodeToKeysym(dpy, ev.xkey.keycode, 0); if (!IsModifierKey(ksym)) { - XConvertCase(ksym, &lksym, &uksym); + if (convertCase) + XConvertCase(ksym, &lksym, &uksym); key = XKeysymToString(uksym); panel->capturing = 0; @@ -296,7 +297,7 @@ static void captureClick(WMWidget * w, void *data) WMSetLabelText(panel->instructionsL, _("Press the desired shortcut key(s) or click Cancel to stop capturing.")); XGrabKeyboard(dpy, WMWidgetXID(panel->parent), True, GrabModeAsync, GrabModeAsync, CurrentTime); - shortcut = captureShortcut(dpy, panel); + shortcut = capture_shortcut(dpy, panel, 1); if (shortcut) { int row = WMGetListSelectedItemRow(panel->actLs); diff --git a/WPrefs.app/Menu.c b/WPrefs.app/Menu.c index 21a9fe1..5617c24 100644 --- a/WPrefs.app/Menu.c +++ b/WPrefs.app/Menu.c @@ -176,6 +176,8 @@ static Bool shouldRemoveItem(struct WEditMenuDelegate *delegate, WEditMenu * men static void freeItemData(ItemData * data); +extern char *capture_shortcut(Display *dpy, _Panel *panel, int convertCase); /* No static now! */ + static WEditMenuDelegate menuDelegate = { NULL, menuItemCloned, @@ -254,58 +256,6 @@ static void browseForFile(WMWidget * self, void *clientData) wfree(oldprog); } -static char *captureShortcut(Display * dpy, _Panel * panel) -{ - XEvent ev; - KeySym ksym; - char buffer[64]; - char *key = NULL; - - while (panel->capturing) { - XAllowEvents(dpy, AsyncKeyboard, CurrentTime); - WMNextEvent(dpy, &ev); - if (ev.type == KeyPress && ev.xkey.keycode != 0) { - ksym = XKeycodeToKeysym(dpy, ev.xkey.keycode, 0); - if (!IsModifierKey(ksym)) { - key = XKeysymToString(ksym); - panel->capturing = 0; - break; - } - } - WMHandleEvent(&ev); - } - - if (!key) - return NULL; - - buffer[0] = 0; - - if (ev.xkey.state & ControlMask) { - strcat(buffer, "Control+"); - } - if (ev.xkey.state & ShiftMask) { - strcat(buffer, "Shift+"); - } - if (ev.xkey.state & Mod1Mask) { - strcat(buffer, "Mod1+"); - } - if (ev.xkey.state & Mod2Mask) { - strcat(buffer, "Mod2+"); - } - if (ev.xkey.state & Mod3Mask) { - strcat(buffer, "Mod3+"); - } - if (ev.xkey.state & Mod4Mask) { - strcat(buffer, "Mod4+"); - } - if (ev.xkey.state & Mod5Mask) { - strcat(buffer, "Mod5+"); - } - strcat(buffer, key); - - return wstrdup(buffer); -} - static void sgrabClicked(WMWidget * w, void *data) { _Panel *panel = (_Panel *) data; @@ -322,7 +272,7 @@ static void sgrabClicked(WMWidget * w, void *data) panel->capturing = 1; WMSetButtonText(w, _("Cancel")); XGrabKeyboard(dpy, WMWidgetXID(panel->parent), True, GrabModeAsync, GrabModeAsync, CurrentTime); - shortcut = captureShortcut(dpy, panel); + shortcut = capture_shortcut(dpy, panel, 0); if (shortcut) { WMSetTextFieldText(panel->shortT, shortcut); updateMenuItem(panel, panel->currentItem, panel->shortT); -- 1.7.2.3
>From 7a03b45993d8127de8de6c3b108dee05d85c7588 Mon Sep 17 00:00:00 2001 From: Rodolfo GarcÃa Peñas (kix) <[email protected]> Date: Tue, 17 Jan 2012 21:43:58 +0100 Subject: [PATCH] WPrefs: Removed duplicated function captureShortcut The function captureShortcut is used in the files KeyboardShortcuts.c and Menu.c, but the function is implemented in both files. The only difference is that the funcion in KeyboardShortcuts.c is used with a upCase function. To solve the problem, then the new function includes a new paramenter (like boolean) to run the upCase function or not. --- WPrefs.app/KeyboardShortcuts.c | 7 +++-- WPrefs.app/Menu.c | 56 ++------------------------------------- 2 files changed, 7 insertions(+), 56 deletions(-) diff --git a/WPrefs.app/KeyboardShortcuts.c b/WPrefs.app/KeyboardShortcuts.c index 1d70854..ad8a039 100644 --- a/WPrefs.app/KeyboardShortcuts.c +++ b/WPrefs.app/KeyboardShortcuts.c @@ -230,7 +230,7 @@ static void XConvertCase(register KeySym sym, KeySym * lower, KeySym * upper) } #endif -static char *captureShortcut(Display * dpy, _Panel * panel) +char *capture_shortcut(Display *dpy, _Panel *panel, int convertCase) { XEvent ev; KeySym ksym, lksym, uksym; @@ -243,7 +243,8 @@ static char *captureShortcut(Display * dpy, _Panel * panel) if (ev.type == KeyPress && ev.xkey.keycode != 0) { ksym = XKeycodeToKeysym(dpy, ev.xkey.keycode, 0); if (!IsModifierKey(ksym)) { - XConvertCase(ksym, &lksym, &uksym); + if (convertCase) + XConvertCase(ksym, &lksym, &uksym); key = XKeysymToString(uksym); panel->capturing = 0; @@ -296,7 +297,7 @@ static void captureClick(WMWidget * w, void *data) WMSetLabelText(panel->instructionsL, _("Press the desired shortcut key(s) or click Cancel to stop capturing.")); XGrabKeyboard(dpy, WMWidgetXID(panel->parent), True, GrabModeAsync, GrabModeAsync, CurrentTime); - shortcut = captureShortcut(dpy, panel); + shortcut = capture_shortcut(dpy, panel, 1); if (shortcut) { int row = WMGetListSelectedItemRow(panel->actLs); diff --git a/WPrefs.app/Menu.c b/WPrefs.app/Menu.c index 21a9fe1..5617c24 100644 --- a/WPrefs.app/Menu.c +++ b/WPrefs.app/Menu.c @@ -176,6 +176,8 @@ static Bool shouldRemoveItem(struct WEditMenuDelegate *delegate, WEditMenu * men static void freeItemData(ItemData * data); +extern char *capture_shortcut(Display *dpy, _Panel *panel, int convertCase); /* No static now! */ + static WEditMenuDelegate menuDelegate = { NULL, menuItemCloned, @@ -254,58 +256,6 @@ static void browseForFile(WMWidget * self, void *clientData) wfree(oldprog); } -static char *captureShortcut(Display * dpy, _Panel * panel) -{ - XEvent ev; - KeySym ksym; - char buffer[64]; - char *key = NULL; - - while (panel->capturing) { - XAllowEvents(dpy, AsyncKeyboard, CurrentTime); - WMNextEvent(dpy, &ev); - if (ev.type == KeyPress && ev.xkey.keycode != 0) { - ksym = XKeycodeToKeysym(dpy, ev.xkey.keycode, 0); - if (!IsModifierKey(ksym)) { - key = XKeysymToString(ksym); - panel->capturing = 0; - break; - } - } - WMHandleEvent(&ev); - } - - if (!key) - return NULL; - - buffer[0] = 0; - - if (ev.xkey.state & ControlMask) { - strcat(buffer, "Control+"); - } - if (ev.xkey.state & ShiftMask) { - strcat(buffer, "Shift+"); - } - if (ev.xkey.state & Mod1Mask) { - strcat(buffer, "Mod1+"); - } - if (ev.xkey.state & Mod2Mask) { - strcat(buffer, "Mod2+"); - } - if (ev.xkey.state & Mod3Mask) { - strcat(buffer, "Mod3+"); - } - if (ev.xkey.state & Mod4Mask) { - strcat(buffer, "Mod4+"); - } - if (ev.xkey.state & Mod5Mask) { - strcat(buffer, "Mod5+"); - } - strcat(buffer, key); - - return wstrdup(buffer); -} - static void sgrabClicked(WMWidget * w, void *data) { _Panel *panel = (_Panel *) data; @@ -322,7 +272,7 @@ static void sgrabClicked(WMWidget * w, void *data) panel->capturing = 1; WMSetButtonText(w, _("Cancel")); XGrabKeyboard(dpy, WMWidgetXID(panel->parent), True, GrabModeAsync, GrabModeAsync, CurrentTime); - shortcut = captureShortcut(dpy, panel); + shortcut = capture_shortcut(dpy, panel, 0); if (shortcut) { WMSetTextFieldText(panel->shortT, shortcut); updateMenuItem(panel, panel->currentItem, panel->shortT); -- 1.7.2.3
