wmaker: remove constants HORIZONTAL and VERTICAL from moveres.c
[wmaker-crm.git] / WPrefs.app / MouseSettings.c
blob6df930090d91f63169e47bc46d0a740dc8f743fb
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 <sys/types.h>
30 #include <sys/stat.h>
31 #include <math.h>
34 #define XSET "xset"
37 static const struct {
38 const char *db_key;
39 int default_action;
40 enum { T_BUTTON, T_WHEEL } type;
41 const char *display_label;
42 } button_list[] = {
43 { "MouseLeftButtonAction", 3, T_BUTTON, N_("Left Button") },
44 { "MouseMiddleButtonAction", 2, T_BUTTON, N_("Middle Button") },
45 { "MouseRightButtonAction", 1, T_BUTTON, N_("Right Button") },
46 { "MouseBackwardButtonAction", 0, T_BUTTON, N_("Back Button") },
47 { "MouseForwardButtonAction", 0, T_BUTTON, N_("Forward Button") },
48 { "MouseWheelAction", 0, T_WHEEL, N_("Mouse Wheel") },
49 { "MouseWheelTiltAction", 0, T_WHEEL, N_("Mouse Wheel Tilt") }
52 static const struct {
53 const char *db_value;
54 const char *label;
55 } button_actions[] = {
56 { "None", N_("None") },
57 { "OpenApplicationsMenu", N_("Applications Menu") },
58 { "OpenWindowListMenu", N_("Window List Menu") },
59 { "SelectWindows", N_("Select Windows") },
60 { "MoveToPrevWorkspace", N_("Previous Workspace") },
61 { "MoveToNextWorkspace", N_("Next Workspace") },
62 { "MoveToPrevWindow", N_("Previous Window") },
63 { "MoveToNextWindow", N_("Next Window") }
66 static const struct {
67 const char *db_value;
68 const char *label;
69 } wheel_actions[] = {
70 { "None", N_("None") },
71 { "SwitchWorkspaces", N_("Switch Workspaces") },
72 { "SwitchWindows", N_("Switch Windows") }
75 typedef struct _Panel {
76 WMBox *box;
78 char *sectionName;
80 char *description;
82 CallbackRec callbacks;
84 WMWidget *parent;
86 WMFrame *speedF;
87 WMLabel *speedL;
88 WMSlider *speedS;
89 WMLabel *acceL;
90 WMTextField *acceT;
91 WMLabel *threL;
92 WMTextField *threT;
94 WMFrame *ddelaF;
95 WMButton *ddelaB[5];
96 WMTextField *ddelaT;
97 WMLabel *ddelaL;
98 DoubleTest *tester;
100 WMFrame *menuF;
101 struct {
102 WMLabel *label;
103 WMPopUpButton *popup;
104 } mouse_action[wlengthof_nocheck(button_list)];
106 WMButton *disaB;
108 WMFrame *grabF;
109 WMPopUpButton *grabP;
111 /**/ int maxThreshold;
112 float acceleration;
113 } _Panel;
115 #define ICON_FILE "mousesettings"
117 #define SPEED_ICON_FILE "mousespeed"
119 #define DELAY_ICON "timer%i"
120 #define DELAY_ICON_S "timer%is"
122 /* need access to the double click variables */
123 #include <WINGs/WINGsP.h>
125 static char *modifierNames[8];
127 #define DELAY(i) ((i)*75+170)
130 static void setMouseAccel(WMScreen * scr, float accel, int threshold)
132 int n, d;
134 d = 10;
135 n = accel * d;
137 XChangePointerControl(WMScreenDisplay(scr), True, True, n, d, threshold);
140 static void speedChange(WMWidget * w, void *data)
142 _Panel *panel = (_Panel *) data;
143 int i;
144 char buffer[64];
145 int threshold;
146 char *tmp;
148 if (w == NULL) {
149 float accel;
151 tmp = WMGetTextFieldText(panel->acceT);
152 if (sscanf(tmp, "%f", &accel) != 1 || accel < 0) {
153 WMRunAlertPanel(WMWidgetScreen(panel->acceT), GetWindow(),
154 _("Error"),
155 _("Invalid mouse acceleration value. Must be a positive real value."),
156 _("OK"), NULL, NULL);
157 wfree(tmp);
158 return;
160 panel->acceleration = accel;
161 wfree(tmp);
162 } else {
163 i = (int)WMGetSliderValue(panel->speedS);
165 panel->acceleration = 0.25 + (i * 0.25);
167 sprintf(buffer, "%.2f", 0.25 + (i * 0.25));
168 WMSetTextFieldText(panel->acceT, buffer);
171 tmp = WMGetTextFieldText(panel->threT);
172 if (sscanf(tmp, "%i", &threshold) != 1 || threshold < 0 || threshold > panel->maxThreshold) {
173 WMRunAlertPanel(WMWidgetScreen(panel->parent), GetWindow(), _("Error"),
175 ("Invalid mouse acceleration threshold value. Must be the number of pixels to travel before accelerating."),
176 _("OK"), NULL, NULL);
177 } else {
178 setMouseAccel(WMWidgetScreen(panel->parent), panel->acceleration, threshold);
180 wfree(tmp);
183 static void returnPressed(void *observerData, WMNotification * notification)
185 _Panel *panel = (_Panel *) observerData;
187 /* Parameter not used, but tell the compiler that it is ok */
188 (void) notification;
190 speedChange(NULL, panel);
193 static void toggle_disabling_of_mouse_actions(WMWidget *w, void *client_data)
195 WMButton *button = (WMButton *) w;
196 Panel *panel = (Panel *) client_data;
197 Bool do_enable;
198 int i;
200 if (WMGetButtonSelected(button))
201 do_enable = False;
202 else
203 do_enable = True;
205 for (i = 0; i < wlengthof(panel->mouse_action); i++)
206 WMSetPopUpButtonEnabled(panel->mouse_action[i].popup, do_enable);
209 static void doubleClick(WMWidget * w, void *data)
211 _Panel *panel = (_Panel *) data;
212 int i;
213 char buffer[32];
215 for (i = 0; i < wlengthof(panel->ddelaB); i++) {
216 if (panel->ddelaB[i] == w)
217 break;
219 WINGsConfiguration.doubleClickDelay = DELAY(i);
221 sprintf(buffer, "%i", DELAY(i));
222 WMSetTextFieldText(panel->ddelaT, buffer);
225 static int getButtonAction(const char *str)
227 int i;
229 if (!str)
230 return -2;
232 for (i = 0; i < wlengthof(button_actions); i++) {
233 if (strcasecmp(str, button_actions[i].db_value) == 0)
234 return i;
237 return -1;
240 static int getWheelAction(const char *str)
242 int i;
244 if (!str)
245 return -2;
247 for (i = 0; i < wlengthof(wheel_actions); i++) {
248 if (strcasecmp(str, wheel_actions[i].db_value) == 0)
249 return i;
252 return -1;
255 static void getMouseParameters(Display * dpy, float *accel, int *thre)
257 int n, d;
259 XGetPointerControl(dpy, &n, &d, thre);
261 *accel = (float)n / (float)d;
264 static void showData(_Panel * panel)
266 char *str;
267 int i;
268 int a = -1, b = -1;
269 float accel;
270 char buffer[32];
271 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->parent));
273 for (i = 0; i < wlengthof(button_list); i++) {
274 int action;
276 str = GetStringForKey(button_list[i].db_key);
277 if (button_list[i].type == T_BUTTON)
278 action = getButtonAction(str);
279 else
280 action = getWheelAction(str);
282 if (action < 0) {
283 if (action == -1)
284 wwarning(_("bad value %s for option %s"), str, button_list[i].db_key);
285 action = button_list[i].default_action;
287 WMSetPopUpButtonSelectedItem(panel->mouse_action[i].popup, action);
290 WMSetButtonSelected(panel->disaB, GetBoolForKey("DisableWSMouseActions"));
291 toggle_disabling_of_mouse_actions(panel->disaB, panel);
293 /**/ getMouseParameters(dpy, &accel, &a);
294 panel->maxThreshold = WidthOfScreen(DefaultScreenOfDisplay(dpy));
295 if (a > panel->maxThreshold) {
296 panel->maxThreshold = a;
298 sprintf(buffer, "%i", a);
299 WMSetTextFieldText(panel->threT, buffer);
301 WMSetSliderValue(panel->speedS, (accel - 0.25) / 0.25);
303 panel->acceleration = accel;
304 sprintf(buffer, "%.2f", accel);
305 WMSetTextFieldText(panel->acceT, buffer);
307 /**/ b = GetIntegerForKey("DoubleClickTime");
308 /* find best match */
309 a = -1;
310 for (i = 0; i < wlengthof(panel->ddelaB); i++) {
311 if (DELAY(i) == b)
312 a = i;
314 if (a >= 0)
315 WMPerformButtonClick(panel->ddelaB[a]);
316 sprintf(buffer, "%i", b);
317 WMSetTextFieldText(panel->ddelaT, buffer);
319 /**/ str = GetStringForKey("ModifierKey");
320 if (!str)
321 str = "mod1";
322 a = ModifierFromKey(dpy, str);
324 if (a != -1) {
325 str = modifierNames[a];
327 a = 0;
328 for (i = 0; i < WMGetPopUpButtonNumberOfItems(panel->grabP); i++) {
329 if (strstr(WMGetPopUpButtonItem(panel->grabP, i), str)) {
330 WMSetPopUpButtonSelectedItem(panel->grabP, i);
331 a = 1;
332 break;
337 if (a < 1) {
338 char *previous;
340 previous = WMGetPopUpButtonItem(panel->grabP, 0);
341 if (previous != NULL)
342 WMSetPopUpButtonSelectedItem(panel->grabP, 0);
343 wwarning(_("modifier key %s for option ModifierKey was not recognized. Using %s as default"),
344 str, previous?previous:"(empty)");
348 static void fillModifierPopUp(WMPopUpButton * pop)
350 XModifierKeymap *mapping;
351 Display *dpy = WMScreenDisplay(WMWidgetScreen(pop));
352 int i, j;
353 char *str;
354 char buffer[64];
356 mapping = XGetModifierMapping(dpy);
358 if (!mapping || mapping->max_keypermod == 0) {
359 WMAddPopUpButtonItem(pop, "Mod1");
360 WMAddPopUpButtonItem(pop, "Mod2");
361 WMAddPopUpButtonItem(pop, "Mod3");
362 WMAddPopUpButtonItem(pop, "Mod4");
363 WMAddPopUpButtonItem(pop, "Mod5");
364 wwarning(_("could not retrieve keyboard modifier mapping"));
365 return;
368 for (j = 0; j < 8; j++) {
369 int idx;
370 char *array[8];
371 int a;
372 KeySym ksym;
373 int k;
374 char *ptr;
375 char *tmp;
377 a = 0;
378 memset(array, 0, sizeof(char *) * 8);
379 for (i = 0; i < mapping->max_keypermod; i++) {
380 idx = i + j * mapping->max_keypermod;
381 if (mapping->modifiermap[idx] != 0) {
382 int l;
383 for (l = 0; l < 4; l++) {
384 if (xext_xkb_supported)
385 ksym = XkbKeycodeToKeysym(dpy, mapping->modifiermap[idx], 0, l);
386 else
387 ksym = XKeycodeToKeysym(dpy, mapping->modifiermap[idx], 0);
388 if (ksym != NoSymbol)
389 break;
391 if (ksym != NoSymbol)
392 str = XKeysymToString(ksym);
393 else
394 str = NULL;
395 if (str && !strstr(str, "_Lock") && !strstr(str, "Shift")
396 && !strstr(str, "Control")) {
397 array[a++] = wstrdup(str);
402 for (k = 0; k < a; k++) {
403 if (array[k] == NULL)
404 continue;
405 tmp = wstrdup(array[k]);
406 ptr = strstr(tmp, "_L");
407 if (ptr)
408 *ptr = 0;
409 ptr = strstr(tmp, "_R");
410 if (ptr)
411 *ptr = 0;
412 sprintf(buffer, "%s (%s)", modifierNames[j], tmp);
413 /*sprintf(buffer, "%s", tmp); */
414 WMAddPopUpButtonItem(pop, buffer);
415 for (i = k + 1; i < a; i++) {
416 if (array[i] == NULL)
417 continue;
418 if (strstr(array[i], tmp)) {
419 wfree(array[i]);
420 array[i] = NULL;
421 break;
424 wfree(tmp);
427 while (--a > 0) {
428 if (array[a])
429 wfree(array[a]);
433 if (mapping)
434 XFreeModifiermap(mapping);
437 static void createPanel(Panel * p)
439 _Panel *panel = (_Panel *) p;
440 WMScreen *scr = WMWidgetScreen(panel->parent);
441 WMPixmap *icon;
442 char *buf1, *buf2;
443 int i;
444 RColor color;
445 char *path;
447 color.red = 0xae;
448 color.green = 0xaa;
449 color.blue = 0xae;
451 panel->box = WMCreateBox(panel->parent);
452 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
454 /**************** Mouse Speed ****************/
455 panel->speedF = WMCreateFrame(panel->box);
456 WMResizeWidget(panel->speedF, 219, 85);
457 WMMoveWidget(panel->speedF, 9, 54);
458 WMSetFrameTitle(panel->speedF, _("Mouse Speed"));
460 panel->speedL = WMCreateLabel(panel->speedF);
461 WMResizeWidget(panel->speedL, 40, 46);
462 WMMoveWidget(panel->speedL, 8, 10);
463 WMSetLabelImagePosition(panel->speedL, WIPImageOnly);
464 path = LocateImage(SPEED_ICON_FILE);
465 if (path) {
466 icon = WMCreateBlendedPixmapFromFile(scr, path, &color);
467 if (icon) {
468 WMSetLabelImage(panel->speedL, icon);
469 WMReleasePixmap(icon);
470 } else {
471 wwarning(_("could not load icon %s"), path);
473 wfree(path);
476 panel->speedS = WMCreateSlider(panel->speedF);
477 WMResizeWidget(panel->speedS, 150, 15);
478 WMMoveWidget(panel->speedS, 58, 30);
479 WMSetSliderMinValue(panel->speedS, 0);
480 WMSetSliderMaxValue(panel->speedS, 40);
481 WMSetSliderContinuous(panel->speedS, False);
482 WMSetSliderAction(panel->speedS, speedChange, panel);
484 panel->acceL = WMCreateLabel(panel->speedF);
485 WMResizeWidget(panel->acceL, 50, 16);
486 WMMoveWidget(panel->acceL, 8, 58);
487 WMSetLabelTextAlignment(panel->acceL, WARight);
488 WMSetLabelText(panel->acceL, _("Accel.:"));
490 panel->acceT = WMCreateTextField(panel->speedF);
491 WMResizeWidget(panel->acceT, 40, 20);
492 WMMoveWidget(panel->acceT, 58, 56);
493 WMAddNotificationObserver(returnPressed, panel, WMTextDidEndEditingNotification, panel->acceT);
495 panel->threL = WMCreateLabel(panel->speedF);
496 WMResizeWidget(panel->threL, 80, 16);
497 WMMoveWidget(panel->threL, 98, 58);
498 WMSetLabelTextAlignment(panel->threL, WARight);
499 WMSetLabelText(panel->threL, _("Threshold:"));
501 panel->threT = WMCreateTextField(panel->speedF);
502 WMResizeWidget(panel->threT, 30, 20);
503 WMMoveWidget(panel->threT, 178, 56);
504 WMAddNotificationObserver(returnPressed, panel, WMTextDidEndEditingNotification, panel->threT);
506 WMMapSubwidgets(panel->speedF);
508 /* ************** Grab Modifier **************** */
509 panel->grabF = WMCreateFrame(panel->box);
510 WMResizeWidget(panel->grabF, 219, 46);
511 WMMoveWidget(panel->grabF, 9, 5);
512 WMSetFrameTitle(panel->grabF, _("Mouse Grab Modifier"));
514 WMSetBalloonTextForView(_("Keyboard modifier to use for actions that\n"
515 "involve dragging windows with the mouse,\n"
516 "clicking inside the window."), WMWidgetView(panel->grabF));
518 panel->grabP = WMCreatePopUpButton(panel->grabF);
519 WMResizeWidget(panel->grabP, 178, 20);
520 WMMoveWidget(panel->grabP, 20, 17);
522 fillModifierPopUp(panel->grabP);
523 WMMapSubwidgets(panel->grabF);
525 /***************** Doubleclick Delay ****************/
527 panel->ddelaF = WMCreateFrame(panel->box);
528 WMResizeWidget(panel->ddelaF, 219, 80);
529 WMMoveWidget(panel->ddelaF, 9, 142);
530 WMSetFrameTitle(panel->ddelaF, _("Double-Click Delay"));
532 buf1 = wmalloc(strlen(DELAY_ICON) + 2);
533 buf2 = wmalloc(strlen(DELAY_ICON_S) + 2);
535 for (i = 0; i < wlengthof(panel->ddelaB); i++) {
536 panel->ddelaB[i] = WMCreateCustomButton(panel->ddelaF, WBBStateChangeMask);
537 WMResizeWidget(panel->ddelaB[i], 25, 25);
538 WMMoveWidget(panel->ddelaB[i], 18 + (40 * i), 18);
539 WMSetButtonBordered(panel->ddelaB[i], False);
540 WMSetButtonImagePosition(panel->ddelaB[i], WIPImageOnly);
541 WMSetButtonAction(panel->ddelaB[i], doubleClick, panel);
542 if (i > 0) {
543 WMGroupButtons(panel->ddelaB[0], panel->ddelaB[i]);
545 sprintf(buf1, DELAY_ICON, i + 1);
546 sprintf(buf2, DELAY_ICON_S, i + 1);
547 path = LocateImage(buf1);
548 if (path) {
549 icon = WMCreatePixmapFromFile(scr, path);
550 if (icon) {
551 WMSetButtonImage(panel->ddelaB[i], icon);
552 WMReleasePixmap(icon);
553 } else {
554 wwarning(_("could not load icon file %s"), path);
556 wfree(path);
558 path = LocateImage(buf2);
559 if (path) {
560 icon = WMCreatePixmapFromFile(scr, path);
561 if (icon) {
562 WMSetButtonAltImage(panel->ddelaB[i], icon);
563 WMReleasePixmap(icon);
564 } else {
565 wwarning(_("could not load icon file %s"), path);
567 wfree(path);
570 wfree(buf1);
571 wfree(buf2);
573 panel->tester = CreateDoubleTest(panel->ddelaF, _("Test"));
574 WMResizeWidget(panel->tester, 84, 24);
575 WMMoveWidget(panel->tester, 20, 48);
577 panel->ddelaT = WMCreateTextField(panel->ddelaF);
578 WMResizeWidget(panel->ddelaT, 40, 20);
579 WMMoveWidget(panel->ddelaT, 130, 50);
581 panel->ddelaL = WMCreateLabel(panel->ddelaF);
582 WMResizeWidget(panel->ddelaL, 40, 16);
583 WMMoveWidget(panel->ddelaL, 173, 54);
585 WMFont *font;
586 WMColor *color;
588 font = WMSystemFontOfSize(scr, 10);
589 color = WMDarkGrayColor(scr);
590 WMSetLabelTextColor(panel->ddelaL, color);
591 WMSetLabelFont(panel->ddelaL, font);
592 WMReleaseFont(font);
593 WMReleaseColor(color);
595 WMSetLabelText(panel->ddelaL, _("ms"));
597 WMMapSubwidgets(panel->ddelaF);
599 /* ************** Workspace Action Buttons **************** */
601 panel->menuF = WMCreateFrame(panel->box);
602 WMResizeWidget(panel->menuF, 276, 217);
603 WMMoveWidget(panel->menuF, 236, 5);
604 WMSetFrameTitle(panel->menuF, _("Workspace Mouse Actions"));
606 panel->disaB = WMCreateSwitchButton(panel->menuF);
607 WMResizeWidget(panel->disaB, 254, 18);
608 WMMoveWidget(panel->disaB, 10, 15);
609 WMSetButtonText(panel->disaB, _("Disable mouse actions"));
610 WMSetButtonAction(panel->disaB, toggle_disabling_of_mouse_actions, panel);
612 for (i = 0; i < wlengthof(button_list); i++) {
613 int j;
615 panel->mouse_action[i].label = WMCreateLabel(panel->menuF);
616 WMResizeWidget(panel->mouse_action[i].label, 115, 20);
617 WMMoveWidget(panel->mouse_action[i].label, 4, 37 + 25 * i);
618 WMSetLabelTextAlignment(panel->mouse_action[i].label, WARight);
619 WMSetLabelText(panel->mouse_action[i].label, _(button_list[i].display_label));
621 panel->mouse_action[i].popup = WMCreatePopUpButton(panel->menuF);
622 WMResizeWidget(panel->mouse_action[i].popup, 145, 20);
623 WMMoveWidget(panel->mouse_action[i].popup, 121, 37 + 25 * i);
625 if (button_list[i].type == T_BUTTON) {
626 for (j = 0; j < wlengthof(button_actions); j++)
627 WMAddPopUpButtonItem(panel->mouse_action[i].popup, _(button_actions[j].label));
628 } else {
629 for (j = 0; j < wlengthof(wheel_actions); j++)
630 WMAddPopUpButtonItem(panel->mouse_action[i].popup, _(wheel_actions[j].label));
633 WMMapSubwidgets(panel->menuF);
635 WMRealizeWidget(panel->box);
636 WMMapSubwidgets(panel->box);
638 showData(panel);
641 static void storeCommandInScript(const char *cmd, const char *line)
643 char *path;
644 FILE *f;
645 char buffer[128];
646 mode_t permissions;
648 /* Calculate permission to be Executable but taking into account user's umask */
649 permissions = umask(0);
650 umask(permissions);
651 permissions = (S_IRWXU | S_IRWXG | S_IRWXO) & (~permissions);
653 path = wstrconcat(wusergnusteppath(), "/Library/WindowMaker/autostart");
655 f = fopen(path, "rb");
656 if (!f) {
657 f = fopen(path, "wb");
658 if (!f) {
659 werror(_("could not create %s"), path);
660 goto end;
662 fprintf(f, "#!/bin/sh\n");
663 fputs(line, f);
664 fputs("\n", f);
665 } else {
666 int len = strlen(cmd);
667 int ok = 0;
668 char *tmppath;
669 FILE *fo;
671 tmppath = wstrconcat(wusergnusteppath(), "/Library/WindowMaker/autostart.tmp");
672 fo = fopen(tmppath, "wb");
673 if (!fo) {
674 werror(_("could not create temporary file %s"), tmppath);
675 wfree(tmppath);
676 goto end;
679 while (!feof(f)) {
680 if (!fgets(buffer, 127, f)) {
681 break;
683 if (buffer[0] == '\n') {
684 /* don't write empty lines, else the file will grow
685 * indefinitely (one '\n' added at end of file on each save).
687 continue;
689 if (strncmp(buffer, cmd, len) == 0) {
690 if (!ok) {
691 fputs(line, fo);
692 fputs("\n", fo);
693 ok = 1;
695 } else {
696 fputs(buffer, fo);
699 if (!ok) {
700 fputs(line, fo);
701 fputs("\n", fo);
703 fsync(fileno(fo));
704 fclose(fo);
706 if (rename(tmppath, path) != 0) {
707 werror(_("could not rename file %s to %s"), tmppath, path);
709 wfree(tmppath);
711 if (chmod(path, permissions) != 0)
712 wwarning(_("could not set permission 0%03o on file \"%s\""), permissions, path);
714 end:
715 wfree(path);
716 if (f) {
717 fsync(fileno(f)); /* this may be rw */
718 fclose(f);
722 static void storeData(_Panel * panel)
724 char buffer[64];
725 int i;
726 char *tmp, *p;
727 WMUserDefaults *udb = WMGetStandardUserDefaults();
729 if (!WMGetUDBoolForKey(udb, "NoXSetStuff")) {
730 tmp = WMGetTextFieldText(panel->threT);
731 if (strlen(tmp) == 0) {
732 wfree(tmp);
733 tmp = wstrdup("4");
736 sprintf(buffer, XSET " m %i/%i %s\n", (int)(panel->acceleration * 10), 10, tmp);
737 storeCommandInScript(XSET " m", buffer);
739 wfree(tmp);
742 tmp = WMGetTextFieldText(panel->ddelaT);
743 if (sscanf(tmp, "%i", &i) == 1 && i > 0)
744 SetIntegerForKey(i, "DoubleClickTime");
745 wfree(tmp);
747 SetBoolForKey(WMGetButtonSelected(panel->disaB), "DisableWSMouseActions");
749 for (i = 0; i < wlengthof(button_list); i++) {
750 const char *db_value;
751 int action;
753 action = WMGetPopUpButtonSelectedItem(panel->mouse_action[i].popup);
754 if (button_list[i].type == T_BUTTON)
755 db_value = button_actions[action].db_value;
756 else
757 db_value = wheel_actions[action].db_value;
758 SetStringForKey(db_value, button_list[i].db_key);
761 tmp = WMGetPopUpButtonItem(panel->grabP, WMGetPopUpButtonSelectedItem(panel->grabP));
762 tmp = wstrdup(tmp);
763 p = strchr(tmp, ' ');
764 if (p != NULL)
765 *p = '\0';
767 SetStringForKey(tmp, "ModifierKey");
769 wfree(tmp);
772 Panel *InitMouseSettings(WMWidget *parent)
774 _Panel *panel;
776 modifierNames[0] = wstrdup(_("Shift"));
777 modifierNames[1] = wstrdup(_("Lock"));
778 modifierNames[2] = wstrdup(_("Control"));
779 modifierNames[3] = wstrdup(_("Mod1"));
780 modifierNames[4] = wstrdup(_("Mod2"));
781 modifierNames[5] = wstrdup(_("Mod3"));
782 modifierNames[6] = wstrdup(_("Mod4"));
783 modifierNames[7] = wstrdup(_("Mod5"));
785 panel = wmalloc(sizeof(_Panel));
787 panel->sectionName = _("Mouse Preferences");
789 panel->description = _("Mouse speed/acceleration, double click delay,\n" "mouse button bindings etc.");
791 panel->parent = parent;
793 panel->callbacks.createWidgets = createPanel;
794 panel->callbacks.updateDomain = storeData;
796 AddSection(panel, ICON_FILE);
798 return panel;