[gimp] app: make Alt+Tab and Alt+Shift+Tab cycle through all open displays



commit 8e5f18fb9e1ceb3a94d2f39d567a0b55da00648f
Author: Michael Natterer <mitch gimp org>
Date:   Mon May 30 23:46:50 2011 +0200

    app: make Alt+Tab and Alt+Shift+Tab cycle through all open displays
    
    in both multi- and single-window mode. This is useful especially in
    multi-window mode because in single-window we can already cycle
    through all tabs with Ctrl+PageUp/Down.

 app/actions/windows-actions.c              |   28 +++++++++++----
 app/actions/windows-commands.c             |   52 +++++++++++++++++++++++++--
 app/actions/windows-commands.h             |    5 +++
 app/display/gimpdisplayshell-tool-events.c |   38 +++++++++++++++++++-
 4 files changed, 109 insertions(+), 14 deletions(-)
---
diff --git a/app/actions/windows-actions.c b/app/actions/windows-actions.c
index 5e0c342..41eb2c8 100644
--- a/app/actions/windows-actions.c
+++ b/app/actions/windows-actions.c
@@ -83,6 +83,13 @@ static void  windows_actions_single_window_mode_notify (GimpDisplayConfig *confi
                                                         GimpActionGroup   *group);
 
 
+/* The only reason we have "Tab" in the action entries below is to
+ * give away the hardcoded keyboard shortcut. If the user changes the
+ * shortcut to something else, both that shortcut and Tab will
+ * work. The reason we have the shortcut hardcoded is beccause
+ * gtk_accelerator_valid() returns FALSE for GDK_tab.
+ */
+
 static const GimpActionEntry windows_actions[] =
 {
   { "windows-menu",         NULL, NC_("windows-action",
@@ -91,19 +98,24 @@ static const GimpActionEntry windows_actions[] =
                                       "_Recently Closed Docks") },
   { "windows-dialogs-menu", NULL, NC_("windows-action",
                                       "_Dockable Dialogs")      },
+
+  { "windows-show-display-next", NULL,
+    NC_("windows-action", "Next Image"), "<alt>Tab",
+    NC_("windows-action", "Switch to the next image"),
+    G_CALLBACK (windows_show_display_next_cmd_callback),
+    NULL },
+
+  { "windows-show-display-previous", NULL,
+    NC_("windows-action", "Previous Image"), "<alt><shift>Tab",
+    NC_("windows-action", "Switch to the previous image"),
+    G_CALLBACK (windows_show_display_previous_cmd_callback),
+    NULL }
 };
 
 static const GimpToggleActionEntry windows_toggle_actions[] =
 {
   { "windows-hide-docks", NULL,
-    NC_("windows-action", "Hide Docks"),
-    /* The only reason we have Tab here is to give away the hardcoded
-     * keyboard shortcut. If the user changes the shortcut to
-     * something else, both that shortcut and Tab will work. The
-     * reason we have the shortcut hardcoded is beccause
-     * gtk_accelerator_valid() returns FALSE for GDK_tab.
-     */
-    "Tab",
+    NC_("windows-action", "Hide Docks"), "Tab",
     NC_("windows-action", "When enabled docks and other dialogs are hidden, leaving only image windows."),
     G_CALLBACK (windows_hide_docks_cmd_callback),
     FALSE,
diff --git a/app/actions/windows-commands.c b/app/actions/windows-commands.c
index dd37e74..f03fee0 100644
--- a/app/actions/windows-commands.c
+++ b/app/actions/windows-commands.c
@@ -46,8 +46,8 @@ void
 windows_hide_docks_cmd_callback (GtkAction *action,
                                  gpointer   data)
 {
-  gboolean         active    = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
-  Gimp            *gimp      = NULL;
+  gboolean  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
+  Gimp     *gimp;
   return_if_no_gimp (gimp, data);
 
   if (GIMP_GUI_CONFIG (gimp->config)->hide_docks == active)
@@ -63,7 +63,7 @@ windows_use_single_window_mode_cmd_callback (GtkAction *action,
                                              gpointer   data)
 {
   gboolean  active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
-  Gimp     *gimp   = NULL;
+  Gimp     *gimp;
   return_if_no_gimp (gimp, data);
 
   if (GIMP_GUI_CONFIG (gimp->config)->single_window_mode == active)
@@ -75,10 +75,54 @@ windows_use_single_window_mode_cmd_callback (GtkAction *action,
 }
 
 void
+windows_show_display_next_cmd_callback (GtkAction *action,
+                                        gpointer   data)
+{
+  GimpDisplay *display;
+  Gimp        *gimp;
+  gint         index;
+  return_if_no_display (display, data);
+  return_if_no_gimp (gimp, data);
+
+  index = gimp_container_get_child_index (gimp->displays,
+                                          GIMP_OBJECT (display));
+  index++;
+
+  if (index >= gimp_container_get_n_children (gimp->displays))
+    index = 0;
+
+  display = GIMP_DISPLAY (gimp_container_get_child_by_index (gimp->displays,
+                                                             index));
+  gimp_display_shell_present (gimp_display_get_shell (display));
+}
+
+void
+windows_show_display_previous_cmd_callback (GtkAction *action,
+                                            gpointer   data)
+{
+  GimpDisplay *display;
+  Gimp        *gimp;
+  gint         index;
+  return_if_no_display (display, data);
+  return_if_no_gimp (gimp, data);
+
+  index = gimp_container_get_child_index (gimp->displays,
+                                          GIMP_OBJECT (display));
+  index--;
+
+  if (index < 0)
+    index = gimp_container_get_n_children (gimp->displays) - 1;
+
+  display = GIMP_DISPLAY (gimp_container_get_child_by_index (gimp->displays,
+                                                             index));
+  gimp_display_shell_present (gimp_display_get_shell (display));
+}
+
+void
 windows_show_display_cmd_callback (GtkAction *action,
                                    gpointer   data)
 {
-  GimpDisplay *display  = g_object_get_data (G_OBJECT (action), "display");
+  GimpDisplay *display = g_object_get_data (G_OBJECT (action), "display");
 
   gimp_display_shell_present (gimp_display_get_shell (display));
 }
diff --git a/app/actions/windows-commands.h b/app/actions/windows-commands.h
index cd3a594..880cdd5 100644
--- a/app/actions/windows-commands.h
+++ b/app/actions/windows-commands.h
@@ -23,6 +23,11 @@ void  windows_hide_docks_cmd_callback             (GtkAction *action,
                                                    gpointer   data);
 void  windows_use_single_window_mode_cmd_callback (GtkAction *action,
                                                    gpointer   data);
+
+void  windows_show_display_next_cmd_callback      (GtkAction *action,
+                                                   gpointer   data);
+void  windows_show_display_previous_cmd_callback  (GtkAction *action,
+                                                   gpointer   data);
 void  windows_show_display_cmd_callback           (GtkAction *action,
                                                    gpointer   data);
 void  windows_show_dock_cmd_callback              (GtkAction *action,
diff --git a/app/display/gimpdisplayshell-tool-events.c b/app/display/gimpdisplayshell-tool-events.c
index c8f5b9b..305a011 100644
--- a/app/display/gimpdisplayshell-tool-events.c
+++ b/app/display/gimpdisplayshell-tool-events.c
@@ -109,6 +109,8 @@ static void       gimp_display_shell_untransform_event_coords (GimpDisplayShell
                                                                gboolean         *update_software_cursor);
 
 static void       gimp_display_shell_toggle_hide_docks        (GimpDisplayShell *shell);
+static void       gimp_display_shell_show_display_next        (GimpDisplayShell *shell);
+static void       gimp_display_shell_show_display_previous    (GimpDisplayShell *shell);
 
 static GdkEvent * gimp_display_shell_compress_motion          (GimpDisplayShell *shell);
 
@@ -259,8 +261,11 @@ gimp_display_shell_canvas_no_image_events (GtkWidget        *canvas,
         if (kevent->keyval == GDK_KEY_Tab ||
             kevent->keyval == GDK_KEY_ISO_Left_Tab)
           {
-            gimp_display_shell_toggle_hide_docks (shell);
-            return TRUE;
+            if (! (kevent->state & GDK_MOD1_MASK))
+              {
+                gimp_display_shell_toggle_hide_docks (shell);
+                return TRUE;
+              }
           }
       }
       break;
@@ -1073,6 +1078,13 @@ gimp_display_shell_canvas_tool_events (GtkWidget        *canvas,
                                                                 -1, kevent->time);
                       }
                   }
+                else if (state & GDK_MOD1_MASK)
+                  {
+                    if (kevent->keyval == GDK_KEY_Tab)
+                      gimp_display_shell_show_display_next (shell);
+                    else
+                      gimp_display_shell_show_display_previous (shell);
+                  }
                 else
                   {
                     gimp_display_shell_toggle_hide_docks (shell);
@@ -1415,6 +1427,28 @@ gimp_display_shell_toggle_hide_docks (GimpDisplayShell *shell)
 }
 
 static void
+gimp_display_shell_show_display_next (GimpDisplayShell *shell)
+{
+  GimpImageWindow *window = gimp_display_shell_get_window (shell);
+
+  if (window)
+    gimp_ui_manager_activate_action (gimp_image_window_get_ui_manager (window),
+                                     "windows",
+                                     "windows-show-display-next");
+}
+
+static void
+gimp_display_shell_show_display_previous (GimpDisplayShell *shell)
+{
+  GimpImageWindow *window = gimp_display_shell_get_window (shell);
+
+  if (window)
+    gimp_ui_manager_activate_action (gimp_image_window_get_ui_manager (window),
+                                     "windows",
+                                     "windows-show-display-previous");
+}
+
+static void
 gimp_display_shell_start_scrolling (GimpDisplayShell *shell,
                                     gint              x,
                                     gint              y)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]