From a559e59ad45df5b32e40a71361b99424ca1aa375 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 28 Oct 2024 18:24:21 -0700 Subject: [PATCH] Move `WlPointer` dispatch code --- src/fade_black.rs | 27 ++++++++++++++++++++++++++- src/main.rs | 36 +++++++++--------------------------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/fade_black.rs b/src/fade_black.rs index 6c23355..4c1e00f 100644 --- a/src/fade_black.rs +++ b/src/fade_black.rs @@ -2,7 +2,7 @@ use keyframe::{ease, functions::EaseInOut}; use std::time::{Duration, Instant}; use wayland_client::{ delegate_noop, - protocol::{wl_buffer, wl_callback, wl_output, wl_surface}, + protocol::{wl_buffer, wl_callback, wl_pointer, wl_output, wl_surface}, Connection, Dispatch, QueueHandle, }; use wayland_protocols::wp::{ @@ -148,6 +148,31 @@ impl Dispatch for State { } } +impl Dispatch for State { + fn event( + _: &mut Self, + pointer: &wl_pointer::WlPointer, + event: wl_pointer::Event, + _: &(), + _: &Connection, + _: &QueueHandle, + ) { + match event { + wl_pointer::Event::Enter { + serial, + surface: _, + surface_x: _, + surface_y: _, + } => { + // The only surface in our client is `FadeBlackSurface`. + // So hide the cursor if entered. + pointer.set_cursor(serial, None, 0, 0); + } + _ => {} + } + } +} + delegate_noop!(State: ignore wl_buffer::WlBuffer); delegate_noop!(State: ignore wl_surface::WlSurface); delegate_noop!(State: wp_single_pixel_buffer_manager_v1::WpSinglePixelBufferManagerV1); diff --git a/src/main.rs b/src/main.rs index 5823aec..c51e285 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,12 +5,14 @@ use calloop_wayland_source::WaylandSource; use cosmic_config::{calloop::ConfigWatchSource, CosmicConfigEntry}; use cosmic_idle_config::CosmicIdleConfig; use futures_lite::stream::StreamExt; -use std::process::Command; +use std::{ + process::Command, +}; use upower_dbus::UPowerProxy; use wayland_client::{ delegate_noop, globals::{registry_queue_init, GlobalListContents}, - protocol::{wl_compositor, wl_output, wl_pointer, wl_registry, wl_seat}, + protocol::{wl_compositor, wl_output, wl_registry, wl_seat}, Connection, Dispatch, Proxy, QueueHandle, }; use wayland_protocols::{ @@ -276,7 +278,10 @@ fn main() { scheduler .schedule(async move { if let Ok(connection) = zbus::Connection::session().await { - if let Err(err) = freedesktop_screensaver::serve(&connection, sender).await { + if let Err(err) = + freedesktop_screensaver::serve(&connection, sender) + .await + { log::error!("failed to serve FreeDesktop screensaver interface: {}", err); } } @@ -368,34 +373,11 @@ impl Dispatch for State { } } -impl Dispatch for State { - fn event( - _: &mut Self, - pointer: &wl_pointer::WlPointer, - event: wl_pointer::Event, - _: &(), - _: &Connection, - _: &QueueHandle, - ) { - match event { - wl_pointer::Event::Enter { - serial, - surface: _, - surface_x: _, - surface_y: _, - } => { - pointer.set_cursor(serial, None, 0, 0); - } - _ => {} - } - } -} - delegate_noop!(State: ignore wl_output::WlOutput); delegate_noop!(State: zwlr_output_power_manager_v1::ZwlrOutputPowerManagerV1); delegate_noop!(State: ignore zwlr_output_power_v1::ZwlrOutputPowerV1); delegate_noop!(State: ext_idle_notifier_v1::ExtIdleNotifierV1); -delegate_noop!(State: ignore wl_seat::WlSeat); // XXX +delegate_noop!(State: ignore wl_seat::WlSeat); // TODO: Capabilties delegate_noop!(State: zwlr_layer_shell_v1::ZwlrLayerShellV1); delegate_noop!(State: wp_viewporter::WpViewporter); delegate_noop!(State: wp_viewport::WpViewport);