-
-
Notifications
You must be signed in to change notification settings - Fork 77
Introduce a WindowPositioner #2087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dc36a60
Introduce a WindowPositioner
leolost2605 e0d73b4
Cleanup
leolost2605 f8bd6cf
We dont need idle
leolost2605 6711ee3
Move positioning funcs to the WindowPositioner
leolost2605 659a492
Merge branch 'main' into leolost/window-positioner
leolost2605 7765ecc
Update src/ShellClients/WindowPositioner.vala
lenemter 72d7c75
Merge branch 'main' into leolost/window-positioner
lenemter b7e9520
Merge branch 'main' into leolost/window-positioner
lenemter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,60 @@ | ||
| /* | ||
| * Copyright 2024 elementary, Inc. (https://elementary.io) | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| * | ||
| * Authored by: Leonhard Kargl <[email protected]> | ||
| */ | ||
|
|
||
| public class Gala.WindowPositioner : Object { | ||
| public enum Position { | ||
| CENTER | ||
| } | ||
|
|
||
| public Meta.Window window { get; construct; } | ||
| public WindowManager wm { get; construct; } | ||
| public Position position { get; private set; } | ||
| public Variant? position_data { get; private set; } | ||
|
|
||
| public WindowPositioner (WindowManager wm, Meta.Window window, Position position, Variant? position_data = null) { | ||
| Object (wm: wm, window: window, position: position, position_data: position_data); | ||
| } | ||
|
|
||
| construct { | ||
| window.stick (); | ||
|
|
||
| window.size_changed.connect (position_window); | ||
| window.position_changed.connect (position_window); | ||
| window.shown.connect (position_window); | ||
|
|
||
| var monitor_manager = wm.get_display ().get_context ().get_backend ().get_monitor_manager (); | ||
| monitor_manager.monitors_changed.connect (position_window); | ||
| monitor_manager.monitors_changed_internal.connect (position_window); | ||
| } | ||
|
|
||
| /** | ||
| * This may only be called after the window was shown. | ||
| */ | ||
| public void update_position (Position new_position, Variant? new_position_data = null) { | ||
| position = new_position; | ||
| position_data = new_position_data; | ||
|
|
||
| position_window (); | ||
| } | ||
|
|
||
| private void position_window () { | ||
| int x = 0, y = 0; | ||
|
|
||
| switch (position) { | ||
| case CENTER: | ||
| unowned var display = wm.get_display (); | ||
| var monitor_geom = display.get_monitor_geometry (display.get_primary_monitor ()); | ||
| var window_rect = window.get_frame_rect (); | ||
|
|
||
| x = monitor_geom.x + (monitor_geom.width - window_rect.width) / 2; | ||
| y = monitor_geom.y + (monitor_geom.height - window_rect.height) / 2; | ||
| break; | ||
| } | ||
|
|
||
| window.move_frame (false, x, y); | ||
| } | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.