WPrefs: Add ability to set integer values in Expert panel
[wmaker-crm.git] / WPrefs.app / Expert.c
blob0c6ed7bea6059383db4e198d6bd60e16b753f81d
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_("Disable workspace pager."),
51 /* default: */ False, OPTION_WMAKER, "DisableWorkspacePager" },
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 a window to side or corner by dragging."),
92 /* default: */ False, OPTION_WMAKER, "WindowSnapping" },
94 { N_("Open dialogs in the same workspace as their owners."),
95 /* default: */ False, OPTION_WMAKER, "OpenTransientOnOwnerWorkspace" }
101 typedef struct _Panel {
102 WMBox *box;
103 char *sectionName;
105 char *description;
107 CallbackRec callbacks;
109 WMWidget *parent;
111 WMButton *swi[wlengthof_nocheck(expert_options)];
113 WMTextField *textfield[wlengthof_nocheck(expert_options)];
115 } _Panel;
117 #define ICON_FILE "expert"
119 static void changeIntTextfield(void *data, int delta)
121 WMTextField *textfield;
122 char *text;
123 int value;
125 textfield = (WMTextField *)data;
126 text = WMGetTextFieldText(textfield);
127 value = atoi(text);
128 value += delta;
129 sprintf(text, "%d", value);
130 WMSetTextFieldText(textfield, text);
133 static void downButtonCallback(WMWidget *self, void *data)
135 (void) self;
136 changeIntTextfield(data, -1);
139 static void upButtonCallback(WMWidget *self, void *data)
141 (void) self;
142 changeIntTextfield(data, 1);
145 static void createPanel(Panel *p)
147 _Panel *panel = (_Panel *) p;
148 WMScrollView *sv;
149 WMFrame *f;
150 WMUserDefaults *udb;
151 int i, state;
153 panel->box = WMCreateBox(panel->parent);
154 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
156 sv = WMCreateScrollView(panel->box);
157 WMResizeWidget(sv, 500, 215);
158 WMMoveWidget(sv, 12, 10);
159 WMSetScrollViewRelief(sv, WRSunken);
160 WMSetScrollViewHasVerticalScroller(sv, True);
161 WMSetScrollViewHasHorizontalScroller(sv, False);
163 f = WMCreateFrame(panel->box);
164 WMResizeWidget(f, 495, wlengthof(expert_options) * 25 + 8);
165 WMSetFrameRelief(f, WRFlat);
167 udb = WMGetStandardUserDefaults();
168 for (i = 0; i < wlengthof(expert_options); i++) {
169 if (expert_options[i].class != OPTION_WMAKER_INT) {
170 panel->swi[i] = WMCreateSwitchButton(f);
171 WMResizeWidget(panel->swi[i], FRAME_WIDTH - 40, 25);
172 WMMoveWidget(panel->swi[i], 5, 5 + i * 25);
174 WMSetButtonText(panel->swi[i], _(expert_options[i].label));
177 switch (expert_options[i].class) {
178 case OPTION_WMAKER:
179 if (GetStringForKey(expert_options[i].op_name))
180 state = GetBoolForKey(expert_options[i].op_name);
181 else
182 state = expert_options[i].def_state;
183 break;
185 case OPTION_WMAKER_ARRAY: {
186 char *str = GetStringForKey(expert_options[i].op_name);
187 state = expert_options[i].def_state;
188 if (str && strcasecmp(str, "None") == 0)
189 state = False;
191 break;
193 case OPTION_USERDEF:
194 state = WMGetUDBoolForKey(udb, expert_options[i].op_name);
195 break;
197 case OPTION_WMAKER_INT:
199 char tmp[10];
200 WMButton *up, *down;
201 WMLabel *label;
203 panel->textfield[i] = WMCreateTextField(f);
204 WMResizeWidget(panel->textfield[i], 41, 20);
205 WMMoveWidget(panel->textfield[i], 22, 7 + i * 25);
207 down = WMCreateCommandButton(f);
208 WMSetButtonImage(down, WMGetSystemPixmap(WMWidgetScreen(down), WSIArrowDown));
209 WMSetButtonAltImage(down,
210 WMGetSystemPixmap(WMWidgetScreen(down), WSIHighlightedArrowDown));
211 WMSetButtonImagePosition(down, WIPImageOnly);
212 WMSetButtonAction(down, downButtonCallback, panel->textfield[i]);
213 WMResizeWidget(down, 16, 16);
214 WMMoveWidget(down, 5, 9 + i * 25);
216 up = WMCreateCommandButton(f);
217 WMSetButtonImage(up, WMGetSystemPixmap(WMWidgetScreen(up), WSIArrowUp));
218 WMSetButtonAltImage(up, WMGetSystemPixmap(WMWidgetScreen(up), WSIHighlightedArrowUp));
219 WMSetButtonImagePosition(up, WIPImageOnly);
220 WMSetButtonAction(up, upButtonCallback, panel->textfield[i]);
221 WMResizeWidget(up, 16, 16);
222 WMMoveWidget(up, 64, 9 + i * 25);
224 label = WMCreateLabel(f);
225 WMSetLabelText(label, _(expert_options[i].label));
226 WMResizeWidget(label, FRAME_WIDTH - 99, 25);
227 WMMoveWidget(label, 85, 5 + i * 25);
229 if (GetStringForKey(expert_options[i].op_name))
230 state = GetIntegerForKey(expert_options[i].op_name);
231 else
232 state = expert_options[i].def_state;
234 sprintf(tmp, "%d", state);
235 WMSetTextFieldText(panel->textfield[i], tmp);
237 break;
240 default:
241 #ifdef DEBUG
242 wwarning("export_options[%d].class = %d, this should not happen\n",
243 i, expert_options[i].class);
244 #endif
245 state = expert_options[i].def_state;
246 break;
248 if (expert_options[i].class != OPTION_WMAKER_INT)
249 WMSetButtonSelected(panel->swi[i], state);
252 WMMapSubwidgets(panel->box);
253 WMSetScrollViewContentView(sv, WMWidgetView(f));
254 WMRealizeWidget(panel->box);
257 static void storeDefaults(_Panel *panel)
259 WMUserDefaults *udb = WMGetStandardUserDefaults();
260 int i;
262 for (i = 0; i < wlengthof(expert_options); i++) {
263 switch (expert_options[i].class) {
264 case OPTION_WMAKER:
265 SetBoolForKey(WMGetButtonSelected(panel->swi[i]), expert_options[i].op_name);
266 break;
268 case OPTION_WMAKER_ARRAY:
269 if (WMGetButtonSelected(panel->swi[i])) {
270 /* check if the array was not manually modified */
271 char *str = GetStringForKey(expert_options[i].op_name);
272 if (str && strcasecmp(str, "None") == 0)
273 RemoveObjectForKey(expert_options[i].op_name);
275 else
276 SetStringForKey("None", expert_options[i].op_name);
277 break;
279 case OPTION_USERDEF:
280 WMSetUDBoolForKey(udb, WMGetButtonSelected(panel->swi[i]), expert_options[i].op_name);
281 break;
283 case OPTION_WMAKER_INT:
285 char *text;
286 int value;
288 text = WMGetTextFieldText(panel->textfield[i]);
289 value = atoi(text);
291 SetIntegerForKey(value, expert_options[i].op_name);
292 break;
298 Panel *InitExpert(WMWidget *parent)
300 _Panel *panel;
302 panel = wmalloc(sizeof(_Panel));
304 panel->sectionName = _("Expert User Preferences");
306 panel->description = _("Options for people who know what they're doing...\n"
307 "Also has some other misc. options.");
309 panel->parent = parent;
311 panel->callbacks.createWidgets = createPanel;
312 panel->callbacks.updateDomain = storeDefaults;
314 AddSection(panel, ICON_FILE);
316 return panel;