Mercurial > pidgin.yaz
annotate finch/libgnt/gntstyle.c @ 16473:5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
This changes the ~/.gntrc config for workspaces to the following format:
[Workspace-1]
name = blist
window-names = buddylist;debug-window
[Workspace-2]
name = im
window-names = conversation-window
window-titles = Preferences
[Workspace-3]
name = chats
window-titles = IRC;conference
author | Richard Nelson <wabz@pidgin.im> |
---|---|
date | Sun, 29 Apr 2007 00:37:28 +0000 |
parents | 4ea517cb7ceb |
children | 08776fc5c06f |
rev | line source |
---|---|
15818 | 1 #include "gntstyle.h" |
2 #include "gntcolors.h" | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
3 #include "gntws.h" |
15818 | 4 |
5 #include <ctype.h> | |
16473
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
6 #include <glib/gprintf.h> |
15818 | 7 #include <string.h> |
8 | |
16472
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16414
diff
changeset
|
9 #define MAX_WORKSPACES 99 |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16414
diff
changeset
|
10 |
15818 | 11 #if GLIB_CHECK_VERSION(2,6,0) |
12 static GKeyFile *gkfile; | |
13 #endif | |
14 | |
15 static char * str_styles[GNT_STYLES]; | |
16 static int int_styles[GNT_STYLES]; | |
17 static int bool_styles[GNT_STYLES]; | |
18 | |
19 const char *gnt_style_get(GntStyle style) | |
20 { | |
21 return str_styles[style]; | |
22 } | |
23 | |
24 gboolean gnt_style_get_bool(GntStyle style, gboolean def) | |
25 { | |
26 int i; | |
27 const char * str; | |
28 | |
29 if (bool_styles[style] != -1) | |
30 return bool_styles[style]; | |
31 | |
32 str = gnt_style_get(style); | |
33 | |
34 if (str) | |
35 { | |
36 if (strcmp(str, "false") == 0) | |
37 def = FALSE; | |
38 else if (strcmp(str, "true") == 0) | |
39 def = TRUE; | |
40 else if (sscanf(str, "%d", &i) == 1) | |
41 { | |
42 if (i) | |
43 def = TRUE; | |
44 else | |
45 def = FALSE; | |
46 } | |
47 } | |
48 | |
49 bool_styles[style] = def; | |
50 return bool_styles[style]; | |
51 } | |
52 | |
53 static void | |
54 refine(char *text) | |
55 { | |
56 char *s = text, *t = text; | |
57 | |
58 while (*s) | |
59 { | |
60 if (*s == '^' && *(s + 1) == '[') | |
61 { | |
62 *t = '\033'; /* escape */ | |
63 s++; | |
64 } | |
65 else if (*s == '\\') | |
66 { | |
67 if (*(s + 1) == '\0') | |
68 *t = ' '; | |
69 else | |
70 { | |
71 s++; | |
72 if (*s == 'r' || *s == 'n') | |
73 *t = '\r'; | |
74 else if (*s == 't') | |
75 *t = '\t'; | |
76 else | |
77 *t = *s; | |
78 } | |
79 } | |
80 else | |
81 *t = *s; | |
82 t++; | |
83 s++; | |
84 } | |
85 *t = '\0'; | |
86 } | |
87 | |
88 static char * | |
89 parse_key(const char *key) | |
90 { | |
91 return (char *)gnt_key_translate(key); | |
92 } | |
93 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
94 void gnt_style_read_workspaces(GntWM *wm) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
95 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
96 #if GLIB_CHECK_VERSION(2,6,0) |
16472
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16414
diff
changeset
|
97 int i; |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
98 gchar *name; |
16473
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
99 gsize c; |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
100 |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
101 for (i = 1; i < MAX_WORKSPACES; ++i) { |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
102 int j; |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
103 GntWS *ws; |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
104 gchar **titles; |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
105 char *group = calloc(12, 1); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
106 g_sprintf(group, "Workspace-%d", i); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
107 name = g_key_file_get_value(gkfile, group, "name", NULL); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
108 if (!name) |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
109 return; |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
110 |
16473
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
111 ws = g_object_new(GNT_TYPE_WS, NULL); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
112 gnt_ws_set_name(ws, name); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
113 gnt_wm_add_workspace(wm, ws); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
114 g_free(name); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
115 |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
116 titles = g_key_file_get_string_list(gkfile, group, "window-names", &c, NULL); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
117 if (titles) { |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
118 for (j = 0; j < c; ++j) |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
119 g_hash_table_replace(wm->name_places, g_strdup(titles[j]), ws); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
120 g_strfreev(titles); |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
121 } |
16473
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
122 |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
123 titles = g_key_file_get_string_list(gkfile, group, "window-titles", &c, NULL); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
124 if (titles) { |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
125 for (j = 0; j < c; ++j) |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
126 g_hash_table_replace(wm->title_places, g_strdup(titles[j]), ws); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
127 g_strfreev(titles); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
128 } |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
16472
diff
changeset
|
129 g_free(group); |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
130 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
131 #endif |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
132 } |
15818 | 133 void gnt_style_read_actions(GType type, GntBindableClass *klass) |
134 { | |
135 #if GLIB_CHECK_VERSION(2,6,0) | |
136 char *name; | |
137 GError *error = NULL; | |
138 | |
139 name = g_strdup_printf("%s::binding", g_type_name(type)); | |
140 | |
141 if (g_key_file_has_group(gkfile, name)) | |
142 { | |
143 gsize len = 0; | |
144 char **keys; | |
145 | |
146 keys = g_key_file_get_keys(gkfile, name, &len, &error); | |
147 if (error) | |
148 { | |
149 g_printerr("GntStyle: %s\n", error->message); | |
150 g_error_free(error); | |
151 g_free(name); | |
152 return; | |
153 } | |
154 | |
155 while (len--) | |
156 { | |
157 char *key, *action; | |
158 | |
159 key = g_strdup(keys[len]); | |
160 action = g_key_file_get_string(gkfile, name, keys[len], &error); | |
161 | |
162 if (error) | |
163 { | |
164 g_printerr("GntStyle: %s\n", error->message); | |
165 g_error_free(error); | |
166 error = NULL; | |
167 } | |
168 else | |
169 { | |
170 const char *keycode = parse_key(key); | |
171 if (keycode == NULL) { | |
172 g_printerr("GntStyle: Invalid key-binding %s\n", key); | |
173 } else { | |
174 gnt_bindable_register_binding(klass, action, keycode, NULL); | |
175 } | |
176 } | |
177 g_free(key); | |
178 g_free(action); | |
179 } | |
180 g_strfreev(keys); | |
181 } | |
182 g_free(name); | |
183 #endif | |
184 } | |
185 | |
186 void gnt_styles_get_keyremaps(GType type, GHashTable *hash) | |
187 { | |
188 #if GLIB_CHECK_VERSION(2,6,0) | |
189 char *name; | |
190 GError *error = NULL; | |
191 | |
192 name = g_strdup_printf("%s::remap", g_type_name(type)); | |
193 | |
194 if (g_key_file_has_group(gkfile, name)) | |
195 { | |
196 gsize len = 0; | |
197 char **keys; | |
198 | |
199 keys = g_key_file_get_keys(gkfile, name, &len, &error); | |
200 if (error) | |
201 { | |
202 g_printerr("GntStyle: %s\n", error->message); | |
203 g_error_free(error); | |
204 g_free(name); | |
205 return; | |
206 } | |
207 | |
208 while (len--) | |
209 { | |
210 char *key, *replace; | |
211 | |
212 key = g_strdup(keys[len]); | |
213 replace = g_key_file_get_string(gkfile, name, keys[len], &error); | |
214 | |
215 if (error) | |
216 { | |
217 g_printerr("GntStyle: %s\n", error->message); | |
218 g_error_free(error); | |
219 error = NULL; | |
220 g_free(key); | |
221 } | |
222 else | |
223 { | |
224 refine(key); | |
225 refine(replace); | |
226 g_hash_table_insert(hash, key, replace); | |
227 } | |
228 } | |
229 g_strfreev(keys); | |
230 } | |
231 | |
232 g_free(name); | |
233 #endif | |
234 } | |
235 | |
236 #if GLIB_CHECK_VERSION(2,6,0) | |
237 static void | |
238 read_general_style(GKeyFile *kfile) | |
239 { | |
240 GError *error = NULL; | |
241 gsize nkeys; | |
242 char **keys = g_key_file_get_keys(kfile, "general", &nkeys, &error); | |
243 int i; | |
244 struct | |
245 { | |
246 const char *style; | |
247 GntStyle en; | |
248 } styles[] = {{"shadow", GNT_STYLE_SHADOW}, | |
249 {"customcolor", GNT_STYLE_COLOR}, | |
250 {"mouse", GNT_STYLE_MOUSE}, | |
251 {"wm", GNT_STYLE_WM}, | |
252 {"remember_position", GNT_STYLE_REMPOS}, | |
253 {NULL, 0}}; | |
254 | |
255 if (error) | |
256 { | |
257 g_printerr("GntStyle: %s\n", error->message); | |
258 g_error_free(error); | |
259 } | |
260 else | |
261 { | |
262 for (i = 0; styles[i].style; i++) | |
263 { | |
264 str_styles[styles[i].en] = | |
15964 | 265 g_key_file_get_string(kfile, "general", styles[i].style, NULL); |
15818 | 266 } |
267 } | |
268 g_strfreev(keys); | |
269 } | |
270 #endif | |
271 | |
272 void gnt_style_read_configure_file(const char *filename) | |
273 { | |
274 #if GLIB_CHECK_VERSION(2,6,0) | |
275 GError *error = NULL; | |
276 gkfile = g_key_file_new(); | |
277 | |
278 if (!g_key_file_load_from_file(gkfile, filename, G_KEY_FILE_NONE, &error)) | |
279 { | |
280 g_printerr("GntStyle: %s\n", error->message); | |
281 g_error_free(error); | |
282 return; | |
283 } | |
284 gnt_colors_parse(gkfile); | |
285 read_general_style(gkfile); | |
286 #endif | |
287 } | |
288 | |
289 void gnt_init_styles() | |
290 { | |
291 int i; | |
292 for (i = 0; i < GNT_STYLES; i++) | |
293 { | |
294 str_styles[i] = NULL; | |
295 int_styles[i] = -1; | |
296 bool_styles[i] = -1; | |
297 } | |
298 } | |
299 | |
300 void gnt_uninit_styles() | |
301 { | |
302 int i; | |
303 for (i = 0; i < GNT_STYLES; i++) | |
304 g_free(str_styles[i]); | |
305 | |
306 #if GLIB_CHECK_VERSION(2,6,0) | |
307 g_key_file_free(gkfile); | |
308 #endif | |
309 } | |
310 |