File: Expert.c

package info (click to toggle)
wmaker 0.96.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,416 kB
  • sloc: ansic: 99,483; sh: 7,068; perl: 3,423; makefile: 1,647; lisp: 219; python: 34
file content (363 lines) | stat: -rw-r--r-- 11,017 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/* Expert.c- expert user options
 *
 *  WPrefs - Window Maker Preferences Program
 *
 *  Copyright (c) 2014-2023 Window Maker Team
 *  Copyright (c) 1998-2003 Alfredo K. Kojima
 *  Copyright (c) 2009-2023 Window Maker Team
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "WPrefs.h"

/* This structure containts the list of all the check-buttons to display in the
 * expert tab of the window with the corresponding information for effect
 */
static struct expert_option {
	const char *label;  /* Text displayed to user */

	int def_state;  /* True/False: the default value, if not defined in current config */

	enum {
		OPTION_WMAKER,
		OPTION_WMAKER_ARRAY,
		OPTION_USERDEF,
		OPTION_WMAKER_INT
	} class;

	const char *op_name;  /* The identifier for the option in the config file */

} expert_options[] = {

	{ N_("Disable miniwindows (icons for minimized windows). For use with KDE/GNOME."),
	  /* default: */ False, OPTION_WMAKER, "DisableMiniwindows" },

	{ N_("Ignore decoration hints for GTK applications."),
	  /* default: */ False, OPTION_WMAKER, "IgnoreGtkHints" },

	{ N_("Enable workspace pager."),
	  /* default: */ False, OPTION_WMAKER, "EnableWorkspacePager" },

	{ N_("Do not set non-WindowMaker specific parameters (do not use xset)."),
	  /* default: */ False, OPTION_USERDEF, "NoXSetStuff" },

	{ N_("Automatically save session when exiting Window Maker."),
	  /* default: */ False, OPTION_WMAKER, "SaveSessionOnExit" },

	{ N_("Use SaveUnder in window frames, icons, menus and other objects."),
	  /* default: */ False, OPTION_WMAKER, "UseSaveUnders" },

	{ N_("Disable confirmation panel for the Kill command."),
	  /* default: */ False, OPTION_WMAKER, "DontConfirmKill" },

	{ N_("Disable selection animation for selected icons."),
	  /* default: */ False, OPTION_WMAKER, "DisableBlinking" },

	{ N_("Smooth font edges (needs restart)."),
	  /* default: */ True, OPTION_WMAKER, "AntialiasedText" },

	{ N_("Cycle windows only on the active head."),
	  /* default: */ False, OPTION_WMAKER, "CycleActiveHeadOnly" },

	{ N_("Ignore minimized windows when cycling."),
	  /* default: */ False, OPTION_WMAKER, "CycleIgnoreMinimized" },

	{ N_("Show switch panel when cycling windows."),
	  /* default: */ True, OPTION_WMAKER_ARRAY, "SwitchPanelImages" },

	{ N_("Show workspace title on Clip."),
	  /* default: */ True, OPTION_WMAKER, "ShowClipTitle" },

	{ N_("Highlight the icon of the application when it has the focus."),
	  /* default: */ True, OPTION_WMAKER, "HighlightActiveApp" },

#ifdef XKB_MODELOCK
	{ N_("Enable keyboard language switch button in window titlebars."),
	  /* default: */ False, OPTION_WMAKER, "KbdModeLock" },
#endif /* XKB_MODELOCK */

	{ N_("Snap a window to edge or corner by dragging."),
	  /* default: */ False, OPTION_WMAKER, "WindowSnapping" },

	{ N_("Distance from edge to begin window snap."),
	  /* default: */ 1, OPTION_WMAKER_INT, "SnapEdgeDetect" },

	{ N_("Distance from corner to begin window snap."),
	  /* default: */ 10, OPTION_WMAKER_INT, "SnapCornerDetect" },

	{ N_("Snap a window to the top to maximize it to the full screen."),
	  /* default: */ False, OPTION_WMAKER, "SnapToTopMaximizesFullscreen" },

	{ N_("Allow move half-maximized windows between multiple screens."),
	  /* default: */ False, OPTION_WMAKER, "MoveHalfMaximizedWindowsBetweenScreens" },

	{ N_("Alternative transitions between states for half maximized windows."),
	  /* default: */ False, OPTION_WMAKER, "AlternativeHalfMaximized" },

	{ N_("Move mouse pointer with half maximized windows."),
	  /* default: */ False, OPTION_WMAKER, "PointerWithHalfMaxWindows" },

	{ N_("Open dialogs in the same workspace as their owners."),
	  /* default: */ False, OPTION_WMAKER, "OpenTransientOnOwnerWorkspace" },

	{ N_("Wrap dock-attached icons around the screen edges."),
	  /* default: */ True, OPTION_WMAKER, "WrapAppiconsInDock" },
	  
	{ N_("Double click on titlebar maximizes/minimizes a window to/from full screen."),
	  /* default: */ False, OPTION_WMAKER, "DbClickFullScreen" },

	{ N_("Close rootmenu when mouse (left or right) is clicked outside focus."),
	  /* default: */ False, OPTION_WMAKER, "CloseRootMenuByLeftOrRightMouseClick" },
	{ N_("Keep dock on primary head."),
	  /* default: */ False, OPTION_WMAKER, "KeepDockOnPrimaryHead"},

};



typedef struct _Panel {
	WMBox *box;
	char *sectionName;

	char *description;

	CallbackRec callbacks;

	WMWidget *parent;

	WMButton *swi[wlengthof_nocheck(expert_options)];

	WMTextField *textfield[wlengthof_nocheck(expert_options)];

} _Panel;

#define ICON_FILE	"expert"

static void changeIntTextfield(void *data, int delta)
{
	WMTextField *textfield;
	char *text, buffer[12];
	int value;

	textfield = (WMTextField *)data;
	text = WMGetTextFieldText(textfield);
	value = atoi(text);
	wfree(text);
	value += delta;
	sprintf(buffer, "%d", value);
	WMSetTextFieldText(textfield, buffer);
}

static void downButtonCallback(WMWidget *self, void *data)
{
	(void) self;
	changeIntTextfield(data, -1);
}

static void upButtonCallback(WMWidget *self, void *data)
{
	(void) self;
	changeIntTextfield(data, 1);
}

static int cmpExpertOptions(const void *v1, const void *v2)
{
	int rc;
	const struct expert_option *opt1 = (struct expert_option *)v1;
	const struct expert_option *opt2 = (struct expert_option *)v2;

	if ((rc = strcmp(opt1->label, opt2->label)) < 0)
		return -1;
	else if (rc > 0)
		return 1;
	return 0;
}

static void createPanel(Panel *p)
{
	_Panel *panel = (_Panel *) p;
	WMScrollView *sv;
	WMFrame *f;
	WMUserDefaults *udb;
	int i, state;

	panel->box = WMCreateBox(panel->parent);
	WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);

	sv = WMCreateScrollView(panel->box);
	WMResizeWidget(sv, 500, 215);
	WMMoveWidget(sv, 12, 10);
	WMSetScrollViewRelief(sv, WRSunken);
	WMSetScrollViewHasVerticalScroller(sv, True);
	WMSetScrollViewHasHorizontalScroller(sv, False);

	f = WMCreateFrame(panel->box);
	WMResizeWidget(f, 495, wlengthof(expert_options) * 25 + 8);
	WMSetFrameRelief(f, WRFlat);

	udb = WMGetStandardUserDefaults();
	qsort(expert_options, wlengthof(expert_options), sizeof(expert_options[0]), cmpExpertOptions);
	for (i = 0; i < wlengthof(expert_options); i++) {
		if (expert_options[i].class != OPTION_WMAKER_INT) {
			panel->swi[i] = WMCreateSwitchButton(f);
			WMResizeWidget(panel->swi[i], FRAME_WIDTH - 40, 25);
			WMMoveWidget(panel->swi[i], 5, 5 + i * 25);

			WMSetButtonText(panel->swi[i], _(expert_options[i].label));
		}

		switch (expert_options[i].class) {
		case OPTION_WMAKER:
			if (GetStringForKey(expert_options[i].op_name))
				state = GetBoolForKey(expert_options[i].op_name);
			else
				state = expert_options[i].def_state;
			break;

		case OPTION_WMAKER_ARRAY: {
				char *str = GetStringForKey(expert_options[i].op_name);
				state = expert_options[i].def_state;
				if (str && strcasecmp(str, "None") == 0)
					state = False;
			}
			break;

		case OPTION_USERDEF:
			state = WMGetUDBoolForKey(udb, expert_options[i].op_name);
			break;

		case OPTION_WMAKER_INT:
		{
			char tmp[10];
			WMButton *up, *down;
			WMLabel *label;

			panel->textfield[i] = WMCreateTextField(f);
			WMResizeWidget(panel->textfield[i], 41, 20);
			WMMoveWidget(panel->textfield[i], 22, 7 + i * 25);

			down = WMCreateCommandButton(f);
			WMSetButtonImage(down, WMGetSystemPixmap(WMWidgetScreen(down), WSIArrowDown));
			WMSetButtonAltImage(down,
					    WMGetSystemPixmap(WMWidgetScreen(down), WSIHighlightedArrowDown));
			WMSetButtonImagePosition(down, WIPImageOnly);
			WMSetButtonAction(down, downButtonCallback, panel->textfield[i]);
			WMResizeWidget(down, 16, 16);
			WMMoveWidget(down, 5, 9 + i * 25);

			up = WMCreateCommandButton(f);
			WMSetButtonImage(up, WMGetSystemPixmap(WMWidgetScreen(up), WSIArrowUp));
			WMSetButtonAltImage(up, WMGetSystemPixmap(WMWidgetScreen(up), WSIHighlightedArrowUp));
			WMSetButtonImagePosition(up, WIPImageOnly);
			WMSetButtonAction(up, upButtonCallback, panel->textfield[i]);
			WMResizeWidget(up, 16, 16);
			WMMoveWidget(up, 64, 9 + i * 25);

			label = WMCreateLabel(f);
			WMSetLabelText(label, _(expert_options[i].label));
			WMResizeWidget(label, FRAME_WIDTH - 99, 25);
			WMMoveWidget(label, 85, 5 + i * 25);

			if (GetStringForKey(expert_options[i].op_name))
				state = GetIntegerForKey(expert_options[i].op_name);
			else
				state = expert_options[i].def_state;

			sprintf(tmp, "%d", state);
			WMSetTextFieldText(panel->textfield[i], tmp);

			break;
		}

		default:
#ifdef DEBUG
			wwarning("export_options[%d].class = %d, this should not happen\n",
				i, expert_options[i].class);
#endif
			state = expert_options[i].def_state;
			break;
		}
		if (expert_options[i].class != OPTION_WMAKER_INT)
			WMSetButtonSelected(panel->swi[i], state);
	}

	WMMapSubwidgets(panel->box);
	WMSetScrollViewContentView(sv, WMWidgetView(f));
	WMRealizeWidget(panel->box);
}

static void storeDefaults(_Panel *panel)
{
	WMUserDefaults *udb = WMGetStandardUserDefaults();
	int i;

	for (i = 0; i < wlengthof(expert_options); i++) {
		switch (expert_options[i].class) {
		case OPTION_WMAKER:
			SetBoolForKey(WMGetButtonSelected(panel->swi[i]), expert_options[i].op_name);
			break;

		case OPTION_WMAKER_ARRAY:
			if (WMGetButtonSelected(panel->swi[i])) {
				/* check if the array was not manually modified */
				char *str = GetStringForKey(expert_options[i].op_name);
				if (str && strcasecmp(str, "None") == 0)
					RemoveObjectForKey(expert_options[i].op_name);
			}
			else
				SetStringForKey("None", expert_options[i].op_name);
			break;

		case OPTION_USERDEF:
			WMSetUDBoolForKey(udb, WMGetButtonSelected(panel->swi[i]), expert_options[i].op_name);
			break;

		case OPTION_WMAKER_INT:
		{
			char *text;
			int value;

			text = WMGetTextFieldText(panel->textfield[i]);
			value = atoi(text);
			wfree(text);

			SetIntegerForKey(value, expert_options[i].op_name);
			break;
		}
		}
	}
}

Panel *InitExpert(WMWidget *parent)
{
	_Panel *panel;

	panel = wmalloc(sizeof(_Panel));

	panel->sectionName = _("Expert User Preferences");

	panel->description = _("Options for people who know what they're doing...\n"
			       "Also has some other misc. options.");

	panel->parent = parent;

	panel->callbacks.createWidgets = createPanel;
	panel->callbacks.updateDomain = storeDefaults;

	AddSection(panel, ICON_FILE);

	return panel;
}