Mercurial > geeqie
annotate src/fullscreen.c @ 1808:6c61c246506b
Fix a small issue with strptime
strptime do not initialize all fields. So the undefined fields could end
in crash later on.
author | mow |
---|---|
date | Sun, 28 Feb 2010 15:17:12 +0000 |
parents | 956aab097ea7 |
children |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
1802 | 4 * Copyright (C) 2008 - 2010 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
13 | |
281 | 14 #include "main.h" |
9 | 15 #include "fullscreen.h" |
16 | |
17 #include "image.h" | |
1144
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
18 #include "misc.h" |
9 | 19 #include "ui_fileops.h" |
20 #include "ui_menu.h" | |
21 #include "ui_misc.h" | |
648
e34c1002e553
Move some functions from main.[ch] to new window.[ch].
zas_
parents:
512
diff
changeset
|
22 #include "window.h" |
1011 | 23 #include "image-load.h" |
9 | 24 |
25 enum { | |
26 FULLSCREEN_CURSOR_HIDDEN = 1 << 0, | |
27 FULLSCREEN_CURSOR_NORMAL = 1 << 1, | |
28 FULLSCREEN_CURSOR_BUSY = 1 << 2 | |
29 }; | |
30 | |
31 | |
32 /* | |
33 *---------------------------------------------------------------------------- | |
34 * full screen functions | |
35 *---------------------------------------------------------------------------- | |
36 */ | |
37 | |
38 static void clear_mouse_cursor(GtkWidget *widget, gint state) | |
39 { | |
40 if (!widget->window) return; | |
41 | |
42 if (state & FULLSCREEN_CURSOR_BUSY) | |
43 { | |
44 GdkCursor *cursor; | |
45 | |
46 cursor = gdk_cursor_new(GDK_WATCH); | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
507
diff
changeset
|
47 gdk_window_set_cursor(widget->window, cursor); |
9 | 48 gdk_cursor_unref(cursor); |
49 } | |
50 else if (state & FULLSCREEN_CURSOR_NORMAL) | |
51 { | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
507
diff
changeset
|
52 gdk_window_set_cursor(widget->window, NULL); |
9 | 53 } |
54 else | |
55 { | |
56 GdkCursor *cursor; | |
57 GdkPixmap *p; | |
58 | |
59 p = gdk_bitmap_create_from_data(widget->window, "\0\0\0", 1, 1); | |
60 | |
61 cursor = gdk_cursor_new_from_pixmap(p, p, | |
62 &widget->style->fg[GTK_STATE_ACTIVE], | |
63 &widget->style->bg[GTK_STATE_ACTIVE], | |
64 0, 0); | |
65 | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
507
diff
changeset
|
66 gdk_window_set_cursor(widget->window, cursor); |
9 | 67 |
68 gdk_cursor_unref(cursor); | |
69 g_object_unref(p); | |
70 } | |
71 } | |
72 | |
1431 | 73 static gboolean fullscreen_hide_mouse_cb(gpointer data) |
9 | 74 { |
75 FullScreenData *fs = data; | |
76 | |
1523 | 77 if (!fs->hide_mouse_id) return FALSE; |
9 | 78 |
79 fs->cursor_state &= ~FULLSCREEN_CURSOR_NORMAL; | |
80 if (!(fs->cursor_state & FULLSCREEN_CURSOR_BUSY)) clear_mouse_cursor(fs->window, fs->cursor_state); | |
81 | |
1523 | 82 g_source_remove(fs->hide_mouse_id); |
83 fs->hide_mouse_id = 0; | |
9 | 84 return FALSE; |
85 } | |
86 | |
87 static void fullscreen_hide_mouse_disable(FullScreenData *fs) | |
88 { | |
1523 | 89 if (fs->hide_mouse_id) |
9 | 90 { |
91 g_source_remove(fs->hide_mouse_id); | |
1523 | 92 fs->hide_mouse_id = 0; |
9 | 93 } |
94 } | |
95 | |
96 static void fullscreen_hide_mouse_reset(FullScreenData *fs) | |
97 { | |
98 fullscreen_hide_mouse_disable(fs); | |
99 fs->hide_mouse_id = g_timeout_add(FULL_SCREEN_HIDE_MOUSE_DELAY, fullscreen_hide_mouse_cb, fs); | |
100 } | |
101 | |
1431 | 102 static gboolean fullscreen_mouse_moved(GtkWidget *widget, GdkEventButton *bevent, gpointer data) |
9 | 103 { |
104 FullScreenData *fs = data; | |
105 | |
106 if (!(fs->cursor_state & FULLSCREEN_CURSOR_NORMAL)) | |
107 { | |
108 fs->cursor_state |= FULLSCREEN_CURSOR_NORMAL; | |
109 if (!(fs->cursor_state & FULLSCREEN_CURSOR_BUSY)) clear_mouse_cursor(fs->window, fs->cursor_state); | |
110 } | |
111 fullscreen_hide_mouse_reset(fs); | |
112 | |
113 return FALSE; | |
114 } | |
115 | |
116 static void fullscreen_busy_mouse_disable(FullScreenData *fs) | |
117 { | |
1523 | 118 if (fs->busy_mouse_id) |
9 | 119 { |
120 g_source_remove(fs->busy_mouse_id); | |
1523 | 121 fs->busy_mouse_id = 0; |
9 | 122 } |
123 } | |
124 | |
1431 | 125 static void fullscreen_mouse_set_busy(FullScreenData *fs, gboolean busy) |
9 | 126 { |
127 fullscreen_busy_mouse_disable(fs); | |
128 | |
1431 | 129 if (!!(fs->cursor_state & FULLSCREEN_CURSOR_BUSY) == (busy)) return; |
9 | 130 |
131 if (busy) | |
132 { | |
133 fs->cursor_state |= FULLSCREEN_CURSOR_BUSY; | |
134 } | |
135 else | |
136 { | |
137 fs->cursor_state &= ~FULLSCREEN_CURSOR_BUSY; | |
138 } | |
139 | |
140 clear_mouse_cursor(fs->window, fs->cursor_state); | |
141 } | |
142 | |
143 static gboolean fullscreen_mouse_set_busy_cb(gpointer data) | |
144 { | |
145 FullScreenData *fs = data; | |
146 | |
1523 | 147 fs->busy_mouse_id = 0; |
9 | 148 fullscreen_mouse_set_busy(fs, TRUE); |
149 return FALSE; | |
150 } | |
151 | |
152 static void fullscreen_mouse_set_busy_idle(FullScreenData *fs) | |
153 { | |
1523 | 154 if (!fs->busy_mouse_id) |
9 | 155 { |
156 fs->busy_mouse_id = g_timeout_add(FULL_SCREEN_BUSY_MOUSE_DELAY, | |
157 fullscreen_mouse_set_busy_cb, fs); | |
158 } | |
159 } | |
160 | |
161 static void fullscreen_image_update_cb(ImageWindow *imd, gpointer data) | |
162 { | |
163 FullScreenData *fs = data; | |
164 | |
165 if (fs->imd->il && | |
1011 | 166 image_loader_get_pixbuf(fs->imd->il) != image_get_pixbuf(fs->imd)) |
9 | 167 { |
168 fullscreen_mouse_set_busy_idle(fs); | |
169 } | |
170 } | |
171 | |
1431 | 172 static void fullscreen_image_complete_cb(ImageWindow *imd, gboolean preload, gpointer data) |
9 | 173 { |
174 FullScreenData *fs = data; | |
175 | |
176 if (!preload) fullscreen_mouse_set_busy(fs, FALSE); | |
177 } | |
178 | |
179 #define XSCREENSAVER_BINARY "xscreensaver-command" | |
180 #define XSCREENSAVER_COMMAND "xscreensaver-command -deactivate >&- 2>&- &" | |
181 | |
182 static void fullscreen_saver_deactivate(void) | |
183 { | |
1437 | 184 static gboolean checked = FALSE; |
185 static gboolean found = FALSE; | |
9 | 186 |
187 if (!checked) | |
188 { | |
189 checked = TRUE; | |
190 found = file_in_path(XSCREENSAVER_BINARY); | |
191 } | |
192 | |
193 if (found) | |
194 { | |
1144
5fe3b8b3a612
Add a wrapper around system() call named runcmd() which allows easier debugging. Improve the code launching the help browser.
zas_
parents:
1055
diff
changeset
|
195 runcmd(XSCREENSAVER_COMMAND); |
9 | 196 } |
197 } | |
198 | |
199 static gboolean fullscreen_saver_block_cb(gpointer data) | |
200 { | |
322 | 201 if (options->fullscreen.disable_saver) |
9 | 202 { |
203 fullscreen_saver_deactivate(); | |
204 } | |
205 | |
206 return TRUE; | |
207 } | |
208 | |
1431 | 209 static gboolean fullscreen_delete_cb(GtkWidget *widget, GdkEventAny *event, gpointer data) |
9 | 210 { |
211 FullScreenData *fs = data; | |
212 | |
213 fullscreen_stop(fs); | |
214 return TRUE; | |
215 } | |
216 | |
217 FullScreenData *fullscreen_start(GtkWidget *window, ImageWindow *imd, | |
218 void (*stop_func)(FullScreenData *, gpointer), gpointer stop_data) | |
219 { | |
220 FullScreenData *fs; | |
221 GdkScreen *screen; | |
1431 | 222 gboolean same; |
9 | 223 gint x, y; |
224 gint w, h; | |
225 GdkGeometry geometry; | |
226 | |
227 if (!window || !imd) return NULL; | |
228 | |
229 fs = g_new0(FullScreenData, 1); | |
230 | |
231 fs->cursor_state = FULLSCREEN_CURSOR_HIDDEN; | |
232 | |
233 fs->normal_window = window; | |
234 fs->normal_imd = imd; | |
235 | |
236 fs->stop_func = stop_func; | |
237 fs->stop_data = stop_data; | |
238 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
239 DEBUG_1("full screen requests screen %d", options->fullscreen.screen); |
322 | 240 fullscreen_prefs_get_geometry(options->fullscreen.screen, window, &x, &y, &w, &h, |
9 | 241 &screen, &same); |
242 | |
289
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
243 fs->window = window_new(GTK_WINDOW_TOPLEVEL, "fullscreen", NULL, NULL, _("Full screen")); |
9 | 244 |
245 /* this requests no decorations, if you still have them complain to the window manager author(s) */ | |
246 gtk_window_set_decorated(GTK_WINDOW(fs->window), FALSE); | |
247 | |
322 | 248 if (options->fullscreen.screen < 0) |
9 | 249 { |
250 /* If we want control of the window size and position this is not what we want. | |
196 | 251 * Geeqie needs control of which monitor(s) to use for full screen. |
9 | 252 */ |
253 gtk_window_fullscreen(GTK_WINDOW(fs->window)); | |
254 } | |
322 | 255 else if (options->fullscreen.above) |
9 | 256 { |
257 /* request to be above other windows */ | |
258 gtk_window_set_keep_above(GTK_WINDOW(fs->window), TRUE); | |
259 } | |
260 | |
261 gtk_window_set_resizable(GTK_WINDOW(fs->window), FALSE); | |
262 | |
263 gtk_window_set_screen(GTK_WINDOW(fs->window), screen); | |
264 gtk_container_set_border_width(GTK_CONTAINER(fs->window), 0); | |
265 g_signal_connect(G_OBJECT(fs->window), "delete_event", | |
266 G_CALLBACK(fullscreen_delete_cb), fs); | |
267 | |
268 geometry.min_width = w; | |
269 geometry.min_height = h; | |
270 geometry.max_width = w; | |
271 geometry.max_height = h; | |
272 geometry.base_width = w; | |
273 geometry.base_height = h; | |
274 geometry.win_gravity = GDK_GRAVITY_STATIC; | |
275 /* By setting USER_POS and USER_SIZE, most window managers will | |
276 * not request positioning of the full screen window (for example twm). | |
277 * | |
278 * In addition, setting gravity to STATIC will result in the | |
279 * decorations of twm to not effect the requested window position, | |
280 * the decorations will simply be off screen, except in multi monitor setups :-/ | |
281 */ | |
282 gtk_window_set_geometry_hints(GTK_WINDOW(fs->window), fs->window, &geometry, | |
283 GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_BASE_SIZE | | |
284 GDK_HINT_WIN_GRAVITY | | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
285 GDK_HINT_USER_POS); |
9 | 286 |
287 gtk_window_set_default_size(GTK_WINDOW(fs->window), w, h); | |
288 gtk_window_move(GTK_WINDOW(fs->window), x, y); | |
289 | |
290 fs->imd = image_new(FALSE); | |
291 | |
292 gtk_container_add(GTK_CONTAINER(fs->window), fs->imd->widget); | |
293 | |
1626
1d7941c147be
Add an option to Image preferences to restrict custom border to fullscreen mode only. Bug 2798062.
zas_
parents:
1523
diff
changeset
|
294 image_background_set_color_from_options(fs->imd, TRUE); |
322 | 295 image_set_delay_flip(fs->imd, options->fullscreen.clean_flip); |
888 | 296 image_auto_refresh_enable(fs->imd, fs->normal_imd->auto_refresh); |
9 | 297 |
322 | 298 if (options->fullscreen.clean_flip) |
9 | 299 { |
300 image_set_update_func(fs->imd, fullscreen_image_update_cb, fs); | |
301 image_set_complete_func(fs->imd, fullscreen_image_complete_cb, fs); | |
302 } | |
303 | |
304 gtk_widget_show(fs->imd->widget); | |
305 | |
306 image_change_from_image(fs->imd, fs->normal_imd); | |
307 | |
308 gtk_widget_show(fs->window); | |
309 | |
310 /* for hiding the mouse */ | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
311 g_signal_connect(G_OBJECT(fs->imd->pr), "motion_notify_event", |
9 | 312 G_CALLBACK(fullscreen_mouse_moved), fs); |
313 clear_mouse_cursor(fs->window, fs->cursor_state); | |
314 | |
315 /* set timer to block screen saver */ | |
316 fs->saver_block_id = g_timeout_add(60 * 1000, fullscreen_saver_block_cb, fs); | |
317 | |
318 /* hide normal window | |
319 * FIXME: properly restore this window on show | |
320 */ | |
321 #ifdef HIDE_WINDOW_IN_FULLSCREEN | |
322 gtk_widget_hide(fs->normal_window); | |
323 #endif | |
138 | 324 image_change_fd(fs->normal_imd, NULL, image_zoom_get(fs->normal_imd)); |
9 | 325 |
326 return fs; | |
327 } | |
328 | |
329 void fullscreen_stop(FullScreenData *fs) | |
330 { | |
331 if (!fs) return; | |
332 | |
1523 | 333 if (fs->saver_block_id) g_source_remove(fs->saver_block_id); |
9 | 334 |
335 fullscreen_hide_mouse_disable(fs); | |
336 fullscreen_busy_mouse_disable(fs); | |
337 gdk_keyboard_ungrab(GDK_CURRENT_TIME); | |
338 | |
339 image_change_from_image(fs->normal_imd, fs->imd); | |
340 #ifdef HIDE_WINDOW_IN_FULLSCREEN | |
341 gtk_widget_show(fs->normal_window); | |
342 #endif | |
343 if (fs->stop_func) fs->stop_func(fs, fs->stop_data); | |
344 | |
345 gtk_widget_destroy(fs->window); | |
346 | |
347 g_free(fs); | |
348 } | |
349 | |
350 | |
351 /* | |
352 *---------------------------------------------------------------------------- | |
353 * full screen preferences and utils | |
354 *---------------------------------------------------------------------------- | |
355 */ | |
356 | |
357 GList *fullscreen_prefs_list(void) | |
358 { | |
359 GList *list = NULL; | |
360 GdkDisplay *display; | |
361 gint number; | |
362 gint i; | |
363 | |
364 display = gdk_display_get_default(); | |
365 number = gdk_display_get_n_screens(display); | |
366 | |
995 | 367 for (i = 0; i < number; i++) |
9 | 368 { |
369 GdkScreen *screen; | |
370 gint monitors; | |
371 gint j; | |
372 | |
373 screen = gdk_display_get_screen(display, i); | |
374 monitors = gdk_screen_get_n_monitors(screen); | |
375 | |
376 for (j = -1; j < monitors; j++) | |
377 { | |
378 ScreenData *sd; | |
379 GdkRectangle rect; | |
380 gchar *name; | |
381 gchar *subname; | |
382 | |
383 name = gdk_screen_make_display_name(screen); | |
384 | |
385 if (j < 0) | |
386 { | |
387 rect.x = 0; | |
388 rect.y = 0; | |
389 rect.width = gdk_screen_get_width(screen); | |
390 rect.height = gdk_screen_get_height(screen); | |
391 subname = g_strdup(_("Full size")); | |
392 } | |
393 else | |
394 { | |
395 gdk_screen_get_monitor_geometry(screen, j, &rect); | |
396 subname = g_strdup_printf("%s %d", _("Monitor"), j + 1); | |
397 } | |
398 | |
399 sd = g_new0(ScreenData, 1); | |
400 sd->number = (i+1) * 100 + j + 1; | |
401 sd->description = g_strdup_printf("%s %s, %s", _("Screen"), name, subname); | |
402 sd->x = rect.x; | |
403 sd->y = rect.y; | |
404 sd->width = rect.width; | |
405 sd->height = rect.height; | |
406 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
407 DEBUG_1("Screen %d %30s %4d,%4d (%4dx%4d)", |
9 | 408 sd->number, sd->description, sd->x, sd->y, sd->width, sd->height); |
409 | |
410 list = g_list_append(list, sd); | |
411 | |
412 g_free(name); | |
413 g_free(subname); | |
414 } | |
415 } | |
416 | |
417 return list; | |
418 } | |
419 | |
420 void fullscreen_prefs_list_free(GList *list) | |
421 { | |
422 GList *work; | |
423 | |
424 work = list; | |
425 while (work) | |
426 { | |
427 ScreenData *sd = work->data; | |
428 work = work->next; | |
429 | |
442 | 430 g_free(sd->description); |
9 | 431 g_free(sd); |
432 } | |
433 | |
434 g_list_free(list); | |
435 } | |
436 | |
437 ScreenData *fullscreen_prefs_list_find(GList *list, gint screen) | |
438 { | |
439 GList *work; | |
440 | |
441 work = list; | |
442 while (work) | |
443 { | |
444 ScreenData *sd = work->data; | |
445 work = work->next; | |
446 | |
447 if (sd->number == screen) return sd; | |
448 } | |
449 | |
450 return NULL; | |
451 } | |
452 | |
453 /* screen is interpreted as such: | |
454 * -1 window manager determines size and position, fallback is (1) active monitor | |
455 * 0 full size of screen containing widget | |
456 * 1 size of monitor containing widget | |
457 * 100 full size of screen 1 (screen, monitor counts start at 1) | |
458 * 101 size of monitor 1 on screen 1 | |
459 * 203 size of monitor 3 on screen 2 | |
460 * returns: | |
461 * dest_screen: screen to place widget [use gtk_window_set_screen()] | |
462 * same_region: the returned region will overlap the current location of widget. | |
463 */ | |
464 void fullscreen_prefs_get_geometry(gint screen, GtkWidget *widget, gint *x, gint *y, gint *width, gint *height, | |
1431 | 465 GdkScreen **dest_screen, gboolean *same_region) |
9 | 466 { |
467 GList *list; | |
468 ScreenData *sd; | |
469 | |
470 list = fullscreen_prefs_list(); | |
471 if (screen >= 100) | |
472 { | |
473 sd = fullscreen_prefs_list_find(list, screen); | |
474 } | |
475 else | |
476 { | |
477 sd = NULL; | |
478 if (screen < 0) screen = 1; | |
479 } | |
480 | |
481 if (sd) | |
482 { | |
483 GdkDisplay *display; | |
484 GdkScreen *screen; | |
485 gint n; | |
486 | |
487 display = gdk_display_get_default(); | |
488 n = sd->number / 100 - 1; | |
489 if (n >= 0 && n < gdk_display_get_n_screens(display)) | |
490 { | |
491 screen = gdk_display_get_screen(display, n); | |
492 } | |
493 else | |
494 { | |
495 screen = gdk_display_get_default_screen(display); | |
496 } | |
497 | |
498 if (x) *x = sd->x; | |
499 if (y) *y = sd->y; | |
500 if (width) *width = sd->width; | |
501 if (height) *height = sd->height; | |
502 | |
503 if (dest_screen) *dest_screen = screen; | |
504 if (same_region) *same_region = (!widget || !widget->window || | |
505 (screen == gtk_widget_get_screen(widget) && | |
506 (sd->number%100 == 0 || | |
507 sd->number%100 == gdk_screen_get_monitor_at_window(screen, widget->window)+1))); | |
508 | |
509 } | |
510 else if (screen != 1 || !widget || !widget->window) | |
511 { | |
512 GdkScreen *screen; | |
513 | |
514 if (widget) | |
515 { | |
516 screen = gtk_widget_get_screen(widget); | |
517 } | |
518 else | |
519 { | |
520 screen = gdk_screen_get_default(); | |
521 } | |
522 | |
523 if (x) *x = 0; | |
524 if (y) *y = 0; | |
525 if (width) *width = gdk_screen_get_width(screen); | |
526 if (height) *height = gdk_screen_get_height(screen); | |
527 | |
528 if (dest_screen) *dest_screen = screen; | |
529 if (same_region) *same_region = TRUE; | |
530 } | |
531 else | |
532 { | |
533 GdkScreen *screen; | |
534 gint monitor; | |
535 GdkRectangle rect; | |
536 | |
537 screen = gtk_widget_get_screen(widget); | |
538 monitor = gdk_screen_get_monitor_at_window(screen, widget->window); | |
539 | |
540 gdk_screen_get_monitor_geometry(screen, monitor, &rect); | |
541 | |
542 if (x) *x = rect.x; | |
543 if (y) *y = rect.y; | |
544 if (width) *width = rect.width; | |
545 if (height) *height = rect.height; | |
546 | |
547 if (dest_screen) *dest_screen = screen; | |
548 if (same_region) *same_region = TRUE; | |
549 } | |
550 | |
551 fullscreen_prefs_list_free(list); | |
552 } | |
553 | |
554 gint fullscreen_prefs_find_screen_for_widget(GtkWidget *widget) | |
555 { | |
556 GdkScreen *screen; | |
557 gint monitor; | |
558 gint n; | |
559 | |
560 if (!widget || !widget->window) return 0; | |
561 | |
562 screen = gtk_widget_get_screen(widget); | |
563 monitor = gdk_screen_get_monitor_at_window(screen, widget->window); | |
564 | |
565 n = (gdk_screen_get_number(screen)+1) * 100 + monitor + 1; | |
566 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
567 DEBUG_1("Screen appears to be %d", n); |
9 | 568 |
569 return n; | |
570 } | |
571 | |
572 enum { | |
573 FS_MENU_COLUMN_NAME = 0, | |
574 FS_MENU_COLUMN_VALUE | |
575 }; | |
576 | |
577 #define BUTTON_ABOVE_KEY "button_above" | |
578 | |
579 static void fullscreen_prefs_selection_cb(GtkWidget *combo, gpointer data) | |
580 { | |
581 gint *value = data; | |
582 GtkTreeModel *store; | |
583 GtkTreeIter iter; | |
584 GtkWidget *button; | |
585 | |
586 if (!value) return; | |
587 | |
588 store = gtk_combo_box_get_model(GTK_COMBO_BOX(combo)); | |
589 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) return; | |
590 gtk_tree_model_get(store, &iter, FS_MENU_COLUMN_VALUE, value, -1); | |
591 | |
592 button = g_object_get_data(G_OBJECT(combo), BUTTON_ABOVE_KEY); | |
593 if (button) | |
594 { | |
595 gtk_widget_set_sensitive(button, *value != -1); | |
596 } | |
597 } | |
598 | |
599 static void fullscreen_prefs_selection_add(GtkListStore *store, const gchar *text, gint value) | |
600 { | |
601 GtkTreeIter iter; | |
602 | |
603 gtk_list_store_append(store, &iter); | |
604 gtk_list_store_set(store, &iter, FS_MENU_COLUMN_NAME, text, | |
605 FS_MENU_COLUMN_VALUE, value, -1); | |
606 } | |
607 | |
1431 | 608 GtkWidget *fullscreen_prefs_selection_new(const gchar *text, gint *screen_value, gboolean *above_value) |
9 | 609 { |
610 GtkWidget *vbox; | |
611 GtkWidget *hbox; | |
612 GtkWidget *combo; | |
613 GtkListStore *store; | |
614 GtkCellRenderer *renderer; | |
615 GtkWidget *button = NULL; | |
616 GList *list; | |
617 GList *work; | |
618 gint current = 0; | |
619 gint n; | |
620 | |
621 if (!screen_value) return NULL; | |
622 | |
623 vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP); | |
624 hbox = pref_box_new(vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE); | |
625 if (text) pref_label_new(hbox, text); | |
626 | |
627 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); | |
628 combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); | |
629 g_object_unref(store); | |
630 | |
631 renderer = gtk_cell_renderer_text_new(); | |
632 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, TRUE); | |
633 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), renderer, | |
634 "text", FS_MENU_COLUMN_NAME, NULL); | |
635 | |
636 if (above_value) | |
637 { | |
638 button = pref_checkbox_new_int(vbox, _("Stay above other windows"), | |
639 *above_value, above_value); | |
640 gtk_widget_set_sensitive(button, *screen_value != -1); | |
641 | |
642 g_object_set_data(G_OBJECT(combo), BUTTON_ABOVE_KEY, button); | |
643 } | |
644 | |
645 fullscreen_prefs_selection_add(store, _("Determined by Window Manager"), -1); | |
646 fullscreen_prefs_selection_add(store, _("Active screen"), 0); | |
647 if (*screen_value == 0) current = 1; | |
648 fullscreen_prefs_selection_add(store, _("Active monitor"), 1); | |
649 if (*screen_value == 1) current = 2; | |
650 | |
651 n = 3; | |
652 list = fullscreen_prefs_list(); | |
653 work = list; | |
654 while (work) | |
655 { | |
656 ScreenData *sd = work->data; | |
657 | |
658 fullscreen_prefs_selection_add(store, sd->description, sd->number); | |
659 if (*screen_value == sd->number) current = n; | |
660 | |
661 work = work->next; | |
662 n++; | |
663 } | |
664 fullscreen_prefs_list_free(list); | |
665 | |
666 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), current); | |
667 | |
668 gtk_box_pack_start(GTK_BOX(hbox), combo, FALSE, FALSE, 0); | |
669 gtk_widget_show(combo); | |
670 | |
671 g_signal_connect(G_OBJECT(combo), "changed", | |
672 G_CALLBACK(fullscreen_prefs_selection_cb), screen_value); | |
673 | |
674 return vbox; | |
675 } | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1011
diff
changeset
|
676 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |