From 26f8c1aeb6131a98357b6cf7ee03ded90418fb58 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Thu, 7 Apr 2022 23:21:32 +0200 Subject: [PATCH] autocommit 2022-04-07 23:21:31 CEST --- src/config/handler.rs | 11 ++++++++ src/ifs/wl_seat.rs | 29 ++++++++++++++++++--- src/ifs/wl_seat/event_handling.rs | 3 ++- src/ifs/wl_seat/wl_pointer.rs | 2 +- src/ifs/wl_surface.rs | 2 +- src/ifs/wl_surface/cursor.rs | 2 +- src/ifs/wl_surface/xwindow.rs | 7 ++--- src/ifs/wl_surface/zwlr_layer_surface_v1.rs | 5 ---- src/state.rs | 5 ++++ src/tasks/connector.rs | 7 +++++ src/tree/display.rs | 14 ++-------- src/tree/output.rs | 22 ++++++++++++++++ src/utils/copyhashmap.rs | 4 +++ src/xwayland/xwm.rs | 1 - 14 files changed, 86 insertions(+), 28 deletions(-) diff --git a/src/config/handler.rs b/src/config/handler.rs index c7610695..bdeb251d 100644 --- a/src/config/handler.rs +++ b/src/config/handler.rs @@ -354,6 +354,17 @@ impl ConfigProxyHandler { if x < 0 || y < 0 || x > MAX_EXTENTS || y > MAX_EXTENTS { return Err(CphError::InvalidConnectorPosition(x, y)); } + let old_pos = connector.node.global.pos.get(); + let seats = self.state.globals.seats.lock(); + for seat in seats.values() { + if seat.get_output().id == connector.node.id { + let seat_pos = seat.position(); + seat.set_position( + seat_pos.0.round_down() + x - old_pos.x1(), + seat_pos.1.round_down() + y - old_pos.y1(), + ); + } + } connector.node.set_position(x, y); Ok(()) } diff --git a/src/ifs/wl_seat.rs b/src/ifs/wl_seat.rs index be69a086..c27d5fd2 100644 --- a/src/ifs/wl_seat.rs +++ b/src/ifs/wl_seat.rs @@ -132,6 +132,7 @@ pub struct WlSeatGlobal { queue_link: Cell>>>, tree_changed_handler: Cell>>, output: CloneCell>, + desired_known_cursor: Cell>, } impl WlSeatGlobal { @@ -168,6 +169,7 @@ impl WlSeatGlobal { queue_link: Cell::new(None), tree_changed_handler: Cell::new(None), output: CloneCell::new(state.dummy_output.get().unwrap()), + desired_known_cursor: Cell::new(None), }); let seat = slf.clone(); let future = state.eng.spawn(async move { @@ -210,6 +212,21 @@ impl WlSeatGlobal { } } + pub fn set_position(&self, x: i32, y: i32) { + self.pos.set((Fixed::from_int(x), Fixed::from_int(y))); + self.trigger_tree_changed(); + } + + pub fn position(&self) -> (Fixed, Fixed) { + self.pos.get() + } + + pub fn render_ctx_changed(&self) { + if let Some(cursor) = self.desired_known_cursor.get() { + self.set_known_cursor(cursor); + } + } + pub fn get_mono(&self) -> Option { self.keyboard_node.get().get_parent_mono() } @@ -326,10 +343,11 @@ impl WlSeatGlobal { } pub fn set_known_cursor(&self, cursor: KnownCursor) { + self.desired_known_cursor.set(Some(cursor)); let cursors = match self.state.cursors.get() { Some(c) => c, None => { - self.set_cursor(None); + self.set_cursor2(None); return; } }; @@ -342,10 +360,15 @@ impl WlSeatGlobal { KnownCursor::ResizeBottomLeft => &cursors.resize_bottom_left, KnownCursor::ResizeBottomRight => &cursors.resize_bottom_right, }; - self.set_cursor(Some(tpl.instantiate())); + self.set_cursor2(Some(tpl.instantiate())); } - pub fn set_cursor(&self, cursor: Option>) { + pub fn set_app_cursor(&self, cursor: Option>) { + self.set_cursor2(cursor); + self.desired_known_cursor.set(None); + } + + fn set_cursor2(&self, cursor: Option>) { if let Some(old) = self.cursor.get() { if let Some(new) = cursor.as_ref() { if rc_eq(&old, new) { diff --git a/src/ifs/wl_seat/event_handling.rs b/src/ifs/wl_seat/event_handling.rs index 35615ccd..1bf69a98 100644 --- a/src/ifs/wl_seat/event_handling.rs +++ b/src/ifs/wl_seat/event_handling.rs @@ -452,8 +452,9 @@ impl WlSeatGlobal { impl WlSeatGlobal { pub fn enter_toplevel(self: &Rc, n: Rc) { if n.accepts_keyboard_focus() { - self.focus_toplevel(n); + log::info!("does not accept input focus"); } + self.focus_toplevel(n); } pub fn enter_popup(self: &Rc, _n: &Rc) { diff --git a/src/ifs/wl_seat/wl_pointer.rs b/src/ifs/wl_seat/wl_pointer.rs index 1add4e57..f9b69309 100644 --- a/src/ifs/wl_seat/wl_pointer.rs +++ b/src/ifs/wl_seat/wl_pointer.rs @@ -144,7 +144,7 @@ impl WlPointer { if pointer_node.client_id() != Some(self.seat.client.id) { return Ok(()); } - self.seat.global.set_cursor(cursor_opt); + self.seat.global.set_app_cursor(cursor_opt); Ok(()) } diff --git a/src/ifs/wl_surface.rs b/src/ifs/wl_surface.rs index 9c2e0671..a20fb867 100644 --- a/src/ifs/wl_surface.rs +++ b/src/ifs/wl_surface.rs @@ -253,7 +253,7 @@ impl WlSurface { pub fn accepts_kb_focus(&self) -> bool { match self.toplevel.get() { - Some(tl) => tl.accepts_keyboard_focus(), + Some(tl) => true, _ => self.ext.get().accepts_kb_focus(), } } diff --git a/src/ifs/wl_surface/cursor.rs b/src/ifs/wl_surface/cursor.rs index f9adf64d..f051aec1 100644 --- a/src/ifs/wl_surface/cursor.rs +++ b/src/ifs/wl_surface/cursor.rs @@ -46,7 +46,7 @@ impl CursorSurface { } pub fn handle_surface_destroy(&self) { - self.seat.set_cursor(None); + self.seat.set_app_cursor(None); } pub fn handle_buffer_change(&self) { diff --git a/src/ifs/wl_surface/xwindow.rs b/src/ifs/wl_surface/xwindow.rs index 752cf0f9..6049fc3a 100644 --- a/src/ifs/wl_surface/xwindow.rs +++ b/src/ifs/wl_surface/xwindow.rs @@ -26,7 +26,7 @@ use { jay_config::Direction, std::{ cell::{Cell, RefCell}, - ops::{Deref, Not}, + ops::{Deref}, rc::Rc, }, thiserror::Error, @@ -273,7 +273,7 @@ impl Xwindow { pub fn map_status_changed(self: &Rc) { match self.map_change() { - Change::None => {} + Change::None => return, Change::Unmap => self.destroy_node(true), Change::Map if self.data.info.override_redirect.get() => { *self.display_link.borrow_mut() = @@ -304,6 +304,7 @@ impl Xwindow { self.data.title_changed(); } } + self.data.state.tree_changed(); } } @@ -447,7 +448,7 @@ impl ToplevelNode for Xwindow { } fn accepts_keyboard_focus(&self) -> bool { - self.data.info.never_focus.get().not() && self.data.info.icccm_hints.input.get() + self.data.info.input_model.get() != XInputModel::None } fn default_surface(&self) -> Rc { diff --git a/src/ifs/wl_surface/zwlr_layer_surface_v1.rs b/src/ifs/wl_surface/zwlr_layer_surface_v1.rs index 37dd92cd..f8455aa6 100644 --- a/src/ifs/wl_surface/zwlr_layer_surface_v1.rs +++ b/src/ifs/wl_surface/zwlr_layer_surface_v1.rs @@ -375,11 +375,6 @@ impl Node for ZwlrLayerSurfaceV1 { } fn find_tree_at(&self, x: i32, y: i32, tree: &mut Vec) -> FindTreeResult { - tree.push(FoundNode { - node: self.surface.clone(), - x, - y, - }); self.surface.find_tree_at_(x, y, tree) } diff --git a/src/state.rs b/src/state.rs index 783dd18e..423683d2 100644 --- a/src/state.rs +++ b/src/state.rs @@ -130,6 +130,11 @@ impl State { } } self.root.clone().visit(&mut Walker); + + let seats = self.globals.seats.lock(); + for seat in seats.values() { + seat.render_ctx_changed(); + } } pub fn add_global(&self, global: &Rc) { diff --git a/src/tasks/connector.rs b/src/tasks/connector.rs index c84b98e6..0cb5cb10 100644 --- a/src/tasks/connector.rs +++ b/src/tasks/connector.rs @@ -101,12 +101,19 @@ impl ConnectorHandler { state: self.state.clone(), is_dummy: false, }); + let mode = info.initial_mode; let output_data = Rc::new(OutputData { connector: self.data.clone(), monitor_info: info, node: on.clone(), }); self.state.outputs.set(self.id, output_data); + if self.state.outputs.len() == 1 { + let seats = self.state.globals.seats.lock(); + for seat in seats.values() { + seat.set_position(x1 + mode.width / 2, mode.height / 2); + } + } global.node.set(Some(on.clone())); if let Some(config) = self.state.config.get() { config.connector_connected(self.id); diff --git a/src/tree/display.rs b/src/tree/display.rs index 9d73cdcf..993a6bc2 100644 --- a/src/tree/display.rs +++ b/src/tree/display.rs @@ -79,18 +79,8 @@ impl Node for DisplayNode { x, y, }); - let len = tree.len(); - for layer in [OVERLAY, TOP] { - for surface in output.layers[layer as usize].rev_iter() { - let pos = surface.absolute_position(); - if pos.contains(x, y) { - let (x, y) = pos.translate(x, y); - if surface.find_tree_at(x, y, tree) == FindTreeResult::AcceptsInput { - return FindTreeResult::AcceptsInput; - } - tree.truncate(len); - } - } + if output.find_layer_surface_at(x, y, &[OVERLAY, TOP], tree) == FindTreeResult::AcceptsInput { + return FindTreeResult::AcceptsInput; } tree.pop(); break; diff --git a/src/tree/output.rs b/src/tree/output.rs index 36ddd99a..27c20c2a 100644 --- a/src/tree/output.rs +++ b/src/tree/output.rs @@ -23,6 +23,7 @@ use { rc::Rc, }, }; +use crate::ifs::zwlr_layer_shell_v1::{BACKGROUND, BOTTOM}; tree_id!(OutputNodeId); pub struct OutputNode { @@ -163,6 +164,23 @@ impl OutputNode { } self.global.send_mode(); } + + pub fn find_layer_surface_at(&self, x: i32, y: i32, layers: &[u32], tree: &mut Vec) -> FindTreeResult { + let len = tree.len(); + for layer in layers.iter().copied() { + for surface in self.layers[layer as usize].rev_iter() { + let pos = surface.absolute_position(); + if pos.contains(x, y) { + let (x, y) = pos.translate(x, y); + if surface.find_tree_at(x, y, tree) == FindTreeResult::AcceptsInput { + return FindTreeResult::AcceptsInput; + } + tree.truncate(len); + } + } + } + FindTreeResult::Other + } } pub struct OutputTitle { @@ -228,6 +246,7 @@ impl Node for OutputNode { let th = self.state.theme.title_height.get(); if y > th { y -= th; + let len = tree.len(); if let Some(ws) = self.workspace.get() { tree.push(FoundNode { node: ws.clone(), @@ -236,6 +255,9 @@ impl Node for OutputNode { }); ws.find_tree_at(x, y, tree); } + if tree.len() == len { + self.find_layer_surface_at(x, y, &[BOTTOM, BACKGROUND], tree); + } } FindTreeResult::AcceptsInput } diff --git a/src/utils/copyhashmap.rs b/src/utils/copyhashmap.rs index 7e9319ba..0ec070ea 100644 --- a/src/utils/copyhashmap.rs +++ b/src/utils/copyhashmap.rs @@ -78,6 +78,10 @@ impl CopyHashMap { pub fn is_empty(&self) -> bool { unsafe { self.map.get().deref().is_empty() } } + + pub fn len(&self) -> usize { + unsafe { self.map.get().deref().len() } + } } pub struct Locked<'a, K, V> { diff --git a/src/xwayland/xwm.rs b/src/xwayland/xwm.rs index 59e5732d..72da70af 100644 --- a/src/xwayland/xwm.rs +++ b/src/xwayland/xwm.rs @@ -460,7 +460,6 @@ impl Wm { return; } let accepts_input = window.info.icccm_hints.input.get(); - log::info!("{:?} ai {}", window.info.title, accepts_input); let mask = if accepts_input { EVENT_MASK_SUBSTRUCTURE_REDIRECT } else {