WPrefs: Fix crash when switching to mouse settings panel
[wmaker-crm.git] / WPrefs.app / MouseSettings.c
blobd28f7ded295603fcf4a62c466d1cb4b73c757df9
2 /* MouseSettings.c- mouse options (some are equivalent to xset)
4 * WPrefs - Window Maker Preferences Program
6 * Copyright (c) 1998-2003 Alfredo K. Kojima
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "WPrefs.h"
25 #include <X11/Xutil.h>
26 #include <X11/XKBlib.h>
28 #include <unistd.h>
29 #include <math.h>
32 #define XSET "xset"
34 typedef struct _Panel {
35 WMBox *box;
37 char *sectionName;
39 char *description;
41 CallbackRec callbacks;
43 WMWidget *parent;
45 WMFrame *speedF;
46 WMLabel *speedL;
47 WMSlider *speedS;
48 WMLabel *acceL;
49 WMTextField *acceT;
50 WMLabel *threL;
51 WMTextField *threT;
53 WMFrame *ddelaF;
54 WMButton *ddelaB[5];
55 WMTextField *ddelaT;
56 WMLabel *ddelaL;
57 DoubleTest *tester;
59 WMFrame *menuF;
60 WMLabel *button1L;
61 WMLabel *button2L;
62 WMLabel *button3L;
63 WMLabel *wheelL;
64 WMPopUpButton *button1P;
65 WMPopUpButton *button2P;
66 WMPopUpButton *button3P;
67 WMPopUpButton *wheelP;
69 WMButton *disaB;
71 WMFrame *grabF;
72 WMPopUpButton *grabP;
74 /**/ int maxThreshold;
75 float acceleration;
76 } _Panel;
78 #define ICON_FILE "mousesettings"
80 #define SPEED_ICON_FILE "mousespeed"
82 #define DELAY_ICON "timer%i"
83 #define DELAY_ICON_S "timer%is"
85 /* need access to the double click variables */
86 #include <WINGs/WINGsP.h>
88 static char *modifierNames[8];
90 static char *buttonActions[4];
92 static char *wheelActions[2];
94 #define DELAY(i) ((i)*75+170)
97 static void setMouseAccel(WMScreen * scr, float accel, int threshold)
99 int n, d;
101 d = 10;
102 n = accel * d;
104 XChangePointerControl(WMScreenDisplay(scr), True, True, n, d, threshold);
107 static void speedChange(WMWidget * w, void *data)
109 _Panel *panel = (_Panel *) data;
110 int i;
111 char buffer[64];
112 int threshold;
113 char *tmp;
115 if (w == NULL) {
116 float accel;
118 tmp = WMGetTextFieldText(panel->acceT);
119 if (sscanf(tmp, "%f", &accel) != 1 || accel < 0) {
120 WMRunAlertPanel(WMWidgetScreen(panel->acceT), GetWindow(panel),
121 _("Error"),
122 _("Invalid mouse acceleration value. Must be a positive real value."),
123 _("OK"), NULL, NULL);
124 wfree(tmp);
125 return;
127 panel->acceleration = accel;
128 wfree(tmp);
129 } else {
130 i = (int)WMGetSliderValue(panel->speedS);
132 panel->acceleration = 0.25 + (i * 0.25);
134 sprintf(buffer, "%.2f", 0.25 + (i * 0.25));
135 WMSetTextFieldText(panel->acceT, buffer);
138 tmp = WMGetTextFieldText(panel->threT);
139 if (sscanf(tmp, "%i", &threshold) != 1 || threshold < 0 || threshold > panel->maxThreshold) {
140 WMRunAlertPanel(WMWidgetScreen(panel->parent), GetWindow(panel), _("Error"),
142 ("Invalid mouse acceleration threshold value. Must be the number of pixels to travel before accelerating."),
143 _("OK"), NULL, NULL);
144 } else {
145 setMouseAccel(WMWidgetScreen(panel->parent), panel->acceleration, threshold);
147 wfree(tmp);
150 static void returnPressed(void *observerData, WMNotification * notification)
152 _Panel *panel = (_Panel *) observerData;
154 speedChange(NULL, panel);
157 static void doubleClick(WMWidget * w, void *data)
159 _Panel *panel = (_Panel *) data;
160 int i;
161 char buffer[32];
163 for (i = 0; i < 5; i++) {
164 if (panel->ddelaB[i] == w)
165 break;
167 WINGsConfiguration.doubleClickDelay = DELAY(i);
169 sprintf(buffer, "%i", DELAY(i));
170 WMSetTextFieldText(panel->ddelaT, buffer);
173 static int getButtonAction(const char *str)
175 if (!str)
176 return -2;
178 if (strcasecmp(str, "None") == 0)
179 return 0;
180 else if (strcasecmp(str, "OpenApplicationsMenu") == 0)
181 return 1;
182 else if (strcasecmp(str, "OpenWindowListMenu") == 0)
183 return 2;
184 else if (strcasecmp(str, "SelectWindows") == 0)
185 return 3;
186 else
187 return -1;
191 static int getWheelAction(const char *str)
193 if (!str)
194 return -2;
196 if (strcasecmp(str, "None") == 0)
197 return 0;
198 else if (strcasecmp(str, "SwitchWorkspaces") == 0)
199 return 1;
200 else
201 return -1;
205 static void getMouseParameters(Display * dpy, float *accel, int *thre)
207 int n, d;
209 XGetPointerControl(dpy, &n, &d, thre);
211 *accel = (float)n / (float)d;
214 static void showData(_Panel * panel)
216 char *str;
217 int i;
218 int a = -1, b = -1, c = -1, w = -1;
219 float accel;
220 char buffer[32];
221 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->parent));
223 str = GetStringForKey("MouseLeftButtonAction");
224 i = getButtonAction(str);
225 if (i < 0) {
226 a = 3;
227 if (i == -1) {
228 wwarning(_("bad value %s for option %s"), str, "MouseLeftButtonAction");
230 } else {
231 a = i;
233 WMSetPopUpButtonSelectedItem(panel->button1P, a);
235 str = GetStringForKey("MouseMiddleButtonAction");
236 i = getButtonAction(str);
237 if (i < 0) {
238 b = 2;
239 if (i == -1) {
240 wwarning(_("bad value %s for option %s"), str, "MouseMiddleButtonAction");
242 } else {
243 b = i;
245 WMSetPopUpButtonSelectedItem(panel->button2P, b);
247 str = GetStringForKey("MouseRightButtonAction");
248 i = getButtonAction(str);
249 if (i < 0) {
250 c = 1;
251 if (i == -1) {
252 wwarning(_("bad value %s for option %s"), str, "MouseRightButtonAction");
254 } else {
255 c = i;
257 WMSetPopUpButtonSelectedItem(panel->button3P, c);
259 str = GetStringForKey("MouseWheelAction");
260 i = getWheelAction(str);
261 if (i < 0) {
262 w = 0;
263 if (i == -1) {
264 wwarning(_("bad value %s for option %s"), str, "MouseWheelAction");
266 } else {
267 w = i;
269 WMSetPopUpButtonSelectedItem(panel->wheelP, w);
271 WMSetButtonSelected(panel->disaB, GetBoolForKey("DisableWSMouseActions"));
273 /**/ getMouseParameters(dpy, &accel, &a);
274 panel->maxThreshold = WidthOfScreen(DefaultScreenOfDisplay(dpy));
275 if (a > panel->maxThreshold) {
276 panel->maxThreshold = a;
278 sprintf(buffer, "%i", a);
279 WMSetTextFieldText(panel->threT, buffer);
281 WMSetSliderValue(panel->speedS, (accel - 0.25) / 0.25);
283 panel->acceleration = accel;
284 sprintf(buffer, "%.2f", accel);
285 WMSetTextFieldText(panel->acceT, buffer);
287 /**/ b = GetIntegerForKey("DoubleClickTime");
288 /* find best match */
289 a = -1;
290 for (i = 0; i < 5; i++) {
291 if (DELAY(i) == b)
292 a = i;
294 if (a >= 0)
295 WMPerformButtonClick(panel->ddelaB[a]);
296 sprintf(buffer, "%i", b);
297 WMSetTextFieldText(panel->ddelaT, buffer);
299 /**/ str = GetStringForKey("ModifierKey");
300 if (!str)
301 str = "mod1";
302 a = ModifierFromKey(dpy, str);
304 if (a != -1) {
305 str = modifierNames[a];
307 a = 0;
308 for (i = 0; i < WMGetPopUpButtonNumberOfItems(panel->grabP); i++) {
309 if (strstr(WMGetPopUpButtonItem(panel->grabP, i), str)) {
310 WMSetPopUpButtonSelectedItem(panel->grabP, i);
311 a = 1;
312 break;
317 if (a < 1) {
318 char *previous;
320 previous = WMGetPopUpButtonItem(panel->grabP, 0);
321 if (previous != NULL)
322 WMSetPopUpButtonSelectedItem(panel->grabP, 0);
323 wwarning(_("modifier key %s for option ModifierKey was not recognized. Using %s as default"),
324 str, previous?previous:"(empty)");
328 static void fillModifierPopUp(WMPopUpButton * pop)
330 XModifierKeymap *mapping;
331 Display *dpy = WMScreenDisplay(WMWidgetScreen(pop));
332 int i, j;
333 char *str;
334 char buffer[64];
336 mapping = XGetModifierMapping(dpy);
338 if (!mapping || mapping->max_keypermod == 0) {
339 WMAddPopUpButtonItem(pop, "Mod1");
340 WMAddPopUpButtonItem(pop, "Mod2");
341 WMAddPopUpButtonItem(pop, "Mod3");
342 WMAddPopUpButtonItem(pop, "Mod4");
343 WMAddPopUpButtonItem(pop, "Mod5");
344 wwarning(_("could not retrieve keyboard modifier mapping"));
345 return;
348 for (j = 0; j < 8; j++) {
349 int idx;
350 char *array[8];
351 int a;
352 KeySym ksym;
353 int k;
354 char *ptr;
355 char *tmp;
357 a = 0;
358 memset(array, 0, sizeof(char *) * 8);
359 for (i = 0; i < mapping->max_keypermod; i++) {
360 idx = i + j * mapping->max_keypermod;
361 if (mapping->modifiermap[idx] != 0) {
362 int l;
363 for (l = 0; l < 4; l++) {
364 ksym = XkbKeycodeToKeysym(dpy, mapping->modifiermap[idx], 0, l);
365 if (ksym != NoSymbol)
366 break;
368 if (ksym != NoSymbol)
369 str = XKeysymToString(ksym);
370 else
371 str = NULL;
372 if (str && !strstr(str, "_Lock") && !strstr(str, "Shift")
373 && !strstr(str, "Control")) {
374 array[a++] = wstrdup(str);
379 for (k = 0; k < a; k++) {
380 if (array[k] == NULL)
381 continue;
382 tmp = wstrdup(array[k]);
383 ptr = strstr(tmp, "_L");
384 if (ptr)
385 *ptr = 0;
386 ptr = strstr(tmp, "_R");
387 if (ptr)
388 *ptr = 0;
389 sprintf(buffer, "%s (%s)", modifierNames[j], tmp);
390 /*sprintf(buffer, "%s", tmp); */
391 WMAddPopUpButtonItem(pop, buffer);
392 for (i = k + 1; i < a; i++) {
393 if (array[i] == NULL)
394 continue;
395 if (strstr(array[i], tmp)) {
396 wfree(array[i]);
397 array[i] = NULL;
398 break;
401 wfree(tmp);
404 while (--a > 0) {
405 if (array[a])
406 wfree(array[a]);
410 if (mapping)
411 XFreeModifiermap(mapping);
414 static void createPanel(Panel * p)
416 _Panel *panel = (_Panel *) p;
417 WMScreen *scr = WMWidgetScreen(panel->parent);
418 WMPixmap *icon;
419 char *buf1, *buf2;
420 int i;
421 RColor color;
422 char *path;
424 color.red = 0xae;
425 color.green = 0xaa;
426 color.blue = 0xae;
428 panel->box = WMCreateBox(panel->parent);
429 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
431 /**************** Mouse Speed ****************/
432 panel->speedF = WMCreateFrame(panel->box);
433 WMResizeWidget(panel->speedF, 245, 100);
434 WMMoveWidget(panel->speedF, 15, 5);
435 WMSetFrameTitle(panel->speedF, _("Mouse Speed"));
437 panel->speedL = WMCreateLabel(panel->speedF);
438 WMResizeWidget(panel->speedL, 40, 46);
439 WMMoveWidget(panel->speedL, 15, 14);
440 WMSetLabelImagePosition(panel->speedL, WIPImageOnly);
441 path = LocateImage(SPEED_ICON_FILE);
442 if (path) {
443 icon = WMCreateBlendedPixmapFromFile(scr, path, &color);
444 if (icon) {
445 WMSetLabelImage(panel->speedL, icon);
446 WMReleasePixmap(icon);
447 } else {
448 wwarning(_("could not load icon %s"), path);
450 wfree(path);
453 panel->speedS = WMCreateSlider(panel->speedF);
454 WMResizeWidget(panel->speedS, 160, 15);
455 WMMoveWidget(panel->speedS, 70, 35);
456 WMSetSliderMinValue(panel->speedS, 0);
457 WMSetSliderMaxValue(panel->speedS, 40);
458 WMSetSliderContinuous(panel->speedS, False);
459 WMSetSliderAction(panel->speedS, speedChange, panel);
461 panel->acceL = WMCreateLabel(panel->speedF);
462 WMResizeWidget(panel->acceL, 70, 16);
463 WMMoveWidget(panel->acceL, 10, 67);
464 WMSetLabelTextAlignment(panel->acceL, WARight);
465 WMSetLabelText(panel->acceL, _("Acceler.:"));
467 panel->acceT = WMCreateTextField(panel->speedF);
468 WMResizeWidget(panel->acceT, 40, 20);
469 WMMoveWidget(panel->acceT, 80, 65);
470 WMAddNotificationObserver(returnPressed, panel, WMTextDidEndEditingNotification, panel->acceT);
472 panel->threL = WMCreateLabel(panel->speedF);
473 WMResizeWidget(panel->threL, 80, 16);
474 WMMoveWidget(panel->threL, 120, 67);
475 WMSetLabelTextAlignment(panel->threL, WARight);
476 WMSetLabelText(panel->threL, _("Threshold:"));
478 panel->threT = WMCreateTextField(panel->speedF);
479 WMResizeWidget(panel->threT, 30, 20);
480 WMMoveWidget(panel->threT, 200, 65);
481 WMAddNotificationObserver(returnPressed, panel, WMTextDidEndEditingNotification, panel->threT);
483 WMMapSubwidgets(panel->speedF);
485 /***************** Doubleclick Delay ****************/
487 panel->ddelaF = WMCreateFrame(panel->box);
488 WMResizeWidget(panel->ddelaF, 245, 105);
489 WMMoveWidget(panel->ddelaF, 15, 115);
490 WMSetFrameTitle(panel->ddelaF, _("Double-Click Delay"));
492 buf1 = wmalloc(strlen(DELAY_ICON) + 2);
493 buf2 = wmalloc(strlen(DELAY_ICON_S) + 2);
495 for (i = 0; i < 5; i++) {
496 panel->ddelaB[i] = WMCreateCustomButton(panel->ddelaF, WBBStateChangeMask);
497 WMResizeWidget(panel->ddelaB[i], 25, 25);
498 WMMoveWidget(panel->ddelaB[i], 30 + (40 * i), 25);
499 WMSetButtonBordered(panel->ddelaB[i], False);
500 WMSetButtonImagePosition(panel->ddelaB[i], WIPImageOnly);
501 WMSetButtonAction(panel->ddelaB[i], doubleClick, panel);
502 if (i > 0) {
503 WMGroupButtons(panel->ddelaB[0], panel->ddelaB[i]);
505 sprintf(buf1, DELAY_ICON, i + 1);
506 sprintf(buf2, DELAY_ICON_S, i + 1);
507 path = LocateImage(buf1);
508 if (path) {
509 icon = WMCreatePixmapFromFile(scr, path);
510 if (icon) {
511 WMSetButtonImage(panel->ddelaB[i], icon);
512 WMReleasePixmap(icon);
513 } else {
514 wwarning(_("could not load icon file %s"), path);
516 wfree(path);
518 path = LocateImage(buf2);
519 if (path) {
520 icon = WMCreatePixmapFromFile(scr, path);
521 if (icon) {
522 WMSetButtonAltImage(panel->ddelaB[i], icon);
523 WMReleasePixmap(icon);
524 } else {
525 wwarning(_("could not load icon file %s"), path);
527 wfree(path);
530 wfree(buf1);
531 wfree(buf2);
533 panel->tester = CreateDoubleTest(panel->ddelaF, _("Test"));
534 WMResizeWidget(panel->tester, 84, 29);
535 WMMoveWidget(panel->tester, 35, 60);
537 panel->ddelaT = WMCreateTextField(panel->ddelaF);
538 WMResizeWidget(panel->ddelaT, 40, 20);
539 WMMoveWidget(panel->ddelaT, 140, 65);
541 panel->ddelaL = WMCreateLabel(panel->ddelaF);
542 WMResizeWidget(panel->ddelaL, 40, 16);
543 WMMoveWidget(panel->ddelaL, 185, 70);
545 WMFont *font;
546 WMColor *color;
548 font = WMSystemFontOfSize(scr, 10);
549 color = WMDarkGrayColor(scr);
550 WMSetLabelTextColor(panel->ddelaL, color);
551 WMSetLabelFont(panel->ddelaL, font);
552 WMReleaseFont(font);
553 WMReleaseColor(color);
555 WMSetLabelText(panel->ddelaL, _("msec"));
557 WMMapSubwidgets(panel->ddelaF);
559 /* ************** Workspace Action Buttons **************** */
560 panel->menuF = WMCreateFrame(panel->box);
561 WMResizeWidget(panel->menuF, 240, 160);
562 WMMoveWidget(panel->menuF, 270, 5);
563 WMSetFrameTitle(panel->menuF, _("Workspace Mouse Actions"));
565 panel->disaB = WMCreateSwitchButton(panel->menuF);
566 WMResizeWidget(panel->disaB, 205, 18);
567 WMMoveWidget(panel->disaB, 10, 18);
568 WMSetButtonText(panel->disaB, _("Disable mouse actions"));
570 panel->button1L = WMCreateLabel(panel->menuF);
571 WMResizeWidget(panel->button1L, 87, 20);
572 WMMoveWidget(panel->button1L, 5, 45);
573 WMSetLabelTextAlignment(panel->button1L, WARight);
574 WMSetLabelText(panel->button1L, _("Left Button"));
576 panel->button1P = WMCreatePopUpButton(panel->menuF);
577 WMResizeWidget(panel->button1P, 135, 20);
578 WMMoveWidget(panel->button1P, 95, 45);
580 panel->button2L = WMCreateLabel(panel->menuF);
581 WMResizeWidget(panel->button2L, 87, 20);
582 WMMoveWidget(panel->button2L, 5, 73);
583 WMSetLabelTextAlignment(panel->button2L, WARight);
584 WMSetLabelText(panel->button2L, _("Middle Button"));
586 panel->button2P = WMCreatePopUpButton(panel->menuF);
587 WMResizeWidget(panel->button2P, 135, 20);
588 WMMoveWidget(panel->button2P, 95, 73);
590 panel->button3L = WMCreateLabel(panel->menuF);
591 WMResizeWidget(panel->button3L, 87, 20);
592 WMMoveWidget(panel->button3L, 5, 101);
593 WMSetLabelTextAlignment(panel->button3L, WARight);
594 WMSetLabelText(panel->button3L, _("Right Button"));
596 panel->button3P = WMCreatePopUpButton(panel->menuF);
597 WMResizeWidget(panel->button3P, 135, 20);
598 WMMoveWidget(panel->button3P, 95, 101);
600 panel->wheelL = WMCreateLabel(panel->menuF);
601 WMResizeWidget(panel->wheelL, 87, 20);
602 WMMoveWidget(panel->wheelL, 5, 129);
603 WMSetLabelTextAlignment(panel->wheelL, WARight);
604 WMSetLabelText(panel->wheelL, _("Mouse Wheel"));
606 panel->wheelP = WMCreatePopUpButton(panel->menuF);
607 WMResizeWidget(panel->wheelP, 135, 20);
608 WMMoveWidget(panel->wheelP, 95, 129);
610 for (i = 0; i < sizeof(buttonActions) / sizeof(buttonActions[0]); i++) {
611 WMAddPopUpButtonItem(panel->button1P, buttonActions[i]);
612 WMAddPopUpButtonItem(panel->button2P, buttonActions[i]);
613 WMAddPopUpButtonItem(panel->button3P, buttonActions[i]);
616 for (i = 0; i < sizeof(wheelActions) / sizeof(wheelActions[0]); i++) {
617 WMAddPopUpButtonItem(panel->wheelP, wheelActions[i]);
620 WMMapSubwidgets(panel->menuF);
622 /* ************** Grab Modifier **************** */
623 panel->grabF = WMCreateFrame(panel->box);
624 WMResizeWidget(panel->grabF, 240, 50);
625 WMMoveWidget(panel->grabF, 270, 170);
626 WMSetFrameTitle(panel->grabF, _("Mouse Grab Modifier"));
628 WMSetBalloonTextForView(_("Keyboard modifier to use for actions that\n"
629 "involve dragging windows with the mouse,\n"
630 "clicking inside the window."), WMWidgetView(panel->grabF));
632 panel->grabP = WMCreatePopUpButton(panel->grabF);
633 WMResizeWidget(panel->grabP, 160, 20);
634 WMMoveWidget(panel->grabP, 40, 20);
636 fillModifierPopUp(panel->grabP);
638 WMMapSubwidgets(panel->grabF);
640 WMRealizeWidget(panel->box);
641 WMMapSubwidgets(panel->box);
643 showData(panel);
646 static void storeCommandInScript(const char *cmd, const char *line)
648 char *path;
649 FILE *f;
650 char buffer[128];
652 path = wstrconcat(wusergnusteppath(), "/Library/WindowMaker/autostart");
654 f = fopen(path, "rb");
655 if (!f) {
656 f = fopen(path, "wb");
657 if (!f) {
658 werror(_("could not create %s"), path);
659 goto end;
661 fprintf(f, "#!/bin/sh\n");
662 fputs(line, f);
663 fputs("\n", f);
664 } else {
665 int len = strlen(cmd);
666 int ok = 0;
667 char *tmppath;
668 FILE *fo;
670 tmppath = wstrconcat(wusergnusteppath(), "/Library/WindowMaker/autostart.tmp");
671 fo = fopen(tmppath, "wb");
672 if (!fo) {
673 werror(_("could not create temporary file %s"), tmppath);
674 wfree(tmppath);
675 goto end;
678 while (!feof(f)) {
679 if (!fgets(buffer, 127, f)) {
680 break;
682 if (buffer[0] == '\n') {
683 /* don't write empty lines, else the file will grow
684 * indefinitely (one '\n' added at end of file on each save).
686 continue;
688 if (strncmp(buffer, cmd, len) == 0) {
689 if (!ok) {
690 fputs(line, fo);
691 fputs("\n", fo);
692 ok = 1;
694 } else {
695 fputs(buffer, fo);
698 if (!ok) {
699 fputs(line, fo);
700 fputs("\n", fo);
702 fsync(fileno(fo));
703 fclose(fo);
705 if (rename(tmppath, path) != 0) {
706 werror(_("could not rename file %s to %s"), tmppath, path);
708 wfree(tmppath);
710 sprintf(buffer, "chmod u+x %s", path);
711 system(buffer);
713 end:
714 wfree(path);
715 if (f) {
716 fsync(fileno(f)); /* this may be rw */
717 fclose(f);
721 static void storeData(_Panel * panel)
723 char buffer[64];
724 int i;
725 char *tmp, *p;
726 static char *button[4] = { "None", "OpenApplicationsMenu", "OpenWindowListMenu", "SelectWindows" };
727 static char *wheel[2] = { "None", "SwitchWorkspaces" };
728 WMUserDefaults *udb = WMGetStandardUserDefaults();
730 if (!WMGetUDBoolForKey(udb, "NoXSetStuff")) {
731 tmp = WMGetTextFieldText(panel->threT);
732 if (strlen(tmp) == 0) {
733 wfree(tmp);
734 tmp = wstrdup("4");
737 sprintf(buffer, XSET " m %i/%i %s\n", (int)(panel->acceleration * 10), 10, tmp);
738 storeCommandInScript(XSET " m", buffer);
740 wfree(tmp);
743 tmp = WMGetTextFieldText(panel->ddelaT);
744 if (sscanf(tmp, "%i", &i) == 1 && i > 0)
745 SetIntegerForKey(i, "DoubleClickTime");
747 SetBoolForKey(WMGetButtonSelected(panel->disaB), "DisableWSMouseActions");
749 i = WMGetPopUpButtonSelectedItem(panel->button1P);
750 SetStringForKey(button[i], "MouseLeftButtonAction");
752 i = WMGetPopUpButtonSelectedItem(panel->button2P);
753 SetStringForKey(button[i], "MouseMiddleButtonAction");
755 i = WMGetPopUpButtonSelectedItem(panel->button3P);
756 SetStringForKey(button[i], "MouseRightButtonAction");
758 i = WMGetPopUpButtonSelectedItem(panel->wheelP);
759 SetStringForKey(wheel[i], "MouseWheelAction");
761 tmp = WMGetPopUpButtonItem(panel->grabP, WMGetPopUpButtonSelectedItem(panel->grabP));
762 tmp = wstrdup(tmp);
763 p = strchr(tmp, ' ');
764 *p = 0;
766 SetStringForKey(tmp, "ModifierKey");
768 wfree(tmp);
771 Panel *InitMouseSettings(WMScreen * scr, WMWidget * parent)
773 _Panel *panel;
775 modifierNames[0] = wstrdup(_("Shift"));
776 modifierNames[1] = wstrdup(_("Lock"));
777 modifierNames[2] = wstrdup(_("Control"));
778 modifierNames[3] = wstrdup(_("Mod1"));
779 modifierNames[4] = wstrdup(_("Mod2"));
780 modifierNames[5] = wstrdup(_("Mod3"));
781 modifierNames[6] = wstrdup(_("Mod4"));
782 modifierNames[7] = wstrdup(_("Mod5"));
784 buttonActions[0] = wstrdup(_("None"));
785 buttonActions[1] = wstrdup(_("Applications Menu"));
786 buttonActions[2] = wstrdup(_("Window List Menu"));
787 buttonActions[3] = wstrdup(_("Select Windows"));
789 wheelActions[0] = wstrdup(_("None"));
790 wheelActions[1] = wstrdup(_("Switch Workspaces"));
792 panel = wmalloc(sizeof(_Panel));
794 panel->sectionName = _("Mouse Preferences");
796 panel->description = _("Mouse speed/acceleration, double click delay,\n" "mouse button bindings etc.");
798 panel->parent = parent;
800 panel->callbacks.createWidgets = createPanel;
801 panel->callbacks.updateDomain = storeData;
803 AddSection(panel, ICON_FILE);
805 return panel;