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];
44 #define ICON_FILE "dockclipdrawersection"
46 #define ARQUIVO_XIS "xis"
47 #define DELAY_ICON "timer%i"
48 #define DELAY_ICON_S "timer%is"
50 static char *autoDelayStrings
[4];
51 static char *autoDelayKeys
[4] = { "ClipAutoexpandDelay", "ClipAutocollapseDelay", "ClipAutoraiseDelay", "ClipAutolowerDelay" };
52 static char *autoDelayPresetValues
[5] = { "0", "100", "250", "600", "1000" };
53 static char *dockDisablingKeys
[3] = { "DisableDock", "DisableClip", "DisableDrawers" };
54 static char *dockFiles
[3] = { "dock", "clip", "drawer" };
56 static void showData(_Panel
*panel
);
57 static void storeData(_Panel
*panel
);
60 static void pushAutoDelayButton(WMWidget
*w
, void *data
)
62 _Panel
*panel
= (_Panel
*) data
;
64 for (i
= 0; i
< 4; i
++)
66 for (j
= 0; j
< 5; j
++)
68 if (w
== panel
->autoDelayB
[i
][j
])
70 WMSetTextFieldText(panel
->autoDelayT
[i
], autoDelayPresetValues
[j
]);
77 static void adjustButtonSelectionBasedOnValue(_Panel
*panel
, int row
, char *value
)
84 for (j
= 0; j
< 5; j
++)
86 int isThatOne
= !strcmp(autoDelayPresetValues
[j
], value
);
87 WMSetButtonSelected(panel
->autoDelayB
[row
][j
], isThatOne
);
93 static void autoDelayChanged(void *observerData
, WMNotification
*notification
)
95 _Panel
*panel
= (_Panel
*) observerData
;
97 WMTextField
*anAutoDelayT
= (WMTextField
*) WMGetNotificationObject(notification
);
98 for (row
= 0; row
< 4; row
++)
100 if (anAutoDelayT
!= panel
->autoDelayT
[row
])
104 char *value
= WMGetTextFieldText(anAutoDelayT
);
105 adjustButtonSelectionBasedOnValue(panel
, row
, value
);
110 static void pushDockButton(WMWidget
*w
, void *data
)
112 _Panel
*panel
= (_Panel
*) data
;
113 WMButton
*button
= (WMButton
*) w
;
114 if (button
== panel
->docksB
[0] &&
115 !WMGetButtonSelected(panel
->docksB
[0]))
117 WMSetButtonSelected(panel
->docksB
[2], False
);
119 if (button
== panel
->docksB
[2] &&
120 WMGetButtonSelected(panel
->docksB
[2]))
122 WMSetButtonSelected(panel
->docksB
[0], True
);
126 static void createPanel(Panel
*p
)
128 _Panel
*panel
= (_Panel
*) p
;
129 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
130 WMPixmap
*icon1
, *icon2
;
132 RContext
*rc
= WMScreenRContext(scr
);
137 path
= LocateImage(ARQUIVO_XIS
);
139 xis
= RLoadImage(rc
, path
, 0);
141 wwarning(_("could not load image file %s"), path
);
146 panel
->box
= WMCreateBox(panel
->parent
);
147 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
149 /***************** Auto-delays *****************/
150 buf1
= wmalloc(strlen(DELAY_ICON
) + 1);
151 buf2
= wmalloc(strlen(DELAY_ICON_S
) + 1);
153 for (k
= 0; k
< 2; k
++)
155 panel
->autoDelayF
[k
] = WMCreateFrame(panel
->box
);
156 WMResizeWidget(panel
->autoDelayF
[k
], 365, 100);
157 WMMoveWidget(panel
->autoDelayF
[k
], 15, 10 + k
* 110);
159 WMSetFrameTitle(panel
->autoDelayF
[k
], _("Delays in milliseconds for autocollapsing clips"));
161 WMSetFrameTitle(panel
->autoDelayF
[k
], _("Delays in milliseconds for autoraising clips"));
163 for (i
= 0; i
< 2; i
++)
165 panel
->autoDelayL
[i
+ k
* 2] = WMCreateLabel(panel
->autoDelayF
[k
]);
166 WMResizeWidget(panel
->autoDelayL
[i
+ k
* 2], 165, 20);
167 WMMoveWidget(panel
->autoDelayL
[i
+ k
* 2], 10, 27 + 40 * i
);
168 WMSetLabelText(panel
->autoDelayL
[i
+ k
* 2], autoDelayStrings
[i
+ k
* 2]);
169 WMSetLabelTextAlignment(panel
->autoDelayL
[i
+ k
* 2], WARight
);
171 for (j
= 0; j
< 5; j
++)
173 panel
->autoDelayB
[i
+ k
* 2][j
] = WMCreateCustomButton(panel
->autoDelayF
[k
], WBBStateChangeMask
);
174 WMResizeWidget(panel
->autoDelayB
[i
+ k
* 2][j
], 25, 25);
175 WMMoveWidget(panel
->autoDelayB
[i
+ k
* 2][j
], 175 + (25 * j
), 25 + 40 * i
);
176 WMSetButtonBordered(panel
->autoDelayB
[i
+ k
* 2][j
], False
);
177 WMSetButtonImagePosition(panel
->autoDelayB
[i
+ k
* 2][j
], WIPImageOnly
);
178 WMSetButtonAction(panel
->autoDelayB
[i
+ k
* 2][j
], pushAutoDelayButton
, panel
);
180 WMGroupButtons(panel
->autoDelayB
[i
+ k
* 2][0], panel
->autoDelayB
[i
+ k
* 2][j
]);
181 sprintf(buf1
, DELAY_ICON
, j
);
182 CreateImages(scr
, rc
, NULL
, buf1
, &icon1
, NULL
);
184 WMSetButtonImage(panel
->autoDelayB
[i
+ k
* 2][j
], icon1
);
185 WMReleasePixmap(icon1
);
187 wwarning(_("could not load icon file %s"), buf1
);
189 sprintf(buf2
, DELAY_ICON_S
, j
);
190 CreateImages(scr
, rc
, NULL
, buf2
, &icon2
, NULL
);
192 WMSetButtonAltImage(panel
->autoDelayB
[i
+ k
* 2][j
], icon2
);
193 WMReleasePixmap(icon2
);
195 wwarning(_("could not load icon file %s"), buf2
);
199 panel
->autoDelayT
[i
+ k
* 2] = WMCreateTextField(panel
->autoDelayF
[k
]);
200 WMResizeWidget(panel
->autoDelayT
[i
+ k
* 2], 36, 20);
201 WMMoveWidget(panel
->autoDelayT
[i
+ k
* 2], 310, 27 + 40 * i
);
202 WMAddNotificationObserver(autoDelayChanged
, panel
, WMTextDidChangeNotification
, panel
->autoDelayT
[i
+ k
* 2]);
205 WMMapSubwidgets(panel
->autoDelayF
[k
]);
210 /***************** Enable/disable clip/dock/drawers *****************/
211 panel
->dockF
= WMCreateFrame(panel
->box
);
212 WMResizeWidget(panel
->dockF
, 115, 210);
213 WMMoveWidget(panel
->dockF
, 390, 10);
214 WMSetFrameTitle(panel
->dockF
, _("Dock/Clip/Drawer"));
216 for (i
= 0; i
< 3; i
++)
218 panel
->docksB
[i
] = WMCreateButton(panel
->dockF
, WBTToggle
);
219 WMResizeWidget(panel
->docksB
[i
], 56, 56);
220 WMMoveWidget(panel
->docksB
[i
], 30, 20 + 62 * i
);
221 WMSetButtonImagePosition(panel
->docksB
[i
], WIPImageOnly
);
222 CreateImages(scr
, rc
, xis
, dockFiles
[i
], &icon1
, &icon2
);
224 WMSetButtonImage(panel
->docksB
[i
], icon2
);
225 WMReleasePixmap(icon2
);
228 WMSetButtonAltImage(panel
->docksB
[i
], icon1
);
229 WMReleasePixmap(icon1
);
234 WMSetBalloonTextForView(_("Disable/enable the application Dock (the\n"
235 "vertical icon bar in the side of the screen)."), WMWidgetView(panel
->docksB
[i
]));
238 WMSetBalloonTextForView(_("Disable/enable the Clip (that thing with\n"
239 "a paper clip icon)."), WMWidgetView(panel
->docksB
[i
]));
242 WMSetBalloonTextForView(_("Disable/enable Drawers (a dock that stores\n"
243 "application icons horizontally). The dock is required."), WMWidgetView(panel
->docksB
[i
]));
246 WMSetButtonAction(panel
->docksB
[i
], pushDockButton
, panel
);
249 WMMapSubwidgets(panel
->dockF
);
254 WMRealizeWidget(panel
->box
);
255 WMMapSubwidgets(panel
->box
);
260 static void storeData(_Panel
*panel
)
263 for (i
= 0; i
< 4; i
++)
265 SetStringForKey(WMGetTextFieldText(panel
->autoDelayT
[i
]), autoDelayKeys
[i
]);
267 for (i
= 0; i
< 3; i
++)
269 SetBoolForKey(!WMGetButtonSelected(panel
->docksB
[i
]), dockDisablingKeys
[i
]);
273 static void showData(_Panel
*panel
)
277 for (i
= 0; i
< 4; i
++)
279 value
= GetStringForKey(autoDelayKeys
[i
]);
280 WMSetTextFieldText(panel
->autoDelayT
[i
], value
);
281 adjustButtonSelectionBasedOnValue(panel
, i
, value
);
283 for (i
= 0; i
< 3; i
++)
285 WMSetButtonSelected(panel
->docksB
[i
], !GetBoolForKey(dockDisablingKeys
[i
]));
289 Panel
*InitDocks(WMScreen
*scr
, WMWidget
*parent
)
293 autoDelayStrings
[0] = _("Delay before auto-expansion");
294 autoDelayStrings
[1] = _("Delay before auto-collapsing");
295 autoDelayStrings
[2] = _("Delay before auto-raise");
296 autoDelayStrings
[3] = _("Delay before auto-lowering");
298 panel
= wmalloc(sizeof(_Panel
));
299 memset(panel
, 0, sizeof(_Panel
));
301 panel
->sectionName
= _("Dock Preferences");
303 panel
->description
= _("Dock and clip features.\n"
304 "Enable/disable the Dock and Clip, and tune some delays.");
306 panel
->parent
= parent
;
308 panel
->callbacks
.createWidgets
= createPanel
;
309 panel
->callbacks
.updateDomain
= storeData
;
311 AddSection(panel
, ICON_FILE
);