Skip to content

Instantly share code, notes, and snippets.

@Opposite34
Last active February 9, 2025 16:01
Show Gist options
  • Select an option

  • Save Opposite34/f3a487d940e9fb968d01f7e30969fbd1 to your computer and use it in GitHub Desktop.

Select an option

Save Opposite34/f3a487d940e9fb968d01f7e30969fbd1 to your computer and use it in GitHub Desktop.
Dwindle (BSPWM, Qtile, Hyprland)-style Tiling Script for GlazeWM
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())
@Opposite34
Copy link
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