From 34f6ffd1ad0d3b7369120a9802d84517748fe887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Tue, 15 Nov 2011 17:29:56 +0100 Subject: [PATCH] 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 --- .gitignore | 1 + po/POTFILES.in | 1 + src/50-mutter-windows.xml.in | 15 ++++++++ src/Makefile.am | 7 ++++ src/core/keybindings.c | 53 +++++++++++++++++++++++++++++ src/meta/prefs.h | 2 ++ src/org.gnome.mutter.gschema.xml.in | 8 +++++ 7 files changed, 87 insertions(+) create mode 100644 src/50-mutter-windows.xml.in diff --git a/.gitignore b/.gitignore index 823859995..671b4b5f7 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ libtool ltmain.sh missing .deps +src/50-mutter-windows.xml src/mutter-wm.desktop src/mutter.desktop *.o diff --git a/po/POTFILES.in b/po/POTFILES.in index 40cab83ec..5845fd453 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,5 +1,6 @@ # List of source files containing translatable strings. # Please keep this file sorted alphabetically. +src/50-mutter-windows.xml.in src/compositor/compositor.c src/core/bell.c src/core/core.c diff --git a/src/50-mutter-windows.xml.in b/src/50-mutter-windows.xml.in new file mode 100644 index 000000000..4e0ab9d52 --- /dev/null +++ b/src/50-mutter-windows.xml.in @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/src/Makefile.am b/src/Makefile.am index 7291a20b5..d9cbfdaba 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -261,6 +261,11 @@ wmproperties_in_files=mutter-wm.desktop.in wmproperties_files=$(wmproperties_in_files:.desktop.in=.desktop) wmproperties_DATA = $(wmproperties_files) +xmldir = @GNOME_KEYBINDINGS_KEYSDIR@ +xml_in_files = \ + 50-mutter-windows.xml.in +xml_DATA = $(xml_in_files:.xml.in=.xml) + gsettings_SCHEMAS = org.gnome.mutter.gschema.xml @INTLTOOL_XML_NOMERGE_RULE@ @GSETTINGS_RULES@ @@ -279,6 +284,7 @@ CLEANFILES = \ mutter.desktop \ mutter-wm.desktop \ org.gnome.mutter.gschema.xml \ + $(xml_DATA) \ $(mutter_built_sources) \ $(typelib_DATA) \ $(gir_DATA) @@ -295,6 +301,7 @@ EXTRA_DIST=$(desktopfiles_files) \ $(IMAGES) \ $(desktopfiles_in_files) \ $(wmproperties_in_files) \ + $(xml_in_files) \ org.gnome.mutter.gschema.xml.in \ mutter-schemas.convert \ libmutter.pc.in \ diff --git a/src/core/keybindings.c b/src/core/keybindings.c index 5510d2876..9d647557c 100644 --- a/src/core/keybindings.c +++ b/src/core/keybindings.c @@ -3232,6 +3232,45 @@ handle_toggle_above (MetaDisplay *display, meta_window_make_above (window); } +static void +handle_toggle_tiled (MetaDisplay *display, + MetaScreen *screen, + MetaWindow *window, + XEvent *event, + MetaKeyBinding *binding, + gpointer dummy) +{ + MetaTileMode mode = binding->handler->data; + + 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 ? window->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 = window->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, @@ -3889,6 +3928,20 @@ init_builtin_key_bindings (MetaDisplay *display) META_KEYBINDING_ACTION_TOGGLE_MAXIMIZED, handle_toggle_maximized, 0); + add_builtin_keybinding (display, + "toggle-tiled-left", + SCHEMA_MUTTER_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_MUTTER_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, diff --git a/src/meta/prefs.h b/src/meta/prefs.h index 6007c7c03..8232a7254 100644 --- a/src/meta/prefs.h +++ b/src/meta/prefs.h @@ -191,6 +191,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.mutter.gschema.xml.in b/src/org.gnome.mutter.gschema.xml.in index 76f13d688..8d11154e1 100644 --- a/src/org.gnome.mutter.gschema.xml.in +++ b/src/org.gnome.mutter.gschema.xml.in @@ -83,6 +83,14 @@ r']]]> + + Left']]]> + + + + Right']]]> + + [] <_summary>Select window from tab popup