1 /* WindowHandling.c- options for handling windows
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1998-2003 Alfredo K. Kojima
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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 typedef struct _Panel
{
31 CallbackRec callbacks
;
62 WMButton
*opaqresizeB
;
68 #define ICON_FILE "whandling"
70 #define OPAQUE_MOVE_PIXMAP "opaque"
72 #define NON_OPAQUE_MOVE_PIXMAP "nonopaque"
74 #define OPAQUE_RESIZE_PIXMAP "opaqueresize"
76 #define NON_OPAQUE_RESIZE_PIXMAP "noopaqueresize"
80 static char *placements
[] = {
89 static void sliderCallback(WMWidget
* w
, void *data
)
91 _Panel
*panel
= (_Panel
*) data
;
94 int swidth
= WMGetSliderMaxValue(panel
->hsli
);
95 int sheight
= WMGetSliderMaxValue(panel
->vsli
);
97 x
= WMGetSliderValue(panel
->hsli
);
98 y
= WMGetSliderValue(panel
->vsli
);
100 rx
= x
* (WMWidgetWidth(panel
->porigF
) - 3) / swidth
+ 2;
101 ry
= y
* (WMWidgetHeight(panel
->porigF
) - 3) / sheight
+ 2;
102 WMMoveWidget(panel
->porigW
, rx
, ry
);
104 sprintf(buffer
, "(%i,%i)", x
, y
);
105 WMSetLabelText(panel
->porigvL
, buffer
);
108 static void resistanceCallback(WMWidget
* w
, void *data
)
110 _Panel
*panel
= (_Panel
*) data
;
114 i
= WMGetSliderValue(panel
->resS
);
117 WMSetLabelText(panel
->resL
, "OFF");
119 sprintf(buffer
, "%i", i
);
120 WMSetLabelText(panel
->resL
, buffer
);
124 static void resizeCallback(WMWidget
* w
, void *data
)
126 _Panel
*panel
= (_Panel
*) data
;
130 i
= WMGetSliderValue(panel
->resizeS
);
133 WMSetLabelText(panel
->resizeL
, "OFF");
135 sprintf(buffer
, "%i", i
);
136 WMSetLabelText(panel
->resizeL
, buffer
);
140 static int getPlacement(char *str
)
145 if (strcasecmp(str
, "auto") == 0)
147 else if (strcasecmp(str
, "random") == 0)
149 else if (strcasecmp(str
, "manual") == 0)
151 else if (strcasecmp(str
, "cascade") == 0)
153 else if (strcasecmp(str
, "smart") == 0)
155 else if (strcasecmp(str
, "center") == 0)
158 wwarning(_("bad option value %s in WindowPlacement. Using default value"), str
);
162 static void showData(_Panel
* panel
)
168 str
= GetStringForKey("WindowPlacement");
170 WMSetPopUpButtonSelectedItem(panel
->placP
, getPlacement(str
));
172 arr
= GetObjectForKey("WindowPlaceOrigin");
176 if (arr
&& (!WMIsPLArray(arr
) || WMGetPropListItemCount(arr
) != 2)) {
177 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
180 x
= atoi(WMGetFromPLString(WMGetFromPLArray(arr
, 0)));
181 y
= atoi(WMGetFromPLString(WMGetFromPLArray(arr
, 1)));
185 WMSetSliderValue(panel
->hsli
, x
);
186 WMSetSliderValue(panel
->vsli
, y
);
188 sliderCallback(NULL
, panel
);
190 x
= GetIntegerForKey("EdgeResistance");
191 WMSetSliderValue(panel
->resS
, x
);
192 resistanceCallback(NULL
, panel
);
194 x
= GetIntegerForKey("ResizeIncrement");
195 WMSetSliderValue(panel
->resizeS
, x
);
196 resizeCallback(NULL
, panel
);
198 WMSetButtonSelected(panel
->tranB
, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
200 WMSetButtonSelected(panel
->opaqB
, GetBoolForKey("OpaqueMove"));
202 WMSetButtonSelected(panel
->opaqresizeB
, GetBoolForKey("OpaqueResize"));
204 WMSetButtonSelected(panel
->miconB
, GetBoolForKey("NoWindowOverIcons"));
206 WMSetButtonSelected(panel
->mdockB
, GetBoolForKey("NoWindowOverDock"));
208 if (GetBoolForKey("Attraction"))
209 WMPerformButtonClick(panel
->resrB
);
211 WMPerformButtonClick(panel
->resaB
);
214 static void storeData(_Panel
* panel
)
219 SetBoolForKey(WMGetButtonSelected(panel
->miconB
), "NoWindowOverIcons");
220 SetBoolForKey(WMGetButtonSelected(panel
->mdockB
), "NoWindowOverDock");
221 SetBoolForKey(WMGetButtonSelected(panel
->opaqB
), "OpaqueMove");
222 SetBoolForKey(WMGetButtonSelected(panel
->opaqresizeB
), "OpaqueResize");
223 SetBoolForKey(WMGetButtonSelected(panel
->tranB
), "OpenTransientOnOwnerWorkspace");
224 SetStringForKey(placements
[WMGetPopUpButtonSelectedItem(panel
->placP
)], "WindowPlacement");
225 sprintf(x
, "%i", WMGetSliderValue(panel
->hsli
));
226 sprintf(y
, "%i", WMGetSliderValue(panel
->vsli
));
227 arr
= WMCreatePLArray(WMCreatePLString(x
), WMCreatePLString(y
), NULL
);
228 SetObjectForKey(arr
, "WindowPlaceOrigin");
229 SetIntegerForKey(WMGetSliderValue(panel
->resS
), "EdgeResistance");
230 SetIntegerForKey(WMGetSliderValue(panel
->resizeS
), "ResizeIncrement");
231 SetBoolForKey(WMGetButtonSelected(panel
->resrB
), "Attraction");
232 WMReleasePropList(arr
);
235 static void createPanel(Panel
* p
)
237 _Panel
*panel
= (Panel
*) p
;
238 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
246 panel
->box
= WMCreateBox(panel
->parent
);
247 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
248 WMSetBoxHorizontal(panel
->box
, False
);
249 WMSetBoxBorderWidth(panel
->box
, 8);
251 hbox
= WMCreateBox(panel
->box
);
252 WMSetBoxHorizontal(hbox
, True
);
253 WMAddBoxSubview(panel
->box
, WMWidgetView(hbox
), False
, True
, 110, 0, 10);
255 /************** Window Placement ***************/
256 panel
->placF
= WMCreateFrame(hbox
);
257 WMMapWidget(panel
->placF
);
258 WMAddBoxSubview(hbox
, WMWidgetView(panel
->placF
), True
, True
, 100, 0, 10);
260 WMSetFrameTitle(panel
->placF
, _("Window Placement"));
261 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
262 "on screen."), WMWidgetView(panel
->placF
));
264 panel
->placP
= WMCreatePopUpButton(panel
->placF
);
265 WMResizeWidget(panel
->placP
, 105, 20);
266 WMMoveWidget(panel
->placP
, 15, 20);
267 WMAddPopUpButtonItem(panel
->placP
, _("Automatic"));
268 WMAddPopUpButtonItem(panel
->placP
, _("Random"));
269 WMAddPopUpButtonItem(panel
->placP
, _("Manual"));
270 WMAddPopUpButtonItem(panel
->placP
, _("Cascade"));
271 WMAddPopUpButtonItem(panel
->placP
, _("Smart"));
272 WMAddPopUpButtonItem(panel
->placP
, _("Center"));
274 panel
->porigL
= WMCreateLabel(panel
->placF
);
275 WMResizeWidget(panel
->porigL
, 120, 32);
276 WMMoveWidget(panel
->porigL
, 5, 45);
277 WMSetLabelTextAlignment(panel
->porigL
, WACenter
);
278 WMSetLabelText(panel
->porigL
, _("Placement Origin"));
280 panel
->porigvL
= WMCreateLabel(panel
->placF
);
281 WMResizeWidget(panel
->porigvL
, 80, 20);
282 WMMoveWidget(panel
->porigvL
, 30, 75);
283 WMSetLabelTextAlignment(panel
->porigvL
, WACenter
);
285 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
286 panel
->porigF
= WMCreateFrame(panel
->placF
);
287 WMSetWidgetBackgroundColor(panel
->porigF
, color
);
288 WMReleaseColor(color
);
289 WMSetFrameRelief(panel
->porigF
, WRSunken
);
291 swidth
= WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
292 sheight
= HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
294 if (sheight
> swidth
) {
296 width
= 70 * swidth
/ sheight
;
299 height
= 240 * sheight
/ swidth
;
302 height
= 240 * sheight
/ swidth
;
305 width
= 70 * swidth
/ sheight
;
307 WMResizeWidget(panel
->porigF
, width
, height
);
308 WMMoveWidget(panel
->porigF
, 130 + (240 - width
) / 2, 20 + (70 - height
) / 2);
310 panel
->porigW
= WMCreateLabel(panel
->porigF
);
311 WMResizeWidget(panel
->porigW
, THUMB_SIZE
, THUMB_SIZE
);
312 WMMoveWidget(panel
->porigW
, 2, 2);
313 WMSetLabelRelief(panel
->porigW
, WRRaised
);
315 panel
->hsli
= WMCreateSlider(panel
->placF
);
316 WMResizeWidget(panel
->hsli
, width
, 12);
317 WMMoveWidget(panel
->hsli
, 130 + (240 - width
) / 2, 20 + (70 - height
) / 2 + height
+ 2);
318 WMSetSliderAction(panel
->hsli
, sliderCallback
, panel
);
319 WMSetSliderMinValue(panel
->hsli
, 0);
320 WMSetSliderMaxValue(panel
->hsli
, swidth
);
322 panel
->vsli
= WMCreateSlider(panel
->placF
);
323 WMResizeWidget(panel
->vsli
, 12, height
);
324 WMMoveWidget(panel
->vsli
, 130 + (240 - width
) / 2 + width
+ 2, 20 + (70 - height
) / 2);
325 WMSetSliderAction(panel
->vsli
, sliderCallback
, panel
);
326 WMSetSliderMinValue(panel
->vsli
, 0);
327 WMSetSliderMaxValue(panel
->vsli
, sheight
);
329 WMMapSubwidgets(panel
->porigF
);
331 WMMapSubwidgets(panel
->placF
);
333 /************** Opaque Move, Resize ***************/
334 panel
->opaqF
= WMCreateFrame(hbox
);
335 WMMapWidget(panel
->opaqF
);
336 WMAddBoxSubview(hbox
, WMWidgetView(panel
->opaqF
), False
, True
, 122, 0, 0);
338 WMSetFrameTitle(panel
->opaqF
, _("Opaque Move/Resize"));
339 WMSetBalloonTextForView(_("Whether the window contents or only a frame should\n"
340 "be displayed during a move or resize.\n"),
341 WMWidgetView(panel
->opaqF
));
343 panel
->opaqB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
344 WMResizeWidget(panel
->opaqB
, 48,48);
345 WMMoveWidget(panel
->opaqB
, 7, 35);
346 WMSetButtonImagePosition(panel
->opaqB
, WIPImageOnly
);
348 path
= LocateImage(NON_OPAQUE_MOVE_PIXMAP
);
350 pixmap
= WMCreatePixmapFromFile(scr
, path
);
352 WMSetButtonImage(panel
->opaqB
, pixmap
);
353 WMReleasePixmap(pixmap
);
355 wwarning(_("could not load icon %s"), path
);
360 path
= LocateImage(OPAQUE_MOVE_PIXMAP
);
362 pixmap
= WMCreatePixmapFromFile(scr
, path
);
364 WMSetButtonAltImage(panel
->opaqB
, pixmap
);
365 WMReleasePixmap(pixmap
);
367 wwarning(_("could not load icon %s"), path
);
374 panel
->opaqresizeB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
375 WMResizeWidget(panel
->opaqresizeB
, 48,48);
376 WMMoveWidget(panel
->opaqresizeB
, 65, 35);
377 WMSetButtonImagePosition(panel
->opaqresizeB
, WIPImageOnly
);
379 path
= LocateImage(NON_OPAQUE_RESIZE_PIXMAP
);
381 pixmap
= WMCreatePixmapFromFile(scr
, path
);
383 WMSetButtonImage(panel
->opaqresizeB
, pixmap
);
384 WMReleasePixmap(pixmap
);
386 wwarning(_("could not load icon %s"), path
);
391 path
= LocateImage(OPAQUE_RESIZE_PIXMAP
);
393 pixmap
= WMCreatePixmapFromFile(scr
, path
);
395 WMSetButtonAltImage(panel
->opaqresizeB
, pixmap
);
396 WMReleasePixmap(pixmap
);
398 wwarning(_("could not load icon %s"), path
);
403 WMMapSubwidgets(panel
->opaqF
);
406 /**************** Account for Icon/Dock ***************/
407 panel
->maxiF
= WMCreateFrame(panel
->box
);
408 WMResizeWidget(panel
->maxiF
, 205, 95);
409 WMMoveWidget(panel
->maxiF
, 305, 125);
410 WMSetFrameTitle(panel
->maxiF
, _("When maximizing..."));
412 panel
->miconB
= WMCreateSwitchButton(panel
->maxiF
);
413 WMResizeWidget(panel
->miconB
, 190, 30);
414 WMMoveWidget(panel
->miconB
, 10, 12);
415 WMSetButtonText(panel
->miconB
, _("...do not cover icons"));
417 panel
->mdockB
= WMCreateSwitchButton(panel
->maxiF
);
418 WMResizeWidget(panel
->mdockB
, 190, 30);
419 WMMoveWidget(panel
->mdockB
, 10, 35);
421 WMSetButtonText(panel
->mdockB
, _("...do not cover dock"));
423 panel
->resizeS
= WMCreateSlider(panel
->maxiF
);
424 WMResizeWidget(panel
->resizeS
, 50, 15);
425 WMMoveWidget(panel
->resizeS
, 10, 70);
426 WMSetSliderMinValue(panel
->resizeS
, 0);
427 WMSetSliderMaxValue(panel
->resizeS
, 100);
428 WMSetSliderAction(panel
->resizeS
, resizeCallback
, panel
);
430 panel
->resizeL
= WMCreateLabel(panel
->maxiF
);
431 WMResizeWidget(panel
->resizeL
, 30, 15);
432 WMMoveWidget(panel
->resizeL
, 60, 70);
434 panel
->resizeTextL
= WMCreateLabel(panel
->maxiF
);
435 WMSetLabelText(panel
->resizeTextL
, "Mod+Wheel\nresize increment");
436 WMResizeWidget(panel
->resizeTextL
, 110, 30);
437 WMMoveWidget(panel
->resizeTextL
, 90, 62);
439 WMMapSubwidgets(panel
->maxiF
);
441 /**************** Edge Resistance ****************/
443 panel
->resF
= WMCreateFrame(panel
->box
);
444 WMResizeWidget(panel
->resF
, 285, 45);
445 WMMoveWidget(panel
->resF
, 8, 125);
446 WMSetFrameTitle(panel
->resF
, _("Edge Resistance"));
448 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
449 "being moved further for the defined threshold\n"
450 "when moved against other windows or the edges\n"
451 "of the screen."), WMWidgetView(panel
->resF
));
453 panel
->resS
= WMCreateSlider(panel
->resF
);
454 WMResizeWidget(panel
->resS
, 80, 15);
455 WMMoveWidget(panel
->resS
, 10, 20);
456 WMSetSliderMinValue(panel
->resS
, 0);
457 WMSetSliderMaxValue(panel
->resS
, 80);
458 WMSetSliderAction(panel
->resS
, resistanceCallback
, panel
);
460 panel
->resL
= WMCreateLabel(panel
->resF
);
461 WMResizeWidget(panel
->resL
, 30, 15);
462 WMMoveWidget(panel
->resL
, 95, 20);
464 panel
->resaB
= WMCreateRadioButton(panel
->resF
);
465 WMMoveWidget(panel
->resaB
, 130, 15);
466 WMResizeWidget(panel
->resaB
, 70, 25);
467 WMSetButtonText(panel
->resaB
, _("Resist"));
469 panel
->resrB
= WMCreateRadioButton(panel
->resF
);
470 WMMoveWidget(panel
->resrB
, 200, 15);
471 WMResizeWidget(panel
->resrB
, 70, 25);
472 WMSetButtonText(panel
->resrB
, _("Attract"));
473 WMGroupButtons(panel
->resrB
, panel
->resaB
);
475 WMMapSubwidgets(panel
->resF
);
477 /**************** Transients on Parent Workspace ****************/
479 panel
->tranF
= WMCreateFrame(panel
->box
);
480 WMResizeWidget(panel
->tranF
, 285, 40);
481 WMMoveWidget(panel
->tranF
, 8, 180);
483 panel
->tranB
= WMCreateSwitchButton(panel
->tranF
);
484 WMMoveWidget(panel
->tranB
, 10, 5);
485 WMResizeWidget(panel
->tranB
, 250, 30);
486 WMSetButtonText(panel
->tranB
, _("Open dialogs in the same workspace\nas their owners"));
488 WMMapSubwidgets(panel
->tranF
);
490 WMRealizeWidget(panel
->box
);
491 WMMapSubwidgets(panel
->box
);
493 /* show the config data */
497 static void undo(_Panel
* panel
)
502 Panel
*InitWindowHandling(WMScreen
* scr
, WMWidget
* parent
)
506 panel
= wmalloc(sizeof(_Panel
));
508 panel
->sectionName
= _("Window Handling Preferences");
510 panel
->description
= _("Window handling options. Initial placement style\n"
511 "edge resistance, opaque move etc.");
513 panel
->parent
= parent
;
515 panel
->callbacks
.createWidgets
= createPanel
;
516 panel
->callbacks
.updateDomain
= storeData
;
517 panel
->callbacks
.undoChanges
= undo
;
519 AddSection(panel
, ICON_FILE
);