Ref #202: "Set as wallpaper" doesn't work with GNOME Shell
[geeqie.git] / src / layout_image.c
index 9df1b2e..2e40174 100644 (file)
@@ -26,6 +26,7 @@
 #include "color-man.h"
 #include "dnd.h"
 #include "editors.h"
+#include "exif.h"
 #include "filedata.h"
 #include "fullscreen.h"
 #include "image.h"
@@ -34,6 +35,7 @@
 #include "layout.h"
 #include "layout_util.h"
 #include "menu.h"
+#include "metadata.h"
 #include "misc.h"
 #include "pixbuf_util.h"
 #include "pixbuf-renderer.h"
 
 #include <gdk/gdkkeysyms.h> /* for keyboard values */
 
+#define FILE_COLUMN_POINTER 0
 
 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw);
 static void layout_image_set_buttons(LayoutWindow *lw);
-void layout_image_animate_stop(LayoutWindow *lw);
-gboolean layout_image_animate_new_file(LayoutWindow *lw);
-void layout_image_animate_update_image(LayoutWindow *lw);
+static void layout_image_animate_stop(LayoutWindow *lw);
+static gboolean layout_image_animate_new_file(LayoutWindow *lw);
+static void layout_image_animate_update_image(LayoutWindow *lw);
 
 /*
  *----------------------------------------------------------------------------
@@ -278,8 +281,8 @@ static gboolean layout_image_slideshow_continue_check(LayoutWindow *lw)
 static void image_animation_data_free(AnimationData *fd)
 {
        if(!fd) return;
-       g_object_unref(fd->iter);
-       g_object_unref(fd->gpa);
+       if(fd->iter) g_object_unref(fd->iter);
+       if(fd->gpa) g_object_unref(fd->gpa);
        g_free(fd);
 }
 
@@ -335,11 +338,11 @@ static gboolean show_next_frame(gpointer data)
        return TRUE;
 }
 
-gboolean layout_image_animate_check(LayoutWindow *lw)
+static gboolean layout_image_animate_check(LayoutWindow *lw)
 {
        if (!layout_valid(&lw)) return FALSE;
 
-       if(!lw->options.animate)
+       if(!lw->options.animate || lw->image->image_fd == NULL)
                {
                if(lw->animation)
                        {
@@ -352,7 +355,7 @@ gboolean layout_image_animate_check(LayoutWindow *lw)
        return TRUE;
 }
 
-void layout_image_animate_stop(LayoutWindow *lw)
+static void layout_image_animate_stop(LayoutWindow *lw)
 {
        if (!layout_valid(&lw)) return;
 
@@ -363,7 +366,7 @@ void layout_image_animate_stop(LayoutWindow *lw)
                }
 }
 
-void layout_image_animate_update_image(LayoutWindow *lw)
+static void layout_image_animate_update_image(LayoutWindow *lw)
 {
        if (!layout_valid(&lw)) return;
 
@@ -376,7 +379,7 @@ void layout_image_animate_update_image(LayoutWindow *lw)
                }
 }
 
-gboolean layout_image_animate_new_file(LayoutWindow *lw)
+static gboolean layout_image_animate_new_file(LayoutWindow *lw)
 {
        GError *err=NULL;
 
@@ -391,6 +394,7 @@ gboolean layout_image_animate_new_file(LayoutWindow *lw)
                !(lw->animation->iter = gdk_pixbuf_animation_get_iter(lw->animation->gpa,NULL)))
                {
                image_animation_data_free(lw->animation);
+               lw->animation = NULL;
                return FALSE;
                }
 
@@ -407,9 +411,15 @@ gboolean layout_image_animate_new_file(LayoutWindow *lw)
 
 void layout_image_animate_toggle(LayoutWindow *lw)
 {
+       GtkAction *action;
+
        if (!lw) return;
 
        lw->options.animate = !lw->options.animate;
+
+       action = gtk_action_group_get_action(lw->action_group, "Animate");
+       gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.animate);
+
        layout_image_animate_new_file(lw);
 }
 
@@ -475,7 +485,7 @@ static void li_pop_menu_alter_cb(GtkWidget *widget, gpointer data)
        lw = submenu_item_get_data(widget);
        type = (AlterType)GPOINTER_TO_INT(data);
 
-       image_alter_orientation(lw->image, type);
+       image_alter_orientation(lw->image, lw->image->image_fd, type);
 }
 
 static void li_pop_menu_new_cb(GtkWidget *widget, gpointer data)
@@ -658,8 +668,9 @@ static GtkWidget *layout_image_pop_menu(LayoutWindow *lw)
        submenu = submenu_add_edit(menu, &item, G_CALLBACK(li_pop_menu_edit_cb), lw, editmenu_fd_list);
        if (!path) gtk_widget_set_sensitive(item, FALSE);
        menu_item_add_divider(submenu);
+#if !GTK_CHECK_VERSION(3,0,0)
        menu_item_add(submenu, _("Set as _wallpaper"), G_CALLBACK(li_pop_menu_wallpaper_cb), lw);
-
+#endif
        item = submenu_add_alter(menu, G_CALLBACK(li_pop_menu_alter_cb), lw);
 
        item = menu_item_add_stock(menu, _("View in _new window"), GTK_STOCK_NEW, G_CALLBACK(li_pop_menu_new_cb), lw);
@@ -997,12 +1008,12 @@ void layout_image_zoom_adjust_at_point(LayoutWindow *lw, gdouble increment, gint
                {
                image_zoom_adjust_at_point(lw->full_screen->imd, increment, x, y);
                }
-
-       if (!connect_zoom) return;
+       if (!connect_zoom && !lw->split_mode) return;
 
        for (i = 0; i < MAX_SPLIT_IMAGES; i++)
                {
-               if (lw->split_images[i] && lw->split_images[i] != lw->image)
+               if (lw->split_images[i] && lw->split_images[i] != lw->image &&
+                                               lw->split_images[i]->mouse_wheel_mode)
                        image_zoom_adjust_at_point(lw->split_images[i], increment, x, y);
                }
 }
@@ -1053,7 +1064,71 @@ void layout_image_alter_orientation(LayoutWindow *lw, AlterType type)
 {
        if (!layout_valid(&lw)) return;
 
-       image_alter_orientation(lw->image, type);
+       GtkTreeModel *store;
+       GList *work;
+       GtkTreeSelection *selection;
+       GtkTreePath *tpath;
+       FileData *fd_n;
+       GtkTreeIter iter;
+       IconData *id;
+
+       if (!lw || !lw->vf) return;
+
+       if (lw->vf->type == FILEVIEW_ICON)
+               {
+               if (!VFICON(lw->vf)->selection) return;
+               work = VFICON(lw->vf)->selection;
+               }
+       else
+               {
+               selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lw->vf->listview));
+               work = gtk_tree_selection_get_selected_rows(selection, &store);
+               }
+
+       while (work)
+               {
+               if (lw->vf->type == FILEVIEW_ICON)
+                       {
+                       id = work->data;
+                       fd_n = id->fd;
+                       work = work->next;
+                       }
+               else
+                       {
+                       tpath = work->data;
+                       gtk_tree_model_get_iter(store, &iter, tpath);
+                       gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd_n, -1);
+                       work = work->next;
+                       }
+
+               image_alter_orientation(lw->image, fd_n, type);
+               }
+}
+
+void layout_image_reset_orientation(LayoutWindow *lw)
+{
+       ImageWindow *imd= lw->image;
+
+       if (!layout_valid(&lw)) return;
+       if (!imd || !imd->pr || !imd->image_fd) return;
+
+       if (imd->orientation < 1 || imd->orientation > 8) imd->orientation = 1;
+
+       if (options->image.exif_rotate_enable)
+               {
+               imd->orientation = metadata_read_int(imd->image_fd, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
+               }
+       else
+               {
+               imd->orientation = 1;
+               }
+
+       if (imd->image_fd->user_orientation != 0)
+               {
+                imd->orientation = imd->image_fd->user_orientation;
+               }
+
+       pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, imd->orientation);
 }
 
 void layout_image_set_desaturate(LayoutWindow *lw, gboolean desaturate)
@@ -1598,7 +1673,8 @@ static void layout_image_scroll_cb(ImageWindow *imd, GdkEventScroll *event, gpoi
                }
 
 
-       if (event->state & GDK_CONTROL_MASK)
+       if ((event->state & GDK_CONTROL_MASK) ||
+                               (imd->mouse_wheel_mode && !options->image_lm_click_nav))
                {
                switch (event->direction)
                        {
@@ -1648,7 +1724,7 @@ static void layout_image_scroll_cb(ImageWindow *imd, GdkEventScroll *event, gpoi
                }
 }
 
-static void layout_image_drag_cb(ImageWindow *imd, GdkEventButton *event, gdouble dx, gdouble dy, gpointer data)
+static void layout_image_drag_cb(ImageWindow *imd, GdkEventMotion *event, gdouble dx, gdouble dy, gpointer data)
 {
        gint i;
        LayoutWindow *lw = data;
@@ -1719,7 +1795,7 @@ static void layout_image_button_inactive_cb(ImageWindow *imd, GdkEventButton *ev
 
 }
 
-static void layout_image_drag_inactive_cb(ImageWindow *imd, GdkEventButton *event, gdouble dx, gdouble dy, gpointer data)
+static void layout_image_drag_inactive_cb(ImageWindow *imd, GdkEventMotion *event, gdouble dx, gdouble dy, gpointer data)
 {
        LayoutWindow *lw = data;
        gint i = image_idx(lw, imd);
@@ -1925,16 +2001,19 @@ static void layout_image_setup_split_common(LayoutWindow *lw, gint n)
                                GList *work = g_list_last(layout_selection_list(lw));
                                gint j = 0;
 
-                               if (work) work = work->prev;
-
                                while (work && j < i)
                                        {
                                        FileData *fd = work->data;
                                        work = work->prev;
 
-                                       j++;
-                                       if (!fd || !*fd->path) continue;
+                                       if (!fd || !*fd->path || fd->parent ||
+                                                                               fd == lw->split_images[0]->image_fd)
+                                               {
+                                               continue;
+                                               }
                                        img_fd = fd;
+
+                                       j++;
                                        }
                                }