Last active
February 9, 2025 16:01
-
-
Save Opposite34/f3a487d940e9fb968d01f7e30969fbd1 to your computer and use it in GitHub Desktop.
Dwindle (BSPWM, Qtile, Hyprland)-style Tiling Script for GlazeWM
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
| import asyncio | |
| import websockets | |
| import json | |
| async def main(): | |
| uri = "ws://localhost:6123" | |
| async with websockets.connect(uri) as websocket: | |
| await websocket.send("sub -e window_managed") | |
| await websocket.send("sub -e focus_changed") | |
| await websocket.send("sub -e focused_container_moved") | |
| while True: | |
| response = await websocket.recv() | |
| json_response = json.loads(response) | |
| if json_response["messageType"] == "client_response": | |
| print(f"Event subscription: {json_response['success']}") | |
| elif json_response["messageType"] == "event_subscription": | |
| window_data = json_response['data'].get('managedWindow') or json_response['data'].get('focusedContainer') | |
| width = window_data['width'] | |
| height = window_data['height'] | |
| print(f"Width: {width}, Height: {height}") | |
| if width != None and height != None: | |
| if width > height: | |
| await websocket.send('c set-tiling-direction horizontal') | |
| elif width < height: | |
| await websocket.send('c set-tiling-direction vertical') | |
| if __name__ == "__main__": | |
| asyncio.run(main()) |
Author
Author
I have now edited this to check window focused and also to base the tiling direction with width/height instead of just toggling. Thank you ThePhxRises on GlazeWM Discord for bringing attention to this.
It is still not fully correct Dwindle behavior though, since the tiling direction check is still done after an action happens like I previously said (this happens when say you move a window the left window from a left top-right/down-right to the right side, it won't be replacing the top-right or the down-right like how Dwindle does.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: so while I said it's dwindle-style it's not 1:1 with dwindle. This is because the direction is calculate at window resizing / closing.
That means if you tile from 1x1 (which spawns window to the left) and then tile on the left window, you don't get a 2x2 grid and you'd still get a 3x1 grid.
You could probably check the size of the currently focused window and then autotile that way to get the exact dwindle behavior. I'm not sure if that's going to be too much or not (and the tiling algo above works well enough for me so).