Skip to content

Commit 6711ee3

Browse files
committed
Move positioning funcs to the WindowPositioner
1 parent f8bd6cf commit 6711ee3

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

src/ShellClients/ShellClientsManager.vala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,7 @@ public class Gala.ShellClientsManager : Object {
184184
}
185185

186186
public void make_centered (Meta.Window window) requires (!is_itself_positioned (window)) {
187-
positioned_windows[window] = new WindowPositioner (window, wm, (ref x, ref y) => {
188-
unowned var display = wm.get_display ();
189-
var monitor_geom = display.get_monitor_geometry (display.get_primary_monitor ());
190-
var window_rect = window.get_frame_rect ();
191-
192-
x = monitor_geom.x + (monitor_geom.width - window_rect.width) / 2;
193-
y = monitor_geom.y + (monitor_geom.height - window_rect.height) / 2;
194-
});
187+
positioned_windows[window] = new WindowPositioner (wm, window, CENTER);
195188

196189
// connect_after so we make sure that any queued move is unqueued
197190
window.unmanaging.connect_after ((_window) => positioned_windows.remove (_window));

src/ShellClients/WindowPositioner.vala

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
*/
77

88
public class Gala.WindowPositioner : Object {
9-
public delegate void PositionFunc (ref int x, ref int y);
9+
public enum Position {
10+
CENTER
11+
}
1012

1113
public Meta.Window window { get; construct; }
1214
public WindowManager wm { get; construct; }
15+
public Position position { get; private set; }
16+
public Variant? position_data { get; private set; }
1317

14-
private PositionFunc position_func;
15-
16-
public WindowPositioner (Meta.Window window, WindowManager wm, owned PositionFunc position_func) {
17-
Object (window: window, wm: wm);
18-
19-
this.position_func = (owned) position_func;
18+
public WindowPositioner (WindowManager wm, Meta.Window window, Position position, Variant? position_data = null) {
19+
Object (wm: wm, window: window, position: position, position_data: position_data);
2020
}
2121

2222
construct {
@@ -31,9 +31,29 @@ public class Gala.WindowPositioner : Object {
3131
monitor_manager.monitors_changed_internal.connect (position_window);
3232
}
3333

34+
/**
35+
* This may only be called after the window was shown.
36+
*/
37+
public void update_position (Position new_position, Variant? new_position_data = null) {
38+
position = new_position;
39+
position_data = new_position_data;
40+
41+
position_window ();
42+
}
43+
3444
private void position_window () {
3545
int x = 0, y = 0;
36-
position_func (ref x, ref y);
46+
47+
switch (position) {
48+
case CENTER:
49+
unowned var display = wm.get_display ();
50+
var monitor_geom = display.get_monitor_geometry (display.get_primary_monitor ());
51+
var window_rect = window.get_frame_rect ();
52+
53+
x = monitor_geom.x + (monitor_geom.width - window_rect.width) / 2;
54+
y = monitor_geom.y + (monitor_geom.height - window_rect.height) / 2;
55+
break;
56+
}
3757

3858
window.move_frame (false, x, y);
3959
}

0 commit comments

Comments
 (0)