Compare commits

..

No commits in common. "081f6bed695f9cf9f3947b44cfe37abad850f89e" and "57d0908e10d9f58fc37fe866404cc8b66be1f0d9" have entirely different histories.

3 changed files with 36 additions and 23 deletions

View file

@ -8,9 +8,5 @@ Currently has no support for command line arguments or any customization.
### Preview:
![image](https://github.com/lelgenio/wl-crosshair/assets/31388299/6e0aaa16-837b-40a8-9a13-ed808ea5db86)
## TODO
- [x] Make the crosshair Click-through https://github.com/lelgenio/wl-crosshair/pull/1
- [ ] Option to control size of crosshair
- [ ] Option to offset crosshair
- [ ] Configuratin file
- [ ] Support for loading custom crosshair images
### Why is it flickering when I put my cursor over it?
In wayland, windows cannot be "click-through", so in order to still send events we "close" the window when you hover it and show it in the next frame.

View file

@ -5,11 +5,11 @@
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"lastModified": 1681202837,
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
"type": "github"
},
"original": {
@ -20,11 +20,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1714091391,
"narHash": "sha256-68n3GBvlm1MIeJXadPzQ3v8Y9sIW3zmv8gI5w5sliC8=",
"lastModified": 1684242266,
"narHash": "sha256-uaCQ2k1bmojHKjWQngvnnnxQJMY8zi1zq527HdWgQf8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "4c86138ce486d601d956a165e2f7a0fc029a03c1",
"rev": "7e0743a5aea1dc755d4b761daf75b20aa486fdad",
"type": "github"
},
"original": {

View file

@ -2,7 +2,8 @@ use std::{fs::File, io::Write, os::unix::prelude::AsRawFd};
use wayland_client::{
protocol::{
wl_buffer, wl_compositor, wl_keyboard, wl_region::WlRegion, wl_registry, wl_seat, wl_shm, wl_shm_pool, wl_surface
wl_buffer, wl_compositor, wl_keyboard, wl_pointer, wl_registry, wl_seat, wl_shm,
wl_shm_pool, wl_surface,
},
Connection, Dispatch, Proxy, QueueHandle,
};
@ -25,6 +26,7 @@ struct State {
layer_surface: Option<zwlr_layer_surface_v1::ZwlrLayerSurfaceV1>,
buffer: Option<wl_buffer::WlBuffer>,
wm_base: Option<xdg_wm_base::XdgWmBase>,
pointer: Option<wl_pointer::WlPointer>,
}
fn main() {
@ -45,6 +47,7 @@ fn main() {
layer_surface: None,
buffer: None,
wm_base: None,
pointer: None,
};
event_queue.blocking_dispatch(&mut state).unwrap();
@ -106,6 +109,9 @@ impl Dispatch<wl_registry::WlRegistry, ()> for State {
(),
);
state.buffer = Some(buffer);
} else if interface == wl_seat::WlSeat::interface().name {
let seat = registry.bind::<wl_seat::WlSeat, _, _>(name, version, qh, ());
state.pointer = Some(seat.get_pointer(qh, ()));
} else if interface == xdg_wm_base::XdgWmBase::interface().name {
let wm_base = registry.bind::<xdg_wm_base::XdgWmBase, _, _>(name, 1, qh, ());
state.wm_base = Some(wm_base);
@ -114,15 +120,31 @@ impl Dispatch<wl_registry::WlRegistry, ()> for State {
}
}
impl Dispatch<WlRegion, ()> for State {
impl Dispatch<wl_pointer::WlPointer, ()> for State {
fn event(
_: &mut Self,
_: &WlRegion,
_: <WlRegion as Proxy>::Event,
state: &mut Self,
_: &wl_pointer::WlPointer,
event: wl_pointer::Event,
_: &(),
_: &Connection,
_: &QueueHandle<Self>,
qh: &QueueHandle<Self>,
) {
eprintln!("WlPointer event {event:#?}");
match event {
wl_pointer::Event::Enter { .. } => {
if let Some(surface) = &state.base_surface {
surface.destroy();
}
state.base_surface = None;
}
wl_pointer::Event::Leave { .. } => {
let surface = state.compositor.as_ref().unwrap().create_surface(qh, ());
state.base_surface = Some(surface);
state.init_layer_surface(qh);
}
_ => {}
}
}
}
@ -175,11 +197,6 @@ impl State {
// A negative value means we will be centered on the screen
// independently of any other xdg_layer_shell
layer.set_exclusive_zone(-1);
// Set empty input region to allow clicking through the window.
if let Some(compositor) = &self.compositor {
let region = compositor.create_region(qh, ());
self.base_surface.as_ref().unwrap().set_input_region(Some(&region));
}
self.base_surface.as_ref().unwrap().commit();
self.layer_surface = Some(layer);