Created
February 5, 2021 22:16
-
-
Save ramnes/a9c10e45801a17ef69e172f276629e06 to your computer and use it in GitHub Desktop.
Qtile hook to center all floating windows, until more sensible defaults or a better solution are available
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
@hook.subscribe.float_change | |
def center_window(): | |
client = qtile.current_window | |
if not client.floating: | |
return | |
screen_rect = qtile.current_screen.get_rect() | |
center_x = screen_rect.x + screen_rect.width / 2 | |
center_y = screen_rect.y + screen_rect.height / 2 | |
x = center_x - client.width / 2 | |
y = center_y - client.height / 2 | |
# don't go off the right... | |
x = min(x, screen_rect.x + screen_rect.width - client.width) | |
# or left... | |
x = max(x, screen_rect.x) | |
# or bottom... | |
y = min(y, screen_rect.y + screen_rect.height - client.height) | |
# or top | |
y = max(y, screen_rect.y) | |
client.x = int(round(x)) | |
client.y = int(round(y)) | |
qtile.current_group.layout_all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much for this! I use it in my config across all machines, works beautifully.
However I encountered a small problem with it when trying to fullscreen YouTube videos (for example) in a browser. It would maximize the video, but the bar would not hide, e.g. not completely fullscreen.
From my understanding a fullscreen video is also floating, which meant that the hook to center floating windows was interfering.
So on line 4 I did a very small adjustment to check if the window is fullscreening:
Now fullscreen videos work properly and floating videos get centered as they should.
I am not a programmer by trade so I don't know if there is a better solution, but maybe this helps someone.