Merge lp:~gala-dev/gala/advanced-window-tiling into lp:gala

Proposed by Tom Beckmann
Status: Needs review
Proposed branch: lp:~gala-dev/gala/advanced-window-tiling
Merge into: lp:gala
Diff against target: 132 lines (+115/-0)
1 file modified
src/Plugin.vala (+115/-0)
To merge this branch: bzr merge lp:~gala-dev/gala/advanced-window-tiling
Reviewer Review Type Date Requested Status
Cody Garver (community) Needs Fixing
Review via email: mp+174811@code.launchpad.net

Description of the change

This adds compiz-like window tiling methods overriding the default keyboard handlers for move-to-*. The window's are tiled to a 4/8, then to 3/8 and 2/8, then to 6/8 and 5/8 and finally back to 4/8 of the screen.

To post a comment you must log in.
Revision history for this message
Cody Garver (codygarver) wrote :

gala/src/Plugin.vala:333.15-333.95: error: 1 extra arguments for `Meta.Rectangle Meta.Workspace.get_work_area_all_monitors ()'
   var geom = screen.get_active_workspace ().get_work_area_all_monitors (active.get_monitor ());
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
make[2]: *** [src/DBus.c] Error 1
make[1]: *** [CMakeFiles/gala.dir/all] Error 2
make: *** [all] Error 2

review: Needs Fixing
348. By Tom Beckmann

fix build error for systems with mutter < 3.8

Revision history for this message
Tom Beckmann (tombeckmann) wrote :

Fixed it.

Revision history for this message
Cody Garver (codygarver) wrote :

Needs trunk merged in a conflicts resolved

Unmerged revisions

348. By Tom Beckmann

fix build error for systems with mutter < 3.8

347. By Tom Beckmann

plugin: override move_to_* keybindings to provide more advanced tiling options

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Plugin.vala'
2--- src/Plugin.vala 2013-07-14 17:20:53 +0000
3+++ src/Plugin.vala 2013-07-29 21:16:26 +0000
4@@ -191,6 +191,16 @@
5
6 KeyBinding.set_custom_handler ("switch-group", () => {});
7 KeyBinding.set_custom_handler ("switch-group-backward", () => {});
8+
9+ KeyBinding.set_custom_handler ("move-to-corner-nw", () => place_window (KeyBindingAction.MOVE_TO_CORNER_NW) );
10+ KeyBinding.set_custom_handler ("move-to-corner-ne", () => place_window (KeyBindingAction.MOVE_TO_CORNER_NE) );
11+ KeyBinding.set_custom_handler ("move-to-corner-sw", () => place_window (KeyBindingAction.MOVE_TO_CORNER_SW) );
12+ KeyBinding.set_custom_handler ("move-to-corner-se", () => place_window (KeyBindingAction.MOVE_TO_CORNER_SE) );
13+ KeyBinding.set_custom_handler ("move-to-side-n", () => place_window (KeyBindingAction.MOVE_TO_SIDE_N) );
14+ KeyBinding.set_custom_handler ("move-to-side-s", () => place_window (KeyBindingAction.MOVE_TO_SIDE_S) );
15+ KeyBinding.set_custom_handler ("move-to-side-e", () => place_window (KeyBindingAction.MOVE_TO_SIDE_E) );
16+ KeyBinding.set_custom_handler ("move-to-side-w", () => place_window (KeyBindingAction.MOVE_TO_SIDE_W) );
17+ KeyBinding.set_custom_handler ("move-to-center", () => place_window (KeyBindingAction.MOVE_TO_CENTER) );
18
19 /*shadows*/
20 Utils.reload_shadow ();
21@@ -308,6 +318,111 @@
22
23 next.activate_with_focus (window, display.get_current_time ());
24 }
25+
26+ /**
27+ * place a window on a place on the screen. If pressed again,
28+ * we decrease the space two times by 1/8th and then increase it to 6/8th
29+ */
30+ void place_window (KeyBindingAction direction)
31+ {
32+ var screen = get_screen ();
33+ var active = screen.get_display ().get_focus_window ();
34+#if HAS_MUTTER38
35+ var geom = screen.get_active_workspace ().get_work_area_for_monitor (active.get_monitor ());
36+#else
37+ var geom = screen.get_active_workspace ().get_work_area_all_monitors ();
38+#endif
39+
40+ var current_dim = active.get_outer_rect ();
41+ current_dim.x -= geom.x;
42+ current_dim.y -= geom.y;
43+ Meta.Rectangle dim = {};
44+
45+ if (active.maximized_horizontally || active.maximized_vertically) {
46+ active.unmaximize (MaximizeFlags.HORIZONTAL | MaximizeFlags.VERTICAL);
47+ // as we want to have this toggle, we're done here
48+ if (direction == KeyBindingAction.MOVE_TO_CENTER)
49+ return;
50+ }
51+
52+ switch (direction) {
53+ case KeyBindingAction.MOVE_TO_CORNER_NW:
54+ dim = {0, 0, geom.width / 2, geom.height / 2};
55+ break;
56+ case KeyBindingAction.MOVE_TO_CORNER_NE:
57+ dim = {geom.width / 2, 0, geom.width / 2, geom.height / 2};
58+ break;
59+ case KeyBindingAction.MOVE_TO_CORNER_SW:
60+ dim = {0, geom.height / 2, geom.width / 2, geom.height / 2};
61+ break;
62+ case KeyBindingAction.MOVE_TO_CORNER_SE:
63+ dim = {geom.width / 2, 0 + geom.height / 2, geom.width / 2, geom.height / 2};
64+ break;
65+ case KeyBindingAction.MOVE_TO_SIDE_N:
66+ dim = {0, 0, geom.width, geom.height / 2};
67+ break;
68+ case KeyBindingAction.MOVE_TO_SIDE_S:
69+ dim = {0, geom.height / 2, geom.width, geom.height / 2};
70+ break;
71+ case KeyBindingAction.MOVE_TO_SIDE_E:
72+ dim = {geom.width / 2, 0, geom.width / 2, geom.height};
73+ break;
74+ case KeyBindingAction.MOVE_TO_SIDE_W:
75+ dim = {0, 0, geom.width / 2, geom.height};
76+ break;
77+ case KeyBindingAction.MOVE_TO_CENTER:
78+ active.maximize (MaximizeFlags.HORIZONTAL | MaximizeFlags.VERTICAL);
79+ return;
80+ default:
81+ assert_not_reached ();
82+ }
83+
84+ var vertical = direction == KeyBindingAction.MOVE_TO_SIDE_N
85+ || direction == KeyBindingAction.MOVE_TO_SIDE_S;
86+ var opposite = direction == KeyBindingAction.MOVE_TO_CORNER_NE
87+ || direction == KeyBindingAction.MOVE_TO_CORNER_SE
88+ || direction == KeyBindingAction.MOVE_TO_SIDE_E
89+ || direction == KeyBindingAction.MOVE_TO_SIDE_S;
90+ dim = get_multiplied (dim, current_dim, vertical, opposite);
91+ active.move_resize_frame (true, dim.x + geom.x, dim.y + geom.y, dim.width, dim.height);
92+ }
93+
94+ const double[] MULT_ORDER = {1, 0.75, 0.5, 1.5, 1.25};
95+ const double[] MULT_ORDER_OPPOSITE = {1, 1.25, 1.5, 0.5, 0.75};
96+ Meta.Rectangle get_multiplied (Meta.Rectangle dest_dim, Meta.Rectangle current_dim,
97+ bool vertical, bool opposite)
98+ {
99+ bool matches = false;
100+ int i;
101+ var multipliers_pos = opposite ? MULT_ORDER_OPPOSITE : MULT_ORDER;
102+ var multipliers_size = MULT_ORDER;
103+ for (i = 0; i < multipliers_pos.length; i++) {
104+ Meta.Rectangle test_dim = {
105+ (int)Math.floor (dest_dim.x * (vertical ? 1 : multipliers_pos[i])),
106+ (int)Math.floor (dest_dim.y * (vertical ? multipliers_pos[i] : 1)),
107+ (int)Math.floor (dest_dim.width * (vertical ? 1 : multipliers_size[i])),
108+ (int)Math.floor (dest_dim.height * (vertical ? multipliers_size[i] : 1))
109+ };
110+
111+ if (test_dim.equal (current_dim)) {
112+ matches = true;
113+ break;
114+ }
115+ }
116+
117+ if (!matches)
118+ return dest_dim;
119+
120+ if (++i >= multipliers_pos.length)
121+ i = 0;
122+
123+ return {
124+ (int)Math.floor (dest_dim.x * (vertical ? 1 : multipliers_pos[i])),
125+ (int)Math.floor (dest_dim.y * (vertical ? multipliers_pos[i] : 1)),
126+ (int)Math.floor (dest_dim.width * (vertical ? 1 : multipliers_size[i])),
127+ (int)Math.floor (dest_dim.height * (vertical ? multipliers_size[i] : 1))
128+ };
129+ }
130
131 public new void begin_modal ()
132 {

Subscribers

People subscribed via source and target branches