[metacity] keybindings: add toggle-tile-left/right bindings



commit 35241cbb60c1ff6af67569541d906100d20491b6
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Wed Apr 15 14:44:54 2015 +0300

    keybindings: add toggle-tile-left/right bindings
    
    Having keybindings for side-by-side tiling has been requested for
    a long time, so add this support now.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=648700
    
    Based on mutter commit:
    https://git.gnome.org/browse/mutter/commit/?id=34f6ffd1ad0d3b7369120a9802d84517748fe887

 src/50-metacity-windows.xml.in        |    8 +++++
 src/core/keybindings.c                |   57 +++++++++++++++++++++++++++++++++
 src/include/prefs.h                   |    2 +
 src/org.gnome.metacity.gschema.xml.in |    9 +++++
 4 files changed, 76 insertions(+), 0 deletions(-)
---
diff --git a/src/50-metacity-windows.xml.in b/src/50-metacity-windows.xml.in
index daf60f9..af4d265 100644
--- a/src/50-metacity-windows.xml.in
+++ b/src/50-metacity-windows.xml.in
@@ -38,5 +38,13 @@
 
        <KeyListEntry name="maximize-horizontally" _description="Maximize window horizontally"/>
 
+       <KeyListEntry name="toggle-tiled-left"
+                     schema="org.gnome.metacity.keybindings"
+                     _description="View split on left"/>
+
+       <KeyListEntry name="toggle-tiled-right"
+                     schema="org.gnome.metacity.keybindings"
+                     _description="View split on right"/>
+
 </KeyListEntries>
 
diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index 81b0649..5a4ed56 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -46,6 +46,7 @@
 #endif
 
 #define SCHEMA_COMMON_KEYBINDINGS "org.gnome.desktop.wm.keybindings"
+#define SCHEMA_METACITY_KEYBINDINGS "org.gnome.metacity.keybindings"
 
 static gboolean all_bindings_disabled = FALSE;
 
@@ -2882,6 +2883,48 @@ handle_toggle_above       (MetaDisplay    *display,
 }
 
 static void
+handle_toggle_tiled (MetaDisplay    *display,
+                     MetaScreen     *screen,
+                     MetaWindow     *window,
+                     XEvent         *event,
+                     MetaKeyBinding *binding,
+                     gpointer        dummy)
+{
+  const MetaXineramaScreenInfo *monitor;
+  MetaTileMode mode = binding->handler->data;
+
+  monitor = meta_screen_get_current_xinerama (window->screen);
+
+  if ((META_WINDOW_TILED_LEFT (window) && mode == META_TILE_LEFT) ||
+      (META_WINDOW_TILED_RIGHT (window) && mode == META_TILE_RIGHT))
+    {
+      window->tile_monitor_number = window->saved_maximize ? monitor->number
+                                                           : -1;
+      window->tile_mode = window->saved_maximize ? META_TILE_MAXIMIZED
+                                                 : META_TILE_NONE;
+
+      if (window->saved_maximize)
+        meta_window_maximize (window, META_MAXIMIZE_VERTICAL |
+                                      META_MAXIMIZE_HORIZONTAL);
+      else
+        meta_window_unmaximize (window, META_MAXIMIZE_VERTICAL |
+                                        META_MAXIMIZE_HORIZONTAL);
+    }
+  else if (meta_window_can_tile_side_by_side (window))
+    {
+      window->tile_monitor_number = monitor->number;
+      window->tile_mode = mode;
+      /* Maximization constraints beat tiling constraints, so if the window
+       * is maximized, tiling won't have any effect unless we unmaximize it
+       * horizontally first; rather than calling meta_window_unmaximize(),
+       * we just set the flag and rely on meta_window_tile() syncing it to
+       * save an additional roundtrip. */
+      window->maximized_horizontally = FALSE;
+      meta_window_tile (window);
+    }
+}
+
+static void
 handle_toggle_maximized    (MetaDisplay    *display,
                            MetaScreen     *screen,
                            MetaWindow     *window,
@@ -3487,6 +3530,20 @@ init_builtin_key_bindings (MetaDisplay *display)
                           (MetaKeyHandlerFunc) handle_toggle_maximized, 0);
 
   add_builtin_keybinding (display,
+                          "toggle-tiled-left",
+                          SCHEMA_METACITY_KEYBINDINGS,
+                          META_KEY_BINDING_PER_WINDOW,
+                          META_KEYBINDING_ACTION_TOGGLE_TILED_LEFT,
+                          handle_toggle_tiled, META_TILE_LEFT);
+
+  add_builtin_keybinding (display,
+                          "toggle-tiled-right",
+                          SCHEMA_METACITY_KEYBINDINGS,
+                          META_KEY_BINDING_PER_WINDOW,
+                          META_KEYBINDING_ACTION_TOGGLE_TILED_RIGHT,
+                          handle_toggle_tiled, META_TILE_RIGHT);
+
+  add_builtin_keybinding (display,
                           "toggle-above",
                           SCHEMA_COMMON_KEYBINDINGS,
                           META_KEY_BINDING_PER_WINDOW,
diff --git a/src/include/prefs.h b/src/include/prefs.h
index 6ce6fd3..1cfaa03 100644
--- a/src/include/prefs.h
+++ b/src/include/prefs.h
@@ -186,6 +186,8 @@ typedef enum _MetaKeyBindingAction
   META_KEYBINDING_ACTION_ACTIVATE_WINDOW_MENU,
   META_KEYBINDING_ACTION_TOGGLE_FULLSCREEN,
   META_KEYBINDING_ACTION_TOGGLE_MAXIMIZED,
+  META_KEYBINDING_ACTION_TOGGLE_TILED_LEFT,
+  META_KEYBINDING_ACTION_TOGGLE_TILED_RIGHT,
   META_KEYBINDING_ACTION_TOGGLE_ABOVE,
   META_KEYBINDING_ACTION_MAXIMIZE,
   META_KEYBINDING_ACTION_UNMAXIMIZE,
diff --git a/src/org.gnome.metacity.gschema.xml.in b/src/org.gnome.metacity.gschema.xml.in
index 94628d0..23a893b 100644
--- a/src/org.gnome.metacity.gschema.xml.in
+++ b/src/org.gnome.metacity.gschema.xml.in
@@ -72,4 +72,13 @@
     </key>
   </schema>
 
+  <schema id="org.gnome.metacity.keybindings" path="/org/gnome/metacity/keybindings/">
+    <key name="toggle-tiled-left" type="as">
+      <default><![CDATA[['<Super>Left']]]></default>
+    </key>
+    <key name="toggle-tiled-right" type="as">
+      <default><![CDATA[['<Super>Right']]]></default>
+    </key>
+  </schema>
+
 </schemalist>


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