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
;
61 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 const 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 /* Parameter not used, but tell the compiler that it is ok */
100 x
= WMGetSliderValue(panel
->hsli
);
101 y
= WMGetSliderValue(panel
->vsli
);
103 rx
= x
* (WMWidgetWidth(panel
->porigF
) - 3) / swidth
+ 2;
104 ry
= y
* (WMWidgetHeight(panel
->porigF
) - 3) / sheight
+ 2;
105 WMMoveWidget(panel
->porigW
, rx
, ry
);
107 sprintf(buffer
, "(%i,%i)", x
, y
);
108 WMSetLabelText(panel
->porigvL
, buffer
);
111 static void resistanceCallback(WMWidget
* w
, void *data
)
113 _Panel
*panel
= (_Panel
*) data
;
117 /* Parameter not used, but tell the compiler that it is ok */
120 i
= WMGetSliderValue(panel
->resS
);
123 WMSetLabelText(panel
->resL
, _("OFF"));
125 sprintf(buffer
, "%i", i
);
126 WMSetLabelText(panel
->resL
, buffer
);
130 static void resizeCallback(WMWidget
* w
, void *data
)
132 _Panel
*panel
= (_Panel
*) data
;
136 /* Parameter not used, but tell the compiler that it is ok */
139 i
= WMGetSliderValue(panel
->resizeS
);
142 WMSetLabelText(panel
->resizeL
, _("OFF"));
144 sprintf(buffer
, "%i", i
);
145 WMSetLabelText(panel
->resizeL
, buffer
);
149 static int getPlacement(const char *str
)
154 if (strcasecmp(str
, "auto") == 0)
156 else if (strcasecmp(str
, "random") == 0)
158 else if (strcasecmp(str
, "manual") == 0)
160 else if (strcasecmp(str
, "cascade") == 0)
162 else if (strcasecmp(str
, "smart") == 0)
164 else if (strcasecmp(str
, "center") == 0)
167 wwarning(_("bad option value %s in WindowPlacement. Using default value"), str
);
171 static void showData(_Panel
* panel
)
177 str
= GetStringForKey("WindowPlacement");
179 WMSetPopUpButtonSelectedItem(panel
->placP
, getPlacement(str
));
181 arr
= GetObjectForKey("WindowPlaceOrigin");
185 if (arr
&& (!WMIsPLArray(arr
) || WMGetPropListItemCount(arr
) != 2)) {
186 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
189 x
= atoi(WMGetFromPLString(WMGetFromPLArray(arr
, 0)));
190 y
= atoi(WMGetFromPLString(WMGetFromPLArray(arr
, 1)));
194 WMSetSliderValue(panel
->hsli
, x
);
195 WMSetSliderValue(panel
->vsli
, y
);
197 sliderCallback(NULL
, panel
);
199 x
= GetIntegerForKey("EdgeResistance");
200 WMSetSliderValue(panel
->resS
, x
);
201 resistanceCallback(NULL
, panel
);
203 x
= GetIntegerForKey("ResizeIncrement");
204 WMSetSliderValue(panel
->resizeS
, x
);
205 resizeCallback(NULL
, panel
);
207 WMSetButtonSelected(panel
->tranB
, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
209 WMSetButtonSelected(panel
->opaqB
, GetBoolForKey("OpaqueMove"));
210 WMSetButtonSelected(panel
->opaqresizeB
, GetBoolForKey("OpaqueResize"));
211 WMSetButtonSelected(panel
->opaqkeybB
, GetBoolForKey("OpaqueMoveResizeKeyboard"));
213 WMSetButtonSelected(panel
->miconB
, GetBoolForKey("NoWindowOverIcons"));
214 WMSetButtonSelected(panel
->mdockB
, GetBoolForKey("NoWindowOverDock"));
216 if (GetBoolForKey("Attraction"))
217 WMPerformButtonClick(panel
->resrB
);
219 WMPerformButtonClick(panel
->resaB
);
222 static void storeData(_Panel
* panel
)
228 SetBoolForKey(WMGetButtonSelected(panel
->miconB
), "NoWindowOverIcons");
229 SetBoolForKey(WMGetButtonSelected(panel
->mdockB
), "NoWindowOverDock");
231 SetBoolForKey(WMGetButtonSelected(panel
->opaqB
), "OpaqueMove");
232 SetBoolForKey(WMGetButtonSelected(panel
->opaqresizeB
), "OpaqueResize");
233 SetBoolForKey(WMGetButtonSelected(panel
->opaqkeybB
), "OpaqueMoveResizeKeyboard");
235 SetBoolForKey(WMGetButtonSelected(panel
->tranB
), "OpenTransientOnOwnerWorkspace");
237 SetStringForKey(placements
[WMGetPopUpButtonSelectedItem(panel
->placP
)], "WindowPlacement");
238 sprintf(buf
, "%i", WMGetSliderValue(panel
->hsli
));
239 x
= WMCreatePLString(buf
);
240 sprintf(buf
, "%i", WMGetSliderValue(panel
->vsli
));
241 y
= WMCreatePLString(buf
);
242 arr
= WMCreatePLArray(x
, y
, NULL
);
243 WMReleasePropList(x
);
244 WMReleasePropList(y
);
245 SetObjectForKey(arr
, "WindowPlaceOrigin");
247 SetIntegerForKey(WMGetSliderValue(panel
->resS
), "EdgeResistance");
249 SetIntegerForKey(WMGetSliderValue(panel
->resizeS
), "ResizeIncrement");
250 SetBoolForKey(WMGetButtonSelected(panel
->resrB
), "Attraction");
252 WMReleasePropList(arr
);
255 static void createPanel(Panel
* p
)
257 _Panel
*panel
= (Panel
*) p
;
258 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
266 panel
->box
= WMCreateBox(panel
->parent
);
267 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
268 WMSetBoxHorizontal(panel
->box
, False
);
269 WMSetBoxBorderWidth(panel
->box
, 8);
271 hbox
= WMCreateBox(panel
->box
);
272 WMSetBoxHorizontal(hbox
, True
);
273 WMAddBoxSubview(panel
->box
, WMWidgetView(hbox
), False
, True
, 110, 0, 10);
275 /************** Window Placement ***************/
276 panel
->placF
= WMCreateFrame(hbox
);
277 WMMapWidget(panel
->placF
);
278 WMAddBoxSubview(hbox
, WMWidgetView(panel
->placF
), True
, True
, 100, 0, 10);
280 WMSetFrameTitle(panel
->placF
, _("Window Placement"));
281 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
282 "on screen."), WMWidgetView(panel
->placF
));
284 panel
->placP
= WMCreatePopUpButton(panel
->placF
);
285 WMResizeWidget(panel
->placP
, 105, 20);
286 WMMoveWidget(panel
->placP
, 10, 20);
287 WMAddPopUpButtonItem(panel
->placP
, _("Automatic"));
288 WMAddPopUpButtonItem(panel
->placP
, _("Random"));
289 WMAddPopUpButtonItem(panel
->placP
, _("Manual"));
290 WMAddPopUpButtonItem(panel
->placP
, _("Cascade"));
291 WMAddPopUpButtonItem(panel
->placP
, _("Smart"));
292 WMAddPopUpButtonItem(panel
->placP
, _("Center"));
294 panel
->porigL
= WMCreateLabel(panel
->placF
);
295 WMResizeWidget(panel
->porigL
, 110, 32);
296 WMMoveWidget(panel
->porigL
, 3, 45);
297 WMSetLabelTextAlignment(panel
->porigL
, WACenter
);
298 WMSetLabelText(panel
->porigL
, _("Placement Origin"));
300 panel
->porigvL
= WMCreateLabel(panel
->placF
);
301 WMResizeWidget(panel
->porigvL
, 80, 20);
302 WMMoveWidget(panel
->porigvL
, 18, 75);
303 WMSetLabelTextAlignment(panel
->porigvL
, WACenter
);
305 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
306 panel
->porigF
= WMCreateFrame(panel
->placF
);
307 WMSetWidgetBackgroundColor(panel
->porigF
, color
);
308 WMReleaseColor(color
);
309 WMSetFrameRelief(panel
->porigF
, WRSunken
);
311 swidth
= WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
312 sheight
= HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
314 if (sheight
> swidth
) {
315 width
= 70 * swidth
/ sheight
;
318 height
= 195 * sheight
/ swidth
;
320 height
= 195 * sheight
/ swidth
;
323 width
= 70 * swidth
/ sheight
;
325 WMResizeWidget(panel
->porigF
, width
, height
);
326 WMMoveWidget(panel
->porigF
, 125 + (195 - width
) / 2, 20 + (70 - height
) / 2);
328 panel
->porigW
= WMCreateLabel(panel
->porigF
);
329 WMResizeWidget(panel
->porigW
, THUMB_SIZE
, THUMB_SIZE
);
330 WMMoveWidget(panel
->porigW
, 2, 2);
331 WMSetLabelRelief(panel
->porigW
, WRRaised
);
333 panel
->hsli
= WMCreateSlider(panel
->placF
);
334 WMResizeWidget(panel
->hsli
, width
, 12);
335 WMMoveWidget(panel
->hsli
, 125 + (195 - width
) / 2, 20 + (70 - height
) / 2 + height
+ 2);
336 WMSetSliderAction(panel
->hsli
, sliderCallback
, panel
);
337 WMSetSliderMinValue(panel
->hsli
, 0);
338 WMSetSliderMaxValue(panel
->hsli
, swidth
);
340 panel
->vsli
= WMCreateSlider(panel
->placF
);
341 WMResizeWidget(panel
->vsli
, 12, height
);
342 WMMoveWidget(panel
->vsli
, 125 + (195 - width
) / 2 + width
+ 2, 20 + (70 - height
) / 2);
343 WMSetSliderAction(panel
->vsli
, sliderCallback
, panel
);
344 WMSetSliderMinValue(panel
->vsli
, 0);
345 WMSetSliderMaxValue(panel
->vsli
, sheight
);
347 WMMapSubwidgets(panel
->porigF
);
349 WMMapSubwidgets(panel
->placF
);
351 /************** Opaque Move, Resize ***************/
352 panel
->opaqF
= WMCreateFrame(hbox
);
353 WMMapWidget(panel
->opaqF
);
354 WMAddBoxSubview(hbox
, WMWidgetView(panel
->opaqF
), False
, True
, 150, 0, 0);
356 WMSetFrameTitle(panel
->opaqF
, _("Opaque Move/Resize"));
357 WMSetBalloonTextForView(_("Whether the window contents or only a frame should\n"
358 "be displayed during a move or resize.\n"),
359 WMWidgetView(panel
->opaqF
));
361 panel
->opaqB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
362 WMResizeWidget(panel
->opaqB
, 54, 54);
363 WMMoveWidget(panel
->opaqB
, 14, 20);
364 WMSetButtonImagePosition(panel
->opaqB
, WIPImageOnly
);
366 path
= LocateImage(NON_OPAQUE_MOVE_PIXMAP
);
368 pixmap
= WMCreatePixmapFromFile(scr
, path
);
370 WMSetButtonImage(panel
->opaqB
, pixmap
);
371 WMReleasePixmap(pixmap
);
373 wwarning(_("could not load icon %s"), path
);
378 path
= LocateImage(OPAQUE_MOVE_PIXMAP
);
380 pixmap
= WMCreatePixmapFromFile(scr
, path
);
382 WMSetButtonAltImage(panel
->opaqB
, pixmap
);
383 WMReleasePixmap(pixmap
);
385 wwarning(_("could not load icon %s"), path
);
392 panel
->opaqresizeB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
393 WMResizeWidget(panel
->opaqresizeB
, 54, 54);
394 WMMoveWidget(panel
->opaqresizeB
, 82, 20);
395 WMSetButtonImagePosition(panel
->opaqresizeB
, WIPImageOnly
);
397 path
= LocateImage(NON_OPAQUE_RESIZE_PIXMAP
);
399 pixmap
= WMCreatePixmapFromFile(scr
, path
);
401 WMSetButtonImage(panel
->opaqresizeB
, pixmap
);
402 WMReleasePixmap(pixmap
);
404 wwarning(_("could not load icon %s"), path
);
409 path
= LocateImage(OPAQUE_RESIZE_PIXMAP
);
411 pixmap
= WMCreatePixmapFromFile(scr
, path
);
413 WMSetButtonAltImage(panel
->opaqresizeB
, pixmap
);
414 WMReleasePixmap(pixmap
);
416 wwarning(_("could not load icon %s"), path
);
421 panel
->opaqkeybB
= WMCreateSwitchButton(panel
->opaqF
);
422 WMResizeWidget(panel
->opaqkeybB
, 122, 25);
423 WMMoveWidget(panel
->opaqkeybB
, 14, 79);
424 WMSetButtonText(panel
->opaqkeybB
, _("by keyboard"));
426 WMMapSubwidgets(panel
->opaqF
);
429 /**************** Account for Icon/Dock ***************/
430 panel
->maxiF
= WMCreateFrame(panel
->box
);
431 WMResizeWidget(panel
->maxiF
, 205, 100);
432 WMMoveWidget(panel
->maxiF
, 307, 125);
433 WMSetFrameTitle(panel
->maxiF
, _("When maximizing..."));
435 panel
->miconB
= WMCreateSwitchButton(panel
->maxiF
);
436 WMResizeWidget(panel
->miconB
, 190, 30);
437 WMMoveWidget(panel
->miconB
, 10, 14);
438 WMSetButtonText(panel
->miconB
, _("...do not cover icons"));
440 panel
->mdockB
= WMCreateSwitchButton(panel
->maxiF
);
441 WMResizeWidget(panel
->mdockB
, 190, 30);
442 WMMoveWidget(panel
->mdockB
, 10, 39);
444 WMSetButtonText(panel
->mdockB
, _("...do not cover dock"));
446 panel
->resizeS
= WMCreateSlider(panel
->maxiF
);
447 WMResizeWidget(panel
->resizeS
, 50, 15);
448 WMMoveWidget(panel
->resizeS
, 10, 74);
449 WMSetSliderMinValue(panel
->resizeS
, 0);
450 WMSetSliderMaxValue(panel
->resizeS
, 100);
451 WMSetSliderAction(panel
->resizeS
, resizeCallback
, panel
);
453 panel
->resizeL
= WMCreateLabel(panel
->maxiF
);
454 WMResizeWidget(panel
->resizeL
, 30, 15);
455 WMMoveWidget(panel
->resizeL
, 60, 74);
457 panel
->resizeTextL
= WMCreateLabel(panel
->maxiF
);
458 WMSetLabelText(panel
->resizeTextL
, _("Mod+Wheel\nresize increment"));
459 WMResizeWidget(panel
->resizeTextL
, 110, 30);
460 WMMoveWidget(panel
->resizeTextL
, 90, 66);
462 WMMapSubwidgets(panel
->maxiF
);
464 /**************** Edge Resistance ****************/
465 panel
->resF
= WMCreateFrame(panel
->box
);
466 WMResizeWidget(panel
->resF
, 289, 50);
467 WMMoveWidget(panel
->resF
, 8, 125);
468 WMSetFrameTitle(panel
->resF
, _("Edge Resistance"));
470 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
471 "being moved further for the defined threshold\n"
472 "when moved against other windows or the edges\n"
473 "of the screen."), WMWidgetView(panel
->resF
));
475 panel
->resS
= WMCreateSlider(panel
->resF
);
476 WMResizeWidget(panel
->resS
, 80, 15);
477 WMMoveWidget(panel
->resS
, 10, 22);
478 WMSetSliderMinValue(panel
->resS
, 0);
479 WMSetSliderMaxValue(panel
->resS
, 80);
480 WMSetSliderAction(panel
->resS
, resistanceCallback
, panel
);
482 panel
->resL
= WMCreateLabel(panel
->resF
);
483 WMResizeWidget(panel
->resL
, 30, 15);
484 WMMoveWidget(panel
->resL
, 95, 22);
486 panel
->resaB
= WMCreateRadioButton(panel
->resF
);
487 WMMoveWidget(panel
->resaB
, 130, 15);
488 WMResizeWidget(panel
->resaB
, 70, 27);
489 WMSetButtonText(panel
->resaB
, _("Resist"));
491 panel
->resrB
= WMCreateRadioButton(panel
->resF
);
492 WMMoveWidget(panel
->resrB
, 200, 15);
493 WMResizeWidget(panel
->resrB
, 70, 27);
494 WMSetButtonText(panel
->resrB
, _("Attract"));
495 WMGroupButtons(panel
->resrB
, panel
->resaB
);
497 WMMapSubwidgets(panel
->resF
);
499 /**************** Transients on Parent Workspace ****************/
500 panel
->tranF
= WMCreateFrame(panel
->box
);
501 WMResizeWidget(panel
->tranF
, 289, 40);
502 WMMoveWidget(panel
->tranF
, 8, 185);
504 panel
->tranB
= WMCreateSwitchButton(panel
->tranF
);
505 WMMoveWidget(panel
->tranB
, 10, 5);
506 WMResizeWidget(panel
->tranB
, 250, 30);
507 WMSetButtonText(panel
->tranB
, _("Open dialogs in the same workspace as their owners"));
509 WMMapSubwidgets(panel
->tranF
);
511 WMRealizeWidget(panel
->box
);
512 WMMapSubwidgets(panel
->box
);
514 /* show the config data */
518 static void undo(_Panel
* panel
)
523 Panel
*InitWindowHandling(WMWidget
*parent
)
527 panel
= wmalloc(sizeof(_Panel
));
529 panel
->sectionName
= _("Window Handling Preferences");
531 panel
->description
= _("Window handling options. Initial placement style\n"
532 "edge resistance, opaque move etc.");
534 panel
->parent
= parent
;
536 panel
->callbacks
.createWidgets
= createPanel
;
537 panel
->callbacks
.updateDomain
= storeData
;
538 panel
->callbacks
.undoChanges
= undo
;
540 AddSection(panel
, ICON_FILE
);