Send output enter/leave to pointer and DnD surfaces
Browse files at this commit382c049b5a67194761b75181bcd0506791602060Parent: 9168f083 changed files +91 -4
- src/cursor.rs +4 -0
- src/main.rs +1 -0
- src/niri.rs +86 -4
src/cursor.rsmodified+4 -0
| @@ -91,6 +91,10 @@ impl Cursor { | |||
| 91 | }) | 91 | }) |
| 92 | .clone() | 92 | .clone() |
| 93 | } | 93 | } |
| 94 | + | ||
| 95 | + pub fn get_cached_hotspot(&self, scale: i32) -> Option<Point<i32, Physical>> { | ||
| 96 | + self.cache.get(&scale).map(|(_, hotspot)| *hotspot) | ||
| 97 | + } | ||
| 94 | } | 98 | } |
| 95 | 99 | ||
| 96 | fn load_xcursor(theme: &str) -> anyhow::Result<Vec<Image>> { | 100 | fn load_xcursor(theme: &str) -> anyhow::Result<Vec<Image>> { |
src/main.rsmodified+1 -0
| @@ -116,6 +116,7 @@ fn main() { | |||
| 116 | 116 | ||
| 117 | // These should be called periodically, before flushing the clients. | 117 | // These should be called periodically, before flushing the clients. |
| 118 | state.niri.monitor_set.refresh(); | 118 | state.niri.monitor_set.refresh(); |
| 119 | + state.niri.refresh_pointer_outputs(); | ||
| 119 | state.niri.popups.cleanup(); | 120 | state.niri.popups.cleanup(); |
| 120 | state.update_focus(); | 121 | state.update_focus(); |
| 121 | 122 | ||
src/niri.rsmodified+86 -4
| @@ -12,6 +12,7 @@ use _server_decoration::server::org_kde_kwin_server_decoration_manager::Mode as | |||
| 12 | use anyhow::Context; | 12 | use anyhow::Context; |
| 13 | use sd_notify::NotifyState; | 13 | use sd_notify::NotifyState; |
| 14 | use smithay::backend::allocator::Fourcc; | 14 | use smithay::backend::allocator::Fourcc; |
| 15 | +use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement}; | ||
| 15 | use smithay::backend::renderer::element::surface::{ | 16 | use smithay::backend::renderer::element::surface::{ |
| 16 | render_elements_from_surface_tree, WaylandSurfaceRenderElement, | 17 | render_elements_from_surface_tree, WaylandSurfaceRenderElement, |
| 17 | }; | 18 | }; |
| @@ -24,10 +25,10 @@ use smithay::backend::renderer::element::{ | |||
| 24 | use smithay::backend::renderer::gles::{GlesMapping, GlesRenderer, GlesTexture}; | 25 | use smithay::backend::renderer::gles::{GlesMapping, GlesRenderer, GlesTexture}; |
| 25 | use smithay::backend::renderer::{Bind, ExportMem, Frame, ImportAll, Offscreen, Renderer}; | 26 | use smithay::backend::renderer::{Bind, ExportMem, Frame, ImportAll, Offscreen, Renderer}; |
| 26 | use smithay::desktop::utils::{ | 27 | use smithay::desktop::utils::{ |
| 27 | - send_dmabuf_feedback_surface_tree, send_frames_surface_tree, | 28 | + bbox_from_surface_tree, output_update, send_dmabuf_feedback_surface_tree, |
| 28 | - surface_presentation_feedback_flags_from_states, surface_primary_scanout_output, | 29 | + send_frames_surface_tree, surface_presentation_feedback_flags_from_states, |
| 29 | - take_presentation_feedback_surface_tree, update_surface_primary_scanout_output, | 30 | + surface_primary_scanout_output, take_presentation_feedback_surface_tree, |
| 30 | - OutputPresentationFeedback, | 31 | + update_surface_primary_scanout_output, OutputPresentationFeedback, |
| 31 | }; | 32 | }; |
| 32 | use smithay::desktop::{layer_map_for_output, PopupManager, Space, Window, WindowSurfaceType}; | 33 | use smithay::desktop::{layer_map_for_output, PopupManager, Space, Window, WindowSurfaceType}; |
| 33 | use smithay::input::keyboard::XkbConfig; | 34 | use smithay::input::keyboard::XkbConfig; |
| @@ -1072,6 +1073,86 @@ impl Niri { | |||
| 1072 | pointer_elements | 1073 | pointer_elements |
| 1073 | } | 1074 | } |
| 1074 | 1075 | ||
| 1076 | + pub fn refresh_pointer_outputs(&self) { | ||
| 1077 | + let _span = tracy_client::span!("Niri::refresh_pointer_outputs"); | ||
| 1078 | + | ||
| 1079 | + match &self.cursor_image { | ||
| 1080 | + CursorImageStatus::Hidden | CursorImageStatus::Named(_) => { | ||
| 1081 | + // There's no cursor surface, but there might be a DnD icon. | ||
| 1082 | + let Some(surface) = &self.dnd_icon else { | ||
| 1083 | + return; | ||
| 1084 | + }; | ||
| 1085 | + | ||
| 1086 | + let pointer_pos = self.seat.get_pointer().unwrap().current_location(); | ||
| 1087 | + | ||
| 1088 | + for output in self.global_space.outputs() { | ||
| 1089 | + let geo = self.global_space.output_geometry(output).unwrap(); | ||
| 1090 | + | ||
| 1091 | + // The default cursor is rendered at the right scale for each output, which | ||
| 1092 | + // means that it may have a different hotspot for each output. | ||
| 1093 | + let output_scale = output.current_scale().integer_scale(); | ||
| 1094 | + let Some(hotspot) = self.default_cursor.get_cached_hotspot(output_scale) else { | ||
| 1095 | + // Oh well; it'll get cached next time we render. | ||
| 1096 | + continue; | ||
| 1097 | + }; | ||
| 1098 | + let hotspot = hotspot.to_logical(output_scale); | ||
| 1099 | + | ||
| 1100 | + let surface_pos = pointer_pos.to_i32_round() - hotspot; | ||
| 1101 | + let bbox = bbox_from_surface_tree(surface, surface_pos); | ||
| 1102 | + | ||
| 1103 | + if let Some(mut overlap) = geo.intersection(bbox) { | ||
| 1104 | + overlap.loc -= surface_pos; | ||
| 1105 | + output_update(output, Some(overlap), surface); | ||
| 1106 | + } else { | ||
| 1107 | + output_update(output, None, surface); | ||
| 1108 | + } | ||
| 1109 | + } | ||
| 1110 | + } | ||
| 1111 | + CursorImageStatus::Surface(surface) => { | ||
| 1112 | + let hotspot = with_states(surface, |states| { | ||
| 1113 | + states | ||
| 1114 | + .data_map | ||
| 1115 | + .get::<Mutex<CursorImageAttributes>>() | ||
| 1116 | + .unwrap() | ||
| 1117 | + .lock() | ||
| 1118 | + .unwrap() | ||
| 1119 | + .hotspot | ||
| 1120 | + }); | ||
| 1121 | + | ||
| 1122 | + let pointer_pos = self.seat.get_pointer().unwrap().current_location(); | ||
| 1123 | + let surface_pos = pointer_pos.to_i32_round() - hotspot; | ||
| 1124 | + let bbox = bbox_from_surface_tree(surface, surface_pos); | ||
| 1125 | + | ||
| 1126 | + let dnd = self | ||
| 1127 | + .dnd_icon | ||
| 1128 | + .as_ref() | ||
| 1129 | + .map(|surface| (surface, bbox_from_surface_tree(surface, surface_pos))); | ||
| 1130 | + | ||
| 1131 | + for output in self.global_space.outputs() { | ||
| 1132 | + let geo = self.global_space.output_geometry(output).unwrap(); | ||
| 1133 | + | ||
| 1134 | + // Compute pointer surface overlap. | ||
| 1135 | + if let Some(mut overlap) = geo.intersection(bbox) { | ||
| 1136 | + overlap.loc -= surface_pos; | ||
| 1137 | + output_update(output, Some(overlap), surface); | ||
| 1138 | + } else { | ||
| 1139 | + output_update(output, None, surface); | ||
| 1140 | + } | ||
| 1141 | + | ||
| 1142 | + // Compute DnD icon surface overlap. | ||
| 1143 | + if let Some((surface, bbox)) = dnd { | ||
| 1144 | + if let Some(mut overlap) = geo.intersection(bbox) { | ||
| 1145 | + overlap.loc -= surface_pos; | ||
| 1146 | + output_update(output, Some(overlap), surface); | ||
| 1147 | + } else { | ||
| 1148 | + output_update(output, None, surface); | ||
| 1149 | + } | ||
| 1150 | + } | ||
| 1151 | + } | ||
| 1152 | + } | ||
| 1153 | + } | ||
| 1154 | + } | ||
| 1155 | + | ||
| 1075 | fn render( | 1156 | fn render( |
| 1076 | &mut self, | 1157 | &mut self, |
| 1077 | renderer: &mut GlesRenderer, | 1158 | renderer: &mut GlesRenderer, |
| @@ -1571,6 +1652,7 @@ render_elements! { | |||
| 1571 | Monitor = MonitorRenderElement<R>, | 1652 | Monitor = MonitorRenderElement<R>, |
| 1572 | Wayland = WaylandSurfaceRenderElement<R>, | 1653 | Wayland = WaylandSurfaceRenderElement<R>, |
| 1573 | DefaultPointer = TextureRenderElement<<R as Renderer>::TextureId>, | 1654 | DefaultPointer = TextureRenderElement<<R as Renderer>::TextureId>, |
| 1655 | + X = SolidColorRenderElement, | ||
| 1574 | } | 1656 | } |
| 1575 | 1657 | ||
| 1576 | #[derive(Default)] | 1658 | #[derive(Default)] |