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()
}
pub fn _cursor_monitor() -> Option<MonitorId> {
pub fn cursor_monitor() -> Option<MonitorId> {
if let Ok(pos) = CursorPosition::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)]
pub enum ControlCommand {
OpenRunMenu,
OpenNetMenu,
}
impl Display for ControlCommand {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
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> {
match s {
"menu" => Ok(ControlCommand::OpenRunMenu),
"net" => Ok(ControlCommand::OpenNetMenu),
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();
display
.monitors()
.connect_items_changed(move |_list, pos, removed, added| {
display.monitors().connect_items_changed({
let action_centre = action_centre.clone();
move |_list, pos, removed, added| {
if removed == 1 {
debug!(&LOGGER, "Detected Monitor disconnect {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 ctl_rx = ctl_channel.take_ctl_rx().unwrap();
let app_clone = 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), {
let action_centre = action_centre.clone();
move || {
while let Ok(cmd) = ctl_rx.try_recv() {
match cmd {
ControlCommand::OpenRunMenu => {
menu.show();
ControlCommand::OpenRunMenu => menu.show(),
ControlCommand::OpenNetMenu => {
action_centre.show_action_centre_active_monitor()
}
}
}
ControlFlow::Continue
}
});
}

View File

@@ -2,6 +2,7 @@ use crate::backend::BackendChannels;
use crate::backend::network::{
Auth, AuthType, ConnectError, NetworkCommand, NetworkInfo, NetworkState,
};
use crate::backend::window_manager_hypr::HyprlandComms;
use crate::ui::widgets::{LabelEntry, WifiWidget};
use glib::prelude::Cast;
use glib::{ControlFlow, clone};
@@ -58,7 +59,7 @@ impl ActionCentre {
window.set_margin(Edge::Top, 20);
window.set_margin(Edge::Right, 20);
window.set_margin(Edge::Bottom, 20);
window.set_keyboard_mode(KeyboardMode::OnDemand);
window.set_keyboard_mode(KeyboardMode::Exclusive);
let instance = Self {
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) {
let window = &self.window;
let monitors = display.monitors();

View File

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