WPrefs: Cleaned dangerous function prototype usage
[wmaker-crm.git] / WPrefs.app / MouseSettings.c
blobbebf9f5d5ce6a889b46131b3161b8d544038d367
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 sscanf(WMGetPopUpButtonItem(panel->grabP, 0), "%s", buffer);
319 WMSetPopUpButtonSelectedItem(panel->grabP, 0);
320 wwarning(_("modifier key %s for option ModifierKey was not recognized. Using %s as default"),
321 str, buffer);
325 static void fillModifierPopUp(WMPopUpButton * pop)
327 XModifierKeymap *mapping;
328 Display *dpy = WMScreenDisplay(WMWidgetScreen(pop));
329 int i, j;
330 char *str;
331 char buffer[64];
333 mapping = XGetModifierMapping(dpy);
335 if (!mapping || mapping->max_keypermod == 0) {
336 WMAddPopUpButtonItem(pop, "Mod1");
337 WMAddPopUpButtonItem(pop, "Mod2");
338 WMAddPopUpButtonItem(pop, "Mod3");
339 WMAddPopUpButtonItem(pop, "Mod4");
340 WMAddPopUpButtonItem(pop, "Mod5");
341 wwarning(_("could not retrieve keyboard modifier mapping"));
342 return;
345 for (j = 0; j < 8; j++) {
346 int idx;
347 char *array[8];
348 int a;
349 KeySym ksym;
350 int k;
351 char *ptr;
352 char *tmp;
354 a = 0;
355 memset(array, 0, sizeof(char *) * 8);
356 for (i = 0; i < mapping->max_keypermod; i++) {
357 idx = i + j * mapping->max_keypermod;
358 if (mapping->modifiermap[idx] != 0) {
359 int l;
360 for (l = 0; l < 4; l++) {
361 ksym = XkbKeycodeToKeysym(dpy, mapping->modifiermap[idx], 0, l);
362 if (ksym != NoSymbol)
363 break;
365 if (ksym != NoSymbol)
366 str = XKeysymToString(ksym);
367 else
368 str = NULL;
369 if (str && !strstr(str, "_Lock") && !strstr(str, "Shift")
370 && !strstr(str, "Control")) {
371 array[a++] = wstrdup(str);
376 for (k = 0; k < a; k++) {
377 if (array[k] == NULL)
378 continue;
379 tmp = wstrdup(array[k]);
380 ptr = strstr(tmp, "_L");
381 if (ptr)
382 *ptr = 0;
383 ptr = strstr(tmp, "_R");
384 if (ptr)
385 *ptr = 0;
386 sprintf(buffer, "%s (%s)", modifierNames[j], tmp);
387 /*sprintf(buffer, "%s", tmp); */
388 WMAddPopUpButtonItem(pop, buffer);
389 for (i = k + 1; i < a; i++) {
390 if (array[i] == NULL)
391 continue;
392 if (strstr(array[i], tmp)) {
393 wfree(array[i]);
394 array[i] = NULL;
395 break;
398 wfree(tmp);
401 while (--a > 0) {
402 if (array[a])
403 wfree(array[a]);
407 if (mapping)
408 XFreeModifiermap(mapping);
411 static void createPanel(Panel * p)
413 _Panel *panel = (_Panel *) p;
414 WMScreen *scr = WMWidgetScreen(panel->parent);
415 WMPixmap *icon;
416 char *buf1, *buf2;
417 int i;
418 RColor color;
419 char *path;
421 color.red = 0xae;
422 color.green = 0xaa;
423 color.blue = 0xae;
425 panel->box = WMCreateBox(panel->parent);
426 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
428 /**************** Mouse Speed ****************/
429 panel->speedF = WMCreateFrame(panel->box);
430 WMResizeWidget(panel->speedF, 245, 100);
431 WMMoveWidget(panel->speedF, 15, 5);
432 WMSetFrameTitle(panel->speedF, _("Mouse Speed"));
434 panel->speedL = WMCreateLabel(panel->speedF);
435 WMResizeWidget(panel->speedL, 40, 46);
436 WMMoveWidget(panel->speedL, 15, 14);
437 WMSetLabelImagePosition(panel->speedL, WIPImageOnly);
438 path = LocateImage(SPEED_ICON_FILE);
439 if (path) {
440 icon = WMCreateBlendedPixmapFromFile(scr, path, &color);
441 if (icon) {
442 WMSetLabelImage(panel->speedL, icon);
443 WMReleasePixmap(icon);
444 } else {
445 wwarning(_("could not load icon %s"), path);
447 wfree(path);
450 panel->speedS = WMCreateSlider(panel->speedF);
451 WMResizeWidget(panel->speedS, 160, 15);
452 WMMoveWidget(panel->speedS, 70, 35);
453 WMSetSliderMinValue(panel->speedS, 0);
454 WMSetSliderMaxValue(panel->speedS, 40);
455 WMSetSliderContinuous(panel->speedS, False);
456 WMSetSliderAction(panel->speedS, speedChange, panel);
458 panel->acceL = WMCreateLabel(panel->speedF);
459 WMResizeWidget(panel->acceL, 70, 16);
460 WMMoveWidget(panel->acceL, 10, 67);
461 WMSetLabelTextAlignment(panel->acceL, WARight);
462 WMSetLabelText(panel->acceL, _("Acceler.:"));
464 panel->acceT = WMCreateTextField(panel->speedF);
465 WMResizeWidget(panel->acceT, 40, 20);
466 WMMoveWidget(panel->acceT, 80, 65);
467 WMAddNotificationObserver(returnPressed, panel, WMTextDidEndEditingNotification, panel->acceT);
469 panel->threL = WMCreateLabel(panel->speedF);
470 WMResizeWidget(panel->threL, 80, 16);
471 WMMoveWidget(panel->threL, 120, 67);
472 WMSetLabelTextAlignment(panel->threL, WARight);
473 WMSetLabelText(panel->threL, _("Threshold:"));
475 panel->threT = WMCreateTextField(panel->speedF);
476 WMResizeWidget(panel->threT, 30, 20);
477 WMMoveWidget(panel->threT, 200, 65);
478 WMAddNotificationObserver(returnPressed, panel, WMTextDidEndEditingNotification, panel->threT);
480 WMMapSubwidgets(panel->speedF);
482 /***************** Doubleclick Delay ****************/
484 panel->ddelaF = WMCreateFrame(panel->box);
485 WMResizeWidget(panel->ddelaF, 245, 105);
486 WMMoveWidget(panel->ddelaF, 15, 115);
487 WMSetFrameTitle(panel->ddelaF, _("Double-Click Delay"));
489 buf1 = wmalloc(strlen(DELAY_ICON) + 2);
490 buf2 = wmalloc(strlen(DELAY_ICON_S) + 2);
492 for (i = 0; i < 5; i++) {
493 panel->ddelaB[i] = WMCreateCustomButton(panel->ddelaF, WBBStateChangeMask);
494 WMResizeWidget(panel->ddelaB[i], 25, 25);
495 WMMoveWidget(panel->ddelaB[i], 30 + (40 * i), 25);
496 WMSetButtonBordered(panel->ddelaB[i], False);
497 WMSetButtonImagePosition(panel->ddelaB[i], WIPImageOnly);
498 WMSetButtonAction(panel->ddelaB[i], doubleClick, panel);
499 if (i > 0) {
500 WMGroupButtons(panel->ddelaB[0], panel->ddelaB[i]);
502 sprintf(buf1, DELAY_ICON, i + 1);
503 sprintf(buf2, DELAY_ICON_S, i + 1);
504 path = LocateImage(buf1);
505 if (path) {
506 icon = WMCreatePixmapFromFile(scr, path);
507 if (icon) {
508 WMSetButtonImage(panel->ddelaB[i], icon);
509 WMReleasePixmap(icon);
510 } else {
511 wwarning(_("could not load icon file %s"), path);
513 wfree(path);
515 path = LocateImage(buf2);
516 if (path) {
517 icon = WMCreatePixmapFromFile(scr, path);
518 if (icon) {
519 WMSetButtonAltImage(panel->ddelaB[i], icon);
520 WMReleasePixmap(icon);
521 } else {
522 wwarning(_("could not load icon file %s"), path);
524 wfree(path);
527 wfree(buf1);
528 wfree(buf2);
530 panel->tester = CreateDoubleTest(panel->ddelaF, _("Test"));
531 WMResizeWidget(panel->tester, 84, 29);
532 WMMoveWidget(panel->tester, 35, 60);
534 panel->ddelaT = WMCreateTextField(panel->ddelaF);
535 WMResizeWidget(panel->ddelaT, 40, 20);
536 WMMoveWidget(panel->ddelaT, 140, 65);
538 panel->ddelaL = WMCreateLabel(panel->ddelaF);
539 WMResizeWidget(panel->ddelaL, 40, 16);
540 WMMoveWidget(panel->ddelaL, 185, 70);
542 WMFont *font;
543 WMColor *color;
545 font = WMSystemFontOfSize(scr, 10);
546 color = WMDarkGrayColor(scr);
547 WMSetLabelTextColor(panel->ddelaL, color);
548 WMSetLabelFont(panel->ddelaL, font);
549 WMReleaseFont(font);
550 WMReleaseColor(color);
552 WMSetLabelText(panel->ddelaL, _("msec"));
554 WMMapSubwidgets(panel->ddelaF);
556 /* ************** Workspace Action Buttons **************** */
557 panel->menuF = WMCreateFrame(panel->box);
558 WMResizeWidget(panel->menuF, 240, 160);
559 WMMoveWidget(panel->menuF, 270, 5);
560 WMSetFrameTitle(panel->menuF, _("Workspace Mouse Actions"));
562 panel->disaB = WMCreateSwitchButton(panel->menuF);
563 WMResizeWidget(panel->disaB, 205, 18);
564 WMMoveWidget(panel->disaB, 10, 18);
565 WMSetButtonText(panel->disaB, _("Disable mouse actions"));
567 panel->button1L = WMCreateLabel(panel->menuF);
568 WMResizeWidget(panel->button1L, 87, 20);
569 WMMoveWidget(panel->button1L, 5, 45);
570 WMSetLabelTextAlignment(panel->button1L, WARight);
571 WMSetLabelText(panel->button1L, _("Left Button"));
573 panel->button1P = WMCreatePopUpButton(panel->menuF);
574 WMResizeWidget(panel->button1P, 135, 20);
575 WMMoveWidget(panel->button1P, 95, 45);
577 panel->button2L = WMCreateLabel(panel->menuF);
578 WMResizeWidget(panel->button2L, 87, 20);
579 WMMoveWidget(panel->button2L, 5, 73);
580 WMSetLabelTextAlignment(panel->button2L, WARight);
581 WMSetLabelText(panel->button2L, _("Middle Button"));
583 panel->button2P = WMCreatePopUpButton(panel->menuF);
584 WMResizeWidget(panel->button2P, 135, 20);
585 WMMoveWidget(panel->button2P, 95, 73);
587 panel->button3L = WMCreateLabel(panel->menuF);
588 WMResizeWidget(panel->button3L, 87, 20);
589 WMMoveWidget(panel->button3L, 5, 101);
590 WMSetLabelTextAlignment(panel->button3L, WARight);
591 WMSetLabelText(panel->button3L, _("Right Button"));
593 panel->button3P = WMCreatePopUpButton(panel->menuF);
594 WMResizeWidget(panel->button3P, 135, 20);
595 WMMoveWidget(panel->button3P, 95, 101);
597 panel->wheelL = WMCreateLabel(panel->menuF);
598 WMResizeWidget(panel->wheelL, 87, 20);
599 WMMoveWidget(panel->wheelL, 5, 129);
600 WMSetLabelTextAlignment(panel->wheelL, WARight);
601 WMSetLabelText(panel->wheelL, _("Mouse Wheel"));
603 panel->wheelP = WMCreatePopUpButton(panel->menuF);
604 WMResizeWidget(panel->wheelP, 135, 20);
605 WMMoveWidget(panel->wheelP, 95, 129);
607 for (i = 0; i < sizeof(buttonActions) / sizeof(buttonActions[0]); i++) {
608 WMAddPopUpButtonItem(panel->button1P, buttonActions[i]);
609 WMAddPopUpButtonItem(panel->button2P, buttonActions[i]);
610 WMAddPopUpButtonItem(panel->button3P, buttonActions[i]);
613 for (i = 0; i < sizeof(wheelActions) / sizeof(wheelActions[0]); i++) {
614 WMAddPopUpButtonItem(panel->wheelP, wheelActions[i]);
617 WMMapSubwidgets(panel->menuF);
619 /* ************** Grab Modifier **************** */
620 panel->grabF = WMCreateFrame(panel->box);
621 WMResizeWidget(panel->grabF, 240, 50);
622 WMMoveWidget(panel->grabF, 270, 170);
623 WMSetFrameTitle(panel->grabF, _("Mouse Grab Modifier"));
625 WMSetBalloonTextForView(_("Keyboard modifier to use for actions that\n"
626 "involve dragging windows with the mouse,\n"
627 "clicking inside the window."), WMWidgetView(panel->grabF));
629 panel->grabP = WMCreatePopUpButton(panel->grabF);
630 WMResizeWidget(panel->grabP, 160, 20);
631 WMMoveWidget(panel->grabP, 40, 20);
633 fillModifierPopUp(panel->grabP);
635 WMMapSubwidgets(panel->grabF);
637 WMRealizeWidget(panel->box);
638 WMMapSubwidgets(panel->box);
640 showData(panel);
643 static void storeCommandInScript(const char *cmd, const char *line)
645 char *path;
646 FILE *f;
647 char buffer[128];
649 path = wstrconcat(wusergnusteppath(), "/Library/WindowMaker/autostart");
651 f = fopen(path, "rb");
652 if (!f) {
653 f = fopen(path, "wb");
654 if (!f) {
655 werror(_("could not create %s"), path);
656 goto end;
658 fprintf(f, "#!/bin/sh\n");
659 fputs(line, f);
660 fputs("\n", f);
661 } else {
662 int len = strlen(cmd);
663 int ok = 0;
664 char *tmppath;
665 FILE *fo;
667 tmppath = wstrconcat(wusergnusteppath(), "/Library/WindowMaker/autostart.tmp");
668 fo = fopen(tmppath, "wb");
669 if (!fo) {
670 werror(_("could not create temporary file %s"), tmppath);
671 wfree(tmppath);
672 goto end;
675 while (!feof(f)) {
676 if (!fgets(buffer, 127, f)) {
677 break;
679 if (buffer[0] == '\n') {
680 /* don't write empty lines, else the file will grow
681 * indefinitely (one '\n' added at end of file on each save).
683 continue;
685 if (strncmp(buffer, cmd, len) == 0) {
686 if (!ok) {
687 fputs(line, fo);
688 fputs("\n", fo);
689 ok = 1;
691 } else {
692 fputs(buffer, fo);
695 if (!ok) {
696 fputs(line, fo);
697 fputs("\n", fo);
699 fsync(fileno(fo));
700 fclose(fo);
702 if (rename(tmppath, path) != 0) {
703 werror(_("could not rename file %s to %s"), tmppath, path);
705 wfree(tmppath);
707 sprintf(buffer, "chmod u+x %s", path);
708 system(buffer);
710 end:
711 wfree(path);
712 if (f) {
713 fsync(fileno(f)); /* this may be rw */
714 fclose(f);
718 static void storeData(_Panel * panel)
720 char buffer[64];
721 int i;
722 char *tmp, *p;
723 static char *button[4] = { "None", "OpenApplicationsMenu", "OpenWindowListMenu", "SelectWindows" };
724 static char *wheel[2] = { "None", "SwitchWorkspaces" };
725 WMUserDefaults *udb = WMGetStandardUserDefaults();
727 if (!WMGetUDBoolForKey(udb, "NoXSetStuff")) {
728 tmp = WMGetTextFieldText(panel->threT);
729 if (strlen(tmp) == 0) {
730 wfree(tmp);
731 tmp = wstrdup("4");
734 sprintf(buffer, XSET " m %i/%i %s\n", (int)(panel->acceleration * 10), 10, tmp);
735 storeCommandInScript(XSET " m", buffer);
737 wfree(tmp);
740 tmp = WMGetTextFieldText(panel->ddelaT);
741 if (sscanf(tmp, "%i", &i) == 1 && i > 0)
742 SetIntegerForKey(i, "DoubleClickTime");
744 SetBoolForKey(WMGetButtonSelected(panel->disaB), "DisableWSMouseActions");
746 i = WMGetPopUpButtonSelectedItem(panel->button1P);
747 SetStringForKey(button[i], "MouseLeftButtonAction");
749 i = WMGetPopUpButtonSelectedItem(panel->button2P);
750 SetStringForKey(button[i], "MouseMiddleButtonAction");
752 i = WMGetPopUpButtonSelectedItem(panel->button3P);
753 SetStringForKey(button[i], "MouseRightButtonAction");
755 i = WMGetPopUpButtonSelectedItem(panel->wheelP);
756 SetStringForKey(wheel[i], "MouseWheelAction");
758 tmp = WMGetPopUpButtonItem(panel->grabP, WMGetPopUpButtonSelectedItem(panel->grabP));
759 tmp = wstrdup(tmp);
760 p = strchr(tmp, ' ');
761 *p = 0;
763 SetStringForKey(tmp, "ModifierKey");
765 wfree(tmp);
768 Panel *InitMouseSettings(WMScreen * scr, WMWidget * parent)
770 _Panel *panel;
772 modifierNames[0] = wstrdup(_("Shift"));
773 modifierNames[1] = wstrdup(_("Lock"));
774 modifierNames[2] = wstrdup(_("Control"));
775 modifierNames[3] = wstrdup(_("Mod1"));
776 modifierNames[4] = wstrdup(_("Mod2"));
777 modifierNames[5] = wstrdup(_("Mod3"));
778 modifierNames[6] = wstrdup(_("Mod4"));
779 modifierNames[7] = wstrdup(_("Mod5"));
781 buttonActions[0] = wstrdup(_("None"));
782 buttonActions[1] = wstrdup(_("Applications Menu"));
783 buttonActions[2] = wstrdup(_("Window List Menu"));
784 buttonActions[3] = wstrdup(_("Select Windows"));
786 wheelActions[0] = wstrdup(_("None"));
787 wheelActions[1] = wstrdup(_("Switch Workspaces"));
789 panel = wmalloc(sizeof(_Panel));
791 panel->sectionName = _("Mouse Preferences");
793 panel->description = _("Mouse speed/acceleration, double click delay,\n" "mouse button bindings etc.");
795 panel->parent = parent;
797 panel->callbacks.createWidgets = createPanel;
798 panel->callbacks.updateDomain = storeData;
800 AddSection(panel, ICON_FILE);
802 return panel;