Left Half / Right Half Maximize
[wmaker-crm.git] / WPrefs.app / KeyboardShortcuts.c
1 /* KeyboardShortcuts.c- keyboard shortcut bindings
2  *
3  *  WPrefs - Window Maker Preferences Program
4  *
5  *  Copyright (c) 1998-2003 Alfredo K. Kojima
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20  *  USA.
21  */
22
23 #include "config.h"             /* for HAVE_XCONVERTCASE */
24
25 #include "WPrefs.h"
26 #include <ctype.h>
27
28 #include <X11/keysym.h>
29
30 typedef struct _Panel {
31         WMBox *box;
32
33         char *sectionName;
34
35         char *description;
36
37         CallbackRec callbacks;
38
39         WMWidget *parent;
40
41         WMLabel *actL;
42         WMList *actLs;
43
44         WMFrame *shoF;
45         WMTextField *shoT;
46         WMButton *cleB;
47         WMButton *defB;
48
49         WMLabel *instructionsL;
50
51         WMColor *white;
52         WMColor *black;
53         WMColor *gray;
54         WMFont *font;
55
56          /**/ char capturing;
57         char **shortcuts;
58         int actionCount;
59 } _Panel;
60
61 #define ICON_FILE       "keyshortcuts"
62
63 /* must be in the same order as the corresponding items in actions list */
64 static char *keyOptions[] = {
65         "RootMenuKey",
66         "WindowListKey",
67         "WindowMenuKey",
68         "HideKey",
69         "HideOthersKey",
70         "MiniaturizeKey",
71         "CloseKey",
72         "MaximizeKey",
73         "VMaximizeKey",
74         "HMaximizeKey",
75         "LHMaximizeKey",
76         "RHMaximizeKey",
77         "RaiseKey",
78         "LowerKey",
79         "RaiseLowerKey",
80         "ShadeKey",
81         "MoveResizeKey",
82         "SelectKey",
83         "FocusNextKey",
84         "FocusPrevKey",
85         "NextWorkspaceKey",
86         "PrevWorkspaceKey",
87         "NextWorkspaceLayerKey",
88         "PrevWorkspaceLayerKey",
89         "Workspace1Key",
90         "Workspace2Key",
91         "Workspace3Key",
92         "Workspace4Key",
93         "Workspace5Key",
94         "Workspace6Key",
95         "Workspace7Key",
96         "Workspace8Key",
97         "Workspace9Key",
98         "Workspace10Key",
99         "WindowShortcut1Key",
100         "WindowShortcut2Key",
101         "WindowShortcut3Key",
102         "WindowShortcut4Key",
103         "WindowShortcut5Key",
104         "WindowShortcut6Key",
105         "WindowShortcut7Key",
106         "WindowShortcut8Key",
107         "WindowShortcut9Key",
108         "WindowShortcut10Key",
109         "ScreenSwitchKey",
110 #ifdef VIRTUAL_DESKTOP
111         "VirtualEdgeLeftKey",
112         "VirtualEdgeRightKey",
113         "VirtualEdgeUpKey",
114         "VirtualEdgeDownKey",
115 #endif
116         "ClipRaiseKey",
117         "ClipLowerKey",
118 #ifndef XKB_MODELOCK
119         "ClipRaiseLowerKey"
120 #else
121         "ClipRaiseLowerKey",
122         "ToggleKbdModeKey"
123 #endif                          /* XKB_MODELOCK */
124 };
125
126 #ifndef HAVE_XCONVERTCASE
127 /* from Xlib */
128
129 static void XConvertCase(register KeySym sym, KeySym * lower, KeySym * upper)
130 {
131         *lower = sym;
132         *upper = sym;
133         switch (sym >> 8) {
134         case 0:         /* Latin 1 */
135                 if ((sym >= XK_A) && (sym <= XK_Z))
136                         *lower += (XK_a - XK_A);
137                 else if ((sym >= XK_a) && (sym <= XK_z))
138                         *upper -= (XK_a - XK_A);
139                 else if ((sym >= XK_Agrave) && (sym <= XK_Odiaeresis))
140                         *lower += (XK_agrave - XK_Agrave);
141                 else if ((sym >= XK_agrave) && (sym <= XK_odiaeresis))
142                         *upper -= (XK_agrave - XK_Agrave);
143                 else if ((sym >= XK_Ooblique) && (sym <= XK_Thorn))
144                         *lower += (XK_oslash - XK_Ooblique);
145                 else if ((sym >= XK_oslash) && (sym <= XK_thorn))
146                         *upper -= (XK_oslash - XK_Ooblique);
147                 break;
148         case 1:         /* Latin 2 */
149                 /* Assume the KeySym is a legal value (ignore discontinuities) */
150                 if (sym == XK_Aogonek)
151                         *lower = XK_aogonek;
152                 else if (sym >= XK_Lstroke && sym <= XK_Sacute)
153                         *lower += (XK_lstroke - XK_Lstroke);
154                 else if (sym >= XK_Scaron && sym <= XK_Zacute)
155                         *lower += (XK_scaron - XK_Scaron);
156                 else if (sym >= XK_Zcaron && sym <= XK_Zabovedot)
157                         *lower += (XK_zcaron - XK_Zcaron);
158                 else if (sym == XK_aogonek)
159                         *upper = XK_Aogonek;
160                 else if (sym >= XK_lstroke && sym <= XK_sacute)
161                         *upper -= (XK_lstroke - XK_Lstroke);
162                 else if (sym >= XK_scaron && sym <= XK_zacute)
163                         *upper -= (XK_scaron - XK_Scaron);
164                 else if (sym >= XK_zcaron && sym <= XK_zabovedot)
165                         *upper -= (XK_zcaron - XK_Zcaron);
166                 else if (sym >= XK_Racute && sym <= XK_Tcedilla)
167                         *lower += (XK_racute - XK_Racute);
168                 else if (sym >= XK_racute && sym <= XK_tcedilla)
169                         *upper -= (XK_racute - XK_Racute);
170                 break;
171         case 2:         /* Latin 3 */
172                 /* Assume the KeySym is a legal value (ignore discontinuities) */
173                 if (sym >= XK_Hstroke && sym <= XK_Hcircumflex)
174                         *lower += (XK_hstroke - XK_Hstroke);
175                 else if (sym >= XK_Gbreve && sym <= XK_Jcircumflex)
176                         *lower += (XK_gbreve - XK_Gbreve);
177                 else if (sym >= XK_hstroke && sym <= XK_hcircumflex)
178                         *upper -= (XK_hstroke - XK_Hstroke);
179                 else if (sym >= XK_gbreve && sym <= XK_jcircumflex)
180                         *upper -= (XK_gbreve - XK_Gbreve);
181                 else if (sym >= XK_Cabovedot && sym <= XK_Scircumflex)
182                         *lower += (XK_cabovedot - XK_Cabovedot);
183                 else if (sym >= XK_cabovedot && sym <= XK_scircumflex)
184                         *upper -= (XK_cabovedot - XK_Cabovedot);
185                 break;
186         case 3:         /* Latin 4 */
187                 /* Assume the KeySym is a legal value (ignore discontinuities) */
188                 if (sym >= XK_Rcedilla && sym <= XK_Tslash)
189                         *lower += (XK_rcedilla - XK_Rcedilla);
190                 else if (sym >= XK_rcedilla && sym <= XK_tslash)
191                         *upper -= (XK_rcedilla - XK_Rcedilla);
192                 else if (sym == XK_ENG)
193                         *lower = XK_eng;
194                 else if (sym == XK_eng)
195                         *upper = XK_ENG;
196                 else if (sym >= XK_Amacron && sym <= XK_Umacron)
197                         *lower += (XK_amacron - XK_Amacron);
198                 else if (sym >= XK_amacron && sym <= XK_umacron)
199                         *upper -= (XK_amacron - XK_Amacron);
200                 break;
201         case 6:         /* Cyrillic */
202                 /* Assume the KeySym is a legal value (ignore discontinuities) */
203                 if (sym >= XK_Serbian_DJE && sym <= XK_Serbian_DZE)
204                         *lower -= (XK_Serbian_DJE - XK_Serbian_dje);
205                 else if (sym >= XK_Serbian_dje && sym <= XK_Serbian_dze)
206                         *upper += (XK_Serbian_DJE - XK_Serbian_dje);
207                 else if (sym >= XK_Cyrillic_YU && sym <= XK_Cyrillic_HARDSIGN)
208                         *lower -= (XK_Cyrillic_YU - XK_Cyrillic_yu);
209                 else if (sym >= XK_Cyrillic_yu && sym <= XK_Cyrillic_hardsign)
210                         *upper += (XK_Cyrillic_YU - XK_Cyrillic_yu);
211                 break;
212         case 7:         /* Greek */
213                 /* Assume the KeySym is a legal value (ignore discontinuities) */
214                 if (sym >= XK_Greek_ALPHAaccent && sym <= XK_Greek_OMEGAaccent)
215                         *lower += (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
216                 else if (sym >= XK_Greek_alphaaccent && sym <= XK_Greek_omegaaccent &&
217                          sym != XK_Greek_iotaaccentdieresis && sym != XK_Greek_upsilonaccentdieresis)
218                         *upper -= (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
219                 else if (sym >= XK_Greek_ALPHA && sym <= XK_Greek_OMEGA)
220                         *lower += (XK_Greek_alpha - XK_Greek_ALPHA);
221                 else if (sym >= XK_Greek_alpha && sym <= XK_Greek_omega && sym != XK_Greek_finalsmallsigma)
222                         *upper -= (XK_Greek_alpha - XK_Greek_ALPHA);
223                 break;
224         case 0x14:              /* Armenian */
225                 if (sym >= XK_Armenian_AYB && sym <= XK_Armenian_fe) {
226                         *lower = sym | 1;
227                         *upper = sym & ~1;
228                 }
229                 break;
230         }
231 }
232 #endif
233
234 static char *captureShortcut(Display * dpy, _Panel * panel)
235 {
236         XEvent ev;
237         KeySym ksym, lksym, uksym;
238         char buffer[64];
239         char *key = NULL;
240
241         while (panel->capturing) {
242                 XAllowEvents(dpy, AsyncKeyboard, CurrentTime);
243                 WMNextEvent(dpy, &ev);
244                 if (ev.type == KeyPress && ev.xkey.keycode != 0) {
245                         ksym = XKeycodeToKeysym(dpy, ev.xkey.keycode, 0);
246                         if (!IsModifierKey(ksym)) {
247                                 XConvertCase(ksym, &lksym, &uksym);
248                                 key = XKeysymToString(uksym);
249
250                                 panel->capturing = 0;
251                                 break;
252                         }
253                 }
254                 WMHandleEvent(&ev);
255         }
256
257         if (!key)
258                 return NULL;
259
260         buffer[0] = 0;
261
262         if (ev.xkey.state & ControlMask) {
263                 strcat(buffer, "Control+");
264         }
265         if (ev.xkey.state & ShiftMask) {
266                 strcat(buffer, "Shift+");
267         }
268         if (ev.xkey.state & Mod1Mask) {
269                 strcat(buffer, "Mod1+");
270         }
271         if (ev.xkey.state & Mod2Mask) {
272                 strcat(buffer, "Mod2+");
273         }
274         if (ev.xkey.state & Mod3Mask) {
275                 strcat(buffer, "Mod3+");
276         }
277         if (ev.xkey.state & Mod4Mask) {
278                 strcat(buffer, "Mod4+");
279         }
280         if (ev.xkey.state & Mod5Mask) {
281                 strcat(buffer, "Mod5+");
282         }
283         strcat(buffer, key);
284
285         return wstrdup(buffer);
286 }
287
288 static void captureClick(WMWidget * w, void *data)
289 {
290         _Panel *panel = (_Panel *) data;
291         Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->parent));
292         char *shortcut;
293
294         if (!panel->capturing) {
295                 panel->capturing = 1;
296                 WMSetButtonText(w, _("Cancel"));
297                 WMSetLabelText(panel->instructionsL,
298                                _("Press the desired shortcut key(s) or click Cancel to stop capturing."));
299                 XGrabKeyboard(dpy, WMWidgetXID(panel->parent), True, GrabModeAsync, GrabModeAsync, CurrentTime);
300                 shortcut = captureShortcut(dpy, panel);
301                 if (shortcut) {
302                         int row = WMGetListSelectedItemRow(panel->actLs);
303
304                         WMSetTextFieldText(panel->shoT, shortcut);
305                         if (row >= 0) {
306                                 if (panel->shortcuts[row])
307                                         wfree(panel->shortcuts[row]);
308                                 panel->shortcuts[row] = shortcut;
309
310                                 WMRedisplayWidget(panel->actLs);
311                         } else {
312                                 wfree(shortcut);
313                         }
314                 }
315         }
316         panel->capturing = 0;
317         WMSetButtonText(w, _("Capture"));
318         WMSetLabelText(panel->instructionsL, _("Click on Capture to interactively define the shortcut key."));
319         XUngrabKeyboard(dpy, CurrentTime);
320 }
321
322 static void clearShortcut(WMWidget * w, void *data)
323 {
324         _Panel *panel = (_Panel *) data;
325         int row = WMGetListSelectedItemRow(panel->actLs);
326
327         WMSetTextFieldText(panel->shoT, NULL);
328
329         if (row >= 0) {
330                 if (panel->shortcuts[row])
331                         wfree(panel->shortcuts[row]);
332                 panel->shortcuts[row] = NULL;
333                 WMRedisplayWidget(panel->actLs);
334         }
335 }
336
337 static void typedKeys(void *observerData, WMNotification * notification)
338 {
339         _Panel *panel = (_Panel *) observerData;
340         int row = WMGetListSelectedItemRow(panel->actLs);
341
342         if (row < 0)
343                 return;
344
345         if (panel->shortcuts[row])
346                 wfree(panel->shortcuts[row]);
347         panel->shortcuts[row] = WMGetTextFieldText(panel->shoT);
348         if (strlen(panel->shortcuts[row]) == 0) {
349                 wfree(panel->shortcuts[row]);
350                 panel->shortcuts[row] = NULL;
351         }
352         WMRedisplayWidget(panel->actLs);
353 }
354
355 static void listClick(WMWidget * w, void *data)
356 {
357         _Panel *panel = (_Panel *) data;
358         int row = WMGetListSelectedItemRow(w);
359
360         WMSetTextFieldText(panel->shoT, panel->shortcuts[row]);
361 }
362
363 static char *trimstr(char *str)
364 {
365         char *p = str;
366         int i;
367
368         while (isspace(*p))
369                 p++;
370         p = wstrdup(p);
371         i = strlen(p);
372         while (isspace(p[i]) && i > 0) {
373                 p[i] = 0;
374                 i--;
375         }
376
377         return p;
378 }
379
380 static void showData(_Panel * panel)
381 {
382         char *str;
383         int i;
384
385         for (i = 0; i < panel->actionCount; i++) {
386
387                 str = GetStringForKey(keyOptions[i]);
388                 if (panel->shortcuts[i])
389                         wfree(panel->shortcuts[i]);
390                 if (str)
391                         panel->shortcuts[i] = trimstr(str);
392                 else
393                         panel->shortcuts[i] = NULL;
394
395                 if (panel->shortcuts[i] &&
396                     (strcasecmp(panel->shortcuts[i], "none") == 0 || strlen(panel->shortcuts[i]) == 0)) {
397                         wfree(panel->shortcuts[i]);
398                         panel->shortcuts[i] = NULL;
399                 }
400         }
401         WMRedisplayWidget(panel->actLs);
402 }
403
404 static void paintItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
405 {
406         int width, height, x, y;
407         _Panel *panel = (_Panel *) WMGetHangedData(lPtr);
408         WMScreen *scr = WMWidgetScreen(lPtr);
409         Display *dpy = WMScreenDisplay(scr);
410         WMColor *backColor = (state & WLDSSelected) ? panel->white : panel->gray;
411
412         width = rect->size.width;
413         height = rect->size.height;
414         x = rect->pos.x;
415         y = rect->pos.y;
416
417         XFillRectangle(dpy, d, WMColorGC(backColor), x, y, width, height);
418
419         if (panel->shortcuts[index]) {
420                 WMPixmap *pix = WMGetSystemPixmap(scr, WSICheckMark);
421                 WMSize size = WMGetPixmapSize(pix);
422
423                 WMDrawPixmap(pix, d, x + (20 - size.width) / 2, (height - size.height) / 2 + y);
424                 WMReleasePixmap(pix);
425         }
426
427         WMDrawString(scr, d, panel->black, panel->font, x + 20, y, text, strlen(text));
428 }
429
430 static void createPanel(Panel * p)
431 {
432         _Panel *panel = (_Panel *) p;
433         WMScreen *scr = WMWidgetScreen(panel->parent);
434         WMColor *color;
435         WMFont *boldFont;
436
437         panel->capturing = 0;
438
439         panel->white = WMWhiteColor(scr);
440         panel->black = WMBlackColor(scr);
441         panel->gray = WMGrayColor(scr);
442         panel->font = WMSystemFontOfSize(scr, 12);
443
444         panel->box = WMCreateBox(panel->parent);
445         WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
446
447         boldFont = WMBoldSystemFontOfSize(scr, 12);
448
449         /* **************** Actions **************** */
450         panel->actL = WMCreateLabel(panel->box);
451         WMResizeWidget(panel->actL, 280, 20);
452         WMMoveWidget(panel->actL, 20, 10);
453         WMSetLabelFont(panel->actL, boldFont);
454         WMSetLabelText(panel->actL, _("Actions"));
455         WMSetLabelRelief(panel->actL, WRSunken);
456         WMSetLabelTextAlignment(panel->actL, WACenter);
457         color = WMDarkGrayColor(scr);
458         WMSetWidgetBackgroundColor(panel->actL, color);
459         WMReleaseColor(color);
460         WMSetLabelTextColor(panel->actL, panel->white);
461
462         panel->actLs = WMCreateList(panel->box);
463         WMResizeWidget(panel->actLs, 280, 190);
464         WMMoveWidget(panel->actLs, 20, 32);
465         WMSetListUserDrawProc(panel->actLs, paintItem);
466         WMHangData(panel->actLs, panel);
467
468         WMAddListItem(panel->actLs, _("Open applications menu"));
469         WMAddListItem(panel->actLs, _("Open window list menu"));
470         WMAddListItem(panel->actLs, _("Open window commands menu"));
471         WMAddListItem(panel->actLs, _("Hide active application"));
472         WMAddListItem(panel->actLs, _("Hide other applications"));
473         WMAddListItem(panel->actLs, _("Miniaturize active window"));
474         WMAddListItem(panel->actLs, _("Close active window"));
475         WMAddListItem(panel->actLs, _("Maximize active window"));
476         WMAddListItem(panel->actLs, _("Maximize active window vertically"));
477         WMAddListItem(panel->actLs, _("Maximize active window horizontally"));
478         WMAddListItem(panel->actLs, _("Maximize active window left half"));
479         WMAddListItem(panel->actLs, _("Maximize active window right half"));
480         WMAddListItem(panel->actLs, _("Raise active window"));
481         WMAddListItem(panel->actLs, _("Lower active window"));
482         WMAddListItem(panel->actLs, _("Raise/Lower window under mouse pointer"));
483         WMAddListItem(panel->actLs, _("Shade active window"));
484         WMAddListItem(panel->actLs, _("Move/Resize active window"));
485         WMAddListItem(panel->actLs, _("Select active window"));
486         WMAddListItem(panel->actLs, _("Focus next window"));
487         WMAddListItem(panel->actLs, _("Focus previous window"));
488         WMAddListItem(panel->actLs, _("Switch to next workspace"));
489         WMAddListItem(panel->actLs, _("Switch to previous workspace"));
490         WMAddListItem(panel->actLs, _("Switch to next ten workspaces"));
491         WMAddListItem(panel->actLs, _("Switch to previous ten workspaces"));
492         WMAddListItem(panel->actLs, _("Switch to workspace 1"));
493         WMAddListItem(panel->actLs, _("Switch to workspace 2"));
494         WMAddListItem(panel->actLs, _("Switch to workspace 3"));
495         WMAddListItem(panel->actLs, _("Switch to workspace 4"));
496         WMAddListItem(panel->actLs, _("Switch to workspace 5"));
497         WMAddListItem(panel->actLs, _("Switch to workspace 6"));
498         WMAddListItem(panel->actLs, _("Switch to workspace 7"));
499         WMAddListItem(panel->actLs, _("Switch to workspace 8"));
500         WMAddListItem(panel->actLs, _("Switch to workspace 9"));
501         WMAddListItem(panel->actLs, _("Switch to workspace 10"));
502         WMAddListItem(panel->actLs, _("Shortcut for window 1"));
503         WMAddListItem(panel->actLs, _("Shortcut for window 2"));
504         WMAddListItem(panel->actLs, _("Shortcut for window 3"));
505         WMAddListItem(panel->actLs, _("Shortcut for window 4"));
506         WMAddListItem(panel->actLs, _("Shortcut for window 5"));
507         WMAddListItem(panel->actLs, _("Shortcut for window 6"));
508         WMAddListItem(panel->actLs, _("Shortcut for window 7"));
509         WMAddListItem(panel->actLs, _("Shortcut for window 8"));
510         WMAddListItem(panel->actLs, _("Shortcut for window 9"));
511         WMAddListItem(panel->actLs, _("Shortcut for window 10"));
512         WMAddListItem(panel->actLs, _("Switch to Next Screen/Monitor"));
513 #ifdef VIRTUAL_DESKTOP
514         WMAddListItem(panel->actLs, _("Move VirtualDesktop to next left edge"));
515         WMAddListItem(panel->actLs, _("Move VirtualDesktop to next right edge"));
516         WMAddListItem(panel->actLs, _("Move VirtualDesktop to next top edge"));
517         WMAddListItem(panel->actLs, _("Move VirtualDesktop to next bottom edge"));
518 #endif
519         WMAddListItem(panel->actLs, _("Raise Clip"));
520         WMAddListItem(panel->actLs, _("Lower Clip"));
521         WMAddListItem(panel->actLs, _("Raise/Lower Clip"));
522 #ifdef XKB_MODELOCK
523         WMAddListItem(panel->actLs, _("Toggle keyboard language"));
524 #endif                          /* XKB_MODELOCK */
525
526         WMSetListAction(panel->actLs, listClick, panel);
527
528         panel->actionCount = WMGetListNumberOfRows(panel->actLs);
529         panel->shortcuts = wmalloc(sizeof(char *) * panel->actionCount);
530         memset(panel->shortcuts, 0, sizeof(char *) * panel->actionCount);
531
532     /***************** Shortcut ****************/
533
534         panel->shoF = WMCreateFrame(panel->box);
535         WMResizeWidget(panel->shoF, 190, 210);
536         WMMoveWidget(panel->shoF, 315, 10);
537         WMSetFrameTitle(panel->shoF, _("Shortcut"));
538
539         panel->shoT = WMCreateTextField(panel->shoF);
540         WMResizeWidget(panel->shoT, 160, 20);
541         WMMoveWidget(panel->shoT, 15, 65);
542         WMAddNotificationObserver(typedKeys, panel, WMTextDidChangeNotification, panel->shoT);
543
544         panel->cleB = WMCreateCommandButton(panel->shoF);
545         WMResizeWidget(panel->cleB, 75, 24);
546         WMMoveWidget(panel->cleB, 15, 95);
547         WMSetButtonText(panel->cleB, _("Clear"));
548         WMSetButtonAction(panel->cleB, clearShortcut, panel);
549
550         panel->defB = WMCreateCommandButton(panel->shoF);
551         WMResizeWidget(panel->defB, 75, 24);
552         WMMoveWidget(panel->defB, 100, 95);
553         WMSetButtonText(panel->defB, _("Capture"));
554         WMSetButtonAction(panel->defB, captureClick, panel);
555
556         panel->instructionsL = WMCreateLabel(panel->shoF);
557         WMResizeWidget(panel->instructionsL, 160, 55);
558         WMMoveWidget(panel->instructionsL, 15, 140);
559         WMSetLabelTextAlignment(panel->instructionsL, WACenter);
560         WMSetLabelWraps(panel->instructionsL, True);
561         WMSetLabelText(panel->instructionsL, _("Click on Capture to interactively define the shortcut key."));
562
563         WMMapSubwidgets(panel->shoF);
564
565         WMReleaseFont(boldFont);
566
567         WMRealizeWidget(panel->box);
568         WMMapSubwidgets(panel->box);
569
570         showData(panel);
571 }
572
573 static void storeData(_Panel * panel)
574 {
575         int i;
576         char *str;
577
578         for (i = 0; i < panel->actionCount; i++) {
579                 str = NULL;
580                 if (panel->shortcuts[i]) {
581                         str = trimstr(panel->shortcuts[i]);
582                         if (strlen(str) == 0) {
583                                 wfree(str);
584                                 str = NULL;
585                         }
586                 }
587                 if (str) {
588                         SetStringForKey(str, keyOptions[i]);
589                         wfree(str);
590                 } else {
591                         SetStringForKey("None", keyOptions[i]);
592                 }
593         }
594 }
595
596 Panel *InitKeyboardShortcuts(WMScreen * scr, WMWidget * parent)
597 {
598         _Panel *panel;
599
600         panel = wmalloc(sizeof(_Panel));
601         memset(panel, 0, sizeof(_Panel));
602
603         panel->sectionName = _("Keyboard Shortcut Preferences");
604
605         panel->description = _("Change the keyboard shortcuts for actions such\n"
606                                "as changing workspaces and opening menus.");
607
608         panel->parent = parent;
609
610         panel->callbacks.createWidgets = createPanel;
611         panel->callbacks.updateDomain = storeData;
612
613         AddSection(panel, ICON_FILE);
614
615         return panel;
616 }