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