Keyboard shortcut to raise the dock
[wmaker-crm.git] / WPrefs.app / KeyboardShortcuts.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/* KeyboardShortcuts.c- keyboard shortcut bindings
6830b057 dan2004-10-12 21:28:27 +00002 *
9af1c6c4 dan1998-10-21 14:43:47 +00003 * WPrefs - Window Maker Preferences Program
6830b057 dan2004-10-12 21:28:27 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 1998-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00006 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00007 * 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
6830b057 dan2004-10-12 21:28:27 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000020 * USA.
21 */
22
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020023#include "config.h" /* for HAVE_XCONVERTCASE */
5db8b566 kojima2002-02-15 21:34:46 +000024
9d2e6ef9 scottc1998-09-29 22:36:29 +000025#include "WPrefs.h"
26#include <ctype.h>
27
28#include <X11/keysym.h>
29
9d2e6ef9 scottc1998-09-29 22:36:29 +000030typedef struct _Panel {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020031 WMBox *box;
9d2e6ef9 scottc1998-09-29 22:36:29 +000032
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020033 char *sectionName;
d3f29988 kojima1999-04-25 01:49:46 +000034
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020035 char *description;
d3f29988 kojima1999-04-25 01:49:46 +000036
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020037 CallbackRec callbacks;
9d2e6ef9 scottc1998-09-29 22:36:29 +000038
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020039 WMWidget *parent;
9d2e6ef9 scottc1998-09-29 22:36:29 +000040
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020041 WMLabel *actL;
42 WMList *actLs;
6830b057 dan2004-10-12 21:28:27 +000043
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020044 WMFrame *shoF;
45 WMTextField *shoT;
46 WMButton *cleB;
47 WMButton *defB;
9d2e6ef9 scottc1998-09-29 22:36:29 +000048
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020049 WMLabel *instructionsL;
0261c326 dan1999-01-06 15:22:33 +000050
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020051 WMColor *white;
52 WMColor *black;
53 WMColor *gray;
54 WMFont *font;
0261c326 dan1999-01-06 15:22:33 +000055
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020056 /**/ char capturing;
57 char **shortcuts;
58 int actionCount;
9d2e6ef9 scottc1998-09-29 22:36:29 +000059} _Panel;
60
9d2e6ef9 scottc1998-09-29 22:36:29 +000061#define ICON_FILE "keyshortcuts"
62
9d2e6ef9 scottc1998-09-29 22:36:29 +000063/* must be in the same order as the corresponding items in actions list */
64static char *keyOptions[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020065 "RootMenuKey",
66 "WindowListKey",
67 "WindowMenuKey",
68 "HideKey",
69 "HideOthersKey",
70 "MiniaturizeKey",
71 "CloseKey",
72 "MaximizeKey",
73 "VMaximizeKey",
74 "HMaximizeKey",
69244548
JH
Johann Haarhoff2009-08-28 21:31:26 +020075 "LHMaximizeKey",
76 "RHMaximizeKey",
9789cf31 Carlos R. Mafra2009-09-14 16:34:37 +020077 "MaximusKey",
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020078 "RaiseKey",
79 "LowerKey",
80 "RaiseLowerKey",
81 "ShadeKey",
82 "MoveResizeKey",
83 "SelectKey",
84 "FocusNextKey",
85 "FocusPrevKey",
18408fff
IP
Iain Patterson2009-09-14 14:37:15 +010086 "GroupNextKey",
87 "GroupPrevKey",
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020088 "NextWorkspaceKey",
89 "PrevWorkspaceKey",
90 "NextWorkspaceLayerKey",
91 "PrevWorkspaceLayerKey",
92 "Workspace1Key",
93 "Workspace2Key",
94 "Workspace3Key",
95 "Workspace4Key",
96 "Workspace5Key",
97 "Workspace6Key",
98 "Workspace7Key",
99 "Workspace8Key",
100 "Workspace9Key",
101 "Workspace10Key",
102 "WindowShortcut1Key",
103 "WindowShortcut2Key",
104 "WindowShortcut3Key",
105 "WindowShortcut4Key",
106 "WindowShortcut5Key",
107 "WindowShortcut6Key",
108 "WindowShortcut7Key",
109 "WindowShortcut8Key",
110 "WindowShortcut9Key",
111 "WindowShortcut10Key",
112 "ScreenSwitchKey",
9aca0d5f dan2004-10-12 01:34:32 +0000113#ifdef VIRTUAL_DESKTOP
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200114 "VirtualEdgeLeftKey",
115 "VirtualEdgeRightKey",
116 "VirtualEdgeUpKey",
117 "VirtualEdgeDownKey",
9aca0d5f dan2004-10-12 01:34:32 +0000118#endif
b6689a01 Brad Jorsch2010-01-06 12:50:36 -0500119 "DockRaiseLowerKey",
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200120 "ClipRaiseKey",
121 "ClipLowerKey",
59eb9475 dan1998-11-03 12:53:26 +0000122#ifndef XKB_MODELOCK
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200123 "ClipRaiseLowerKey"
59eb9475 dan1998-11-03 12:53:26 +0000124#else
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200125 "ClipRaiseLowerKey",
126 "ToggleKbdModeKey"
127#endif /* XKB_MODELOCK */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000128};
129
5db8b566 kojima2002-02-15 21:34:46 +0000130#ifndef HAVE_XCONVERTCASE
131/* from Xlib */
132
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200133static void XConvertCase(register KeySym sym, KeySym * lower, KeySym * upper)
5db8b566 kojima2002-02-15 21:34:46 +0000134{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200135 *lower = sym;
136 *upper = sym;
137 switch (sym >> 8) {
138 case 0: /* Latin 1 */
139 if ((sym >= XK_A) && (sym <= XK_Z))
140 *lower += (XK_a - XK_A);
141 else if ((sym >= XK_a) && (sym <= XK_z))
142 *upper -= (XK_a - XK_A);
143 else if ((sym >= XK_Agrave) && (sym <= XK_Odiaeresis))
144 *lower += (XK_agrave - XK_Agrave);
145 else if ((sym >= XK_agrave) && (sym <= XK_odiaeresis))
146 *upper -= (XK_agrave - XK_Agrave);
147 else if ((sym >= XK_Ooblique) && (sym <= XK_Thorn))
148 *lower += (XK_oslash - XK_Ooblique);
149 else if ((sym >= XK_oslash) && (sym <= XK_thorn))
150 *upper -= (XK_oslash - XK_Ooblique);
151 break;
152 case 1: /* Latin 2 */
153 /* Assume the KeySym is a legal value (ignore discontinuities) */
154 if (sym == XK_Aogonek)
155 *lower = XK_aogonek;
156 else if (sym >= XK_Lstroke && sym <= XK_Sacute)
157 *lower += (XK_lstroke - XK_Lstroke);
158 else if (sym >= XK_Scaron && sym <= XK_Zacute)
159 *lower += (XK_scaron - XK_Scaron);
160 else if (sym >= XK_Zcaron && sym <= XK_Zabovedot)
161 *lower += (XK_zcaron - XK_Zcaron);
162 else if (sym == XK_aogonek)
163 *upper = XK_Aogonek;
164 else if (sym >= XK_lstroke && sym <= XK_sacute)
165 *upper -= (XK_lstroke - XK_Lstroke);
166 else if (sym >= XK_scaron && sym <= XK_zacute)
167 *upper -= (XK_scaron - XK_Scaron);
168 else if (sym >= XK_zcaron && sym <= XK_zabovedot)
169 *upper -= (XK_zcaron - XK_Zcaron);
170 else if (sym >= XK_Racute && sym <= XK_Tcedilla)
171 *lower += (XK_racute - XK_Racute);
172 else if (sym >= XK_racute && sym <= XK_tcedilla)
173 *upper -= (XK_racute - XK_Racute);
174 break;
175 case 2: /* Latin 3 */
176 /* Assume the KeySym is a legal value (ignore discontinuities) */
177 if (sym >= XK_Hstroke && sym <= XK_Hcircumflex)
178 *lower += (XK_hstroke - XK_Hstroke);
179 else if (sym >= XK_Gbreve && sym <= XK_Jcircumflex)
180 *lower += (XK_gbreve - XK_Gbreve);
181 else if (sym >= XK_hstroke && sym <= XK_hcircumflex)
182 *upper -= (XK_hstroke - XK_Hstroke);
183 else if (sym >= XK_gbreve && sym <= XK_jcircumflex)
184 *upper -= (XK_gbreve - XK_Gbreve);
185 else if (sym >= XK_Cabovedot && sym <= XK_Scircumflex)
186 *lower += (XK_cabovedot - XK_Cabovedot);
187 else if (sym >= XK_cabovedot && sym <= XK_scircumflex)
188 *upper -= (XK_cabovedot - XK_Cabovedot);
189 break;
190 case 3: /* Latin 4 */
191 /* Assume the KeySym is a legal value (ignore discontinuities) */
192 if (sym >= XK_Rcedilla && sym <= XK_Tslash)
193 *lower += (XK_rcedilla - XK_Rcedilla);
194 else if (sym >= XK_rcedilla && sym <= XK_tslash)
195 *upper -= (XK_rcedilla - XK_Rcedilla);
196 else if (sym == XK_ENG)
197 *lower = XK_eng;
198 else if (sym == XK_eng)
199 *upper = XK_ENG;
200 else if (sym >= XK_Amacron && sym <= XK_Umacron)
201 *lower += (XK_amacron - XK_Amacron);
202 else if (sym >= XK_amacron && sym <= XK_umacron)
203 *upper -= (XK_amacron - XK_Amacron);
204 break;
205 case 6: /* Cyrillic */
206 /* Assume the KeySym is a legal value (ignore discontinuities) */
207 if (sym >= XK_Serbian_DJE && sym <= XK_Serbian_DZE)
208 *lower -= (XK_Serbian_DJE - XK_Serbian_dje);
209 else if (sym >= XK_Serbian_dje && sym <= XK_Serbian_dze)
210 *upper += (XK_Serbian_DJE - XK_Serbian_dje);
211 else if (sym >= XK_Cyrillic_YU && sym <= XK_Cyrillic_HARDSIGN)
212 *lower -= (XK_Cyrillic_YU - XK_Cyrillic_yu);
213 else if (sym >= XK_Cyrillic_yu && sym <= XK_Cyrillic_hardsign)
214 *upper += (XK_Cyrillic_YU - XK_Cyrillic_yu);
215 break;
216 case 7: /* Greek */
217 /* Assume the KeySym is a legal value (ignore discontinuities) */
218 if (sym >= XK_Greek_ALPHAaccent && sym <= XK_Greek_OMEGAaccent)
219 *lower += (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
220 else if (sym >= XK_Greek_alphaaccent && sym <= XK_Greek_omegaaccent &&
221 sym != XK_Greek_iotaaccentdieresis && sym != XK_Greek_upsilonaccentdieresis)
222 *upper -= (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
223 else if (sym >= XK_Greek_ALPHA && sym <= XK_Greek_OMEGA)
224 *lower += (XK_Greek_alpha - XK_Greek_ALPHA);
225 else if (sym >= XK_Greek_alpha && sym <= XK_Greek_omega && sym != XK_Greek_finalsmallsigma)
226 *upper -= (XK_Greek_alpha - XK_Greek_ALPHA);
227 break;
228 case 0x14: /* Armenian */
229 if (sym >= XK_Armenian_AYB && sym <= XK_Armenian_fe) {
230 *lower = sym | 1;
231 *upper = sym & ~1;
232 }
233 break;
234 }
5db8b566 kojima2002-02-15 21:34:46 +0000235}
236#endif
237
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200238static char *captureShortcut(Display * dpy, _Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000239{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200240 XEvent ev;
241 KeySym ksym, lksym, uksym;
242 char buffer[64];
243 char *key = NULL;
244
245 while (panel->capturing) {
246 XAllowEvents(dpy, AsyncKeyboard, CurrentTime);
247 WMNextEvent(dpy, &ev);
248 if (ev.type == KeyPress && ev.xkey.keycode != 0) {
249 ksym = XKeycodeToKeysym(dpy, ev.xkey.keycode, 0);
250 if (!IsModifierKey(ksym)) {
251 XConvertCase(ksym, &lksym, &uksym);
252 key = XKeysymToString(uksym);
253
254 panel->capturing = 0;
255 break;
256 }
257 }
258 WMHandleEvent(&ev);
259 }
260
261 if (!key)
262 return NULL;
263
264 buffer[0] = 0;
265
266 if (ev.xkey.state & ControlMask) {
267 strcat(buffer, "Control+");
268 }
269 if (ev.xkey.state & ShiftMask) {
270 strcat(buffer, "Shift+");
271 }
272 if (ev.xkey.state & Mod1Mask) {
273 strcat(buffer, "Mod1+");
274 }
275 if (ev.xkey.state & Mod2Mask) {
276 strcat(buffer, "Mod2+");
277 }
278 if (ev.xkey.state & Mod3Mask) {
279 strcat(buffer, "Mod3+");
280 }
281 if (ev.xkey.state & Mod4Mask) {
282 strcat(buffer, "Mod4+");
283 }
284 if (ev.xkey.state & Mod5Mask) {
285 strcat(buffer, "Mod5+");
286 }
287 strcat(buffer, key);
288
289 return wstrdup(buffer);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000290}
291
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200292static void captureClick(WMWidget * w, void *data)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000293{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200294 _Panel *panel = (_Panel *) data;
295 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->parent));
296 char *shortcut;
297
298 if (!panel->capturing) {
299 panel->capturing = 1;
300 WMSetButtonText(w, _("Cancel"));
301 WMSetLabelText(panel->instructionsL,
302 _("Press the desired shortcut key(s) or click Cancel to stop capturing."));
303 XGrabKeyboard(dpy, WMWidgetXID(panel->parent), True, GrabModeAsync, GrabModeAsync, CurrentTime);
304 shortcut = captureShortcut(dpy, panel);
305 if (shortcut) {
306 int row = WMGetListSelectedItemRow(panel->actLs);
307
308 WMSetTextFieldText(panel->shoT, shortcut);
309 if (row >= 0) {
310 if (panel->shortcuts[row])
311 wfree(panel->shortcuts[row]);
312 panel->shortcuts[row] = shortcut;
313
314 WMRedisplayWidget(panel->actLs);
315 } else {
316 wfree(shortcut);
317 }
318 }
319 }
320 panel->capturing = 0;
321 WMSetButtonText(w, _("Capture"));
322 WMSetLabelText(panel->instructionsL, _("Click on Capture to interactively define the shortcut key."));
323 XUngrabKeyboard(dpy, CurrentTime);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000324}
325
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200326static void clearShortcut(WMWidget * w, void *data)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000327{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200328 _Panel *panel = (_Panel *) data;
329 int row = WMGetListSelectedItemRow(panel->actLs);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000330
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200331 WMSetTextFieldText(panel->shoT, NULL);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000332
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200333 if (row >= 0) {
334 if (panel->shortcuts[row])
335 wfree(panel->shortcuts[row]);
336 panel->shortcuts[row] = NULL;
337 WMRedisplayWidget(panel->actLs);
338 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000339}
340
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200341static void typedKeys(void *observerData, WMNotification * notification)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000342{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200343 _Panel *panel = (_Panel *) observerData;
344 int row = WMGetListSelectedItemRow(panel->actLs);
345
346 if (row < 0)
347 return;
348
349 if (panel->shortcuts[row])
350 wfree(panel->shortcuts[row]);
351 panel->shortcuts[row] = WMGetTextFieldText(panel->shoT);
352 if (strlen(panel->shortcuts[row]) == 0) {
353 wfree(panel->shortcuts[row]);
354 panel->shortcuts[row] = NULL;
355 }
356 WMRedisplayWidget(panel->actLs);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000357}
358
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200359static void listClick(WMWidget * w, void *data)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000360{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200361 _Panel *panel = (_Panel *) data;
362 int row = WMGetListSelectedItemRow(w);
6830b057 dan2004-10-12 21:28:27 +0000363
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200364 WMSetTextFieldText(panel->shoT, panel->shortcuts[row]);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000365}
366
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200367static char *trimstr(char *str)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000368{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200369 char *p = str;
370 int i;
371
372 while (isspace(*p))
373 p++;
374 p = wstrdup(p);
375 i = strlen(p);
376 while (isspace(p[i]) && i > 0) {
377 p[i] = 0;
378 i--;
379 }
380
381 return p;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000382}
383
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200384static void showData(_Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000385{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200386 char *str;
387 int i;
388
389 for (i = 0; i < panel->actionCount; i++) {
390
391 str = GetStringForKey(keyOptions[i]);
392 if (panel->shortcuts[i])
393 wfree(panel->shortcuts[i]);
394 if (str)
395 panel->shortcuts[i] = trimstr(str);
396 else
397 panel->shortcuts[i] = NULL;
398
399 if (panel->shortcuts[i] &&
400 (strcasecmp(panel->shortcuts[i], "none") == 0 || strlen(panel->shortcuts[i]) == 0)) {
401 wfree(panel->shortcuts[i]);
402 panel->shortcuts[i] = NULL;
403 }
404 }
405 WMRedisplayWidget(panel->actLs);
0261c326 dan1999-01-06 15:22:33 +0000406}
407
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200408static void paintItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
0261c326 dan1999-01-06 15:22:33 +0000409{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200410 int width, height, x, y;
411 _Panel *panel = (_Panel *) WMGetHangedData(lPtr);
412 WMScreen *scr = WMWidgetScreen(lPtr);
413 Display *dpy = WMScreenDisplay(scr);
414 WMColor *backColor = (state & WLDSSelected) ? panel->white : panel->gray;
0261c326 dan1999-01-06 15:22:33 +0000415
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200416 width = rect->size.width;
417 height = rect->size.height;
418 x = rect->pos.x;
419 y = rect->pos.y;
0261c326 dan1999-01-06 15:22:33 +0000420
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200421 XFillRectangle(dpy, d, WMColorGC(backColor), x, y, width, height);
0261c326 dan1999-01-06 15:22:33 +0000422
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200423 if (panel->shortcuts[index]) {
424 WMPixmap *pix = WMGetSystemPixmap(scr, WSICheckMark);
425 WMSize size = WMGetPixmapSize(pix);
6830b057 dan2004-10-12 21:28:27 +0000426
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200427 WMDrawPixmap(pix, d, x + (20 - size.width) / 2, (height - size.height) / 2 + y);
428 WMReleasePixmap(pix);
429 }
0261c326 dan1999-01-06 15:22:33 +0000430
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200431 WMDrawString(scr, d, panel->black, panel->font, x + 20, y, text, strlen(text));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000432}
433
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200434static void createPanel(Panel * p)
6830b057 dan2004-10-12 21:28:27 +0000435{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200436 _Panel *panel = (_Panel *) p;
437 WMScreen *scr = WMWidgetScreen(panel->parent);
438 WMColor *color;
439 WMFont *boldFont;
440
441 panel->capturing = 0;
442
443 panel->white = WMWhiteColor(scr);
444 panel->black = WMBlackColor(scr);
445 panel->gray = WMGrayColor(scr);
446 panel->font = WMSystemFontOfSize(scr, 12);
447
448 panel->box = WMCreateBox(panel->parent);
449 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
450
451 boldFont = WMBoldSystemFontOfSize(scr, 12);
452
453 /* **************** Actions **************** */
454 panel->actL = WMCreateLabel(panel->box);
455 WMResizeWidget(panel->actL, 280, 20);
456 WMMoveWidget(panel->actL, 20, 10);
457 WMSetLabelFont(panel->actL, boldFont);
458 WMSetLabelText(panel->actL, _("Actions"));
459 WMSetLabelRelief(panel->actL, WRSunken);
460 WMSetLabelTextAlignment(panel->actL, WACenter);
461 color = WMDarkGrayColor(scr);
462 WMSetWidgetBackgroundColor(panel->actL, color);
463 WMReleaseColor(color);
464 WMSetLabelTextColor(panel->actL, panel->white);
465
466 panel->actLs = WMCreateList(panel->box);
467 WMResizeWidget(panel->actLs, 280, 190);
468 WMMoveWidget(panel->actLs, 20, 32);
469 WMSetListUserDrawProc(panel->actLs, paintItem);
470 WMHangData(panel->actLs, panel);
471
472 WMAddListItem(panel->actLs, _("Open applications menu"));
473 WMAddListItem(panel->actLs, _("Open window list menu"));
474 WMAddListItem(panel->actLs, _("Open window commands menu"));
475 WMAddListItem(panel->actLs, _("Hide active application"));
476 WMAddListItem(panel->actLs, _("Hide other applications"));
477 WMAddListItem(panel->actLs, _("Miniaturize active window"));
478 WMAddListItem(panel->actLs, _("Close active window"));
479 WMAddListItem(panel->actLs, _("Maximize active window"));
480 WMAddListItem(panel->actLs, _("Maximize active window vertically"));
481 WMAddListItem(panel->actLs, _("Maximize active window horizontally"));
69244548
JH
Johann Haarhoff2009-08-28 21:31:26 +0200482 WMAddListItem(panel->actLs, _("Maximize active window left half"));
483 WMAddListItem(panel->actLs, _("Maximize active window right half"));
9789cf31 Carlos R. Mafra2009-09-14 16:34:37 +0200484 WMAddListItem(panel->actLs, _("Maximus: Tiled maximization "));
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200485 WMAddListItem(panel->actLs, _("Raise active window"));
486 WMAddListItem(panel->actLs, _("Lower active window"));
487 WMAddListItem(panel->actLs, _("Raise/Lower window under mouse pointer"));
488 WMAddListItem(panel->actLs, _("Shade active window"));
489 WMAddListItem(panel->actLs, _("Move/Resize active window"));
490 WMAddListItem(panel->actLs, _("Select active window"));
491 WMAddListItem(panel->actLs, _("Focus next window"));
492 WMAddListItem(panel->actLs, _("Focus previous window"));
18408fff
IP
Iain Patterson2009-09-14 14:37:15 +0100493 WMAddListItem(panel->actLs, _("Focus next group window"));
494 WMAddListItem(panel->actLs, _("Focus previous group window"));
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200495 WMAddListItem(panel->actLs, _("Switch to next workspace"));
496 WMAddListItem(panel->actLs, _("Switch to previous workspace"));
497 WMAddListItem(panel->actLs, _("Switch to next ten workspaces"));
498 WMAddListItem(panel->actLs, _("Switch to previous ten workspaces"));
499 WMAddListItem(panel->actLs, _("Switch to workspace 1"));
500 WMAddListItem(panel->actLs, _("Switch to workspace 2"));
501 WMAddListItem(panel->actLs, _("Switch to workspace 3"));
502 WMAddListItem(panel->actLs, _("Switch to workspace 4"));
503 WMAddListItem(panel->actLs, _("Switch to workspace 5"));
504 WMAddListItem(panel->actLs, _("Switch to workspace 6"));
505 WMAddListItem(panel->actLs, _("Switch to workspace 7"));
506 WMAddListItem(panel->actLs, _("Switch to workspace 8"));
507 WMAddListItem(panel->actLs, _("Switch to workspace 9"));
508 WMAddListItem(panel->actLs, _("Switch to workspace 10"));
509 WMAddListItem(panel->actLs, _("Shortcut for window 1"));
510 WMAddListItem(panel->actLs, _("Shortcut for window 2"));
511 WMAddListItem(panel->actLs, _("Shortcut for window 3"));
512 WMAddListItem(panel->actLs, _("Shortcut for window 4"));
513 WMAddListItem(panel->actLs, _("Shortcut for window 5"));
514 WMAddListItem(panel->actLs, _("Shortcut for window 6"));
515 WMAddListItem(panel->actLs, _("Shortcut for window 7"));
516 WMAddListItem(panel->actLs, _("Shortcut for window 8"));
517 WMAddListItem(panel->actLs, _("Shortcut for window 9"));
518 WMAddListItem(panel->actLs, _("Shortcut for window 10"));
519 WMAddListItem(panel->actLs, _("Switch to Next Screen/Monitor"));
9aca0d5f dan2004-10-12 01:34:32 +0000520#ifdef VIRTUAL_DESKTOP
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200521 WMAddListItem(panel->actLs, _("Move VirtualDesktop to next left edge"));
522 WMAddListItem(panel->actLs, _("Move VirtualDesktop to next right edge"));
523 WMAddListItem(panel->actLs, _("Move VirtualDesktop to next top edge"));
524 WMAddListItem(panel->actLs, _("Move VirtualDesktop to next bottom edge"));
9aca0d5f dan2004-10-12 01:34:32 +0000525#endif
b6689a01 Brad Jorsch2010-01-06 12:50:36 -0500526 WMAddListItem(panel->actLs, _("Raise/Lower Dock"));
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200527 WMAddListItem(panel->actLs, _("Raise Clip"));
528 WMAddListItem(panel->actLs, _("Lower Clip"));
529 WMAddListItem(panel->actLs, _("Raise/Lower Clip"));
59eb9475 dan1998-11-03 12:53:26 +0000530#ifdef XKB_MODELOCK
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200531 WMAddListItem(panel->actLs, _("Toggle keyboard language"));
532#endif /* XKB_MODELOCK */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000533
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200534 WMSetListAction(panel->actLs, listClick, panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000535
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200536 panel->actionCount = WMGetListNumberOfRows(panel->actLs);
537 panel->shortcuts = wmalloc(sizeof(char *) * panel->actionCount);
538 memset(panel->shortcuts, 0, sizeof(char *) * panel->actionCount);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000539
540 /***************** Shortcut ****************/
541
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200542 panel->shoF = WMCreateFrame(panel->box);
543 WMResizeWidget(panel->shoF, 190, 210);
544 WMMoveWidget(panel->shoF, 315, 10);
545 WMSetFrameTitle(panel->shoF, _("Shortcut"));
6830b057 dan2004-10-12 21:28:27 +0000546
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200547 panel->shoT = WMCreateTextField(panel->shoF);
548 WMResizeWidget(panel->shoT, 160, 20);
549 WMMoveWidget(panel->shoT, 15, 65);
550 WMAddNotificationObserver(typedKeys, panel, WMTextDidChangeNotification, panel->shoT);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000551
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200552 panel->cleB = WMCreateCommandButton(panel->shoF);
553 WMResizeWidget(panel->cleB, 75, 24);
554 WMMoveWidget(panel->cleB, 15, 95);
555 WMSetButtonText(panel->cleB, _("Clear"));
556 WMSetButtonAction(panel->cleB, clearShortcut, panel);
6830b057 dan2004-10-12 21:28:27 +0000557
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200558 panel->defB = WMCreateCommandButton(panel->shoF);
559 WMResizeWidget(panel->defB, 75, 24);
560 WMMoveWidget(panel->defB, 100, 95);
561 WMSetButtonText(panel->defB, _("Capture"));
562 WMSetButtonAction(panel->defB, captureClick, panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000563
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200564 panel->instructionsL = WMCreateLabel(panel->shoF);
565 WMResizeWidget(panel->instructionsL, 160, 55);
566 WMMoveWidget(panel->instructionsL, 15, 140);
567 WMSetLabelTextAlignment(panel->instructionsL, WACenter);
568 WMSetLabelWraps(panel->instructionsL, True);
569 WMSetLabelText(panel->instructionsL, _("Click on Capture to interactively define the shortcut key."));
6830b057 dan2004-10-12 21:28:27 +0000570
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200571 WMMapSubwidgets(panel->shoF);
6830b057 dan2004-10-12 21:28:27 +0000572
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200573 WMReleaseFont(boldFont);
6830b057 dan2004-10-12 21:28:27 +0000574
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200575 WMRealizeWidget(panel->box);
576 WMMapSubwidgets(panel->box);
6830b057 dan2004-10-12 21:28:27 +0000577
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200578 showData(panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000579}
580
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200581static void storeData(_Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000582{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200583 int i;
584 char *str;
585
586 for (i = 0; i < panel->actionCount; i++) {
587 str = NULL;
588 if (panel->shortcuts[i]) {
589 str = trimstr(panel->shortcuts[i]);
590 if (strlen(str) == 0) {
591 wfree(str);
592 str = NULL;
593 }
594 }
595 if (str) {
596 SetStringForKey(str, keyOptions[i]);
597 wfree(str);
598 } else {
599 SetStringForKey("None", keyOptions[i]);
600 }
601 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000602}
603
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200604Panel *InitKeyboardShortcuts(WMScreen * scr, WMWidget * parent)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000605{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200606 _Panel *panel;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000607
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200608 panel = wmalloc(sizeof(_Panel));
609 memset(panel, 0, sizeof(_Panel));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000610
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200611 panel->sectionName = _("Keyboard Shortcut Preferences");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000612
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200613 panel->description = _("Change the keyboard shortcuts for actions such\n"
614 "as changing workspaces and opening menus.");
d3f29988 kojima1999-04-25 01:49:46 +0000615
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200616 panel->parent = parent;
1e922744 dan2002-10-16 04:05:45 +0000617
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200618 panel->callbacks.createWidgets = createPanel;
619 panel->callbacks.updateDomain = storeData;
0261c326 dan1999-01-06 15:22:33 +0000620
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200621 AddSection(panel, ICON_FILE);
1e922744 dan2002-10-16 04:05:45 +0000622
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200623 return panel;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000624}