ChangeLog: Update with commits since v0.95.7.
[wmaker-crm.git] / WPrefs.app / Expert.c
blob561f4e3f7af8350a0a9dc5e160413154dee730dc
1 /* Expert.c- expert user options
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 2014 Window Maker Team
6 * Copyright (c) 1998-2003 Alfredo K. Kojima
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "WPrefs.h"
25 /* This structure containts the list of all the check-buttons to display in the
26 * expert tab of the window with the corresponding information for effect
28 static const struct {
29 const char *label; /* Text displayed to user */
31 int def_state; /* True/False: the default value, if not defined in current config */
33 enum {
34 OPTION_WMAKER,
35 OPTION_WMAKER_ARRAY,
36 OPTION_USERDEF,
37 OPTION_WMAKER_INT
38 } class;
40 const char *op_name; /* The identifier for the option in the config file */
42 } expert_options[] = {
44 { N_("Disable miniwindows (icons for minimized windows). For use with KDE/GNOME."),
45 /* default: */ False, OPTION_WMAKER, "DisableMiniwindows" },
47 { N_("Ignore decoration hints for GTK applications."),
48 /* default: */ False, OPTION_WMAKER, "IgnoreGtkHints" },
50 { N_("Enable workspace pager."),
51 /* default: */ False, OPTION_WMAKER, "EnableWorkspacePager" },
53 { N_("Do not set non-WindowMaker specific parameters (do not use xset)."),
54 /* default: */ False, OPTION_USERDEF, "NoXSetStuff" },
56 { N_("Automatically save session when exiting Window Maker."),
57 /* default: */ False, OPTION_WMAKER, "SaveSessionOnExit" },
59 { N_("Use SaveUnder in window frames, icons, menus and other objects."),
60 /* default: */ False, OPTION_WMAKER, "UseSaveUnders" },
62 { N_("Disable confirmation panel for the Kill command."),
63 /* default: */ False, OPTION_WMAKER, "DontConfirmKill" },
65 { N_("Disable selection animation for selected icons."),
66 /* default: */ False, OPTION_WMAKER, "DisableBlinking" },
68 { N_("Smooth font edges (needs restart)."),
69 /* default: */ True, OPTION_WMAKER, "AntialiasedText" },
71 { N_("Cycle windows only on the active head."),
72 /* default: */ False, OPTION_WMAKER, "CycleActiveHeadOnly" },
74 { N_("Ignore minimized windows when cycling."),
75 /* default: */ False, OPTION_WMAKER, "CycleIgnoreMinimized" },
77 { N_("Show switch panel when cycling windows."),
78 /* default: */ True, OPTION_WMAKER_ARRAY, "SwitchPanelImages" },
80 { N_("Show workspace title on Clip."),
81 /* default: */ True, OPTION_WMAKER, "ShowClipTitle" },
83 { N_("Highlight the icon of the application when it has the focus."),
84 /* default: */ True, OPTION_WMAKER, "HighlightActiveApp" },
86 #ifdef XKB_MODELOCK
87 { N_("Enable keyboard language switch button in window titlebars."),
88 /* default: */ False, OPTION_WMAKER, "KbdModeLock" },
89 #endif /* XKB_MODELOCK */
91 { N_("Maximize (snap) a window to edge or corner by dragging."),
92 /* default: */ False, OPTION_WMAKER, "WindowSnapping" },
94 { N_("Distance from edge to begin window snap."),
95 /* default: */ 1, OPTION_WMAKER_INT, "SnapEdgeDetect" },
97 { N_("Distance from corner to begin window snap."),
98 /* default: */ 10, OPTION_WMAKER_INT, "SnapCornerDetect" },
100 { N_("Snapping a window to the top maximizes it to the full screen."),
101 /* default: */ False, OPTION_WMAKER, "SnapToTopMaximizesFullscreen" },
103 { N_("Allow move half-maximized windows between multiple screens."),
104 /* default: */ False, OPTION_WMAKER, "MoveHalfMaximizedWindowsBetweenScreens" },
106 { N_("Alternative transitions between states for half maximized windows."),
107 /* default: */ False, OPTION_WMAKER, "AlternativeHalfMaximized" },
109 { N_("Move mouse pointer with half maximized windows."),
110 /* default: */ False, OPTION_WMAKER, "PointerWithHalfMaxWindows" },
112 { N_("Open dialogs in the same workspace as their owners."),
113 /* default: */ False, OPTION_WMAKER, "OpenTransientOnOwnerWorkspace" }
119 typedef struct _Panel {
120 WMBox *box;
121 char *sectionName;
123 char *description;
125 CallbackRec callbacks;
127 WMWidget *parent;
129 WMButton *swi[wlengthof_nocheck(expert_options)];
131 WMTextField *textfield[wlengthof_nocheck(expert_options)];
133 } _Panel;
135 #define ICON_FILE "expert"
137 static void changeIntTextfield(void *data, int delta)
139 WMTextField *textfield;
140 char *text;
141 int value;
143 textfield = (WMTextField *)data;
144 text = WMGetTextFieldText(textfield);
145 value = atoi(text);
146 value += delta;
147 sprintf(text, "%d", value);
148 WMSetTextFieldText(textfield, text);
151 static void downButtonCallback(WMWidget *self, void *data)
153 (void) self;
154 changeIntTextfield(data, -1);
157 static void upButtonCallback(WMWidget *self, void *data)
159 (void) self;
160 changeIntTextfield(data, 1);
163 static void createPanel(Panel *p)
165 _Panel *panel = (_Panel *) p;
166 WMScrollView *sv;
167 WMFrame *f;
168 WMUserDefaults *udb;
169 int i, state;
171 panel->box = WMCreateBox(panel->parent);
172 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
174 sv = WMCreateScrollView(panel->box);
175 WMResizeWidget(sv, 500, 215);
176 WMMoveWidget(sv, 12, 10);
177 WMSetScrollViewRelief(sv, WRSunken);
178 WMSetScrollViewHasVerticalScroller(sv, True);
179 WMSetScrollViewHasHorizontalScroller(sv, False);
181 f = WMCreateFrame(panel->box);
182 WMResizeWidget(f, 495, wlengthof(expert_options) * 25 + 8);
183 WMSetFrameRelief(f, WRFlat);
185 udb = WMGetStandardUserDefaults();
186 for (i = 0; i < wlengthof(expert_options); i++) {
187 if (expert_options[i].class != OPTION_WMAKER_INT) {
188 panel->swi[i] = WMCreateSwitchButton(f);
189 WMResizeWidget(panel->swi[i], FRAME_WIDTH - 40, 25);
190 WMMoveWidget(panel->swi[i], 5, 5 + i * 25);
192 WMSetButtonText(panel->swi[i], _(expert_options[i].label));
195 switch (expert_options[i].class) {
196 case OPTION_WMAKER:
197 if (GetStringForKey(expert_options[i].op_name))
198 state = GetBoolForKey(expert_options[i].op_name);
199 else
200 state = expert_options[i].def_state;
201 break;
203 case OPTION_WMAKER_ARRAY: {
204 char *str = GetStringForKey(expert_options[i].op_name);
205 state = expert_options[i].def_state;
206 if (str && strcasecmp(str, "None") == 0)
207 state = False;
209 break;
211 case OPTION_USERDEF:
212 state = WMGetUDBoolForKey(udb, expert_options[i].op_name);
213 break;
215 case OPTION_WMAKER_INT:
217 char tmp[10];
218 WMButton *up, *down;
219 WMLabel *label;
221 panel->textfield[i] = WMCreateTextField(f);
222 WMResizeWidget(panel->textfield[i], 41, 20);
223 WMMoveWidget(panel->textfield[i], 22, 7 + i * 25);
225 down = WMCreateCommandButton(f);
226 WMSetButtonImage(down, WMGetSystemPixmap(WMWidgetScreen(down), WSIArrowDown));
227 WMSetButtonAltImage(down,
228 WMGetSystemPixmap(WMWidgetScreen(down), WSIHighlightedArrowDown));
229 WMSetButtonImagePosition(down, WIPImageOnly);
230 WMSetButtonAction(down, downButtonCallback, panel->textfield[i]);
231 WMResizeWidget(down, 16, 16);
232 WMMoveWidget(down, 5, 9 + i * 25);
234 up = WMCreateCommandButton(f);
235 WMSetButtonImage(up, WMGetSystemPixmap(WMWidgetScreen(up), WSIArrowUp));
236 WMSetButtonAltImage(up, WMGetSystemPixmap(WMWidgetScreen(up), WSIHighlightedArrowUp));
237 WMSetButtonImagePosition(up, WIPImageOnly);
238 WMSetButtonAction(up, upButtonCallback, panel->textfield[i]);
239 WMResizeWidget(up, 16, 16);
240 WMMoveWidget(up, 64, 9 + i * 25);
242 label = WMCreateLabel(f);
243 WMSetLabelText(label, _(expert_options[i].label));
244 WMResizeWidget(label, FRAME_WIDTH - 99, 25);
245 WMMoveWidget(label, 85, 5 + i * 25);
247 if (GetStringForKey(expert_options[i].op_name))
248 state = GetIntegerForKey(expert_options[i].op_name);
249 else
250 state = expert_options[i].def_state;
252 sprintf(tmp, "%d", state);
253 WMSetTextFieldText(panel->textfield[i], tmp);
255 break;
258 default:
259 #ifdef DEBUG
260 wwarning("export_options[%d].class = %d, this should not happen\n",
261 i, expert_options[i].class);
262 #endif
263 state = expert_options[i].def_state;
264 break;
266 if (expert_options[i].class != OPTION_WMAKER_INT)
267 WMSetButtonSelected(panel->swi[i], state);
270 WMMapSubwidgets(panel->box);
271 WMSetScrollViewContentView(sv, WMWidgetView(f));
272 WMRealizeWidget(panel->box);
275 static void storeDefaults(_Panel *panel)
277 WMUserDefaults *udb = WMGetStandardUserDefaults();
278 int i;
280 for (i = 0; i < wlengthof(expert_options); i++) {
281 switch (expert_options[i].class) {
282 case OPTION_WMAKER:
283 SetBoolForKey(WMGetButtonSelected(panel->swi[i]), expert_options[i].op_name);
284 break;
286 case OPTION_WMAKER_ARRAY:
287 if (WMGetButtonSelected(panel->swi[i])) {
288 /* check if the array was not manually modified */
289 char *str = GetStringForKey(expert_options[i].op_name);
290 if (str && strcasecmp(str, "None") == 0)
291 RemoveObjectForKey(expert_options[i].op_name);
293 else
294 SetStringForKey("None", expert_options[i].op_name);
295 break;
297 case OPTION_USERDEF:
298 WMSetUDBoolForKey(udb, WMGetButtonSelected(panel->swi[i]), expert_options[i].op_name);
299 break;
301 case OPTION_WMAKER_INT:
303 char *text;
304 int value;
306 text = WMGetTextFieldText(panel->textfield[i]);
307 value = atoi(text);
309 SetIntegerForKey(value, expert_options[i].op_name);
310 break;
316 Panel *InitExpert(WMWidget *parent)
318 _Panel *panel;
320 panel = wmalloc(sizeof(_Panel));
322 panel->sectionName = _("Expert User Preferences");
324 panel->description = _("Options for people who know what they're doing...\n"
325 "Also has some other misc. options.");
327 panel->parent = parent;
329 panel->callbacks.createWidgets = createPanel;
330 panel->callbacks.updateDomain = storeDefaults;
332 AddSection(panel, ICON_FILE);
334 return panel;