Configure: Added proper check for Xmu library for WRaster
[wmaker-crm.git] / WPrefs.app / MouseSettings.c
blob32886dbb5eae0fde8e1bef2ae2dcde4aa1fe42fd
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 /* Parameter not used, but tell the compiler that it is ok */
155 (void) notification;
157 speedChange(NULL, panel);
160 static void doubleClick(WMWidget * w, void *data)
162 _Panel *panel = (_Panel *) data;
163 int i;
164 char buffer[32];
166 for (i = 0; i < 5; i++) {
167 if (panel->ddelaB[i] == w)
168 break;
170 WINGsConfiguration.doubleClickDelay = DELAY(i);
172 sprintf(buffer, "%i", DELAY(i));
173 WMSetTextFieldText(panel->ddelaT, buffer);
176 static int getButtonAction(const char *str)
178 if (!str)
179 return -2;
181 if (strcasecmp(str, "None") == 0)
182 return 0;
183 else if (strcasecmp(str, "OpenApplicationsMenu") == 0)
184 return 1;
185 else if (strcasecmp(str, "OpenWindowListMenu") == 0)
186 return 2;
187 else if (strcasecmp(str, "SelectWindows") == 0)
188 return 3;
189 else
190 return -1;
194 static int getWheelAction(const char *str)
196 if (!str)
197 return -2;
199 if (strcasecmp(str, "None") == 0)
200 return 0;
201 else if (strcasecmp(str, "SwitchWorkspaces") == 0)
202 return 1;
203 else
204 return -1;
208 static void getMouseParameters(Display * dpy, float *accel, int *thre)
210 int n, d;
212 XGetPointerControl(dpy, &n, &d, thre);
214 *accel = (float)n / (float)d;
217 static void showData(_Panel * panel)
219 char *str;
220 int i;
221 int a = -1, b = -1, c = -1, w = -1;
222 float accel;
223 char buffer[32];
224 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->parent));
226 str = GetStringForKey("MouseLeftButtonAction");
227 i = getButtonAction(str);
228 if (i < 0) {
229 a = 3;
230 if (i == -1) {
231 wwarning(_("bad value %s for option %s"), str, "MouseLeftButtonAction");
233 } else {
234 a = i;
236 WMSetPopUpButtonSelectedItem(panel->button1P, a);
238 str = GetStringForKey("MouseMiddleButtonAction");
239 i = getButtonAction(str);
240 if (i < 0) {
241 b = 2;
242 if (i == -1) {
243 wwarning(_("bad value %s for option %s"), str, "MouseMiddleButtonAction");
245 } else {
246 b = i;
248 WMSetPopUpButtonSelectedItem(panel->button2P, b);
250 str = GetStringForKey("MouseRightButtonAction");
251 i = getButtonAction(str);
252 if (i < 0) {
253 c = 1;
254 if (i == -1) {
255 wwarning(_("bad value %s for option %s"), str, "MouseRightButtonAction");
257 } else {
258 c = i;
260 WMSetPopUpButtonSelectedItem(panel->button3P, c);
262 str = GetStringForKey("MouseWheelAction");
263 i = getWheelAction(str);
264 if (i < 0) {
265 w = 0;
266 if (i == -1) {
267 wwarning(_("bad value %s for option %s"), str, "MouseWheelAction");
269 } else {
270 w = i;
272 WMSetPopUpButtonSelectedItem(panel->wheelP, w);
274 WMSetButtonSelected(panel->disaB, GetBoolForKey("DisableWSMouseActions"));
276 /**/ getMouseParameters(dpy, &accel, &a);
277 panel->maxThreshold = WidthOfScreen(DefaultScreenOfDisplay(dpy));
278 if (a > panel->maxThreshold) {
279 panel->maxThreshold = a;
281 sprintf(buffer, "%i", a);
282 WMSetTextFieldText(panel->threT, buffer);
284 WMSetSliderValue(panel->speedS, (accel - 0.25) / 0.25);
286 panel->acceleration = accel;
287 sprintf(buffer, "%.2f", accel);
288 WMSetTextFieldText(panel->acceT, buffer);
290 /**/ b = GetIntegerForKey("DoubleClickTime");
291 /* find best match */
292 a = -1;
293 for (i = 0; i < 5; i++) {
294 if (DELAY(i) == b)
295 a = i;
297 if (a >= 0)
298 WMPerformButtonClick(panel->ddelaB[a]);
299 sprintf(buffer, "%i", b);
300 WMSetTextFieldText(panel->ddelaT, buffer);
302 /**/ str = GetStringForKey("ModifierKey");
303 if (!str)
304 str = "mod1";
305 a = ModifierFromKey(dpy, str);
307 if (a != -1) {
308 str = modifierNames[a];
310 a = 0;
311 for (i = 0; i < WMGetPopUpButtonNumberOfItems(panel->grabP); i++) {
312 if (strstr(WMGetPopUpButtonItem(panel->grabP, i), str)) {
313 WMSetPopUpButtonSelectedItem(panel->grabP, i);
314 a = 1;
315 break;
320 if (a < 1) {
321 char *previous;
323 previous = WMGetPopUpButtonItem(panel->grabP, 0);
324 if (previous != NULL)
325 WMSetPopUpButtonSelectedItem(panel->grabP, 0);
326 wwarning(_("modifier key %s for option ModifierKey was not recognized. Using %s as default"),
327 str, previous?previous:"(empty)");
331 static void fillModifierPopUp(WMPopUpButton * pop)
333 XModifierKeymap *mapping;
334 Display *dpy = WMScreenDisplay(WMWidgetScreen(pop));
335 int i, j;
336 char *str;
337 char buffer[64];
339 mapping = XGetModifierMapping(dpy);
341 if (!mapping || mapping->max_keypermod == 0) {
342 WMAddPopUpButtonItem(pop, "Mod1");
343 WMAddPopUpButtonItem(pop, "Mod2");
344 WMAddPopUpButtonItem(pop, "Mod3");
345 WMAddPopUpButtonItem(pop, "Mod4");
346 WMAddPopUpButtonItem(pop, "Mod5");
347 wwarning(_("could not retrieve keyboard modifier mapping"));
348 return;
351 for (j = 0; j < 8; j++) {
352 int idx;
353 char *array[8];
354 int a;
355 KeySym ksym;
356 int k;
357 char *ptr;
358 char *tmp;
360 a = 0;
361 memset(array, 0, sizeof(char *) * 8);
362 for (i = 0; i < mapping->max_keypermod; i++) {
363 idx = i + j * mapping->max_keypermod;
364 if (mapping->modifiermap[idx] != 0) {
365 int l;
366 for (l = 0; l < 4; l++) {
367 if (xext_xkb_supported)
368 ksym = XkbKeycodeToKeysym(dpy, mapping->modifiermap[idx], 0, l);
369 else
370 ksym = XKeycodeToKeysym(dpy, mapping->modifiermap[idx], 0);
371 if (ksym != NoSymbol)
372 break;
374 if (ksym != NoSymbol)
375 str = XKeysymToString(ksym);
376 else
377 str = NULL;
378 if (str && !strstr(str, "_Lock") && !strstr(str, "Shift")
379 && !strstr(str, "Control")) {
380 array[a++] = wstrdup(str);
385 for (k = 0; k < a; k++) {
386 if (array[k] == NULL)
387 continue;
388 tmp = wstrdup(array[k]);
389 ptr = strstr(tmp, "_L");
390 if (ptr)
391 *ptr = 0;
392 ptr = strstr(tmp, "_R");
393 if (ptr)
394 *ptr = 0;
395 sprintf(buffer, "%s (%s)", modifierNames[j], tmp);
396 /*sprintf(buffer, "%s", tmp); */
397 WMAddPopUpButtonItem(pop, buffer);
398 for (i = k + 1; i < a; i++) {
399 if (array[i] == NULL)
400 continue;
401 if (strstr(array[i], tmp)) {
402 wfree(array[i]);
403 array[i] = NULL;
404 break;
407 wfree(tmp);
410 while (--a > 0) {
411 if (array[a])
412 wfree(array[a]);
416 if (mapping)
417 XFreeModifiermap(mapping);
420 static void createPanel(Panel * p)
422 _Panel *panel = (_Panel *) p;
423 WMScreen *scr = WMWidgetScreen(panel->parent);
424 WMPixmap *icon;
425 char *buf1, *buf2;
426 int i;
427 RColor color;
428 char *path;
430 color.red = 0xae;
431 color.green = 0xaa;
432 color.blue = 0xae;
434 panel->box = WMCreateBox(panel->parent);
435 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
437 /**************** Mouse Speed ****************/
438 panel->speedF = WMCreateFrame(panel->box);
439 WMResizeWidget(panel->speedF, 245, 100);
440 WMMoveWidget(panel->speedF, 15, 5);
441 WMSetFrameTitle(panel->speedF, _("Mouse Speed"));
443 panel->speedL = WMCreateLabel(panel->speedF);
444 WMResizeWidget(panel->speedL, 40, 46);
445 WMMoveWidget(panel->speedL, 15, 14);
446 WMSetLabelImagePosition(panel->speedL, WIPImageOnly);
447 path = LocateImage(SPEED_ICON_FILE);
448 if (path) {
449 icon = WMCreateBlendedPixmapFromFile(scr, path, &color);
450 if (icon) {
451 WMSetLabelImage(panel->speedL, icon);
452 WMReleasePixmap(icon);
453 } else {
454 wwarning(_("could not load icon %s"), path);
456 wfree(path);
459 panel->speedS = WMCreateSlider(panel->speedF);
460 WMResizeWidget(panel->speedS, 160, 15);
461 WMMoveWidget(panel->speedS, 70, 35);
462 WMSetSliderMinValue(panel->speedS, 0);
463 WMSetSliderMaxValue(panel->speedS, 40);
464 WMSetSliderContinuous(panel->speedS, False);
465 WMSetSliderAction(panel->speedS, speedChange, panel);
467 panel->acceL = WMCreateLabel(panel->speedF);
468 WMResizeWidget(panel->acceL, 70, 16);
469 WMMoveWidget(panel->acceL, 10, 67);
470 WMSetLabelTextAlignment(panel->acceL, WARight);
471 WMSetLabelText(panel->acceL, _("Acceler.:"));
473 panel->acceT = WMCreateTextField(panel->speedF);
474 WMResizeWidget(panel->acceT, 40, 20);
475 WMMoveWidget(panel->acceT, 80, 65);
476 WMAddNotificationObserver(returnPressed, panel, WMTextDidEndEditingNotification, panel->acceT);
478 panel->threL = WMCreateLabel(panel->speedF);
479 WMResizeWidget(panel->threL, 80, 16);
480 WMMoveWidget(panel->threL, 120, 67);
481 WMSetLabelTextAlignment(panel->threL, WARight);
482 WMSetLabelText(panel->threL, _("Threshold:"));
484 panel->threT = WMCreateTextField(panel->speedF);
485 WMResizeWidget(panel->threT, 30, 20);
486 WMMoveWidget(panel->threT, 200, 65);
487 WMAddNotificationObserver(returnPressed, panel, WMTextDidEndEditingNotification, panel->threT);
489 WMMapSubwidgets(panel->speedF);
491 /***************** Doubleclick Delay ****************/
493 panel->ddelaF = WMCreateFrame(panel->box);
494 WMResizeWidget(panel->ddelaF, 245, 105);
495 WMMoveWidget(panel->ddelaF, 15, 115);
496 WMSetFrameTitle(panel->ddelaF, _("Double-Click Delay"));
498 buf1 = wmalloc(strlen(DELAY_ICON) + 2);
499 buf2 = wmalloc(strlen(DELAY_ICON_S) + 2);
501 for (i = 0; i < 5; i++) {
502 panel->ddelaB[i] = WMCreateCustomButton(panel->ddelaF, WBBStateChangeMask);
503 WMResizeWidget(panel->ddelaB[i], 25, 25);
504 WMMoveWidget(panel->ddelaB[i], 30 + (40 * i), 25);
505 WMSetButtonBordered(panel->ddelaB[i], False);
506 WMSetButtonImagePosition(panel->ddelaB[i], WIPImageOnly);
507 WMSetButtonAction(panel->ddelaB[i], doubleClick, panel);
508 if (i > 0) {
509 WMGroupButtons(panel->ddelaB[0], panel->ddelaB[i]);
511 sprintf(buf1, DELAY_ICON, i + 1);
512 sprintf(buf2, DELAY_ICON_S, i + 1);
513 path = LocateImage(buf1);
514 if (path) {
515 icon = WMCreatePixmapFromFile(scr, path);
516 if (icon) {
517 WMSetButtonImage(panel->ddelaB[i], icon);
518 WMReleasePixmap(icon);
519 } else {
520 wwarning(_("could not load icon file %s"), path);
522 wfree(path);
524 path = LocateImage(buf2);
525 if (path) {
526 icon = WMCreatePixmapFromFile(scr, path);
527 if (icon) {
528 WMSetButtonAltImage(panel->ddelaB[i], icon);
529 WMReleasePixmap(icon);
530 } else {
531 wwarning(_("could not load icon file %s"), path);
533 wfree(path);
536 wfree(buf1);
537 wfree(buf2);
539 panel->tester = CreateDoubleTest(panel->ddelaF, _("Test"));
540 WMResizeWidget(panel->tester, 84, 29);
541 WMMoveWidget(panel->tester, 35, 60);
543 panel->ddelaT = WMCreateTextField(panel->ddelaF);
544 WMResizeWidget(panel->ddelaT, 40, 20);
545 WMMoveWidget(panel->ddelaT, 140, 65);
547 panel->ddelaL = WMCreateLabel(panel->ddelaF);
548 WMResizeWidget(panel->ddelaL, 40, 16);
549 WMMoveWidget(panel->ddelaL, 185, 70);
551 WMFont *font;
552 WMColor *color;
554 font = WMSystemFontOfSize(scr, 10);
555 color = WMDarkGrayColor(scr);
556 WMSetLabelTextColor(panel->ddelaL, color);
557 WMSetLabelFont(panel->ddelaL, font);
558 WMReleaseFont(font);
559 WMReleaseColor(color);
561 WMSetLabelText(panel->ddelaL, _("msec"));
563 WMMapSubwidgets(panel->ddelaF);
565 /* ************** Workspace Action Buttons **************** */
566 panel->menuF = WMCreateFrame(panel->box);
567 WMResizeWidget(panel->menuF, 240, 160);
568 WMMoveWidget(panel->menuF, 270, 5);
569 WMSetFrameTitle(panel->menuF, _("Workspace Mouse Actions"));
571 panel->disaB = WMCreateSwitchButton(panel->menuF);
572 WMResizeWidget(panel->disaB, 205, 18);
573 WMMoveWidget(panel->disaB, 10, 18);
574 WMSetButtonText(panel->disaB, _("Disable mouse actions"));
576 panel->button1L = WMCreateLabel(panel->menuF);
577 WMResizeWidget(panel->button1L, 87, 20);
578 WMMoveWidget(panel->button1L, 5, 45);
579 WMSetLabelTextAlignment(panel->button1L, WARight);
580 WMSetLabelText(panel->button1L, _("Left Button"));
582 panel->button1P = WMCreatePopUpButton(panel->menuF);
583 WMResizeWidget(panel->button1P, 135, 20);
584 WMMoveWidget(panel->button1P, 95, 45);
586 panel->button2L = WMCreateLabel(panel->menuF);
587 WMResizeWidget(panel->button2L, 87, 20);
588 WMMoveWidget(panel->button2L, 5, 73);
589 WMSetLabelTextAlignment(panel->button2L, WARight);
590 WMSetLabelText(panel->button2L, _("Middle Button"));
592 panel->button2P = WMCreatePopUpButton(panel->menuF);
593 WMResizeWidget(panel->button2P, 135, 20);
594 WMMoveWidget(panel->button2P, 95, 73);
596 panel->button3L = WMCreateLabel(panel->menuF);
597 WMResizeWidget(panel->button3L, 87, 20);
598 WMMoveWidget(panel->button3L, 5, 101);
599 WMSetLabelTextAlignment(panel->button3L, WARight);
600 WMSetLabelText(panel->button3L, _("Right Button"));
602 panel->button3P = WMCreatePopUpButton(panel->menuF);
603 WMResizeWidget(panel->button3P, 135, 20);
604 WMMoveWidget(panel->button3P, 95, 101);
606 panel->wheelL = WMCreateLabel(panel->menuF);
607 WMResizeWidget(panel->wheelL, 87, 20);
608 WMMoveWidget(panel->wheelL, 5, 129);
609 WMSetLabelTextAlignment(panel->wheelL, WARight);
610 WMSetLabelText(panel->wheelL, _("Mouse Wheel"));
612 panel->wheelP = WMCreatePopUpButton(panel->menuF);
613 WMResizeWidget(panel->wheelP, 135, 20);
614 WMMoveWidget(panel->wheelP, 95, 129);
616 for (i = 0; i < wlengthof(buttonActions); i++) {
617 WMAddPopUpButtonItem(panel->button1P, buttonActions[i]);
618 WMAddPopUpButtonItem(panel->button2P, buttonActions[i]);
619 WMAddPopUpButtonItem(panel->button3P, buttonActions[i]);
622 for (i = 0; i < wlengthof(wheelActions); i++) {
623 WMAddPopUpButtonItem(panel->wheelP, wheelActions[i]);
626 WMMapSubwidgets(panel->menuF);
628 /* ************** Grab Modifier **************** */
629 panel->grabF = WMCreateFrame(panel->box);
630 WMResizeWidget(panel->grabF, 240, 50);
631 WMMoveWidget(panel->grabF, 270, 170);
632 WMSetFrameTitle(panel->grabF, _("Mouse Grab Modifier"));
634 WMSetBalloonTextForView(_("Keyboard modifier to use for actions that\n"
635 "involve dragging windows with the mouse,\n"
636 "clicking inside the window."), WMWidgetView(panel->grabF));
638 panel->grabP = WMCreatePopUpButton(panel->grabF);
639 WMResizeWidget(panel->grabP, 160, 20);
640 WMMoveWidget(panel->grabP, 40, 20);
642 fillModifierPopUp(panel->grabP);
644 WMMapSubwidgets(panel->grabF);
646 WMRealizeWidget(panel->box);
647 WMMapSubwidgets(panel->box);
649 showData(panel);
652 static void storeCommandInScript(const char *cmd, const char *line)
654 char *path;
655 FILE *f;
656 char buffer[128];
658 path = wstrconcat(wusergnusteppath(), "/Library/WindowMaker/autostart");
660 f = fopen(path, "rb");
661 if (!f) {
662 f = fopen(path, "wb");
663 if (!f) {
664 werror(_("could not create %s"), path);
665 goto end;
667 fprintf(f, "#!/bin/sh\n");
668 fputs(line, f);
669 fputs("\n", f);
670 } else {
671 int len = strlen(cmd);
672 int ok = 0;
673 char *tmppath;
674 FILE *fo;
676 tmppath = wstrconcat(wusergnusteppath(), "/Library/WindowMaker/autostart.tmp");
677 fo = fopen(tmppath, "wb");
678 if (!fo) {
679 werror(_("could not create temporary file %s"), tmppath);
680 wfree(tmppath);
681 goto end;
684 while (!feof(f)) {
685 if (!fgets(buffer, 127, f)) {
686 break;
688 if (buffer[0] == '\n') {
689 /* don't write empty lines, else the file will grow
690 * indefinitely (one '\n' added at end of file on each save).
692 continue;
694 if (strncmp(buffer, cmd, len) == 0) {
695 if (!ok) {
696 fputs(line, fo);
697 fputs("\n", fo);
698 ok = 1;
700 } else {
701 fputs(buffer, fo);
704 if (!ok) {
705 fputs(line, fo);
706 fputs("\n", fo);
708 fsync(fileno(fo));
709 fclose(fo);
711 if (rename(tmppath, path) != 0) {
712 werror(_("could not rename file %s to %s"), tmppath, path);
714 wfree(tmppath);
716 sprintf(buffer, "chmod u+x %s", path);
717 system(buffer);
719 end:
720 wfree(path);
721 if (f) {
722 fsync(fileno(f)); /* this may be rw */
723 fclose(f);
727 static void storeData(_Panel * panel)
729 char buffer[64];
730 int i;
731 char *tmp, *p;
732 static char *button[4] = { "None", "OpenApplicationsMenu", "OpenWindowListMenu", "SelectWindows" };
733 static char *wheel[2] = { "None", "SwitchWorkspaces" };
734 WMUserDefaults *udb = WMGetStandardUserDefaults();
736 if (!WMGetUDBoolForKey(udb, "NoXSetStuff")) {
737 tmp = WMGetTextFieldText(panel->threT);
738 if (strlen(tmp) == 0) {
739 wfree(tmp);
740 tmp = wstrdup("4");
743 sprintf(buffer, XSET " m %i/%i %s\n", (int)(panel->acceleration * 10), 10, tmp);
744 storeCommandInScript(XSET " m", buffer);
746 wfree(tmp);
749 tmp = WMGetTextFieldText(panel->ddelaT);
750 if (sscanf(tmp, "%i", &i) == 1 && i > 0)
751 SetIntegerForKey(i, "DoubleClickTime");
753 SetBoolForKey(WMGetButtonSelected(panel->disaB), "DisableWSMouseActions");
755 i = WMGetPopUpButtonSelectedItem(panel->button1P);
756 SetStringForKey(button[i], "MouseLeftButtonAction");
758 i = WMGetPopUpButtonSelectedItem(panel->button2P);
759 SetStringForKey(button[i], "MouseMiddleButtonAction");
761 i = WMGetPopUpButtonSelectedItem(panel->button3P);
762 SetStringForKey(button[i], "MouseRightButtonAction");
764 i = WMGetPopUpButtonSelectedItem(panel->wheelP);
765 SetStringForKey(wheel[i], "MouseWheelAction");
767 tmp = WMGetPopUpButtonItem(panel->grabP, WMGetPopUpButtonSelectedItem(panel->grabP));
768 tmp = wstrdup(tmp);
769 p = strchr(tmp, ' ');
770 *p = 0;
772 SetStringForKey(tmp, "ModifierKey");
774 wfree(tmp);
777 Panel *InitMouseSettings(WMWidget *parent)
779 _Panel *panel;
781 modifierNames[0] = wstrdup(_("Shift"));
782 modifierNames[1] = wstrdup(_("Lock"));
783 modifierNames[2] = wstrdup(_("Control"));
784 modifierNames[3] = wstrdup(_("Mod1"));
785 modifierNames[4] = wstrdup(_("Mod2"));
786 modifierNames[5] = wstrdup(_("Mod3"));
787 modifierNames[6] = wstrdup(_("Mod4"));
788 modifierNames[7] = wstrdup(_("Mod5"));
790 buttonActions[0] = wstrdup(_("None"));
791 buttonActions[1] = wstrdup(_("Applications Menu"));
792 buttonActions[2] = wstrdup(_("Window List Menu"));
793 buttonActions[3] = wstrdup(_("Select Windows"));
795 wheelActions[0] = wstrdup(_("None"));
796 wheelActions[1] = wstrdup(_("Switch Workspaces"));
798 panel = wmalloc(sizeof(_Panel));
800 panel->sectionName = _("Mouse Preferences");
802 panel->description = _("Mouse speed/acceleration, double click delay,\n" "mouse button bindings etc.");
804 panel->parent = parent;
806 panel->callbacks.createWidgets = createPanel;
807 panel->callbacks.updateDomain = storeData;
809 AddSection(panel, ICON_FILE);
811 return panel;