-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wayland: Implement make_center (#1942)
Co-authored-by: Danielle Foré <[email protected]>
- Loading branch information
1 parent
060deb2
commit f8346f0
Showing
6 changed files
with
119 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2024 elementary, Inc. (https://elementary.io) | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* | ||
* Authored by: Leonhard Kargl <[email protected]> | ||
*/ | ||
|
||
public class Gala.CenteredWindow : Object { | ||
public WindowManager wm { get; construct; } | ||
public Meta.Window window { get; construct; } | ||
|
||
public CenteredWindow (WindowManager wm, Meta.Window window) { | ||
Object (wm: wm, window: window); | ||
} | ||
|
||
construct { | ||
window.size_changed.connect (position_window); | ||
window.stick (); | ||
|
||
var monitor_manager = wm.get_display ().get_context ().get_backend ().get_monitor_manager (); | ||
monitor_manager.monitors_changed.connect (() => position_window ()); | ||
|
||
position_window (); | ||
|
||
window.shown.connect (() => window.focus (wm.get_display ().get_current_time ())); | ||
} | ||
|
||
private void position_window () { | ||
var display = wm.get_display (); | ||
var monitor_geom = display.get_monitor_geometry (display.get_primary_monitor ()); | ||
var window_rect = window.get_frame_rect (); | ||
|
||
var x = monitor_geom.x + (monitor_geom.width - window_rect.width) / 2; | ||
var y = monitor_geom.y + (monitor_geom.height - window_rect.height) / 2; | ||
|
||
Idle.add (() => { | ||
window.move_frame (false, x, y); | ||
return Source.REMOVE; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters