Change to the linux kernel coding style
[wmaker-crm.git] / src / wdefaults.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/* wdefaults.c - window specific defaults
6830b057 dan2004-10-12 21:28:27 +00002 *
9af1c6c4 dan1998-10-21 14:43:47 +00003 * Window Maker window manager
6830b057 dan2004-10-12 21:28:27 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 1997-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00006 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00007 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
6830b057 dan2004-10-12 21:28:27 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000020 * USA.
21 */
22
23#include "wconfig.h"
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <unistd.h>
28#include <string.h>
29#include <ctype.h>
6830b057 dan2004-10-12 21:28:27 +000030
9d2e6ef9 scottc1998-09-29 22:36:29 +000031#include <X11/Xlib.h>
32#include <X11/Xutil.h>
33#include <X11/keysym.h>
34
35#include <wraster.h>
36
9d2e6ef9 scottc1998-09-29 22:36:29 +000037#include "WindowMaker.h"
38#include "window.h"
39#include "screen.h"
40#include "funcs.h"
41#include "workspace.h"
42#include "defaults.h"
43#include "icon.h"
44
9d2e6ef9 scottc1998-09-29 22:36:29 +000045/* Global stuff */
46
47extern WPreferences wPreferences;
48
33cc542e dan2001-10-04 03:07:34 +000049extern WMPropList *wAttributeDomainName;
9d2e6ef9 scottc1998-09-29 22:36:29 +000050
51extern WDDomain *WDWindowAttributes;
52
9d2e6ef9 scottc1998-09-29 22:36:29 +000053/* Local stuff */
54
9d2e6ef9 scottc1998-09-29 22:36:29 +000055/* type converters */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020056static int getBool(WMPropList *, WMPropList *);
33cc542e dan2001-10-04 03:07:34 +000057
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020058static char *getString(WMPropList *, WMPropList *);
33cc542e dan2001-10-04 03:07:34 +000059
60static WMPropList *ANoTitlebar = NULL;
61static WMPropList *ANoResizebar;
62static WMPropList *ANoMiniaturizeButton;
63static WMPropList *ANoCloseButton;
64static WMPropList *ANoBorder;
65static WMPropList *ANoHideOthers;
66static WMPropList *ANoMouseBindings;
67static WMPropList *ANoKeyBindings;
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020068static WMPropList *ANoAppIcon; /* app */
33cc542e dan2001-10-04 03:07:34 +000069static WMPropList *AKeepOnTop;
70static WMPropList *AKeepOnBottom;
71static WMPropList *AOmnipresent;
72static WMPropList *ASkipWindowList;
73static WMPropList *AKeepInsideScreen;
74static WMPropList *AUnfocusable;
75static WMPropList *AAlwaysUserIcon;
76static WMPropList *AStartMiniaturized;
77static WMPropList *AStartMaximized;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020078static WMPropList *AStartHidden; /* app */
79static WMPropList *ADontSaveSession; /* app */
33cc542e dan2001-10-04 03:07:34 +000080static WMPropList *AEmulateAppIcon;
81static WMPropList *AFullMaximize;
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020082static WMPropList *ASharedAppIcon; /* app */
a43f369e id1999-05-29 15:45:19 +000083#ifdef XKB_BUTTON_HINT
33cc542e dan2001-10-04 03:07:34 +000084static WMPropList *ANoLanguageButton;
a43f369e id1999-05-29 15:45:19 +000085#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +000086
33cc542e dan2001-10-04 03:07:34 +000087static WMPropList *AStartWorkspace;
9d2e6ef9 scottc1998-09-29 22:36:29 +000088
33cc542e dan2001-10-04 03:07:34 +000089static WMPropList *AIcon;
9d2e6ef9 scottc1998-09-29 22:36:29 +000090
33cc542e dan2001-10-04 03:07:34 +000091static WMPropList *AnyWindow;
92static WMPropList *No;
9d2e6ef9 scottc1998-09-29 22:36:29 +000093
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020094static void init_wdefaults(WScreen * scr)
9d2e6ef9 scottc1998-09-29 22:36:29 +000095{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020096 AIcon = WMCreatePLString("Icon");
97
98 ANoTitlebar = WMCreatePLString("NoTitlebar");
99 ANoResizebar = WMCreatePLString("NoResizebar");
100 ANoMiniaturizeButton = WMCreatePLString("NoMiniaturizeButton");
101 ANoCloseButton = WMCreatePLString("NoCloseButton");
102 ANoBorder = WMCreatePLString("NoBorder");
103 ANoHideOthers = WMCreatePLString("NoHideOthers");
104 ANoMouseBindings = WMCreatePLString("NoMouseBindings");
105 ANoKeyBindings = WMCreatePLString("NoKeyBindings");
106 ANoAppIcon = WMCreatePLString("NoAppIcon");
107 AKeepOnTop = WMCreatePLString("KeepOnTop");
108 AKeepOnBottom = WMCreatePLString("KeepOnBottom");
109 AOmnipresent = WMCreatePLString("Omnipresent");
110 ASkipWindowList = WMCreatePLString("SkipWindowList");
111 AKeepInsideScreen = WMCreatePLString("KeepInsideScreen");
112 AUnfocusable = WMCreatePLString("Unfocusable");
113 AAlwaysUserIcon = WMCreatePLString("AlwaysUserIcon");
114 AStartMiniaturized = WMCreatePLString("StartMiniaturized");
115 AStartHidden = WMCreatePLString("StartHidden");
116 AStartMaximized = WMCreatePLString("StartMaximized");
117 ADontSaveSession = WMCreatePLString("DontSaveSession");
118 AEmulateAppIcon = WMCreatePLString("EmulateAppIcon");
119 AFullMaximize = WMCreatePLString("FullMaximize");
120 ASharedAppIcon = WMCreatePLString("SharedAppIcon");
a43f369e id1999-05-29 15:45:19 +0000121#ifdef XKB_BUTTON_HINT
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200122 ANoLanguageButton = WMCreatePLString("NoLanguageButton");
a43f369e id1999-05-29 15:45:19 +0000123#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +0000124
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200125 AStartWorkspace = WMCreatePLString("StartWorkspace");
6830b057 dan2004-10-12 21:28:27 +0000126
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200127 AnyWindow = WMCreatePLString("*");
128 No = WMCreatePLString("No");
129 /*
130 if (!scr->wattribs) {
131 scr->wattribs = PLGetDomain(wAttributeDomainName);
132 } */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000133}
134
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200135static WMPropList *get_value(WMPropList * dict_win, WMPropList * dict_class, WMPropList * dict_name,
136 WMPropList * dict_any, WMPropList * option, WMPropList * default_value,
137 Bool useGlobalDefault)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000138{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200139 WMPropList *value;
140
141 if (dict_win) {
142 value = WMGetFromPLDictionary(dict_win, option);
143 if (value)
144 return value;
145 }
146
147 if (dict_name) {
148 value = WMGetFromPLDictionary(dict_name, option);
149 if (value)
150 return value;
151 }
152
153 if (dict_class) {
154 value = WMGetFromPLDictionary(dict_class, option);
155 if (value)
156 return value;
157 }
158
159 if (!useGlobalDefault)
160 return NULL;
161
162 if (dict_any) {
163 value = WMGetFromPLDictionary(dict_any, option);
164 if (value)
165 return value;
166 }
167
168 return default_value;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000169}
170
0261c326 dan1999-01-06 15:22:33 +0000171/*
172 *----------------------------------------------------------------------
173 * wDefaultFillAttributes--
174 * Retrieves attributes for the specified instance/class and
175 * fills attr with it. Values that are actually defined are also
176 * set in mask. If useGlobalDefault is True, the default for
177 * all windows ("*") will be used for when no values are found
6830b057 dan2004-10-12 21:28:27 +0000178 * for that instance/class.
179 *
0261c326 dan1999-01-06 15:22:33 +0000180 *----------------------------------------------------------------------
181 */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000182void
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200183wDefaultFillAttributes(WScreen * scr, char *instance, char *class,
184 WWindowAttributes * attr, WWindowAttributes * mask, Bool useGlobalDefault)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000185{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200186 WMPropList *value, *key1, *key2, *key3, *dw, *dc, *dn, *da;
187
188 if (class && instance) {
189 char *buffer;
190
191 buffer = wmalloc(strlen(class) + strlen(instance) + 2);
192 sprintf(buffer, "%s.%s", instance, class);
193 key1 = WMCreatePLString(buffer);
194 wfree(buffer);
195 } else {
196 key1 = NULL;
197 }
198
199 if (instance)
200 key2 = WMCreatePLString(instance);
201 else
202 key2 = NULL;
203
204 if (class)
205 key3 = WMCreatePLString(class);
206 else
207 key3 = NULL;
208
209 if (!ANoTitlebar) {
210 init_wdefaults(scr);
211 }
212
213 WMPLSetCaseSensitive(True);
214
215 if (WDWindowAttributes->dictionary) {
216 dw = key1 ? WMGetFromPLDictionary(WDWindowAttributes->dictionary, key1) : NULL;
217 dn = key2 ? WMGetFromPLDictionary(WDWindowAttributes->dictionary, key2) : NULL;
218 dc = key3 ? WMGetFromPLDictionary(WDWindowAttributes->dictionary, key3) : NULL;
219 if (useGlobalDefault)
220 da = WMGetFromPLDictionary(WDWindowAttributes->dictionary, AnyWindow);
221 else
222 da = NULL;
223 } else {
224 dw = NULL;
225 dn = NULL;
226 dc = NULL;
227 da = NULL;
228 }
229 if (key1)
230 WMReleasePropList(key1);
231 if (key2)
232 WMReleasePropList(key2);
233 if (key3)
234 WMReleasePropList(key3);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000235
0261c326 dan1999-01-06 15:22:33 +0000236#define APPLY_VAL(value, flag, attrib) \
6830b057 dan2004-10-12 21:28:27 +0000237 if (value) {attr->flag = getBool(attrib, value); \
238 if (mask) mask->flag = 1;}
0261c326 dan1999-01-06 15:22:33 +0000239
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200240 /* get the data */
241 value = get_value(dw, dc, dn, da, ANoTitlebar, No, useGlobalDefault);
242 APPLY_VAL(value, no_titlebar, ANoTitlebar);
672c42cc dan2001-12-17 04:02:33 +0000243
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200244 value = get_value(dw, dc, dn, da, ANoResizebar, No, useGlobalDefault);
245 APPLY_VAL(value, no_resizebar, ANoResizebar);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000246
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200247 value = get_value(dw, dc, dn, da, ANoMiniaturizeButton, No, useGlobalDefault);
248 APPLY_VAL(value, no_miniaturize_button, ANoMiniaturizeButton);
672c42cc dan2001-12-17 04:02:33 +0000249
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200250 value = get_value(dw, dc, dn, da, ANoCloseButton, No, useGlobalDefault);
251 APPLY_VAL(value, no_close_button, ANoCloseButton);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000252
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200253 value = get_value(dw, dc, dn, da, ANoBorder, No, useGlobalDefault);
254 APPLY_VAL(value, no_border, ANoBorder);
f2de1c9d kojima2000-01-14 16:30:56 +0000255
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200256 value = get_value(dw, dc, dn, da, ANoHideOthers, No, useGlobalDefault);
257 APPLY_VAL(value, no_hide_others, ANoHideOthers);
672c42cc dan2001-12-17 04:02:33 +0000258
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200259 value = get_value(dw, dc, dn, da, ANoMouseBindings, No, useGlobalDefault);
260 APPLY_VAL(value, no_bind_mouse, ANoMouseBindings);
672c42cc dan2001-12-17 04:02:33 +0000261
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200262 value = get_value(dw, dc, dn, da, ANoKeyBindings, No, useGlobalDefault);
263 APPLY_VAL(value, no_bind_keys, ANoKeyBindings);
672c42cc dan2001-12-17 04:02:33 +0000264
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200265 value = get_value(dw, dc, dn, da, ANoAppIcon, No, useGlobalDefault);
266 APPLY_VAL(value, no_appicon, ANoAppIcon);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000267
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200268 value = get_value(dw, dc, dn, da, ASharedAppIcon, No, useGlobalDefault);
269 APPLY_VAL(value, shared_appicon, ASharedAppIcon);
672c42cc dan2001-12-17 04:02:33 +0000270
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200271 value = get_value(dw, dc, dn, da, AKeepOnTop, No, useGlobalDefault);
272 APPLY_VAL(value, floating, AKeepOnTop);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000273
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200274 value = get_value(dw, dc, dn, da, AKeepOnBottom, No, useGlobalDefault);
275 APPLY_VAL(value, sunken, AKeepOnBottom);
9007a657 dan1998-11-23 11:32:19 +0000276
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200277 value = get_value(dw, dc, dn, da, AOmnipresent, No, useGlobalDefault);
278 APPLY_VAL(value, omnipresent, AOmnipresent);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000279
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200280 value = get_value(dw, dc, dn, da, ASkipWindowList, No, useGlobalDefault);
281 APPLY_VAL(value, skip_window_list, ASkipWindowList);
6830b057 dan2004-10-12 21:28:27 +0000282
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200283 value = get_value(dw, dc, dn, da, AKeepInsideScreen, No, useGlobalDefault);
284 APPLY_VAL(value, dont_move_off, AKeepInsideScreen);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000285
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200286 value = get_value(dw, dc, dn, da, AUnfocusable, No, useGlobalDefault);
287 APPLY_VAL(value, no_focusable, AUnfocusable);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000288
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200289 value = get_value(dw, dc, dn, da, AAlwaysUserIcon, No, useGlobalDefault);
290 APPLY_VAL(value, always_user_icon, AAlwaysUserIcon);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000291
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200292 value = get_value(dw, dc, dn, da, AStartMiniaturized, No, useGlobalDefault);
293 APPLY_VAL(value, start_miniaturized, AStartMiniaturized);
6830b057 dan2004-10-12 21:28:27 +0000294
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200295 value = get_value(dw, dc, dn, da, AStartHidden, No, useGlobalDefault);
296 APPLY_VAL(value, start_hidden, AStartHidden);
0261c326 dan1999-01-06 15:22:33 +0000297
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200298 value = get_value(dw, dc, dn, da, AStartMaximized, No, useGlobalDefault);
299 APPLY_VAL(value, start_maximized, AStartMaximized);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000300
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200301 value = get_value(dw, dc, dn, da, ADontSaveSession, No, useGlobalDefault);
302 APPLY_VAL(value, dont_save_session, ADontSaveSession);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000303
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200304 value = get_value(dw, dc, dn, da, AEmulateAppIcon, No, useGlobalDefault);
305 APPLY_VAL(value, emulate_appicon, AEmulateAppIcon);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000306
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200307 value = get_value(dw, dc, dn, da, AFullMaximize, No, useGlobalDefault);
308 APPLY_VAL(value, full_maximize, AFullMaximize);
088c0ac2 dan1999-03-09 14:58:01 +0000309
a43f369e id1999-05-29 15:45:19 +0000310#ifdef XKB_BUTTON_HINT
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200311 value = get_value(dw, dc, dn, da, ANoLanguageButton, No, useGlobalDefault);
312 APPLY_VAL(value, no_language_button, ANoLanguageButton);
a43f369e id1999-05-29 15:45:19 +0000313#endif
314
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200315 /* clean up */
316 WMPLSetCaseSensitive(False);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000317}
318
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200319WMPropList *get_generic_value(WScreen * scr, char *instance, char *class, WMPropList * option, Bool noDefault)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000320{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200321 WMPropList *value, *key, *dict;
6830b057 dan2004-10-12 21:28:27 +0000322
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200323 value = NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000324
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200325 WMPLSetCaseSensitive(True);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000326
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200327 if (class && instance) {
328 char *buffer;
8cb297a6 dan2001-10-10 18:52:14 +0000329
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200330 buffer = wmalloc(strlen(class) + strlen(instance) + 2);
331 sprintf(buffer, "%s.%s", instance, class);
332 key = WMCreatePLString(buffer);
333 wfree(buffer);
3c046182 kojima1999-09-16 02:58:56 +0000334
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200335 dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary, key);
336 WMReleasePropList(key);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000337
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200338 if (dict) {
339 value = WMGetFromPLDictionary(dict, option);
340 }
341 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000342
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200343 if (!value && instance) {
344 key = WMCreatePLString(instance);
6830b057 dan2004-10-12 21:28:27 +0000345
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200346 dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary, key);
347 WMReleasePropList(key);
348 if (dict) {
349 value = WMGetFromPLDictionary(dict, option);
350 }
351 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000352
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200353 if (!value && class) {
354 key = WMCreatePLString(class);
6830b057 dan2004-10-12 21:28:27 +0000355
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200356 dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary, key);
357 WMReleasePropList(key);
6830b057 dan2004-10-12 21:28:27 +0000358
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200359 if (dict) {
360 value = WMGetFromPLDictionary(dict, option);
361 }
362 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000363
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200364 if (!value && !noDefault) {
365 dict = WMGetFromPLDictionary(WDWindowAttributes->dictionary, AnyWindow);
6830b057 dan2004-10-12 21:28:27 +0000366
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200367 if (dict) {
368 value = WMGetFromPLDictionary(dict, option);
369 }
370 }
6830b057 dan2004-10-12 21:28:27 +0000371
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200372 WMPLSetCaseSensitive(False);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000373
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200374 return value;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000375}
376
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200377char *wDefaultGetIconFile(WScreen * scr, char *instance, char *class, Bool noDefault)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000378{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200379 WMPropList *value;
380 char *tmp;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000381
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200382 if (!ANoTitlebar) {
383 init_wdefaults(scr);
384 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000385
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200386 if (!WDWindowAttributes->dictionary)
387 return NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000388
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200389 value = get_generic_value(scr, instance, class, AIcon, noDefault);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000390
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200391 if (!value)
392 return NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000393
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200394 tmp = getString(AIcon, value);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000395
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200396 return tmp;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000397}
398
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200399RImage *wDefaultGetImage(WScreen * scr, char *winstance, char *wclass)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000400{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200401 char *file_name;
402 char *path;
403 RImage *image;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000404
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200405 file_name = wDefaultGetIconFile(scr, winstance, wclass, False);
406 if (!file_name)
407 return NULL;
6830b057 dan2004-10-12 21:28:27 +0000408
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200409 path = FindImage(wPreferences.icon_path, file_name);
6830b057 dan2004-10-12 21:28:27 +0000410
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200411 if (!path) {
412 wwarning(_("could not find icon file \"%s\""), file_name);
413 return NULL;
414 }
6830b057 dan2004-10-12 21:28:27 +0000415
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200416 image = RLoadImage(scr->rcontext, path, 0);
417 if (!image) {
418 wwarning(_("error loading image file \"%s\""), path, RMessageForError(RErrorCode));
419 }
420 wfree(path);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000421
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200422 image = wIconValidateIconSize(scr, image);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000423
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200424 return image;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000425}
426
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200427int wDefaultGetStartWorkspace(WScreen * scr, char *instance, char *class)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000428{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200429 WMPropList *value;
430 int w, i;
431 char *tmp;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000432
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200433 if (!ANoTitlebar) {
434 init_wdefaults(scr);
435 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000436
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200437 if (!WDWindowAttributes->dictionary)
438 return -1;
6830b057 dan2004-10-12 21:28:27 +0000439
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200440 value = get_generic_value(scr, instance, class, AStartWorkspace, False);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000441
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200442 if (!value)
443 return -1;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000444
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200445 tmp = getString(AStartWorkspace, value);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000446
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200447 if (!tmp || strlen(tmp) == 0)
448 return -1;
4a473b8a kojima1999-04-10 18:27:21 +0000449
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200450 if (sscanf(tmp, "%i", &w) != 1) {
451 w = -1;
452 for (i = 0; i < scr->workspace_count; i++) {
453 if (strcmp(scr->workspaces[i]->name, tmp) == 0) {
454 w = i;
455 break;
456 }
457 }
458 } else {
459 w--;
460 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000461
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200462 return w;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000463}
464
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200465void wDefaultChangeIcon(WScreen * scr, char *instance, char *class, char *file)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000466{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200467 WDDomain *db = WDWindowAttributes;
468 WMPropList *icon_value = NULL, *value, *attr, *key, *def_win, *def_icon = NULL;
469 WMPropList *dict = db->dictionary;
470 int same = 0;
471
472 if (!dict) {
473 dict = WMCreatePLDictionary(NULL, NULL);
474 if (dict) {
475 db->dictionary = dict;
476 } else {
477 return;
478 }
479 }
480
481 WMPLSetCaseSensitive(True);
482
483 if (instance && class) {
484 char *buffer;
485 buffer = wmalloc(strlen(instance) + strlen(class) + 2);
486 sprintf(buffer, "%s.%s", instance, class);
487 key = WMCreatePLString(buffer);
488 wfree(buffer);
489 } else if (instance) {
490 key = WMCreatePLString(instance);
491 } else if (class) {
492 key = WMCreatePLString(class);
493 } else {
494 key = WMRetainPropList(AnyWindow);
495 }
496
497 if (file) {
498 value = WMCreatePLString(file);
499 icon_value = WMCreatePLDictionary(AIcon, value, NULL);
500 WMReleasePropList(value);
501
502 if ((def_win = WMGetFromPLDictionary(dict, AnyWindow)) != NULL) {
503 def_icon = WMGetFromPLDictionary(def_win, AIcon);
504 }
505
506 if (def_icon && !strcmp(WMGetFromPLString(def_icon), file))
507 same = 1;
508 }
509
510 if ((attr = WMGetFromPLDictionary(dict, key)) != NULL) {
511 if (WMIsPLDictionary(attr)) {
512 if (icon_value != NULL && !same)
513 WMMergePLDictionaries(attr, icon_value, False);
514 else
515 WMRemoveFromPLDictionary(attr, AIcon);
516 }
517 } else if (icon_value != NULL && !same) {
518 WMPutInPLDictionary(dict, key, icon_value);
519 }
520 if (!wPreferences.flags.noupdates) {
521 UpdateDomainFile(db);
522 }
523
524 WMReleasePropList(key);
525 if (icon_value)
526 WMReleasePropList(icon_value);
527
528 WMPLSetCaseSensitive(False);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000529}
530
9d2e6ef9 scottc1998-09-29 22:36:29 +0000531/* --------------------------- Local ----------------------- */
532
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200533static int getBool(WMPropList * key, WMPropList * value)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000534{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200535 char *val;
536
537 if (!WMIsPLString(value)) {
538 wwarning(_("Wrong option format for key \"%s\". Should be %s."),
539 WMGetFromPLString(key), "Boolean");
540 return 0;
541 }
542 val = WMGetFromPLString(value);
543
544 if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y' || val[0] == 'T' || val[0] == 't' || val[0] == '1'))
545 || (strcasecmp(val, "YES") == 0 || strcasecmp(val, "TRUE") == 0)) {
546
547 return 1;
548 } else if ((val[1] == '\0'
549 && (val[0] == 'n' || val[0] == 'N' || val[0] == 'F' || val[0] == 'f' || val[0] == '0'))
550 || (strcasecmp(val, "NO") == 0 || strcasecmp(val, "FALSE") == 0)) {
551
552 return 0;
553 } else {
554 wwarning(_("can't convert \"%s\" to boolean"), val);
555 /* We return False if we can't convert to BOOLEAN.
556 * This is because all options defaults to False.
557 * -1 is not checked and thus is interpreted as True,
558 * which is not good.*/
559 return 0;
560 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000561}
562
6830b057 dan2004-10-12 21:28:27 +0000563/* WARNING: Do not free the value returned by this function!! */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200564static char *getString(WMPropList * key, WMPropList * value)
6830b057 dan2004-10-12 21:28:27 +0000565{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200566 if (!WMIsPLString(value)) {
567 wwarning(_("Wrong option format for key \"%s\". Should be %s."), WMGetFromPLString(key), "String");
568 return NULL;
569 }
6830b057 dan2004-10-12 21:28:27 +0000570
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200571 return WMGetFromPLString(value);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000572}