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
{
31 CallbackRec callbacks
;
56 #define ICON_FILE "whandling"
58 #define OPAQUE_MOVE_PIXMAP "opaque"
60 #define NON_OPAQUE_MOVE_PIXMAP "nonopaque"
66 static char *placements
[] = {
75 sliderCallback(WMWidget
*w
, void *data
)
77 _Panel
*panel
= (_Panel
*)data
;
80 int swidth
= WMGetSliderMaxValue(panel
->hsli
);
81 int sheight
= WMGetSliderMaxValue(panel
->vsli
);
83 x
= WMGetSliderValue(panel
->hsli
);
84 y
= WMGetSliderValue(panel
->vsli
);
86 rx
= x
*(WMWidgetWidth(panel
->porigF
)-3)/swidth
+2;
87 ry
= y
*(WMWidgetHeight(panel
->porigF
)-3)/sheight
+2;
88 WMMoveWidget(panel
->porigW
, rx
, ry
);
90 sprintf(buffer
, "(%i,%i)", x
, y
);
91 WMSetLabelText(panel
->porigvL
, buffer
);
96 getPlacement(char *str
)
98 if (strcasecmp(str
, "auto")==0 || strcasecmp(str
, "smart")==0)
100 else if (strcasecmp(str
, "random")==0)
102 else if (strcasecmp(str
, "manual")==0)
104 else if (strcasecmp(str
, "cascade")==0)
107 wwarning(_("bad option value %s in WindowPlacement. Using default value"),
114 showData(_Panel
*panel
)
120 str
= GetStringForKey("WindowPlacement");
122 WMSetPopUpButtonSelectedItem(panel
->placP
, getPlacement(str
));
124 arr
= GetObjectForKey("WindowPlaceOrigin");
128 if (arr
&& (!PLIsArray(arr
) || PLGetNumberOfElements(arr
)!=2)) {
129 wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
132 x
= atoi(PLGetString(PLGetArrayElement(arr
, 0)));
133 y
= atoi(PLGetString(PLGetArrayElement(arr
, 1)));
137 WMSetSliderValue(panel
->hsli
, x
);
138 WMSetSliderValue(panel
->vsli
, y
);
140 sliderCallback(NULL
, panel
);
142 WMSetButtonSelected(panel
->tranB
, GetBoolForKey("OnTopTransients"));
144 WMSetButtonSelected(panel
->opaqB
, GetBoolForKey("OpaqueMove"));
146 WMSetButtonSelected(panel
->miconB
, GetBoolForKey("NoWindowOverIcons"));
151 storeData(_Panel
*panel
)
156 SetBoolForKey(WMGetButtonSelected(panel
->miconB
), "NoWindowOverIcons");
157 SetBoolForKey(WMGetButtonSelected(panel
->opaqB
), "OpaqueMove");
158 SetBoolForKey(WMGetButtonSelected(panel
->tranB
), "OnTopTransients");
159 SetStringForKey(placements
[WMGetPopUpButtonSelectedItem(panel
->placP
)],
161 sprintf(x
, "%i", WMGetSliderValue(panel
->hsli
));
162 sprintf(y
, "%i", WMGetSliderValue(panel
->vsli
));
163 arr
= PLMakeArrayFromElements(PLMakeString(x
), PLMakeString(y
), NULL
);
164 SetObjectForKey(arr
, "WindowPlaceOrigin");
170 createPanel(Panel
*p
)
172 _Panel
*panel
= (Panel
*)p
;
173 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
180 panel
->frame
= WMCreateFrame(panel
->win
);
181 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
182 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
184 /************** Window Placement ***************/
185 panel
->placF
= WMCreateFrame(panel
->frame
);
186 WMResizeWidget(panel
->placF
, 270, 150);
187 WMMoveWidget(panel
->placF
, 20, 15);
188 WMSetFrameTitle(panel
->placF
, _("Window Placement"));
190 panel
->placP
= WMCreatePopUpButton(panel
->placF
);
191 WMResizeWidget(panel
->placP
, 195, 20);
192 WMMoveWidget(panel
->placP
, 35, 20);
193 WMAddPopUpButtonItem(panel
->placP
, _("Automatic"));
194 WMAddPopUpButtonItem(panel
->placP
, _("Random"));
195 WMAddPopUpButtonItem(panel
->placP
, _("Manual"));
196 WMAddPopUpButtonItem(panel
->placP
, _("Cascade"));
198 panel
->porigL
= WMCreateLabel(panel
->placF
);
199 WMResizeWidget(panel
->porigL
, 118, 32);
200 WMMoveWidget(panel
->porigL
, 5, 60);
201 WMSetLabelTextAlignment(panel
->porigL
, WACenter
);
202 WMSetLabelText(panel
->porigL
, _("Placement Origin"));
204 panel
->porigvL
= WMCreateLabel(panel
->placF
);
205 WMResizeWidget(panel
->porigvL
, 70, 20);
206 WMMoveWidget(panel
->porigvL
, 25, 95);
207 WMSetLabelTextAlignment(panel
->porigvL
, WACenter
);
209 color
= WMCreateRGBColor(scr
, 0x5100, 0x5100, 0x7100, True
);
210 panel
->porigF
= WMCreateFrame(panel
->placF
);
211 WMSetWidgetBackgroundColor(panel
->porigF
, color
);
212 WMReleaseColor(color
);
213 WMSetFrameRelief(panel
->porigF
, WRSunken
);
215 swidth
= WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
216 sheight
= HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
218 if (120*sheight
/swidth
< 80*swidth
/sheight
) {
219 width
= 80*swidth
/sheight
;
222 height
= 120*sheight
/swidth
;
225 WMResizeWidget(panel
->porigF
, width
, height
);
226 WMMoveWidget(panel
->porigF
, 125+(120-width
)/2, 45+(80-height
)/2);
228 panel
->porigW
= WMCreateLabel(panel
->porigF
);
229 WMResizeWidget(panel
->porigW
, THUMB_SIZE
, THUMB_SIZE
);
230 WMMoveWidget(panel
->porigW
, 2, 2);
231 WMSetLabelRelief(panel
->porigW
, WRRaised
);
234 panel
->hsli
= WMCreateSlider(panel
->placF
);
235 WMResizeWidget(panel
->hsli
, width
, 12);
236 WMMoveWidget(panel
->hsli
, 125+(120-width
)/2, 45+(80-height
)/2+height
+2);
237 WMSetSliderAction(panel
->hsli
, sliderCallback
, panel
);
238 WMSetSliderMinValue(panel
->hsli
, 0);
239 WMSetSliderMaxValue(panel
->hsli
, swidth
);
241 panel
->vsli
= WMCreateSlider(panel
->placF
);
242 WMResizeWidget(panel
->vsli
, 12, height
);
243 WMMoveWidget(panel
->vsli
, 125+(120-width
)/2+width
+2, 45+(80-height
)/2);
244 WMSetSliderAction(panel
->vsli
, sliderCallback
, panel
);
245 WMSetSliderMinValue(panel
->vsli
, 0);
246 WMSetSliderMaxValue(panel
->vsli
, sheight
);
248 WMMapSubwidgets(panel
->porigF
);
250 WMMapSubwidgets(panel
->placF
);
252 /************** Opaque Move ***************/
253 panel
->opaqF
= WMCreateFrame(panel
->frame
);
254 WMMoveWidget(panel
->opaqF
, 300, 15);
255 WMResizeWidget(panel
->opaqF
, 205, 125);
256 WMSetFrameTitle(panel
->opaqF
, _("Opaque Move"));
258 panel
->opaqB
= WMCreateButton(panel
->opaqF
, WBTToggle
);
259 WMResizeWidget(panel
->opaqB
, 64, 64);
260 WMMoveWidget(panel
->opaqB
, 70, 35);
261 WMSetButtonImagePosition(panel
->opaqB
, WIPImageOnly
);
263 path
= LocateImage(NON_OPAQUE_MOVE_PIXMAP
);
265 pixmap
= WMCreatePixmapFromFile(scr
, path
);
267 WMSetButtonImage(panel
->opaqB
, pixmap
);
268 WMReleasePixmap(pixmap
);
270 wwarning(_("could not load icon %s"), path
);
275 path
= LocateImage(OPAQUE_MOVE_PIXMAP
);
277 pixmap
= WMCreatePixmapFromFile(scr
, path
);
279 WMSetButtonAltImage(panel
->opaqB
, pixmap
);
280 WMReleasePixmap(pixmap
);
282 wwarning(_("could not load icon %s"), path
);
286 WMMapSubwidgets(panel
->opaqF
);
288 /**************** Account for Icon/Dock ***************/
289 panel
->maxiF
= WMCreateFrame(panel
->frame
);
290 WMResizeWidget(panel
->maxiF
, 205, 70);
291 WMMoveWidget(panel
->maxiF
, 300, 145);
292 WMSetFrameTitle(panel
->maxiF
, _("When maximizing..."));
294 panel
->miconB
= WMCreateSwitchButton(panel
->maxiF
);
295 WMResizeWidget(panel
->miconB
, 185, 35);
296 WMMoveWidget(panel
->miconB
, 10, 20);
297 WMSetButtonText(panel
->miconB
, _("...do not resize over icons"));
299 WMMapSubwidgets(panel
->maxiF
);
301 /**************** Transients On Top ****************/
303 panel
->tranF
= WMCreateFrame(panel
->frame
);
304 WMResizeWidget(panel
->tranF
, 270, 40);
305 WMMoveWidget(panel
->tranF
, 20, 175);
307 panel
->tranB
= WMCreateSwitchButton(panel
->tranF
);
308 WMMoveWidget(panel
->tranB
, 10, 10);
309 WMResizeWidget(panel
->tranB
, 235, 20);
310 WMSetButtonText(panel
->tranB
, _("Keep transients above their owners"));
312 WMMapSubwidgets(panel
->tranF
);
314 WMRealizeWidget(panel
->frame
);
315 WMMapSubwidgets(panel
->frame
);
317 /* show the config data */
330 InitWindowHandling(WMScreen
*scr
, WMWindow
*win
)
334 panel
= wmalloc(sizeof(_Panel
));
335 memset(panel
, 0, sizeof(_Panel
));
337 panel
->sectionName
= _("Window Handling Preferences");
341 panel
->callbacks
.createWidgets
= createPanel
;
342 panel
->callbacks
.updateDomain
= storeData
;
343 panel
->callbacks
.undoChanges
= undo
;
345 AddSection(panel
, ICON_FILE
);