1 /* Workspace.c- workspace options
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 2012 Daniel Déchelotte (heavily inspired from file (c) 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
;
35 WMFrame
*autoDelayF
[2];
36 WMLabel
*autoDelayL
[4];
37 WMButton
*autoDelayB
[4][5];
38 WMTextField
*autoDelayT
[4];
39 WMLabel
*autoDelayMsL
[4];
45 #define ICON_FILE "dockclipdrawersection"
47 #define ARQUIVO_XIS "xis"
48 #define DELAY_ICON "timer%i"
49 #define DELAY_ICON_S "timer%is"
55 { "ClipAutoexpandDelay", N_("Before auto-expansion") },
56 { "ClipAutocollapseDelay", N_("Before auto-collapsing") },
57 { "ClipAutoraiseDelay", N_("Before auto-raise") },
58 { "ClipAutolowerDelay", N_("Before auto-lowering") }
62 static char *autoDelayPresetValues
[5] = { "0", "100", "250", "600", "1000" };
65 const char *disable_key
;
66 const char *icon_file
;
68 { "DisableDock", "dock" },
69 { "DisableClip", "clip" },
70 { "DisableDrawers", "drawer" }
73 static void showData(_Panel
*panel
);
74 static void storeData(_Panel
*panel
);
77 static void pushAutoDelayButton(WMWidget
*w
, void *data
)
79 _Panel
*panel
= (_Panel
*) data
;
81 for (i
= 0; i
< 4; i
++)
83 for (j
= 0; j
< 5; j
++)
85 if (w
== panel
->autoDelayB
[i
][j
])
87 WMSetTextFieldText(panel
->autoDelayT
[i
], autoDelayPresetValues
[j
]);
94 static void adjustButtonSelectionBasedOnValue(_Panel
*panel
, int row
, const char *value
)
101 for (j
= 0; j
< 5; j
++)
103 int isThatOne
= !strcmp(autoDelayPresetValues
[j
], value
);
104 WMSetButtonSelected(panel
->autoDelayB
[row
][j
], isThatOne
);
110 static void autoDelayChanged(void *observerData
, WMNotification
*notification
)
112 _Panel
*panel
= (_Panel
*) observerData
;
114 WMTextField
*anAutoDelayT
= (WMTextField
*) WMGetNotificationObject(notification
);
115 for (row
= 0; row
< 4; row
++)
117 if (anAutoDelayT
!= panel
->autoDelayT
[row
])
121 char *value
= WMGetTextFieldText(anAutoDelayT
);
122 adjustButtonSelectionBasedOnValue(panel
, row
, value
);
127 static void pushDockButton(WMWidget
*w
, void *data
)
129 _Panel
*panel
= (_Panel
*) data
;
130 WMButton
*button
= (WMButton
*) w
;
131 if (button
== panel
->docksB
[0] &&
132 !WMGetButtonSelected(panel
->docksB
[0]))
134 WMSetButtonSelected(panel
->docksB
[2], False
);
136 if (button
== panel
->docksB
[2] &&
137 WMGetButtonSelected(panel
->docksB
[2]))
139 WMSetButtonSelected(panel
->docksB
[0], True
);
143 static void createPanel(Panel
*p
)
145 _Panel
*panel
= (_Panel
*) p
;
146 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
147 WMPixmap
*icon1
, *icon2
;
149 RContext
*rc
= WMScreenRContext(scr
);
156 path
= LocateImage(ARQUIVO_XIS
);
158 xis
= RLoadImage(rc
, path
, 0);
160 wwarning(_("could not load image file %s"), path
);
165 panel
->box
= WMCreateBox(panel
->parent
);
166 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
168 /***************** Auto-delays *****************/
169 buf1
= wmalloc(strlen(DELAY_ICON
) + 1);
170 buf2
= wmalloc(strlen(DELAY_ICON_S
) + 1);
172 for (k
= 0; k
< 2; k
++)
174 panel
->autoDelayF
[k
] = WMCreateFrame(panel
->box
);
175 WMResizeWidget(panel
->autoDelayF
[k
], 370, 100);
176 WMMoveWidget(panel
->autoDelayF
[k
], 15, 10 + k
* 110);
178 WMSetFrameTitle(panel
->autoDelayF
[k
], _("Clip autocollapsing delays"));
180 WMSetFrameTitle(panel
->autoDelayF
[k
], _("Clip autoraising delays"));
182 for (i
= 0; i
< 2; i
++)
184 panel
->autoDelayL
[i
+ k
* 2] = WMCreateLabel(panel
->autoDelayF
[k
]);
185 WMResizeWidget(panel
->autoDelayL
[i
+ k
* 2], 155, 20);
186 WMMoveWidget(panel
->autoDelayL
[i
+ k
* 2], 10, 27 + 40 * i
);
187 WMSetLabelText(panel
->autoDelayL
[i
+ k
* 2], _(auto_delay
[i
+ k
* 2].string
));
188 /* WMSetLabelTextAlignment(panel->autoDelayL[i + k * 2], WARight); */
190 for (j
= 0; j
< 5; j
++)
192 panel
->autoDelayB
[i
+ k
* 2][j
] = WMCreateCustomButton(panel
->autoDelayF
[k
], WBBStateChangeMask
);
193 WMResizeWidget(panel
->autoDelayB
[i
+ k
* 2][j
], 25, 25);
194 WMMoveWidget(panel
->autoDelayB
[i
+ k
* 2][j
], 145 + (28 * j
), 25 + 40 * i
);
195 WMSetButtonBordered(panel
->autoDelayB
[i
+ k
* 2][j
], False
);
196 WMSetButtonImagePosition(panel
->autoDelayB
[i
+ k
* 2][j
], WIPImageOnly
);
197 WMSetButtonAction(panel
->autoDelayB
[i
+ k
* 2][j
], pushAutoDelayButton
, panel
);
199 WMGroupButtons(panel
->autoDelayB
[i
+ k
* 2][0], panel
->autoDelayB
[i
+ k
* 2][j
]);
200 sprintf(buf1
, DELAY_ICON
, j
);
201 CreateImages(scr
, rc
, NULL
, buf1
, &icon1
, NULL
);
203 WMSetButtonImage(panel
->autoDelayB
[i
+ k
* 2][j
], icon1
);
204 WMReleasePixmap(icon1
);
206 wwarning(_("could not load icon file %s"), buf1
);
208 sprintf(buf2
, DELAY_ICON_S
, j
);
209 CreateImages(scr
, rc
, NULL
, buf2
, &icon2
, NULL
);
211 WMSetButtonAltImage(panel
->autoDelayB
[i
+ k
* 2][j
], icon2
);
212 WMReleasePixmap(icon2
);
214 wwarning(_("could not load icon file %s"), buf2
);
218 panel
->autoDelayT
[i
+ k
* 2] = WMCreateTextField(panel
->autoDelayF
[k
]);
219 WMResizeWidget(panel
->autoDelayT
[i
+ k
* 2], 36, 20);
220 WMMoveWidget(panel
->autoDelayT
[i
+ k
* 2], 287, 27 + 40 * i
);
221 WMAddNotificationObserver(autoDelayChanged
, panel
, WMTextDidChangeNotification
, panel
->autoDelayT
[i
+ k
* 2]);
223 color
= WMDarkGrayColor(scr
);
224 font
= WMSystemFontOfSize(scr
, 10);
225 panel
->autoDelayMsL
[i
+ k
* 2] = WMCreateLabel(panel
->autoDelayF
[k
]);
226 WMResizeWidget(panel
->autoDelayMsL
[i
+ k
* 2], 36, 16);
227 WMMoveWidget(panel
->autoDelayMsL
[i
+ k
* 2], 327, 33 + 40 *i
);
228 WMSetLabelText(panel
->autoDelayMsL
[i
+ k
* 2], _("msec"));
229 WMSetLabelTextColor(panel
->autoDelayMsL
[i
+ k
* 2], color
);
230 WMSetLabelFont(panel
->autoDelayMsL
[i
+ k
* 2], font
);
231 WMReleaseColor(color
);
235 WMMapSubwidgets(panel
->autoDelayF
[k
]);
240 /***************** Enable/disable clip/dock/drawers *****************/
241 panel
->dockF
= WMCreateFrame(panel
->box
);
242 WMResizeWidget(panel
->dockF
, 115, 210);
243 WMMoveWidget(panel
->dockF
, 390, 10);
244 WMSetFrameTitle(panel
->dockF
, _("Dock/Clip/Drawer"));
246 for (i
= 0; i
< 3; i
++)
248 panel
->docksB
[i
] = WMCreateButton(panel
->dockF
, WBTToggle
);
249 WMResizeWidget(panel
->docksB
[i
], 56, 56);
250 WMMoveWidget(panel
->docksB
[i
], 30, 20 + 62 * i
);
251 WMSetButtonImagePosition(panel
->docksB
[i
], WIPImageOnly
);
252 CreateImages(scr
, rc
, xis
, dock_config
[i
].icon_file
, &icon1
, &icon2
);
254 WMSetButtonImage(panel
->docksB
[i
], icon2
);
255 WMReleasePixmap(icon2
);
258 WMSetButtonAltImage(panel
->docksB
[i
], icon1
);
259 WMReleasePixmap(icon1
);
264 WMSetBalloonTextForView(_("Disable/enable the application Dock (the\n"
265 "vertical icon bar in the side of the screen)."), WMWidgetView(panel
->docksB
[i
]));
268 WMSetBalloonTextForView(_("Disable/enable the Clip (that thing with\n"
269 "a paper clip icon)."), WMWidgetView(panel
->docksB
[i
]));
272 WMSetBalloonTextForView(_("Disable/enable Drawers (a dock that stores\n"
273 "application icons horizontally). The dock is required."), WMWidgetView(panel
->docksB
[i
]));
276 WMSetButtonAction(panel
->docksB
[i
], pushDockButton
, panel
);
279 WMMapSubwidgets(panel
->dockF
);
284 WMRealizeWidget(panel
->box
);
285 WMMapSubwidgets(panel
->box
);
290 static void storeData(_Panel
*panel
)
293 for (i
= 0; i
< 4; i
++)
295 SetStringForKey(WMGetTextFieldText(panel
->autoDelayT
[i
]), auto_delay
[i
].key
);
297 for (i
= 0; i
< 3; i
++)
299 SetBoolForKey(!WMGetButtonSelected(panel
->docksB
[i
]), dock_config
[i
].disable_key
);
303 static void showData(_Panel
*panel
)
307 for (i
= 0; i
< 4; i
++)
309 value
= GetStringForKey(auto_delay
[i
].key
);
310 WMSetTextFieldText(panel
->autoDelayT
[i
], value
);
311 adjustButtonSelectionBasedOnValue(panel
, i
, value
);
313 for (i
= 0; i
< 3; i
++)
315 WMSetButtonSelected(panel
->docksB
[i
], !GetBoolForKey(dock_config
[i
].disable_key
));
319 Panel
*InitDocks(WMWidget
*parent
)
323 panel
= wmalloc(sizeof(_Panel
));
324 memset(panel
, 0, sizeof(_Panel
));
326 panel
->sectionName
= _("Dock Preferences");
328 panel
->description
= _("Dock and clip features.\n"
329 "Enable/disable the Dock and Clip, and tune some delays.");
331 panel
->parent
= parent
;
333 panel
->callbacks
.createWidgets
= createPanel
;
334 panel
->callbacks
.updateDomain
= storeData
;
336 AddSection(panel
, ICON_FILE
);