Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic keyboard quarter tiling #408

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 27 additions & 7 deletions data/org.pantheon.desktop.gala.gschema.xml.in
Expand Up @@ -15,7 +15,7 @@
<value nick='grid' value='0'/>
<value nick='natural' value='1'/>
</enum>

<schema path="/org/pantheon/desktop/gala/behavior/" id="org.pantheon.desktop.gala.behavior" gettext-domain="@GETTEXT_PACKAGE@">
<key enum="GalaActionType" name="hotcorner-topleft">
<default>'none'</default>
Expand Down Expand Up @@ -83,7 +83,7 @@
<description>When launching the window-switcher, Gala iterates over this list and attempts to find a window matching the names. If it does, it will hide this window and fade it back in, once the the switcher is closed.</description>
</key>
</schema>

<schema path="/org/pantheon/desktop/gala/keybindings/" id="org.pantheon.desktop.gala.keybindings" gettext-domain="@GETTEXT_PACKAGE@">
<key type="as" name="switch-to-workspace-first">
<default><![CDATA[['<Super>Home']]]></default>
Expand Down Expand Up @@ -147,8 +147,28 @@
<summary>The shortcut to enable picture-in-picture window</summary>
<description>The shortcut to show the selection area to choose a window.</description>
</key>
<key type="as" name="tile-topleft">
<default><![CDATA[['<Super><Ctrl>1']]]></default>
<summary>Tile window to top left</summary>
<description>The shortcut to quarter tile window to top left.</description>
</key>
<key type="as" name="tile-topright">
<default><![CDATA[['<Super><Ctrl>2']]]></default>
<summary>Tile window to top right</summary>
<description>The shortcut to quarter tile window to top right.</description>
</key>
<key type="as" name="tile-bottomleft">
<default><![CDATA[['<Super><Ctrl>3']]]></default>
<summary>Tile window to bottom left</summary>
<description>The shortcut to quarter tile window to bottom left.</description>
</key>
<key type="as" name="tile-bottomright">
<default><![CDATA[['<Super><Ctrl>4']]]></default>
<summary>Tile window to bottom right</summary>
<description>The shortcut to quarter tile window to bottom right.</description>
</key>
</schema>

<schema path="/org/pantheon/desktop/gala/appearance/" id="org.pantheon.desktop.gala.appearance" gettext-domain="@GETTEXT_PACKAGE@">
<key type="b" name="attach-modal-dialogs">
<default>false</default>
Expand All @@ -175,7 +195,7 @@
<summary>Background-image used in the workspace-switcher</summary>
</key>
</schema>

<schema path="/org/pantheon/desktop/gala/animations/" id="org.pantheon.desktop.gala.animations" gettext-domain="@GETTEXT_PACKAGE@">
<key type="b" name="enable-animations">
<default>true</default>
Expand Down Expand Up @@ -206,7 +226,7 @@
<summary>Duration of the menu mapping animation</summary>
</key>
</schema>

<schema path="/org/pantheon/desktop/gala/shadows/" id="org.pantheon.desktop.gala.shadows" gettext-domain="@GETTEXT_PACKAGE@">
<key type="as" name="normal-focused">
<default>['20', '-1', '0', '15', '220']</default>
Expand Down Expand Up @@ -234,7 +254,7 @@
<description>See normal-focused.</description>
</key>
</schema>

<schema path="/org/pantheon/desktop/gala/notifications/" id="org.pantheon.desktop.gala.notifications" gettext-domain="@GETTEXT_PACKAGE@">
<key type="b" name="do-not-disturb">
<default>false</default>
Expand All @@ -257,7 +277,7 @@
<summary>Show missed notifications in notification center</summary>
</key>
</schema>

<schema path="/org/pantheon/desktop/gala/mask-corners/" id="org.pantheon.desktop.gala.mask-corners" gettext-domain="@GETTEXT_PACKAGE@">
<key type="b" name="enable">
<default>true</default>
Expand Down
1 change: 1 addition & 0 deletions meson.build
Expand Up @@ -265,6 +265,7 @@ subdir('daemon')
subdir('plugins/maskcorners')
subdir('plugins/notify')
subdir('plugins/pip')
subdir('plugins/quartertiler')
subdir('plugins/template')
subdir('plugins/zoom')
if get_option('documentation')
Expand Down
86 changes: 86 additions & 0 deletions plugins/quartertiler/Main.vala
@@ -0,0 +1,86 @@
//
// Copyright (C) 2018 Peter Uithoven
//
// 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 3 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, see <http://www.gnu.org/licenses/>.
//

namespace Gala.Plugins.QuarterTiler
{
public class Main : Gala.Plugin
{
public override void initialize (Gala.WindowManager wm)
{
unowned Meta.Display display = wm.get_screen ().get_display ();

var settings = new GLib.Settings (Config.SCHEMA + ".keybindings");

display.add_keybinding ("tile-topleft", settings, Meta.KeyBindingFlags.NONE, (Meta.KeyHandlerFunc) on_initiate);
display.add_keybinding ("tile-topright", settings, Meta.KeyBindingFlags.NONE, (Meta.KeyHandlerFunc) on_initiate);
display.add_keybinding ("tile-bottomleft", settings, Meta.KeyBindingFlags.NONE, (Meta.KeyHandlerFunc) on_initiate);
display.add_keybinding ("tile-bottomright", settings, Meta.KeyBindingFlags.NONE, (Meta.KeyHandlerFunc) on_initiate);
}

[CCode (instance_pos = -1)]
void on_initiate (Meta.Display display, Meta.Screen screen,
Meta.Window? window, Clutter.KeyEvent event, Meta.KeyBinding binding)
{
unowned Meta.Window focused_window = display.get_focus_window ();
if (focused_window.maximized_vertically || focused_window.maximized_horizontally) {
focused_window.unmaximize (Meta.MaximizeFlags.BOTH);
}
if (focused_window.fullscreen) {
focused_window.unmake_fullscreen ();
}

Meta.Rectangle wa = focused_window.get_work_area_current_monitor ();

int x = wa.x;
int y = wa.y;
int width = wa.width / 2;
int height = wa.height / 2;
switch (binding.get_name ()) {
case "tile-topleft":
default:
break;
case "tile-topright":
x += width;
break;
case "tile-bottomleft":
y += height;
break;
case "tile-bottomright":
x += width;
y += height;
break;
}

focused_window.move_resize_frame (true, x, y, width, height);
}

public override void destroy ()
{
}
}
}

public Gala.PluginInfo register_plugin ()
{
return {
"Quarter tiler",
"Peter Uithoven <peter@peteruithoven.com>",
typeof (Gala.Plugins.QuarterTiler.Main),
Gala.PluginFunction.ADDITION,
Gala.LoadPriority.IMMEDIATE
};
}
13 changes: 13 additions & 0 deletions plugins/quartertiler/meson.build
@@ -0,0 +1,13 @@
gala_quartertiler_sources = [
'Main.vala',
]

gala_quartertiler_lib = shared_library(
'gala-quartertiler',
gala_quartertiler_sources,
dependencies: [gala_dep, gala_base_dep],
include_directories: config_inc_dir,
install: true,
install_dir: plugins_dir,
install_rpath: mutter_typelib_dir,
)