0.51.1 pre snapshot. Be careful, it may be buggy. It fixes some bugs though.
[wmaker-crm.git] / WPrefs.app / MouseSettings.c
blobbfaaaa5889dbf65a7457b90f734179e6c9990757
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 DoubleTest *tester;
60 WMFrame *menuF;
61 WMLabel *listL;
62 WMLabel *appL;
63 WMLabel *selL;
64 WMLabel *mblL;
65 WMLabel *mbmL;
66 WMLabel *mbrL;
67 WMButton *lmb[3];
68 WMButton *amb[3];
69 WMButton *smb[3];
72 WMButton *disaB;
74 WMFrame *grabF;
75 WMPopUpButton *grabP;
77 /**/
78 WMButton *lastClickedSpeed;
79 int maxThreshold;
80 float acceleration;
81 } _Panel;
84 #define ICON_FILE "mousesettings"
86 #define SPEED_ICON_FILE "mousespeed"
87 #define SPEED_IMAGE "speed%i"
88 #define SPEED_IMAGE_S "speed%is"
90 #define DELAY_ICON "timer%i"
91 #define DELAY_ICON_S "timer%is"
93 #define MOUSEB_L "minimouseleft"
94 #define MOUSEB_M "minimousemiddle"
95 #define MOUSEB_R "minimouseright"
97 /* need access to the double click variables */
98 #include "WINGsP.h"
102 static char *modifierNames[] = {
103 "Shift",
104 "Lock",
105 "Control",
106 "Mod1",
107 "Mod2",
108 "Mod3",
109 "Mod4",
110 "Mod5"
114 #define DELAY(i) ((i)*75+170)
117 int ModifierFromKey(Display *dpy, char *key);
120 static void
121 setMouseAccel(WMScreen *scr, float accel, int threshold)
123 int n, d;
125 d = 10;
126 n = accel*d;
128 XChangePointerControl(WMScreenDisplay(scr), True, True, n, d, threshold);
132 static void
133 speedClick(WMWidget *w, void *data)
135 _Panel *panel = (_Panel*)data;
136 int i;
137 char buffer[64];
138 int threshold;
139 char *tmp;
141 if (w == NULL) {
142 float accel;
144 tmp = WMGetTextFieldText(panel->acceT);
145 if (sscanf(tmp, "%f", &accel)!=1 || accel < 0) {
146 WMRunAlertPanel(WMWidgetScreen(w), GetWindow(panel), _("Error"),
147 _("Invalid mouse acceleration value. Must be a positive real value."),
148 _("OK"), NULL, NULL);
149 free(tmp);
150 return;
152 panel->acceleration = accel;
153 free(tmp);
154 } else {
155 for (i=0; i<5; i++) {
156 if (panel->speedB[i]==w)
157 break;
160 panel->acceleration = 0.5+(i*0.5);
162 sprintf(buffer, "%.2f", 0.5+(i*0.5));
163 WMSetTextFieldText(panel->acceT, buffer);
166 tmp = WMGetTextFieldText(panel->threT);
167 if (sscanf(tmp, "%i", &threshold)!=1 || threshold < 0
168 || threshold > panel->maxThreshold) {
169 WMRunAlertPanel(WMWidgetScreen(panel->win), GetWindow(panel), _("Error"),
170 _("Invalid mouse acceleration threshold value. Must be the number of pixels to travel before accelerating."),
171 _("OK"), NULL, NULL);
172 } else {
173 setMouseAccel(WMWidgetScreen(panel->win), panel->acceleration,
174 threshold);
176 free(tmp);
180 static void
181 returnPressed(void *observerData, WMNotification *notification)
183 _Panel *panel = (_Panel*)observerData;
185 speedClick(NULL, panel);
189 static void
190 doubleClick(WMWidget *w, void *data)
192 _Panel *panel = (_Panel*)data;
193 int i;
194 extern _WINGsConfiguration WINGsConfiguration;
196 for (i=0; i<5; i++) {
197 if (panel->ddelaB[i]==w)
198 break;
200 WINGsConfiguration.doubleClickDelay = DELAY(i);
206 getbutton(char *str)
208 if (!str)
209 return -2;
211 if (strcasecmp(str, "left")==0)
212 return 0;
213 else if (strcasecmp(str, "middle")==0)
214 return 1;
215 else if (strcasecmp(str, "right")==0)
216 return 2;
217 else if (strcasecmp(str, "button1")==0)
218 return 0;
219 else if (strcasecmp(str, "button2")==0)
220 return 1;
221 else if (strcasecmp(str, "button3")==0)
222 return 2;
223 else if (strcasecmp(str, "button4")==0
224 || strcasecmp(str, "button5")==0) {
225 wwarning(_("mouse button %s not supported by WPrefs."), str);
226 return -2;
227 } else {
228 return -1;
233 static void
234 getMouseParameters(Display *dpy, float *accel, int *thre)
236 int n, d;
238 XGetPointerControl(dpy, &n, &d, thre);
240 *accel = (float)n/(float)d;
245 static void
246 showData(_Panel *panel)
248 char *str;
249 int i;
250 int a=-1, b=-1, c=-1;
251 float accel;
252 char buffer[32];
253 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
255 str = GetStringForKey("SelectWindowsMouseButton");
256 if (!str)
257 str = "left";
258 i = getbutton(str);
259 if (i==-1) {
260 a = 0;
261 wwarning(_("bad value %s for option %s"),str, "SelectWindowsMouseButton");
262 WMPerformButtonClick(panel->smb[0]);
263 } else if (i>=0) {
264 a = i;
265 WMPerformButtonClick(panel->smb[i]);
268 str = GetStringForKey("WindowListMouseButton");
269 if (!str)
270 str = "middle";
271 i = getbutton(str);
272 if (i==-1) {
273 b = 0;
274 wwarning(_("bad value %s for option %s"), str, "WindowListMouseButton");
275 WMPerformButtonClick(panel->lmb[1]);
276 } else if (i>=0) {
277 b = i;
278 WMPerformButtonClick(panel->lmb[i]);
281 str = GetStringForKey("ApplicationMenuMouseButton");
282 if (!str)
283 str = "right";
284 i = getbutton(str);
285 if (i==-1) {
286 c = 0;
287 wwarning(_("bad value %s for option %s"), str, "ApplicationMenuMouseButton");
288 WMPerformButtonClick(panel->amb[2]);
289 } else if (i>=0) {
290 c = i;
291 WMPerformButtonClick(panel->amb[i]);
295 WMSetButtonSelected(panel->disaB, GetBoolForKey("DisableWSMouseActions"));
297 /**/
298 getMouseParameters(dpy, &accel, &a);
299 panel->maxThreshold = WidthOfScreen(DefaultScreenOfDisplay(dpy));
300 if (a > panel->maxThreshold) {
301 panel->maxThreshold = a;
303 sprintf(buffer, "%i", a);
304 WMSetTextFieldText(panel->threT, buffer);
305 /* find best match */
306 a = 0;
307 for (i=0; i<5; i++) {
308 if (fabs((0.5+((float)i*0.5))-accel) < fabs((0.5+((float)a*0.5))-accel))
309 a = i;
311 WMPerformButtonClick(panel->speedB[a]);
312 panel->lastClickedSpeed = panel->speedB[a];
313 panel->acceleration = accel;
315 speedClick(panel->lastClickedSpeed, panel);
316 /**/
317 b = GetIntegerForKey("DoubleClickTime");
318 /* find best match */
319 a = 0;
320 for (i=0; i<5; i++) {
321 if (abs(b - DELAY(i)) < abs(b - DELAY(a)))
322 a = i;
324 WMPerformButtonClick(panel->ddelaB[a]);
326 /**/
327 str = GetStringForKey("ModifierKey");
328 if (!str)
329 str = "mod1";
330 a = ModifierFromKey(dpy, str);
332 if (a != -1) {
333 str = modifierNames[a];
335 a = 0;
336 for (i=0; i<WMGetPopUpButtonNumberOfItems(panel->grabP); i++) {
337 if (strstr(WMGetPopUpButtonItem(panel->grabP, i), str)) {
338 WMSetPopUpButtonSelectedItem(panel->grabP, i);
339 a = 1;
340 break;
345 if (a < 1) {
346 sscanf(WMGetPopUpButtonItem(panel->grabP, 0), "%s", buffer);
347 WMSetPopUpButtonSelectedItem(panel->grabP, 0);
348 wwarning(_("modifier key %s for option ModifierKey was not recognized. Using %s as default"),
349 str, buffer);
355 static void
356 fillModifierPopUp(WMPopUpButton *pop)
358 XModifierKeymap *mapping;
359 Display *dpy = WMScreenDisplay(WMWidgetScreen(pop));
360 int i, j;
361 char *str;
362 char buffer[64];
365 mapping = XGetModifierMapping(dpy);
367 if (!mapping || mapping->max_keypermod==0) {
368 WMAddPopUpButtonItem(pop, "Mod1");
369 WMAddPopUpButtonItem(pop, "Mod2");
370 WMAddPopUpButtonItem(pop, "Mod3");
371 WMAddPopUpButtonItem(pop, "Mod4");
372 WMAddPopUpButtonItem(pop, "Mod5");
373 wwarning(_("could not retrieve keyboard modifier mapping"));
374 return;
378 for (j=0; j<8; j++) {
379 int idx;
380 char *array[8];
381 int a;
382 KeySym ksym;
383 int k;
384 char *ptr;
385 char *tmp;
387 a = 0;
388 memset(array, 0, sizeof(char*)*8);
389 for (i=0; i < mapping->max_keypermod; i++) {
390 idx = i+j*mapping->max_keypermod;
391 if (mapping->modifiermap[idx]!=0) {
392 int l;
393 for (l=0; l<4; l++) {
394 ksym = XKeycodeToKeysym(dpy, mapping->modifiermap[idx], l);
395 if (ksym!=NoSymbol)
396 break;
398 if (ksym!=NoSymbol)
399 str = XKeysymToString(ksym);
400 else
401 str = NULL;
402 if (str && !strstr(str, "_Lock") && !strstr(str, "Shift")
403 && !strstr(str, "Control")) {
404 array[a++] = wstrdup(str);
409 for (k=0; k<a; k++) {
410 if (array[k]==NULL)
411 continue;
412 tmp = wstrdup(array[k]);
413 ptr = strstr(tmp, "_L");
414 if (ptr)
415 *ptr = 0;
416 ptr = strstr(tmp, "_R");
417 if (ptr)
418 *ptr = 0;
419 sprintf(buffer, "%s (%s)", modifierNames[j], tmp);
420 WMAddPopUpButtonItem(pop, buffer);
421 for (i=k+1; i<a; i++) {
422 if (strstr(array[i], tmp)) {
423 free(array[i]);
424 array[i]=NULL;
425 break;
428 free(tmp);
431 while (--a>0) {
432 if (array[a])
433 free(array[a]);
437 if (mapping)
438 XFreeModifiermap(mapping);
443 static void
444 mouseButtonClickA(WMWidget *w, void *data)
446 _Panel *panel = (_Panel*)data;
447 int i;
449 for (i=0; i<3; i++) {
450 if (panel->amb[i]==w)
451 break;
453 if (i==3)
454 return;
455 if (WMGetButtonSelected(panel->lmb[i]))
456 WMSetButtonSelected(panel->lmb[i], False);
457 if (WMGetButtonSelected(panel->smb[i]))
458 WMSetButtonSelected(panel->smb[i], False);
461 static void
462 mouseButtonClickL(WMWidget *w, void *data)
464 _Panel *panel = (_Panel*)data;
465 int i;
467 for (i=0; i<3; i++) {
468 if (panel->lmb[i]==w)
469 break;
471 if (i==3)
472 return;
473 if (WMGetButtonSelected(panel->smb[i]))
474 WMSetButtonSelected(panel->smb[i], False);
475 if (WMGetButtonSelected(panel->amb[i]))
476 WMSetButtonSelected(panel->amb[i], False);
479 static void
480 mouseButtonClickS(WMWidget *w, void *data)
482 _Panel *panel = (_Panel*)data;
483 int i;
485 for (i=0; i<3; i++) {
486 if (panel->smb[i]==w)
487 break;
489 if (i==3)
490 return;
491 if (WMGetButtonSelected(panel->lmb[i]))
492 WMSetButtonSelected(panel->lmb[i], False);
493 if (WMGetButtonSelected(panel->amb[i]))
494 WMSetButtonSelected(panel->amb[i], False);
497 static void
498 createPanel(Panel *p)
500 _Panel *panel = (_Panel*)p;
501 WMScreen *scr = WMWidgetScreen(panel->win);
502 WMPixmap *icon;
503 char *buf1, *buf2;
504 int i;
505 RColor color;
506 char *path;
508 color.red = 0xaa;
509 color.green = 0xae;
510 color.blue = 0xaa;
512 panel->frame = WMCreateFrame(panel->win);
513 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
514 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
516 /**************** Mouse Speed ****************/
517 panel->speedF = WMCreateFrame(panel->frame);
518 WMResizeWidget(panel->speedF, 245, 100);
519 WMMoveWidget(panel->speedF, 15, 15);
520 WMSetFrameTitle(panel->speedF, _("Mouse Speed"));
522 panel->speedL = WMCreateLabel(panel->speedF);
523 WMResizeWidget(panel->speedL, 40, 46);
524 WMMoveWidget(panel->speedL, 15, 14);
525 WMSetLabelImagePosition(panel->speedL, WIPImageOnly);
526 path = LocateImage(SPEED_ICON_FILE);
527 if (path) {
528 icon = WMCreateBlendedPixmapFromFile(scr, path, &color);
529 if (icon) {
530 WMSetLabelImage(panel->speedL, icon);
531 WMReleasePixmap(icon);
532 } else {
533 wwarning(_("could not load icon %s"), path);
535 free(path);
538 buf1 = wmalloc(strlen(SPEED_IMAGE)+2);
539 buf2 = wmalloc(strlen(SPEED_IMAGE_S)+2);
541 for (i = 0; i < 5; i++) {
542 panel->speedB[i] = WMCreateCustomButton(panel->speedF,
543 WBBStateChangeMask);
544 WMResizeWidget(panel->speedB[i], 26, 26);
545 WMMoveWidget(panel->speedB[i], 60+(35*i), 25);
546 WMSetButtonBordered(panel->speedB[i], False);
547 WMSetButtonImagePosition(panel->speedB[i], WIPImageOnly);
548 WMSetButtonAction(panel->speedB[i], speedClick, panel);
549 if (i > 0) {
550 WMGroupButtons(panel->speedB[0], panel->speedB[i]);
552 sprintf(buf1, SPEED_IMAGE, i);
553 sprintf(buf2, SPEED_IMAGE_S, i);
554 path = LocateImage(buf1);
555 if (path) {
556 icon = WMCreatePixmapFromFile(scr, path);
557 if (icon) {
558 WMSetButtonImage(panel->speedB[i], icon);
559 WMReleasePixmap(icon);
560 } else {
561 wwarning(_("could not load icon file %s"), path);
563 free(path);
565 path = LocateImage(buf2);
566 if (path) {
567 icon = WMCreatePixmapFromFile(scr, path);
568 if (icon) {
569 WMSetButtonAltImage(panel->speedB[i], icon);
570 WMReleasePixmap(icon);
571 } else {
572 wwarning(_("could not load icon file %s"), path);
576 free(buf1);
577 free(buf2);
579 panel->acceL = WMCreateLabel(panel->speedF);
580 WMResizeWidget(panel->acceL, 80, 16);
581 WMMoveWidget(panel->acceL, 10, 67);
582 WMSetLabelText(panel->acceL, _("Acceler.:"));
584 panel->acceT = WMCreateTextField(panel->speedF);
585 WMResizeWidget(panel->acceT, 35, 20);
586 WMMoveWidget(panel->acceT, 85, 65);
587 WMAddNotificationObserver(returnPressed, panel,
588 WMTextDidEndEditingNotification, panel->acceT);
591 panel->threL = WMCreateLabel(panel->speedF);
592 WMResizeWidget(panel->threL, 80, 16);
593 WMMoveWidget(panel->threL, 120, 67);
594 WMSetLabelText(panel->threL, _("Threshold:"));
596 panel->threT = WMCreateTextField(panel->speedF);
597 WMResizeWidget(panel->threT, 30, 20);
598 WMMoveWidget(panel->threT, 200, 65);
599 WMAddNotificationObserver(returnPressed, panel,
600 WMTextDidEndEditingNotification, panel->threT);
602 WMMapSubwidgets(panel->speedF);
604 /***************** Doubleclick Delay ****************/
606 panel->ddelaF = WMCreateFrame(panel->frame);
607 WMResizeWidget(panel->ddelaF, 245, 95);
608 WMMoveWidget(panel->ddelaF, 15, 125);
609 WMSetFrameTitle(panel->ddelaF, _("Double-Click Delay"));
611 buf1 = wmalloc(strlen(DELAY_ICON)+2);
612 buf2 = wmalloc(strlen(DELAY_ICON_S)+2);
614 for (i = 0; i < 5; i++) {
615 panel->ddelaB[i] = WMCreateCustomButton(panel->ddelaF,
616 WBBStateChangeMask);
617 WMResizeWidget(panel->ddelaB[i], 25, 25);
618 WMMoveWidget(panel->ddelaB[i], 30+(40*i), 20);
619 WMSetButtonBordered(panel->ddelaB[i], False);
620 WMSetButtonImagePosition(panel->ddelaB[i], WIPImageOnly);
621 WMSetButtonAction(panel->ddelaB[i], doubleClick, panel);
622 if (i>0) {
623 WMGroupButtons(panel->ddelaB[0], panel->ddelaB[i]);
625 sprintf(buf1, DELAY_ICON, i+1);
626 sprintf(buf2, DELAY_ICON_S, i+1);
627 path = LocateImage(buf1);
628 if (path) {
629 icon = WMCreatePixmapFromFile(scr, path);
630 if (icon) {
631 WMSetButtonImage(panel->ddelaB[i], icon);
632 WMReleasePixmap(icon);
633 } else {
634 wwarning(_("could not load icon file %s"), path);
636 free(path);
638 path = LocateImage(buf2);
639 if (path) {
640 icon = WMCreatePixmapFromFile(scr, path);
641 if (icon) {
642 WMSetButtonAltImage(panel->ddelaB[i], icon);
643 WMReleasePixmap(icon);
644 } else {
645 wwarning(_("could not load icon file %s"), path);
647 free(path);
650 free(buf1);
651 free(buf2);
653 panel->tester = CreateDoubleTest(panel->ddelaF, _("Test"));
654 WMResizeWidget(panel->tester, 84, 29);
655 WMMoveWidget(panel->tester, 85, 55);
657 WMMapSubwidgets(panel->ddelaF);
659 /* ************** Workspace Action Buttons **************** */
660 panel->menuF = WMCreateFrame(panel->frame);
661 WMResizeWidget(panel->menuF, 240, 145);
662 WMMoveWidget(panel->menuF, 270, 15);
663 WMSetFrameTitle(panel->menuF, _("Workspace Mouse Actions"));
665 panel->disaB = WMCreateSwitchButton(panel->menuF);
666 WMResizeWidget(panel->disaB, 205, 18);
667 WMMoveWidget(panel->disaB, 10, 20);
668 WMSetButtonText(panel->disaB, _("Disable mouse actions"));
670 panel->mblL = WMCreateLabel(panel->menuF);
671 WMResizeWidget(panel->mblL, 16, 22);
672 WMMoveWidget(panel->mblL, 135, 40);
673 WMSetLabelImagePosition(panel->mblL, WIPImageOnly);
674 path = LocateImage(MOUSEB_L);
675 if (path) {
676 icon = WMCreatePixmapFromFile(scr, path);
677 if (icon) {
678 WMSetLabelImage(panel->mblL, icon);
679 WMReleasePixmap(icon);
680 } else {
681 wwarning(_("could not load icon file %s"), path);
683 free(path);
685 panel->mbmL = WMCreateLabel(panel->menuF);
686 WMResizeWidget(panel->mbmL, 16, 22);
687 WMMoveWidget(panel->mbmL, 170, 40);
688 WMSetLabelImagePosition(panel->mbmL, WIPImageOnly);
689 path = LocateImage(MOUSEB_M);
690 if (path) {
691 icon = WMCreatePixmapFromFile(scr, path);
692 if (icon) {
693 WMSetLabelImage(panel->mbmL, icon);
694 WMReleasePixmap(icon);
695 } else {
696 wwarning(_("could not load icon file %s"), path);
698 free(path);
701 panel->mbrL = WMCreateLabel(panel->menuF);
702 WMResizeWidget(panel->mbrL, 16, 22);
703 WMMoveWidget(panel->mbrL, 205, 40);
704 WMSetLabelImagePosition(panel->mbrL, WIPImageOnly);
705 path = LocateImage(MOUSEB_R);
706 if (path) {
707 icon = WMCreatePixmapFromFile(scr, path);
708 if (icon) {
709 WMSetLabelImage(panel->mbrL, icon);
710 WMReleasePixmap(icon);
711 } else {
712 wwarning(_("could not load icon file %s"), path);
714 free(path);
717 panel->appL = WMCreateLabel(panel->menuF);
718 WMResizeWidget(panel->appL, 125, 16);
719 WMMoveWidget(panel->appL, 5, 65);
720 WMSetLabelTextAlignment(panel->appL, WARight);
721 WMSetLabelText(panel->appL, _("Applications menu"));
723 panel->listL = WMCreateLabel(panel->menuF);
724 WMResizeWidget(panel->listL, 125, 16);
725 WMMoveWidget(panel->listL, 5, 90);
726 WMSetLabelTextAlignment(panel->listL, WARight);
727 WMSetLabelText(panel->listL, _("Window list menu"));
729 panel->selL = WMCreateLabel(panel->menuF);
730 WMResizeWidget(panel->selL, 125, 16);
731 WMMoveWidget(panel->selL, 5, 115);
732 WMSetLabelTextAlignment(panel->selL, WARight);
733 WMSetLabelText(panel->selL, _("Select windows"));
736 for (i=0; i<3; i++) {
737 panel->amb[i] = WMCreateRadioButton(panel->menuF);
738 WMResizeWidget(panel->amb[i], 24, 24);
739 WMMoveWidget(panel->amb[i], 135+35*i, 65);
740 WMSetButtonText(panel->amb[i], NULL);
741 WMSetButtonAction(panel->amb[i], mouseButtonClickA, panel);
743 panel->lmb[i] = WMCreateRadioButton(panel->menuF);
744 WMResizeWidget(panel->lmb[i], 24, 24);
745 WMMoveWidget(panel->lmb[i], 135+35*i, 90);
746 WMSetButtonText(panel->lmb[i], NULL);
747 WMSetButtonAction(panel->lmb[i], mouseButtonClickL, panel);
749 panel->smb[i] = WMCreateRadioButton(panel->menuF);
750 WMResizeWidget(panel->smb[i], 24, 24);
751 WMMoveWidget(panel->smb[i], 135+35*i, 115);
752 WMSetButtonText(panel->smb[i], NULL);
753 WMSetButtonAction(panel->smb[i], mouseButtonClickS, panel);
755 if (i>0) {
756 WMGroupButtons(panel->lmb[0], panel->lmb[i]);
757 WMGroupButtons(panel->amb[0], panel->amb[i]);
758 WMGroupButtons(panel->smb[0], panel->smb[i]);
762 WMMapSubwidgets(panel->menuF);
764 /* ************** Grab Modifier **************** */
765 panel->grabF = WMCreateFrame(panel->frame);
766 WMResizeWidget(panel->grabF, 240, 55);
767 WMMoveWidget(panel->grabF, 270, 165);
768 WMSetFrameTitle(panel->grabF, _("Mouse Grab Modifier"));
770 panel->grabP = WMCreatePopUpButton(panel->grabF);
771 WMResizeWidget(panel->grabP, 160, 20);
772 WMMoveWidget(panel->grabP, 40, 25);
774 fillModifierPopUp(panel->grabP);
776 WMMapSubwidgets(panel->grabF);
778 WMRealizeWidget(panel->frame);
779 WMMapSubwidgets(panel->frame);
782 showData(panel);
786 static void
787 storeCommandInScript(char *cmd, char *line)
789 char *path;
790 char *p;
791 FILE *f;
792 char buffer[128];
794 p = wusergnusteppath();
795 path = wmalloc(strlen(p)+64);
796 sprintf(path, "%s/Library/WindowMaker/autostart", p);
798 f = fopen(path, "r");
799 if (!f) {
800 f = fopen(path, "w");
801 if (!f) {
802 wsyserror(_("could not create %s"), path);
803 goto end;
805 fprintf(f, "#!/bin/sh\n");
806 fputs(line, f);
807 fputs("\n", f);
808 } else {
809 int len = strlen(cmd);
810 int ok = 0;
811 char *tmppath;
812 FILE *fo;
814 tmppath = wmalloc(strlen(p)+64);
815 sprintf(tmppath, "%s/Library/WindowMaker/autostart.tmp", p);
816 fo = fopen(tmppath, "w");
817 if (!fo) {
818 wsyserror(_("could not create temporary file %s"), tmppath);
819 goto end;
822 while (!feof(f)) {
823 if (!fgets(buffer, 127, f)) {
824 break;
826 if (strncmp(buffer, cmd, len)==0) {
827 if (!ok) {
828 fputs(line, fo);
829 fputs("\n", fo);
830 ok = 1;
832 } else {
833 fputs(buffer, fo);
836 if (!ok) {
837 fputs(line, fo);
838 fputs("\n", fo);
840 fclose(fo);
842 if (rename(tmppath, path)!=0) {
843 wsyserror(_("could not rename file %s to %s\n"), tmppath, path);
845 free(tmppath);
847 sprintf(buffer, "chmod u+x %s", path);
848 system(buffer);
850 end:
851 free(p);
852 free(path);
853 if (f)
854 fclose(f);
858 static void
859 storeData(_Panel *panel)
861 char buffer[64];
862 int i;
863 char *tmp, *p;
864 static char *button[3] = {"left", "middle", "right"};
865 WMUserDefaults *udb = WMGetStandardUserDefaults();
867 if (!WMGetUDBoolForKey(udb, "NoXSetStuff")) {
868 tmp = WMGetTextFieldText(panel->threT);
869 if (strlen(tmp)==0) {
870 free(tmp);
871 tmp = wstrdup("4");
874 sprintf(buffer, XSET" m %i/%i %s\n", (int)(panel->acceleration*10),
875 10, tmp);
876 storeCommandInScript(XSET" m", buffer);
878 free(tmp);
881 for (i=0; i<5; i++) {
882 if (WMGetButtonSelected(panel->ddelaB[i]))
883 break;
885 SetIntegerForKey(DELAY(i), "DoubleClickTime");
887 SetBoolForKey(WMGetButtonSelected(panel->disaB), "DisableWSMouseActions");
889 for (i=0; i<3; i++) {
890 if (WMGetButtonSelected(panel->amb[i]))
891 break;
893 if (i<3)
894 SetStringForKey(button[i], "ApplicationMenuMouseButton");
896 for (i=0; i<3; i++) {
897 if (WMGetButtonSelected(panel->lmb[i]))
898 break;
900 if (i<3)
901 SetStringForKey(button[i], "WindowListMouseButton");
903 for (i=0; i<3; i++) {
904 if (WMGetButtonSelected(panel->smb[i]))
905 break;
907 if (i<3)
908 SetStringForKey(button[i], "SelectWindowsMouseButton");
910 tmp = WMGetPopUpButtonItem(panel->grabP,
911 WMGetPopUpButtonSelectedItem(panel->grabP));
912 tmp = wstrdup(tmp);
913 p = strchr(tmp, ' ');
914 *p = 0;
916 SetStringForKey(tmp, "ModifierKey");
918 free(tmp);
922 Panel*
923 InitMouseSettings(WMScreen *scr, WMWindow *win)
925 _Panel *panel;
927 panel = wmalloc(sizeof(_Panel));
928 memset(panel, 0, sizeof(_Panel));
930 panel->sectionName = _("Mouse Preferences");
932 panel->win = win;
934 panel->callbacks.createWidgets = createPanel;
935 panel->callbacks.updateDomain = storeData;
937 AddSection(panel, ICON_FILE);
939 return panel;