Updated some .po files, added man page for wsetfont, and fixed a small bug
[wmaker-crm.git] / WPrefs.app / WindowHandling.c
blob6142f9efbe6b23c1ca00a09e3817ececea6edf11
1 /* WindowHandling.c- options for handling windows
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 typedef struct _Panel {
27 WMFrame *frame;
29 char *sectionName;
31 char *description;
33 CallbackRec callbacks;
35 WMWindow *win;
37 WMFrame *placF;
38 WMPopUpButton *placP;
39 WMLabel *porigL;
40 WMLabel *porigvL;
41 WMFrame *porigF;
42 WMLabel *porigW;
44 WMSlider *vsli;
45 WMSlider *hsli;
47 WMFrame *resF;
48 WMSlider *resS;
49 WMLabel *resL;
51 WMFrame *maxiF;
52 WMButton *miconB;
53 WMButton *mdockB;
55 WMFrame *opaqF;
56 WMButton *opaqB;
58 WMFrame *tranF;
59 WMButton *tranB;
60 } _Panel;
63 #define ICON_FILE "whandling"
65 #define OPAQUE_MOVE_PIXMAP "opaque"
67 #define NON_OPAQUE_MOVE_PIXMAP "nonopaque"
70 #define THUMB_SIZE 16
73 static char *placements[] = {
74 "auto",
75 "random",
76 "manual",
77 "cascade"
81 static void
82 sliderCallback(WMWidget *w, void *data)
84 _Panel *panel = (_Panel*)data;
85 int x, y, rx, ry;
86 char buffer[64];
87 int swidth = WMGetSliderMaxValue(panel->hsli);
88 int sheight = WMGetSliderMaxValue(panel->vsli);
90 x = WMGetSliderValue(panel->hsli);
91 y = WMGetSliderValue(panel->vsli);
93 rx = x*(WMWidgetWidth(panel->porigF)-3)/swidth+2;
94 ry = y*(WMWidgetHeight(panel->porigF)-3)/sheight+2;
95 WMMoveWidget(panel->porigW, rx, ry);
97 sprintf(buffer, "(%i,%i)", x, y);
98 WMSetLabelText(panel->porigvL, buffer);
103 static void
104 resistanceCallback(WMWidget *w, void *data)
106 _Panel *panel = (_Panel*)data;
107 char buffer[64];
108 int i;
110 i = WMGetSliderValue(panel->resS);
112 if (i == 0)
113 WMSetLabelText(panel->resL, "OFF");
114 else {
115 sprintf(buffer, "%i", i);
116 WMSetLabelText(panel->resL, buffer);
121 static int
122 getPlacement(char *str)
124 if (!str)
125 return 0;
127 if (strcasecmp(str, "auto")==0 || strcasecmp(str, "smart")==0)
128 return 0;
129 else if (strcasecmp(str, "random")==0)
130 return 1;
131 else if (strcasecmp(str, "manual")==0)
132 return 2;
133 else if (strcasecmp(str, "cascade")==0)
134 return 3;
135 else
136 wwarning(_("bad option value %s in WindowPlacement. Using default value"),
137 str);
138 return 0;
142 static void
143 showData(_Panel *panel)
145 char *str;
146 proplist_t arr;
147 int x, y;
149 str = GetStringForKey("WindowPlacement");
151 WMSetPopUpButtonSelectedItem(panel->placP, getPlacement(str));
153 arr = GetObjectForKey("WindowPlaceOrigin");
155 x = 0;
156 y = 0;
157 if (arr && (!PLIsArray(arr) || PLGetNumberOfElements(arr)!=2)) {
158 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
159 } else {
160 if (arr) {
161 x = atoi(PLGetString(PLGetArrayElement(arr, 0)));
162 y = atoi(PLGetString(PLGetArrayElement(arr, 1)));
166 WMSetSliderValue(panel->hsli, x);
167 WMSetSliderValue(panel->vsli, y);
169 sliderCallback(NULL, panel);
171 x = GetIntegerForKey("EdgeResistance");
172 WMSetSliderValue(panel->resS, x);
173 resistanceCallback(NULL, panel);
175 WMSetButtonSelected(panel->tranB, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
177 WMSetButtonSelected(panel->opaqB, GetBoolForKey("OpaqueMove"));
179 WMSetButtonSelected(panel->miconB, GetBoolForKey("NoWindowOverIcons"));
181 WMSetButtonSelected(panel->mdockB, GetBoolForKey("NoWindowOverDock"));
185 static void
186 storeData(_Panel *panel)
188 proplist_t arr;
189 char x[16], y[16];
191 SetBoolForKey(WMGetButtonSelected(panel->miconB), "NoWindowOverIcons");
192 SetBoolForKey(WMGetButtonSelected(panel->mdockB), "NoWindowOverDock");
193 SetBoolForKey(WMGetButtonSelected(panel->opaqB), "OpaqueMove");
194 SetBoolForKey(WMGetButtonSelected(panel->tranB), "OpenTransientOnOwnerWorkspace");
195 SetStringForKey(placements[WMGetPopUpButtonSelectedItem(panel->placP)],
196 "WindowPlacement");
197 sprintf(x, "%i", WMGetSliderValue(panel->hsli));
198 sprintf(y, "%i", WMGetSliderValue(panel->vsli));
199 arr = PLMakeArrayFromElements(PLMakeString(x), PLMakeString(y), NULL);
200 SetObjectForKey(arr, "WindowPlaceOrigin");
201 SetIntegerForKey(WMGetSliderValue(panel->resS), "EdgeResistance");
202 PLRelease(arr);
206 static void
207 createPanel(Panel *p)
209 _Panel *panel = (Panel*)p;
210 WMScreen *scr = WMWidgetScreen(panel->win);
211 WMColor *color;
212 WMPixmap *pixmap;
213 int width, height;
214 int swidth, sheight;
215 char *path;
217 panel->frame = WMCreateFrame(panel->win);
218 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
219 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
221 /************** Window Placement ***************/
222 panel->placF = WMCreateFrame(panel->frame);
223 WMResizeWidget(panel->placF, 270, 110);
224 WMMoveWidget(panel->placF, 20, 10);
225 WMSetFrameTitle(panel->placF, _("Window Placement"));
226 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
227 "on screen."), WMWidgetView(panel->placF));
229 panel->placP = WMCreatePopUpButton(panel->placF);
230 WMResizeWidget(panel->placP, 105, 20);
231 WMMoveWidget(panel->placP, 15, 20);
232 WMAddPopUpButtonItem(panel->placP, _("Automatic"));
233 WMAddPopUpButtonItem(panel->placP, _("Random"));
234 WMAddPopUpButtonItem(panel->placP, _("Manual"));
235 WMAddPopUpButtonItem(panel->placP, _("Cascade"));
237 panel->porigL = WMCreateLabel(panel->placF);
238 WMResizeWidget(panel->porigL, 120, 32);
239 WMMoveWidget(panel->porigL, 5, 45);
240 WMSetLabelTextAlignment(panel->porigL, WACenter);
241 WMSetLabelText(panel->porigL, _("Placement Origin"));
243 panel->porigvL = WMCreateLabel(panel->placF);
244 WMResizeWidget(panel->porigvL, 80, 20);
245 WMMoveWidget(panel->porigvL, 30, 75);
246 WMSetLabelTextAlignment(panel->porigvL, WACenter);
248 color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
249 panel->porigF = WMCreateFrame(panel->placF);
250 WMSetWidgetBackgroundColor(panel->porigF, color);
251 WMReleaseColor(color);
252 WMSetFrameRelief(panel->porigF, WRSunken);
254 swidth = WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
255 sheight = HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
257 if (sheight > swidth) {
258 height = 70;
259 width = 70*swidth/sheight;
260 if (width > 115)
261 width = 115;
262 height = 115*sheight/swidth;
263 } else {
264 width = 115;
265 height = 115*sheight/swidth;
266 if (height > 70)
267 height = 70;
268 width = 70*swidth/sheight;
270 WMResizeWidget(panel->porigF, width, height);
271 WMMoveWidget(panel->porigF, 130+(115-width)/2, 20+(70-height)/2);
273 panel->porigW = WMCreateLabel(panel->porigF);
274 WMResizeWidget(panel->porigW, THUMB_SIZE, THUMB_SIZE);
275 WMMoveWidget(panel->porigW, 2, 2);
276 WMSetLabelRelief(panel->porigW, WRRaised);
279 panel->hsli = WMCreateSlider(panel->placF);
280 WMResizeWidget(panel->hsli, width, 12);
281 WMMoveWidget(panel->hsli, 130+(115-width)/2, 20+(70-height)/2+height+2);
282 WMSetSliderAction(panel->hsli, sliderCallback, panel);
283 WMSetSliderMinValue(panel->hsli, 0);
284 WMSetSliderMaxValue(panel->hsli, swidth);
286 panel->vsli = WMCreateSlider(panel->placF);
287 WMResizeWidget(panel->vsli, 12, height);
288 WMMoveWidget(panel->vsli, 130+(115-width)/2+width+2, 20+(70-height)/2);
289 WMSetSliderAction(panel->vsli, sliderCallback, panel);
290 WMSetSliderMinValue(panel->vsli, 0);
291 WMSetSliderMaxValue(panel->vsli, sheight);
293 WMMapSubwidgets(panel->porigF);
295 WMMapSubwidgets(panel->placF);
297 /************** Opaque Move ***************/
298 panel->opaqF = WMCreateFrame(panel->frame);
299 WMResizeWidget(panel->opaqF, 205, 110);
300 WMMoveWidget(panel->opaqF, 300, 10);
301 WMSetFrameTitle(panel->opaqF, _("Opaque Move"));
302 WMSetBalloonTextForView(_("Whether the window contents should be moved\n"
303 "when dragging windows aroung or if only a\n"
304 "frame should be displayed.\n"),
305 WMWidgetView(panel->opaqF));
307 panel->opaqB = WMCreateButton(panel->opaqF, WBTToggle);
308 WMResizeWidget(panel->opaqB, 64, 64);
309 WMMoveWidget(panel->opaqB, 70, 25);
310 WMSetButtonImagePosition(panel->opaqB, WIPImageOnly);
312 path = LocateImage(NON_OPAQUE_MOVE_PIXMAP);
313 if (path) {
314 pixmap = WMCreatePixmapFromFile(scr, path);
315 if (pixmap) {
316 WMSetButtonImage(panel->opaqB, pixmap);
317 WMReleasePixmap(pixmap);
318 } else {
319 wwarning(_("could not load icon %s"), path);
321 free(path);
324 path = LocateImage(OPAQUE_MOVE_PIXMAP);
325 if (path) {
326 pixmap = WMCreatePixmapFromFile(scr, path);
327 if (pixmap) {
328 WMSetButtonAltImage(panel->opaqB, pixmap);
329 WMReleasePixmap(pixmap);
330 } else {
331 wwarning(_("could not load icon %s"), path);
333 free(path);
335 WMMapSubwidgets(panel->opaqF);
337 /**************** Account for Icon/Dock ***************/
338 panel->maxiF = WMCreateFrame(panel->frame);
339 WMResizeWidget(panel->maxiF, 205, 95);
340 WMMoveWidget(panel->maxiF, 300, 125);
341 WMSetFrameTitle(panel->maxiF, _("When maximizing..."));
343 panel->miconB = WMCreateSwitchButton(panel->maxiF);
344 WMResizeWidget(panel->miconB, 185, 30);
345 WMMoveWidget(panel->miconB, 10, 18);
346 WMSetButtonText(panel->miconB, _("...do not cover icons"));
348 panel->mdockB = WMCreateSwitchButton(panel->maxiF);
349 WMResizeWidget(panel->mdockB, 185, 30);
350 WMMoveWidget(panel->mdockB, 10, 53);
352 WMSetButtonText(panel->mdockB, _("...do not cover dock"));
354 WMMapSubwidgets(panel->maxiF);
356 /**************** Edge Resistance ****************/
358 panel->resF = WMCreateFrame(panel->frame);
359 WMResizeWidget(panel->resF, 270, 45);
360 WMMoveWidget(panel->resF, 20, 125);
361 WMSetFrameTitle(panel->resF, _("Edge Resistance"));
363 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
364 "being moved further for the defined threshold\n"
365 "when moved against other windows or the edges\n"
366 "of the screen."), WMWidgetView(panel->resF));
368 panel->resS = WMCreateSlider(panel->resF);
369 WMResizeWidget(panel->resS, 200, 15);
370 WMMoveWidget(panel->resS, 20, 20);
371 WMSetSliderMinValue(panel->resS, 0);
372 WMSetSliderMaxValue(panel->resS, 200);
373 WMSetSliderAction(panel->resS, resistanceCallback, panel);
375 panel->resL = WMCreateLabel(panel->resF);
376 WMResizeWidget(panel->resL, 30, 15);
377 WMMoveWidget(panel->resL, 230, 20);
379 WMMapSubwidgets(panel->resF);
381 /**************** Transients on Parent Workspace ****************/
383 panel->tranF = WMCreateFrame(panel->frame);
384 WMResizeWidget(panel->tranF, 270, 40);
385 WMMoveWidget(panel->tranF, 20, 180);
387 panel->tranB = WMCreateSwitchButton(panel->tranF);
388 WMMoveWidget(panel->tranB, 10, 5);
389 WMResizeWidget(panel->tranB, 250, 30);
390 WMSetButtonText(panel->tranB, _("Open dialogs in same workspace as their owners"));
392 WMMapSubwidgets(panel->tranF);
394 WMRealizeWidget(panel->frame);
395 WMMapSubwidgets(panel->frame);
397 /* show the config data */
398 showData(panel);
402 static void
403 undo(_Panel *panel)
405 showData(panel);
409 Panel*
410 InitWindowHandling(WMScreen *scr, WMWindow *win)
412 _Panel *panel;
414 panel = wmalloc(sizeof(_Panel));
415 memset(panel, 0, sizeof(_Panel));
417 panel->sectionName = _("Window Handling Preferences");
419 panel->description = _("Window handling options. Initial placement style\n"
420 "edge resistance, opaque move etc.");
422 panel->win = win;
424 panel->callbacks.createWidgets = createPanel;
425 panel->callbacks.updateDomain = storeData;
426 panel->callbacks.undoChanges = undo;
428 AddSection(panel, ICON_FILE);
430 return panel;