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 */
27 #include <X11/keysym.h>
28 #include <X11/XKBlib.h>
30 typedef struct _Panel
{
37 CallbackRec callbacks
;
49 WMLabel
*instructionsL
;
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 struct keyOption
{
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 { "KeepOnTopKey", N_("Toggle window on top status") },
93 { "KeepAtBottomKey",N_("Toggle window at bottom status") },
94 { "OmnipresentKey", N_("Toggle window omnipresent status") },
95 { "RaiseKey", N_("Raise active window") },
96 { "LowerKey", N_("Lower active window") },
97 { "RaiseLowerKey", N_("Raise/Lower window under mouse pointer") },
98 { "ShadeKey", N_("Shade active window") },
99 { "MoveResizeKey", N_("Move/Resize active window") },
100 { "SelectKey", N_("Select active window") },
101 { "FocusNextKey", N_("Focus next window") },
102 { "FocusPrevKey", N_("Focus previous window") },
103 { "GroupNextKey", N_("Focus next group window") },
104 { "GroupPrevKey", N_("Focus previous group window") },
106 /* Workspace Related */
107 { "WorkspaceMapKey", N_("Open workspace pager") },
108 { "NextWorkspaceKey", N_("Switch to next workspace") },
109 { "PrevWorkspaceKey", N_("Switch to previous workspace") },
110 { "LastWorkspaceKey", N_("Switch to last used workspace") },
111 { "NextWorkspaceLayerKey", N_("Switch to next ten workspaces") },
112 { "PrevWorkspaceLayerKey", N_("Switch to previous ten workspaces") },
113 { "Workspace1Key", N_("Switch to workspace 1") },
114 { "Workspace2Key", N_("Switch to workspace 2") },
115 { "Workspace3Key", N_("Switch to workspace 3") },
116 { "Workspace4Key", N_("Switch to workspace 4") },
117 { "Workspace5Key", N_("Switch to workspace 5") },
118 { "Workspace6Key", N_("Switch to workspace 6") },
119 { "Workspace7Key", N_("Switch to workspace 7") },
120 { "Workspace8Key", N_("Switch to workspace 8") },
121 { "Workspace9Key", N_("Switch to workspace 9") },
122 { "Workspace10Key", N_("Switch to workspace 10") },
123 { "MoveToNextWorkspaceKey", N_("Move window to next workspace") },
124 { "MoveToPrevWorkspaceKey", N_("Move window to previous workspace") },
125 { "MoveToLastWorkspaceKey", N_("Move window to last used workspace") },
126 { "MoveToNextWorkspaceLayerKey", N_("Move window to next ten workspaces") },
127 { "MoveToPrevWorkspaceLayerKey", N_("Move window to previous ten workspaces") },
128 { "MoveToWorkspace1Key", N_("Move window to workspace 1") },
129 { "MoveToWorkspace2Key", N_("Move window to workspace 2") },
130 { "MoveToWorkspace3Key", N_("Move window to workspace 3") },
131 { "MoveToWorkspace4Key", N_("Move window to workspace 4") },
132 { "MoveToWorkspace5Key", N_("Move window to workspace 5") },
133 { "MoveToWorkspace6Key", N_("Move window to workspace 6") },
134 { "MoveToWorkspace7Key", N_("Move window to workspace 7") },
135 { "MoveToWorkspace8Key", N_("Move window to workspace 8") },
136 { "MoveToWorkspace9Key", N_("Move window to workspace 9") },
137 { "MoveToWorkspace10Key", N_("Move window to workspace 10") },
139 /* Window Selection */
140 { "WindowShortcut1Key", N_("Shortcut for window 1") },
141 { "WindowShortcut2Key", N_("Shortcut for window 2") },
142 { "WindowShortcut3Key", N_("Shortcut for window 3") },
143 { "WindowShortcut4Key", N_("Shortcut for window 4") },
144 { "WindowShortcut5Key", N_("Shortcut for window 5") },
145 { "WindowShortcut6Key", N_("Shortcut for window 6") },
146 { "WindowShortcut7Key", N_("Shortcut for window 7") },
147 { "WindowShortcut8Key", N_("Shortcut for window 8") },
148 { "WindowShortcut9Key", N_("Shortcut for window 9") },
149 { "WindowShortcut10Key", N_("Shortcut for window 10") },
152 { "MoveTo12to6Head", N_("Move to right/bottom/left/top head") },
153 { "MoveTo6to12Head", N_("Move to left/top/right/bottom head") },
156 { "WindowRelaunchKey", N_("Launch new instance of application") },
157 { "ScreenSwitchKey", N_("Switch to Next Screen/Monitor") },
158 { "RunKey", N_("Run application") },
159 { "ExitKey", N_("Exit Window Maker") },
160 { "DockRaiseLowerKey", N_("Raise/Lower Dock") },
161 { "ClipRaiseLowerKey", N_("Raise/Lower Clip") },
162 { "ScreenCaptureKey", N_("Capture the entire screen") },
163 { "WindowCaptureKey", N_("Capture a window") },
164 { "PartialCaptureKey", N_("Capture a portion of the screen") }
166 ,{ "ToggleKbdModeKey", N_("Toggle keyboard language") }
167 #endif /* XKB_MODELOCK */
170 #ifndef HAVE_XCONVERTCASE
173 static void XConvertCase(register KeySym sym
, KeySym
* lower
, KeySym
* upper
)
178 case 0: /* Latin 1 */
179 if ((sym
>= XK_A
) && (sym
<= XK_Z
))
180 *lower
+= (XK_a
- XK_A
);
181 else if ((sym
>= XK_a
) && (sym
<= XK_z
))
182 *upper
-= (XK_a
- XK_A
);
183 else if ((sym
>= XK_Agrave
) && (sym
<= XK_Odiaeresis
))
184 *lower
+= (XK_agrave
- XK_Agrave
);
185 else if ((sym
>= XK_agrave
) && (sym
<= XK_odiaeresis
))
186 *upper
-= (XK_agrave
- XK_Agrave
);
187 else if ((sym
>= XK_Ooblique
) && (sym
<= XK_Thorn
))
188 *lower
+= (XK_oslash
- XK_Ooblique
);
189 else if ((sym
>= XK_oslash
) && (sym
<= XK_thorn
))
190 *upper
-= (XK_oslash
- XK_Ooblique
);
192 case 1: /* Latin 2 */
193 /* Assume the KeySym is a legal value (ignore discontinuities) */
194 if (sym
== XK_Aogonek
)
196 else if (sym
>= XK_Lstroke
&& sym
<= XK_Sacute
)
197 *lower
+= (XK_lstroke
- XK_Lstroke
);
198 else if (sym
>= XK_Scaron
&& sym
<= XK_Zacute
)
199 *lower
+= (XK_scaron
- XK_Scaron
);
200 else if (sym
>= XK_Zcaron
&& sym
<= XK_Zabovedot
)
201 *lower
+= (XK_zcaron
- XK_Zcaron
);
202 else if (sym
== XK_aogonek
)
204 else if (sym
>= XK_lstroke
&& sym
<= XK_sacute
)
205 *upper
-= (XK_lstroke
- XK_Lstroke
);
206 else if (sym
>= XK_scaron
&& sym
<= XK_zacute
)
207 *upper
-= (XK_scaron
- XK_Scaron
);
208 else if (sym
>= XK_zcaron
&& sym
<= XK_zabovedot
)
209 *upper
-= (XK_zcaron
- XK_Zcaron
);
210 else if (sym
>= XK_Racute
&& sym
<= XK_Tcedilla
)
211 *lower
+= (XK_racute
- XK_Racute
);
212 else if (sym
>= XK_racute
&& sym
<= XK_tcedilla
)
213 *upper
-= (XK_racute
- XK_Racute
);
215 case 2: /* Latin 3 */
216 /* Assume the KeySym is a legal value (ignore discontinuities) */
217 if (sym
>= XK_Hstroke
&& sym
<= XK_Hcircumflex
)
218 *lower
+= (XK_hstroke
- XK_Hstroke
);
219 else if (sym
>= XK_Gbreve
&& sym
<= XK_Jcircumflex
)
220 *lower
+= (XK_gbreve
- XK_Gbreve
);
221 else if (sym
>= XK_hstroke
&& sym
<= XK_hcircumflex
)
222 *upper
-= (XK_hstroke
- XK_Hstroke
);
223 else if (sym
>= XK_gbreve
&& sym
<= XK_jcircumflex
)
224 *upper
-= (XK_gbreve
- XK_Gbreve
);
225 else if (sym
>= XK_Cabovedot
&& sym
<= XK_Scircumflex
)
226 *lower
+= (XK_cabovedot
- XK_Cabovedot
);
227 else if (sym
>= XK_cabovedot
&& sym
<= XK_scircumflex
)
228 *upper
-= (XK_cabovedot
- XK_Cabovedot
);
230 case 3: /* Latin 4 */
231 /* Assume the KeySym is a legal value (ignore discontinuities) */
232 if (sym
>= XK_Rcedilla
&& sym
<= XK_Tslash
)
233 *lower
+= (XK_rcedilla
- XK_Rcedilla
);
234 else if (sym
>= XK_rcedilla
&& sym
<= XK_tslash
)
235 *upper
-= (XK_rcedilla
- XK_Rcedilla
);
236 else if (sym
== XK_ENG
)
238 else if (sym
== XK_eng
)
240 else if (sym
>= XK_Amacron
&& sym
<= XK_Umacron
)
241 *lower
+= (XK_amacron
- XK_Amacron
);
242 else if (sym
>= XK_amacron
&& sym
<= XK_umacron
)
243 *upper
-= (XK_amacron
- XK_Amacron
);
245 case 6: /* Cyrillic */
246 /* Assume the KeySym is a legal value (ignore discontinuities) */
247 if (sym
>= XK_Serbian_DJE
&& sym
<= XK_Serbian_DZE
)
248 *lower
-= (XK_Serbian_DJE
- XK_Serbian_dje
);
249 else if (sym
>= XK_Serbian_dje
&& sym
<= XK_Serbian_dze
)
250 *upper
+= (XK_Serbian_DJE
- XK_Serbian_dje
);
251 else if (sym
>= XK_Cyrillic_YU
&& sym
<= XK_Cyrillic_HARDSIGN
)
252 *lower
-= (XK_Cyrillic_YU
- XK_Cyrillic_yu
);
253 else if (sym
>= XK_Cyrillic_yu
&& sym
<= XK_Cyrillic_hardsign
)
254 *upper
+= (XK_Cyrillic_YU
- XK_Cyrillic_yu
);
257 /* Assume the KeySym is a legal value (ignore discontinuities) */
258 if (sym
>= XK_Greek_ALPHAaccent
&& sym
<= XK_Greek_OMEGAaccent
)
259 *lower
+= (XK_Greek_alphaaccent
- XK_Greek_ALPHAaccent
);
260 else if (sym
>= XK_Greek_alphaaccent
&& sym
<= XK_Greek_omegaaccent
&&
261 sym
!= XK_Greek_iotaaccentdieresis
&& sym
!= XK_Greek_upsilonaccentdieresis
)
262 *upper
-= (XK_Greek_alphaaccent
- XK_Greek_ALPHAaccent
);
263 else if (sym
>= XK_Greek_ALPHA
&& sym
<= XK_Greek_OMEGA
)
264 *lower
+= (XK_Greek_alpha
- XK_Greek_ALPHA
);
265 else if (sym
>= XK_Greek_alpha
&& sym
<= XK_Greek_omega
&& sym
!= XK_Greek_finalsmallsigma
)
266 *upper
-= (XK_Greek_alpha
- XK_Greek_ALPHA
);
268 case 0x14: /* Armenian */
269 if (sym
>= XK_Armenian_AYB
&& sym
<= XK_Armenian_fe
) {
278 static int NumLockMask(Display
*dpy
)
281 XModifierKeymap
*map
;
282 static int mask_table
[8] = {
283 ShiftMask
, LockMask
, ControlMask
, Mod1Mask
,
284 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
286 KeyCode numlock_keycode
= XKeysymToKeycode(dpy
, XK_Num_Lock
);
288 if (numlock_keycode
== NoSymbol
)
291 map
= XGetModifierMapping(dpy
);
296 for (i
= 0; i
< 8 * map
->max_keypermod
; i
++) {
297 if (map
->modifiermap
[i
] == numlock_keycode
&& mask
== 0) {
298 mask
= mask_table
[i
/map
->max_keypermod
];
304 XFreeModifiermap(map
);
309 char *capture_shortcut(Display
*dpy
, Bool
*capturing
, Bool convert_case
)
312 KeySym ksym
, lksym
, uksym
;
315 unsigned int numlock_mask
;
318 XAllowEvents(dpy
, AsyncKeyboard
, CurrentTime
);
319 WMNextEvent(dpy
, &ev
);
320 if (ev
.type
== KeyPress
&& ev
.xkey
.keycode
!= 0) {
321 numlock_mask
= NumLockMask(dpy
);
323 /* conditional mask check to get numeric keypad keys */
324 ksym
= W_KeycodeToKeysym(dpy
, ev
.xkey
.keycode
, ev
.xkey
.state
& numlock_mask
?1:0);
326 if (!IsModifierKey(ksym
)) {
328 XConvertCase(ksym
, &lksym
, &uksym
);
329 key
= XKeysymToString(uksym
);
331 key
= XKeysymToString(ksym
);
346 if (ev
.xkey
.state
& ControlMask
)
347 strcat(buffer
, "Control+");
349 if (ev
.xkey
.state
& ShiftMask
)
350 strcat(buffer
, "Shift+");
352 if ((numlock_mask
!= Mod1Mask
) && (ev
.xkey
.state
& Mod1Mask
))
353 strcat(buffer
, "Mod1+");
355 if ((numlock_mask
!= Mod2Mask
) && (ev
.xkey
.state
& Mod2Mask
))
356 strcat(buffer
, "Mod2+");
358 if ((numlock_mask
!= Mod3Mask
) && (ev
.xkey
.state
& Mod3Mask
))
359 strcat(buffer
, "Mod3+");
361 if ((numlock_mask
!= Mod4Mask
) && (ev
.xkey
.state
& Mod4Mask
))
362 strcat(buffer
, "Mod4+");
364 if ((numlock_mask
!= Mod5Mask
) && (ev
.xkey
.state
& Mod5Mask
))
365 strcat(buffer
, "Mod5+");
367 wstrlcat(buffer
, key
, sizeof(buffer
));
369 return wstrdup(buffer
);
373 * check if the keystr entered is already set to another action
374 * if found it returns the position in the keyOptions
376 static int isKeySet(_Panel
*panel
, char *keystr
)
381 for (i
= 0; i
< panel
->actionCount
; i
++) {
383 if (panel
->shortcuts
[i
]) {
384 str
= wtrimspace(panel
->shortcuts
[i
]);
385 if (strlen(str
) == 0) {
391 if (strcmp(keystr
, str
) == 0) {
402 static void captureClick(WMWidget
* w
, void *data
)
404 _Panel
*panel
= (_Panel
*) data
;
405 Display
*dpy
= WMScreenDisplay(WMWidgetScreen(panel
->parent
));
408 if (!panel
->capturing
) {
409 panel
->capturing
= 1;
410 WMSetButtonText(w
, _("Cancel"));
411 WMSetLabelText(panel
->instructionsL
,
412 _("Press the desired shortcut key(s) or click Cancel to stop capturing."));
413 XGrabKeyboard(dpy
, WMWidgetXID(panel
->parent
), True
, GrabModeAsync
, GrabModeAsync
, CurrentTime
);
414 shortcut
= capture_shortcut(dpy
, &panel
->capturing
, 1);
417 int row
= WMGetListSelectedItemRow(panel
->actLs
);
419 key_idx
= isKeySet(panel
, shortcut
);
420 if (key_idx
>= 0 && (key_idx
!= row
)) {
423 msg
= wstrconcat(_("Key shortcut already in use by the "), _(keyOptions
[key_idx
].title
));
424 WMRunAlertPanel(WMWidgetScreen(w
), GetWindow(),
427 _("OK"), NULL
, NULL
);
431 WMSetTextFieldText(panel
->shoT
, shortcut
);
433 if (panel
->shortcuts
[row
])
434 wfree(panel
->shortcuts
[row
]);
435 panel
->shortcuts
[row
] = shortcut
;
437 WMRedisplayWidget(panel
->actLs
);
444 panel
->capturing
= 0;
445 WMSetButtonText(w
, _("Capture"));
446 WMSetLabelText(panel
->instructionsL
, _("Click on Capture to interactively define the shortcut key."));
447 XUngrabKeyboard(dpy
, CurrentTime
);
450 static void clearShortcut(WMWidget
* w
, void *data
)
452 _Panel
*panel
= (_Panel
*) data
;
453 int row
= WMGetListSelectedItemRow(panel
->actLs
);
455 /* Parameter not used, but tell the compiler that it is ok */
458 WMSetTextFieldText(panel
->shoT
, NULL
);
461 if (panel
->shortcuts
[row
])
462 wfree(panel
->shortcuts
[row
]);
463 panel
->shortcuts
[row
] = NULL
;
464 WMRedisplayWidget(panel
->actLs
);
468 static void typedKeys(void *observerData
, WMNotification
* notification
)
470 _Panel
*panel
= (_Panel
*) observerData
;
471 int row
= WMGetListSelectedItemRow(panel
->actLs
);
473 /* Parameter not used, but tell the compiler that it is ok */
479 if (panel
->shortcuts
[row
])
480 wfree(panel
->shortcuts
[row
]);
481 panel
->shortcuts
[row
] = WMGetTextFieldText(panel
->shoT
);
482 if (strlen(panel
->shortcuts
[row
]) == 0) {
483 wfree(panel
->shortcuts
[row
]);
484 panel
->shortcuts
[row
] = NULL
;
486 WMRedisplayWidget(panel
->actLs
);
489 static void listClick(WMWidget
* w
, void *data
)
491 _Panel
*panel
= (_Panel
*) data
;
492 int row
= WMGetListSelectedItemRow(w
);
494 WMSetTextFieldText(panel
->shoT
, panel
->shortcuts
[row
]);
497 static void showData(_Panel
* panel
)
502 for (i
= 0; i
< panel
->actionCount
; i
++) {
504 str
= GetStringForKey(keyOptions
[i
].key
);
505 if (panel
->shortcuts
[i
])
506 wfree(panel
->shortcuts
[i
]);
508 panel
->shortcuts
[i
] = wtrimspace(str
);
510 panel
->shortcuts
[i
] = NULL
;
512 if (panel
->shortcuts
[i
] &&
513 (strcasecmp(panel
->shortcuts
[i
], "none") == 0 || strlen(panel
->shortcuts
[i
]) == 0)) {
514 wfree(panel
->shortcuts
[i
]);
515 panel
->shortcuts
[i
] = NULL
;
518 WMRedisplayWidget(panel
->actLs
);
521 static void paintItem(WMList
* lPtr
, int index
, Drawable d
, char *text
, int state
, WMRect
* rect
)
523 int width
, height
, x
, y
;
524 _Panel
*panel
= (_Panel
*) WMGetHangedData(lPtr
);
525 WMScreen
*scr
= WMWidgetScreen(lPtr
);
526 Display
*dpy
= WMScreenDisplay(scr
);
527 WMColor
*backColor
= (state
& WLDSSelected
) ? panel
->white
: panel
->gray
;
529 width
= rect
->size
.width
;
530 height
= rect
->size
.height
;
534 XFillRectangle(dpy
, d
, WMColorGC(backColor
), x
, y
, width
, height
);
536 if (panel
->shortcuts
[index
]) {
537 WMPixmap
*pix
= WMGetSystemPixmap(scr
, WSICheckMark
);
538 WMSize size
= WMGetPixmapSize(pix
);
540 WMDrawPixmap(pix
, d
, x
+ (20 - size
.width
) / 2, (height
- size
.height
) / 2 + y
);
541 WMReleasePixmap(pix
);
544 WMDrawString(scr
, d
, panel
->black
, panel
->font
, x
+ 20, y
, text
, strlen(text
));
547 static int cmpKeyOptions(const void *v1
, const void *v2
)
550 const struct keyOption
*opt1
= (struct keyOption
*)v1
;
551 const struct keyOption
*opt2
= (struct keyOption
*)v2
;
553 if ((rc
= strcmp(opt1
->title
, opt2
->title
)) < 0)
561 static void createPanel(Panel
* p
)
563 _Panel
*panel
= (_Panel
*) p
;
564 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
569 panel
->capturing
= 0;
571 panel
->white
= WMWhiteColor(scr
);
572 panel
->black
= WMBlackColor(scr
);
573 panel
->gray
= WMGrayColor(scr
);
574 panel
->font
= WMSystemFontOfSize(scr
, 12);
576 panel
->box
= WMCreateBox(panel
->parent
);
577 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
579 boldFont
= WMBoldSystemFontOfSize(scr
, 12);
581 /* **************** Actions **************** */
582 panel
->actL
= WMCreateLabel(panel
->box
);
583 WMResizeWidget(panel
->actL
, 314, 20);
584 WMMoveWidget(panel
->actL
, 9, 9);
585 WMSetLabelFont(panel
->actL
, boldFont
);
586 WMSetLabelText(panel
->actL
, _("Actions"));
587 WMSetLabelRelief(panel
->actL
, WRSunken
);
588 WMSetLabelTextAlignment(panel
->actL
, WACenter
);
589 color
= WMDarkGrayColor(scr
);
590 WMSetWidgetBackgroundColor(panel
->actL
, color
);
591 WMReleaseColor(color
);
592 WMSetLabelTextColor(panel
->actL
, panel
->white
);
594 panel
->actLs
= WMCreateList(panel
->box
);
595 WMResizeWidget(panel
->actLs
, 314, 191);
596 WMMoveWidget(panel
->actLs
, 9, 31);
597 WMSetListUserDrawProc(panel
->actLs
, paintItem
);
598 WMHangData(panel
->actLs
, panel
);
600 qsort(keyOptions
, wlengthof(keyOptions
), sizeof(keyOptions
[0]), cmpKeyOptions
);
601 for (i
= 0; i
< wlengthof(keyOptions
); i
++) {
602 WMAddListItem(panel
->actLs
, _(keyOptions
[i
].title
));
604 WMSetListAction(panel
->actLs
, listClick
, panel
);
606 panel
->actionCount
= WMGetListNumberOfRows(panel
->actLs
);
607 panel
->shortcuts
= wmalloc(sizeof(char *) * panel
->actionCount
);
609 /***************** Shortcut ****************/
611 panel
->shoF
= WMCreateFrame(panel
->box
);
612 WMResizeWidget(panel
->shoF
, 178, 214);
613 WMMoveWidget(panel
->shoF
, 333, 8);
614 WMSetFrameTitle(panel
->shoF
, _("Shortcut"));
616 panel
->shoT
= WMCreateTextField(panel
->shoF
);
617 WMResizeWidget(panel
->shoT
, 160, 20);
618 WMMoveWidget(panel
->shoT
, 9, 65);
619 WMAddNotificationObserver(typedKeys
, panel
, WMTextDidChangeNotification
, panel
->shoT
);
621 panel
->cleB
= WMCreateCommandButton(panel
->shoF
);
622 WMResizeWidget(panel
->cleB
, 75, 24);
623 WMMoveWidget(panel
->cleB
, 9, 95);
624 WMSetButtonText(panel
->cleB
, _("Clear"));
625 WMSetButtonAction(panel
->cleB
, clearShortcut
, panel
);
627 panel
->defB
= WMCreateCommandButton(panel
->shoF
);
628 WMResizeWidget(panel
->defB
, 75, 24);
629 WMMoveWidget(panel
->defB
, 94, 95);
630 WMSetButtonText(panel
->defB
, _("Capture"));
631 WMSetButtonAction(panel
->defB
, captureClick
, panel
);
633 panel
->instructionsL
= WMCreateLabel(panel
->shoF
);
634 WMResizeWidget(panel
->instructionsL
, 160, 55);
635 WMMoveWidget(panel
->instructionsL
, 9, 140);
636 WMSetLabelTextAlignment(panel
->instructionsL
, WACenter
);
637 WMSetLabelWraps(panel
->instructionsL
, True
);
638 WMSetLabelText(panel
->instructionsL
, _("Click on Capture to interactively define the shortcut key."));
640 WMMapSubwidgets(panel
->shoF
);
642 WMReleaseFont(boldFont
);
644 WMRealizeWidget(panel
->box
);
645 WMMapSubwidgets(panel
->box
);
650 static void storeData(_Panel
* panel
)
655 for (i
= 0; i
< panel
->actionCount
; i
++) {
657 if (panel
->shortcuts
[i
]) {
658 str
= wtrimspace(panel
->shortcuts
[i
]);
659 if (strlen(str
) == 0) {
665 SetStringForKey(str
, keyOptions
[i
].key
);
668 SetStringForKey("None", keyOptions
[i
].key
);
673 Panel
*InitKeyboardShortcuts(WMWidget
*parent
)
677 panel
= wmalloc(sizeof(_Panel
));
679 panel
->sectionName
= _("Keyboard Shortcut Preferences");
681 panel
->description
= _("Change the keyboard shortcuts for actions such\n"
682 "as changing workspaces and opening menus.");
684 panel
->parent
= parent
;
686 panel
->callbacks
.createWidgets
= createPanel
;
687 panel
->callbacks
.updateDomain
= storeData
;
689 AddSection(panel
, ICON_FILE
);