1 /* Icons.c- icon preferences
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.
28 } icon_animation
[] = {
29 { "zoom", N_("Shrinking/Zooming") },
30 { "twist", N_("Spinning/Twisting") },
31 { "flip", N_("3D-flipping") },
32 { "none", N_("None") }
36 * The code is using a convenient trick to make the link between the icon
37 * position and its representing number:
38 * bit[0] tell if the icon are arranged horizontally or vertically
39 * bit[2:1] tell the corner to which they are starting from:
40 * bit[2] is for Top or Bottom choice
41 * bit[1] is for Left or Right choice
43 static const char icon_position_dbvalue
[][4] = {
54 typedef struct _Panel
{
61 CallbackRec callbacks
;
73 WMButton
*posB
[wlengthof_nocheck(icon_position_dbvalue
)];
76 WMButton
*animB
[wlengthof_nocheck(icon_animation
)];
96 * Minimum size for a Mini-Preview:
97 * This value is actually twice the size of the minimum icon size choosable.
98 * We set the slider min to taht number minus one, because when set to this
99 * value WPrefs will consider that the user wants the feature turned off.
101 static const int minipreview_minimum_size
= 2 * 24 - 1;
103 static const int minipreview_maximum_size
= 512; /* Arbitrary limit for the slider */
105 #define ICON_FILE "iconprefs"
107 static void showIconLayout(WMWidget
* widget
, void *data
)
109 _Panel
*panel
= (_Panel
*) data
;
113 for (i
= 0; i
< wlengthof(panel
->posB
); i
++) {
114 if (panel
->posB
[i
] == widget
) {
120 if (panel
->iconPos
& 1) {
127 WMResizeWidget(panel
->posV
, w
, h
);
129 switch (panel
->iconPos
& ~1) {
131 WMMoveWidget(panel
->posV
, 2, 2);
134 WMMoveWidget(panel
->posV
, panel
->icon_position
.width
- 2 - w
, 2);
137 WMMoveWidget(panel
->posV
, 2, panel
->icon_position
.height
- 2 - h
);
140 WMMoveWidget(panel
->posV
, panel
->icon_position
.width
- 2 - w
, panel
->icon_position
.height
- 2 - h
);
145 static void minipreview_slider_changed(WMWidget
*w
, void *data
)
147 _Panel
*panel
= (_Panel
*) data
;
151 /* Parameter is not used, but tell the compiler that it is ok */
154 value
= WMGetSliderValue(panel
->minipreview
.slider
);
156 /* Round the value to a multiple of 8 because it makes the displayed value look better */
159 if (value
<= minipreview_minimum_size
)
160 sprintf(buffer
, _("OFF"));
162 sprintf(buffer
, "%i", value
);
164 WMSetLabelText(panel
->minipreview
.label
, buffer
);
167 static void showData(_Panel
* panel
)
173 WMSetButtonSelected(panel
->arrB
, GetBoolForKey("AutoArrangeIcons"));
174 WMSetButtonSelected(panel
->omnB
, GetBoolForKey("StickyIcons"));
175 WMSetButtonSelected(panel
->sclB
, GetBoolForKey("SingleClickLaunch"));
177 str
= GetStringForKey("IconPosition");
179 for (i
= 0; i
< wlengthof(icon_position_dbvalue
); i
++)
180 if (strcmp(str
, icon_position_dbvalue
[i
]) == 0) {
182 goto found_position_value
;
184 wwarning(_("bad value \"%s\" for option %s, using default \"%s\""),
185 str
, "IconPosition", icon_position_dbvalue
[5]);
188 found_position_value
:
189 WMPerformButtonClick(panel
->posB
[panel
->iconPos
]);
191 i
= GetIntegerForKey("IconSize");
198 WMSetPopUpButtonSelectedItem(panel
->sizeP
, i
);
200 /* Mini-Previews for Icons */
201 b
= GetBoolForKey("MiniwindowApercuBalloons");
203 i
= GetIntegerForKey("ApercuSize");
204 if (i
<= minipreview_minimum_size
)
205 i
= minipreview_minimum_size
;
207 i
= minipreview_minimum_size
;
209 WMSetSliderValue(panel
->minipreview
.slider
, i
);
210 minipreview_slider_changed(panel
->minipreview
.slider
, panel
);
213 str
= GetStringForKey("IconificationStyle");
215 for (i
= 0; i
< wlengthof(icon_animation
); i
++) {
216 if (strcasecmp(str
, icon_animation
[i
].db_value
) == 0) {
217 WMPerformButtonClick(panel
->animB
[i
]);
218 goto found_animation_value
;
221 wwarning(_("animation style \"%s\" is unknown, resetting to \"%s\""),
222 str
, icon_animation
[0].db_value
);
224 /* If we're here, no valid value have been found so we fall-back to the default */
225 WMPerformButtonClick(panel
->animB
[0]);
226 found_animation_value
:
230 static void createPanel(Panel
* p
)
232 _Panel
*panel
= (_Panel
*) p
;
241 panel
->box
= WMCreateBox(panel
->parent
);
242 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
244 /***************** Positioning of Icons *****************/
245 panel
->posF
= WMCreateFrame(panel
->box
);
246 WMResizeWidget(panel
->posF
, 268, 155);
247 WMMoveWidget(panel
->posF
, 12, 6);
248 WMSetFrameTitle(panel
->posF
, _("Icon Positioning"));
251 * There is an available area of 240 x 122, starting at x=14 y=20
252 * We have to keep 14 pixels on each side for the buttons,
253 * and an extra pixel for spacing. We also want the final dimension
254 * to be an even number so we can have the 2 buttons per side of
256 * In this area, we want to have a rectangle with the same aspect
257 * ratio as the screen.
259 scr
= WMWidgetScreen(panel
->parent
);
260 swidth
= WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
261 sheight
= HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr
)));
263 width
= swidth
* (122 - 15 * 2) / sheight
;
264 if (width
<= (240 - 15 * 2)) {
265 height
= 122 - 15 * 2;
267 width
= 240 - 15 * 2;
268 height
= sheight
* (240 - 15 * 2) / swidth
;
271 panel
->icon_position
.width
= width
;
272 panel
->icon_position
.height
= height
;
274 startx
= 14 + (240 - 15 * 2 - width
) / 2;
275 starty
= 20 + (122 - 15 * 2 - height
) / 2;
277 for (i
= 0; i
< wlengthof(icon_position_dbvalue
); i
++) {
280 panel
->posB
[i
] = WMCreateButton(panel
->posF
, WBTOnOff
);
281 WMSetButtonAction(panel
->posB
[i
], showIconLayout
, panel
);
284 WMGroupButtons(panel
->posB
[0], panel
->posB
[i
]);
286 if (i
& 1) { /* 0=Vertical, 1=Horizontal */
293 WMResizeWidget(panel
->posB
[i
], w
, h
);
298 case 0: x
+= 0; y
+= 15; break;
299 case 1: x
+= 15; y
+= 0; break;
300 case 2: x
+= 15 + width
; y
+= 15; break;
301 case 3: x
+= 15 + w
; y
+= 0; break;
302 case 4: x
+= 0; y
+= 15 + h
; break;
303 case 5: x
+= 15; y
+= 15 + height
; break;
304 case 6: x
+= 15 + width
; y
+= 15 + h
; break;
305 case 7: x
+= 15 + w
; y
+= 15 + height
; break;
307 WMMoveWidget(panel
->posB
[i
], x
, y
);
310 color
= WMCreateRGBColor(WMWidgetScreen(panel
->parent
), 0x5100, 0x5100, 0x7100, True
);
311 panel
->posVF
= WMCreateFrame(panel
->posF
);
312 WMResizeWidget(panel
->posVF
, width
, height
);
313 WMMoveWidget(panel
->posVF
, startx
+ 15, starty
+ 15);
314 WMSetFrameRelief(panel
->posVF
, WRSunken
);
315 WMSetWidgetBackgroundColor(panel
->posVF
, color
);
316 WMReleaseColor(color
);
318 panel
->posV
= WMCreateFrame(panel
->posVF
);
319 WMSetFrameRelief(panel
->posV
, WRSimple
);
321 WMMapSubwidgets(panel
->posF
);
323 /***************** Icon Size ****************/
324 panel
->sizeF
= WMCreateFrame(panel
->box
);
325 WMResizeWidget(panel
->sizeF
, 100, 52);
326 WMMoveWidget(panel
->sizeF
, 12, 168);
327 WMSetFrameTitle(panel
->sizeF
, _("Icon Size"));
329 WMSetBalloonTextForView(_("The size of the dock/application icon and miniwindows"),
330 WMWidgetView(panel
->sizeF
));
332 panel
->sizeP
= WMCreatePopUpButton(panel
->sizeF
);
333 WMResizeWidget(panel
->sizeP
, 80, 20);
334 WMMoveWidget(panel
->sizeP
, 10, 19);
335 for (i
= 24; i
<= 96; i
+= 8) {
336 sprintf(buf
, "%ix%i", i
, i
);
337 WMAddPopUpButtonItem(panel
->sizeP
, buf
);
340 WMMapSubwidgets(panel
->sizeF
);
342 /***************** Mini-Previews ****************/
343 panel
->minipreview
.frame
= WMCreateFrame(panel
->box
);
344 WMResizeWidget(panel
->minipreview
.frame
, 156, 52);
345 WMMoveWidget(panel
->minipreview
.frame
, 124, 168);
346 WMSetFrameTitle(panel
->minipreview
.frame
, _("Mini-Previews for Icons"));
348 WMSetBalloonTextForView(_("The Mini-Preview provides a small view of the content of the\n"
349 "window when the mouse is placed over the icon."),
350 WMWidgetView(panel
->minipreview
.frame
));
352 panel
->minipreview
.slider
= WMCreateSlider(panel
->minipreview
.frame
);
353 WMResizeWidget(panel
->minipreview
.slider
, 109, 15);
354 WMMoveWidget(panel
->minipreview
.slider
, 11, 23);
355 WMSetSliderMinValue(panel
->minipreview
.slider
, minipreview_minimum_size
);
356 WMSetSliderMaxValue(panel
->minipreview
.slider
, minipreview_maximum_size
);
357 WMSetSliderAction(panel
->minipreview
.slider
, minipreview_slider_changed
, panel
);
359 panel
->minipreview
.label
= WMCreateLabel(panel
->minipreview
.frame
);
360 WMResizeWidget(panel
->minipreview
.label
, 33, 15);
361 WMMoveWidget(panel
->minipreview
.label
, 120, 23);
362 WMSetLabelText(panel
->minipreview
.label
, _("OFF"));
364 WMMapSubwidgets(panel
->minipreview
.frame
);
366 /***************** Animation ****************/
367 panel
->animF
= WMCreateFrame(panel
->box
);
368 WMResizeWidget(panel
->animF
, 215, 110);
369 WMMoveWidget(panel
->animF
, 292, 6);
370 WMSetFrameTitle(panel
->animF
, _("Iconification Animation"));
372 for (i
= 0; i
< wlengthof(icon_animation
); i
++) {
373 panel
->animB
[i
] = WMCreateRadioButton(panel
->animF
);
374 WMResizeWidget(panel
->animB
[i
], 192, 20);
375 WMMoveWidget(panel
->animB
[i
], 12, 16 + i
* 22);
378 WMGroupButtons(panel
->animB
[0], panel
->animB
[i
]);
380 WMSetButtonText(panel
->animB
[i
], _(icon_animation
[i
].label
));
383 WMMapSubwidgets(panel
->animF
);
385 /***************** Options ****************/
386 panel
->optF
= WMCreateFrame(panel
->box
);
387 WMResizeWidget(panel
->optF
, 215, 90);
388 WMMoveWidget(panel
->optF
, 292, 130);
389 /* WMSetFrameTitle(panel->optF, _("Icon Display")); */
391 panel
->arrB
= WMCreateSwitchButton(panel
->optF
);
392 WMResizeWidget(panel
->arrB
, 198, 20);
393 WMMoveWidget(panel
->arrB
, 12, 10);
394 WMSetButtonText(panel
->arrB
, _("Auto-arrange icons"));
396 WMSetBalloonTextForView(_("Keep icons and miniwindows arranged all the time."), WMWidgetView(panel
->arrB
));
398 panel
->omnB
= WMCreateSwitchButton(panel
->optF
);
399 WMResizeWidget(panel
->omnB
, 198, 20);
400 WMMoveWidget(panel
->omnB
, 12, 35);
401 WMSetButtonText(panel
->omnB
, _("Omnipresent miniwindows"));
403 WMSetBalloonTextForView(_("Make miniwindows be present in all workspaces."), WMWidgetView(panel
->omnB
));
405 panel
->sclB
= WMCreateSwitchButton(panel
->optF
);
406 WMResizeWidget(panel
->sclB
, 198, 28);
407 WMMoveWidget(panel
->sclB
, 12, 56);
408 WMSetButtonText(panel
->sclB
, _("Single click activation"));
410 WMSetBalloonTextForView(_("Launch applications and restore windows with a single click."), WMWidgetView(panel
->sclB
));
412 WMMapSubwidgets(panel
->optF
);
414 WMRealizeWidget(panel
->box
);
415 WMMapSubwidgets(panel
->box
);
420 static void storeData(_Panel
* panel
)
424 SetBoolForKey(WMGetButtonSelected(panel
->arrB
), "AutoArrangeIcons");
425 SetBoolForKey(WMGetButtonSelected(panel
->omnB
), "StickyIcons");
426 SetBoolForKey(WMGetButtonSelected(panel
->sclB
), "SingleClickLaunch");
428 SetIntegerForKey(WMGetPopUpButtonSelectedItem(panel
->sizeP
) * 8 + 24, "IconSize");
430 SetStringForKey(icon_position_dbvalue
[panel
->iconPos
], "IconPosition");
432 i
= WMGetSliderValue(panel
->minipreview
.slider
);
433 if (i
<= minipreview_minimum_size
) {
434 SetBoolForKey(False
, "MiniwindowApercuBalloons");
436 SetBoolForKey(True
, "MiniwindowApercuBalloons");
437 if (i
< minipreview_maximum_size
) {
439 * If the value is bigger, it means it was edited by the user manually
440 * so we keep as-is. Otherwise, we round it to a multiple of 8 like it
441 * was done for display
445 SetIntegerForKey(i
, "ApercuSize");
448 for (i
= 0; i
< wlengthof(icon_animation
); i
++) {
449 if (WMGetButtonSelected(panel
->animB
[i
])) {
450 SetStringForKey(icon_animation
[i
].db_value
, "IconificationStyle");
456 Panel
*InitIcons(WMWidget
*parent
)
460 panel
= wmalloc(sizeof(_Panel
));
462 panel
->sectionName
= _("Icon Preferences");
464 panel
->description
= _("Icon/Miniwindow handling options. Icon positioning\n"
465 "area, sizes of icons, miniaturization animation style.");
467 panel
->parent
= parent
;
469 panel
->callbacks
.createWidgets
= createPanel
;
470 panel
->callbacks
.updateDomain
= storeData
;
472 AddSection(panel
, ICON_FILE
);