1 /* Expert.c- expert user options
2  *
3  *  WPrefs - Window Maker Preferences Program
4  *
5  *  Copyright (c) 2014 Window Maker Team
6  *  Copyright (c) 1998-2003 Alfredo K. Kojima
7  *
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.
12  *
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.
17  *
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.
21  */
22 
23 #include "WPrefs.h"
24 
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
27  */
28 static const struct {
29 	const char *label;  /* Text displayed to user */
30 
31 	int def_state;  /* True/False: the default value, if not defined in current config */
32 
33 	enum {
34 		OPTION_WMAKER,
35 		OPTION_WMAKER_ARRAY,
36 		OPTION_USERDEF,
37 		OPTION_WMAKER_INT
38 	} class;
39 
40 	const char *op_name;  /* The identifier for the option in the config file */
41 
42 } expert_options[] = {
43 
44 	{ N_("Disable miniwindows (icons for minimized windows). For use with KDE/GNOME."),
45 	  /* default: */ False, OPTION_WMAKER, "DisableMiniwindows" },
46 
47 	{ N_("Ignore decoration hints for GTK applications."),
48 	  /* default: */ False, OPTION_WMAKER, "IgnoreGtkHints" },
49 
50 	{ N_("Enable workspace pager."),
51 	  /* default: */ False, OPTION_WMAKER, "EnableWorkspacePager" },
52 
53 	{ N_("Do not set non-WindowMaker specific parameters (do not use xset)."),
54 	  /* default: */ False, OPTION_USERDEF, "NoXSetStuff" },
55 
56 	{ N_("Automatically save session when exiting Window Maker."),
57 	  /* default: */ False, OPTION_WMAKER, "SaveSessionOnExit" },
58 
59 	{ N_("Use SaveUnder in window frames, icons, menus and other objects."),
60 	  /* default: */ False, OPTION_WMAKER, "UseSaveUnders" },
61 
62 	{ N_("Disable confirmation panel for the Kill command."),
63 	  /* default: */ False, OPTION_WMAKER, "DontConfirmKill" },
64 
65 	{ N_("Disable selection animation for selected icons."),
66 	  /* default: */ False, OPTION_WMAKER, "DisableBlinking" },
67 
68 	{ N_("Smooth font edges (needs restart)."),
69 	  /* default: */ True, OPTION_WMAKER, "AntialiasedText" },
70 
71 	{ N_("Cycle windows only on the active head."),
72 	  /* default: */ False, OPTION_WMAKER, "CycleActiveHeadOnly" },
73 
74 	{ N_("Ignore minimized windows when cycling."),
75 	  /* default: */ False, OPTION_WMAKER, "CycleIgnoreMinimized" },
76 
77 	{ N_("Show switch panel when cycling windows."),
78 	  /* default: */ True, OPTION_WMAKER_ARRAY, "SwitchPanelImages" },
79 
80 	{ N_("Show workspace title on Clip."),
81 	  /* default: */ True, OPTION_WMAKER, "ShowClipTitle" },
82 
83 	{ N_("Highlight the icon of the application when it has the focus."),
84 	  /* default: */ True, OPTION_WMAKER, "HighlightActiveApp" },
85 
86 #ifdef XKB_MODELOCK
87 	{ N_("Enable keyboard language switch button in window titlebars."),
88 	  /* default: */ False, OPTION_WMAKER, "KbdModeLock" },
89 #endif /* XKB_MODELOCK */
90 
91 	{ N_("Maximize (snap) a window to edge or corner by dragging."),
92 	  /* default: */ False, OPTION_WMAKER, "WindowSnapping" },
93 
94 	{ N_("Distance from edge to begin window snap."),
95 	  /* default: */ 1, OPTION_WMAKER_INT, "SnapEdgeDetect" },
96 
97 	{ N_("Distance from corner to begin window snap."),
98 	  /* default: */ 10, OPTION_WMAKER_INT, "SnapCornerDetect" },
99 
100 	{ N_("Snapping a window to the top maximizes it to the full screen."),
101 	  /* default: */ False, OPTION_WMAKER, "SnapToTopMaximizesFullscreen" },
102 
103 	{ N_("Allow move half-maximized windows between multiple screens."),
104 	  /* default: */ False, OPTION_WMAKER, "MoveHalfMaximizedWindowsBetweenScreens" },
105 
106 	{ N_("Alternative transitions between states for half maximized windows."),
107 	  /* default: */ False, OPTION_WMAKER, "AlternativeHalfMaximized" },
108 
109 	{ N_("Move mouse pointer with half maximized windows."),
110 	  /* default: */ False, OPTION_WMAKER, "PointerWithHalfMaxWindows" },
111 
112 	{ N_("Open dialogs in the same workspace as their owners."),
113 	  /* default: */ False, OPTION_WMAKER, "OpenTransientOnOwnerWorkspace" },
114 
115 	{ N_("Wrap dock-attached icons around the screen edges."),
116 	  /* default: */ True, OPTION_WMAKER, "WrapAppiconsInDock" }
117 
118 };
119 
120 
121 
122 typedef struct _Panel {
123 	WMBox *box;
124 	char *sectionName;
125 
126 	char *description;
127 
128 	CallbackRec callbacks;
129 
130 	WMWidget *parent;
131 
132 	WMButton *swi[wlengthof_nocheck(expert_options)];
133 
134 	WMTextField *textfield[wlengthof_nocheck(expert_options)];
135 
136 } _Panel;
137 
138 #define ICON_FILE	"expert"
139 
changeIntTextfield(void * data,int delta)140 static void changeIntTextfield(void *data, int delta)
141 {
142 	WMTextField *textfield;
143 	char *text;
144 	int value;
145 
146 	textfield = (WMTextField *)data;
147 	text = WMGetTextFieldText(textfield);
148 	value = atoi(text);
149 	value += delta;
150 	sprintf(text, "%d", value);
151 	WMSetTextFieldText(textfield, text);
152 }
153 
downButtonCallback(WMWidget * self,void * data)154 static void downButtonCallback(WMWidget *self, void *data)
155 {
156 	(void) self;
157 	changeIntTextfield(data, -1);
158 }
159 
upButtonCallback(WMWidget * self,void * data)160 static void upButtonCallback(WMWidget *self, void *data)
161 {
162 	(void) self;
163 	changeIntTextfield(data, 1);
164 }
165 
createPanel(Panel * p)166 static void createPanel(Panel *p)
167 {
168 	_Panel *panel = (_Panel *) p;
169 	WMScrollView *sv;
170 	WMFrame *f;
171 	WMUserDefaults *udb;
172 	int i, state;
173 
174 	panel->box = WMCreateBox(panel->parent);
175 	WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
176 
177 	sv = WMCreateScrollView(panel->box);
178 	WMResizeWidget(sv, 500, 215);
179 	WMMoveWidget(sv, 12, 10);
180 	WMSetScrollViewRelief(sv, WRSunken);
181 	WMSetScrollViewHasVerticalScroller(sv, True);
182 	WMSetScrollViewHasHorizontalScroller(sv, False);
183 
184 	f = WMCreateFrame(panel->box);
185 	WMResizeWidget(f, 495, wlengthof(expert_options) * 25 + 8);
186 	WMSetFrameRelief(f, WRFlat);
187 
188 	udb = WMGetStandardUserDefaults();
189 	for (i = 0; i < wlengthof(expert_options); i++) {
190 		if (expert_options[i].class != OPTION_WMAKER_INT) {
191 			panel->swi[i] = WMCreateSwitchButton(f);
192 			WMResizeWidget(panel->swi[i], FRAME_WIDTH - 40, 25);
193 			WMMoveWidget(panel->swi[i], 5, 5 + i * 25);
194 
195 			WMSetButtonText(panel->swi[i], _(expert_options[i].label));
196 		}
197 
198 		switch (expert_options[i].class) {
199 		case OPTION_WMAKER:
200 			if (GetStringForKey(expert_options[i].op_name))
201 				state = GetBoolForKey(expert_options[i].op_name);
202 			else
203 				state = expert_options[i].def_state;
204 			break;
205 
206 		case OPTION_WMAKER_ARRAY: {
207 				char *str = GetStringForKey(expert_options[i].op_name);
208 				state = expert_options[i].def_state;
209 				if (str && strcasecmp(str, "None") == 0)
210 					state = False;
211 			}
212 			break;
213 
214 		case OPTION_USERDEF:
215 			state = WMGetUDBoolForKey(udb, expert_options[i].op_name);
216 			break;
217 
218 		case OPTION_WMAKER_INT:
219 		{
220 			char tmp[10];
221 			WMButton *up, *down;
222 			WMLabel *label;
223 
224 			panel->textfield[i] = WMCreateTextField(f);
225 			WMResizeWidget(panel->textfield[i], 41, 20);
226 			WMMoveWidget(panel->textfield[i], 22, 7 + i * 25);
227 
228 			down = WMCreateCommandButton(f);
229 			WMSetButtonImage(down, WMGetSystemPixmap(WMWidgetScreen(down), WSIArrowDown));
230 			WMSetButtonAltImage(down,
231 					    WMGetSystemPixmap(WMWidgetScreen(down), WSIHighlightedArrowDown));
232 			WMSetButtonImagePosition(down, WIPImageOnly);
233 			WMSetButtonAction(down, downButtonCallback, panel->textfield[i]);
234 			WMResizeWidget(down, 16, 16);
235 			WMMoveWidget(down, 5, 9 + i * 25);
236 
237 			up = WMCreateCommandButton(f);
238 			WMSetButtonImage(up, WMGetSystemPixmap(WMWidgetScreen(up), WSIArrowUp));
239 			WMSetButtonAltImage(up, WMGetSystemPixmap(WMWidgetScreen(up), WSIHighlightedArrowUp));
240 			WMSetButtonImagePosition(up, WIPImageOnly);
241 			WMSetButtonAction(up, upButtonCallback, panel->textfield[i]);
242 			WMResizeWidget(up, 16, 16);
243 			WMMoveWidget(up, 64, 9 + i * 25);
244 
245 			label = WMCreateLabel(f);
246 			WMSetLabelText(label, _(expert_options[i].label));
247 			WMResizeWidget(label, FRAME_WIDTH - 99, 25);
248 			WMMoveWidget(label, 85, 5 + i * 25);
249 
250 			if (GetStringForKey(expert_options[i].op_name))
251 				state = GetIntegerForKey(expert_options[i].op_name);
252 			else
253 				state = expert_options[i].def_state;
254 
255 			sprintf(tmp, "%d", state);
256 			WMSetTextFieldText(panel->textfield[i], tmp);
257 
258 			break;
259 		}
260 
261 		default:
262 #ifdef DEBUG
263 			wwarning("export_options[%d].class = %d, this should not happen\n",
264 				i, expert_options[i].class);
265 #endif
266 			state = expert_options[i].def_state;
267 			break;
268 		}
269 		if (expert_options[i].class != OPTION_WMAKER_INT)
270 			WMSetButtonSelected(panel->swi[i], state);
271 	}
272 
273 	WMMapSubwidgets(panel->box);
274 	WMSetScrollViewContentView(sv, WMWidgetView(f));
275 	WMRealizeWidget(panel->box);
276 }
277 
storeDefaults(_Panel * panel)278 static void storeDefaults(_Panel *panel)
279 {
280 	WMUserDefaults *udb = WMGetStandardUserDefaults();
281 	int i;
282 
283 	for (i = 0; i < wlengthof(expert_options); i++) {
284 		switch (expert_options[i].class) {
285 		case OPTION_WMAKER:
286 			SetBoolForKey(WMGetButtonSelected(panel->swi[i]), expert_options[i].op_name);
287 			break;
288 
289 		case OPTION_WMAKER_ARRAY:
290 			if (WMGetButtonSelected(panel->swi[i])) {
291 				/* check if the array was not manually modified */
292 				char *str = GetStringForKey(expert_options[i].op_name);
293 				if (str && strcasecmp(str, "None") == 0)
294 					RemoveObjectForKey(expert_options[i].op_name);
295 			}
296 			else
297 				SetStringForKey("None", expert_options[i].op_name);
298 			break;
299 
300 		case OPTION_USERDEF:
301 			WMSetUDBoolForKey(udb, WMGetButtonSelected(panel->swi[i]), expert_options[i].op_name);
302 			break;
303 
304 		case OPTION_WMAKER_INT:
305 		{
306 			char *text;
307 			int value;
308 
309 			text = WMGetTextFieldText(panel->textfield[i]);
310 			value = atoi(text);
311 
312 			SetIntegerForKey(value, expert_options[i].op_name);
313 			break;
314 		}
315 		}
316 	}
317 }
318 
InitExpert(WMWidget * parent)319 Panel *InitExpert(WMWidget *parent)
320 {
321 	_Panel *panel;
322 
323 	panel = wmalloc(sizeof(_Panel));
324 
325 	panel->sectionName = _("Expert User Preferences");
326 
327 	panel->description = _("Options for people who know what they're doing...\n"
328 			       "Also has some other misc. options.");
329 
330 	panel->parent = parent;
331 
332 	panel->callbacks.createWidgets = createPanel;
333 	panel->callbacks.updateDomain = storeDefaults;
334 
335 	AddSection(panel, ICON_FILE);
336 
337 	return panel;
338 }
339