From 066af13b5c33aeb96b832d90177394b0bc425c9a Mon Sep 17 00:00:00 2001 From: "Carlos R. Mafra" Date: Wed, 19 Aug 2009 22:03:43 +0200 Subject: [PATCH] Clean up case switching in handleKeyPress() GCC has an extension to deal with ranges within case statements. Let's use it to make the code more readable and ~5% smaller, [mafra@Pilar:wmaker.git]$ size src/event.o.* text data bss dec hex filename 13087 0 1056 14143 373f src/event.o.new 13711 0 1056 14767 39af src/event.o.old --- src/event.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/event.c b/src/event.c index ff092fc0..3afe07a9 100644 --- a/src/event.c +++ b/src/event.c @@ -1430,9 +1430,9 @@ handleKeyPress(XEvent *event) { WScreen *scr = wScreenForRootWindow(event->xkey.root); WWindow *wwin = scr->focused_window; - int i; + short i, widx; int modifiers; - int command=-1, widx; + int command = -1; #ifdef KEEP_XKB_LOCK_STATUS XkbStateRec staterec; #endif /*KEEP_XKB_LOCK_STATUS*/ @@ -1634,30 +1634,13 @@ handleKeyPress(XEvent *event) StartWindozeCycle(wwin, event, False); break; -#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) -#define GOTOWORKS(wk) case WKBD_WORKSPACE##wk:\ - i = (scr->current_workspace/10)*10 + wk - 1;\ - if (wPreferences.ws_advance || iworkspace_count)\ - wWorkspaceChange(scr, i);\ - break -#else -#define GOTOWORKS(wk) case WKBD_WORKSPACE/**/wk:\ - i = (scr->current_workspace/10)*10 + wk - 1;\ - if (wPreferences.ws_advance || iworkspace_count)\ - wWorkspaceChange(scr, i);\ - break -#endif - GOTOWORKS(1); - GOTOWORKS(2); - GOTOWORKS(3); - GOTOWORKS(4); - GOTOWORKS(5); - GOTOWORKS(6); - GOTOWORKS(7); - GOTOWORKS(8); - GOTOWORKS(9); - GOTOWORKS(10); -#undef GOTOWORKS + case WKBD_WORKSPACE1 ... WKBD_WORKSPACE10: + widx = command - WKBD_WORKSPACE1; + i = (scr->current_workspace / 10) * 10 + widx; + if (wPreferences.ws_advance || i < scr->workspace_count) + wWorkspaceChange(scr, i); + break; + case WKBD_NEXTWORKSPACE: wWorkspaceRelativeChange(scr, 1); break;