Launcher appears on correct display, Action centre can be triggered by control command

This commit is contained in:
jmb05
2026-11-02 19:55:43 +01:00
parent f46c2408a5
commit 541ce5ccb2
5 changed files with 33 additions and 15 deletions

View File

@@ -204,7 +204,7 @@ impl HyprlandComms {
.output() .output()
} }
pub fn _cursor_monitor() -> Option<MonitorId> { pub fn cursor_monitor() -> Option<MonitorId> {
if let Ok(pos) = CursorPosition::get() if let Ok(pos) = CursorPosition::get()
&& let Ok(monitors) = Monitors::get() && let Ok(monitors) = Monitors::get()
{ {

View File

@@ -9,12 +9,14 @@ pub const SOCKET_PATH: &str = "/run/user/1000/jmb-bar.sock";
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum ControlCommand { pub enum ControlCommand {
OpenRunMenu, OpenRunMenu,
OpenNetMenu,
} }
impl Display for ControlCommand { impl Display for ControlCommand {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self { match self {
ControlCommand::OpenRunMenu => f.write_str("menu"), ControlCommand::OpenRunMenu => f.write_str("menu"),
ControlCommand::OpenNetMenu => f.write_str("net"),
} }
} }
} }
@@ -25,6 +27,7 @@ impl FromStr for ControlCommand {
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
match s { match s {
"menu" => Ok(ControlCommand::OpenRunMenu), "menu" => Ok(ControlCommand::OpenRunMenu),
"net" => Ok(ControlCommand::OpenNetMenu),
other => Err(format!("Unknown command: {other}")), other => Err(format!("Unknown command: {other}")),
} }
} }

View File

@@ -46,9 +46,9 @@ pub fn create_bars(app: &Application, backend: Backend) {
); );
} }
let backend_clone = backend.clone(); let backend_clone = backend.clone();
display display.monitors().connect_items_changed({
.monitors() let action_centre = action_centre.clone();
.connect_items_changed(move |_list, pos, removed, added| { move |_list, pos, removed, added| {
if removed == 1 { if removed == 1 {
debug!(&LOGGER, "Detected Monitor disconnect {pos}"); debug!(&LOGGER, "Detected Monitor disconnect {pos}");
if let Some(bar) = bars.lock().expect("Couldn't get active bars").remove(&pos) { if let Some(bar) = bars.lock().expect("Couldn't get active bars").remove(&pos) {
@@ -68,21 +68,26 @@ pub fn create_bars(app: &Application, backend: Backend) {
); );
}); });
} }
}); }
});
let mut ctl_channel = backend.subscribe(&[ChannelType::Control]); let mut ctl_channel = backend.subscribe(&[ChannelType::Control]);
let ctl_rx = ctl_channel.take_ctl_rx().unwrap(); let ctl_rx = ctl_channel.take_ctl_rx().unwrap();
let app_clone = app.clone(); let app_clone = app.clone();
let mut menu = RunMenu::create(app_clone); let mut menu = RunMenu::create(app_clone);
glib::timeout_add_local(Duration::from_millis(100), move || { glib::timeout_add_local(Duration::from_millis(100), {
while let Ok(cmd) = ctl_rx.try_recv() { let action_centre = action_centre.clone();
match cmd { move || {
ControlCommand::OpenRunMenu => { while let Ok(cmd) = ctl_rx.try_recv() {
menu.show(); match cmd {
ControlCommand::OpenRunMenu => menu.show(),
ControlCommand::OpenNetMenu => {
action_centre.show_action_centre_active_monitor()
}
} }
} }
ControlFlow::Continue
} }
ControlFlow::Continue
}); });
} }

View File

@@ -2,6 +2,7 @@ use crate::backend::BackendChannels;
use crate::backend::network::{ use crate::backend::network::{
Auth, AuthType, ConnectError, NetworkCommand, NetworkInfo, NetworkState, Auth, AuthType, ConnectError, NetworkCommand, NetworkInfo, NetworkState,
}; };
use crate::backend::window_manager_hypr::HyprlandComms;
use crate::ui::widgets::{LabelEntry, WifiWidget}; use crate::ui::widgets::{LabelEntry, WifiWidget};
use glib::prelude::Cast; use glib::prelude::Cast;
use glib::{ControlFlow, clone}; use glib::{ControlFlow, clone};
@@ -58,7 +59,7 @@ impl ActionCentre {
window.set_margin(Edge::Top, 20); window.set_margin(Edge::Top, 20);
window.set_margin(Edge::Right, 20); window.set_margin(Edge::Right, 20);
window.set_margin(Edge::Bottom, 20); window.set_margin(Edge::Bottom, 20);
window.set_keyboard_mode(KeyboardMode::OnDemand); window.set_keyboard_mode(KeyboardMode::Exclusive);
let instance = Self { let instance = Self {
window: window.clone(), window: window.clone(),
@@ -318,6 +319,16 @@ impl ActionCentre {
} }
} }
pub fn show_action_centre_active_monitor(&self) {
let Some(display) = Display::default() else {
return;
};
let Some(monitor) = HyprlandComms::cursor_monitor() else {
return;
};
self.show_action_centre(monitor as u32, &display);
}
pub fn show_action_centre(&self, monitor_idx: u32, display: &Display) { pub fn show_action_centre(&self, monitor_idx: u32, display: &Display) {
let window = &self.window; let window = &self.window;
let monitors = display.monitors(); let monitors = display.monitors();

View File

@@ -67,9 +67,8 @@ impl RunMenu {
window.set_child(Some(&v_box)); window.set_child(Some(&v_box));
let display = Display::default().expect("Couldn't get display"); let display = Display::default().expect("Couldn't get display");
let monitor = display let monitor = HyprlandComms::cursor_monitor()
.monitors() .and_then(|id| display.monitors().item(id as u32))
.item(HyprlandComms::current_monitor() as u32)
.expect("Couldn't get monitor") .expect("Couldn't get monitor")
.downcast::<Monitor>() .downcast::<Monitor>()
.ok(); .ok();