1 /* WindowHandling.c- options for handling windows
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1998 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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
26 typedef struct _Panel
{
33 CallbackRec callbacks
;
65 #define ICON_FILE "whandling"
67 #define OPAQUE_MOVE_PIXMAP "opaque"
69 #define NON_OPAQUE_MOVE_PIXMAP "nonopaque"
75 static char *placements
[] = {
85 sliderCallback(WMWidget
*w
, void *data
)
87 _Panel
*panel
= (_Panel
*)data
;
90 int swidth
= WMGetSliderMaxValue(panel
->hsli
);
91 int sheight
= WMGetSliderMaxValue(panel
->vsli
);
93 x
= WMGetSliderValue(panel
->hsli
);
94 y
= WMGetSliderValue(panel
->vsli
);
96 rx
= x
*(WMWidgetWidth(panel
->porigF
)-3)/swidth
+2;
97 ry
= y
*(WMWidgetHeight(panel
->porigF
)-3)/sheight
+2;
98 WMMoveWidget(panel
->porigW
, rx
, ry
);
100 sprintf(buffer
, "(%i,%i)", x
, y
);
101 WMSetLabelText(panel
->porigvL
, buffer
);
107 resistanceCallback(WMWidget
*w
, void *data
)
109 _Panel
*panel
= (_Panel
*)data
;
113 i
= WMGetSliderValue(panel
->resS
);
116 WMSetLabelText(panel
->resL
, "OFF");
118 sprintf(buffer
, "%i", i
);
119 WMSetLabelText(panel
->resL
, buffer
);
125 getPlacement(char *str
)
130 if (strcasecmp(str
, "auto")==0)
132 else if (strcasecmp(str
, "random")==0)
134 else if (strcasecmp(str
, "manual")==0)
136 else if (strcasecmp(str
, "cascade")==0)
138 else if (strcasecmp(str
, "smart")==0)
141 wwarning(_("bad option value %s in WindowPlacement. Using default value"),
148 showData(_Panel
*panel
)
154 str
= GetStringForKey("WindowPlacement");
156 WMSetPopUpButtonSelectedItem(panel
->placP
, getPlacement(str
));
158 arr
= GetObjectForKey("WindowPlaceOrigin");
162 if (arr
&& (!PLIsArray(arr
) || PLGetNumberOfElements(arr
)!=2)) {
163 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
166 x
= atoi(PLGetString(PLGetArrayElement(arr
, 0)));
167 y
= atoi(PLGetString(PLGetArrayElement(arr
, 1)));
171 WMSetSliderValue(panel
->hsli
, x
);
172 WMSetSliderValue(panel
->vsli
, y
);
174 sliderCallback(NULL
, panel
);
176 x
= GetIntegerForKey("EdgeResistance");
177 WMSetSliderValue(panel
->resS
, x
);
178 resistanceCallback(NULL
, panel
);
180 WMSetButtonSelected(panel
->tranB
, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
182 WMSetButtonSelected(panel
->opaqB
, GetBoolForKey("OpaqueMove"));
184 WMSetButtonSelected(panel
->miconB
, GetBoolForKey("NoWindowOverIcons"));
186 WMSetButtonSelected(panel
->mdockB
, GetBoolForKey("NoWindowOverDock"));
188 if (GetBoolForKey("Attraction"))
189 WMPerformButtonClick(panel
->resrB
);
191 WMPerformButtonClick(panel
->resaB
);
196 storeData(_Panel
*panel
)
201 SetBoolForKey(WMGetButtonSelected(panel
->miconB
), "NoWindowOverIcons");
202 SetBoolForKey(WMGetButtonSelected(panel
->mdockB
), "NoWindowOverDock");
203 SetBoolForKey(WMGetButtonSelected(panel
->opaqB
), "OpaqueMove");
204 SetBoolForKey(WMGetButtonSelected(panel
->tranB
), "OpenTransientOnOwnerWorkspace");
205 SetStringForKey(placements
[WMGetPopUpButtonSelectedItem(panel
->placP
)],
207 sprintf(x
, "%i", WMGetSliderValue(panel
->hsli
));
208 sprintf(y
, "%i", WMGetSliderValue(panel
->vsli
));
209 arr
= PLMakeArrayFromElements(PLMakeString(x
), PLMakeString(y
), NULL
);
210 SetObjectForKey(arr
, "WindowPlaceOrigin");
211 SetIntegerForKey(WMGetSliderValue(panel
->resS
), "EdgeResistance");
212 SetBoolForKey(WMGetButtonSelected(panel
->resrB
), "Attraction");
218 createPanel(Panel
*p
)
220 _Panel
*panel
= (Panel
*)p
;
221 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
228 panel
->frame
= WMCreateFrame(panel
->win
);
229 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
230 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
232 /************** Window Placement ***************/
233 panel
->placF
= WMCreateFrame(panel
->frame
);
234 WMResizeWidget(panel
->placF
, 270, 110);
235 WMMoveWidget(panel
->placF
, 20, 10);
236 WMSetFrameTitle(panel
->placF
, _("Window Placement"));
237 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
238 "on screen."), WMWidgetView(panel
->placF
));
240 panel
->placP
= WMCreatePopUpButton(panel
->placF
);
241 WMResizeWidget(panel
->placP
, 105, 20);
242 WMMoveWidget(panel
->placP
, 15, 20);
243 WMAddPopUpButtonItem(panel
->placP
, _("Automatic"));
244 WMAddPopUpButtonItem(panel
->placP
, _("Random"));
245 WMAddPopUpButtonItem(panel
->placP
, _("Manual"));
246 WMAddPopUpButtonItem(panel
->placP
, _("Cascade"));
247 WMAddPopUpButtonItem(panel
->placP
, _("Smart"));
249 panel
->porigL
= WMCreateLabel(panel
->placF
);
250 WMResizeWidget(panel
->porigL
, 120, 32);
251 WMMoveWidget(panel
->porigL
, 5, 45);
252 WMSetLabelTextAlignment(panel
->porigL
, WACenter
);
253 WMSetLabelText(panel
->porigL
, _("Placement Origin"));
255 panel
->porigvL
= WMCreateLabel(panel
->placF
);
256 WMResizeWidget(panel
->porigvL
, 80, 20);
257 WMMoveWidget(panel
->porigvL
, 30, 75);
258 WMSetLabelTextAlignment(panel
->porigvL
, WACenter
);
260 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
261 panel
->porigF
= WMCreateFrame(panel
->placF
);
262 WMSetWidgetBackgroundColor(panel
->porigF
, color
);
263 WMReleaseColor(color
);
264 WMSetFrameRelief(panel
->porigF
, WRSunken
);
266 swidth
= WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
267 sheight
= HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
269 if (sheight
> swidth
) {
271 width
= 70*swidth
/sheight
;
274 height
= 115*sheight
/swidth
;
277 height
= 115*sheight
/swidth
;
280 width
= 70*swidth
/sheight
;
282 WMResizeWidget(panel
->porigF
, width
, height
);
283 WMMoveWidget(panel
->porigF
, 130+(115-width
)/2, 20+(70-height
)/2);
285 panel
->porigW
= WMCreateLabel(panel
->porigF
);
286 WMResizeWidget(panel
->porigW
, THUMB_SIZE
, THUMB_SIZE
);
287 WMMoveWidget(panel
->porigW
, 2, 2);
288 WMSetLabelRelief(panel
->porigW
, WRRaised
);
291 panel
->hsli
= WMCreateSlider(panel
->placF
);
292 WMResizeWidget(panel
->hsli
, width
, 12);
293 WMMoveWidget(panel
->hsli
, 130+(115-width
)/2, 20+(70-height
)/2+height
+2);
294 WMSetSliderAction(panel
->hsli
, sliderCallback
, panel
);
295 WMSetSliderMinValue(panel
->hsli
, 0);
296 WMSetSliderMaxValue(panel
->hsli
, swidth
);
298 panel
->vsli
= WMCreateSlider(panel
->placF
);
299 WMResizeWidget(panel
->vsli
, 12, height
);
300 WMMoveWidget(panel
->vsli
, 130+(115-width
)/2+width
+2, 20+(70-height
)/2);
301 WMSetSliderAction(panel
->vsli
, sliderCallback
, panel
);
302 WMSetSliderMinValue(panel
->vsli
, 0);
303 WMSetSliderMaxValue(panel
->vsli
, sheight
);
305 WMMapSubwidgets(panel
->porigF
);
307 WMMapSubwidgets(panel
->placF
);
309 /************** Opaque Move ***************/
310 panel
->opaqF
= WMCreateFrame(panel
->frame
);
311 WMResizeWidget(panel
->opaqF
, 205, 110);
312 WMMoveWidget(panel
->opaqF
, 300, 10);
313 WMSetFrameTitle(panel
->opaqF
, _("Opaque Move"));
314 WMSetBalloonTextForView(_("Whether the window contents should be moved\n"
315 "when dragging windows aroung or if only a\n"
316 "frame should be displayed.\n"),
317 WMWidgetView(panel
->opaqF
));
319 panel
->opaqB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
320 WMResizeWidget(panel
->opaqB
, 64, 64);
321 WMMoveWidget(panel
->opaqB
, 70, 25);
322 WMSetButtonImagePosition(panel
->opaqB
, WIPImageOnly
);
324 path
= LocateImage(NON_OPAQUE_MOVE_PIXMAP
);
326 pixmap
= WMCreatePixmapFromFile(scr
, path
);
328 WMSetButtonImage(panel
->opaqB
, pixmap
);
329 WMReleasePixmap(pixmap
);
331 wwarning(_("could not load icon %s"), path
);
336 path
= LocateImage(OPAQUE_MOVE_PIXMAP
);
338 pixmap
= WMCreatePixmapFromFile(scr
, path
);
340 WMSetButtonAltImage(panel
->opaqB
, pixmap
);
341 WMReleasePixmap(pixmap
);
343 wwarning(_("could not load icon %s"), path
);
347 WMMapSubwidgets(panel
->opaqF
);
349 /**************** Account for Icon/Dock ***************/
350 panel
->maxiF
= WMCreateFrame(panel
->frame
);
351 WMResizeWidget(panel
->maxiF
, 205, 95);
352 WMMoveWidget(panel
->maxiF
, 300, 125);
353 WMSetFrameTitle(panel
->maxiF
, _("When maximizing..."));
355 panel
->miconB
= WMCreateSwitchButton(panel
->maxiF
);
356 WMResizeWidget(panel
->miconB
, 185, 30);
357 WMMoveWidget(panel
->miconB
, 10, 18);
358 WMSetButtonText(panel
->miconB
, _("...do not cover icons"));
360 panel
->mdockB
= WMCreateSwitchButton(panel
->maxiF
);
361 WMResizeWidget(panel
->mdockB
, 185, 30);
362 WMMoveWidget(panel
->mdockB
, 10, 53);
364 WMSetButtonText(panel
->mdockB
, _("...do not cover dock"));
366 WMMapSubwidgets(panel
->maxiF
);
368 /**************** Edge Resistance ****************/
370 panel
->resF
= WMCreateFrame(panel
->frame
);
371 WMResizeWidget(panel
->resF
, 270, 45);
372 WMMoveWidget(panel
->resF
, 20, 125);
373 WMSetFrameTitle(panel
->resF
, _("Edge Resistance"));
375 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
376 "being moved further for the defined threshold\n"
377 "when moved against other windows or the edges\n"
378 "of the screen."), WMWidgetView(panel
->resF
));
380 panel
->resS
= WMCreateSlider(panel
->resF
);
381 WMResizeWidget(panel
->resS
, 80, 15);
382 WMMoveWidget(panel
->resS
, 10, 20);
383 WMSetSliderMinValue(panel
->resS
, 0);
384 WMSetSliderMaxValue(panel
->resS
, 80);
385 WMSetSliderAction(panel
->resS
, resistanceCallback
, panel
);
387 panel
->resL
= WMCreateLabel(panel
->resF
);
388 WMResizeWidget(panel
->resL
, 30, 15);
389 WMMoveWidget(panel
->resL
, 95, 20);
391 panel
->resaB
= WMCreateRadioButton(panel
->resF
);
392 WMMoveWidget(panel
->resaB
, 130, 12);
393 WMResizeWidget(panel
->resaB
, 70, 30);
394 WMSetButtonText(panel
->resaB
, _("Resist"));
396 panel
->resrB
= WMCreateRadioButton(panel
->resF
);
397 WMMoveWidget(panel
->resrB
, 200, 12);
398 WMResizeWidget(panel
->resrB
, 65, 30);
399 WMSetButtonText(panel
->resrB
, _("Attract"));
400 WMGroupButtons(panel
->resrB
, panel
->resaB
);
404 WMMapSubwidgets(panel
->resF
);
406 /**************** Transients on Parent Workspace ****************/
408 panel
->tranF
= WMCreateFrame(panel
->frame
);
409 WMResizeWidget(panel
->tranF
, 270, 40);
410 WMMoveWidget(panel
->tranF
, 20, 180);
412 panel
->tranB
= WMCreateSwitchButton(panel
->tranF
);
413 WMMoveWidget(panel
->tranB
, 10, 5);
414 WMResizeWidget(panel
->tranB
, 250, 30);
415 WMSetButtonText(panel
->tranB
, _("Open dialogs in same workspace as their owners"));
417 WMMapSubwidgets(panel
->tranF
);
419 WMRealizeWidget(panel
->frame
);
420 WMMapSubwidgets(panel
->frame
);
422 /* show the config data */
435 InitWindowHandling(WMScreen
*scr
, WMWindow
*win
)
439 panel
= wmalloc(sizeof(_Panel
));
440 memset(panel
, 0, sizeof(_Panel
));
442 panel
->sectionName
= _("Window Handling Preferences");
444 panel
->description
= _("Window handling options. Initial placement style\n"
445 "edge resistance, opaque move etc.");
449 panel
->callbacks
.createWidgets
= createPanel
;
450 panel
->callbacks
.updateDomain
= storeData
;
451 panel
->callbacks
.undoChanges
= undo
;
453 AddSection(panel
, ICON_FILE
);