Files
wmaker/WPrefs.app/MouseSettings.c
T

864 lines
23 KiB
C
Raw Normal View History

1999-04-17 18:24:23 +00:00
1998-09-29 22:36:29 +00:00
/* MouseSettings.c- mouse options (some are equivalent to xset)
2004-10-12 21:28:27 +00:00
*
1998-10-21 14:43:47 +00:00
* WPrefs - Window Maker Preferences Program
2004-10-12 21:28:27 +00:00
*
2003-01-16 23:30:45 +00:00
* Copyright (c) 1998-2003 Alfredo K. Kojima
2004-10-12 21:28:27 +00:00
*
1998-09-29 22:36:29 +00:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2004-10-12 21:28:27 +00:00
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
1998-09-29 22:36:29 +00:00
* USA.
*/
#include "WPrefs.h"
#include <X11/Xutil.h>
#include <math.h>
/* double-click tester */
#include "double.h"
#define XSET "xset"
typedef struct _Panel {
WMBox *box;
1998-09-29 22:36:29 +00:00
char *sectionName;
1999-04-25 01:49:46 +00:00
char *description;
1998-09-29 22:36:29 +00:00
CallbackRec callbacks;
2004-10-12 21:28:27 +00:00
WMWidget *parent;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
WMFrame *speedF;
WMLabel *speedL;
1999-04-17 18:24:23 +00:00
WMSlider *speedS;
1998-09-29 22:36:29 +00:00
WMLabel *acceL;
1999-01-25 19:06:50 +00:00
WMTextField *acceT;
1998-09-29 22:36:29 +00:00
WMLabel *threL;
WMTextField *threT;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
WMFrame *ddelaF;
WMButton *ddelaB[5];
1999-03-09 14:58:01 +00:00
WMTextField *ddelaT;
WMLabel *ddelaL;
1998-09-29 22:36:29 +00:00
DoubleTest *tester;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
WMFrame *menuF;
WMLabel *button1L;
WMLabel *button2L;
WMLabel *button3L;
WMLabel *wheelL;
WMPopUpButton *button1P;
WMPopUpButton *button2P;
WMPopUpButton *button3P;
WMPopUpButton *wheelP;
1998-09-29 22:36:29 +00:00
WMButton *disaB;
WMFrame *grabF;
WMPopUpButton *grabP;
/**/
int maxThreshold;
float acceleration;
} _Panel;
#define ICON_FILE "mousesettings"
#define SPEED_ICON_FILE "mousespeed"
#define DELAY_ICON "timer%i"
#define DELAY_ICON_S "timer%is"
/* need access to the double click variables */
#include <WINGs/WINGsP.h>
1998-09-29 22:36:29 +00:00
2004-10-12 21:28:27 +00:00
static char *modifierNames[8];
2001-02-08 22:43:00 +00:00
static char *buttonActions[4];
static char *wheelActions[2];
1999-09-16 03:01:14 +00:00
1998-09-29 22:36:29 +00:00
#define DELAY(i) ((i)*75+170)
int ModifierFromKey(Display *dpy, char *key);
static void
setMouseAccel(WMScreen *scr, float accel, int threshold)
{
int n, d;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
d = 10;
n = accel*d;
XChangePointerControl(WMScreenDisplay(scr), True, True, n, d, threshold);
}
static void
1999-04-17 18:24:23 +00:00
speedChange(WMWidget *w, void *data)
1998-09-29 22:36:29 +00:00
{
_Panel *panel = (_Panel*)data;
int i;
char buffer[64];
int threshold;
char *tmp;
1999-01-25 19:06:50 +00:00
if (w == NULL) {
2004-10-12 21:28:27 +00:00
float accel;
tmp = WMGetTextFieldText(panel->acceT);
if (sscanf(tmp, "%f", &accel)!=1 || accel < 0) {
WMRunAlertPanel(WMWidgetScreen(panel->acceT), GetWindow(panel),
_("Error"),
_("Invalid mouse acceleration value. Must be a positive real value."),
_("OK"), NULL, NULL);
wfree(tmp);
return;
}
panel->acceleration = accel;
wfree(tmp);
1999-01-25 19:06:50 +00:00
} else {
2004-10-12 21:28:27 +00:00
i = (int)WMGetSliderValue(panel->speedS);
panel->acceleration = 0.25+(i*0.25);
1999-01-25 19:06:50 +00:00
2004-10-12 21:28:27 +00:00
sprintf(buffer, "%.2f", 0.25+(i*0.25));
WMSetTextFieldText(panel->acceT, buffer);
1999-01-25 19:06:50 +00:00
}
1998-09-29 22:36:29 +00:00
tmp = WMGetTextFieldText(panel->threT);
2004-10-12 21:28:27 +00:00
if (sscanf(tmp, "%i", &threshold)!=1 || threshold < 0
|| threshold > panel->maxThreshold) {
WMRunAlertPanel(WMWidgetScreen(panel->parent), GetWindow(panel), _("Error"),
_("Invalid mouse acceleration threshold value. Must be the number of pixels to travel before accelerating."),
_("OK"), NULL, NULL);
1998-09-29 22:36:29 +00:00
} else {
2004-10-12 21:28:27 +00:00
setMouseAccel(WMWidgetScreen(panel->parent), panel->acceleration,
threshold);
1998-09-29 22:36:29 +00:00
}
wfree(tmp);
1998-09-29 22:36:29 +00:00
}
static void
returnPressed(void *observerData, WMNotification *notification)
{
_Panel *panel = (_Panel*)observerData;
1999-04-17 18:24:23 +00:00
speedChange(NULL, panel);
1998-09-29 22:36:29 +00:00
}
static void
doubleClick(WMWidget *w, void *data)
{
_Panel *panel = (_Panel*)data;
int i;
extern _WINGsConfiguration WINGsConfiguration;
1999-03-09 14:58:01 +00:00
char buffer[32];
1998-09-29 22:36:29 +00:00
for (i=0; i<5; i++) {
2004-10-12 21:28:27 +00:00
if (panel->ddelaB[i]==w)
break;
1998-09-29 22:36:29 +00:00
}
WINGsConfiguration.doubleClickDelay = DELAY(i);
2004-10-12 21:28:27 +00:00
1999-03-09 14:58:01 +00:00
sprintf(buffer, "%i", DELAY(i));
WMSetTextFieldText(panel->ddelaT, buffer);
1998-09-29 22:36:29 +00:00
}
static int
getButtonAction(char *str)
1998-09-29 22:36:29 +00:00
{
if (!str)
2004-10-12 21:28:27 +00:00
return -2;
1998-09-29 22:36:29 +00:00
if (strcasecmp(str, "None")==0)
2004-10-12 21:28:27 +00:00
return 0;
else if (strcasecmp(str, "OpenApplicationsMenu")==0)
2004-10-12 21:28:27 +00:00
return 1;
else if (strcasecmp(str, "OpenWindowListMenu")==0)
2004-10-12 21:28:27 +00:00
return 2;
else if (strcasecmp(str, "SelectWindows")==0)
2004-10-12 21:28:27 +00:00
return 3;
else
return -1;
}
static int
getWheelAction(char *str)
{
if (!str)
2004-10-12 21:28:27 +00:00
return -2;
if (strcasecmp(str, "None")==0)
2004-10-12 21:28:27 +00:00
return 0;
else if (strcasecmp(str, "SwitchWorkspaces")==0)
2004-10-12 21:28:27 +00:00
return 1;
else
2004-10-12 21:28:27 +00:00
return -1;
1998-09-29 22:36:29 +00:00
}
static void
getMouseParameters(Display *dpy, float *accel, int *thre)
{
int n, d;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
XGetPointerControl(dpy, &n, &d, thre);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
*accel = (float)n/(float)d;
}
static void
showData(_Panel *panel)
{
char *str;
int i;
int a=-1, b=-1, c=-1, w=-1;
1998-09-29 22:36:29 +00:00
float accel;
char buffer[32];
Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->parent));
1998-09-29 22:36:29 +00:00
str = GetStringForKey("MouseLeftButtonAction");
i = getButtonAction(str);
if (i<0) {
a = 3;
if (i==-1) {
wwarning(_("bad value %s for option %s"), str, "MouseLeftButtonAction");
}
1999-09-16 03:01:14 +00:00
} else {
a = i;
1999-09-16 03:01:14 +00:00
}
WMSetPopUpButtonSelectedItem(panel->button1P, a);
2004-10-12 21:28:27 +00:00
str = GetStringForKey("MouseMiddleButtonAction");
i = getButtonAction(str);
if (i<0) {
b = 2;
if (i==-1) {
wwarning(_("bad value %s for option %s"), str, "MouseMiddleButtonAction");
}
1999-09-16 03:01:14 +00:00
} else {
b = i;
1999-09-16 03:01:14 +00:00
}
WMSetPopUpButtonSelectedItem(panel->button2P, b);
2004-10-12 21:28:27 +00:00
str = GetStringForKey("MouseRightButtonAction");
i = getButtonAction(str);
if (i<0) {
c = 1;
if (i==-1) {
wwarning(_("bad value %s for option %s"), str, "MouseRightButtonAction");
}
} else {
c = i;
}
WMSetPopUpButtonSelectedItem(panel->button3P, c);
str = GetStringForKey("MouseWheelAction");
i = getWheelAction(str);
if (i<0) {
w = 0;
if (i==-1) {
wwarning(_("bad value %s for option %s"), str, "MouseWheelAction");
}
1999-09-16 03:01:14 +00:00
} else {
w = i;
1998-09-29 22:36:29 +00:00
}
WMSetPopUpButtonSelectedItem(panel->wheelP, w);
1999-09-16 03:01:14 +00:00
1998-09-29 22:36:29 +00:00
WMSetButtonSelected(panel->disaB, GetBoolForKey("DisableWSMouseActions"));
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
/**/
getMouseParameters(dpy, &accel, &a);
panel->maxThreshold = WidthOfScreen(DefaultScreenOfDisplay(dpy));
if (a > panel->maxThreshold) {
2004-10-12 21:28:27 +00:00
panel->maxThreshold = a;
1998-09-29 22:36:29 +00:00
}
sprintf(buffer, "%i", a);
WMSetTextFieldText(panel->threT, buffer);
1999-03-09 14:58:01 +00:00
1999-04-17 18:24:23 +00:00
WMSetSliderValue(panel->speedS, (accel - 0.25)/0.25);
1998-09-29 22:36:29 +00:00
panel->acceleration = accel;
1999-03-09 14:58:01 +00:00
sprintf(buffer, "%.2f", accel);
WMSetTextFieldText(panel->acceT, buffer);
1998-09-29 22:36:29 +00:00
/**/
b = GetIntegerForKey("DoubleClickTime");
/* find best match */
1999-03-09 14:58:01 +00:00
a = -1;
1998-09-29 22:36:29 +00:00
for (i=0; i<5; i++) {
2004-10-12 21:28:27 +00:00
if (DELAY(i) == b)
a = i;
1998-09-29 22:36:29 +00:00
}
1999-03-09 14:58:01 +00:00
if (a >= 0)
2004-10-12 21:28:27 +00:00
WMPerformButtonClick(panel->ddelaB[a]);
1999-03-09 14:58:01 +00:00
sprintf(buffer, "%i", b);
WMSetTextFieldText(panel->ddelaT, buffer);
1998-09-29 22:36:29 +00:00
/**/
str = GetStringForKey("ModifierKey");
if (!str)
2004-10-12 21:28:27 +00:00
str = "mod1";
1998-09-29 22:36:29 +00:00
a = ModifierFromKey(dpy, str);
1998-09-29 22:36:29 +00:00
if (a != -1) {
2004-10-12 21:28:27 +00:00
str = modifierNames[a];
a = 0;
for (i=0; i<WMGetPopUpButtonNumberOfItems(panel->grabP); i++) {
if (strstr(WMGetPopUpButtonItem(panel->grabP, i), str)) {
WMSetPopUpButtonSelectedItem(panel->grabP, i);
a = 1;
break;
}
}
1998-09-29 22:36:29 +00:00
}
1998-09-29 22:36:29 +00:00
if (a < 1) {
2004-10-12 21:28:27 +00:00
sscanf(WMGetPopUpButtonItem(panel->grabP, 0), "%s", buffer);
WMSetPopUpButtonSelectedItem(panel->grabP, 0);
wwarning(_("modifier key %s for option ModifierKey was not recognized. Using %s as default"),
str, buffer);
1998-09-29 22:36:29 +00:00
}
}
static void
fillModifierPopUp(WMPopUpButton *pop)
{
XModifierKeymap *mapping;
Display *dpy = WMScreenDisplay(WMWidgetScreen(pop));
int i, j;
char *str;
char buffer[64];
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
mapping = XGetModifierMapping(dpy);
if (!mapping || mapping->max_keypermod==0) {
2004-10-12 21:28:27 +00:00
WMAddPopUpButtonItem(pop, "Mod1");
WMAddPopUpButtonItem(pop, "Mod2");
WMAddPopUpButtonItem(pop, "Mod3");
WMAddPopUpButtonItem(pop, "Mod4");
WMAddPopUpButtonItem(pop, "Mod5");
wwarning(_("could not retrieve keyboard modifier mapping"));
return;
1998-09-29 22:36:29 +00:00
}
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
for (j=0; j<8; j++) {
2004-10-12 21:28:27 +00:00
int idx;
char *array[8];
int a;
KeySym ksym;
int k;
char *ptr;
char *tmp;
a = 0;
memset(array, 0, sizeof(char*)*8);
for (i=0; i < mapping->max_keypermod; i++) {
idx = i+j*mapping->max_keypermod;
if (mapping->modifiermap[idx]!=0) {
int l;
for (l=0; l<4; l++) {
ksym = XKeycodeToKeysym(dpy, mapping->modifiermap[idx], l);
if (ksym!=NoSymbol)
break;
}
if (ksym!=NoSymbol)
str = XKeysymToString(ksym);
else
str = NULL;
if (str && !strstr(str, "_Lock") && !strstr(str, "Shift")
&& !strstr(str, "Control")) {
array[a++] = wstrdup(str);
}
}
}
for (k=0; k<a; k++) {
if (array[k]==NULL)
continue;
tmp = wstrdup(array[k]);
ptr = strstr(tmp, "_L");
if (ptr)
*ptr = 0;
ptr = strstr(tmp, "_R");
if (ptr)
*ptr = 0;
sprintf(buffer, "%s (%s)", modifierNames[j], tmp);
/*sprintf(buffer, "%s", tmp);*/
2004-10-12 21:28:27 +00:00
WMAddPopUpButtonItem(pop, buffer);
for (i=k+1; i<a; i++) {
if (array[i] == NULL)
continue;
if (strstr(array[i], tmp)) {
wfree(array[i]);
array[i]=NULL;
break;
}
}
wfree(tmp);
}
while (--a>0) {
if (array[a])
wfree(array[a]);
}
1998-09-29 22:36:29 +00:00
}
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
if (mapping)
2004-10-12 21:28:27 +00:00
XFreeModifiermap(mapping);
1998-09-29 22:36:29 +00:00
}
static void
createPanel(Panel *p)
{
_Panel *panel = (_Panel*)p;
WMScreen *scr = WMWidgetScreen(panel->parent);
1998-09-29 22:36:29 +00:00
WMPixmap *icon;
char *buf1, *buf2;
int i;
RColor color;
char *path;
2001-04-25 02:03:08 +00:00
color.red = 0xae;
color.green = 0xaa;
color.blue = 0xae;
2004-10-12 21:28:27 +00:00
panel->box = WMCreateBox(panel->parent);
2001-04-25 02:03:08 +00:00
WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
/**************** Mouse Speed ****************/
panel->speedF = WMCreateFrame(panel->box);
1998-09-29 22:36:29 +00:00
WMResizeWidget(panel->speedF, 245, 100);
WMMoveWidget(panel->speedF, 15, 5);
1998-09-29 22:36:29 +00:00
WMSetFrameTitle(panel->speedF, _("Mouse Speed"));
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
panel->speedL = WMCreateLabel(panel->speedF);
WMResizeWidget(panel->speedL, 40, 46);
WMMoveWidget(panel->speedL, 15, 14);
WMSetLabelImagePosition(panel->speedL, WIPImageOnly);
path = LocateImage(SPEED_ICON_FILE);
if (path) {
2004-10-12 21:28:27 +00:00
icon = WMCreateBlendedPixmapFromFile(scr, path, &color);
if (icon) {
WMSetLabelImage(panel->speedL, icon);
WMReleasePixmap(icon);
} else {
wwarning(_("could not load icon %s"), path);
}
wfree(path);
1998-09-29 22:36:29 +00:00
}
1999-04-17 18:24:23 +00:00
panel->speedS = WMCreateSlider(panel->speedF);
WMResizeWidget(panel->speedS, 160, 15);
WMMoveWidget(panel->speedS, 70, 35);
WMSetSliderMinValue(panel->speedS, 0);
WMSetSliderMaxValue(panel->speedS, 40);
WMSetSliderContinuous(panel->speedS, False);
WMSetSliderAction(panel->speedS, speedChange, panel);
1998-09-29 22:36:29 +00:00
panel->acceL = WMCreateLabel(panel->speedF);
1999-03-09 14:58:01 +00:00
WMResizeWidget(panel->acceL, 70, 16);
1998-09-29 22:36:29 +00:00
WMMoveWidget(panel->acceL, 10, 67);
1999-03-09 14:58:01 +00:00
WMSetLabelTextAlignment(panel->acceL, WARight);
1999-01-25 19:06:50 +00:00
WMSetLabelText(panel->acceL, _("Acceler.:"));
panel->acceT = WMCreateTextField(panel->speedF);
1999-03-09 14:58:01 +00:00
WMResizeWidget(panel->acceT, 40, 20);
WMMoveWidget(panel->acceT, 80, 65);
1999-01-25 19:06:50 +00:00
WMAddNotificationObserver(returnPressed, panel,
2004-10-12 21:28:27 +00:00
WMTextDidEndEditingNotification, panel->acceT);
1998-09-29 22:36:29 +00:00
panel->threL = WMCreateLabel(panel->speedF);
WMResizeWidget(panel->threL, 80, 16);
WMMoveWidget(panel->threL, 120, 67);
1999-03-09 14:58:01 +00:00
WMSetLabelTextAlignment(panel->threL, WARight);
1998-09-29 22:36:29 +00:00
WMSetLabelText(panel->threL, _("Threshold:"));
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
panel->threT = WMCreateTextField(panel->speedF);
1999-01-25 19:06:50 +00:00
WMResizeWidget(panel->threT, 30, 20);
WMMoveWidget(panel->threT, 200, 65);
1998-09-29 22:36:29 +00:00
WMAddNotificationObserver(returnPressed, panel,
2004-10-12 21:28:27 +00:00
WMTextDidEndEditingNotification, panel->threT);
1998-09-29 22:36:29 +00:00
WMMapSubwidgets(panel->speedF);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
/***************** Doubleclick Delay ****************/
panel->ddelaF = WMCreateFrame(panel->box);
WMResizeWidget(panel->ddelaF, 245, 105);
WMMoveWidget(panel->ddelaF, 15, 115);
1998-09-29 22:36:29 +00:00
WMSetFrameTitle(panel->ddelaF, _("Double-Click Delay"));
2004-10-12 21:28:27 +00:00
buf1 = wmalloc(strlen(DELAY_ICON)+2);
buf2 = wmalloc(strlen(DELAY_ICON_S)+2);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
for (i = 0; i < 5; i++) {
2004-10-12 21:28:27 +00:00
panel->ddelaB[i] = WMCreateCustomButton(panel->ddelaF,
WBBStateChangeMask);
WMResizeWidget(panel->ddelaB[i], 25, 25);
WMMoveWidget(panel->ddelaB[i], 30+(40*i), 25);
WMSetButtonBordered(panel->ddelaB[i], False);
WMSetButtonImagePosition(panel->ddelaB[i], WIPImageOnly);
WMSetButtonAction(panel->ddelaB[i], doubleClick, panel);
if (i>0) {
WMGroupButtons(panel->ddelaB[0], panel->ddelaB[i]);
}
sprintf(buf1, DELAY_ICON, i+1);
sprintf(buf2, DELAY_ICON_S, i+1);
path = LocateImage(buf1);
if (path) {
icon = WMCreatePixmapFromFile(scr, path);
if (icon) {
WMSetButtonImage(panel->ddelaB[i], icon);
WMReleasePixmap(icon);
} else {
wwarning(_("could not load icon file %s"), path);
}
wfree(path);
}
path = LocateImage(buf2);
if (path) {
icon = WMCreatePixmapFromFile(scr, path);
if (icon) {
WMSetButtonAltImage(panel->ddelaB[i], icon);
WMReleasePixmap(icon);
} else {
wwarning(_("could not load icon file %s"), path);
}
wfree(path);
}
1998-09-29 22:36:29 +00:00
}
wfree(buf1);
wfree(buf2);
1998-09-29 22:36:29 +00:00
panel->tester = CreateDoubleTest(panel->ddelaF, _("Test"));
WMResizeWidget(panel->tester, 84, 29);
WMMoveWidget(panel->tester, 35, 60);
1999-03-09 14:58:01 +00:00
panel->ddelaT = WMCreateTextField(panel->ddelaF);
WMResizeWidget(panel->ddelaT, 40, 20);
WMMoveWidget(panel->ddelaT, 140, 65);
1999-03-09 14:58:01 +00:00
panel->ddelaL = WMCreateLabel(panel->ddelaF);
WMResizeWidget(panel->ddelaL, 40, 16);
WMMoveWidget(panel->ddelaL, 185, 70);
1999-03-09 14:58:01 +00:00
{
2004-10-12 21:28:27 +00:00
WMFont *font;
WMColor *color;
font = WMSystemFontOfSize(scr, 10);
color = WMDarkGrayColor(scr);
WMSetLabelTextColor(panel->ddelaL, color);
WMSetLabelFont(panel->ddelaL, font);
WMReleaseFont(font);
WMReleaseColor(color);
1999-03-09 14:58:01 +00:00
}
2001-02-08 22:43:00 +00:00
WMSetLabelText(panel->ddelaL, _("msec"));
1998-09-29 22:36:29 +00:00
WMMapSubwidgets(panel->ddelaF);
1998-09-29 22:36:29 +00:00
/* ************** Workspace Action Buttons **************** */
panel->menuF = WMCreateFrame(panel->box);
WMResizeWidget(panel->menuF, 240, 160);
WMMoveWidget(panel->menuF, 270, 5);
1998-09-29 22:36:29 +00:00
WMSetFrameTitle(panel->menuF, _("Workspace Mouse Actions"));
panel->disaB = WMCreateSwitchButton(panel->menuF);
1999-01-06 15:22:33 +00:00
WMResizeWidget(panel->disaB, 205, 18);
WMMoveWidget(panel->disaB, 10, 18);
1998-09-29 22:36:29 +00:00
WMSetButtonText(panel->disaB, _("Disable mouse actions"));
panel->button1L = WMCreateLabel(panel->menuF);
WMResizeWidget(panel->button1L, 87, 20);
WMMoveWidget(panel->button1L, 5, 45);
WMSetLabelTextAlignment(panel->button1L, WARight);
WMSetLabelText(panel->button1L, _("Left Button"));
panel->button1P = WMCreatePopUpButton(panel->menuF);
WMResizeWidget(panel->button1P, 135, 20);
WMMoveWidget(panel->button1P, 95, 45);
2004-10-12 21:28:27 +00:00
panel->button2L = WMCreateLabel(panel->menuF);
WMResizeWidget(panel->button2L, 87, 20);
WMMoveWidget(panel->button2L, 5, 73);
WMSetLabelTextAlignment(panel->button2L, WARight);
WMSetLabelText(panel->button2L, _("Middle Button"));
2004-10-12 21:28:27 +00:00
panel->button2P = WMCreatePopUpButton(panel->menuF);
WMResizeWidget(panel->button2P, 135, 20);
WMMoveWidget(panel->button2P, 95, 73);
panel->button3L = WMCreateLabel(panel->menuF);
WMResizeWidget(panel->button3L, 87, 20);
WMMoveWidget(panel->button3L, 5, 101);
WMSetLabelTextAlignment(panel->button3L, WARight);
WMSetLabelText(panel->button3L, _("Right Button"));
panel->button3P = WMCreatePopUpButton(panel->menuF);
WMResizeWidget(panel->button3P, 135, 20);
WMMoveWidget(panel->button3P, 95, 101);
panel->wheelL = WMCreateLabel(panel->menuF);
WMResizeWidget(panel->wheelL, 87, 20);
WMMoveWidget(panel->wheelL, 5, 129);
WMSetLabelTextAlignment(panel->wheelL, WARight);
WMSetLabelText(panel->wheelL, _("Mouse Wheel"));
panel->wheelP = WMCreatePopUpButton(panel->menuF);
WMResizeWidget(panel->wheelP, 135, 20);
WMMoveWidget(panel->wheelP, 95, 129);
for (i = 0; i < sizeof(buttonActions)/sizeof(char*); i++) {
WMAddPopUpButtonItem(panel->button1P, buttonActions[i]);
WMAddPopUpButtonItem(panel->button2P, buttonActions[i]);
WMAddPopUpButtonItem(panel->button3P, buttonActions[i]);
}
1998-09-29 22:36:29 +00:00
for (i = 0; i < sizeof(wheelActions)/sizeof(char*); i++) {
WMAddPopUpButtonItem(panel->wheelP, wheelActions[i]);
1998-09-29 22:36:29 +00:00
}
1998-09-29 22:36:29 +00:00
WMMapSubwidgets(panel->menuF);
1998-09-29 22:36:29 +00:00
/* ************** Grab Modifier **************** */
panel->grabF = WMCreateFrame(panel->box);
WMResizeWidget(panel->grabF, 240, 50);
WMMoveWidget(panel->grabF, 270, 170);
1998-09-29 22:36:29 +00:00
WMSetFrameTitle(panel->grabF, _("Mouse Grab Modifier"));
1999-04-25 01:49:46 +00:00
WMSetBalloonTextForView(_("Keyboard modifier to use for actions that\n"
2004-10-12 21:28:27 +00:00
"involve dragging windows with the mouse,\n"
"clicking inside the window."),
WMWidgetView(panel->grabF));
1999-04-25 01:49:46 +00:00
1998-09-29 22:36:29 +00:00
panel->grabP = WMCreatePopUpButton(panel->grabF);
1998-10-21 14:43:47 +00:00
WMResizeWidget(panel->grabP, 160, 20);
WMMoveWidget(panel->grabP, 40, 20);
1998-09-29 22:36:29 +00:00
fillModifierPopUp(panel->grabP);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
WMMapSubwidgets(panel->grabF);
2004-10-12 21:28:27 +00:00
WMRealizeWidget(panel->box);
WMMapSubwidgets(panel->box);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
showData(panel);
}
static void
storeCommandInScript(char *cmd, char *line)
{
char *path;
FILE *f;
char buffer[128];
2000-11-01 15:40:15 +00:00
path = wstrconcat(wusergnusteppath(), "/Library/WindowMaker/autostart");
2004-10-12 21:28:27 +00:00
f = fopen(path, "rb");
1998-09-29 22:36:29 +00:00
if (!f) {
2004-10-12 21:28:27 +00:00
f = fopen(path, "wb");
if (!f) {
wsyserror(_("could not create %s"), path);
goto end;
}
fprintf(f, "#!/bin/sh\n");
fputs(line, f);
fputs("\n", f);
1998-09-29 22:36:29 +00:00
} else {
2004-10-12 21:28:27 +00:00
int len = strlen(cmd);
int ok = 0;
char *tmppath;
FILE *fo;
tmppath = wstrconcat(wusergnusteppath(),
"/Library/WindowMaker/autostart.tmp");
fo = fopen(tmppath, "wb");
if (!fo) {
wsyserror(_("could not create temporary file %s"), tmppath);
wfree(tmppath);
2004-10-12 21:28:27 +00:00
goto end;
}
1998-09-29 22:36:29 +00:00
2004-10-12 21:28:27 +00:00
while (!feof(f)) {
if (!fgets(buffer, 127, f)) {
break;
}
if (buffer[0] == '\n') {
/* don't write empty lines, else the file will grow
* indefinitely (one '\n' added at end of file on each save).
*/
continue;
}
2004-10-12 21:28:27 +00:00
if (strncmp(buffer, cmd, len)==0) {
if (!ok) {
fputs(line, fo);
fputs("\n", fo);
ok = 1;
}
} else {
fputs(buffer, fo);
}
}
if (!ok) {
fputs(line, fo);
fputs("\n", fo);
}
fclose(fo);
if (rename(tmppath, path)!=0) {
wsyserror(_("could not rename file %s to %s\n"), tmppath, path);
}
wfree(tmppath);
1998-09-29 22:36:29 +00:00
}
sprintf(buffer, "chmod u+x %s", path);
system(buffer);
end:
wfree(path);
1998-09-29 22:36:29 +00:00
if (f)
2004-10-12 21:28:27 +00:00
fclose(f);
1998-09-29 22:36:29 +00:00
}
static void
storeData(_Panel *panel)
{
char buffer[64];
int i;
char *tmp, *p;
static char *button[4] = {"None", "OpenApplicationsMenu", "OpenWindowListMenu", "SelectWindows"};
static char *wheel[2] = {"None", "SwitchWorkspaces"};
WMUserDefaults *udb = WMGetStandardUserDefaults();
if (!WMGetUDBoolForKey(udb, "NoXSetStuff")) {
2004-10-12 21:28:27 +00:00
tmp = WMGetTextFieldText(panel->threT);
if (strlen(tmp)==0) {
wfree(tmp);
tmp = wstrdup("4");
}
2004-10-12 21:28:27 +00:00
sprintf(buffer, XSET" m %i/%i %s\n", (int)(panel->acceleration*10),
10, tmp);
storeCommandInScript(XSET" m", buffer);
1998-09-29 22:36:29 +00:00
2004-10-12 21:28:27 +00:00
wfree(tmp);
1998-09-29 22:36:29 +00:00
}
1999-03-09 14:58:01 +00:00
tmp = WMGetTextFieldText(panel->ddelaT);
if (sscanf(tmp, "%i", &i) == 1 && i > 0)
2004-10-12 21:28:27 +00:00
SetIntegerForKey(i, "DoubleClickTime");
1998-09-29 22:36:29 +00:00
SetBoolForKey(WMGetButtonSelected(panel->disaB), "DisableWSMouseActions");
i = WMGetPopUpButtonSelectedItem(panel->button1P);
SetStringForKey(button[i], "MouseLeftButtonAction");
1999-09-16 03:01:14 +00:00
i = WMGetPopUpButtonSelectedItem(panel->button2P);
SetStringForKey(button[i], "MouseMiddleButtonAction");
2004-10-12 21:28:27 +00:00
i = WMGetPopUpButtonSelectedItem(panel->button3P);
SetStringForKey(button[i], "MouseRightButtonAction");
2004-10-12 21:28:27 +00:00
i = WMGetPopUpButtonSelectedItem(panel->wheelP);
SetStringForKey(wheel[i], "MouseWheelAction");
2004-10-12 21:28:27 +00:00
1999-09-16 03:01:14 +00:00
tmp = WMGetPopUpButtonItem(panel->grabP,
2004-10-12 21:28:27 +00:00
WMGetPopUpButtonSelectedItem(panel->grabP));
1998-09-29 22:36:29 +00:00
tmp = wstrdup(tmp);
p = strchr(tmp, ' ');
*p = 0;
SetStringForKey(tmp, "ModifierKey");
wfree(tmp);
1998-09-29 22:36:29 +00:00
}
Panel*
InitMouseSettings(WMScreen *scr, WMWidget *parent)
1998-09-29 22:36:29 +00:00
{
_Panel *panel;
2001-02-08 22:43:00 +00:00
modifierNames[0] = wstrdup(_("Shift"));
modifierNames[1] = wstrdup(_("Lock"));
modifierNames[2] = wstrdup(_("Control"));
modifierNames[3] = wstrdup(_("Mod1"));
modifierNames[4] = wstrdup(_("Mod2"));
modifierNames[5] = wstrdup(_("Mod3"));
modifierNames[6] = wstrdup(_("Mod4"));
modifierNames[7] = wstrdup(_("Mod5"));
buttonActions[0] = wstrdup(_("None"));
buttonActions[1] = wstrdup(_("Applications Menu"));
buttonActions[2] = wstrdup(_("Window List Menu"));
buttonActions[3] = wstrdup(_("Select Windows"));
wheelActions[0] = wstrdup(_("None"));
wheelActions[1] = wstrdup(_("Switch Workspaces"));
1998-09-29 22:36:29 +00:00
panel = wmalloc(sizeof(_Panel));
memset(panel, 0, sizeof(_Panel));
panel->sectionName = _("Mouse Preferences");
1999-04-25 01:49:46 +00:00
panel->description = _("Mouse speed/acceleration, double click delay,\n"
2004-10-12 21:28:27 +00:00
"mouse button bindings etc.");
1999-04-25 01:49:46 +00:00
panel->parent = parent;
1999-04-25 01:49:46 +00:00
1998-09-29 22:36:29 +00:00
panel->callbacks.createWidgets = createPanel;
panel->callbacks.updateDomain = storeData;
AddSection(panel, ICON_FILE);
return panel;
}
2004-10-12 21:28:27 +00:00