Skip to content

Commit

Permalink
Offset default pointer by hotspot
Browse files Browse the repository at this point in the history
Fixes #252. Currently a temporary fix until I implement cursor shape
  • Loading branch information
Ottatop committed Jun 18, 2024
1 parent fc4dd9d commit 39fd958
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ features = [
"x11rb_event_source",
]

[workspace.lints.clippy]
too_many_arguments = "allow"

########################################################################yo😎###########

[package]
Expand Down Expand Up @@ -140,3 +143,6 @@ testing = [
"smithay/renderer_test",
]
wlcs = ["testing"]

[lints]
workspace = true
2 changes: 0 additions & 2 deletions src/api/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ impl window_service_server::WindowService for WindowService {
) -> Result<Response<()>, Status> {
let request = request.into_inner();

tracing::info!(request = ?request);

let window_id = WindowId(
request
.window_id
Expand Down
33 changes: 13 additions & 20 deletions src/backend/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use smithay::{
vulkan::{self, version::Version, PhysicalDevice},
SwapBuffersError,
},
desktop::utils::{send_frames_surface_tree, OutputPresentationFeedback},
desktop::utils::OutputPresentationFeedback,
input::pointer::CursorImageStatus,
output::{Output, PhysicalProperties, Subpixel},
reexports::{
Expand Down Expand Up @@ -1414,17 +1414,15 @@ impl Udev {
let _ = renderer.downscale_filter(self.downscale_filter);

let pointer_images = &mut self.pointer_images;
let pointer_image = pointer_images
let (pointer_image, hotspot) = pointer_images
.iter()
.find_map(
|(image, texture)| {
if image == &frame {
Some(texture.clone())
} else {
None
}
},
)
.find_map(|(image, texture)| {
if image == &frame {
Some((texture.clone(), (frame.xhot as i32, frame.yhot as i32)))
} else {
None
}
})
.unwrap_or_else(|| {
let texture = TextureBuffer::from_memory(
&mut renderer,
Expand All @@ -1437,8 +1435,9 @@ impl Udev {
None,
)
.expect("Failed to import cursor bitmap");
let hotspot = (frame.xhot as i32, frame.yhot as i32);
pointer_images.push((frame, texture.clone()));
texture
(texture, hotspot)
});

let pointer_location = pinnacle
Expand All @@ -1455,14 +1454,6 @@ impl Udev {
if let CursorImageStatus::Surface(surface) = &pinnacle.cursor_status {
if !surface.alive() {
pinnacle.cursor_status = CursorImageStatus::default_named();
} else {
send_frames_surface_tree(
surface,
output,
pinnacle.clock.now(),
Some(Duration::ZERO),
|_, _| None,
);
}
}

Expand Down Expand Up @@ -1499,6 +1490,7 @@ impl Udev {
pointer_location,
&mut pinnacle.cursor_status,
pinnacle.dnd_icon.as_ref(),
hotspot.into(),
&self.pointer_element,
);
self.pointer_element.set_element_kind(element::Kind::Cursor);
Expand All @@ -1513,6 +1505,7 @@ impl Udev {
pointer_location,
&mut pinnacle.cursor_status,
pinnacle.dnd_icon.as_ref(),
hotspot.into(),
&self.pointer_element,
);
output_render_elements.extend(pointer_render_elements);
Expand Down
1 change: 0 additions & 1 deletion src/backend/udev/gamma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ impl Udev {
}
None => PendingGammaChange::Restore,
};
tracing::info!("SET PENDING GAMMA WOO");
return Ok(());
}

Expand Down
1 change: 1 addition & 0 deletions src/backend/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ impl Winit {
pointer_location,
&mut pinnacle.cursor_status,
pinnacle.dnd_icon.as_ref(),
(0, 0).into(), // Nonsurface cursors are hidden
&pointer_element,
);
output_render_elements.extend(pointer_render_elements);
Expand Down
3 changes: 2 additions & 1 deletion src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ pub fn pointer_render_elements<R: PRenderer>(
pointer_location: Point<f64, Logical>,
cursor_status: &mut CursorImageStatus,
dnd_icon: Option<&WlSurface>,
fallback_hotspot: Point<i32, Logical>,
pointer_element: &PointerElement<<R as Renderer>::TextureId>,
) -> Vec<OutputRenderElement<R>> {
let mut output_render_elements = Vec::new();
Expand All @@ -296,7 +297,7 @@ pub fn pointer_render_elements<R: PRenderer>(
.hotspot
})
} else {
(0, 0).into()
fallback_hotspot
};

let cursor_pos = pointer_location - output_geometry.loc.to_f64() - cursor_hotspot.to_f64();
Expand Down

0 comments on commit 39fd958

Please sign in to comment.