WPrefs: fix key capture
[wmaker-crm.git] / WPrefs.app / KeyboardShortcuts.c
blob7cf97c61ae30be68e6d3f9ae0c7f43ac95cd57eb
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 { "RaiseKey", N_("Raise active window") },
93 { "LowerKey", N_("Lower active window") },
94 { "RaiseLowerKey", N_("Raise/Lower window under mouse pointer") },
95 { "ShadeKey", N_("Shade active window") },
96 { "MoveResizeKey", N_("Move/Resize active window") },
97 { "SelectKey", N_("Select active window") },
98 { "FocusNextKey", N_("Focus next window") },
99 { "FocusPrevKey", N_("Focus previous window") },
100 { "GroupNextKey", N_("Focus next group window") },
101 { "GroupPrevKey", N_("Focus previous group window") },
103 /* Workspace Related */
104 { "NextWorkspaceKey", N_("Switch to next workspace") },
105 { "PrevWorkspaceKey", N_("Switch to previous workspace") },
106 { "LastWorkspaceKey", N_("Switch to last used workspace") },
107 { "NextWorkspaceLayerKey", N_("Switch to next ten workspaces") },
108 { "PrevWorkspaceLayerKey", N_("Switch to previous ten workspaces") },
109 { "Workspace1Key", N_("Switch to workspace 1") },
110 { "Workspace2Key", N_("Switch to workspace 2") },
111 { "Workspace3Key", N_("Switch to workspace 3") },
112 { "Workspace4Key", N_("Switch to workspace 4") },
113 { "Workspace5Key", N_("Switch to workspace 5") },
114 { "Workspace6Key", N_("Switch to workspace 6") },
115 { "Workspace7Key", N_("Switch to workspace 7") },
116 { "Workspace8Key", N_("Switch to workspace 8") },
117 { "Workspace9Key", N_("Switch to workspace 9") },
118 { "Workspace10Key", N_("Switch to workspace 10") },
119 { "MoveToNextWorkspaceKey", N_("Move window to next workspace") },
120 { "MoveToPrevWorkspaceKey", N_("Move window to previous workspace") },
121 { "MoveToLastWorkspaceKey", N_("Move window to last used workspace") },
122 { "MoveToNextWorkspaceLayerKey", N_("Move window to next ten workspaces") },
123 { "MoveToPrevWorkspaceLayerKey", N_("Move window to previous ten workspaces") },
124 { "MoveToWorkspace1Key", N_("Move window to workspace 1") },
125 { "MoveToWorkspace2Key", N_("Move window to workspace 2") },
126 { "MoveToWorkspace3Key", N_("Move window to workspace 3") },
127 { "MoveToWorkspace4Key", N_("Move window to workspace 4") },
128 { "MoveToWorkspace5Key", N_("Move window to workspace 5") },
129 { "MoveToWorkspace6Key", N_("Move window to workspace 6") },
130 { "MoveToWorkspace7Key", N_("Move window to workspace 7") },
131 { "MoveToWorkspace8Key", N_("Move window to workspace 8") },
132 { "MoveToWorkspace9Key", N_("Move window to workspace 9") },
133 { "MoveToWorkspace10Key", N_("Move window to workspace 10") },
135 /* Window Selection */
136 { "WindowShortcut1Key", N_("Shortcut for window 1") },
137 { "WindowShortcut2Key", N_("Shortcut for window 2") },
138 { "WindowShortcut3Key", N_("Shortcut for window 3") },
139 { "WindowShortcut4Key", N_("Shortcut for window 4") },
140 { "WindowShortcut5Key", N_("Shortcut for window 5") },
141 { "WindowShortcut6Key", N_("Shortcut for window 6") },
142 { "WindowShortcut7Key", N_("Shortcut for window 7") },
143 { "WindowShortcut8Key", N_("Shortcut for window 8") },
144 { "WindowShortcut9Key", N_("Shortcut for window 9") },
145 { "WindowShortcut10Key", N_("Shortcut for window 10") },
147 /* Misc. */
148 { "WindowRelaunchKey", N_("Launch new instance of application") },
149 { "ScreenSwitchKey", N_("Switch to Next Screen/Monitor") },
150 { "RunKey", N_("Run application") },
151 { "DockRaiseLowerKey", N_("Raise/Lower Dock") },
152 { "ClipRaiseLowerKey", N_("Raise/Lower Clip") }
153 #ifdef XKB_MODELOCK
154 ,{ "ToggleKbdModeKey", N_("Toggle keyboard language") }
155 #endif /* XKB_MODELOCK */
158 #ifndef HAVE_XCONVERTCASE
159 /* from Xlib */
161 static void XConvertCase(register KeySym sym, KeySym * lower, KeySym * upper)
163 *lower = sym;
164 *upper = sym;
165 switch (sym >> 8) {
166 case 0: /* Latin 1 */
167 if ((sym >= XK_A) && (sym <= XK_Z))
168 *lower += (XK_a - XK_A);
169 else if ((sym >= XK_a) && (sym <= XK_z))
170 *upper -= (XK_a - XK_A);
171 else if ((sym >= XK_Agrave) && (sym <= XK_Odiaeresis))
172 *lower += (XK_agrave - XK_Agrave);
173 else if ((sym >= XK_agrave) && (sym <= XK_odiaeresis))
174 *upper -= (XK_agrave - XK_Agrave);
175 else if ((sym >= XK_Ooblique) && (sym <= XK_Thorn))
176 *lower += (XK_oslash - XK_Ooblique);
177 else if ((sym >= XK_oslash) && (sym <= XK_thorn))
178 *upper -= (XK_oslash - XK_Ooblique);
179 break;
180 case 1: /* Latin 2 */
181 /* Assume the KeySym is a legal value (ignore discontinuities) */
182 if (sym == XK_Aogonek)
183 *lower = XK_aogonek;
184 else if (sym >= XK_Lstroke && sym <= XK_Sacute)
185 *lower += (XK_lstroke - XK_Lstroke);
186 else if (sym >= XK_Scaron && sym <= XK_Zacute)
187 *lower += (XK_scaron - XK_Scaron);
188 else if (sym >= XK_Zcaron && sym <= XK_Zabovedot)
189 *lower += (XK_zcaron - XK_Zcaron);
190 else if (sym == XK_aogonek)
191 *upper = XK_Aogonek;
192 else if (sym >= XK_lstroke && sym <= XK_sacute)
193 *upper -= (XK_lstroke - XK_Lstroke);
194 else if (sym >= XK_scaron && sym <= XK_zacute)
195 *upper -= (XK_scaron - XK_Scaron);
196 else if (sym >= XK_zcaron && sym <= XK_zabovedot)
197 *upper -= (XK_zcaron - XK_Zcaron);
198 else if (sym >= XK_Racute && sym <= XK_Tcedilla)
199 *lower += (XK_racute - XK_Racute);
200 else if (sym >= XK_racute && sym <= XK_tcedilla)
201 *upper -= (XK_racute - XK_Racute);
202 break;
203 case 2: /* Latin 3 */
204 /* Assume the KeySym is a legal value (ignore discontinuities) */
205 if (sym >= XK_Hstroke && sym <= XK_Hcircumflex)
206 *lower += (XK_hstroke - XK_Hstroke);
207 else if (sym >= XK_Gbreve && sym <= XK_Jcircumflex)
208 *lower += (XK_gbreve - XK_Gbreve);
209 else if (sym >= XK_hstroke && sym <= XK_hcircumflex)
210 *upper -= (XK_hstroke - XK_Hstroke);
211 else if (sym >= XK_gbreve && sym <= XK_jcircumflex)
212 *upper -= (XK_gbreve - XK_Gbreve);
213 else if (sym >= XK_Cabovedot && sym <= XK_Scircumflex)
214 *lower += (XK_cabovedot - XK_Cabovedot);
215 else if (sym >= XK_cabovedot && sym <= XK_scircumflex)
216 *upper -= (XK_cabovedot - XK_Cabovedot);
217 break;
218 case 3: /* Latin 4 */
219 /* Assume the KeySym is a legal value (ignore discontinuities) */
220 if (sym >= XK_Rcedilla && sym <= XK_Tslash)
221 *lower += (XK_rcedilla - XK_Rcedilla);
222 else if (sym >= XK_rcedilla && sym <= XK_tslash)
223 *upper -= (XK_rcedilla - XK_Rcedilla);
224 else if (sym == XK_ENG)
225 *lower = XK_eng;
226 else if (sym == XK_eng)
227 *upper = XK_ENG;
228 else if (sym >= XK_Amacron && sym <= XK_Umacron)
229 *lower += (XK_amacron - XK_Amacron);
230 else if (sym >= XK_amacron && sym <= XK_umacron)
231 *upper -= (XK_amacron - XK_Amacron);
232 break;
233 case 6: /* Cyrillic */
234 /* Assume the KeySym is a legal value (ignore discontinuities) */
235 if (sym >= XK_Serbian_DJE && sym <= XK_Serbian_DZE)
236 *lower -= (XK_Serbian_DJE - XK_Serbian_dje);
237 else if (sym >= XK_Serbian_dje && sym <= XK_Serbian_dze)
238 *upper += (XK_Serbian_DJE - XK_Serbian_dje);
239 else if (sym >= XK_Cyrillic_YU && sym <= XK_Cyrillic_HARDSIGN)
240 *lower -= (XK_Cyrillic_YU - XK_Cyrillic_yu);
241 else if (sym >= XK_Cyrillic_yu && sym <= XK_Cyrillic_hardsign)
242 *upper += (XK_Cyrillic_YU - XK_Cyrillic_yu);
243 break;
244 case 7: /* Greek */
245 /* Assume the KeySym is a legal value (ignore discontinuities) */
246 if (sym >= XK_Greek_ALPHAaccent && sym <= XK_Greek_OMEGAaccent)
247 *lower += (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
248 else if (sym >= XK_Greek_alphaaccent && sym <= XK_Greek_omegaaccent &&
249 sym != XK_Greek_iotaaccentdieresis && sym != XK_Greek_upsilonaccentdieresis)
250 *upper -= (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
251 else if (sym >= XK_Greek_ALPHA && sym <= XK_Greek_OMEGA)
252 *lower += (XK_Greek_alpha - XK_Greek_ALPHA);
253 else if (sym >= XK_Greek_alpha && sym <= XK_Greek_omega && sym != XK_Greek_finalsmallsigma)
254 *upper -= (XK_Greek_alpha - XK_Greek_ALPHA);
255 break;
256 case 0x14: /* Armenian */
257 if (sym >= XK_Armenian_AYB && sym <= XK_Armenian_fe) {
258 *lower = sym | 1;
259 *upper = sym & ~1;
261 break;
264 #endif
266 static int NumLockMask(Display *dpy)
268 int i, mask;
269 XModifierKeymap *map;
270 static int mask_table[8] = {
271 ShiftMask, LockMask, ControlMask, Mod1Mask,
272 Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
274 KeyCode numlock_keycode = XKeysymToKeycode(dpy, XK_Num_Lock);
276 if (numlock_keycode == NoSymbol)
277 return 0;
279 map = XGetModifierMapping(dpy);
280 if (!map)
281 return 0;
283 mask = 0;
284 for (i = 0; i < 8 * map->max_keypermod; i++) {
285 if (map->modifiermap[i] == numlock_keycode && mask == 0) {
286 mask = mask_table[i/map->max_keypermod];
287 break;
291 if (map)
292 XFreeModifiermap(map);
294 return mask;
297 char *capture_shortcut(Display *dpy, Bool *capturing, Bool convert_case)
299 XEvent ev;
300 KeySym ksym, lksym, uksym;
301 char buffer[64];
302 char *key = NULL;
303 unsigned int numlock_mask;
305 while (*capturing) {
306 XAllowEvents(dpy, AsyncKeyboard, CurrentTime);
307 WMNextEvent(dpy, &ev);
308 if (ev.type == KeyPress && ev.xkey.keycode != 0) {
309 numlock_mask = NumLockMask(dpy);
311 if (xext_xkb_supported)
312 /* conditional mask check to get numeric keypad keys */
313 ksym = XkbKeycodeToKeysym(dpy, ev.xkey.keycode, 0, ev.xkey.state & numlock_mask?1:0);
314 else
315 ksym = XKeycodeToKeysym(dpy, ev.xkey.keycode, 0);
317 if (!IsModifierKey(ksym)) {
318 if (convert_case) {
319 XConvertCase(ksym, &lksym, &uksym);
320 key = XKeysymToString(uksym);
321 } else {
322 key = XKeysymToString(ksym);
325 *capturing = 0;
326 break;
329 WMHandleEvent(&ev);
332 if (!key)
333 return NULL;
335 buffer[0] = 0;
337 if (ev.xkey.state & ControlMask)
338 strcat(buffer, "Control+");
340 if (ev.xkey.state & ShiftMask)
341 strcat(buffer, "Shift+");
343 if ((numlock_mask != Mod1Mask) && (ev.xkey.state & Mod1Mask))
344 strcat(buffer, "Mod1+");
346 if ((numlock_mask != Mod2Mask) && (ev.xkey.state & Mod2Mask))
347 strcat(buffer, "Mod2+");
349 if ((numlock_mask != Mod3Mask) && (ev.xkey.state & Mod3Mask))
350 strcat(buffer, "Mod3+");
352 if ((numlock_mask != Mod4Mask) && (ev.xkey.state & Mod4Mask))
353 strcat(buffer, "Mod4+");
355 if ((numlock_mask != Mod5Mask) && (ev.xkey.state & Mod5Mask))
356 strcat(buffer, "Mod5+");
358 strcat(buffer, key);
360 return wstrdup(buffer);
363 static void captureClick(WMWidget * w, void *data)
365 _Panel *panel = (_Panel *) data;
366 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->parent));
367 char *shortcut;
369 if (!panel->capturing) {
370 panel->capturing = 1;
371 WMSetButtonText(w, _("Cancel"));
372 WMSetLabelText(panel->instructionsL,
373 _("Press the desired shortcut key(s) or click Cancel to stop capturing."));
374 XGrabKeyboard(dpy, WMWidgetXID(panel->parent), True, GrabModeAsync, GrabModeAsync, CurrentTime);
375 shortcut = capture_shortcut(dpy, &panel->capturing, 1);
376 if (shortcut) {
377 int row = WMGetListSelectedItemRow(panel->actLs);
379 WMSetTextFieldText(panel->shoT, shortcut);
380 if (row >= 0) {
381 if (panel->shortcuts[row])
382 wfree(panel->shortcuts[row]);
383 panel->shortcuts[row] = shortcut;
385 WMRedisplayWidget(panel->actLs);
386 } else {
387 wfree(shortcut);
391 panel->capturing = 0;
392 WMSetButtonText(w, _("Capture"));
393 WMSetLabelText(panel->instructionsL, _("Click on Capture to interactively define the shortcut key."));
394 XUngrabKeyboard(dpy, CurrentTime);
397 static void clearShortcut(WMWidget * w, void *data)
399 _Panel *panel = (_Panel *) data;
400 int row = WMGetListSelectedItemRow(panel->actLs);
402 /* Parameter not used, but tell the compiler that it is ok */
403 (void) w;
405 WMSetTextFieldText(panel->shoT, NULL);
407 if (row >= 0) {
408 if (panel->shortcuts[row])
409 wfree(panel->shortcuts[row]);
410 panel->shortcuts[row] = NULL;
411 WMRedisplayWidget(panel->actLs);
415 static void typedKeys(void *observerData, WMNotification * notification)
417 _Panel *panel = (_Panel *) observerData;
418 int row = WMGetListSelectedItemRow(panel->actLs);
420 /* Parameter not used, but tell the compiler that it is ok */
421 (void) notification;
423 if (row < 0)
424 return;
426 if (panel->shortcuts[row])
427 wfree(panel->shortcuts[row]);
428 panel->shortcuts[row] = WMGetTextFieldText(panel->shoT);
429 if (strlen(panel->shortcuts[row]) == 0) {
430 wfree(panel->shortcuts[row]);
431 panel->shortcuts[row] = NULL;
433 WMRedisplayWidget(panel->actLs);
436 static void listClick(WMWidget * w, void *data)
438 _Panel *panel = (_Panel *) data;
439 int row = WMGetListSelectedItemRow(w);
441 WMSetTextFieldText(panel->shoT, panel->shortcuts[row]);
444 static void showData(_Panel * panel)
446 char *str;
447 int i;
449 for (i = 0; i < panel->actionCount; i++) {
451 str = GetStringForKey(keyOptions[i].key);
452 if (panel->shortcuts[i])
453 wfree(panel->shortcuts[i]);
454 if (str)
455 panel->shortcuts[i] = wtrimspace(str);
456 else
457 panel->shortcuts[i] = NULL;
459 if (panel->shortcuts[i] &&
460 (strcasecmp(panel->shortcuts[i], "none") == 0 || strlen(panel->shortcuts[i]) == 0)) {
461 wfree(panel->shortcuts[i]);
462 panel->shortcuts[i] = NULL;
465 WMRedisplayWidget(panel->actLs);
468 static void paintItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
470 int width, height, x, y;
471 _Panel *panel = (_Panel *) WMGetHangedData(lPtr);
472 WMScreen *scr = WMWidgetScreen(lPtr);
473 Display *dpy = WMScreenDisplay(scr);
474 WMColor *backColor = (state & WLDSSelected) ? panel->white : panel->gray;
476 width = rect->size.width;
477 height = rect->size.height;
478 x = rect->pos.x;
479 y = rect->pos.y;
481 XFillRectangle(dpy, d, WMColorGC(backColor), x, y, width, height);
483 if (panel->shortcuts[index]) {
484 WMPixmap *pix = WMGetSystemPixmap(scr, WSICheckMark);
485 WMSize size = WMGetPixmapSize(pix);
487 WMDrawPixmap(pix, d, x + (20 - size.width) / 2, (height - size.height) / 2 + y);
488 WMReleasePixmap(pix);
491 WMDrawString(scr, d, panel->black, panel->font, x + 20, y, text, strlen(text));
494 static void createPanel(Panel * p)
496 _Panel *panel = (_Panel *) p;
497 WMScreen *scr = WMWidgetScreen(panel->parent);
498 WMColor *color;
499 WMFont *boldFont;
500 int i;
502 panel->capturing = 0;
504 panel->white = WMWhiteColor(scr);
505 panel->black = WMBlackColor(scr);
506 panel->gray = WMGrayColor(scr);
507 panel->font = WMSystemFontOfSize(scr, 12);
509 panel->box = WMCreateBox(panel->parent);
510 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
512 boldFont = WMBoldSystemFontOfSize(scr, 12);
514 /* **************** Actions **************** */
515 panel->actL = WMCreateLabel(panel->box);
516 WMResizeWidget(panel->actL, 280, 20);
517 WMMoveWidget(panel->actL, 20, 10);
518 WMSetLabelFont(panel->actL, boldFont);
519 WMSetLabelText(panel->actL, _("Actions"));
520 WMSetLabelRelief(panel->actL, WRSunken);
521 WMSetLabelTextAlignment(panel->actL, WACenter);
522 color = WMDarkGrayColor(scr);
523 WMSetWidgetBackgroundColor(panel->actL, color);
524 WMReleaseColor(color);
525 WMSetLabelTextColor(panel->actL, panel->white);
527 panel->actLs = WMCreateList(panel->box);
528 WMResizeWidget(panel->actLs, 280, 190);
529 WMMoveWidget(panel->actLs, 20, 32);
530 WMSetListUserDrawProc(panel->actLs, paintItem);
531 WMHangData(panel->actLs, panel);
533 for (i = 0; i < wlengthof(keyOptions); i++) {
534 WMAddListItem(panel->actLs, _(keyOptions[i].title));
536 WMSetListAction(panel->actLs, listClick, panel);
538 panel->actionCount = WMGetListNumberOfRows(panel->actLs);
539 panel->shortcuts = wmalloc(sizeof(char *) * panel->actionCount);
541 /***************** Shortcut ****************/
543 panel->shoF = WMCreateFrame(panel->box);
544 WMResizeWidget(panel->shoF, 190, 210);
545 WMMoveWidget(panel->shoF, 315, 10);
546 WMSetFrameTitle(panel->shoF, _("Shortcut"));
548 panel->shoT = WMCreateTextField(panel->shoF);
549 WMResizeWidget(panel->shoT, 160, 20);
550 WMMoveWidget(panel->shoT, 15, 65);
551 WMAddNotificationObserver(typedKeys, panel, WMTextDidChangeNotification, panel->shoT);
553 panel->cleB = WMCreateCommandButton(panel->shoF);
554 WMResizeWidget(panel->cleB, 75, 24);
555 WMMoveWidget(panel->cleB, 15, 95);
556 WMSetButtonText(panel->cleB, _("Clear"));
557 WMSetButtonAction(panel->cleB, clearShortcut, panel);
559 panel->defB = WMCreateCommandButton(panel->shoF);
560 WMResizeWidget(panel->defB, 75, 24);
561 WMMoveWidget(panel->defB, 100, 95);
562 WMSetButtonText(panel->defB, _("Capture"));
563 WMSetButtonAction(panel->defB, captureClick, panel);
565 panel->instructionsL = WMCreateLabel(panel->shoF);
566 WMResizeWidget(panel->instructionsL, 160, 55);
567 WMMoveWidget(panel->instructionsL, 15, 140);
568 WMSetLabelTextAlignment(panel->instructionsL, WACenter);
569 WMSetLabelWraps(panel->instructionsL, True);
570 WMSetLabelText(panel->instructionsL, _("Click on Capture to interactively define the shortcut key."));
572 WMMapSubwidgets(panel->shoF);
574 WMReleaseFont(boldFont);
576 WMRealizeWidget(panel->box);
577 WMMapSubwidgets(panel->box);
579 showData(panel);
582 static void storeData(_Panel * panel)
584 int i;
585 char *str;
587 for (i = 0; i < panel->actionCount; i++) {
588 str = NULL;
589 if (panel->shortcuts[i]) {
590 str = wtrimspace(panel->shortcuts[i]);
591 if (strlen(str) == 0) {
592 wfree(str);
593 str = NULL;
596 if (str) {
597 SetStringForKey(str, keyOptions[i].key);
598 wfree(str);
599 } else {
600 SetStringForKey("None", keyOptions[i].key);
605 Panel *InitKeyboardShortcuts(WMWidget *parent)
607 _Panel *panel;
609 panel = wmalloc(sizeof(_Panel));
611 panel->sectionName = _("Keyboard Shortcut Preferences");
613 panel->description = _("Change the keyboard shortcuts for actions such\n"
614 "as changing workspaces and opening menus.");
616 panel->parent = parent;
618 panel->callbacks.createWidgets = createPanel;
619 panel->callbacks.updateDomain = storeData;
621 AddSection(panel, ICON_FILE);
623 return panel;