Files
wmaker/WPrefs.app/Focus.c
T

378 lines
11 KiB
C
Raw Normal View History

1998-09-29 22:36:29 +00:00
/* Focus.c- input and colormap focus stuff
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"
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 *kfocF;
WMButton *kfocB[2];
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
WMFrame *cfocF;
WMButton *autB;
WMButton *manB;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
WMFrame *raisF;
WMButton *raisB[5];
WMTextField *raisT;
WMLabel *raisL;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
WMFrame *optF;
WMButton *ignB;
WMButton *newB;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
char raiseDelaySelected;
} _Panel;
#define ICON_FILE "windowfocus"
#define DELAY_ICON "timer%i"
#define DELAY_ICON_S "timer%is"
static void
showData(_Panel *panel)
{
char *str;
int i;
char buffer[32];
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
str = GetStringForKey("FocusMode");
if (!str)
2004-10-12 21:28:27 +00:00
str = "manual";
1998-09-29 22:36:29 +00:00
if (strcasecmp(str, "manual")==0 || strcasecmp(str, "clicktofocus")==0)
2004-10-12 21:28:27 +00:00
WMSetButtonSelected(panel->kfocB[0], 1);
else if (strcasecmp(str, "auto")==0 || strcasecmp(str, "semiauto")==0
|| strcasecmp(str, "sloppy")==0)
WMSetButtonSelected(panel->kfocB[1], 1);
1998-09-29 22:36:29 +00:00
else {
2004-10-12 21:28:27 +00:00
wwarning(_("bad option value %s for option FocusMode. Using default Manual"),
str);
WMSetButtonSelected(panel->kfocB[0], 1);
1998-09-29 22:36:29 +00:00
}
/**/
str = GetStringForKey("ColormapMode");
if (!str)
2004-10-12 21:28:27 +00:00
str = "auto";
1998-09-29 22:36:29 +00:00
if (strcasecmp(str, "manual")==0 || strcasecmp(str, "clicktofocus")==0) {
2004-10-12 21:28:27 +00:00
WMPerformButtonClick(panel->manB);
1998-09-29 22:36:29 +00:00
} else if (strcasecmp(str, "auto")==0 || strcasecmp(str, "focusfollowsmouse")==0) {
2004-10-12 21:28:27 +00:00
WMPerformButtonClick(panel->autB);
1998-09-29 22:36:29 +00:00
} else {
2004-10-12 21:28:27 +00:00
wwarning(_("bad option value %s for option ColormapMode. Using default Auto"),
str);
WMPerformButtonClick(panel->manB);
1998-09-29 22:36:29 +00:00
}
/**/
i = GetIntegerForKey("RaiseDelay");
sprintf(buffer, "%i", i);
WMSetTextFieldText(panel->raisT, buffer);
switch (i) {
2004-10-12 21:28:27 +00:00
case 0:
WMPerformButtonClick(panel->raisB[0]);
break;
case 10:
WMPerformButtonClick(panel->raisB[1]);
break;
case 100:
WMPerformButtonClick(panel->raisB[2]);
break;
case 350:
WMPerformButtonClick(panel->raisB[3]);
break;
case 800:
WMPerformButtonClick(panel->raisB[4]);
break;
1998-09-29 22:36:29 +00:00
}
/**/
WMSetButtonSelected(panel->ignB, GetBoolForKey("IgnoreFocusClick"));
WMSetButtonSelected(panel->newB, GetBoolForKey("AutoFocus"));
}
static void
storeData(_Panel *panel)
{
char *str;
int i;
if (WMGetButtonSelected(panel->kfocB[1]))
2004-10-12 21:28:27 +00:00
str = "sloppy";
else
2004-10-12 21:28:27 +00:00
str = "manual";
1998-09-29 22:36:29 +00:00
SetStringForKey(str, "FocusMode");
if (WMGetButtonSelected(panel->manB)) {
2004-10-12 21:28:27 +00:00
SetStringForKey("manual", "ColormapMode");
1998-09-29 22:36:29 +00:00
} else {
2004-10-12 21:28:27 +00:00
SetStringForKey("auto", "ColormapMode");
1998-09-29 22:36:29 +00:00
}
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
str = WMGetTextFieldText(panel->raisT);
if (sscanf(str, "%i", &i)!=1)
2004-10-12 21:28:27 +00:00
i = 0;
1998-09-29 22:36:29 +00:00
SetIntegerForKey(i, "RaiseDelay");
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
SetBoolForKey(WMGetButtonSelected(panel->ignB), "IgnoreFocusClick");
2004-10-12 21:28:27 +00:00
SetBoolForKey(WMGetButtonSelected(panel->newB), "AutoFocus");
1998-09-29 22:36:29 +00:00
}
static void
pushDelayButton(WMWidget *w, void *data)
{
_Panel *panel = (_Panel*)data;
panel->raiseDelaySelected = 1;
if (w == panel->raisB[0]) {
2004-10-12 21:28:27 +00:00
WMSetTextFieldText(panel->raisT, "OFF");
1998-09-29 22:36:29 +00:00
} else if (w == panel->raisB[1]) {
2004-10-12 21:28:27 +00:00
WMSetTextFieldText(panel->raisT, "10");
1998-09-29 22:36:29 +00:00
} else if (w == panel->raisB[2]) {
2004-10-12 21:28:27 +00:00
WMSetTextFieldText(panel->raisT, "100");
1998-09-29 22:36:29 +00:00
} else if (w == panel->raisB[3]) {
2004-10-12 21:28:27 +00:00
WMSetTextFieldText(panel->raisT, "350");
1998-09-29 22:36:29 +00:00
} else if (w == panel->raisB[4]) {
2004-10-12 21:28:27 +00:00
WMSetTextFieldText(panel->raisT, "800");
1998-09-29 22:36:29 +00:00
}
}
static void
raiseTextChanged(void *observerData, WMNotification *notification)
{
_Panel *panel = (_Panel*)observerData;
int i;
if (panel->raiseDelaySelected) {
2004-10-12 21:28:27 +00:00
for (i=0; i<5; i++) {
WMSetButtonSelected(panel->raisB[i], False);
}
panel->raiseDelaySelected = 0;
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
int i;
char *buf1, *buf2;
WMPixmap *icon;
WMColor *color;
WMFont *font;
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
/***************** Input Focus Mode *****************/
panel->kfocF = WMCreateFrame(panel->box);
1998-09-29 22:36:29 +00:00
WMResizeWidget(panel->kfocF, 240, 130);
WMMoveWidget(panel->kfocF, 15, 15);
WMSetFrameTitle(panel->kfocF, _("Input Focus Mode"));
{
2004-10-12 21:28:27 +00:00
WMBox *box = WMCreateBox(panel->kfocF);
WMSetViewExpandsToParent(WMWidgetView(box), 10, 15, 10, 10);
WMSetBoxHorizontal(box, False);
panel->kfocB[0] = WMCreateRadioButton(box);
WMSetButtonText(panel->kfocB[0], _("Manual: Click on the window to set "\
"keyboard input focus."));
2004-10-12 21:28:27 +00:00
WMAddBoxSubview(box, WMWidgetView(panel->kfocB[0]), True, True,
20, 0, 0);
panel->kfocB[1] = WMCreateRadioButton(box);
WMGroupButtons(panel->kfocB[0], panel->kfocB[1]);
WMSetButtonText(panel->kfocB[1], _("Auto: Set keyboard input focus to "\
"the window under the mouse pointer."));
2004-10-12 21:28:27 +00:00
WMAddBoxSubview(box, WMWidgetView(panel->kfocB[1]), True, True,
20, 0, 0);
WMMapSubwidgets(box);
WMMapWidget(box);
}
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
/***************** Colormap Installation Mode ****************/
2004-10-12 21:28:27 +00:00
panel->cfocF = WMCreateFrame(panel->box);
1998-09-29 22:36:29 +00:00
WMResizeWidget(panel->cfocF, 240, 70);
WMMoveWidget(panel->cfocF, 15, 150);
WMSetFrameTitle(panel->cfocF, _("Install colormap in the window..."));
panel->manB = WMCreateRadioButton(panel->cfocF);
WMResizeWidget(panel->manB, 225, 20);
WMMoveWidget(panel->manB, 10, 18);
1998-09-29 22:36:29 +00:00
WMSetButtonText(panel->manB, _("...that has the input focus."));
panel->autB = WMCreateRadioButton(panel->cfocF);
WMResizeWidget(panel->autB, 225, 20);
WMMoveWidget(panel->autB, 10, 43);
WMSetButtonText(panel->autB, _("...that's under the mouse pointer."));
1998-09-29 22:36:29 +00:00
WMGroupButtons(panel->manB, panel->autB);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
WMMapSubwidgets(panel->cfocF);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
/***************** Automatic window raise delay *****************/
panel->raisF = WMCreateFrame(panel->box);
1998-09-29 22:36:29 +00:00
WMResizeWidget(panel->raisF, 245, 70);
WMMoveWidget(panel->raisF, 265, 15);
WMSetFrameTitle(panel->raisF, _("Automatic Window Raise Delay"));
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
buf1 = wmalloc(strlen(DELAY_ICON)+1);
buf2 = wmalloc(strlen(DELAY_ICON_S)+1);
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
char *path;
panel->raisB[i] = WMCreateCustomButton(panel->raisF,
WBBStateChangeMask);
WMResizeWidget(panel->raisB[i], 25, 25);
WMMoveWidget(panel->raisB[i], 10+(30*i), 25);
WMSetButtonBordered(panel->raisB[i], False);
WMSetButtonImagePosition(panel->raisB[i], WIPImageOnly);
WMSetButtonAction(panel->raisB[i], pushDelayButton, panel);
if (i>0)
WMGroupButtons(panel->raisB[0], panel->raisB[i]);
sprintf(buf1, DELAY_ICON, i);
sprintf(buf2, DELAY_ICON_S, i);
path = LocateImage(buf1);
if (path) {
icon = WMCreatePixmapFromFile(scr, path);
if (icon) {
WMSetButtonImage(panel->raisB[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->raisB[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);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
panel->raisT = WMCreateTextField(panel->raisF);
WMResizeWidget(panel->raisT, 36, 20);
WMMoveWidget(panel->raisT, 165, 30);
2004-10-12 21:28:27 +00:00
WMAddNotificationObserver(raiseTextChanged, panel,
WMTextDidChangeNotification, panel->raisT);
1998-09-29 22:36:29 +00:00
color = WMDarkGrayColor(scr);
font = WMSystemFontOfSize(scr, 10);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
panel->raisL = WMCreateLabel(panel->raisF);
WMResizeWidget(panel->raisL, 36, 16);
WMMoveWidget(panel->raisL, 205, 35);
WMSetLabelText(panel->raisL, _("msec"));
WMSetLabelTextColor(panel->raisL, color);
WMSetLabelFont(panel->raisL, font);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
WMReleaseColor(color);
WMReleaseFont(font);
WMMapSubwidgets(panel->raisF);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
/***************** Options ****************/
panel->optF = WMCreateFrame(panel->box);
1998-09-29 22:36:29 +00:00
WMResizeWidget(panel->optF, 245, 125);
WMMoveWidget(panel->optF, 265, 95);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
panel->ignB = WMCreateSwitchButton(panel->optF);
WMResizeWidget(panel->ignB, 225, 50);
WMMoveWidget(panel->ignB, 10, 10);
WMSetButtonText(panel->ignB, _("Do not let applications receive "
"the click used to focus windows."));
1998-09-29 22:36:29 +00:00
panel->newB = WMCreateSwitchButton(panel->optF);
WMResizeWidget(panel->newB, 225, 35);
WMMoveWidget(panel->newB, 10, 70);
WMSetButtonText(panel->newB, _("Automatically focus new windows."));
1998-09-29 22:36:29 +00:00
WMMapSubwidgets(panel->optF);
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);
}
Panel*
InitFocus(WMScreen *scr, WMWindow *win)
{
_Panel *panel;
panel = wmalloc(sizeof(_Panel));
memset(panel, 0, sizeof(_Panel));
panel->sectionName = _("Window Focus Preferences");
1999-04-25 01:49:46 +00:00
panel->description = _("Keyboard focus switching policy, colormap switching\n"
2004-10-12 21:28:27 +00:00
"policy for 8bpp displays and other related options.");
1999-04-25 01:49:46 +00:00
panel->parent = win;
1998-09-29 22:36:29 +00:00
panel->callbacks.createWidgets = createPanel;
panel->callbacks.updateDomain = storeData;
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
AddSection(panel, ICON_FILE);
return panel;
}
2004-10-12 21:28:27 +00:00