Repository navigation
Add param to choose which monitor the window will be placed on - #10
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds the ability to specify which monitor a window should be placed on by accepting an optional monitor name parameter. When a monitor name is provided, the framework queries available monitors via Wayland protocol and places the window on the matching monitor, falling back to the default monitor if the specified one is not found.
Key Changes:
- Added
monitor_namefield toWindowConfstruct for specifying target monitor - Implemented monitor discovery logic using temporary Wayland queue during window creation
- Added
TempStatehelper struct to handle monitor enumeration via Wayland's OutputState
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| spell-framework/src/configure.rs | Adds monitor_name field to WindowConf struct and updates constructor to accept monitor name parameter |
| spell-framework/src/wayland_adapter.rs | Implements monitor discovery logic, creates temporary Wayland state for monitor enumeration, and adds TempState handler implementation |
| Cargo.lock | Updates spell-framework version from 1.0.0 to 1.0.1 and adjusts dependency references |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| layer_type: Layer, | ||
| board_interactivity: KeyboardInteractivity, | ||
| exclusive_zone: Option<i32>, | ||
| monitor_name: Option<String>, |
There was a problem hiding this comment.
Adding a new required parameter to WindowConf::new() is a breaking API change. All existing code using this constructor will fail to compile. Consider adding a separate constructor like new_with_monitor() or making this parameter the last in a builder pattern, or provide a default value through an impl Default or by making the new parameter have a default value in a different way. This breaking change will affect all users of the spell-framework library who have hardcoded calls to WindowConf::new(), including the template code in spell-cli/src/constantvals.rs.
There was a problem hiding this comment.
Adding monitor_name breaks API, I was thinking of adding a builder method (with intermediate struct WindowConfBuilder) because in a sense apart from width and height, there can be defaults set for every other argument. Then we can mark WindowConf::new as #[deprecated()] to be removed from 1.0.5(giving time for transition to the new way). Link of discussion regarding concerns about changing the APIs. I just wanted that since 1.0.0 is out, people may actually be using it, so end interface changes should be a bit gradual.
|
I tested it on 2 monitors & 1 monitor log 2 monitors: INFO Win: taskbar-eDP-1 layer created successfully. log 1 monitor: INFO Win: taskbar-eDP-1 layer created successfully. |
| let output_state = OutputState::new(&temp_globals, &temp_queue_handle); | ||
| let mut temp_state = TempState { output_state }; | ||
|
|
||
| temp_queue.roundtrip(&mut temp_state).ok()?; |
There was a problem hiding this comment.
The logic seems perfect, I was just thinking for a way to avoid a whole connection to compositor just to get monitors/outputs. I think this logic can directly be embed into SpellWin if we wrap the LayerSurface in an option and confirm a roundtrip of SpellWIn and later set it. The only downside seems to be addition of unwrap in a tone of places.
There was a problem hiding this comment.
Something similar I did for getting monitors in SpellLock.
…llwin event queue
|
I've embedded the monitor discovery into spellwin, it does in fact add some unwraps for everywhere where we use the layer attr, but they should in normal case never trigger a panic. I've decided to keep the caching to only do a roundtrip once. Ofcourse when (un)plugging a monitor, you have to soft restart your application, which is the easiest & safest solution (and still very fast). I think a sophisticated hotplug system could be addressed in the future. |
|
Thanks for your contribution, that will do. I will keep a note that global var needs refreshing if a monitor is un-plugged. |
I'm using the spell framework to create my own shell for hyprland. Currently the spell framework was missing the feature to choose which monitor the window should be placed on.
This is my implementation, it currently works by passing the name of the monitor (easily fetchable with hyprctl, or whatever is available on other DEs). If no monitor with that name is found, it will use the default monitor.
It now also includes caching, so the actual fetching of the monitors via Wayland happens only once.
impl: