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 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
)
227 SetBoolForKey(WMGetButtonSelected(panel
->miconB
), "NoWindowOverIcons");
228 SetBoolForKey(WMGetButtonSelected(panel
->mdockB
), "NoWindowOverDock");
230 SetBoolForKey(WMGetButtonSelected(panel
->opaqB
), "OpaqueMove");
231 SetBoolForKey(WMGetButtonSelected(panel
->opaqresizeB
), "OpaqueResize");
232 SetBoolForKey(WMGetButtonSelected(panel
->opaqkeybB
), "OpaqueMoveResizeKeyboard");
234 SetBoolForKey(WMGetButtonSelected(panel
->tranB
), "OpenTransientOnOwnerWorkspace");
236 SetStringForKey(placements
[WMGetPopUpButtonSelectedItem(panel
->placP
)], "WindowPlacement");
237 sprintf(x
, "%i", WMGetSliderValue(panel
->hsli
));
238 sprintf(y
, "%i", WMGetSliderValue(panel
->vsli
));
239 arr
= WMCreatePLArray(WMCreatePLString(x
), WMCreatePLString(y
), NULL
);
240 SetObjectForKey(arr
, "WindowPlaceOrigin");
242 SetIntegerForKey(WMGetSliderValue(panel
->resS
), "EdgeResistance");
244 SetIntegerForKey(WMGetSliderValue(panel
->resizeS
), "ResizeIncrement");
245 SetBoolForKey(WMGetButtonSelected(panel
->resrB
), "Attraction");
247 WMReleasePropList(arr
);
250 static void createPanel(Panel
* p
)
252 _Panel
*panel
= (Panel
*) p
;
253 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
261 panel
->box
= WMCreateBox(panel
->parent
);
262 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
263 WMSetBoxHorizontal(panel
->box
, False
);
264 WMSetBoxBorderWidth(panel
->box
, 8);
266 hbox
= WMCreateBox(panel
->box
);
267 WMSetBoxHorizontal(hbox
, True
);
268 WMAddBoxSubview(panel
->box
, WMWidgetView(hbox
), False
, True
, 110, 0, 10);
270 /************** Window Placement ***************/
271 panel
->placF
= WMCreateFrame(hbox
);
272 WMMapWidget(panel
->placF
);
273 WMAddBoxSubview(hbox
, WMWidgetView(panel
->placF
), True
, True
, 100, 0, 10);
275 WMSetFrameTitle(panel
->placF
, _("Window Placement"));
276 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
277 "on screen."), WMWidgetView(panel
->placF
));
279 panel
->placP
= WMCreatePopUpButton(panel
->placF
);
280 WMResizeWidget(panel
->placP
, 105, 20);
281 WMMoveWidget(panel
->placP
, 10, 20);
282 WMAddPopUpButtonItem(panel
->placP
, _("Automatic"));
283 WMAddPopUpButtonItem(panel
->placP
, _("Random"));
284 WMAddPopUpButtonItem(panel
->placP
, _("Manual"));
285 WMAddPopUpButtonItem(panel
->placP
, _("Cascade"));
286 WMAddPopUpButtonItem(panel
->placP
, _("Smart"));
287 WMAddPopUpButtonItem(panel
->placP
, _("Center"));
289 panel
->porigL
= WMCreateLabel(panel
->placF
);
290 WMResizeWidget(panel
->porigL
, 110, 32);
291 WMMoveWidget(panel
->porigL
, 3, 45);
292 WMSetLabelTextAlignment(panel
->porigL
, WACenter
);
293 WMSetLabelText(panel
->porigL
, _("Placement Origin"));
295 panel
->porigvL
= WMCreateLabel(panel
->placF
);
296 WMResizeWidget(panel
->porigvL
, 80, 20);
297 WMMoveWidget(panel
->porigvL
, 18, 75);
298 WMSetLabelTextAlignment(panel
->porigvL
, WACenter
);
300 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
301 panel
->porigF
= WMCreateFrame(panel
->placF
);
302 WMSetWidgetBackgroundColor(panel
->porigF
, color
);
303 WMReleaseColor(color
);
304 WMSetFrameRelief(panel
->porigF
, WRSunken
);
306 swidth
= WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
307 sheight
= HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
309 if (sheight
> swidth
) {
310 width
= 70 * swidth
/ sheight
;
313 height
= 195 * sheight
/ swidth
;
315 height
= 195 * sheight
/ swidth
;
318 width
= 70 * swidth
/ sheight
;
320 WMResizeWidget(panel
->porigF
, width
, height
);
321 WMMoveWidget(panel
->porigF
, 125 + (195 - width
) / 2, 20 + (70 - height
) / 2);
323 panel
->porigW
= WMCreateLabel(panel
->porigF
);
324 WMResizeWidget(panel
->porigW
, THUMB_SIZE
, THUMB_SIZE
);
325 WMMoveWidget(panel
->porigW
, 2, 2);
326 WMSetLabelRelief(panel
->porigW
, WRRaised
);
328 panel
->hsli
= WMCreateSlider(panel
->placF
);
329 WMResizeWidget(panel
->hsli
, width
, 12);
330 WMMoveWidget(panel
->hsli
, 125 + (195 - width
) / 2, 20 + (70 - height
) / 2 + height
+ 2);
331 WMSetSliderAction(panel
->hsli
, sliderCallback
, panel
);
332 WMSetSliderMinValue(panel
->hsli
, 0);
333 WMSetSliderMaxValue(panel
->hsli
, swidth
);
335 panel
->vsli
= WMCreateSlider(panel
->placF
);
336 WMResizeWidget(panel
->vsli
, 12, height
);
337 WMMoveWidget(panel
->vsli
, 125 + (195 - width
) / 2 + width
+ 2, 20 + (70 - height
) / 2);
338 WMSetSliderAction(panel
->vsli
, sliderCallback
, panel
);
339 WMSetSliderMinValue(panel
->vsli
, 0);
340 WMSetSliderMaxValue(panel
->vsli
, sheight
);
342 WMMapSubwidgets(panel
->porigF
);
344 WMMapSubwidgets(panel
->placF
);
346 /************** Opaque Move, Resize ***************/
347 panel
->opaqF
= WMCreateFrame(hbox
);
348 WMMapWidget(panel
->opaqF
);
349 WMAddBoxSubview(hbox
, WMWidgetView(panel
->opaqF
), False
, True
, 150, 0, 0);
351 WMSetFrameTitle(panel
->opaqF
, _("Opaque Move/Resize"));
352 WMSetBalloonTextForView(_("Whether the window contents or only a frame should\n"
353 "be displayed during a move or resize.\n"),
354 WMWidgetView(panel
->opaqF
));
356 panel
->opaqB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
357 WMResizeWidget(panel
->opaqB
, 48,48);
358 WMMoveWidget(panel
->opaqB
, 18, 20);
359 WMSetButtonImagePosition(panel
->opaqB
, WIPImageOnly
);
361 path
= LocateImage(NON_OPAQUE_MOVE_PIXMAP
);
363 pixmap
= WMCreatePixmapFromFile(scr
, path
);
365 WMSetButtonImage(panel
->opaqB
, pixmap
);
366 WMReleasePixmap(pixmap
);
368 wwarning(_("could not load icon %s"), path
);
373 path
= LocateImage(OPAQUE_MOVE_PIXMAP
);
375 pixmap
= WMCreatePixmapFromFile(scr
, path
);
377 WMSetButtonAltImage(panel
->opaqB
, pixmap
);
378 WMReleasePixmap(pixmap
);
380 wwarning(_("could not load icon %s"), path
);
387 panel
->opaqresizeB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
388 WMResizeWidget(panel
->opaqresizeB
, 48,48);
389 WMMoveWidget(panel
->opaqresizeB
, 86, 20);
390 WMSetButtonImagePosition(panel
->opaqresizeB
, WIPImageOnly
);
392 path
= LocateImage(NON_OPAQUE_RESIZE_PIXMAP
);
394 pixmap
= WMCreatePixmapFromFile(scr
, path
);
396 WMSetButtonImage(panel
->opaqresizeB
, pixmap
);
397 WMReleasePixmap(pixmap
);
399 wwarning(_("could not load icon %s"), path
);
404 path
= LocateImage(OPAQUE_RESIZE_PIXMAP
);
406 pixmap
= WMCreatePixmapFromFile(scr
, path
);
408 WMSetButtonAltImage(panel
->opaqresizeB
, pixmap
);
409 WMReleasePixmap(pixmap
);
411 wwarning(_("could not load icon %s"), path
);
416 panel
->opaqkeybB
= WMCreateSwitchButton(panel
->opaqF
);
417 WMResizeWidget(panel
->opaqkeybB
, 100, 25);
418 WMMoveWidget(panel
->opaqkeybB
, 18, 76);
419 WMSetButtonText(panel
->opaqkeybB
, _("by keyboard"));
421 WMMapSubwidgets(panel
->opaqF
);
424 /**************** Account for Icon/Dock ***************/
425 panel
->maxiF
= WMCreateFrame(panel
->box
);
426 WMResizeWidget(panel
->maxiF
, 205, 100);
427 WMMoveWidget(panel
->maxiF
, 307, 125);
428 WMSetFrameTitle(panel
->maxiF
, _("When maximizing..."));
430 panel
->miconB
= WMCreateSwitchButton(panel
->maxiF
);
431 WMResizeWidget(panel
->miconB
, 190, 30);
432 WMMoveWidget(panel
->miconB
, 10, 14);
433 WMSetButtonText(panel
->miconB
, _("...do not cover icons"));
435 panel
->mdockB
= WMCreateSwitchButton(panel
->maxiF
);
436 WMResizeWidget(panel
->mdockB
, 190, 30);
437 WMMoveWidget(panel
->mdockB
, 10, 39);
439 WMSetButtonText(panel
->mdockB
, _("...do not cover dock"));
441 panel
->resizeS
= WMCreateSlider(panel
->maxiF
);
442 WMResizeWidget(panel
->resizeS
, 50, 15);
443 WMMoveWidget(panel
->resizeS
, 10, 74);
444 WMSetSliderMinValue(panel
->resizeS
, 0);
445 WMSetSliderMaxValue(panel
->resizeS
, 100);
446 WMSetSliderAction(panel
->resizeS
, resizeCallback
, panel
);
448 panel
->resizeL
= WMCreateLabel(panel
->maxiF
);
449 WMResizeWidget(panel
->resizeL
, 30, 15);
450 WMMoveWidget(panel
->resizeL
, 60, 74);
452 panel
->resizeTextL
= WMCreateLabel(panel
->maxiF
);
453 WMSetLabelText(panel
->resizeTextL
, "Mod+Wheel\nresize increment");
454 WMResizeWidget(panel
->resizeTextL
, 110, 30);
455 WMMoveWidget(panel
->resizeTextL
, 90, 66);
457 WMMapSubwidgets(panel
->maxiF
);
459 /**************** Edge Resistance ****************/
460 panel
->resF
= WMCreateFrame(panel
->box
);
461 WMResizeWidget(panel
->resF
, 289, 50);
462 WMMoveWidget(panel
->resF
, 8, 125);
463 WMSetFrameTitle(panel
->resF
, _("Edge Resistance"));
465 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
466 "being moved further for the defined threshold\n"
467 "when moved against other windows or the edges\n"
468 "of the screen."), WMWidgetView(panel
->resF
));
470 panel
->resS
= WMCreateSlider(panel
->resF
);
471 WMResizeWidget(panel
->resS
, 80, 15);
472 WMMoveWidget(panel
->resS
, 10, 22);
473 WMSetSliderMinValue(panel
->resS
, 0);
474 WMSetSliderMaxValue(panel
->resS
, 80);
475 WMSetSliderAction(panel
->resS
, resistanceCallback
, panel
);
477 panel
->resL
= WMCreateLabel(panel
->resF
);
478 WMResizeWidget(panel
->resL
, 30, 15);
479 WMMoveWidget(panel
->resL
, 95, 22);
481 panel
->resaB
= WMCreateRadioButton(panel
->resF
);
482 WMMoveWidget(panel
->resaB
, 130, 15);
483 WMResizeWidget(panel
->resaB
, 70, 27);
484 WMSetButtonText(panel
->resaB
, _("Resist"));
486 panel
->resrB
= WMCreateRadioButton(panel
->resF
);
487 WMMoveWidget(panel
->resrB
, 200, 15);
488 WMResizeWidget(panel
->resrB
, 70, 27);
489 WMSetButtonText(panel
->resrB
, _("Attract"));
490 WMGroupButtons(panel
->resrB
, panel
->resaB
);
492 WMMapSubwidgets(panel
->resF
);
494 /**************** Transients on Parent Workspace ****************/
495 panel
->tranF
= WMCreateFrame(panel
->box
);
496 WMResizeWidget(panel
->tranF
, 289, 40);
497 WMMoveWidget(panel
->tranF
, 8, 185);
499 panel
->tranB
= WMCreateSwitchButton(panel
->tranF
);
500 WMMoveWidget(panel
->tranB
, 10, 5);
501 WMResizeWidget(panel
->tranB
, 250, 30);
502 WMSetButtonText(panel
->tranB
, _("Open dialogs in the same workspace\nas their owners"));
504 WMMapSubwidgets(panel
->tranF
);
506 WMRealizeWidget(panel
->box
);
507 WMMapSubwidgets(panel
->box
);
509 /* show the config data */
513 static void undo(_Panel
* panel
)
518 Panel
*InitWindowHandling(WMWidget
*parent
)
522 panel
= wmalloc(sizeof(_Panel
));
524 panel
->sectionName
= _("Window Handling Preferences");
526 panel
->description
= _("Window handling options. Initial placement style\n"
527 "edge resistance, opaque move etc.");
529 panel
->parent
= parent
;
531 panel
->callbacks
.createWidgets
= createPanel
;
532 panel
->callbacks
.updateDomain
= storeData
;
533 panel
->callbacks
.undoChanges
= undo
;
535 AddSection(panel
, ICON_FILE
);