Skip to content

Commit dc36a60

Browse files
committed
Introduce a WindowPositioner
1 parent 4c11882 commit dc36a60

File tree

3 files changed

+46
-34
lines changed

3 files changed

+46
-34
lines changed

src/ShellClients/ShellClientsManager.vala

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public class Gala.ShellClientsManager : Object {
2525
private NotificationsClient notifications_client;
2626
private ManagedClient[] protocol_clients = {};
2727

28-
private GLib.HashTable<Meta.Window, PanelWindow> windows = new GLib.HashTable<Meta.Window, PanelWindow> (null, null);
29-
private GLib.HashTable<Meta.Window, CenteredWindow> centered_windows = new GLib.HashTable<Meta.Window, CenteredWindow> (null, null);
28+
private GLib.HashTable<Meta.Window, PanelWindow> panel_windows = new GLib.HashTable<Meta.Window, PanelWindow> (null, null);
29+
private GLib.HashTable<Meta.Window, WindowPositioner> positioned_windows = new GLib.HashTable<Meta.Window, WindowPositioner> (null, null);
3030

3131
private ShellClientsManager (WindowManager wm) {
3232
Object (wm: wm);
@@ -144,18 +144,18 @@ public class Gala.ShellClientsManager : Object {
144144
}
145145

146146
public void set_anchor (Meta.Window window, Meta.Side side) {
147-
if (window in windows) {
148-
windows[window].update_anchor (side);
147+
if (window in panel_windows) {
148+
panel_windows[window].update_anchor (side);
149149
return;
150150
}
151151

152152
make_dock (window);
153153
// TODO: Return if requested by window that's not a trusted client?
154154

155-
windows[window] = new PanelWindow (wm, window, side);
155+
panel_windows[window] = new PanelWindow (wm, window, side);
156156

157157
// connect_after so we make sure the PanelWindow can destroy its barriers and struts
158-
window.unmanaging.connect_after (() => windows.remove (window));
158+
window.unmanaging.connect_after ((_window) => panel_windows.remove (_window));
159159
}
160160

161161
/**
@@ -166,37 +166,45 @@ public class Gala.ShellClientsManager : Object {
166166
* TODO: Maybe use for strut only?
167167
*/
168168
public void set_size (Meta.Window window, int width, int height) {
169-
if (!(window in windows)) {
169+
if (!(window in panel_windows)) {
170170
warning ("Set anchor for window before size.");
171171
return;
172172
}
173173

174-
windows[window].set_size (width, height);
174+
panel_windows[window].set_size (width, height);
175175
}
176176

177177
public void set_hide_mode (Meta.Window window, Pantheon.Desktop.HideMode hide_mode) {
178-
if (!(window in windows)) {
178+
if (!(window in panel_windows)) {
179179
warning ("Set anchor for window before hide mode.");
180180
return;
181181
}
182182

183-
windows[window].set_hide_mode (hide_mode);
183+
panel_windows[window].set_hide_mode (hide_mode);
184184
}
185185

186-
public void make_centered (Meta.Window window) {
187-
if (window in centered_windows) {
188-
return;
189-
}
186+
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 ();
190191

191-
centered_windows[window] = new CenteredWindow (wm, window);
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+
});
195+
196+
// connect_after so we make sure that any queued move is unqueued
197+
window.unmanaging.connect_after ((_window) => positioned_windows.remove (_window));
198+
}
192199

193-
window.unmanaging.connect_after (() => centered_windows.remove (window));
200+
private bool is_itself_positioned (Meta.Window window) {
201+
return (window in positioned_windows) || (window in panel_windows);
194202
}
195203

196204
public bool is_positioned_window (Meta.Window window) {
197-
bool positioned = (window in centered_windows) || (window in windows);
205+
bool positioned = is_itself_positioned (window);
198206
window.foreach_ancestor ((ancestor) => {
199-
if (ancestor in centered_windows || ancestor in windows) {
207+
if (ancestor in positioned_windows || ancestor in panel_windows) {
200208
positioned = true;
201209
}
202210

src/ShellClients/CenteredWindow.vala renamed to src/ShellClients/WindowPositioner.vala

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,35 @@
55
* Authored by: Leonhard Kargl <[email protected]>
66
*/
77

8-
public class Gala.CenteredWindow : Object {
9-
public WindowManager wm { get; construct; }
8+
public class Gala.WindowPositioner : Object {
9+
public delegate void PositionFunc (ref int x, ref int y);
10+
1011
public Meta.Window window { get; construct; }
12+
public WindowManager wm { get; construct; }
13+
14+
private PositionFunc position_func;
1115

1216
private uint idle_move_id = 0;
1317

14-
public CenteredWindow (WindowManager wm, Meta.Window window) {
15-
Object (wm: wm, window: window);
18+
public WindowPositioner (Meta.Window window, WindowManager wm, owned PositionFunc position_func) {
19+
Object (window: window, wm: wm);
20+
21+
this.position_func = (owned) position_func;
1622
}
1723

1824
construct {
19-
window.size_changed.connect (position_window);
2025
window.stick ();
2126

27+
window.size_changed.connect (position_window);
28+
window.position_changed.connect (position_window);
29+
window.shown.connect (position_window);
30+
2231
var monitor_manager = wm.get_display ().get_context ().get_backend ().get_monitor_manager ();
23-
monitor_manager.monitors_changed.connect (() => position_window ());
32+
monitor_manager.monitors_changed.connect (position_window);
33+
monitor_manager.monitors_changed_internal.connect (position_window);
2434

2535
position_window ();
2636

27-
window.shown.connect (() => window.focus (wm.get_display ().get_current_time ()));
28-
2937
window.unmanaging.connect (() => {
3038
if (idle_move_id != 0) {
3139
Source.remove (idle_move_id);
@@ -34,18 +42,14 @@ public class Gala.CenteredWindow : Object {
3442
}
3543

3644
private void position_window () {
37-
var display = wm.get_display ();
38-
var monitor_geom = display.get_monitor_geometry (display.get_primary_monitor ());
39-
var window_rect = window.get_frame_rect ();
40-
41-
var x = monitor_geom.x + (monitor_geom.width - window_rect.width) / 2;
42-
var y = monitor_geom.y + (monitor_geom.height - window_rect.height) / 2;
43-
4445
if (idle_move_id != 0) {
4546
Source.remove (idle_move_id);
4647
}
4748

4849
idle_move_id = Idle.add (() => {
50+
int x = 0, y = 0;
51+
position_func (ref x, ref y);
52+
4953
window.move_frame (false, x, y);
5054

5155
idle_move_id = 0;

src/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ gala_bin_sources = files(
4141
'HotCorners/Barrier.vala',
4242
'HotCorners/HotCorner.vala',
4343
'HotCorners/HotCornerManager.vala',
44-
'ShellClients/CenteredWindow.vala',
4544
'ShellClients/HideTracker.vala',
4645
'ShellClients/ManagedClient.vala',
4746
'ShellClients/NotificationsClient.vala',
4847
'ShellClients/PanelClone.vala',
4948
'ShellClients/PanelWindow.vala',
5049
'ShellClients/ShellClientsManager.vala',
50+
'ShellClients/WindowPositioner.vala',
5151
'Widgets/DwellClickTimer.vala',
5252
'Widgets/IconGroup.vala',
5353
'Widgets/IconGroupContainer.vala',

0 commit comments

Comments
 (0)