Update for 0.51.2-pre2
[wmaker-crm.git] / WPrefs.app / MouseSettings.c
blobfed3f0c427c23b49a934de3f034f47caa429abab
1 /* MouseSettings.c- mouse options (some are equivalent to xset)
2 *
3 * WPrefs - Window Maker Preferences Program
4 *
5 * Copyright (c) 1998 Alfredo K. Kojima
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
24 #include "WPrefs.h"
26 #include <X11/Xutil.h>
28 #include <math.h>
30 /* double-click tester */
31 #include "double.h"
35 #define XSET "xset"
39 typedef struct _Panel {
40 WMFrame *frame;
42 char *sectionName;
44 CallbackRec callbacks;
46 WMWindow *win;
48 WMFrame *speedF;
49 WMLabel *speedL;
50 WMButton *speedB[5];
51 WMLabel *acceL;
52 WMTextField *acceT;
53 WMLabel *threL;
54 WMTextField *threT;
56 WMFrame *ddelaF;
57 WMButton *ddelaB[5];
58 WMTextField *ddelaT;
59 WMLabel *ddelaL;
60 DoubleTest *tester;
62 WMFrame *menuF;
63 WMLabel *listL;
64 WMLabel *appL;
65 WMLabel *selL;
66 WMLabel *mblL;
67 WMLabel *mbmL;
68 WMLabel *mbrL;
69 WMButton *lmb[3];
70 WMButton *amb[3];
71 WMButton *smb[3];
74 WMButton *disaB;
76 WMFrame *grabF;
77 WMPopUpButton *grabP;
79 /**/
80 WMButton *lastClickedSpeed;
81 int maxThreshold;
82 float acceleration;
83 } _Panel;
86 #define ICON_FILE "mousesettings"
88 #define SPEED_ICON_FILE "mousespeed"
89 #define SPEED_IMAGE "speed%i"
90 #define SPEED_IMAGE_S "speed%is"
92 #define DELAY_ICON "timer%i"
93 #define DELAY_ICON_S "timer%is"
95 #define MOUSEB_L "minimouseleft"
96 #define MOUSEB_M "minimousemiddle"
97 #define MOUSEB_R "minimouseright"
99 /* need access to the double click variables */
100 #include "WINGsP.h"
104 static char *modifierNames[] = {
105 "Shift",
106 "Lock",
107 "Control",
108 "Mod1",
109 "Mod2",
110 "Mod3",
111 "Mod4",
112 "Mod5"
116 #define DELAY(i) ((i)*75+170)
119 int ModifierFromKey(Display *dpy, char *key);
122 static void
123 setMouseAccel(WMScreen *scr, float accel, int threshold)
125 int n, d;
127 d = 10;
128 n = accel*d;
130 XChangePointerControl(WMScreenDisplay(scr), True, True, n, d, threshold);
134 static void
135 speedClick(WMWidget *w, void *data)
137 _Panel *panel = (_Panel*)data;
138 int i;
139 char buffer[64];
140 int threshold;
141 char *tmp;
143 if (w == NULL) {
144 float accel;
146 tmp = WMGetTextFieldText(panel->acceT);
147 if (sscanf(tmp, "%f", &accel)!=1 || accel < 0) {
148 WMRunAlertPanel(WMWidgetScreen(panel->acceT), GetWindow(panel),
149 _("Error"),
150 _("Invalid mouse acceleration value. Must be a positive real value."),
151 _("OK"), NULL, NULL);
152 free(tmp);
153 return;
155 panel->acceleration = accel;
156 free(tmp);
157 } else {
158 for (i=0; i<5; i++) {
159 if (panel->speedB[i]==w)
160 break;
163 panel->acceleration = 0.5+(i*0.5);
165 sprintf(buffer, "%.2f", 0.5+(i*0.5));
166 WMSetTextFieldText(panel->acceT, buffer);
169 tmp = WMGetTextFieldText(panel->threT);
170 if (sscanf(tmp, "%i", &threshold)!=1 || threshold < 0
171 || threshold > panel->maxThreshold) {
172 WMRunAlertPanel(WMWidgetScreen(panel->win), GetWindow(panel), _("Error"),
173 _("Invalid mouse acceleration threshold value. Must be the number of pixels to travel before accelerating."),
174 _("OK"), NULL, NULL);
175 } else {
176 setMouseAccel(WMWidgetScreen(panel->win), panel->acceleration,
177 threshold);
179 free(tmp);
183 static void
184 returnPressed(void *observerData, WMNotification *notification)
186 _Panel *panel = (_Panel*)observerData;
188 speedClick(NULL, panel);
192 static void
193 doubleClick(WMWidget *w, void *data)
195 _Panel *panel = (_Panel*)data;
196 int i;
197 extern _WINGsConfiguration WINGsConfiguration;
198 char buffer[32];
200 for (i=0; i<5; i++) {
201 if (panel->ddelaB[i]==w)
202 break;
204 WINGsConfiguration.doubleClickDelay = DELAY(i);
206 sprintf(buffer, "%i", DELAY(i));
207 WMSetTextFieldText(panel->ddelaT, buffer);
213 getbutton(char *str)
215 if (!str)
216 return -2;
218 if (strcasecmp(str, "left")==0)
219 return 0;
220 else if (strcasecmp(str, "middle")==0)
221 return 1;
222 else if (strcasecmp(str, "right")==0)
223 return 2;
224 else if (strcasecmp(str, "button1")==0)
225 return 0;
226 else if (strcasecmp(str, "button2")==0)
227 return 1;
228 else if (strcasecmp(str, "button3")==0)
229 return 2;
230 else if (strcasecmp(str, "button4")==0
231 || strcasecmp(str, "button5")==0) {
232 wwarning(_("mouse button %s not supported by WPrefs."), str);
233 return -2;
234 } else {
235 return -1;
240 static void
241 getMouseParameters(Display *dpy, float *accel, int *thre)
243 int n, d;
245 XGetPointerControl(dpy, &n, &d, thre);
247 *accel = (float)n/(float)d;
252 static void
253 showData(_Panel *panel)
255 char *str;
256 int i;
257 int a=-1, b=-1, c=-1;
258 float accel;
259 char buffer[32];
260 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
262 str = GetStringForKey("SelectWindowsMouseButton");
263 if (!str)
264 str = "left";
265 i = getbutton(str);
266 if (i==-1) {
267 a = 0;
268 wwarning(_("bad value %s for option %s"),str, "SelectWindowsMouseButton");
269 WMPerformButtonClick(panel->smb[0]);
270 } else if (i>=0) {
271 a = i;
272 WMPerformButtonClick(panel->smb[i]);
275 str = GetStringForKey("WindowListMouseButton");
276 if (!str)
277 str = "middle";
278 i = getbutton(str);
279 if (i==-1) {
280 b = 0;
281 wwarning(_("bad value %s for option %s"), str, "WindowListMouseButton");
282 WMPerformButtonClick(panel->lmb[1]);
283 } else if (i>=0) {
284 b = i;
285 WMPerformButtonClick(panel->lmb[i]);
288 str = GetStringForKey("ApplicationMenuMouseButton");
289 if (!str)
290 str = "right";
291 i = getbutton(str);
292 if (i==-1) {
293 c = 0;
294 wwarning(_("bad value %s for option %s"), str, "ApplicationMenuMouseButton");
295 WMPerformButtonClick(panel->amb[2]);
296 } else if (i>=0) {
297 c = i;
298 WMPerformButtonClick(panel->amb[i]);
302 WMSetButtonSelected(panel->disaB, GetBoolForKey("DisableWSMouseActions"));
304 /**/
305 getMouseParameters(dpy, &accel, &a);
306 panel->maxThreshold = WidthOfScreen(DefaultScreenOfDisplay(dpy));
307 if (a > panel->maxThreshold) {
308 panel->maxThreshold = a;
310 sprintf(buffer, "%i", a);
311 WMSetTextFieldText(panel->threT, buffer);
313 a = -1;
314 for (i=0; i<5; i++) {
315 if (0.5+(float)i*0.5 == accel)
316 a = i;
318 if (a >= 0) {
319 WMPerformButtonClick(panel->speedB[a]);
320 panel->lastClickedSpeed = panel->speedB[a];
322 panel->acceleration = accel;
323 sprintf(buffer, "%.2f", accel);
324 WMSetTextFieldText(panel->acceT, buffer);
326 speedClick(panel->lastClickedSpeed, panel);
327 /**/
328 b = GetIntegerForKey("DoubleClickTime");
329 /* find best match */
330 a = -1;
331 for (i=0; i<5; i++) {
332 if (DELAY(i) == b)
333 a = i;
335 if (a >= 0)
336 WMPerformButtonClick(panel->ddelaB[a]);
337 sprintf(buffer, "%i", b);
338 WMSetTextFieldText(panel->ddelaT, buffer);
340 /**/
341 str = GetStringForKey("ModifierKey");
342 if (!str)
343 str = "mod1";
344 a = ModifierFromKey(dpy, str);
346 if (a != -1) {
347 str = modifierNames[a];
349 a = 0;
350 for (i=0; i<WMGetPopUpButtonNumberOfItems(panel->grabP); i++) {
351 if (strstr(WMGetPopUpButtonItem(panel->grabP, i), str)) {
352 WMSetPopUpButtonSelectedItem(panel->grabP, i);
353 a = 1;
354 break;
359 if (a < 1) {
360 sscanf(WMGetPopUpButtonItem(panel->grabP, 0), "%s", buffer);
361 WMSetPopUpButtonSelectedItem(panel->grabP, 0);
362 wwarning(_("modifier key %s for option ModifierKey was not recognized. Using %s as default"),
363 str, buffer);
369 static void
370 fillModifierPopUp(WMPopUpButton *pop)
372 XModifierKeymap *mapping;
373 Display *dpy = WMScreenDisplay(WMWidgetScreen(pop));
374 int i, j;
375 char *str;
376 char buffer[64];
379 mapping = XGetModifierMapping(dpy);
381 if (!mapping || mapping->max_keypermod==0) {
382 WMAddPopUpButtonItem(pop, "Mod1");
383 WMAddPopUpButtonItem(pop, "Mod2");
384 WMAddPopUpButtonItem(pop, "Mod3");
385 WMAddPopUpButtonItem(pop, "Mod4");
386 WMAddPopUpButtonItem(pop, "Mod5");
387 wwarning(_("could not retrieve keyboard modifier mapping"));
388 return;
392 for (j=0; j<8; j++) {
393 int idx;
394 char *array[8];
395 int a;
396 KeySym ksym;
397 int k;
398 char *ptr;
399 char *tmp;
401 a = 0;
402 memset(array, 0, sizeof(char*)*8);
403 for (i=0; i < mapping->max_keypermod; i++) {
404 idx = i+j*mapping->max_keypermod;
405 if (mapping->modifiermap[idx]!=0) {
406 int l;
407 for (l=0; l<4; l++) {
408 ksym = XKeycodeToKeysym(dpy, mapping->modifiermap[idx], l);
409 if (ksym!=NoSymbol)
410 break;
412 if (ksym!=NoSymbol)
413 str = XKeysymToString(ksym);
414 else
415 str = NULL;
416 if (str && !strstr(str, "_Lock") && !strstr(str, "Shift")
417 && !strstr(str, "Control")) {
418 array[a++] = wstrdup(str);
423 for (k=0; k<a; k++) {
424 if (array[k]==NULL)
425 continue;
426 tmp = wstrdup(array[k]);
427 ptr = strstr(tmp, "_L");
428 if (ptr)
429 *ptr = 0;
430 ptr = strstr(tmp, "_R");
431 if (ptr)
432 *ptr = 0;
433 sprintf(buffer, "%s (%s)", modifierNames[j], tmp);
434 WMAddPopUpButtonItem(pop, buffer);
435 for (i=k+1; i<a; i++) {
436 if (strstr(array[i], tmp)) {
437 free(array[i]);
438 array[i]=NULL;
439 break;
442 free(tmp);
445 while (--a>0) {
446 if (array[a])
447 free(array[a]);
451 if (mapping)
452 XFreeModifiermap(mapping);
457 static void
458 mouseButtonClickA(WMWidget *w, void *data)
460 _Panel *panel = (_Panel*)data;
461 int i;
463 for (i=0; i<3; i++) {
464 if (panel->amb[i]==w)
465 break;
467 if (i==3)
468 return;
469 if (WMGetButtonSelected(panel->lmb[i]))
470 WMSetButtonSelected(panel->lmb[i], False);
471 if (WMGetButtonSelected(panel->smb[i]))
472 WMSetButtonSelected(panel->smb[i], False);
475 static void
476 mouseButtonClickL(WMWidget *w, void *data)
478 _Panel *panel = (_Panel*)data;
479 int i;
481 for (i=0; i<3; i++) {
482 if (panel->lmb[i]==w)
483 break;
485 if (i==3)
486 return;
487 if (WMGetButtonSelected(panel->smb[i]))
488 WMSetButtonSelected(panel->smb[i], False);
489 if (WMGetButtonSelected(panel->amb[i]))
490 WMSetButtonSelected(panel->amb[i], False);
493 static void
494 mouseButtonClickS(WMWidget *w, void *data)
496 _Panel *panel = (_Panel*)data;
497 int i;
499 for (i=0; i<3; i++) {
500 if (panel->smb[i]==w)
501 break;
503 if (i==3)
504 return;
505 if (WMGetButtonSelected(panel->lmb[i]))
506 WMSetButtonSelected(panel->lmb[i], False);
507 if (WMGetButtonSelected(panel->amb[i]))
508 WMSetButtonSelected(panel->amb[i], False);
511 static void
512 createPanel(Panel *p)
514 _Panel *panel = (_Panel*)p;
515 WMScreen *scr = WMWidgetScreen(panel->win);
516 WMPixmap *icon;
517 char *buf1, *buf2;
518 int i;
519 RColor color;
520 char *path;
522 color.red = 0xaa;
523 color.green = 0xae;
524 color.blue = 0xaa;
526 panel->frame = WMCreateFrame(panel->win);
527 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
528 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
530 /**************** Mouse Speed ****************/
531 panel->speedF = WMCreateFrame(panel->frame);
532 WMResizeWidget(panel->speedF, 245, 100);
533 WMMoveWidget(panel->speedF, 15, 15);
534 WMSetFrameTitle(panel->speedF, _("Mouse Speed"));
536 panel->speedL = WMCreateLabel(panel->speedF);
537 WMResizeWidget(panel->speedL, 40, 46);
538 WMMoveWidget(panel->speedL, 15, 14);
539 WMSetLabelImagePosition(panel->speedL, WIPImageOnly);
540 path = LocateImage(SPEED_ICON_FILE);
541 if (path) {
542 icon = WMCreateBlendedPixmapFromFile(scr, path, &color);
543 if (icon) {
544 WMSetLabelImage(panel->speedL, icon);
545 WMReleasePixmap(icon);
546 } else {
547 wwarning(_("could not load icon %s"), path);
549 free(path);
552 buf1 = wmalloc(strlen(SPEED_IMAGE)+2);
553 buf2 = wmalloc(strlen(SPEED_IMAGE_S)+2);
555 for (i = 0; i < 5; i++) {
556 panel->speedB[i] = WMCreateCustomButton(panel->speedF,
557 WBBStateChangeMask);
558 WMResizeWidget(panel->speedB[i], 26, 26);
559 WMMoveWidget(panel->speedB[i], 60+(35*i), 25);
560 WMSetButtonBordered(panel->speedB[i], False);
561 WMSetButtonImagePosition(panel->speedB[i], WIPImageOnly);
562 WMSetButtonAction(panel->speedB[i], speedClick, panel);
563 if (i > 0) {
564 WMGroupButtons(panel->speedB[0], panel->speedB[i]);
566 sprintf(buf1, SPEED_IMAGE, i);
567 sprintf(buf2, SPEED_IMAGE_S, i);
568 path = LocateImage(buf1);
569 if (path) {
570 icon = WMCreatePixmapFromFile(scr, path);
571 if (icon) {
572 WMSetButtonImage(panel->speedB[i], icon);
573 WMReleasePixmap(icon);
574 } else {
575 wwarning(_("could not load icon file %s"), path);
577 free(path);
579 path = LocateImage(buf2);
580 if (path) {
581 icon = WMCreatePixmapFromFile(scr, path);
582 if (icon) {
583 WMSetButtonAltImage(panel->speedB[i], icon);
584 WMReleasePixmap(icon);
585 } else {
586 wwarning(_("could not load icon file %s"), path);
590 free(buf1);
591 free(buf2);
593 panel->acceL = WMCreateLabel(panel->speedF);
594 WMResizeWidget(panel->acceL, 70, 16);
595 WMMoveWidget(panel->acceL, 10, 67);
596 WMSetLabelTextAlignment(panel->acceL, WARight);
597 WMSetLabelText(panel->acceL, _("Acceler.:"));
599 panel->acceT = WMCreateTextField(panel->speedF);
600 WMResizeWidget(panel->acceT, 40, 20);
601 WMMoveWidget(panel->acceT, 80, 65);
602 WMAddNotificationObserver(returnPressed, panel,
603 WMTextDidEndEditingNotification, panel->acceT);
606 panel->threL = WMCreateLabel(panel->speedF);
607 WMResizeWidget(panel->threL, 80, 16);
608 WMMoveWidget(panel->threL, 120, 67);
609 WMSetLabelTextAlignment(panel->threL, WARight);
610 WMSetLabelText(panel->threL, _("Threshold:"));
612 panel->threT = WMCreateTextField(panel->speedF);
613 WMResizeWidget(panel->threT, 30, 20);
614 WMMoveWidget(panel->threT, 200, 65);
615 WMAddNotificationObserver(returnPressed, panel,
616 WMTextDidEndEditingNotification, panel->threT);
618 WMMapSubwidgets(panel->speedF);
620 /***************** Doubleclick Delay ****************/
622 panel->ddelaF = WMCreateFrame(panel->frame);
623 WMResizeWidget(panel->ddelaF, 245, 95);
624 WMMoveWidget(panel->ddelaF, 15, 125);
625 WMSetFrameTitle(panel->ddelaF, _("Double-Click Delay"));
627 buf1 = wmalloc(strlen(DELAY_ICON)+2);
628 buf2 = wmalloc(strlen(DELAY_ICON_S)+2);
630 for (i = 0; i < 5; i++) {
631 panel->ddelaB[i] = WMCreateCustomButton(panel->ddelaF,
632 WBBStateChangeMask);
633 WMResizeWidget(panel->ddelaB[i], 25, 25);
634 WMMoveWidget(panel->ddelaB[i], 30+(40*i), 20);
635 WMSetButtonBordered(panel->ddelaB[i], False);
636 WMSetButtonImagePosition(panel->ddelaB[i], WIPImageOnly);
637 WMSetButtonAction(panel->ddelaB[i], doubleClick, panel);
638 if (i>0) {
639 WMGroupButtons(panel->ddelaB[0], panel->ddelaB[i]);
641 sprintf(buf1, DELAY_ICON, i+1);
642 sprintf(buf2, DELAY_ICON_S, i+1);
643 path = LocateImage(buf1);
644 if (path) {
645 icon = WMCreatePixmapFromFile(scr, path);
646 if (icon) {
647 WMSetButtonImage(panel->ddelaB[i], icon);
648 WMReleasePixmap(icon);
649 } else {
650 wwarning(_("could not load icon file %s"), path);
652 free(path);
654 path = LocateImage(buf2);
655 if (path) {
656 icon = WMCreatePixmapFromFile(scr, path);
657 if (icon) {
658 WMSetButtonAltImage(panel->ddelaB[i], icon);
659 WMReleasePixmap(icon);
660 } else {
661 wwarning(_("could not load icon file %s"), path);
663 free(path);
666 free(buf1);
667 free(buf2);
669 panel->tester = CreateDoubleTest(panel->ddelaF, _("Test"));
670 WMResizeWidget(panel->tester, 84, 29);
671 WMMoveWidget(panel->tester, 35, 55);
673 panel->ddelaT = WMCreateTextField(panel->ddelaF);
674 WMResizeWidget(panel->ddelaT, 40, 20);
675 WMMoveWidget(panel->ddelaT, 140, 60);
677 panel->ddelaL = WMCreateLabel(panel->ddelaF);
678 WMResizeWidget(panel->ddelaL, 40, 16);
679 WMMoveWidget(panel->ddelaL, 185, 65);
681 WMFont *font;
682 WMColor *color;
684 font = WMSystemFontOfSize(scr, 10);
685 color = WMDarkGrayColor(scr);
686 WMSetLabelTextColor(panel->ddelaL, color);
687 WMSetLabelFont(panel->ddelaL, font);
688 WMReleaseFont(font);
689 WMReleaseColor(color);
691 WMSetLabelText(panel->ddelaL, "msec");
693 WMMapSubwidgets(panel->ddelaF);
695 /* ************** Workspace Action Buttons **************** */
696 panel->menuF = WMCreateFrame(panel->frame);
697 WMResizeWidget(panel->menuF, 240, 145);
698 WMMoveWidget(panel->menuF, 270, 15);
699 WMSetFrameTitle(panel->menuF, _("Workspace Mouse Actions"));
701 panel->disaB = WMCreateSwitchButton(panel->menuF);
702 WMResizeWidget(panel->disaB, 205, 18);
703 WMMoveWidget(panel->disaB, 10, 20);
704 WMSetButtonText(panel->disaB, _("Disable mouse actions"));
706 panel->mblL = WMCreateLabel(panel->menuF);
707 WMResizeWidget(panel->mblL, 16, 22);
708 WMMoveWidget(panel->mblL, 135, 40);
709 WMSetLabelImagePosition(panel->mblL, WIPImageOnly);
710 path = LocateImage(MOUSEB_L);
711 if (path) {
712 icon = WMCreatePixmapFromFile(scr, path);
713 if (icon) {
714 WMSetLabelImage(panel->mblL, icon);
715 WMReleasePixmap(icon);
716 } else {
717 wwarning(_("could not load icon file %s"), path);
719 free(path);
721 panel->mbmL = WMCreateLabel(panel->menuF);
722 WMResizeWidget(panel->mbmL, 16, 22);
723 WMMoveWidget(panel->mbmL, 170, 40);
724 WMSetLabelImagePosition(panel->mbmL, WIPImageOnly);
725 path = LocateImage(MOUSEB_M);
726 if (path) {
727 icon = WMCreatePixmapFromFile(scr, path);
728 if (icon) {
729 WMSetLabelImage(panel->mbmL, icon);
730 WMReleasePixmap(icon);
731 } else {
732 wwarning(_("could not load icon file %s"), path);
734 free(path);
737 panel->mbrL = WMCreateLabel(panel->menuF);
738 WMResizeWidget(panel->mbrL, 16, 22);
739 WMMoveWidget(panel->mbrL, 205, 40);
740 WMSetLabelImagePosition(panel->mbrL, WIPImageOnly);
741 path = LocateImage(MOUSEB_R);
742 if (path) {
743 icon = WMCreatePixmapFromFile(scr, path);
744 if (icon) {
745 WMSetLabelImage(panel->mbrL, icon);
746 WMReleasePixmap(icon);
747 } else {
748 wwarning(_("could not load icon file %s"), path);
750 free(path);
753 panel->appL = WMCreateLabel(panel->menuF);
754 WMResizeWidget(panel->appL, 125, 16);
755 WMMoveWidget(panel->appL, 5, 65);
756 WMSetLabelTextAlignment(panel->appL, WARight);
757 WMSetLabelText(panel->appL, _("Applications menu"));
759 panel->listL = WMCreateLabel(panel->menuF);
760 WMResizeWidget(panel->listL, 125, 16);
761 WMMoveWidget(panel->listL, 5, 90);
762 WMSetLabelTextAlignment(panel->listL, WARight);
763 WMSetLabelText(panel->listL, _("Window list menu"));
765 panel->selL = WMCreateLabel(panel->menuF);
766 WMResizeWidget(panel->selL, 125, 16);
767 WMMoveWidget(panel->selL, 5, 115);
768 WMSetLabelTextAlignment(panel->selL, WARight);
769 WMSetLabelText(panel->selL, _("Select windows"));
772 for (i=0; i<3; i++) {
773 panel->amb[i] = WMCreateRadioButton(panel->menuF);
774 WMResizeWidget(panel->amb[i], 24, 24);
775 WMMoveWidget(panel->amb[i], 135+35*i, 65);
776 WMSetButtonText(panel->amb[i], NULL);
777 WMSetButtonAction(panel->amb[i], mouseButtonClickA, panel);
779 panel->lmb[i] = WMCreateRadioButton(panel->menuF);
780 WMResizeWidget(panel->lmb[i], 24, 24);
781 WMMoveWidget(panel->lmb[i], 135+35*i, 90);
782 WMSetButtonText(panel->lmb[i], NULL);
783 WMSetButtonAction(panel->lmb[i], mouseButtonClickL, panel);
785 panel->smb[i] = WMCreateRadioButton(panel->menuF);
786 WMResizeWidget(panel->smb[i], 24, 24);
787 WMMoveWidget(panel->smb[i], 135+35*i, 115);
788 WMSetButtonText(panel->smb[i], NULL);
789 WMSetButtonAction(panel->smb[i], mouseButtonClickS, panel);
791 if (i>0) {
792 WMGroupButtons(panel->lmb[0], panel->lmb[i]);
793 WMGroupButtons(panel->amb[0], panel->amb[i]);
794 WMGroupButtons(panel->smb[0], panel->smb[i]);
798 WMMapSubwidgets(panel->menuF);
800 /* ************** Grab Modifier **************** */
801 panel->grabF = WMCreateFrame(panel->frame);
802 WMResizeWidget(panel->grabF, 240, 55);
803 WMMoveWidget(panel->grabF, 270, 165);
804 WMSetFrameTitle(panel->grabF, _("Mouse Grab Modifier"));
806 panel->grabP = WMCreatePopUpButton(panel->grabF);
807 WMResizeWidget(panel->grabP, 160, 20);
808 WMMoveWidget(panel->grabP, 40, 25);
810 fillModifierPopUp(panel->grabP);
812 WMMapSubwidgets(panel->grabF);
814 WMRealizeWidget(panel->frame);
815 WMMapSubwidgets(panel->frame);
818 showData(panel);
822 static void
823 storeCommandInScript(char *cmd, char *line)
825 char *path;
826 char *p;
827 FILE *f;
828 char buffer[128];
830 p = wusergnusteppath();
831 path = wmalloc(strlen(p)+64);
832 sprintf(path, "%s/Library/WindowMaker/autostart", p);
834 f = fopen(path, "r");
835 if (!f) {
836 f = fopen(path, "w");
837 if (!f) {
838 wsyserror(_("could not create %s"), path);
839 goto end;
841 fprintf(f, "#!/bin/sh\n");
842 fputs(line, f);
843 fputs("\n", f);
844 } else {
845 int len = strlen(cmd);
846 int ok = 0;
847 char *tmppath;
848 FILE *fo;
850 tmppath = wmalloc(strlen(p)+64);
851 sprintf(tmppath, "%s/Library/WindowMaker/autostart.tmp", p);
852 fo = fopen(tmppath, "w");
853 if (!fo) {
854 wsyserror(_("could not create temporary file %s"), tmppath);
855 goto end;
858 while (!feof(f)) {
859 if (!fgets(buffer, 127, f)) {
860 break;
862 if (strncmp(buffer, cmd, len)==0) {
863 if (!ok) {
864 fputs(line, fo);
865 fputs("\n", fo);
866 ok = 1;
868 } else {
869 fputs(buffer, fo);
872 if (!ok) {
873 fputs(line, fo);
874 fputs("\n", fo);
876 fclose(fo);
878 if (rename(tmppath, path)!=0) {
879 wsyserror(_("could not rename file %s to %s\n"), tmppath, path);
881 free(tmppath);
883 sprintf(buffer, "chmod u+x %s", path);
884 system(buffer);
886 end:
887 free(p);
888 free(path);
889 if (f)
890 fclose(f);
894 static void
895 storeData(_Panel *panel)
897 char buffer[64];
898 int i;
899 char *tmp, *p;
900 static char *button[3] = {"left", "middle", "right"};
901 WMUserDefaults *udb = WMGetStandardUserDefaults();
903 if (!WMGetUDBoolForKey(udb, "NoXSetStuff")) {
904 tmp = WMGetTextFieldText(panel->threT);
905 if (strlen(tmp)==0) {
906 free(tmp);
907 tmp = wstrdup("4");
910 sprintf(buffer, XSET" m %i/%i %s\n", (int)(panel->acceleration*10),
911 10, tmp);
912 storeCommandInScript(XSET" m", buffer);
914 free(tmp);
917 tmp = WMGetTextFieldText(panel->ddelaT);
918 if (sscanf(tmp, "%i", &i) == 1 && i > 0)
919 SetIntegerForKey(i, "DoubleClickTime");
921 SetBoolForKey(WMGetButtonSelected(panel->disaB), "DisableWSMouseActions");
923 for (i=0; i<3; i++) {
924 if (WMGetButtonSelected(panel->amb[i]))
925 break;
927 if (i<3)
928 SetStringForKey(button[i], "ApplicationMenuMouseButton");
930 for (i=0; i<3; i++) {
931 if (WMGetButtonSelected(panel->lmb[i]))
932 break;
934 if (i<3)
935 SetStringForKey(button[i], "WindowListMouseButton");
937 for (i=0; i<3; i++) {
938 if (WMGetButtonSelected(panel->smb[i]))
939 break;
941 if (i<3)
942 SetStringForKey(button[i], "SelectWindowsMouseButton");
944 tmp = WMGetPopUpButtonItem(panel->grabP,
945 WMGetPopUpButtonSelectedItem(panel->grabP));
946 tmp = wstrdup(tmp);
947 p = strchr(tmp, ' ');
948 *p = 0;
950 SetStringForKey(tmp, "ModifierKey");
952 free(tmp);
956 Panel*
957 InitMouseSettings(WMScreen *scr, WMWindow *win)
959 _Panel *panel;
961 panel = wmalloc(sizeof(_Panel));
962 memset(panel, 0, sizeof(_Panel));
964 panel->sectionName = _("Mouse Preferences");
966 panel->win = win;
968 panel->callbacks.createWidgets = createPanel;
969 panel->callbacks.updateDomain = storeData;
971 AddSection(panel, ICON_FILE);
973 return panel;