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
[] = {
84 sliderCallback(WMWidget
*w
, void *data
)
86 _Panel
*panel
= (_Panel
*)data
;
89 int swidth
= WMGetSliderMaxValue(panel
->hsli
);
90 int sheight
= WMGetSliderMaxValue(panel
->vsli
);
92 x
= WMGetSliderValue(panel
->hsli
);
93 y
= WMGetSliderValue(panel
->vsli
);
95 rx
= x
*(WMWidgetWidth(panel
->porigF
)-3)/swidth
+2;
96 ry
= y
*(WMWidgetHeight(panel
->porigF
)-3)/sheight
+2;
97 WMMoveWidget(panel
->porigW
, rx
, ry
);
99 sprintf(buffer
, "(%i,%i)", x
, y
);
100 WMSetLabelText(panel
->porigvL
, buffer
);
106 resistanceCallback(WMWidget
*w
, void *data
)
108 _Panel
*panel
= (_Panel
*)data
;
112 i
= WMGetSliderValue(panel
->resS
);
115 WMSetLabelText(panel
->resL
, "OFF");
117 sprintf(buffer
, "%i", i
);
118 WMSetLabelText(panel
->resL
, buffer
);
124 getPlacement(char *str
)
129 if (strcasecmp(str
, "auto")==0 || strcasecmp(str
, "smart")==0)
131 else if (strcasecmp(str
, "random")==0)
133 else if (strcasecmp(str
, "manual")==0)
135 else if (strcasecmp(str
, "cascade")==0)
138 wwarning(_("bad option value %s in WindowPlacement. Using default value"),
145 showData(_Panel
*panel
)
151 str
= GetStringForKey("WindowPlacement");
153 WMSetPopUpButtonSelectedItem(panel
->placP
, getPlacement(str
));
155 arr
= GetObjectForKey("WindowPlaceOrigin");
159 if (arr
&& (!PLIsArray(arr
) || PLGetNumberOfElements(arr
)!=2)) {
160 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
163 x
= atoi(PLGetString(PLGetArrayElement(arr
, 0)));
164 y
= atoi(PLGetString(PLGetArrayElement(arr
, 1)));
168 WMSetSliderValue(panel
->hsli
, x
);
169 WMSetSliderValue(panel
->vsli
, y
);
171 sliderCallback(NULL
, panel
);
173 x
= GetIntegerForKey("EdgeResistance");
174 WMSetSliderValue(panel
->resS
, x
);
175 resistanceCallback(NULL
, panel
);
177 WMSetButtonSelected(panel
->tranB
, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
179 WMSetButtonSelected(panel
->opaqB
, GetBoolForKey("OpaqueMove"));
181 WMSetButtonSelected(panel
->miconB
, GetBoolForKey("NoWindowOverIcons"));
183 WMSetButtonSelected(panel
->mdockB
, GetBoolForKey("NoWindowOverDock"));
185 if (GetBoolForKey("Attraction"))
186 WMPerformButtonClick(panel
->resrB
);
188 WMPerformButtonClick(panel
->resaB
);
193 storeData(_Panel
*panel
)
198 SetBoolForKey(WMGetButtonSelected(panel
->miconB
), "NoWindowOverIcons");
199 SetBoolForKey(WMGetButtonSelected(panel
->mdockB
), "NoWindowOverDock");
200 SetBoolForKey(WMGetButtonSelected(panel
->opaqB
), "OpaqueMove");
201 SetBoolForKey(WMGetButtonSelected(panel
->tranB
), "OpenTransientOnOwnerWorkspace");
202 SetStringForKey(placements
[WMGetPopUpButtonSelectedItem(panel
->placP
)],
204 sprintf(x
, "%i", WMGetSliderValue(panel
->hsli
));
205 sprintf(y
, "%i", WMGetSliderValue(panel
->vsli
));
206 arr
= PLMakeArrayFromElements(PLMakeString(x
), PLMakeString(y
), NULL
);
207 SetObjectForKey(arr
, "WindowPlaceOrigin");
208 SetIntegerForKey(WMGetSliderValue(panel
->resS
), "EdgeResistance");
209 SetBoolForKey(WMGetButtonSelected(panel
->resrB
), "Attraction");
215 createPanel(Panel
*p
)
217 _Panel
*panel
= (Panel
*)p
;
218 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
225 panel
->frame
= WMCreateFrame(panel
->win
);
226 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
227 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
229 /************** Window Placement ***************/
230 panel
->placF
= WMCreateFrame(panel
->frame
);
231 WMResizeWidget(panel
->placF
, 270, 110);
232 WMMoveWidget(panel
->placF
, 20, 10);
233 WMSetFrameTitle(panel
->placF
, _("Window Placement"));
234 WMSetBalloonTextForView(_("How to place windows when they are first put\n"
235 "on screen."), WMWidgetView(panel
->placF
));
237 panel
->placP
= WMCreatePopUpButton(panel
->placF
);
238 WMResizeWidget(panel
->placP
, 105, 20);
239 WMMoveWidget(panel
->placP
, 15, 20);
240 WMAddPopUpButtonItem(panel
->placP
, _("Automatic"));
241 WMAddPopUpButtonItem(panel
->placP
, _("Random"));
242 WMAddPopUpButtonItem(panel
->placP
, _("Manual"));
243 WMAddPopUpButtonItem(panel
->placP
, _("Cascade"));
245 panel
->porigL
= WMCreateLabel(panel
->placF
);
246 WMResizeWidget(panel
->porigL
, 120, 32);
247 WMMoveWidget(panel
->porigL
, 5, 45);
248 WMSetLabelTextAlignment(panel
->porigL
, WACenter
);
249 WMSetLabelText(panel
->porigL
, _("Placement Origin"));
251 panel
->porigvL
= WMCreateLabel(panel
->placF
);
252 WMResizeWidget(panel
->porigvL
, 80, 20);
253 WMMoveWidget(panel
->porigvL
, 30, 75);
254 WMSetLabelTextAlignment(panel
->porigvL
, WACenter
);
256 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
257 panel
->porigF
= WMCreateFrame(panel
->placF
);
258 WMSetWidgetBackgroundColor(panel
->porigF
, color
);
259 WMReleaseColor(color
);
260 WMSetFrameRelief(panel
->porigF
, WRSunken
);
262 swidth
= WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
263 sheight
= HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
265 if (sheight
> swidth
) {
267 width
= 70*swidth
/sheight
;
270 height
= 115*sheight
/swidth
;
273 height
= 115*sheight
/swidth
;
276 width
= 70*swidth
/sheight
;
278 WMResizeWidget(panel
->porigF
, width
, height
);
279 WMMoveWidget(panel
->porigF
, 130+(115-width
)/2, 20+(70-height
)/2);
281 panel
->porigW
= WMCreateLabel(panel
->porigF
);
282 WMResizeWidget(panel
->porigW
, THUMB_SIZE
, THUMB_SIZE
);
283 WMMoveWidget(panel
->porigW
, 2, 2);
284 WMSetLabelRelief(panel
->porigW
, WRRaised
);
287 panel
->hsli
= WMCreateSlider(panel
->placF
);
288 WMResizeWidget(panel
->hsli
, width
, 12);
289 WMMoveWidget(panel
->hsli
, 130+(115-width
)/2, 20+(70-height
)/2+height
+2);
290 WMSetSliderAction(panel
->hsli
, sliderCallback
, panel
);
291 WMSetSliderMinValue(panel
->hsli
, 0);
292 WMSetSliderMaxValue(panel
->hsli
, swidth
);
294 panel
->vsli
= WMCreateSlider(panel
->placF
);
295 WMResizeWidget(panel
->vsli
, 12, height
);
296 WMMoveWidget(panel
->vsli
, 130+(115-width
)/2+width
+2, 20+(70-height
)/2);
297 WMSetSliderAction(panel
->vsli
, sliderCallback
, panel
);
298 WMSetSliderMinValue(panel
->vsli
, 0);
299 WMSetSliderMaxValue(panel
->vsli
, sheight
);
301 WMMapSubwidgets(panel
->porigF
);
303 WMMapSubwidgets(panel
->placF
);
305 /************** Opaque Move ***************/
306 panel
->opaqF
= WMCreateFrame(panel
->frame
);
307 WMResizeWidget(panel
->opaqF
, 205, 110);
308 WMMoveWidget(panel
->opaqF
, 300, 10);
309 WMSetFrameTitle(panel
->opaqF
, _("Opaque Move"));
310 WMSetBalloonTextForView(_("Whether the window contents should be moved\n"
311 "when dragging windows aroung or if only a\n"
312 "frame should be displayed.\n"),
313 WMWidgetView(panel
->opaqF
));
315 panel
->opaqB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
316 WMResizeWidget(panel
->opaqB
, 64, 64);
317 WMMoveWidget(panel
->opaqB
, 70, 25);
318 WMSetButtonImagePosition(panel
->opaqB
, WIPImageOnly
);
320 path
= LocateImage(NON_OPAQUE_MOVE_PIXMAP
);
322 pixmap
= WMCreatePixmapFromFile(scr
, path
);
324 WMSetButtonImage(panel
->opaqB
, pixmap
);
325 WMReleasePixmap(pixmap
);
327 wwarning(_("could not load icon %s"), path
);
332 path
= LocateImage(OPAQUE_MOVE_PIXMAP
);
334 pixmap
= WMCreatePixmapFromFile(scr
, path
);
336 WMSetButtonAltImage(panel
->opaqB
, pixmap
);
337 WMReleasePixmap(pixmap
);
339 wwarning(_("could not load icon %s"), path
);
343 WMMapSubwidgets(panel
->opaqF
);
345 /**************** Account for Icon/Dock ***************/
346 panel
->maxiF
= WMCreateFrame(panel
->frame
);
347 WMResizeWidget(panel
->maxiF
, 205, 95);
348 WMMoveWidget(panel
->maxiF
, 300, 125);
349 WMSetFrameTitle(panel
->maxiF
, _("When maximizing..."));
351 panel
->miconB
= WMCreateSwitchButton(panel
->maxiF
);
352 WMResizeWidget(panel
->miconB
, 185, 30);
353 WMMoveWidget(panel
->miconB
, 10, 18);
354 WMSetButtonText(panel
->miconB
, _("...do not cover icons"));
356 panel
->mdockB
= WMCreateSwitchButton(panel
->maxiF
);
357 WMResizeWidget(panel
->mdockB
, 185, 30);
358 WMMoveWidget(panel
->mdockB
, 10, 53);
360 WMSetButtonText(panel
->mdockB
, _("...do not cover dock"));
362 WMMapSubwidgets(panel
->maxiF
);
364 /**************** Edge Resistance ****************/
366 panel
->resF
= WMCreateFrame(panel
->frame
);
367 WMResizeWidget(panel
->resF
, 270, 45);
368 WMMoveWidget(panel
->resF
, 20, 125);
369 WMSetFrameTitle(panel
->resF
, _("Edge Resistance"));
371 WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
372 "being moved further for the defined threshold\n"
373 "when moved against other windows or the edges\n"
374 "of the screen."), WMWidgetView(panel
->resF
));
376 panel
->resS
= WMCreateSlider(panel
->resF
);
377 WMResizeWidget(panel
->resS
, 80, 15);
378 WMMoveWidget(panel
->resS
, 10, 20);
379 WMSetSliderMinValue(panel
->resS
, 0);
380 WMSetSliderMaxValue(panel
->resS
, 80);
381 WMSetSliderAction(panel
->resS
, resistanceCallback
, panel
);
383 panel
->resL
= WMCreateLabel(panel
->resF
);
384 WMResizeWidget(panel
->resL
, 30, 15);
385 WMMoveWidget(panel
->resL
, 95, 20);
387 panel
->resaB
= WMCreateRadioButton(panel
->resF
);
388 WMMoveWidget(panel
->resaB
, 130, 12);
389 WMResizeWidget(panel
->resaB
, 70, 30);
390 WMSetButtonText(panel
->resaB
, _("Resist"));
392 panel
->resrB
= WMCreateRadioButton(panel
->resF
);
393 WMMoveWidget(panel
->resrB
, 200, 12);
394 WMResizeWidget(panel
->resrB
, 65, 30);
395 WMSetButtonText(panel
->resrB
, _("Attract"));
396 WMGroupButtons(panel
->resrB
, panel
->resaB
);
400 WMMapSubwidgets(panel
->resF
);
402 /**************** Transients on Parent Workspace ****************/
404 panel
->tranF
= WMCreateFrame(panel
->frame
);
405 WMResizeWidget(panel
->tranF
, 270, 40);
406 WMMoveWidget(panel
->tranF
, 20, 180);
408 panel
->tranB
= WMCreateSwitchButton(panel
->tranF
);
409 WMMoveWidget(panel
->tranB
, 10, 5);
410 WMResizeWidget(panel
->tranB
, 250, 30);
411 WMSetButtonText(panel
->tranB
, _("Open dialogs in same workspace as their owners"));
413 WMMapSubwidgets(panel
->tranF
);
415 WMRealizeWidget(panel
->frame
);
416 WMMapSubwidgets(panel
->frame
);
418 /* show the config data */
431 InitWindowHandling(WMScreen
*scr
, WMWindow
*win
)
435 panel
= wmalloc(sizeof(_Panel
));
436 memset(panel
, 0, sizeof(_Panel
));
438 panel
->sectionName
= _("Window Handling Preferences");
440 panel
->description
= _("Window handling options. Initial placement style\n"
441 "edge resistance, opaque move etc.");
445 panel
->callbacks
.createWidgets
= createPanel
;
446 panel
->callbacks
.updateDomain
= storeData
;
447 panel
->callbacks
.undoChanges
= undo
;
449 AddSection(panel
, ICON_FILE
);