Skip to content

Add param to choose which monitor the window will be placed on - #10

Merged
VimYoung merged 9 commits into
VimYoung:mainfrom
dotsem:main
Jan 2, 2026
Merged

VimYoung merged 9 commits into
VimYoung:mainfrom
dotsem:main

Conversation

@dotsem

@dotsem dotsem commented Dec 29, 2025 •

Copy link
Copy Markdown
Contributor

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:

let monitors: Vec<Monitor> = match Monitors::get() {
      Ok(monitors) => monitors.iter().cloned().collect(),
      Err(e) => {
          error!("Failed to get monitors: {}", e);
          return Err(e.into());
      }
  };

  if monitors.is_empty() {
      error!("No monitors found!");
      return Err("No monitors found!".into());
  }

  debug!("Found {} monitors", monitors.len());

  let configs: Vec<(String, WindowConf)> = monitors
      .iter()
      .map(|monitor| {
          let name = format!("taskbar-{}", monitor.name);
          let conf = WindowConf::new(
              monitor.width as u32,
              TASKBAR_HEIGHT,
              (
                  Some(LayerAnchor::TOP | LayerAnchor::LEFT | LayerAnchor::RIGHT),
                  None,
              ),
              (0, 0, 0, 0),
              LayerType::Top,
              BoardType::None,
              Some(TASKBAR_HEIGHT as i32),
              Some(monitor.name.clone()),
          );
          (name, conf)
      })
      .collect();

  let configs_ref: Vec<(&str, WindowConf)> = configs
      .iter()
      .map(|(name, conf)| (name.as_str(), conf.clone()))
      .collect();

  let windows: Vec<SpellWin> = SpellMultiWinHandler::conjure_spells(configs_ref);

  debug!("Created {} windows", windows.len());

Copilot AI review requested due to automatic review settings December 29, 2025 22:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_name field to WindowConf struct for specifying target monitor
  • Implemented monitor discovery logic using temporary Wayland queue during window creation
  • Added TempState helper 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.

Comment thread spell-framework/src/configure.rs Resolved
Comment thread spell-framework/src/configure.rs Resolved
layer_type: Layer,
board_interactivity: KeyboardInteractivity,
exclusive_zone: Option<i32>,
monitor_name: Option<String>,

Copilot AI Dec 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

@VimYoung VimYoung Jan 1, 2026 •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread spell-framework/src/wayland_adapter.rs Resolved
Comment thread spell-framework/src/wayland_adapter.rs Resolved
Comment thread spell-framework/src/wayland_adapter.rs Resolved
@dotsem
dotsem marked this pull request as draft December 30, 2025 10:23
@dotsem

dotsem commented Dec 31, 2025

Copy link
Copy Markdown
Contributor Author

I tested it on 2 monitors & 1 monitor
(CapyShell is my own shell written with the Spell Framework)

log 2 monitors:

INFO Win: taskbar-eDP-1 layer created successfully.
INFO Win: taskbar-HDMI-A-1 layer created successfully.
INFO Taskbar 0 assigned to monitor 'eDP-1'
INFO Taskbar 1 assigned to monitor 'HDMI-A-1'
INFO CapyShell running with 2 taskbars.
INFO Starting windows
TRACE SpellWin { adapter: SpellSkiaWinAdapter { size: Cell { value: PhysicalSize { width: 1920, height: 48 } }, redraw: Cell { value: true } }, first_configure: true, is_hidden: Cell { value: false }, config: WindowConf { width: 1920, height: 48, anchor: (Some(Anchor(TOP | LEFT | RIGHT)), None), margin: (0, 0, 0, 0), layer_type: Top, board_interactivity: Cell { value: None }, exclusive_zone: Some(48), monitor_name: Some("eDP-1") } }
TRACE SpellWin { adapter: SpellSkiaWinAdapter { size: Cell { value: PhysicalSize { width: 1920, height: 48 } }, redraw: Cell { value: true } }, first_configure: true, is_hidden: Cell { value: false }, config: WindowConf { width: 1920, height: 48, anchor: (Some(Anchor(TOP | LEFT | RIGHT)), None), margin: (0, 0, 0, 0), layer_type: Top, board_interactivity: Cell { value: None }, exclusive_zone: Some(48), monitor_name: Some("HDMI-A-1") } }

log 1 monitor:

INFO Win: taskbar-eDP-1 layer created successfully.
INFO Taskbar 0 assigned to monitor 'eDP-1'
INFO CapyShell running with 1 taskbars.
INFO Starting windows
TRACE SpellWin { adapter: SpellSkiaWinAdapter { size: Cell { value: PhysicalSize { width: 1920, height: 48 } }, redraw: Cell { value: true } }, first_configure: true, is_hidden: Cell { value: false }, config: WindowConf { width: 1920, height: 48, anchor: (Some(Anchor(TOP | LEFT | RIGHT)), None), margin: (0, 0, 0, 0), layer_type: Top, board_interactivity: Cell { value: None }, exclusive_zone: Some(48), monitor_name: Some("eDP-1") } }

@dotsem
dotsem marked this pull request as ready for review December 31, 2025 16:32
Comment thread spell-framework/src/wayland_adapter.rs Outdated
let output_state = OutputState::new(&temp_globals, &temp_queue_handle);
let mut temp_state = TempState { output_state };

temp_queue.roundtrip(&mut temp_state).ok()?;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something similar I did for getting monitors in SpellLock.

@dotsem

dotsem commented Jan 1, 2026

Copy link
Copy Markdown
Contributor Author

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.

@dotsem
dotsem requested a review from VimYoung January 1, 2026 21:57
VimYoung

This comment was marked as outdated.

@VimYoung
VimYoung dismissed their stale review January 2, 2026 04:51

Not necessary.

@VimYoung
VimYoung merged commit 67faeeb into VimYoung:main Jan 2, 2026
@VimYoung

VimYoung commented Jan 2, 2026

Copy link
Copy Markdown
Owner

Thanks for your contribution, that will do. I will keep a note that global var needs refreshing if a monitor is un-plugged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants