wmaker: remove useless null pointer check (Coverity #109612)
[wmaker-crm.git] / WPrefs.app / KeyboardShortcuts.c
blob6984a918cc85f0076e6eb55ba1fabce9964b31db
1 /* KeyboardShortcuts.c- keyboard shortcut bindings
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1998-2003 Alfredo K. Kojima
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.
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.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "config.h" /* for HAVE_XCONVERTCASE */
24 #include "WPrefs.h"
25 #include <ctype.h>
27 #include <X11/keysym.h>
28 #include <X11/XKBlib.h>
30 typedef struct _Panel {
31 WMBox *box;
33 char *sectionName;
35 char *description;
37 CallbackRec callbacks;
39 WMWidget *parent;
41 WMLabel *actL;
42 WMList *actLs;
44 WMFrame *shoF;
45 WMTextField *shoT;
46 WMButton *cleB;
47 WMButton *defB;
49 WMLabel *instructionsL;
51 WMColor *white;
52 WMColor *black;
53 WMColor *gray;
54 WMFont *font;
56 Bool capturing;
57 char **shortcuts;
58 int actionCount;
59 } _Panel;
61 #define ICON_FILE "keyshortcuts"
64 * List of user definable shortcut keys
65 * First parameter is the internal keyword known by WMaker
66 * Second is the text displayed to the user
68 static const struct {
69 const char *key;
70 const char *title;
71 } keyOptions[] = {
72 { "RootMenuKey", N_("Open applications menu") },
73 { "WindowListKey", N_("Open window list menu") },
74 { "WindowMenuKey", N_("Open window commands menu") },
75 { "HideKey", N_("Hide active application") },
76 { "HideOthersKey", N_("Hide other applications") },
77 { "MiniaturizeKey", N_("Miniaturize active window") },
78 { "MinimizeAllKey", N_("Miniaturize all windows") },
79 { "CloseKey", N_("Close active window") },
80 { "MaximizeKey", N_("Maximize active window") },
81 { "VMaximizeKey", N_("Maximize active window vertically") },
82 { "HMaximizeKey", N_("Maximize active window horizontally") },
83 { "LHMaximizeKey", N_("Maximize active window left half") },
84 { "RHMaximizeKey", N_("Maximize active window right half") },
85 { "THMaximizeKey", N_("Maximize active window top half") },
86 { "BHMaximizeKey", N_("Maximize active window bottom half") },
87 { "LTCMaximizeKey", N_("Maximize active window left top corner") },
88 { "RTCMaximizeKey", N_("Maximize active window right top corner") },
89 { "LBCMaximizeKey", N_("Maximize active window left bottom corner") },
90 { "RBCMaximizeKey", N_("Maximize active window right bottom corner") },
91 { "MaximusKey", N_("Maximus: Tiled maximization ") },
92 { "OmnipresentKey", N_("Toggle window omnipresent status") },
93 { "RaiseKey", N_("Raise active window") },
94 { "LowerKey", N_("Lower active window") },
95 { "RaiseLowerKey", N_("Raise/Lower window under mouse pointer") },
96 { "ShadeKey", N_("Shade active window") },
97 { "MoveResizeKey", N_("Move/Resize active window") },
98 { "SelectKey", N_("Select active window") },
99 { "FocusNextKey", N_("Focus next window") },
100 { "FocusPrevKey", N_("Focus previous window") },
101 { "GroupNextKey", N_("Focus next group window") },
102 { "GroupPrevKey", N_("Focus previous group window") },
104 /* Workspace Related */
105 { "WorkspaceMapKey", N_("Open workspace pager") },
106 { "NextWorkspaceKey", N_("Switch to next workspace") },
107 { "PrevWorkspaceKey", N_("Switch to previous workspace") },
108 { "LastWorkspaceKey", N_("Switch to last used workspace") },
109 { "NextWorkspaceLayerKey", N_("Switch to next ten workspaces") },
110 { "PrevWorkspaceLayerKey", N_("Switch to previous ten workspaces") },
111 { "Workspace1Key", N_("Switch to workspace 1") },
112 { "Workspace2Key", N_("Switch to workspace 2") },
113 { "Workspace3Key", N_("Switch to workspace 3") },
114 { "Workspace4Key", N_("Switch to workspace 4") },
115 { "Workspace5Key", N_("Switch to workspace 5") },
116 { "Workspace6Key", N_("Switch to workspace 6") },
117 { "Workspace7Key", N_("Switch to workspace 7") },
118 { "Workspace8Key", N_("Switch to workspace 8") },
119 { "Workspace9Key", N_("Switch to workspace 9") },
120 { "Workspace10Key", N_("Switch to workspace 10") },
121 { "MoveToNextWorkspaceKey", N_("Move window to next workspace") },
122 { "MoveToPrevWorkspaceKey", N_("Move window to previous workspace") },
123 { "MoveToLastWorkspaceKey", N_("Move window to last used workspace") },
124 { "MoveToNextWorkspaceLayerKey", N_("Move window to next ten workspaces") },
125 { "MoveToPrevWorkspaceLayerKey", N_("Move window to previous ten workspaces") },
126 { "MoveToWorkspace1Key", N_("Move window to workspace 1") },
127 { "MoveToWorkspace2Key", N_("Move window to workspace 2") },
128 { "MoveToWorkspace3Key", N_("Move window to workspace 3") },
129 { "MoveToWorkspace4Key", N_("Move window to workspace 4") },
130 { "MoveToWorkspace5Key", N_("Move window to workspace 5") },
131 { "MoveToWorkspace6Key", N_("Move window to workspace 6") },
132 { "MoveToWorkspace7Key", N_("Move window to workspace 7") },
133 { "MoveToWorkspace8Key", N_("Move window to workspace 8") },
134 { "MoveToWorkspace9Key", N_("Move window to workspace 9") },
135 { "MoveToWorkspace10Key", N_("Move window to workspace 10") },
137 /* Window Selection */
138 { "WindowShortcut1Key", N_("Shortcut for window 1") },
139 { "WindowShortcut2Key", N_("Shortcut for window 2") },
140 { "WindowShortcut3Key", N_("Shortcut for window 3") },
141 { "WindowShortcut4Key", N_("Shortcut for window 4") },
142 { "WindowShortcut5Key", N_("Shortcut for window 5") },
143 { "WindowShortcut6Key", N_("Shortcut for window 6") },
144 { "WindowShortcut7Key", N_("Shortcut for window 7") },
145 { "WindowShortcut8Key", N_("Shortcut for window 8") },
146 { "WindowShortcut9Key", N_("Shortcut for window 9") },
147 { "WindowShortcut10Key", N_("Shortcut for window 10") },
149 /* Misc. */
150 { "WindowRelaunchKey", N_("Launch new instance of application") },
151 { "ScreenSwitchKey", N_("Switch to Next Screen/Monitor") },
152 { "RunKey", N_("Run application") },
153 { "DockRaiseLowerKey", N_("Raise/Lower Dock") },
154 { "ClipRaiseLowerKey", N_("Raise/Lower Clip") }
155 #ifdef XKB_MODELOCK
156 ,{ "ToggleKbdModeKey", N_("Toggle keyboard language") }
157 #endif /* XKB_MODELOCK */
160 #ifndef HAVE_XCONVERTCASE
161 /* from Xlib */
163 static void XConvertCase(register KeySym sym, KeySym * lower, KeySym * upper)
165 *lower = sym;
166 *upper = sym;
167 switch (sym >> 8) {
168 case 0: /* Latin 1 */
169 if ((sym >= XK_A) && (sym <= XK_Z))
170 *lower += (XK_a - XK_A);
171 else if ((sym >= XK_a) && (sym <= XK_z))
172 *upper -= (XK_a - XK_A);
173 else if ((sym >= XK_Agrave) && (sym <= XK_Odiaeresis))
174 *lower += (XK_agrave - XK_Agrave);
175 else if ((sym >= XK_agrave) && (sym <= XK_odiaeresis))
176 *upper -= (XK_agrave - XK_Agrave);
177 else if ((sym >= XK_Ooblique) && (sym <= XK_Thorn))
178 *lower += (XK_oslash - XK_Ooblique);
179 else if ((sym >= XK_oslash) && (sym <= XK_thorn))
180 *upper -= (XK_oslash - XK_Ooblique);
181 break;
182 case 1: /* Latin 2 */
183 /* Assume the KeySym is a legal value (ignore discontinuities) */
184 if (sym == XK_Aogonek)
185 *lower = XK_aogonek;
186 else if (sym >= XK_Lstroke && sym <= XK_Sacute)
187 *lower += (XK_lstroke - XK_Lstroke);
188 else if (sym >= XK_Scaron && sym <= XK_Zacute)
189 *lower += (XK_scaron - XK_Scaron);
190 else if (sym >= XK_Zcaron && sym <= XK_Zabovedot)
191 *lower += (XK_zcaron - XK_Zcaron);
192 else if (sym == XK_aogonek)
193 *upper = XK_Aogonek;
194 else if (sym >= XK_lstroke && sym <= XK_sacute)
195 *upper -= (XK_lstroke - XK_Lstroke);
196 else if (sym >= XK_scaron && sym <= XK_zacute)
197 *upper -= (XK_scaron - XK_Scaron);
198 else if (sym >= XK_zcaron && sym <= XK_zabovedot)
199 *upper -= (XK_zcaron - XK_Zcaron);
200 else if (sym >= XK_Racute && sym <= XK_Tcedilla)
201 *lower += (XK_racute - XK_Racute);
202 else if (sym >= XK_racute && sym <= XK_tcedilla)
203 *upper -= (XK_racute - XK_Racute);
204 break;
205 case 2: /* Latin 3 */
206 /* Assume the KeySym is a legal value (ignore discontinuities) */
207 if (sym >= XK_Hstroke && sym <= XK_Hcircumflex)
208 *lower += (XK_hstroke - XK_Hstroke);
209 else if (sym >= XK_Gbreve && sym <= XK_Jcircumflex)
210 *lower += (XK_gbreve - XK_Gbreve);
211 else if (sym >= XK_hstroke && sym <= XK_hcircumflex)
212 *upper -= (XK_hstroke - XK_Hstroke);
213 else if (sym >= XK_gbreve && sym <= XK_jcircumflex)
214 *upper -= (XK_gbreve - XK_Gbreve);
215 else if (sym >= XK_Cabovedot && sym <= XK_Scircumflex)
216 *lower += (XK_cabovedot - XK_Cabovedot);
217 else if (sym >= XK_cabovedot && sym <= XK_scircumflex)
218 *upper -= (XK_cabovedot - XK_Cabovedot);
219 break;
220 case 3: /* Latin 4 */
221 /* Assume the KeySym is a legal value (ignore discontinuities) */
222 if (sym >= XK_Rcedilla && sym <= XK_Tslash)
223 *lower += (XK_rcedilla - XK_Rcedilla);
224 else if (sym >= XK_rcedilla && sym <= XK_tslash)
225 *upper -= (XK_rcedilla - XK_Rcedilla);
226 else if (sym == XK_ENG)
227 *lower = XK_eng;
228 else if (sym == XK_eng)
229 *upper = XK_ENG;
230 else if (sym >= XK_Amacron && sym <= XK_Umacron)
231 *lower += (XK_amacron - XK_Amacron);
232 else if (sym >= XK_amacron && sym <= XK_umacron)
233 *upper -= (XK_amacron - XK_Amacron);
234 break;
235 case 6: /* Cyrillic */
236 /* Assume the KeySym is a legal value (ignore discontinuities) */
237 if (sym >= XK_Serbian_DJE && sym <= XK_Serbian_DZE)
238 *lower -= (XK_Serbian_DJE - XK_Serbian_dje);
239 else if (sym >= XK_Serbian_dje && sym <= XK_Serbian_dze)
240 *upper += (XK_Serbian_DJE - XK_Serbian_dje);
241 else if (sym >= XK_Cyrillic_YU && sym <= XK_Cyrillic_HARDSIGN)
242 *lower -= (XK_Cyrillic_YU - XK_Cyrillic_yu);
243 else if (sym >= XK_Cyrillic_yu && sym <= XK_Cyrillic_hardsign)
244 *upper += (XK_Cyrillic_YU - XK_Cyrillic_yu);
245 break;
246 case 7: /* Greek */
247 /* Assume the KeySym is a legal value (ignore discontinuities) */
248 if (sym >= XK_Greek_ALPHAaccent && sym <= XK_Greek_OMEGAaccent)
249 *lower += (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
250 else if (sym >= XK_Greek_alphaaccent && sym <= XK_Greek_omegaaccent &&
251 sym != XK_Greek_iotaaccentdieresis && sym != XK_Greek_upsilonaccentdieresis)
252 *upper -= (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
253 else if (sym >= XK_Greek_ALPHA && sym <= XK_Greek_OMEGA)
254 *lower += (XK_Greek_alpha - XK_Greek_ALPHA);
255 else if (sym >= XK_Greek_alpha && sym <= XK_Greek_omega && sym != XK_Greek_finalsmallsigma)
256 *upper -= (XK_Greek_alpha - XK_Greek_ALPHA);
257 break;
258 case 0x14: /* Armenian */
259 if (sym >= XK_Armenian_AYB && sym <= XK_Armenian_fe) {
260 *lower = sym | 1;
261 *upper = sym & ~1;
263 break;
266 #endif
268 static int NumLockMask(Display *dpy)
270 int i, mask;
271 XModifierKeymap *map;
272 static int mask_table[8] = {
273 ShiftMask, LockMask, ControlMask, Mod1Mask,
274 Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
276 KeyCode numlock_keycode = XKeysymToKeycode(dpy, XK_Num_Lock);
278 if (numlock_keycode == NoSymbol)
279 return 0;
281 map = XGetModifierMapping(dpy);
282 if (!map)
283 return 0;
285 mask = 0;
286 for (i = 0; i < 8 * map->max_keypermod; i++) {
287 if (map->modifiermap[i] == numlock_keycode && mask == 0) {
288 mask = mask_table[i/map->max_keypermod];
289 break;
293 if (map)
294 XFreeModifiermap(map);
296 return mask;
299 char *capture_shortcut(Display *dpy, Bool *capturing, Bool convert_case)
301 XEvent ev;
302 KeySym ksym, lksym, uksym;
303 char buffer[64];
304 char *key = NULL;
305 unsigned int numlock_mask;
307 while (*capturing) {
308 XAllowEvents(dpy, AsyncKeyboard, CurrentTime);
309 WMNextEvent(dpy, &ev);
310 if (ev.type == KeyPress && ev.xkey.keycode != 0) {
311 numlock_mask = NumLockMask(dpy);
313 if (xext_xkb_supported)
314 /* conditional mask check to get numeric keypad keys */
315 ksym = XkbKeycodeToKeysym(dpy, ev.xkey.keycode, 0, ev.xkey.state & numlock_mask?1:0);
316 else
317 ksym = XKeycodeToKeysym(dpy, ev.xkey.keycode, 0);
319 if (!IsModifierKey(ksym)) {
320 if (convert_case) {
321 XConvertCase(ksym, &lksym, &uksym);
322 key = XKeysymToString(uksym);
323 } else {
324 key = XKeysymToString(ksym);
327 *capturing = 0;
328 break;
331 WMHandleEvent(&ev);
334 if (!key)
335 return NULL;
337 buffer[0] = 0;
339 if (ev.xkey.state & ControlMask)
340 strcat(buffer, "Control+");
342 if (ev.xkey.state & ShiftMask)
343 strcat(buffer, "Shift+");
345 if ((numlock_mask != Mod1Mask) && (ev.xkey.state & Mod1Mask))
346 strcat(buffer, "Mod1+");
348 if ((numlock_mask != Mod2Mask) && (ev.xkey.state & Mod2Mask))
349 strcat(buffer, "Mod2+");
351 if ((numlock_mask != Mod3Mask) && (ev.xkey.state & Mod3Mask))
352 strcat(buffer, "Mod3+");
354 if ((numlock_mask != Mod4Mask) && (ev.xkey.state & Mod4Mask))
355 strcat(buffer, "Mod4+");
357 if ((numlock_mask != Mod5Mask) && (ev.xkey.state & Mod5Mask))
358 strcat(buffer, "Mod5+");
360 wstrlcat(buffer, key, sizeof(buffer));
362 return wstrdup(buffer);
365 static void captureClick(WMWidget * w, void *data)
367 _Panel *panel = (_Panel *) data;
368 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->parent));
369 char *shortcut;
371 if (!panel->capturing) {
372 panel->capturing = 1;
373 WMSetButtonText(w, _("Cancel"));
374 WMSetLabelText(panel->instructionsL,
375 _("Press the desired shortcut key(s) or click Cancel to stop capturing."));
376 XGrabKeyboard(dpy, WMWidgetXID(panel->parent), True, GrabModeAsync, GrabModeAsync, CurrentTime);
377 shortcut = capture_shortcut(dpy, &panel->capturing, 1);
378 if (shortcut) {
379 int row = WMGetListSelectedItemRow(panel->actLs);
381 WMSetTextFieldText(panel->shoT, shortcut);
382 if (row >= 0) {
383 if (panel->shortcuts[row])
384 wfree(panel->shortcuts[row]);
385 panel->shortcuts[row] = shortcut;
387 WMRedisplayWidget(panel->actLs);
388 } else {
389 wfree(shortcut);
393 panel->capturing = 0;
394 WMSetButtonText(w, _("Capture"));
395 WMSetLabelText(panel->instructionsL, _("Click on Capture to interactively define the shortcut key."));
396 XUngrabKeyboard(dpy, CurrentTime);
399 static void clearShortcut(WMWidget * w, void *data)
401 _Panel *panel = (_Panel *) data;
402 int row = WMGetListSelectedItemRow(panel->actLs);
404 /* Parameter not used, but tell the compiler that it is ok */
405 (void) w;
407 WMSetTextFieldText(panel->shoT, NULL);
409 if (row >= 0) {
410 if (panel->shortcuts[row])
411 wfree(panel->shortcuts[row]);
412 panel->shortcuts[row] = NULL;
413 WMRedisplayWidget(panel->actLs);
417 static void typedKeys(void *observerData, WMNotification * notification)
419 _Panel *panel = (_Panel *) observerData;
420 int row = WMGetListSelectedItemRow(panel->actLs);
422 /* Parameter not used, but tell the compiler that it is ok */
423 (void) notification;
425 if (row < 0)
426 return;
428 if (panel->shortcuts[row])
429 wfree(panel->shortcuts[row]);
430 panel->shortcuts[row] = WMGetTextFieldText(panel->shoT);
431 if (strlen(panel->shortcuts[row]) == 0) {
432 wfree(panel->shortcuts[row]);
433 panel->shortcuts[row] = NULL;
435 WMRedisplayWidget(panel->actLs);
438 static void listClick(WMWidget * w, void *data)
440 _Panel *panel = (_Panel *) data;
441 int row = WMGetListSelectedItemRow(w);
443 WMSetTextFieldText(panel->shoT, panel->shortcuts[row]);
446 static void showData(_Panel * panel)
448 char *str;
449 int i;
451 for (i = 0; i < panel->actionCount; i++) {
453 str = GetStringForKey(keyOptions[i].key);
454 if (panel->shortcuts[i])
455 wfree(panel->shortcuts[i]);
456 if (str)
457 panel->shortcuts[i] = wtrimspace(str);
458 else
459 panel->shortcuts[i] = NULL;
461 if (panel->shortcuts[i] &&
462 (strcasecmp(panel->shortcuts[i], "none") == 0 || strlen(panel->shortcuts[i]) == 0)) {
463 wfree(panel->shortcuts[i]);
464 panel->shortcuts[i] = NULL;
467 WMRedisplayWidget(panel->actLs);
470 static void paintItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
472 int width, height, x, y;
473 _Panel *panel = (_Panel *) WMGetHangedData(lPtr);
474 WMScreen *scr = WMWidgetScreen(lPtr);
475 Display *dpy = WMScreenDisplay(scr);
476 WMColor *backColor = (state & WLDSSelected) ? panel->white : panel->gray;
478 width = rect->size.width;
479 height = rect->size.height;
480 x = rect->pos.x;
481 y = rect->pos.y;
483 XFillRectangle(dpy, d, WMColorGC(backColor), x, y, width, height);
485 if (panel->shortcuts[index]) {
486 WMPixmap *pix = WMGetSystemPixmap(scr, WSICheckMark);
487 WMSize size = WMGetPixmapSize(pix);
489 WMDrawPixmap(pix, d, x + (20 - size.width) / 2, (height - size.height) / 2 + y);
490 WMReleasePixmap(pix);
493 WMDrawString(scr, d, panel->black, panel->font, x + 20, y, text, strlen(text));
496 static void createPanel(Panel * p)
498 _Panel *panel = (_Panel *) p;
499 WMScreen *scr = WMWidgetScreen(panel->parent);
500 WMColor *color;
501 WMFont *boldFont;
502 int i;
504 panel->capturing = 0;
506 panel->white = WMWhiteColor(scr);
507 panel->black = WMBlackColor(scr);
508 panel->gray = WMGrayColor(scr);
509 panel->font = WMSystemFontOfSize(scr, 12);
511 panel->box = WMCreateBox(panel->parent);
512 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
514 boldFont = WMBoldSystemFontOfSize(scr, 12);
516 /* **************** Actions **************** */
517 panel->actL = WMCreateLabel(panel->box);
518 WMResizeWidget(panel->actL, 314, 20);
519 WMMoveWidget(panel->actL, 9, 9);
520 WMSetLabelFont(panel->actL, boldFont);
521 WMSetLabelText(panel->actL, _("Actions"));
522 WMSetLabelRelief(panel->actL, WRSunken);
523 WMSetLabelTextAlignment(panel->actL, WACenter);
524 color = WMDarkGrayColor(scr);
525 WMSetWidgetBackgroundColor(panel->actL, color);
526 WMReleaseColor(color);
527 WMSetLabelTextColor(panel->actL, panel->white);
529 panel->actLs = WMCreateList(panel->box);
530 WMResizeWidget(panel->actLs, 314, 191);
531 WMMoveWidget(panel->actLs, 9, 31);
532 WMSetListUserDrawProc(panel->actLs, paintItem);
533 WMHangData(panel->actLs, panel);
535 for (i = 0; i < wlengthof(keyOptions); i++) {
536 WMAddListItem(panel->actLs, _(keyOptions[i].title));
538 WMSetListAction(panel->actLs, listClick, panel);
540 panel->actionCount = WMGetListNumberOfRows(panel->actLs);
541 panel->shortcuts = wmalloc(sizeof(char *) * panel->actionCount);
543 /***************** Shortcut ****************/
545 panel->shoF = WMCreateFrame(panel->box);
546 WMResizeWidget(panel->shoF, 178, 214);
547 WMMoveWidget(panel->shoF, 333, 8);
548 WMSetFrameTitle(panel->shoF, _("Shortcut"));
550 panel->shoT = WMCreateTextField(panel->shoF);
551 WMResizeWidget(panel->shoT, 160, 20);
552 WMMoveWidget(panel->shoT, 9, 65);
553 WMAddNotificationObserver(typedKeys, panel, WMTextDidChangeNotification, panel->shoT);
555 panel->cleB = WMCreateCommandButton(panel->shoF);
556 WMResizeWidget(panel->cleB, 75, 24);
557 WMMoveWidget(panel->cleB, 9, 95);
558 WMSetButtonText(panel->cleB, _("Clear"));
559 WMSetButtonAction(panel->cleB, clearShortcut, panel);
561 panel->defB = WMCreateCommandButton(panel->shoF);
562 WMResizeWidget(panel->defB, 75, 24);
563 WMMoveWidget(panel->defB, 94, 95);
564 WMSetButtonText(panel->defB, _("Capture"));
565 WMSetButtonAction(panel->defB, captureClick, panel);
567 panel->instructionsL = WMCreateLabel(panel->shoF);
568 WMResizeWidget(panel->instructionsL, 160, 55);
569 WMMoveWidget(panel->instructionsL, 9, 140);
570 WMSetLabelTextAlignment(panel->instructionsL, WACenter);
571 WMSetLabelWraps(panel->instructionsL, True);
572 WMSetLabelText(panel->instructionsL, _("Click on Capture to interactively define the shortcut key."));
574 WMMapSubwidgets(panel->shoF);
576 WMReleaseFont(boldFont);
578 WMRealizeWidget(panel->box);
579 WMMapSubwidgets(panel->box);
581 showData(panel);
584 static void storeData(_Panel * panel)
586 int i;
587 char *str;
589 for (i = 0; i < panel->actionCount; i++) {
590 str = NULL;
591 if (panel->shortcuts[i]) {
592 str = wtrimspace(panel->shortcuts[i]);
593 if (strlen(str) == 0) {
594 wfree(str);
595 str = NULL;
598 if (str) {
599 SetStringForKey(str, keyOptions[i].key);
600 wfree(str);
601 } else {
602 SetStringForKey("None", keyOptions[i].key);
607 Panel *InitKeyboardShortcuts(WMWidget *parent)
609 _Panel *panel;
611 panel = wmalloc(sizeof(_Panel));
613 panel->sectionName = _("Keyboard Shortcut Preferences");
615 panel->description = _("Change the keyboard shortcuts for actions such\n"
616 "as changing workspaces and opening menus.");
618 panel->parent = parent;
620 panel->callbacks.createWidgets = createPanel;
621 panel->callbacks.updateDomain = storeData;
623 AddSection(panel, ICON_FILE);
625 return panel;