Files
wmaker/WPrefs.app/WindowHandling.c
T

479 lines
13 KiB
C
Raw Normal View History

1998-09-29 22:36:29 +00:00
/* WindowHandling.c- options for handling windows
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 {
2009-08-20 00:59:40 +02:00
WMBox *box;
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
char *sectionName;
1999-04-25 01:49:46 +00:00
2009-08-20 00:59:40 +02:00
char *description;
1999-04-25 01:49:46 +00:00
2009-08-20 00:59:40 +02:00
CallbackRec callbacks;
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
WMWidget *parent;
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
WMFrame *placF;
WMPopUpButton *placP;
WMLabel *porigL;
WMLabel *porigvL;
WMFrame *porigF;
WMLabel *porigW;
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
WMSlider *vsli;
WMSlider *hsli;
2009-08-20 00:59:40 +02:00
WMFrame *resF;
WMSlider *resS;
WMLabel *resL;
WMButton *resaB;
WMButton *resrB;
2009-08-20 00:59:40 +02:00
WMFrame *maxiF;
WMButton *miconB;
WMButton *mdockB;
2004-10-12 21:28:27 +00:00
2009-10-11 21:36:46 +02:00
WMLabel *resizeL;
WMLabel *resizeTextL;
WMSlider *resizeS;
2009-08-20 00:59:40 +02:00
WMFrame *opaqF;
WMButton *opaqB;
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
WMFrame *tranF;
WMButton *tranB;
1998-09-29 22:36:29 +00:00
} _Panel;
#define ICON_FILE "whandling"
#define OPAQUE_MOVE_PIXMAP "opaque"
#define NON_OPAQUE_MOVE_PIXMAP "nonopaque"
#define THUMB_SIZE 16
static char *placements[] = {
2009-08-20 00:59:40 +02:00
"auto",
"random",
"manual",
"cascade",
"smart"
1998-09-29 22:36:29 +00:00
};
2009-08-20 00:59:40 +02:00
static void sliderCallback(WMWidget * w, void *data)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
_Panel *panel = (_Panel *) data;
int x, y, rx, ry;
char buffer[64];
int swidth = WMGetSliderMaxValue(panel->hsli);
int sheight = WMGetSliderMaxValue(panel->vsli);
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
x = WMGetSliderValue(panel->hsli);
y = WMGetSliderValue(panel->vsli);
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
rx = x * (WMWidgetWidth(panel->porigF) - 3) / swidth + 2;
ry = y * (WMWidgetHeight(panel->porigF) - 3) / sheight + 2;
WMMoveWidget(panel->porigW, rx, ry);
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
sprintf(buffer, "(%i,%i)", x, y);
WMSetLabelText(panel->porigvL, buffer);
1998-09-29 22:36:29 +00:00
}
2009-08-20 00:59:40 +02:00
static void resistanceCallback(WMWidget * w, void *data)
{
2009-08-20 00:59:40 +02:00
_Panel *panel = (_Panel *) data;
char buffer[64];
int i;
i = WMGetSliderValue(panel->resS);
if (i == 0)
WMSetLabelText(panel->resL, "OFF");
else {
sprintf(buffer, "%i", i);
WMSetLabelText(panel->resL, buffer);
}
}
2009-10-11 21:36:46 +02:00
static void resizeCallback(WMWidget * w, void *data)
{
_Panel *panel = (_Panel *) data;
char buffer[64];
int i;
i = WMGetSliderValue(panel->resizeS);
if (i == 0)
WMSetLabelText(panel->resizeL, "OFF");
else {
sprintf(buffer, "%i", i);
WMSetLabelText(panel->resizeL, buffer);
}
}
2009-08-20 00:59:40 +02:00
static int getPlacement(char *str)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
if (!str)
return 0;
if (strcasecmp(str, "auto") == 0)
return 0;
else if (strcasecmp(str, "random") == 0)
return 1;
else if (strcasecmp(str, "manual") == 0)
return 2;
else if (strcasecmp(str, "cascade") == 0)
return 3;
else if (strcasecmp(str, "smart") == 0)
return 4;
else
wwarning(_("bad option value %s in WindowPlacement. Using default value"), str);
return 0;
1998-09-29 22:36:29 +00:00
}
2009-08-20 00:59:40 +02:00
static void showData(_Panel * panel)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
char *str;
WMPropList *arr;
int x, y;
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
str = GetStringForKey("WindowPlacement");
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
WMSetPopUpButtonSelectedItem(panel->placP, getPlacement(str));
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
arr = GetObjectForKey("WindowPlaceOrigin");
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
x = 0;
y = 0;
if (arr && (!WMIsPLArray(arr) || WMGetPropListItemCount(arr) != 2)) {
wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
} else {
if (arr) {
x = atoi(WMGetFromPLString(WMGetFromPLArray(arr, 0)));
y = atoi(WMGetFromPLString(WMGetFromPLArray(arr, 1)));
}
}
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
WMSetSliderValue(panel->hsli, x);
WMSetSliderValue(panel->vsli, y);
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
sliderCallback(NULL, panel);
2009-08-20 00:59:40 +02:00
x = GetIntegerForKey("EdgeResistance");
WMSetSliderValue(panel->resS, x);
resistanceCallback(NULL, panel);
2009-10-11 21:36:46 +02:00
x = GetIntegerForKey("ResizeIncrement");
WMSetSliderValue(panel->resizeS, x);
resizeCallback(NULL, panel);
2009-08-20 00:59:40 +02:00
WMSetButtonSelected(panel->tranB, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
WMSetButtonSelected(panel->opaqB, GetBoolForKey("OpaqueMove"));
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
WMSetButtonSelected(panel->miconB, GetBoolForKey("NoWindowOverIcons"));
1998-11-23 11:32:19 +00:00
2009-08-20 00:59:40 +02:00
WMSetButtonSelected(panel->mdockB, GetBoolForKey("NoWindowOverDock"));
1999-07-14 14:42:29 +00:00
2009-08-20 00:59:40 +02:00
if (GetBoolForKey("Attraction"))
WMPerformButtonClick(panel->resrB);
else
WMPerformButtonClick(panel->resaB);
1998-09-29 22:36:29 +00:00
}
2009-08-20 00:59:40 +02:00
static void storeData(_Panel * panel)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
WMPropList *arr;
char x[16], y[16];
SetBoolForKey(WMGetButtonSelected(panel->miconB), "NoWindowOverIcons");
SetBoolForKey(WMGetButtonSelected(panel->mdockB), "NoWindowOverDock");
SetBoolForKey(WMGetButtonSelected(panel->opaqB), "OpaqueMove");
SetBoolForKey(WMGetButtonSelected(panel->tranB), "OpenTransientOnOwnerWorkspace");
SetStringForKey(placements[WMGetPopUpButtonSelectedItem(panel->placP)], "WindowPlacement");
sprintf(x, "%i", WMGetSliderValue(panel->hsli));
sprintf(y, "%i", WMGetSliderValue(panel->vsli));
arr = WMCreatePLArray(WMCreatePLString(x), WMCreatePLString(y), NULL);
SetObjectForKey(arr, "WindowPlaceOrigin");
SetIntegerForKey(WMGetSliderValue(panel->resS), "EdgeResistance");
2009-10-11 21:36:46 +02:00
SetIntegerForKey(WMGetSliderValue(panel->resizeS), "ResizeIncrement");
2009-08-20 00:59:40 +02:00
SetBoolForKey(WMGetButtonSelected(panel->resrB), "Attraction");
WMReleasePropList(arr);
1998-09-29 22:36:29 +00:00
}
2009-08-20 00:59:40 +02:00
static void createPanel(Panel * p)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
_Panel *panel = (Panel *) p;
WMScreen *scr = WMWidgetScreen(panel->parent);
WMColor *color;
WMPixmap *pixmap;
int width, height;
int swidth, sheight;
char *path;
WMBox *hbox;
panel->box = WMCreateBox(panel->parent);
WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
WMSetBoxHorizontal(panel->box, False);
WMSetBoxBorderWidth(panel->box, 8);
hbox = WMCreateBox(panel->box);
WMSetBoxHorizontal(hbox, True);
WMAddBoxSubview(panel->box, WMWidgetView(hbox), False, True, 110, 0, 10);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
/************** Window Placement ***************/
2009-08-20 00:59:40 +02:00
panel->placF = WMCreateFrame(hbox);
WMMapWidget(panel->placF);
WMAddBoxSubview(hbox, WMWidgetView(panel->placF), True, True, 100, 0, 10);
WMSetFrameTitle(panel->placF, _("Window Placement"));
WMSetBalloonTextForView(_("How to place windows when they are first put\n"
"on screen."), WMWidgetView(panel->placF));
panel->placP = WMCreatePopUpButton(panel->placF);
WMResizeWidget(panel->placP, 105, 20);
WMMoveWidget(panel->placP, 15, 20);
WMAddPopUpButtonItem(panel->placP, _("Automatic"));
WMAddPopUpButtonItem(panel->placP, _("Random"));
WMAddPopUpButtonItem(panel->placP, _("Manual"));
WMAddPopUpButtonItem(panel->placP, _("Cascade"));
WMAddPopUpButtonItem(panel->placP, _("Smart"));
panel->porigL = WMCreateLabel(panel->placF);
WMResizeWidget(panel->porigL, 120, 32);
WMMoveWidget(panel->porigL, 5, 45);
WMSetLabelTextAlignment(panel->porigL, WACenter);
WMSetLabelText(panel->porigL, _("Placement Origin"));
panel->porigvL = WMCreateLabel(panel->placF);
WMResizeWidget(panel->porigvL, 80, 20);
WMMoveWidget(panel->porigvL, 30, 75);
WMSetLabelTextAlignment(panel->porigvL, WACenter);
color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
panel->porigF = WMCreateFrame(panel->placF);
WMSetWidgetBackgroundColor(panel->porigF, color);
WMReleaseColor(color);
WMSetFrameRelief(panel->porigF, WRSunken);
swidth = WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
sheight = HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
if (sheight > swidth) {
height = 70;
width = 70 * swidth / sheight;
if (width > 240)
width = 240;
height = 240 * sheight / swidth;
} else {
width = 240;
height = 240 * sheight / swidth;
if (height > 70)
height = 70;
width = 70 * swidth / sheight;
}
WMResizeWidget(panel->porigF, width, height);
WMMoveWidget(panel->porigF, 130 + (240 - width) / 2, 20 + (70 - height) / 2);
panel->porigW = WMCreateLabel(panel->porigF);
WMResizeWidget(panel->porigW, THUMB_SIZE, THUMB_SIZE);
WMMoveWidget(panel->porigW, 2, 2);
WMSetLabelRelief(panel->porigW, WRRaised);
panel->hsli = WMCreateSlider(panel->placF);
WMResizeWidget(panel->hsli, width, 12);
WMMoveWidget(panel->hsli, 130 + (240 - width) / 2, 20 + (70 - height) / 2 + height + 2);
WMSetSliderAction(panel->hsli, sliderCallback, panel);
WMSetSliderMinValue(panel->hsli, 0);
WMSetSliderMaxValue(panel->hsli, swidth);
panel->vsli = WMCreateSlider(panel->placF);
WMResizeWidget(panel->vsli, 12, height);
WMMoveWidget(panel->vsli, 130 + (240 - width) / 2 + width + 2, 20 + (70 - height) / 2);
WMSetSliderAction(panel->vsli, sliderCallback, panel);
WMSetSliderMinValue(panel->vsli, 0);
WMSetSliderMaxValue(panel->vsli, sheight);
WMMapSubwidgets(panel->porigF);
WMMapSubwidgets(panel->placF);
1998-09-29 22:36:29 +00:00
/************** Opaque Move ***************/
2009-08-20 00:59:40 +02:00
panel->opaqF = WMCreateFrame(hbox);
WMMapWidget(panel->opaqF);
WMAddBoxSubview(hbox, WMWidgetView(panel->opaqF), False, True, 110, 0, 0);
WMSetFrameTitle(panel->opaqF, _("Opaque Move"));
WMSetBalloonTextForView(_("Whether the window contents should be moved\n"
"when dragging windows aroung or if only a\n"
"frame should be displayed.\n"), WMWidgetView(panel->opaqF));
panel->opaqB = WMCreateButton(panel->opaqF, WBTToggle);
WMResizeWidget(panel->opaqB, 64, 64);
WMMoveWidget(panel->opaqB, 24, 25);
WMSetButtonImagePosition(panel->opaqB, WIPImageOnly);
path = LocateImage(NON_OPAQUE_MOVE_PIXMAP);
if (path) {
pixmap = WMCreatePixmapFromFile(scr, path);
if (pixmap) {
WMSetButtonImage(panel->opaqB, pixmap);
WMReleasePixmap(pixmap);
} else {
wwarning(_("could not load icon %s"), path);
}
wfree(path);
}
path = LocateImage(OPAQUE_MOVE_PIXMAP);
if (path) {
pixmap = WMCreatePixmapFromFile(scr, path);
if (pixmap) {
WMSetButtonAltImage(panel->opaqB, pixmap);
WMReleasePixmap(pixmap);
} else {
wwarning(_("could not load icon %s"), path);
}
wfree(path);
}
WMMapSubwidgets(panel->opaqF);
2004-10-12 21:28:27 +00:00
1998-09-29 22:36:29 +00:00
/**************** Account for Icon/Dock ***************/
2009-08-20 00:59:40 +02:00
panel->maxiF = WMCreateFrame(panel->box);
WMResizeWidget(panel->maxiF, 205, 95);
WMMoveWidget(panel->maxiF, 305, 125);
WMSetFrameTitle(panel->maxiF, _("When maximizing..."));
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
panel->miconB = WMCreateSwitchButton(panel->maxiF);
WMResizeWidget(panel->miconB, 190, 30);
2009-10-11 21:36:46 +02:00
WMMoveWidget(panel->miconB, 10, 12);
2009-08-20 00:59:40 +02:00
WMSetButtonText(panel->miconB, _("...do not cover icons"));
1998-10-21 14:43:47 +00:00
2009-08-20 00:59:40 +02:00
panel->mdockB = WMCreateSwitchButton(panel->maxiF);
WMResizeWidget(panel->mdockB, 190, 30);
2009-10-11 21:36:46 +02:00
WMMoveWidget(panel->mdockB, 10, 35);
1998-11-23 11:32:19 +00:00
2009-08-20 00:59:40 +02:00
WMSetButtonText(panel->mdockB, _("...do not cover dock"));
1998-11-23 11:32:19 +00:00
2009-10-11 21:36:46 +02:00
panel->resizeS = WMCreateSlider(panel->maxiF);
WMResizeWidget(panel->resizeS, 50, 15);
WMMoveWidget(panel->resizeS, 10, 70);
WMSetSliderMinValue(panel->resizeS, 0);
WMSetSliderMaxValue(panel->resizeS, 100);
WMSetSliderAction(panel->resizeS, resizeCallback, panel);
panel->resizeL = WMCreateLabel(panel->maxiF);
WMResizeWidget(panel->resizeL, 30, 15);
WMMoveWidget(panel->resizeL, 60, 70);
panel->resizeTextL = WMCreateLabel(panel->maxiF);
WMSetLabelText(panel->resizeTextL, "Mod+Wheel\nresize increment");
WMResizeWidget(panel->resizeTextL, 110, 30);
WMMoveWidget(panel->resizeTextL, 90, 62);
2009-08-20 00:59:40 +02:00
WMMapSubwidgets(panel->maxiF);
/**************** Edge Resistance ****************/
2009-08-20 00:59:40 +02:00
panel->resF = WMCreateFrame(panel->box);
WMResizeWidget(panel->resF, 285, 45);
WMMoveWidget(panel->resF, 8, 125);
WMSetFrameTitle(panel->resF, _("Edge Resistance"));
2009-08-20 00:59:40 +02:00
WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
"being moved further for the defined threshold\n"
"when moved against other windows or the edges\n"
"of the screen."), WMWidgetView(panel->resF));
1999-04-25 01:49:46 +00:00
2009-08-20 00:59:40 +02:00
panel->resS = WMCreateSlider(panel->resF);
WMResizeWidget(panel->resS, 80, 15);
WMMoveWidget(panel->resS, 10, 20);
WMSetSliderMinValue(panel->resS, 0);
WMSetSliderMaxValue(panel->resS, 80);
WMSetSliderAction(panel->resS, resistanceCallback, panel);
2009-08-20 00:59:40 +02:00
panel->resL = WMCreateLabel(panel->resF);
WMResizeWidget(panel->resL, 30, 15);
WMMoveWidget(panel->resL, 95, 20);
1999-07-14 14:42:29 +00:00
2009-08-20 00:59:40 +02:00
panel->resaB = WMCreateRadioButton(panel->resF);
WMMoveWidget(panel->resaB, 130, 15);
WMResizeWidget(panel->resaB, 70, 25);
WMSetButtonText(panel->resaB, _("Resist"));
1999-07-14 14:42:29 +00:00
2009-08-20 00:59:40 +02:00
panel->resrB = WMCreateRadioButton(panel->resF);
WMMoveWidget(panel->resrB, 200, 15);
WMResizeWidget(panel->resrB, 70, 25);
WMSetButtonText(panel->resrB, _("Attract"));
WMGroupButtons(panel->resrB, panel->resaB);
1999-07-14 14:42:29 +00:00
2009-08-20 00:59:40 +02:00
WMMapSubwidgets(panel->resF);
/**************** Transients on Parent Workspace ****************/
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
panel->tranF = WMCreateFrame(panel->box);
WMResizeWidget(panel->tranF, 285, 40);
WMMoveWidget(panel->tranF, 8, 180);
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
panel->tranB = WMCreateSwitchButton(panel->tranF);
WMMoveWidget(panel->tranB, 10, 5);
WMResizeWidget(panel->tranB, 250, 30);
WMSetButtonText(panel->tranB, _("Open dialogs in the same workspace\nas their owners"));
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
WMMapSubwidgets(panel->tranF);
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
WMRealizeWidget(panel->box);
WMMapSubwidgets(panel->box);
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
/* show the config data */
showData(panel);
1998-09-29 22:36:29 +00:00
}
2009-08-20 00:59:40 +02:00
static void undo(_Panel * panel)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
showData(panel);
1998-09-29 22:36:29 +00:00
}
2009-08-20 00:59:40 +02:00
Panel *InitWindowHandling(WMScreen * scr, WMWidget * parent)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
_Panel *panel;
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
panel = wmalloc(sizeof(_Panel));
memset(panel, 0, sizeof(_Panel));
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
panel->sectionName = _("Window Handling Preferences");
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
panel->description = _("Window handling options. Initial placement style\n"
"edge resistance, opaque move etc.");
1999-04-25 01:49:46 +00:00
2009-08-20 00:59:40 +02:00
panel->parent = parent;
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
panel->callbacks.createWidgets = createPanel;
panel->callbacks.updateDomain = storeData;
panel->callbacks.undoChanges = undo;
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
AddSection(panel, ICON_FILE);
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
return panel;
1998-09-29 22:36:29 +00:00
}