Update Serbian translation from master branch
[wmaker-crm.git] / WPrefs.app / MouseSettings.c
blobd15d7a45d58f27a551fb779c03004c66929f0c12
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.25F) / 0.25F);
303 panel->acceleration = accel;
304 sprintf(buffer, "%.2f", (double)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 ksym = W_KeycodeToKeysym(dpy, mapping->modifiermap[idx], l);
385 if (ksym != NoSymbol)
386 break;
388 if (ksym != NoSymbol)
389 str = XKeysymToString(ksym);
390 else
391 str = NULL;
392 if (str && !strstr(str, "_Lock") && !strstr(str, "Shift")
393 && !strstr(str, "Control")) {
394 array[a++] = wstrdup(str);
399 for (k = 0; k < a; k++) {
400 if (array[k] == NULL)
401 continue;
402 tmp = wstrdup(array[k]);
403 ptr = strstr(tmp, "_L");
404 if (ptr)
405 *ptr = 0;
406 ptr = strstr(tmp, "_R");
407 if (ptr)
408 *ptr = 0;
409 sprintf(buffer, "%s (%s)", modifierNames[j], tmp);
410 /*sprintf(buffer, "%s", tmp); */
411 WMAddPopUpButtonItem(pop, buffer);
412 for (i = k + 1; i < a; i++) {
413 if (array[i] == NULL)
414 continue;
415 if (strstr(array[i], tmp)) {
416 wfree(array[i]);
417 array[i] = NULL;
418 break;
421 wfree(tmp);
424 while (--a > 0) {
425 if (array[a])
426 wfree(array[a]);
430 if (mapping)
431 XFreeModifiermap(mapping);
434 static void createPanel(Panel * p)
436 _Panel *panel = (_Panel *) p;
437 WMScreen *scr = WMWidgetScreen(panel->parent);
438 WMPixmap *icon;
439 char *buf1, *buf2;
440 int i;
441 RColor color;
442 char *path;
444 color.red = 0xae;
445 color.green = 0xaa;
446 color.blue = 0xae;
448 panel->box = WMCreateBox(panel->parent);
449 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
451 /**************** Mouse Speed ****************/
452 panel->speedF = WMCreateFrame(panel->box);
453 WMResizeWidget(panel->speedF, 219, 85);
454 WMMoveWidget(panel->speedF, 9, 54);
455 WMSetFrameTitle(panel->speedF, _("Mouse Speed"));
457 panel->speedL = WMCreateLabel(panel->speedF);
458 WMResizeWidget(panel->speedL, 40, 46);
459 WMMoveWidget(panel->speedL, 8, 10);
460 WMSetLabelImagePosition(panel->speedL, WIPImageOnly);
461 path = LocateImage(SPEED_ICON_FILE);
462 if (path) {
463 icon = WMCreateBlendedPixmapFromFile(scr, path, &color);
464 if (icon) {
465 WMSetLabelImage(panel->speedL, icon);
466 WMReleasePixmap(icon);
467 } else {
468 wwarning(_("could not load icon %s"), path);
470 wfree(path);
473 panel->speedS = WMCreateSlider(panel->speedF);
474 WMResizeWidget(panel->speedS, 150, 15);
475 WMMoveWidget(panel->speedS, 58, 30);
476 WMSetSliderMinValue(panel->speedS, 0);
477 WMSetSliderMaxValue(panel->speedS, 40);
478 WMSetSliderContinuous(panel->speedS, False);
479 WMSetSliderAction(panel->speedS, speedChange, panel);
481 panel->acceL = WMCreateLabel(panel->speedF);
482 WMResizeWidget(panel->acceL, 50, 16);
483 WMMoveWidget(panel->acceL, 8, 58);
484 WMSetLabelTextAlignment(panel->acceL, WARight);
485 WMSetLabelText(panel->acceL, _("Accel.:"));
487 panel->acceT = WMCreateTextField(panel->speedF);
488 WMResizeWidget(panel->acceT, 40, 20);
489 WMMoveWidget(panel->acceT, 58, 56);
490 WMAddNotificationObserver(returnPressed, panel, WMTextDidEndEditingNotification, panel->acceT);
492 panel->threL = WMCreateLabel(panel->speedF);
493 WMResizeWidget(panel->threL, 80, 16);
494 WMMoveWidget(panel->threL, 98, 58);
495 WMSetLabelTextAlignment(panel->threL, WARight);
496 WMSetLabelText(panel->threL, _("Threshold:"));
498 panel->threT = WMCreateTextField(panel->speedF);
499 WMResizeWidget(panel->threT, 30, 20);
500 WMMoveWidget(panel->threT, 178, 56);
501 WMAddNotificationObserver(returnPressed, panel, WMTextDidEndEditingNotification, panel->threT);
503 WMMapSubwidgets(panel->speedF);
505 /* ************** Grab Modifier **************** */
506 panel->grabF = WMCreateFrame(panel->box);
507 WMResizeWidget(panel->grabF, 219, 46);
508 WMMoveWidget(panel->grabF, 9, 5);
509 WMSetFrameTitle(panel->grabF, _("Mouse Grab Modifier"));
511 WMSetBalloonTextForView(_("Keyboard modifier to use for actions that\n"
512 "involve dragging windows with the mouse,\n"
513 "clicking inside the window."), WMWidgetView(panel->grabF));
515 panel->grabP = WMCreatePopUpButton(panel->grabF);
516 WMResizeWidget(panel->grabP, 178, 20);
517 WMMoveWidget(panel->grabP, 20, 17);
519 fillModifierPopUp(panel->grabP);
520 WMMapSubwidgets(panel->grabF);
522 /***************** Doubleclick Delay ****************/
524 panel->ddelaF = WMCreateFrame(panel->box);
525 WMResizeWidget(panel->ddelaF, 219, 80);
526 WMMoveWidget(panel->ddelaF, 9, 142);
527 WMSetFrameTitle(panel->ddelaF, _("Double-Click Delay"));
529 buf1 = wmalloc(strlen(DELAY_ICON) + 2);
530 buf2 = wmalloc(strlen(DELAY_ICON_S) + 2);
532 for (i = 0; i < wlengthof(panel->ddelaB); i++) {
533 panel->ddelaB[i] = WMCreateCustomButton(panel->ddelaF, WBBStateChangeMask);
534 WMResizeWidget(panel->ddelaB[i], 25, 25);
535 WMMoveWidget(panel->ddelaB[i], 18 + (40 * i), 18);
536 WMSetButtonBordered(panel->ddelaB[i], False);
537 WMSetButtonImagePosition(panel->ddelaB[i], WIPImageOnly);
538 WMSetButtonAction(panel->ddelaB[i], doubleClick, panel);
539 if (i > 0) {
540 WMGroupButtons(panel->ddelaB[0], panel->ddelaB[i]);
542 sprintf(buf1, DELAY_ICON, i + 1);
543 sprintf(buf2, DELAY_ICON_S, i + 1);
544 path = LocateImage(buf1);
545 if (path) {
546 icon = WMCreatePixmapFromFile(scr, path);
547 if (icon) {
548 WMSetButtonImage(panel->ddelaB[i], icon);
549 WMReleasePixmap(icon);
550 } else {
551 wwarning(_("could not load icon file %s"), path);
553 wfree(path);
555 path = LocateImage(buf2);
556 if (path) {
557 icon = WMCreatePixmapFromFile(scr, path);
558 if (icon) {
559 WMSetButtonAltImage(panel->ddelaB[i], icon);
560 WMReleasePixmap(icon);
561 } else {
562 wwarning(_("could not load icon file %s"), path);
564 wfree(path);
567 wfree(buf1);
568 wfree(buf2);
570 panel->tester = CreateDoubleTest(panel->ddelaF, _("Test"));
571 WMResizeWidget(panel->tester, 84, 24);
572 WMMoveWidget(panel->tester, 20, 48);
574 panel->ddelaT = WMCreateTextField(panel->ddelaF);
575 WMResizeWidget(panel->ddelaT, 40, 20);
576 WMMoveWidget(panel->ddelaT, 130, 50);
578 panel->ddelaL = WMCreateLabel(panel->ddelaF);
579 WMResizeWidget(panel->ddelaL, 40, 16);
580 WMMoveWidget(panel->ddelaL, 173, 54);
582 WMFont *font;
583 WMColor *color;
585 font = WMSystemFontOfSize(scr, 10);
586 color = WMDarkGrayColor(scr);
587 WMSetLabelTextColor(panel->ddelaL, color);
588 WMSetLabelFont(panel->ddelaL, font);
589 WMReleaseFont(font);
590 WMReleaseColor(color);
592 WMSetLabelText(panel->ddelaL, _("ms"));
594 WMMapSubwidgets(panel->ddelaF);
596 /* ************** Workspace Action Buttons **************** */
598 panel->menuF = WMCreateFrame(panel->box);
599 WMResizeWidget(panel->menuF, 276, 217);
600 WMMoveWidget(panel->menuF, 236, 5);
601 WMSetFrameTitle(panel->menuF, _("Workspace Mouse Actions"));
603 panel->disaB = WMCreateSwitchButton(panel->menuF);
604 WMResizeWidget(panel->disaB, 254, 18);
605 WMMoveWidget(panel->disaB, 10, 15);
606 WMSetButtonText(panel->disaB, _("Disable mouse actions"));
607 WMSetButtonAction(panel->disaB, toggle_disabling_of_mouse_actions, panel);
609 for (i = 0; i < wlengthof(button_list); i++) {
610 int j;
612 panel->mouse_action[i].label = WMCreateLabel(panel->menuF);
613 WMResizeWidget(panel->mouse_action[i].label, 115, 20);
614 WMMoveWidget(panel->mouse_action[i].label, 4, 37 + 25 * i);
615 WMSetLabelTextAlignment(panel->mouse_action[i].label, WARight);
616 WMSetLabelText(panel->mouse_action[i].label, _(button_list[i].display_label));
618 panel->mouse_action[i].popup = WMCreatePopUpButton(panel->menuF);
619 WMResizeWidget(panel->mouse_action[i].popup, 145, 20);
620 WMMoveWidget(panel->mouse_action[i].popup, 121, 37 + 25 * i);
622 if (button_list[i].type == T_BUTTON) {
623 for (j = 0; j < wlengthof(button_actions); j++)
624 WMAddPopUpButtonItem(panel->mouse_action[i].popup, _(button_actions[j].label));
625 } else {
626 for (j = 0; j < wlengthof(wheel_actions); j++)
627 WMAddPopUpButtonItem(panel->mouse_action[i].popup, _(wheel_actions[j].label));
630 WMMapSubwidgets(panel->menuF);
632 WMRealizeWidget(panel->box);
633 WMMapSubwidgets(panel->box);
635 showData(panel);
638 static void storeCommandInScript(const char *cmd, const char *line)
640 char *path;
641 FILE *f;
642 char buffer[128];
643 mode_t permissions;
645 /* Calculate permission to be Executable but taking into account user's umask */
646 permissions = umask(0);
647 umask(permissions);
648 permissions = (S_IRWXU | S_IRWXG | S_IRWXO) & (~permissions);
650 path = wstrconcat(wuserdatapath(), "/" PACKAGE_TARNAME "/autostart");
652 f = fopen(path, "rb");
653 if (!f) {
654 f = fopen(path, "wb");
655 if (!f) {
656 werror(_("could not create %s"), path);
657 goto end;
659 fprintf(f, "#!/bin/sh\n");
660 fputs(line, f);
661 fputs("\n", f);
662 } else {
663 int len = strlen(cmd);
664 int ok = 0;
665 char *tmppath;
666 FILE *fo;
668 tmppath = wstrconcat(wuserdatapath(), "/" PACKAGE_TARNAME "/autostart.tmp");
669 fo = fopen(tmppath, "wb");
670 if (!fo) {
671 werror(_("could not create temporary file %s"), tmppath);
672 wfree(tmppath);
673 goto end;
676 while (!feof(f)) {
677 if (!fgets(buffer, 127, f)) {
678 break;
680 if (buffer[0] == '\n') {
681 /* don't write empty lines, else the file will grow
682 * indefinitely (one '\n' added at end of file on each save).
684 continue;
686 if (strncmp(buffer, cmd, len) == 0) {
687 if (!ok) {
688 fputs(line, fo);
689 fputs("\n", fo);
690 ok = 1;
692 } else {
693 fputs(buffer, fo);
696 if (!ok) {
697 fputs(line, fo);
698 fputs("\n", fo);
700 fsync(fileno(fo));
701 fclose(fo);
703 if (rename(tmppath, path) != 0) {
704 werror(_("could not rename file %s to %s"), tmppath, path);
706 wfree(tmppath);
708 if (chmod(path, permissions) != 0)
709 wwarning(_("could not set permission 0%03o on file \"%s\""), permissions, path);
711 end:
712 wfree(path);
713 if (f) {
714 fsync(fileno(f)); /* this may be rw */
715 fclose(f);
719 static void storeData(_Panel * panel)
721 char buffer[64];
722 int i;
723 char *tmp, *p;
724 WMUserDefaults *udb = WMGetStandardUserDefaults();
726 if (!WMGetUDBoolForKey(udb, "NoXSetStuff")) {
727 tmp = WMGetTextFieldText(panel->threT);
728 if (strlen(tmp) == 0) {
729 wfree(tmp);
730 tmp = wstrdup("4");
733 sprintf(buffer, XSET " m %i/%i %s\n", (int)(panel->acceleration * 10), 10, tmp);
734 storeCommandInScript(XSET " m", buffer);
736 wfree(tmp);
739 tmp = WMGetTextFieldText(panel->ddelaT);
740 if (sscanf(tmp, "%i", &i) == 1 && i > 0)
741 SetIntegerForKey(i, "DoubleClickTime");
742 wfree(tmp);
744 SetBoolForKey(WMGetButtonSelected(panel->disaB), "DisableWSMouseActions");
746 for (i = 0; i < wlengthof(button_list); i++) {
747 const char *db_value;
748 int action;
750 action = WMGetPopUpButtonSelectedItem(panel->mouse_action[i].popup);
751 if (action < 0)
752 continue;
753 if (button_list[i].type == T_BUTTON)
754 db_value = button_actions[action].db_value;
755 else
756 db_value = wheel_actions[action].db_value;
757 SetStringForKey(db_value, button_list[i].db_key);
760 tmp = WMGetPopUpButtonItem(panel->grabP, WMGetPopUpButtonSelectedItem(panel->grabP));
761 tmp = wstrdup(tmp);
762 p = strchr(tmp, ' ');
763 if (p != NULL)
764 *p = '\0';
766 SetStringForKey(tmp, "ModifierKey");
768 wfree(tmp);
771 Panel *InitMouseSettings(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 panel = wmalloc(sizeof(_Panel));
786 panel->sectionName = _("Mouse Preferences");
788 panel->description = _("Mouse speed/acceleration, double click delay,\n" "mouse button bindings etc.");
790 panel->parent = parent;
792 panel->callbacks.createWidgets = createPanel;
793 panel->callbacks.updateDomain = storeData;
795 AddSection(panel, ICON_FILE);
797 return panel;