66 */
77
88public 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