Pull the search UI construction code out into a distinct function.
[geeqie.git] / src / fullscreen.c
index b90e895..4ae884c 100644 (file)
@@ -1,16 +1,24 @@
 /*
- * Geeqie
- * (C) 2004 John Ellis
- * Copyright (C) 2008 - 2012 The Geeqie Team
+ * Copyright (C) 2004 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
  * Author: John Ellis
  *
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * 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 "main.h"
 #include "fullscreen.h"
 
@@ -55,7 +63,7 @@ static void clear_mouse_cursor(GtkWidget *widget, gint state)
        else
                {
                GdkCursor *cursor;
-               
+
                cursor = gdk_cursor_new(GDK_BLANK_CURSOR);
                gdk_window_set_cursor(window, cursor);
                gdk_cursor_unref(cursor);
@@ -91,7 +99,7 @@ static void fullscreen_hide_mouse_reset(FullScreenData *fs)
        fs->hide_mouse_id = g_timeout_add(FULL_SCREEN_HIDE_MOUSE_DELAY, fullscreen_hide_mouse_cb, fs);
 }
 
-static gboolean fullscreen_mouse_moved(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
+static gboolean fullscreen_mouse_moved(GtkWidget *widget, GdkEventMotion *event, gpointer data)
 {
        FullScreenData *fs = data;
 
@@ -211,11 +219,9 @@ FullScreenData *fullscreen_start(GtkWidget *window, ImageWindow *imd,
 {
        FullScreenData *fs;
        GdkScreen *screen;
-       gboolean same;
        gint x, y;
        gint w, h;
        GdkGeometry geometry;
-       GdkWindow *gdkwin;
 
        if (!window || !imd) return NULL;
 
@@ -231,39 +237,34 @@ FullScreenData *fullscreen_start(GtkWidget *window, ImageWindow *imd,
 
        DEBUG_1("full screen requests screen %d", options->fullscreen.screen);
        fullscreen_prefs_get_geometry(options->fullscreen.screen, window, &x, &y, &w, &h,
-                                     &screen, &same);
+                                     &screen, &fs->same_region);
 
        fs->window = window_new(GTK_WINDOW_TOPLEVEL, "fullscreen", NULL, NULL, _("Full screen"));
 
-       /* this requests no decorations, if you still have them complain to the window manager author(s) */
+       g_signal_connect(G_OBJECT(fs->window), "delete_event",
+                        G_CALLBACK(fullscreen_delete_cb), fs);
+
+       /* few cosmetic details */
        gtk_window_set_decorated(GTK_WINDOW(fs->window), FALSE);
+       gtk_container_set_border_width(GTK_CONTAINER(fs->window), 0);
 
-       if (options->fullscreen.screen < 0)
-               {
-               /* If we want control of the window size and position this is not what we want.
-                * Geeqie needs control of which monitor(s) to use for full screen.
-                */
-               gtk_window_fullscreen(GTK_WINDOW(fs->window));
-               }
-       else
-               {
+       /* make window fullscreen -- let Gtk do it's job, don't screw it in any way */
+       gtk_window_fullscreen(GTK_WINDOW(fs->window));
+
+       /* move it to requested screen */
+       if (options->fullscreen.screen >= 0) {
                gtk_window_set_screen(GTK_WINDOW(fs->window), screen);
-               if (options->fullscreen.above)
-                       gtk_window_set_keep_above(GTK_WINDOW(fs->window), TRUE);
-               }
+       }
 
-       gtk_window_set_resizable(GTK_WINDOW(fs->window), FALSE);
-       gtk_container_set_border_width(GTK_CONTAINER(fs->window), 0);
-       g_signal_connect(G_OBJECT(fs->window), "delete_event",
-                        G_CALLBACK(fullscreen_delete_cb), fs);
+       /* keep window above others, if requested */
+       if (options->fullscreen.above) {
+               gtk_window_set_keep_above(GTK_WINDOW(fs->window), TRUE);
+       }
+
+       /* set default size and position, so the window appears where it was before */
+       gtk_window_set_default_size(GTK_WINDOW(fs->window), w, h);
+       gtk_window_move(GTK_WINDOW(fs->window), x, y);
 
-       geometry.min_width = w;
-       geometry.min_height = h;
-       geometry.max_width = w;
-       geometry.max_height = h;
-       geometry.base_width = w;
-       geometry.base_height = h;
-       geometry.win_gravity = GDK_GRAVITY_STATIC;
        /* By setting USER_POS and USER_SIZE, most window managers will
         * not request positioning of the full screen window (for example twm).
         *
@@ -271,18 +272,15 @@ FullScreenData *fullscreen_start(GtkWidget *window, ImageWindow *imd,
         * decorations of twm to not effect the requested window position,
         * the decorations will simply be off screen, except in multi monitor setups :-/
         */
+       geometry.min_width = 1;
+       geometry.min_height = 1;
+       geometry.base_width = w;
+       geometry.base_height = h;
+       geometry.win_gravity = GDK_GRAVITY_STATIC;
        gtk_window_set_geometry_hints(GTK_WINDOW(fs->window), fs->window, &geometry,
-                                     GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_BASE_SIZE |
-                                     GDK_HINT_WIN_GRAVITY |
-                                     GDK_HINT_USER_POS);
-
-       gtk_window_set_default_size(GTK_WINDOW(fs->window), w, h);
-       gtk_window_move(GTK_WINDOW(fs->window), x, y);
+                       GDK_HINT_WIN_GRAVITY | GDK_HINT_USER_POS | GDK_HINT_USER_SIZE);
 
        gtk_widget_realize(fs->window);
-       gdkwin = gtk_widget_get_window(fs->window);
-       if (gdkwin != NULL)
-               gdk_window_set_override_redirect(gdkwin, TRUE);
 
        fs->imd = image_new(FALSE);
 
@@ -291,7 +289,7 @@ FullScreenData *fullscreen_start(GtkWidget *window, ImageWindow *imd,
        image_background_set_color_from_options(fs->imd, TRUE);
        image_set_delay_flip(fs->imd, options->fullscreen.clean_flip);
        image_auto_refresh_enable(fs->imd, fs->normal_imd->auto_refresh);
-       
+
        if (options->fullscreen.clean_flip)
                {
                image_set_update_func(fs->imd, fullscreen_image_update_cb, fs);
@@ -300,7 +298,16 @@ FullScreenData *fullscreen_start(GtkWidget *window, ImageWindow *imd,
 
        gtk_widget_show(fs->imd->widget);
 
-       image_change_from_image(fs->imd, fs->normal_imd);
+       if (fs->same_region)
+               {
+               DEBUG_0("Original window is not visible, enabling std. fullscreen mode");
+               image_move_from_image(fs->imd, fs->normal_imd);
+               }
+       else
+               {
+               DEBUG_0("Original window is still visible, enabling presentation fullscreen mode");
+               image_copy_from_image(fs->imd, fs->normal_imd);
+               }
 
        if (options->stereo.enable_fsmode) {
                image_stereo_set(fs->imd, options->stereo.fsmode);
@@ -319,10 +326,13 @@ FullScreenData *fullscreen_start(GtkWidget *window, ImageWindow *imd,
        /* hide normal window
         * FIXME: properly restore this window on show
         */
+       if (fs->same_region)
+               {
 #ifdef HIDE_WINDOW_IN_FULLSCREEN
-       gtk_widget_hide(fs->normal_window);
+               gtk_widget_hide(fs->normal_window);
 #endif
-       image_change_fd(fs->normal_imd, NULL, image_zoom_get(fs->normal_imd));
+               image_change_fd(fs->normal_imd, NULL, image_zoom_get(fs->normal_imd));
+               }
 
        return fs;
 }
@@ -337,19 +347,25 @@ void fullscreen_stop(FullScreenData *fs)
        fullscreen_busy_mouse_disable(fs);
        gdk_keyboard_ungrab(GDK_CURRENT_TIME);
 
-       image_change_from_image(fs->normal_imd, fs->imd);
-
-       if (options->stereo.enable_fsmode) {
-               image_stereo_set(fs->normal_imd, options->stereo.mode);
-       }
-
+       if (fs->same_region)
+               {
+               image_move_from_image(fs->normal_imd, fs->imd);
 #ifdef HIDE_WINDOW_IN_FULLSCREEN
-       gtk_widget_show(fs->normal_window);
+               gtk_widget_show(fs->normal_window);
 #endif
+               if (options->stereo.enable_fsmode)
+                       {
+                       image_stereo_set(fs->normal_imd, options->stereo.mode);
+                       }
+               }
+
+
        if (fs->stop_func) fs->stop_func(fs, fs->stop_data);
 
        gtk_widget_destroy(fs->window);
 
+       gtk_window_present(GTK_WINDOW(fs->normal_window));
+
        g_free(fs);
 }
 
@@ -622,7 +638,6 @@ GtkWidget *fullscreen_prefs_selection_new(const gchar *text, gint *screen_value,
        GtkWidget *combo;
        GtkListStore *store;
        GtkCellRenderer *renderer;
-       GtkWidget *button = NULL;
        GList *list;
        GList *work;
        gint current = 0;
@@ -643,15 +658,6 @@ GtkWidget *fullscreen_prefs_selection_new(const gchar *text, gint *screen_value,
        gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), renderer,
                                       "text", FS_MENU_COLUMN_NAME, NULL);
 
-       if (above_value)
-               {
-               button = pref_checkbox_new_int(vbox, _("Stay above other windows"),
-                                              *above_value, above_value);
-               gtk_widget_set_sensitive(button, *screen_value != -1);
-
-               g_object_set_data(G_OBJECT(combo), BUTTON_ABOVE_KEY, button);
-               }
-
        fullscreen_prefs_selection_add(store, _("Determined by Window Manager"), -1);
        fullscreen_prefs_selection_add(store, _("Active screen"), 0);
        if (*screen_value == 0) current = 1;