Left Half / Right Half Maximize
[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",
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020077 "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",
9aca0d5f dan2004-10-12 01:34:32 +0000110#ifdef VIRTUAL_DESKTOP
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200111 "VirtualEdgeLeftKey",
112 "VirtualEdgeRightKey",
113 "VirtualEdgeUpKey",
114 "VirtualEdgeDownKey",
9aca0d5f dan2004-10-12 01:34:32 +0000115#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200116 "ClipRaiseKey",
117 "ClipLowerKey",
59eb9475 dan1998-11-03 12:53:26 +0000118#ifndef XKB_MODELOCK
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200119 "ClipRaiseLowerKey"
59eb9475 dan1998-11-03 12:53:26 +0000120#else
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200121 "ClipRaiseLowerKey",
122 "ToggleKbdModeKey"
123#endif /* XKB_MODELOCK */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000124};
125
5db8b566 kojima2002-02-15 21:34:46 +0000126#ifndef HAVE_XCONVERTCASE
127/* from Xlib */
128
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200129static void XConvertCase(register KeySym sym, KeySym * lower, KeySym * upper)
5db8b566 kojima2002-02-15 21:34:46 +0000130{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200131 *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 }
5db8b566 kojima2002-02-15 21:34:46 +0000231}
232#endif
233
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200234static char *captureShortcut(Display * dpy, _Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000235{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200236 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);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000286}
287
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200288static void captureClick(WMWidget * w, void *data)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000289{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200290 _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);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000320}
321
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200322static void clearShortcut(WMWidget * w, void *data)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000323{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200324 _Panel *panel = (_Panel *) data;
325 int row = WMGetListSelectedItemRow(panel->actLs);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000326
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200327 WMSetTextFieldText(panel->shoT, NULL);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000328
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200329 if (row >= 0) {
330 if (panel->shortcuts[row])
331 wfree(panel->shortcuts[row]);
332 panel->shortcuts[row] = NULL;
333 WMRedisplayWidget(panel->actLs);
334 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000335}
336
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200337static void typedKeys(void *observerData, WMNotification * notification)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000338{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200339 _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);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000353}
354
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200355static void listClick(WMWidget * w, void *data)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000356{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200357 _Panel *panel = (_Panel *) data;
358 int row = WMGetListSelectedItemRow(w);
6830b057 dan2004-10-12 21:28:27 +0000359
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200360 WMSetTextFieldText(panel->shoT, panel->shortcuts[row]);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000361}
362
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200363static char *trimstr(char *str)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000364{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200365 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;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000378}
379
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200380static void showData(_Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000381{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200382 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);
0261c326 dan1999-01-06 15:22:33 +0000402}
403
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200404static void paintItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
0261c326 dan1999-01-06 15:22:33 +0000405{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200406 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;
0261c326 dan1999-01-06 15:22:33 +0000411
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200412 width = rect->size.width;
413 height = rect->size.height;
414 x = rect->pos.x;
415 y = rect->pos.y;
0261c326 dan1999-01-06 15:22:33 +0000416
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200417 XFillRectangle(dpy, d, WMColorGC(backColor), x, y, width, height);
0261c326 dan1999-01-06 15:22:33 +0000418
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200419 if (panel->shortcuts[index]) {
420 WMPixmap *pix = WMGetSystemPixmap(scr, WSICheckMark);
421 WMSize size = WMGetPixmapSize(pix);
6830b057 dan2004-10-12 21:28:27 +0000422
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200423 WMDrawPixmap(pix, d, x + (20 - size.width) / 2, (height - size.height) / 2 + y);
424 WMReleasePixmap(pix);
425 }
0261c326 dan1999-01-06 15:22:33 +0000426
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200427 WMDrawString(scr, d, panel->black, panel->font, x + 20, y, text, strlen(text));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000428}
429
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200430static void createPanel(Panel * p)
6830b057 dan2004-10-12 21:28:27 +0000431{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200432 _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"));
69244548
JH
Johann Haarhoff2009-08-28 21:31:26 +0200478 WMAddListItem(panel->actLs, _("Maximize active window left half"));
479 WMAddListItem(panel->actLs, _("Maximize active window right half"));
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200480 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"));
9aca0d5f dan2004-10-12 01:34:32 +0000513#ifdef VIRTUAL_DESKTOP
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200514 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"));
9aca0d5f dan2004-10-12 01:34:32 +0000518#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200519 WMAddListItem(panel->actLs, _("Raise Clip"));
520 WMAddListItem(panel->actLs, _("Lower Clip"));
521 WMAddListItem(panel->actLs, _("Raise/Lower Clip"));
59eb9475 dan1998-11-03 12:53:26 +0000522#ifdef XKB_MODELOCK
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200523 WMAddListItem(panel->actLs, _("Toggle keyboard language"));
524#endif /* XKB_MODELOCK */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000525
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200526 WMSetListAction(panel->actLs, listClick, panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000527
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200528 panel->actionCount = WMGetListNumberOfRows(panel->actLs);
529 panel->shortcuts = wmalloc(sizeof(char *) * panel->actionCount);
530 memset(panel->shortcuts, 0, sizeof(char *) * panel->actionCount);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000531
532 /***************** Shortcut ****************/
533
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200534 panel->shoF = WMCreateFrame(panel->box);
535 WMResizeWidget(panel->shoF, 190, 210);
536 WMMoveWidget(panel->shoF, 315, 10);
537 WMSetFrameTitle(panel->shoF, _("Shortcut"));
6830b057 dan2004-10-12 21:28:27 +0000538
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200539 panel->shoT = WMCreateTextField(panel->shoF);
540 WMResizeWidget(panel->shoT, 160, 20);
541 WMMoveWidget(panel->shoT, 15, 65);
542 WMAddNotificationObserver(typedKeys, panel, WMTextDidChangeNotification, panel->shoT);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000543
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200544 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);
6830b057 dan2004-10-12 21:28:27 +0000549
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200550 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);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000555
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200556 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."));
6830b057 dan2004-10-12 21:28:27 +0000562
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200563 WMMapSubwidgets(panel->shoF);
6830b057 dan2004-10-12 21:28:27 +0000564
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200565 WMReleaseFont(boldFont);
6830b057 dan2004-10-12 21:28:27 +0000566
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200567 WMRealizeWidget(panel->box);
568 WMMapSubwidgets(panel->box);
6830b057 dan2004-10-12 21:28:27 +0000569
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200570 showData(panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000571}
572
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200573static void storeData(_Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000574{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200575 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 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000594}
595
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200596Panel *InitKeyboardShortcuts(WMScreen * scr, WMWidget * parent)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000597{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200598 _Panel *panel;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000599
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200600 panel = wmalloc(sizeof(_Panel));
601 memset(panel, 0, sizeof(_Panel));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000602
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200603 panel->sectionName = _("Keyboard Shortcut Preferences");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000604
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200605 panel->description = _("Change the keyboard shortcuts for actions such\n"
606 "as changing workspaces and opening menus.");
d3f29988 kojima1999-04-25 01:49:46 +0000607
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200608 panel->parent = parent;
1e922744 dan2002-10-16 04:05:45 +0000609
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200610 panel->callbacks.createWidgets = createPanel;
611 panel->callbacks.updateDomain = storeData;
0261c326 dan1999-01-06 15:22:33 +0000612
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200613 AddSection(panel, ICON_FILE);
1e922744 dan2002-10-16 04:05:45 +0000614
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200615 return panel;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000616}