Include screen.h in dialog.h for definition of WScreen
[wmaker-crm.git] / WPrefs.app / Expert.c
blob8195d876e2327a226fc445b0f358fa68f82c78dc
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" },
115 { N_("Wrap dock-attached icons around the screen edges."),
116 /* default: */ True, OPTION_WMAKER, "WrapAppiconsInDock" },
118 { N_("Double click on titlebar maximize a window to full screen."),
119 /* default: */ False, OPTION_WMAKER, "DbClickFullScreen" },
121 { N_("Close rootmenu when mouse (left or right) is clicked outside focus."),
122 /* default: */ False, OPTION_WMAKER, "CloseRootMenuByLeftOrRightMouseClick" },
123 { N_("Keep dock on primary head."),
124 /* default: */ False, OPTION_WMAKER, "KeepDockOnPrimaryHead"},
130 typedef struct _Panel {
131 WMBox *box;
132 char *sectionName;
134 char *description;
136 CallbackRec callbacks;
138 WMWidget *parent;
140 WMButton *swi[wlengthof_nocheck(expert_options)];
142 WMTextField *textfield[wlengthof_nocheck(expert_options)];
144 } _Panel;
146 #define ICON_FILE "expert"
148 static void changeIntTextfield(void *data, int delta)
150 WMTextField *textfield;
151 char *text, buffer[12];
152 int value;
154 textfield = (WMTextField *)data;
155 text = WMGetTextFieldText(textfield);
156 value = atoi(text);
157 wfree(text);
158 value += delta;
159 sprintf(buffer, "%d", value);
160 WMSetTextFieldText(textfield, buffer);
163 static void downButtonCallback(WMWidget *self, void *data)
165 (void) self;
166 changeIntTextfield(data, -1);
169 static void upButtonCallback(WMWidget *self, void *data)
171 (void) self;
172 changeIntTextfield(data, 1);
175 static void createPanel(Panel *p)
177 _Panel *panel = (_Panel *) p;
178 WMScrollView *sv;
179 WMFrame *f;
180 WMUserDefaults *udb;
181 int i, state;
183 panel->box = WMCreateBox(panel->parent);
184 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
186 sv = WMCreateScrollView(panel->box);
187 WMResizeWidget(sv, 500, 215);
188 WMMoveWidget(sv, 12, 10);
189 WMSetScrollViewRelief(sv, WRSunken);
190 WMSetScrollViewHasVerticalScroller(sv, True);
191 WMSetScrollViewHasHorizontalScroller(sv, False);
193 f = WMCreateFrame(panel->box);
194 WMResizeWidget(f, 495, wlengthof(expert_options) * 25 + 8);
195 WMSetFrameRelief(f, WRFlat);
197 udb = WMGetStandardUserDefaults();
198 for (i = 0; i < wlengthof(expert_options); i++) {
199 if (expert_options[i].class != OPTION_WMAKER_INT) {
200 panel->swi[i] = WMCreateSwitchButton(f);
201 WMResizeWidget(panel->swi[i], FRAME_WIDTH - 40, 25);
202 WMMoveWidget(panel->swi[i], 5, 5 + i * 25);
204 WMSetButtonText(panel->swi[i], _(expert_options[i].label));
207 switch (expert_options[i].class) {
208 case OPTION_WMAKER:
209 if (GetStringForKey(expert_options[i].op_name))
210 state = GetBoolForKey(expert_options[i].op_name);
211 else
212 state = expert_options[i].def_state;
213 break;
215 case OPTION_WMAKER_ARRAY: {
216 char *str = GetStringForKey(expert_options[i].op_name);
217 state = expert_options[i].def_state;
218 if (str && strcasecmp(str, "None") == 0)
219 state = False;
221 break;
223 case OPTION_USERDEF:
224 state = WMGetUDBoolForKey(udb, expert_options[i].op_name);
225 break;
227 case OPTION_WMAKER_INT:
229 char tmp[10];
230 WMButton *up, *down;
231 WMLabel *label;
233 panel->textfield[i] = WMCreateTextField(f);
234 WMResizeWidget(panel->textfield[i], 41, 20);
235 WMMoveWidget(panel->textfield[i], 22, 7 + i * 25);
237 down = WMCreateCommandButton(f);
238 WMSetButtonImage(down, WMGetSystemPixmap(WMWidgetScreen(down), WSIArrowDown));
239 WMSetButtonAltImage(down,
240 WMGetSystemPixmap(WMWidgetScreen(down), WSIHighlightedArrowDown));
241 WMSetButtonImagePosition(down, WIPImageOnly);
242 WMSetButtonAction(down, downButtonCallback, panel->textfield[i]);
243 WMResizeWidget(down, 16, 16);
244 WMMoveWidget(down, 5, 9 + i * 25);
246 up = WMCreateCommandButton(f);
247 WMSetButtonImage(up, WMGetSystemPixmap(WMWidgetScreen(up), WSIArrowUp));
248 WMSetButtonAltImage(up, WMGetSystemPixmap(WMWidgetScreen(up), WSIHighlightedArrowUp));
249 WMSetButtonImagePosition(up, WIPImageOnly);
250 WMSetButtonAction(up, upButtonCallback, panel->textfield[i]);
251 WMResizeWidget(up, 16, 16);
252 WMMoveWidget(up, 64, 9 + i * 25);
254 label = WMCreateLabel(f);
255 WMSetLabelText(label, _(expert_options[i].label));
256 WMResizeWidget(label, FRAME_WIDTH - 99, 25);
257 WMMoveWidget(label, 85, 5 + i * 25);
259 if (GetStringForKey(expert_options[i].op_name))
260 state = GetIntegerForKey(expert_options[i].op_name);
261 else
262 state = expert_options[i].def_state;
264 sprintf(tmp, "%d", state);
265 WMSetTextFieldText(panel->textfield[i], tmp);
267 break;
270 default:
271 #ifdef DEBUG
272 wwarning("export_options[%d].class = %d, this should not happen\n",
273 i, expert_options[i].class);
274 #endif
275 state = expert_options[i].def_state;
276 break;
278 if (expert_options[i].class != OPTION_WMAKER_INT)
279 WMSetButtonSelected(panel->swi[i], state);
282 WMMapSubwidgets(panel->box);
283 WMSetScrollViewContentView(sv, WMWidgetView(f));
284 WMRealizeWidget(panel->box);
287 static void storeDefaults(_Panel *panel)
289 WMUserDefaults *udb = WMGetStandardUserDefaults();
290 int i;
292 for (i = 0; i < wlengthof(expert_options); i++) {
293 switch (expert_options[i].class) {
294 case OPTION_WMAKER:
295 SetBoolForKey(WMGetButtonSelected(panel->swi[i]), expert_options[i].op_name);
296 break;
298 case OPTION_WMAKER_ARRAY:
299 if (WMGetButtonSelected(panel->swi[i])) {
300 /* check if the array was not manually modified */
301 char *str = GetStringForKey(expert_options[i].op_name);
302 if (str && strcasecmp(str, "None") == 0)
303 RemoveObjectForKey(expert_options[i].op_name);
305 else
306 SetStringForKey("None", expert_options[i].op_name);
307 break;
309 case OPTION_USERDEF:
310 WMSetUDBoolForKey(udb, WMGetButtonSelected(panel->swi[i]), expert_options[i].op_name);
311 break;
313 case OPTION_WMAKER_INT:
315 char *text;
316 int value;
318 text = WMGetTextFieldText(panel->textfield[i]);
319 value = atoi(text);
320 wfree(text);
322 SetIntegerForKey(value, expert_options[i].op_name);
323 break;
329 Panel *InitExpert(WMWidget *parent)
331 _Panel *panel;
333 panel = wmalloc(sizeof(_Panel));
335 panel->sectionName = _("Expert User Preferences");
337 panel->description = _("Options for people who know what they're doing...\n"
338 "Also has some other misc. options.");
340 panel->parent = parent;
342 panel->callbacks.createWidgets = createPanel;
343 panel->callbacks.updateDomain = storeDefaults;
345 AddSection(panel, ICON_FILE);
347 return panel;