forge
Explore
Log in

Don't you dare go Hollow

handlers: implement cursor session for toplevel image copy

Browse files at this commit

3388de749a8cbcde27352cfee9872004cab1409aHigherOrderLogicParent: a44ce66
src/handlers/image_copy_capture.rsmodified+1 -1
@@ -359,7 +359,7 @@ impl ImageCopyCaptureHandler for State {
359 source: &ImageCaptureSource,359 source: &ImageCaptureSource,
360 _pointer: &WlPointer,360 _pointer: &WlPointer,
361 ) -> Option<BufferConstraints> {361 ) -> Option<BufferConstraints> {
362- let output = source_output(source)?;362+ let output = source_session_output(&self.niri, source)?;
363 if !self.niri.output_state.contains_key(&output) {363 if !self.niri.output_state.contains_key(&output) {
364 return None;364 return None;
365 }365 }
src/niri.rsmodified+70 -44
@@ -6151,25 +6151,22 @@ impl Niri {
6151 for s in &mut sessions {6151 for s in &mut sessions {
6152 let source = s.session.source();6152 let source = s.session.source();
6153 6153
6154- let (_, output) = if let Some(id) = image_copy_capture_impl::source_mapped_id(&source) {6154+ let (mapped, output) =
6155- let Some((mapped, Some(output))) = self.find_mapped_output_by_id(id) else {6155+ if let Some(id) = image_copy_capture_impl::source_mapped_id(&source) {
6156- s.session.set_cursor_pos(None);6156+ let Some((mapped, Some(output))) = self.find_mapped_output_by_id(id) else {
6157- continue;6157+ s.session.set_cursor_pos(None);
6158- };6158+ continue;
6159- (Some(mapped), output.clone())6159+ };
6160- } else {6160+ (Some(mapped), output.clone())
6161- let Some(output) = image_copy_capture_impl::source_output(&source) else {6161+ } else {
6162- s.session.set_cursor_pos(None);6162+ let Some(output) = image_copy_capture_impl::source_output(&source) else {
6163- continue;6163+ s.session.set_cursor_pos(None);
6164+ continue;
6165+ };
6166+ (None, output)
6164 };6167 };
6165- (None, output)
6166- };
6167 6168
6168- let Some(geo) = self.global_space.output_geometry(&output) else {6169+ let Some(output_geo) = self.global_space.output_geometry(&output) else {
6169- s.session.set_cursor_pos(None);
6170- continue;
6171- };
6172- let Some(mode) = output.current_mode() else {
6173 s.session.set_cursor_pos(None);6170 s.session.set_cursor_pos(None);
6174 continue;6171 continue;
6175 };6172 };
@@ -6196,34 +6193,63 @@ impl Niri {
6196 let hotspot = image_copy_capture_impl::cursor_capture_hotspot(self, &output);6193 let hotspot = image_copy_capture_impl::cursor_capture_hotspot(self, &output);
6197 s.session.set_cursor_hotspot((hotspot.x, hotspot.y));6194 s.session.set_cursor_hotspot((hotspot.x, hotspot.y));
6198 6195
6199- // Unlike frame damage, the position is in transformed buffer coordinates, i.e. the6196+ let pos = if !self.pointer_visibility.is_visible() {
6200- // displayed orientation, so the output transform is not undone here. This matches6197+ None
6201- // wlroots.6198+ } else if let Some(mapped) = mapped {
6202- let pos: Point<i32, Physical> =6199+ // For window casts, we intentionally use the same logic as in PipeWire: the window
6203- (pointer_pos - geo.loc.to_f64()).to_physical_precise_round(scale);6200+ // must have pointer focus to show the pointer. The reasoning is to prevent
6204-6201+ // accidental leaking of pointer position when not interacting with the window.
6205- // Cursors are considered to have entered if any part of the image6202+ //
6206- // intersects the output, not just the hotspot, so the position may6203+ // While this may seem to contradict the protocol wording, I'd argue one of the
6207- // be negative or past the edge.6204+ // readings does allow it.
6208- //6205+ //
6209- // The imagecopy protocol specifies this interpretation6206+ // > The cursor enters the captured area when the cursor image
6210- // specifically, even though it differs from wl_pointer.enter,6207+ // > intersects with the captured area.
6211- // including the coordinates being outside the output bounds. This6208+ //
6212- // is also how wlroots implements it.6209+ // For windows, the captured area is the window itself, not a cut-out of the output.
6213- //6210+ // Therefore, we consider the pointer to not intersect the "captured area" when the
6214- // This intentionally differs from how PipeWire casts work since PW6211+ // window doesn't have pointer focus. (Otherwise the pointer would need to be
6215- // requires the pointer to be within the output bounds, but this6212+ // displayed even when it's over a different window completely covering the casted
6216- // isn't relevant (or wanted) for the imagecopy protocol.6213+ // one.)
6217- let hotspot = Point::<i32, Physical>::from((hotspot.x, hotspot.y));6214+ self.pointer_pos_for_window_cast(mapped)
6218- let image = Rectangle::new(pos - hotspot, Size::from((cursor_size.w, cursor_size.h)));6215+ .map(|(pointer_pos, win_pos)| {
6219- let output_rect =6216+ let bbox = mapped.capture_bbox(scale);
6220- Rectangle::from_size(output.current_transform().transform_size(mode.size));6217+ let buf_pos = win_pos + bbox.loc.to_f64().to_logical(scale);
6221- if self.pointer_visibility.is_visible() && image.overlaps(output_rect) {6218+ let ipos = (pointer_pos - output_geo.loc.to_f64() - buf_pos)
6222- // not geo.to_f64().contains(pointer_pos)6219+ .to_physical_precise_round(scale);
6223- s.session.set_cursor_pos(Some(Point::from((pos.x, pos.y))));6220+ Point::from((ipos.x, ipos.y))
6221+ })
6222+ } else if let Some(mode) = output.current_mode() {
6223+ // Unlike frame damage, the position is in transformed buffer coordinates, i.e. the
6224+ // displayed orientation, so the output transform is not undone here. This matches
6225+ // wlroots.
6226+ let pos: Point<i32, Physical> =
6227+ (pointer_pos - output_geo.loc.to_f64()).to_physical_precise_round(scale);
6228+
6229+ // Cursors are considered to have entered if any part of the image
6230+ // intersects the output, not just the hotspot, so the position may
6231+ // be negative or past the edge.
6232+ //
6233+ // The imagecopy protocol specifies this interpretation
6234+ // specifically, even though it differs from wl_pointer.enter,
6235+ // including the coordinates being outside the output bounds. This
6236+ // is also how wlroots implements it.
6237+ //
6238+ // This intentionally differs from how PipeWire casts work since PW
6239+ // requires the pointer to be within the output bounds, but this
6240+ // isn't relevant (or wanted) for the imagecopy protocol.
6241+ let hotspot = Point::<i32, Physical>::from((hotspot.x, hotspot.y));
6242+ let image =
6243+ Rectangle::new(pos - hotspot, Size::from((cursor_size.w, cursor_size.h)));
6244+ let output_rect =
6245+ Rectangle::from_size(output.current_transform().transform_size(mode.size));
6246+ image
6247+ .overlaps(output_rect)
6248+ .then_some(Point::from((pos.x, pos.y)))
6224 } else {6249 } else {
6225- s.session.set_cursor_pos(None);6250+ None
6226- }6251+ };
6252+ s.session.set_cursor_pos(pos);
6227 }6253 }
6228 // This shouldn't be possible since sessions are only added from the6254 // This shouldn't be possible since sessions are only added from the
6229 // ImageCopyCaptureHandler callbacks, which run in dispatch_clients()6255 // ImageCopyCaptureHandler callbacks, which run in dispatch_clients()