Code update for Window Maker version 0.50.0
[wmaker-crm.git] / WPrefs.app / MouseSettings.c
blobffc8504d8a64c92db17e16fd6364cef46083fa02
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 WMLabel *threL;
53 WMTextField *threT;
55 WMFrame *ddelaF;
56 WMButton *ddelaB[5];
57 DoubleTest *tester;
59 WMFrame *menuF;
60 WMLabel *listL;
61 WMLabel *appL;
62 WMLabel *selL;
63 WMLabel *mblL;
64 WMLabel *mbmL;
65 WMLabel *mbrL;
66 WMButton *lmb[3];
67 WMButton *amb[3];
68 WMButton *smb[3];
71 WMButton *disaB;
73 WMFrame *grabF;
74 WMPopUpButton *grabP;
76 /**/
77 WMButton *lastClickedSpeed;
78 int maxThreshold;
79 float acceleration;
80 } _Panel;
83 #define ICON_FILE "mousesettings"
85 #define SPEED_ICON_FILE "mousespeed"
86 #define SPEED_IMAGE "speed%i"
87 #define SPEED_IMAGE_S "speed%is"
89 #define DELAY_ICON "timer%i"
90 #define DELAY_ICON_S "timer%is"
92 #define MOUSEB_L "minimouseleft"
93 #define MOUSEB_M "minimousemiddle"
94 #define MOUSEB_R "minimouseright"
96 /* need access to the double click variables */
97 #include "WINGsP.h"
101 static char *modifierNames[] = {
102 "Shift",
103 "Lock",
104 "Control",
105 "Mod1",
106 "Mod2",
107 "Mod3",
108 "Mod4",
109 "Mod5"
113 #define DELAY(i) ((i)*75+170)
116 int ModifierFromKey(Display *dpy, char *key);
119 static void
120 setMouseAccel(WMScreen *scr, float accel, int threshold)
122 int n, d;
124 d = 10;
125 n = accel*d;
127 XChangePointerControl(WMScreenDisplay(scr), True, True, n, d, threshold);
131 static void
132 speedClick(WMWidget *w, void *data)
134 _Panel *panel = (_Panel*)data;
135 int i;
136 char buffer[64];
137 int threshold;
138 char *tmp;
140 for (i=0; i<5; i++) {
141 if (panel->speedB[i]==w)
142 break;
145 panel->lastClickedSpeed = panel->speedB[i];
146 panel->acceleration = 0.5+(i*0.5);
148 sprintf(buffer, "Accel.: %.2f", 0.5+(i*0.5));
149 WMSetLabelText(panel->acceL, buffer);
151 tmp = WMGetTextFieldText(panel->threT);
152 if (sscanf(tmp, "%i", &threshold)!=1 || threshold < 0
153 || threshold > panel->maxThreshold) {
154 WMRunAlertPanel(WMWidgetScreen(w), GetWindow(panel), _("Error"),
155 _("Invalid mouse acceleration threshold value. Must be the number of pixels to travel before accelerating."),
156 _("OK"), NULL, NULL);
157 } else {
158 setMouseAccel(WMWidgetScreen(w), 0.5+(i*0.5), threshold);
160 free(tmp);
164 static void
165 returnPressed(void *observerData, WMNotification *notification)
167 _Panel *panel = (_Panel*)observerData;
169 speedClick(panel->lastClickedSpeed, panel);
173 static void
174 doubleClick(WMWidget *w, void *data)
176 _Panel *panel = (_Panel*)data;
177 int i;
178 extern _WINGsConfiguration WINGsConfiguration;
180 for (i=0; i<5; i++) {
181 if (panel->ddelaB[i]==w)
182 break;
184 WINGsConfiguration.doubleClickDelay = DELAY(i);
190 getbutton(char *str)
192 if (!str)
193 return -2;
195 if (strcasecmp(str, "left")==0)
196 return 0;
197 else if (strcasecmp(str, "middle")==0)
198 return 1;
199 else if (strcasecmp(str, "right")==0)
200 return 2;
201 else if (strcasecmp(str, "button1")==0)
202 return 0;
203 else if (strcasecmp(str, "button2")==0)
204 return 1;
205 else if (strcasecmp(str, "button3")==0)
206 return 2;
207 else if (strcasecmp(str, "button4")==0
208 || strcasecmp(str, "button5")==0) {
209 wwarning(_("mouse button %s not supported by WPrefs."), str);
210 return -2;
211 } else {
212 return -1;
217 static void
218 getMouseParameters(Display *dpy, float *accel, int *thre)
220 int n, d;
222 XGetPointerControl(dpy, &n, &d, thre);
224 *accel = (float)n/(float)d;
229 static void
230 showData(_Panel *panel)
232 char *str;
233 int i;
234 int a=-1, b=-1, c=-1;
235 float accel;
236 char buffer[32];
237 Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
239 str = GetStringForKey("SelectWindowsMouseButton");
240 i = getbutton(str);
241 if (i==-1) {
242 a = 0;
243 wwarning(_("bad value %s for option %s"),str, "SelectWindowsMouseButton");
244 WMPerformButtonClick(panel->smb[0]);
245 } else if (i>=0) {
246 a = i;
247 WMPerformButtonClick(panel->smb[i]);
250 str = GetStringForKey("WindowListMouseButton");
251 i = getbutton(str);
252 if (i==-1) {
253 b = 0;
254 wwarning(_("bad value %s for option %s"), str, "WindowListMouseButton");
255 WMPerformButtonClick(panel->lmb[1]);
256 } else if (i>=0) {
257 b = i;
258 WMPerformButtonClick(panel->lmb[i]);
261 str = GetStringForKey("ApplicationMenuMouseButton");
262 i = getbutton(str);
263 if (i==-1) {
264 c = 0;
265 wwarning(_("bad value %s for option %s"), str, "ApplicationMenuMouseButton");
266 WMPerformButtonClick(panel->amb[2]);
267 } else if (i>=0) {
268 c = i;
269 WMPerformButtonClick(panel->amb[i]);
273 WMSetButtonSelected(panel->disaB, GetBoolForKey("DisableWSMouseActions"));
275 /**/
276 getMouseParameters(dpy, &accel, &a);
277 panel->maxThreshold = WidthOfScreen(DefaultScreenOfDisplay(dpy));
278 if (a > panel->maxThreshold) {
279 panel->maxThreshold = a;
281 sprintf(buffer, "%i", a);
282 WMSetTextFieldText(panel->threT, buffer);
283 /* find best match */
284 a = 0;
285 for (i=0; i<5; i++) {
286 if (fabs((0.5+((float)i*0.5))-accel) < fabs((0.5+((float)a*0.5))-accel))
287 a = i;
289 WMPerformButtonClick(panel->speedB[a]);
290 panel->lastClickedSpeed = panel->speedB[a];
291 panel->acceleration = accel;
293 speedClick(panel->lastClickedSpeed, panel);
294 /**/
295 b = GetIntegerForKey("DoubleClickTime");
296 /* find best match */
297 a = 0;
298 for (i=0; i<5; i++) {
299 if (abs(b - DELAY(i)) < abs(b - DELAY(a)))
300 a = i;
302 WMPerformButtonClick(panel->ddelaB[a]);
304 /**/
305 str = GetStringForKey("ModifierKey");
307 a = ModifierFromKey(dpy, str);
309 if (a != -1) {
310 str = modifierNames[a];
312 a = 0;
313 for (i=0; i<WMGetPopUpButtonNumberOfItems(panel->grabP); i++) {
314 if (strstr(WMGetPopUpButtonItem(panel->grabP, i), str)) {
315 WMSetPopUpButtonSelectedItem(panel->grabP, i);
316 a = 1;
317 break;
322 if (a < 1) {
323 sscanf(WMGetPopUpButtonItem(panel->grabP, 0), "%s", buffer);
324 WMSetPopUpButtonSelectedItem(panel->grabP, 0);
325 wwarning(_("modifier key %s for option ModifierKey was not recognized. Using %s as default"),
326 str, buffer);
332 static void
333 fillModifierPopUp(WMPopUpButton *pop)
335 XModifierKeymap *mapping;
336 Display *dpy = WMScreenDisplay(WMWidgetScreen(pop));
337 int i, j;
338 char *str;
339 char buffer[64];
342 mapping = XGetModifierMapping(dpy);
344 if (!mapping || mapping->max_keypermod==0) {
345 WMAddPopUpButtonItem(pop, "Mod1");
346 WMAddPopUpButtonItem(pop, "Mod2");
347 WMAddPopUpButtonItem(pop, "Mod3");
348 WMAddPopUpButtonItem(pop, "Mod4");
349 WMAddPopUpButtonItem(pop, "Mod5");
350 wwarning(_("could not retrieve keyboard modifier mapping"));
351 return;
355 for (j=0; j<8; j++) {
356 int idx;
357 char *array[8];
358 int a;
359 KeySym ksym;
360 int k;
361 char *ptr;
362 char *tmp;
364 a = 0;
365 memset(array, 0, sizeof(char*)*8);
366 for (i=0; i < mapping->max_keypermod; i++) {
367 idx = i+j*mapping->max_keypermod;
368 if (mapping->modifiermap[idx]!=0) {
369 int l;
370 for (l=0; l<4; l++) {
371 ksym = XKeycodeToKeysym(dpy, mapping->modifiermap[idx], l);
372 if (ksym!=NoSymbol)
373 break;
375 if (ksym!=NoSymbol)
376 str = XKeysymToString(ksym);
377 else
378 str = NULL;
379 if (str && !strstr(str, "_Lock") && !strstr(str, "Shift")
380 && !strstr(str, "Control")) {
381 array[a++] = wstrdup(str);
386 for (k=0; k<a; k++) {
387 if (array[k]==NULL)
388 continue;
389 tmp = wstrdup(array[k]);
390 ptr = strstr(tmp, "_L");
391 if (ptr)
392 *ptr = 0;
393 ptr = strstr(tmp, "_R");
394 if (ptr)
395 *ptr = 0;
396 sprintf(buffer, "%s (%s)", modifierNames[j], tmp);
397 WMAddPopUpButtonItem(pop, buffer);
398 for (i=k+1; i<a; i++) {
399 if (strstr(array[i], tmp)) {
400 free(array[i]);
401 array[i]=NULL;
402 break;
405 free(tmp);
408 while (--a>0) {
409 if (array[a])
410 free(array[a]);
414 if (mapping)
415 XFreeModifiermap(mapping);
420 static void
421 mouseButtonClickA(WMWidget *w, void *data)
423 _Panel *panel = (_Panel*)data;
424 int i;
426 for (i=0; i<3; i++) {
427 if (panel->amb[i]==w)
428 break;
430 if (i==3)
431 return;
432 if (WMGetButtonSelected(panel->lmb[i]))
433 WMSetButtonSelected(panel->lmb[i], False);
434 if (WMGetButtonSelected(panel->smb[i]))
435 WMSetButtonSelected(panel->smb[i], False);
438 static void
439 mouseButtonClickL(WMWidget *w, void *data)
441 _Panel *panel = (_Panel*)data;
442 int i;
444 for (i=0; i<3; i++) {
445 if (panel->lmb[i]==w)
446 break;
448 if (i==3)
449 return;
450 if (WMGetButtonSelected(panel->smb[i]))
451 WMSetButtonSelected(panel->smb[i], False);
452 if (WMGetButtonSelected(panel->amb[i]))
453 WMSetButtonSelected(panel->amb[i], False);
456 static void
457 mouseButtonClickS(WMWidget *w, void *data)
459 _Panel *panel = (_Panel*)data;
460 int i;
462 for (i=0; i<3; i++) {
463 if (panel->smb[i]==w)
464 break;
466 if (i==3)
467 return;
468 if (WMGetButtonSelected(panel->lmb[i]))
469 WMSetButtonSelected(panel->lmb[i], False);
470 if (WMGetButtonSelected(panel->amb[i]))
471 WMSetButtonSelected(panel->amb[i], False);
474 static void
475 createPanel(Panel *p)
477 _Panel *panel = (_Panel*)p;
478 WMScreen *scr = WMWidgetScreen(panel->win);
479 WMPixmap *icon;
480 char *buf1, *buf2;
481 int i;
482 RColor color;
483 char *path;
485 color.red = 0xaa;
486 color.green = 0xae;
487 color.blue = 0xaa;
489 panel->frame = WMCreateFrame(panel->win);
490 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
491 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
493 /**************** Mouse Speed ****************/
494 panel->speedF = WMCreateFrame(panel->frame);
495 WMResizeWidget(panel->speedF, 245, 100);
496 WMMoveWidget(panel->speedF, 15, 15);
497 WMSetFrameTitle(panel->speedF, _("Mouse Speed"));
499 panel->speedL = WMCreateLabel(panel->speedF);
500 WMResizeWidget(panel->speedL, 40, 46);
501 WMMoveWidget(panel->speedL, 15, 14);
502 WMSetLabelImagePosition(panel->speedL, WIPImageOnly);
503 path = LocateImage(SPEED_ICON_FILE);
504 if (path) {
505 icon = WMCreateBlendedPixmapFromFile(scr, path, &color);
506 if (icon) {
507 WMSetLabelImage(panel->speedL, icon);
508 WMReleasePixmap(icon);
509 } else {
510 wwarning(_("could not load icon %s"), path);
512 free(path);
515 buf1 = wmalloc(strlen(SPEED_IMAGE)+1);
516 buf2 = wmalloc(strlen(SPEED_IMAGE_S)+1);
518 for (i = 0; i < 5; i++) {
519 panel->speedB[i] = WMCreateCustomButton(panel->speedF,
520 WBBStateChangeMask);
521 WMResizeWidget(panel->speedB[i], 26, 26);
522 WMMoveWidget(panel->speedB[i], 60+(35*i), 25);
523 WMSetButtonBordered(panel->speedB[i], False);
524 WMSetButtonImagePosition(panel->speedB[i], WIPImageOnly);
525 WMSetButtonAction(panel->speedB[i], speedClick, panel);
526 if (i > 0) {
527 WMGroupButtons(panel->speedB[0], panel->speedB[i]);
529 sprintf(buf1, SPEED_IMAGE, i);
530 sprintf(buf2, SPEED_IMAGE_S, i);
531 path = LocateImage(buf1);
532 if (path) {
533 icon = WMCreatePixmapFromFile(scr, path);
534 if (icon) {
535 WMSetButtonImage(panel->speedB[i], icon);
536 WMReleasePixmap(icon);
537 } else {
538 wwarning(_("could not load icon file %s"), path);
540 free(path);
542 path = LocateImage(buf2);
543 if (path) {
544 icon = WMCreatePixmapFromFile(scr, path);
545 if (icon) {
546 WMSetButtonAltImage(panel->speedB[i], icon);
547 WMReleasePixmap(icon);
548 } else {
549 wwarning(_("could not load icon file %s"), path);
553 free(buf1);
554 free(buf2);
556 panel->acceL = WMCreateLabel(panel->speedF);
557 WMResizeWidget(panel->acceL, 100, 16);
558 WMMoveWidget(panel->acceL, 10, 67);
561 panel->threL = WMCreateLabel(panel->speedF);
562 WMResizeWidget(panel->threL, 80, 16);
563 WMMoveWidget(panel->threL, 120, 67);
564 WMSetLabelText(panel->threL, _("Threshold:"));
566 panel->threT = WMCreateTextField(panel->speedF);
567 WMResizeWidget(panel->threT, 40, 20);
568 WMMoveWidget(panel->threT, 190, 65);
569 WMAddNotificationObserver(returnPressed, panel,
570 WMTextDidEndEditingNotification, panel->threT);
572 WMMapSubwidgets(panel->speedF);
574 /***************** Doubleclick Delay ****************/
576 panel->ddelaF = WMCreateFrame(panel->frame);
577 WMResizeWidget(panel->ddelaF, 245, 95);
578 WMMoveWidget(panel->ddelaF, 15, 125);
579 WMSetFrameTitle(panel->ddelaF, _("Double-Click Delay"));
581 buf1 = wmalloc(strlen(DELAY_ICON)+1);
582 buf2 = wmalloc(strlen(DELAY_ICON_S)+1);
584 for (i = 0; i < 5; i++) {
585 panel->ddelaB[i] = WMCreateCustomButton(panel->ddelaF,
586 WBBStateChangeMask);
587 WMResizeWidget(panel->ddelaB[i], 25, 25);
588 WMMoveWidget(panel->ddelaB[i], 30+(40*i), 20);
589 WMSetButtonBordered(panel->ddelaB[i], False);
590 WMSetButtonImagePosition(panel->ddelaB[i], WIPImageOnly);
591 WMSetButtonAction(panel->ddelaB[i], doubleClick, panel);
592 if (i>0) {
593 WMGroupButtons(panel->ddelaB[0], panel->ddelaB[i]);
595 sprintf(buf1, DELAY_ICON, i+1);
596 sprintf(buf2, DELAY_ICON_S, i+1);
597 path = LocateImage(buf1);
598 if (path) {
599 icon = WMCreatePixmapFromFile(scr, path);
600 if (icon) {
601 WMSetButtonImage(panel->ddelaB[i], icon);
602 WMReleasePixmap(icon);
603 } else {
604 wwarning(_("could not load icon file %s"), path);
606 free(path);
608 path = LocateImage(buf2);
609 if (path) {
610 icon = WMCreatePixmapFromFile(scr, path);
611 if (icon) {
612 WMSetButtonAltImage(panel->ddelaB[i], icon);
613 WMReleasePixmap(icon);
614 } else {
615 wwarning(_("could not load icon file %s"), path);
617 free(path);
620 free(buf1);
621 free(buf2);
623 panel->tester = CreateDoubleTest(panel->ddelaF, _("Test"));
624 WMResizeWidget(panel->tester, 84, 29);
625 WMMoveWidget(panel->tester, 85, 55);
627 WMMapSubwidgets(panel->ddelaF);
629 /* ************** Workspace Action Buttons **************** */
630 panel->menuF = WMCreateFrame(panel->frame);
631 WMResizeWidget(panel->menuF, 240, 145);
632 WMMoveWidget(panel->menuF, 270, 15);
633 WMSetFrameTitle(panel->menuF, _("Workspace Mouse Actions"));
635 panel->disaB = WMCreateSwitchButton(panel->menuF);
636 WMResizeWidget(panel->disaB, 205, 18);
637 WMMoveWidget(panel->disaB, 10, 20);
638 WMSetButtonText(panel->disaB, _("Disable mouse actions"));
640 panel->mblL = WMCreateLabel(panel->menuF);
641 WMResizeWidget(panel->mblL, 16, 22);
642 WMMoveWidget(panel->mblL, 135, 40);
643 WMSetLabelImagePosition(panel->mblL, WIPImageOnly);
644 path = LocateImage(MOUSEB_L);
645 if (path) {
646 icon = WMCreatePixmapFromFile(scr, path);
647 if (icon) {
648 WMSetLabelImage(panel->mblL, icon);
649 WMReleasePixmap(icon);
650 } else {
651 wwarning(_("could not load icon file %s"), path);
653 free(path);
655 panel->mbmL = WMCreateLabel(panel->menuF);
656 WMResizeWidget(panel->mbmL, 16, 22);
657 WMMoveWidget(panel->mbmL, 170, 40);
658 WMSetLabelImagePosition(panel->mbmL, WIPImageOnly);
659 path = LocateImage(MOUSEB_M);
660 if (path) {
661 icon = WMCreatePixmapFromFile(scr, path);
662 if (icon) {
663 WMSetLabelImage(panel->mbmL, icon);
664 WMReleasePixmap(icon);
665 } else {
666 wwarning(_("could not load icon file %s"), path);
668 free(path);
671 panel->mbrL = WMCreateLabel(panel->menuF);
672 WMResizeWidget(panel->mbrL, 16, 22);
673 WMMoveWidget(panel->mbrL, 205, 40);
674 WMSetLabelImagePosition(panel->mbrL, WIPImageOnly);
675 path = LocateImage(MOUSEB_R);
676 if (path) {
677 icon = WMCreatePixmapFromFile(scr, path);
678 if (icon) {
679 WMSetLabelImage(panel->mbrL, icon);
680 WMReleasePixmap(icon);
681 } else {
682 wwarning(_("could not load icon file %s"), path);
684 free(path);
687 panel->appL = WMCreateLabel(panel->menuF);
688 WMResizeWidget(panel->appL, 125, 16);
689 WMMoveWidget(panel->appL, 5, 65);
690 WMSetLabelTextAlignment(panel->appL, WARight);
691 WMSetLabelText(panel->appL, _("Applications menu"));
693 panel->listL = WMCreateLabel(panel->menuF);
694 WMResizeWidget(panel->listL, 125, 16);
695 WMMoveWidget(panel->listL, 5, 90);
696 WMSetLabelTextAlignment(panel->listL, WARight);
697 WMSetLabelText(panel->listL, _("Window list menu"));
699 panel->selL = WMCreateLabel(panel->menuF);
700 WMResizeWidget(panel->selL, 125, 16);
701 WMMoveWidget(panel->selL, 5, 115);
702 WMSetLabelTextAlignment(panel->selL, WARight);
703 WMSetLabelText(panel->selL, _("Select windows"));
706 for (i=0; i<3; i++) {
707 panel->amb[i] = WMCreateRadioButton(panel->menuF);
708 WMResizeWidget(panel->amb[i], 24, 24);
709 WMMoveWidget(panel->amb[i], 135+35*i, 65);
710 WMSetButtonText(panel->amb[i], NULL);
711 WMSetButtonAction(panel->amb[i], mouseButtonClickA, panel);
713 panel->lmb[i] = WMCreateRadioButton(panel->menuF);
714 WMResizeWidget(panel->lmb[i], 24, 24);
715 WMMoveWidget(panel->lmb[i], 135+35*i, 90);
716 WMSetButtonText(panel->lmb[i], NULL);
717 WMSetButtonAction(panel->lmb[i], mouseButtonClickL, panel);
719 panel->smb[i] = WMCreateRadioButton(panel->menuF);
720 WMResizeWidget(panel->smb[i], 24, 24);
721 WMMoveWidget(panel->smb[i], 135+35*i, 115);
722 WMSetButtonText(panel->smb[i], NULL);
723 WMSetButtonAction(panel->smb[i], mouseButtonClickS, panel);
725 if (i>0) {
726 WMGroupButtons(panel->lmb[0], panel->lmb[i]);
727 WMGroupButtons(panel->amb[0], panel->amb[i]);
728 WMGroupButtons(panel->smb[0], panel->smb[i]);
732 WMMapSubwidgets(panel->menuF);
734 /* ************** Grab Modifier **************** */
735 panel->grabF = WMCreateFrame(panel->frame);
736 WMResizeWidget(panel->grabF, 240, 55);
737 WMMoveWidget(panel->grabF, 270, 165);
738 WMSetFrameTitle(panel->grabF, _("Mouse Grab Modifier"));
740 panel->grabP = WMCreatePopUpButton(panel->grabF);
741 WMResizeWidget(panel->grabP, 160, 20);
742 WMMoveWidget(panel->grabP, 40, 25);
744 fillModifierPopUp(panel->grabP);
746 WMMapSubwidgets(panel->grabF);
748 WMRealizeWidget(panel->frame);
749 WMMapSubwidgets(panel->frame);
752 showData(panel);
756 static void
757 storeCommandInScript(char *cmd, char *line)
759 char *path;
760 char *p;
761 FILE *f;
762 char buffer[128];
764 p = wusergnusteppath();
765 path = wmalloc(strlen(p)+64);
766 sprintf(path, "%s/Library/WindowMaker/autostart", p);
768 f = fopen(path, "r");
769 if (!f) {
770 f = fopen(path, "w");
771 if (!f) {
772 wsyserror(_("could not create %s"), path);
773 goto end;
775 fprintf(f, "#!/bin/sh\n");
776 fputs(line, f);
777 fputs("\n", f);
778 } else {
779 int len = strlen(cmd);
780 int ok = 0;
781 char *tmppath;
782 FILE *fo;
784 tmppath = wmalloc(strlen(p)+64);
785 sprintf(tmppath, "%s/Library/WindowMaker/autostart.tmp", p);
786 fo = fopen(tmppath, "w");
787 if (!fo) {
788 wsyserror(_("could not create temporary file %s"), tmppath);
789 goto end;
792 while (!feof(f)) {
793 if (!fgets(buffer, 127, f)) {
794 break;
796 if (strncmp(buffer, cmd, len)==0) {
797 if (!ok) {
798 fputs(line, fo);
799 fputs("\n", fo);
800 ok = 1;
802 } else {
803 fputs(buffer, fo);
806 if (!ok) {
807 fputs(line, fo);
808 fputs("\n", fo);
810 fclose(fo);
812 if (rename(tmppath, path)!=0) {
813 wsyserror(_("could not rename file %s to %s\n"), tmppath, path);
815 free(tmppath);
817 sprintf(buffer, "chmod u+x %s", path);
818 system(buffer);
820 end:
821 free(p);
822 free(path);
823 if (f)
824 fclose(f);
828 static void
829 storeData(_Panel *panel)
831 char buffer[64];
832 int i;
833 char *tmp, *p;
834 static char *button[3] = {"left", "middle", "right"};
836 tmp = WMGetTextFieldText(panel->threT);
837 if (strlen(tmp)==0) {
838 free(tmp);
839 tmp = wstrdup("0");
842 sprintf(buffer, XSET" m %i/%i %s\n", (int)(panel->acceleration*10),10, tmp);
843 storeCommandInScript(XSET" m", buffer);
845 free(tmp);
847 for (i=0; i<5; i++) {
848 if (WMGetButtonSelected(panel->ddelaB[i]))
849 break;
851 SetIntegerForKey(DELAY(i), "DoubleClickTime");
853 SetBoolForKey(WMGetButtonSelected(panel->disaB), "DisableWSMouseActions");
855 for (i=0; i<3; i++) {
856 if (WMGetButtonSelected(panel->amb[i]))
857 break;
859 if (i<3)
860 SetStringForKey(button[i], "ApplicationMenuMouseButton");
862 for (i=0; i<3; i++) {
863 if (WMGetButtonSelected(panel->lmb[i]))
864 break;
866 if (i<3)
867 SetStringForKey(button[i], "WindowListMouseButton");
869 for (i=0; i<3; i++) {
870 if (WMGetButtonSelected(panel->smb[i]))
871 break;
873 if (i<3)
874 SetStringForKey(button[i], "SelectWindowsMouseButton");
876 tmp = WMGetPopUpButtonItem(panel->grabP,
877 WMGetPopUpButtonSelectedItem(panel->grabP));
878 tmp = wstrdup(tmp);
879 p = strchr(tmp, ' ');
880 *p = 0;
882 SetStringForKey(tmp, "ModifierKey");
884 free(tmp);
888 Panel*
889 InitMouseSettings(WMScreen *scr, WMWindow *win)
891 _Panel *panel;
893 panel = wmalloc(sizeof(_Panel));
894 memset(panel, 0, sizeof(_Panel));
896 panel->sectionName = _("Mouse Preferences");
898 panel->win = win;
900 panel->callbacks.createWidgets = createPanel;
901 panel->callbacks.updateDomain = storeData;
903 AddSection(panel, ICON_FILE);
905 return panel;