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
;
65 WMPopUpButton
*dragmaxP
;
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 *const placements
[] = {
89 static const char *const dragMaximizedWindowOptions
[] = {
96 static void sliderCallback(WMWidget
* w
, void *data
)
98 _Panel
*panel
= (_Panel
*) data
;
101 int swidth
= WMGetSliderMaxValue(panel
->hsli
);
102 int sheight
= WMGetSliderMaxValue(panel
->vsli
);
104 /* Parameter not used, but tell the compiler that it is ok */
107 x
= WMGetSliderValue(panel
->hsli
);
108 y
= WMGetSliderValue(panel
->vsli
);
110 rx
= x
* (WMWidgetWidth(panel
->porigF
) - 3) / swidth
+ 2;
111 ry
= y
* (WMWidgetHeight(panel
->porigF
) - 3) / sheight
+ 2;
112 WMMoveWidget(panel
->porigW
, rx
, ry
);
114 sprintf(buffer
, "(%i,%i)", x
, y
);
115 WMSetLabelText(panel
->porigvL
, buffer
);
118 static void resistanceCallback(WMWidget
* w
, void *data
)
120 _Panel
*panel
= (_Panel
*) data
;
124 /* Parameter not used, but tell the compiler that it is ok */
127 i
= WMGetSliderValue(panel
->resS
);
130 WMSetLabelText(panel
->resL
, _("OFF"));
132 sprintf(buffer
, "%i", i
);
133 WMSetLabelText(panel
->resL
, buffer
);
137 static void resizeCallback(WMWidget
* w
, void *data
)
139 _Panel
*panel
= (_Panel
*) data
;
143 /* Parameter not used, but tell the compiler that it is ok */
146 i
= WMGetSliderValue(panel
->resizeS
);
149 WMSetLabelText(panel
->resizeL
, _("OFF"));
151 sprintf(buffer
, "%i", i
);
152 WMSetLabelText(panel
->resizeL
, buffer
);
156 static int getPlacement(const char *str
)
161 if (strcasecmp(str
, "auto") == 0)
163 else if (strcasecmp(str
, "random") == 0)
165 else if (strcasecmp(str
, "manual") == 0)
167 else if (strcasecmp(str
, "cascade") == 0)
169 else if (strcasecmp(str
, "smart") == 0)
171 else if (strcasecmp(str
, "center") == 0)
174 wwarning(_("bad option value %s in WindowPlacement. Using default value"), str
);
178 static int getDragMaximizedWindow(const char *str
)
183 if (strcasecmp(str
, "Move") == 0)
185 else if (strcasecmp(str
, "RestoreGeometry") == 0)
187 else if (strcasecmp(str
, "Unmaximize") == 0)
189 else if (strcasecmp(str
, "NoMove") == 0)
192 wwarning(_("bad option value %s in WindowPlacement. Using default value"), str
);
197 static void showData(_Panel
* panel
)
203 str
= GetStringForKey("WindowPlacement");
205 WMSetPopUpButtonSelectedItem(panel
->placP
, getPlacement(str
));
207 arr
= GetObjectForKey("WindowPlaceOrigin");
211 if (arr
&& (!WMIsPLArray(arr
) || WMGetPropListItemCount(arr
) != 2)) {
212 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
215 x
= atoi(WMGetFromPLString(WMGetFromPLArray(arr
, 0)));
216 y
= atoi(WMGetFromPLString(WMGetFromPLArray(arr
, 1)));
220 WMSetSliderValue(panel
->hsli
, x
);
221 WMSetSliderValue(panel
->vsli
, y
);
223 sliderCallback(NULL
, panel
);
225 x
= GetIntegerForKey("EdgeResistance");
226 WMSetSliderValue(panel
->resS
, x
);
227 resistanceCallback(NULL
, panel
);
229 str
= GetStringForKey("DragMaximizedWindow");
230 WMSetPopUpButtonSelectedItem(panel
->dragmaxP
, getDragMaximizedWindow(str
));
232 x
= GetIntegerForKey("ResizeIncrement");
233 WMSetSliderValue(panel
->resizeS
, x
);
234 resizeCallback(NULL
, panel
);
236 WMSetButtonSelected(panel
->opaqB
, GetBoolForKey("OpaqueMove"));
237 WMSetButtonSelected(panel
->opaqresizeB
, GetBoolForKey("OpaqueResize"));
238 WMSetButtonSelected(panel
->opaqkeybB
, GetBoolForKey("OpaqueMoveResizeKeyboard"));
240 WMSetButtonSelected(panel
->miconB
, GetBoolForKey("NoWindowOverIcons"));
241 WMSetButtonSelected(panel
->mdockB
, GetBoolForKey("NoWindowOverDock"));
243 if (GetBoolForKey("Attraction"))
244 WMPerformButtonClick(panel
->resrB
);
246 WMPerformButtonClick(panel
->resaB
);
249 static void storeData(_Panel
* panel
)
255 SetBoolForKey(WMGetButtonSelected(panel
->miconB
), "NoWindowOverIcons");
256 SetBoolForKey(WMGetButtonSelected(panel
->mdockB
), "NoWindowOverDock");
258 SetBoolForKey(WMGetButtonSelected(panel
->opaqB
), "OpaqueMove");
259 SetBoolForKey(WMGetButtonSelected(panel
->opaqresizeB
), "OpaqueResize");
260 SetBoolForKey(WMGetButtonSelected(panel
->opaqkeybB
), "OpaqueMoveResizeKeyboard");
262 SetStringForKey(placements
[WMGetPopUpButtonSelectedItem(panel
->placP
)], "WindowPlacement");
263 sprintf(buf
, "%i", WMGetSliderValue(panel
->hsli
));
264 x
= WMCreatePLString(buf
);
265 sprintf(buf
, "%i", WMGetSliderValue(panel
->vsli
));
266 y
= WMCreatePLString(buf
);
267 arr
= WMCreatePLArray(x
, y
, NULL
);
268 WMReleasePropList(x
);
269 WMReleasePropList(y
);
270 SetObjectForKey(arr
, "WindowPlaceOrigin");
272 SetIntegerForKey(WMGetSliderValue(panel
->resS
), "EdgeResistance");
274 SetStringForKey(dragMaximizedWindowOptions
[WMGetPopUpButtonSelectedItem(panel
->dragmaxP
)],
275 "DragMaximizedWindow");
277 SetIntegerForKey(WMGetSliderValue(panel
->resizeS
), "ResizeIncrement");
278 SetBoolForKey(WMGetButtonSelected(panel
->resrB
), "Attraction");
280 WMReleasePropList(arr
);
283 static void createPanel(Panel
* p
)
285 _Panel
*panel
= (Panel
*) p
;
286 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
294 panel
->box
= WMCreateBox(panel
->parent
);
295 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
296 WMSetBoxHorizontal(panel
->box
, False
);
297 WMSetBoxBorderWidth(panel
->box
, 8);
299 hbox
= WMCreateBox(panel
->box
);
300 WMSetBoxHorizontal(hbox
, True
);
301 WMAddBoxSubview(panel
->box
, WMWidgetView(hbox
), False
, True
, 110, 0, 10);
303 /************** Window Placement ***************/
304 panel
->placF
= WMCreateFrame(hbox
);
305 WMMapWidget(panel
->placF
);
306 WMAddBoxSubview(hbox
, WMWidgetView(panel
->placF
), True
, True
, 100, 0, 10);
308 WMSetFrameTitle(panel
->placF
, _("Window Placement"));
309 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
310 "on screen."), WMWidgetView(panel
->placF
));
312 panel
->placP
= WMCreatePopUpButton(panel
->placF
);
313 WMResizeWidget(panel
->placP
, 105, 20);
314 WMMoveWidget(panel
->placP
, 10, 20);
315 WMAddPopUpButtonItem(panel
->placP
, _("Automatic"));
316 WMAddPopUpButtonItem(panel
->placP
, _("Random"));
317 WMAddPopUpButtonItem(panel
->placP
, _("Manual"));
318 WMAddPopUpButtonItem(panel
->placP
, _("Cascade"));
319 WMAddPopUpButtonItem(panel
->placP
, _("Smart"));
320 WMAddPopUpButtonItem(panel
->placP
, _("Center"));
322 panel
->porigL
= WMCreateLabel(panel
->placF
);
323 WMResizeWidget(panel
->porigL
, 110, 32);
324 WMMoveWidget(panel
->porigL
, 3, 45);
325 WMSetLabelTextAlignment(panel
->porigL
, WACenter
);
326 WMSetLabelText(panel
->porigL
, _("Placement Origin"));
328 panel
->porigvL
= WMCreateLabel(panel
->placF
);
329 WMResizeWidget(panel
->porigvL
, 80, 20);
330 WMMoveWidget(panel
->porigvL
, 18, 75);
331 WMSetLabelTextAlignment(panel
->porigvL
, WACenter
);
333 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
334 panel
->porigF
= WMCreateFrame(panel
->placF
);
335 WMSetWidgetBackgroundColor(panel
->porigF
, color
);
336 WMReleaseColor(color
);
337 WMSetFrameRelief(panel
->porigF
, WRSunken
);
339 swidth
= WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
340 sheight
= HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
342 if (sheight
> swidth
) {
343 width
= 70 * swidth
/ sheight
;
346 height
= 195 * sheight
/ swidth
;
348 height
= 195 * sheight
/ swidth
;
351 width
= 70 * swidth
/ sheight
;
353 WMResizeWidget(panel
->porigF
, width
, height
);
354 WMMoveWidget(panel
->porigF
, 125 + (195 - width
) / 2, 20 + (70 - height
) / 2);
356 panel
->porigW
= WMCreateLabel(panel
->porigF
);
357 WMResizeWidget(panel
->porigW
, THUMB_SIZE
, THUMB_SIZE
);
358 WMMoveWidget(panel
->porigW
, 2, 2);
359 WMSetLabelRelief(panel
->porigW
, WRRaised
);
361 panel
->hsli
= WMCreateSlider(panel
->placF
);
362 WMResizeWidget(panel
->hsli
, width
, 12);
363 WMMoveWidget(panel
->hsli
, 125 + (195 - width
) / 2, 20 + (70 - height
) / 2 + height
+ 2);
364 WMSetSliderAction(panel
->hsli
, sliderCallback
, panel
);
365 WMSetSliderMinValue(panel
->hsli
, 0);
366 WMSetSliderMaxValue(panel
->hsli
, swidth
);
368 panel
->vsli
= WMCreateSlider(panel
->placF
);
369 WMResizeWidget(panel
->vsli
, 12, height
);
370 WMMoveWidget(panel
->vsli
, 125 + (195 - width
) / 2 + width
+ 2, 20 + (70 - height
) / 2);
371 WMSetSliderAction(panel
->vsli
, sliderCallback
, panel
);
372 WMSetSliderMinValue(panel
->vsli
, 0);
373 WMSetSliderMaxValue(panel
->vsli
, sheight
);
375 WMMapSubwidgets(panel
->porigF
);
377 WMMapSubwidgets(panel
->placF
);
379 /************** Opaque Move, Resize ***************/
380 panel
->opaqF
= WMCreateFrame(hbox
);
381 WMMapWidget(panel
->opaqF
);
382 WMAddBoxSubview(hbox
, WMWidgetView(panel
->opaqF
), False
, True
, 150, 0, 0);
384 WMSetFrameTitle(panel
->opaqF
, _("Opaque Move/Resize"));
385 WMSetBalloonTextForView(_("Whether the window contents or only a frame should\n"
386 "be displayed during a move or resize.\n"),
387 WMWidgetView(panel
->opaqF
));
389 panel
->opaqB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
390 WMResizeWidget(panel
->opaqB
, 54, 54);
391 WMMoveWidget(panel
->opaqB
, 14, 20);
392 WMSetButtonImagePosition(panel
->opaqB
, WIPImageOnly
);
394 path
= LocateImage(NON_OPAQUE_MOVE_PIXMAP
);
396 pixmap
= WMCreatePixmapFromFile(scr
, path
);
398 WMSetButtonImage(panel
->opaqB
, pixmap
);
399 WMReleasePixmap(pixmap
);
401 wwarning(_("could not load icon %s"), path
);
406 path
= LocateImage(OPAQUE_MOVE_PIXMAP
);
408 pixmap
= WMCreatePixmapFromFile(scr
, path
);
410 WMSetButtonAltImage(panel
->opaqB
, pixmap
);
411 WMReleasePixmap(pixmap
);
413 wwarning(_("could not load icon %s"), path
);
420 panel
->opaqresizeB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
421 WMResizeWidget(panel
->opaqresizeB
, 54, 54);
422 WMMoveWidget(panel
->opaqresizeB
, 82, 20);
423 WMSetButtonImagePosition(panel
->opaqresizeB
, WIPImageOnly
);
425 path
= LocateImage(NON_OPAQUE_RESIZE_PIXMAP
);
427 pixmap
= WMCreatePixmapFromFile(scr
, path
);
429 WMSetButtonImage(panel
->opaqresizeB
, pixmap
);
430 WMReleasePixmap(pixmap
);
432 wwarning(_("could not load icon %s"), path
);
437 path
= LocateImage(OPAQUE_RESIZE_PIXMAP
);
439 pixmap
= WMCreatePixmapFromFile(scr
, path
);
441 WMSetButtonAltImage(panel
->opaqresizeB
, pixmap
);
442 WMReleasePixmap(pixmap
);
444 wwarning(_("could not load icon %s"), path
);
449 panel
->opaqkeybB
= WMCreateSwitchButton(panel
->opaqF
);
450 WMResizeWidget(panel
->opaqkeybB
, 122, 25);
451 WMMoveWidget(panel
->opaqkeybB
, 14, 79);
452 WMSetButtonText(panel
->opaqkeybB
, _("by keyboard"));
454 WMMapSubwidgets(panel
->opaqF
);
457 /**************** Account for Icon/Dock ***************/
458 panel
->maxiF
= WMCreateFrame(panel
->box
);
459 WMResizeWidget(panel
->maxiF
, 205, 100);
460 WMMoveWidget(panel
->maxiF
, 307, 125);
461 WMSetFrameTitle(panel
->maxiF
, _("When maximizing..."));
463 panel
->miconB
= WMCreateSwitchButton(panel
->maxiF
);
464 WMResizeWidget(panel
->miconB
, 190, 30);
465 WMMoveWidget(panel
->miconB
, 10, 14);
466 WMSetButtonText(panel
->miconB
, _("...do not cover icons"));
468 panel
->mdockB
= WMCreateSwitchButton(panel
->maxiF
);
469 WMResizeWidget(panel
->mdockB
, 190, 30);
470 WMMoveWidget(panel
->mdockB
, 10, 39);
472 WMSetButtonText(panel
->mdockB
, _("...do not cover dock"));
474 panel
->resizeS
= WMCreateSlider(panel
->maxiF
);
475 WMResizeWidget(panel
->resizeS
, 50, 15);
476 WMMoveWidget(panel
->resizeS
, 10, 74);
477 WMSetSliderMinValue(panel
->resizeS
, 0);
478 WMSetSliderMaxValue(panel
->resizeS
, 100);
479 WMSetSliderAction(panel
->resizeS
, resizeCallback
, panel
);
481 panel
->resizeL
= WMCreateLabel(panel
->maxiF
);
482 WMResizeWidget(panel
->resizeL
, 30, 15);
483 WMMoveWidget(panel
->resizeL
, 60, 74);
485 panel
->resizeTextL
= WMCreateLabel(panel
->maxiF
);
486 WMSetLabelText(panel
->resizeTextL
, _("Mod+Wheel\nresize increment"));
487 WMResizeWidget(panel
->resizeTextL
, 110, 30);
488 WMMoveWidget(panel
->resizeTextL
, 90, 66);
490 WMMapSubwidgets(panel
->maxiF
);
492 /**************** Edge Resistance ****************/
493 panel
->resF
= WMCreateFrame(panel
->box
);
494 WMResizeWidget(panel
->resF
, 289, 47);
495 WMMoveWidget(panel
->resF
, 8, 125);
496 WMSetFrameTitle(panel
->resF
, _("Edge Resistance"));
498 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
499 "being moved further for the defined threshold\n"
500 "when moved against other windows or the edges\n"
501 "of the screen."), WMWidgetView(panel
->resF
));
503 panel
->resS
= WMCreateSlider(panel
->resF
);
504 WMResizeWidget(panel
->resS
, 80, 15);
505 WMMoveWidget(panel
->resS
, 10, 20);
506 WMSetSliderMinValue(panel
->resS
, 0);
507 WMSetSliderMaxValue(panel
->resS
, 80);
508 WMSetSliderAction(panel
->resS
, resistanceCallback
, panel
);
510 panel
->resL
= WMCreateLabel(panel
->resF
);
511 WMResizeWidget(panel
->resL
, 30, 15);
512 WMMoveWidget(panel
->resL
, 95, 22);
514 panel
->resaB
= WMCreateRadioButton(panel
->resF
);
515 WMMoveWidget(panel
->resaB
, 130, 15);
516 WMResizeWidget(panel
->resaB
, 70, 27);
517 WMSetButtonText(panel
->resaB
, _("Resist"));
519 panel
->resrB
= WMCreateRadioButton(panel
->resF
);
520 WMMoveWidget(panel
->resrB
, 200, 15);
521 WMResizeWidget(panel
->resrB
, 70, 27);
522 WMSetButtonText(panel
->resrB
, _("Attract"));
523 WMGroupButtons(panel
->resrB
, panel
->resaB
);
525 WMMapSubwidgets(panel
->resF
);
527 /**************** Dragging a Maximized Window ****************/
528 panel
->dragmaxF
= WMCreateFrame(panel
->box
);
529 WMResizeWidget(panel
->dragmaxF
, 289, 46);
530 WMMoveWidget(panel
->dragmaxF
, 8, 179);
531 WMSetFrameTitle(panel
->dragmaxF
, _("When dragging a maximized window..."));
533 panel
->dragmaxP
= WMCreatePopUpButton(panel
->dragmaxF
);
534 WMResizeWidget(panel
->dragmaxP
, 269, 20);
535 WMMoveWidget(panel
->dragmaxP
, 10, 20);
536 WMAddPopUpButtonItem(panel
->dragmaxP
, _("...change position (normal behavior)"));
537 WMAddPopUpButtonItem(panel
->dragmaxP
, _("...restore unmaximized geometry"));
538 WMAddPopUpButtonItem(panel
->dragmaxP
, _("...consider the window unmaximized"));
539 WMAddPopUpButtonItem(panel
->dragmaxP
, _("...do not move the window"));
541 WMMapSubwidgets(panel
->dragmaxF
);
543 WMRealizeWidget(panel
->box
);
544 WMMapSubwidgets(panel
->box
);
546 /* show the config data */
550 static void undo(_Panel
* panel
)
555 Panel
*InitWindowHandling(WMWidget
*parent
)
559 panel
= wmalloc(sizeof(_Panel
));
561 panel
->sectionName
= _("Window Handling Preferences");
563 panel
->description
= _("Window handling options. Initial placement style\n"
564 "edge resistance, opaque move etc.");
566 panel
->parent
= parent
;
568 panel
->callbacks
.createWidgets
= createPanel
;
569 panel
->callbacks
.updateDomain
= storeData
;
570 panel
->callbacks
.undoChanges
= undo
;
572 AddSection(panel
, ICON_FILE
);