From 1f13ba2b940539973f301164e06a0e11920923d7 Mon Sep 17 00:00:00 2001 From: Timo Zuccarello Date: Fri, 19 Apr 2024 21:22:41 +0200 Subject: [PATCH 1/3] Don't close the window on mouse over and allow clicking through window. This patch sets an empty input region allowing clicking through the window. It also removes the pointer event handler and no longer removes the window on mouse over. --- src/main.rs | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5feff70..fa9fcc7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,8 +2,7 @@ use std::{fs::File, io::Write, os::unix::prelude::AsRawFd}; use wayland_client::{ protocol::{ - wl_buffer, wl_compositor, wl_keyboard, wl_pointer, wl_registry, wl_seat, wl_shm, - wl_shm_pool, wl_surface, + wl_buffer, wl_compositor, wl_keyboard, wl_region::WlRegion, wl_registry, wl_seat, wl_shm, wl_shm_pool, wl_surface }, Connection, Dispatch, Proxy, QueueHandle, }; @@ -26,7 +25,6 @@ struct State { layer_surface: Option, buffer: Option, wm_base: Option, - pointer: Option, } fn main() { @@ -47,7 +45,6 @@ fn main() { layer_surface: None, buffer: None, wm_base: None, - pointer: None, }; event_queue.blocking_dispatch(&mut state).unwrap(); @@ -109,9 +106,6 @@ impl Dispatch for State { (), ); state.buffer = Some(buffer); - } else if interface == wl_seat::WlSeat::interface().name { - let seat = registry.bind::(name, version, qh, ()); - state.pointer = Some(seat.get_pointer(qh, ())); } else if interface == xdg_wm_base::XdgWmBase::interface().name { let wm_base = registry.bind::(name, 1, qh, ()); state.wm_base = Some(wm_base); @@ -120,31 +114,15 @@ impl Dispatch for State { } } -impl Dispatch for State { +impl Dispatch for State { fn event( - state: &mut Self, - _: &wl_pointer::WlPointer, - event: wl_pointer::Event, + _: &mut Self, + _: &WlRegion, + _: ::Event, _: &(), _: &Connection, - qh: &QueueHandle, + _: &QueueHandle, ) { - 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); - } - _ => {} - } } } @@ -197,6 +175,11 @@ 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(®ion)); + } self.base_surface.as_ref().unwrap().commit(); self.layer_surface = Some(layer); From effbf9ebc881f3299c1c3ca3738a80adbcbdcc32 Mon Sep 17 00:00:00 2001 From: lelgenio Date: Fri, 26 Apr 2024 14:31:58 -0300 Subject: [PATCH 2/3] update flake.lock --- flake.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index 0cdbed2..50ef5da 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1681202837, - "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1684242266, - "narHash": "sha256-uaCQ2k1bmojHKjWQngvnnnxQJMY8zi1zq527HdWgQf8=", + "lastModified": 1714091391, + "narHash": "sha256-68n3GBvlm1MIeJXadPzQ3v8Y9sIW3zmv8gI5w5sliC8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "7e0743a5aea1dc755d4b761daf75b20aa486fdad", + "rev": "4c86138ce486d601d956a165e2f7a0fc029a03c1", "type": "github" }, "original": { From 081f6bed695f9cf9f3947b44cfe37abad850f89e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Eug=C3=AAnio?= Date: Fri, 26 Apr 2024 14:42:16 -0300 Subject: [PATCH 3/3] Update README.md Add more items to the todo-list, remove mention of focus limitation. --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3b057bd..eb01347 100644 --- a/README.md +++ b/README.md @@ -8,5 +8,9 @@ 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) -### 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. +## 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