Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic monitor switching? #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/bus/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ pub struct Notification {
pub tag: Option<String>,
pub note: Option<String>,

pub monitor: Option<String>,

pub app_name: String,

pub summary: String,
Expand Down Expand Up @@ -283,6 +285,7 @@ impl Notification {
id,
tag: None,
note: None,
monitor: None,
app_name: "Wired".to_owned(),
summary: summary.to_owned(),
body: body.to_owned(),
Expand Down Expand Up @@ -438,6 +441,9 @@ impl Notification {
let tag = arg::prop_cast::<String>(&hints, "wired-tag").cloned();
let note = arg::prop_cast::<String>(&hints, "wired-note").cloned();

// Allow overriding the monitor through a hint, used for scripts.
let monitor = arg::prop_cast::<String>(&hints, "wired-monitor").cloned();

let percentage: Option<f32>;
if let Some(value) = arg::prop_cast::<i32>(&hints, "value") {
// This should be ok since we only support values from 0 to 100.
Expand All @@ -457,6 +463,7 @@ impl Notification {
id,
tag,
note,
monitor,
app_name,
summary,
body,
Expand Down
37 changes: 37 additions & 0 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ impl NotifyWindowManager {
let (pos, size) = (monitor.position(), monitor.size());
let monitor_rect = Rect::new(pos.x.into(), pos.y.into(), size.width.into(), size.height.into());
let mut prev_rect = monitor_rect;
let mut last_mon = monitor;

let mut real_idx = 0;
for window in windows {
Expand All @@ -269,6 +270,42 @@ impl NotifyWindowManager {
continue;
}

// Testing individual notification monitor overrides:
// This is not the right way to handle this IMO, but it works.
// Ideally, creating a notification with a monitor override would
// actually create a new layout/window for that stack of notifications
// on that monitor. We could do this statically by defining RenderCriteria
// for each monitor, but that wouldn't actually scale dynamically with an
// arbitrary number of monitors. It also would mean duplicating entire
// layout stacks, at least until templates become an option, which still
// wouldn't completely solve the issue, but would make it better.
if window.notification.monitor.is_some() {
let maybe_monitor2 = self
.base_window
.available_monitors()
.nth(window
.notification
.monitor
.as_ref()
.unwrap()
.parse::<i8>()
.unwrap() as usize
);

if maybe_monitor2.is_some() {
let new_mon = maybe_monitor2.unwrap();
if last_mon != new_mon {
let new_rect = Rect::new(
new_mon.position().x.into(),
new_mon.position().y.into(),
new_mon.size().width.into(),
new_mon.size().height.into());
prev_rect = new_rect;
last_mon = new_mon;
}
}
}

let mut window_rect = window.get_inner_rect();

// For the first notification, we attach to the monitor.
Expand Down