From 794eb6f56b6024a9ebed973db6bd4f4472ff2fbd Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Fri, 9 Feb 2024 14:49:49 +0100 Subject: [PATCH] Switch to upstream idle-notify --- Cargo.lock | 2 +- Cargo.toml | 2 +- catacomb_ipc/Cargo.toml | 2 +- src/catacomb.rs | 19 +- src/input.rs | 2 +- src/protocols/idle_notify/mod.rs | 319 ------------------------------- src/protocols/mod.rs | 1 - src/windows/surface.rs | 17 -- 8 files changed, 12 insertions(+), 352 deletions(-) delete mode 100644 src/protocols/idle_notify/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 15700fb..f3a5602 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1482,7 +1482,7 @@ checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "smithay" version = "0.3.0" -source = "git+https://github.com/chrisduerr/smithay?rev=48d7a8cff7c17758e5435ac94ce3f954a10cb39a#48d7a8cff7c17758e5435ac94ce3f954a10cb39a" +source = "git+https://github.com/chrisduerr/smithay?rev=805038526f4d300c1389fda7a860126b7fd94470#805038526f4d300c1389fda7a860126b7fd94470" dependencies = [ "appendlist", "bitflags 2.4.2", diff --git a/Cargo.toml b/Cargo.toml index c5f75ea..666b2ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ members = ["catacomb_ipc"] [dependencies.smithay] git = "https://github.com/chrisduerr/smithay" -rev = "48d7a8cff7c17758e5435ac94ce3f954a10cb39a" +rev = "805038526f4d300c1389fda7a860126b7fd94470" default-features = false features = [ "use_system_lib", diff --git a/catacomb_ipc/Cargo.toml b/catacomb_ipc/Cargo.toml index a3e476a..d844601 100644 --- a/catacomb_ipc/Cargo.toml +++ b/catacomb_ipc/Cargo.toml @@ -10,7 +10,7 @@ edition = "2021" [dependencies.smithay] git = "https://github.com/chrisduerr/smithay" -rev = "48d7a8cff7c17758e5435ac94ce3f954a10cb39a" +rev = "805038526f4d300c1389fda7a860126b7fd94470" default-features = false features = [ "use_system_lib", diff --git a/src/catacomb.rs b/src/catacomb.rs index 6c583dd..ae75795 100644 --- a/src/catacomb.rs +++ b/src/catacomb.rs @@ -35,6 +35,7 @@ use smithay::wayland::fractional_scale::{ self, FractionalScaleHandler, FractionalScaleManagerState, }; use smithay::wayland::idle_inhibit::{IdleInhibitHandler, IdleInhibitManagerState}; +use smithay::wayland::idle_notify::{IdleNotifierHandler, IdleNotifierState}; use smithay::wayland::input_method::{ InputMethodHandler, InputMethodManagerState, InputMethodSeat, PopupSurface as ImeSurface, }; @@ -72,12 +73,12 @@ use smithay::wayland::xdg_activation::{ }; use smithay::{ delegate_compositor, delegate_data_control, delegate_data_device, delegate_dmabuf, - delegate_fractional_scale, delegate_idle_inhibit, delegate_input_method_manager, - delegate_kde_decoration, delegate_keyboard_shortcuts_inhibit, delegate_layer_shell, - delegate_output, delegate_presentation, delegate_primary_selection, delegate_seat, - delegate_session_lock, delegate_shm, delegate_text_input_manager, delegate_viewporter, - delegate_virtual_keyboard_manager, delegate_xdg_activation, delegate_xdg_decoration, - delegate_xdg_shell, + delegate_fractional_scale, delegate_idle_inhibit, delegate_idle_notify, + delegate_input_method_manager, delegate_kde_decoration, delegate_keyboard_shortcuts_inhibit, + delegate_layer_shell, delegate_output, delegate_presentation, delegate_primary_selection, + delegate_seat, delegate_session_lock, delegate_shm, delegate_text_input_manager, + delegate_viewporter, delegate_virtual_keyboard_manager, delegate_xdg_activation, + delegate_xdg_decoration, delegate_xdg_shell, }; use tracing::{error, info}; use zbus::zvariant::OwnedFd; @@ -87,17 +88,13 @@ use crate::drawing::CatacombSurfaceData; use crate::input::TouchState; use crate::orientation::{Accelerometer, AccelerometerSource}; use crate::output::Output; -use crate::protocols::idle_notify::{IdleNotifierHandler, IdleNotifierState}; use crate::protocols::screencopy::frame::Screencopy; use crate::protocols::screencopy::{ScreencopyHandler, ScreencopyManagerState}; use crate::protocols::single_pixel_buffer::SinglePixelBufferState; use crate::udev::Udev; use crate::windows::surface::Surface; use crate::windows::Windows; -use crate::{ - dbus, delegate_idle_notify, delegate_screencopy, delegate_single_pixel_buffer, ipc_server, - trace_error, -}; +use crate::{dbus, delegate_screencopy, delegate_single_pixel_buffer, ipc_server, trace_error}; /// Time before xdg_activation tokens are invalidated. const ACTIVATION_TIMEOUT: Duration = Duration::from_secs(10); diff --git a/src/input.rs b/src/input.rs index d8be88d..60c54bc 100644 --- a/src/input.rs +++ b/src/input.rs @@ -337,7 +337,7 @@ impl Catacomb { } // Reset idle sleep timer. - self.idle_notifier_state.notify_activity(); + self.idle_notifier_state.notify_activity(&self.seat); match event { InputEvent::Keyboard { event, .. } => { diff --git a/src/protocols/idle_notify/mod.rs b/src/protocols/idle_notify/mod.rs deleted file mode 100644 index d0ba389..0000000 --- a/src/protocols/idle_notify/mod.rs +++ /dev/null @@ -1,319 +0,0 @@ -//! This interface allows clients to monitor user idle status. -//! -//! ``` -//! # extern crate wayland_server; -//! # #[macro_use] extern crate smithay; -//! use smithay::delegate_idle_notify; -//! use smithay::wayland::idle_notify::{IdleNotifierState, IdleNotifierHandler}; -//! # use smithay::input::{Seat, SeatHandler, SeatState, pointer::CursorImageStatus}; -//! # use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; -//! -//! struct State { idle_notifier: IdleNotifierState } -//! # let mut event_loop = smithay::reexports::calloop::EventLoop::::try_new().unwrap(); -//! # let mut display = wayland_server::Display::::new().unwrap(); -//! // Create the primary_selection state -//! let idle_notifier = IdleNotifierState::::new( -//! &display.handle(), -//! event_loop.handle(), -//! ); -//! -//! let state = State { idle_notifier }; -//! -//! // implement the necessary traits -//! # impl SeatHandler for State { -//! # type KeyboardFocus = WlSurface; -//! # type PointerFocus = WlSurface; -//! # fn seat_state(&mut self) -> &mut SeatState { unimplemented!() } -//! # fn focus_changed(&mut self, seat: &Seat, focused: Option<&WlSurface>) { unimplemented!() } -//! # fn cursor_image(&mut self, seat: &Seat, image: CursorImageStatus) { unimplemented!() } -//! # } -//! impl IdleNotifierHandler for State { -//! fn idle_notifier_state(&mut self) -> &mut IdleNotifierState { -//! &mut self.idle_notifier -//! } -//! } -//! delegate_idle_notify!(State); -//! -//! // On input you should notify the idle_notifier -//! // state.idle_notifier.notify_activity(&wl_seat); -//! ``` - -use std::collections::HashMap; -use std::sync::atomic::{self, AtomicBool}; -use std::sync::Mutex; -use std::time::Duration; - -use calloop::timer::TimeoutAction; -use calloop::{LoopHandle, RegistrationToken}; -use smithay::reexports::wayland_server::backend::{ClientId, GlobalId, ObjectId}; -use smithay::reexports::wayland_server::{ - Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, -}; -use smithay::reexports::wayland_protocols::ext::idle_notify::v1::server::ext_idle_notification_v1::{ - self, ExtIdleNotificationV1, -}; -use smithay::reexports::wayland_protocols::ext::idle_notify::v1::server::ext_idle_notifier_v1::{ - self, ExtIdleNotifierV1, -}; - -/// Handler trait for ext idle notify module -pub trait IdleNotifierHandler: Sized { - /// [IdleNotifierSeatState] getter - fn idle_notifier_state(&mut self) -> &mut IdleNotifierState; -} - -/// User data of [ExtIdleNotificationV1] resource -#[derive(Debug)] -pub struct IdleNotificationUserData { - is_idle: AtomicBool, - timeout: Duration, - timer_token: Mutex>, -} - -impl IdleNotificationUserData { - fn take_timer_token(&self) -> Option { - self.timer_token.lock().unwrap().take() - } - - fn set_timer_token(&self, idle: Option) { - *self.timer_token.lock().unwrap() = idle; - } - - fn set_idle(&self, idle: bool) { - self.is_idle.store(idle, atomic::Ordering::Release); - } - - fn is_idle(&self) -> bool { - self.is_idle.load(atomic::Ordering::Acquire) - } -} - -/// State of ext-idle-notify module -#[derive(Debug)] -pub struct IdleNotifierState { - global: GlobalId, - notifications: HashMap, - loop_handle: LoopHandle<'static, D>, - is_inhibited: bool, -} - -#[allow(unused)] -impl IdleNotifierState { - /// Create new [`ExtIdleNotifierV1`] global. - pub fn new(display: &DisplayHandle, loop_handle: LoopHandle<'static, D>) -> Self - where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: IdleNotifierHandler, - D: 'static, - { - let global = display.create_global::(1, ()); - Self { global, notifications: HashMap::new(), loop_handle, is_inhibited: false } - } - - /// Inhibit entering idle state, eg. by wp idle inhibit protocol - pub fn set_is_inhibited(&mut self, is_inhibited: bool) { - if self.is_inhibited == is_inhibited { - return; - } - - self.is_inhibited = is_inhibited; - - for notification in self.notifications() { - if is_inhibited { - let data = notification.data::().unwrap(); - - if data.is_idle() { - notification.resumed(); - } - - if let Some(token) = data.take_timer_token() { - self.loop_handle.remove(token); - } - } else { - self.reinsert_timer(notification); - } - } - } - - /// Is idle state inhibited, eg. by wp idle inhibit protocol - pub fn is_inhibited(&mut self) -> bool { - self.is_inhibited - } - - /// Should be called whenever activity occurs on a seat, eg. mouse/keyboard - /// input - pub fn notify_activity(&mut self) { - for notification in self.notifications.values() { - let data = notification.data::().unwrap(); - - if data.is_idle() { - notification.resumed(); - data.set_idle(false); - } - - self.reinsert_timer(notification); - } - } - - /// Returns the [`ExtIdleNotifierV1`] global. - pub fn global(&self) -> GlobalId { - self.global.clone() - } - - fn notifications(&self) -> impl Iterator { - self.notifications.values() - } - - fn reinsert_timer(&self, notification: &ExtIdleNotificationV1) { - let data = notification.data::().unwrap(); - - if let Some(token) = data.take_timer_token() { - self.loop_handle.remove(token); - } - - if self.is_inhibited { - return; - } - - let token = - self.loop_handle.insert_source(calloop::timer::Timer::from_duration(data.timeout), { - let idle_notification = notification.clone(); - move |_, _, state| { - let data = idle_notification.data::().unwrap(); - - if !state.idle_notifier_state().is_inhibited && !data.is_idle() { - idle_notification.idled(); - data.set_idle(true); - } - - data.set_timer_token(None); - TimeoutAction::Drop - } - }); - - data.set_timer_token(token.ok()); - } -} - -impl GlobalDispatch for IdleNotifierState -where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: IdleNotifierHandler, - D: 'static, -{ - fn bind( - _state: &mut D, - _handle: &DisplayHandle, - _client: &Client, - resource: New, - _global_data: &(), - data_init: &mut DataInit<'_, D>, - ) { - data_init.init(resource, ()); - } -} - -impl Dispatch for IdleNotifierState -where - D: GlobalDispatch, - D: Dispatch, - D: Dispatch, - D: IdleNotifierHandler, - D: 'static, -{ - fn request( - state: &mut D, - _client: &Client, - _resource: &ExtIdleNotifierV1, - request: ext_idle_notifier_v1::Request, - _data: &(), - _dhandle: &DisplayHandle, - data_init: &mut DataInit<'_, D>, - ) { - match request { - ext_idle_notifier_v1::Request::GetIdleNotification { id, timeout, .. } => { - let timeout = Duration::from_millis(timeout as u64); - - let idle_notifier_state = state.idle_notifier_state(); - - let idle_notification = data_init.init(id, IdleNotificationUserData { - is_idle: AtomicBool::new(false), - timeout, - timer_token: Mutex::new(None), - }); - - idle_notifier_state.reinsert_timer(&idle_notification); - - state - .idle_notifier_state() - .notifications - .insert(idle_notification.id(), idle_notification); - }, - ext_idle_notifier_v1::Request::Destroy => {}, - _ => unimplemented!(), - } - } -} - -impl Dispatch for IdleNotifierState -where - D: Dispatch, - D: IdleNotifierHandler, -{ - fn request( - _state: &mut D, - _client: &Client, - _resource: &ExtIdleNotificationV1, - request: ext_idle_notification_v1::Request, - _data: &IdleNotificationUserData, - _dhandle: &DisplayHandle, - _data_init: &mut DataInit<'_, D>, - ) { - match request { - ext_idle_notification_v1::Request::Destroy => {}, - _ => unimplemented!(), - } - } - - fn destroyed( - state: &mut D, - _client: ClientId, - idle_notification: &ExtIdleNotificationV1, - _data: &IdleNotificationUserData, - ) { - state.idle_notifier_state().notifications.remove(&idle_notification.id()); - } -} - -/// Macro to delegate implementation of the ext idle notify protocol -#[macro_export] -macro_rules! delegate_idle_notify { - ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { - type __ExtIdleNotifierV1 = - smithay::reexports::wayland_protocols::ext::idle_notify::v1::server::ext_idle_notifier_v1::ExtIdleNotifierV1; - type __ExtIdleNotificationV1 = - smithay::reexports::wayland_protocols::ext::idle_notify::v1::server::ext_idle_notification_v1::ExtIdleNotificationV1; - - smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: - [ - __ExtIdleNotifierV1: () - ] => $crate::protocols::idle_notify::IdleNotifierState<$ty> - ); - - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: - [ - __ExtIdleNotifierV1: () - ] => $crate::protocols::idle_notify::IdleNotifierState<$ty> - ); - - smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: - [ - __ExtIdleNotificationV1: $crate::protocols::idle_notify::IdleNotificationUserData - ] => $crate::protocols::idle_notify::IdleNotifierState<$ty> - ); - }; -} diff --git a/src/protocols/mod.rs b/src/protocols/mod.rs index 3282333..6207516 100644 --- a/src/protocols/mod.rs +++ b/src/protocols/mod.rs @@ -1,3 +1,2 @@ -pub mod idle_notify; pub mod screencopy; pub mod single_pixel_buffer; diff --git a/src/windows/surface.rs b/src/windows/surface.rs index 1259748..e308b47 100644 --- a/src/windows/surface.rs +++ b/src/windows/surface.rs @@ -30,9 +30,6 @@ pub trait Surface { /// Check if the window has been closed. fn alive(&self) -> bool; - /// Request application shutdown. - fn send_close(&self); - /// Send the initial configure. fn initial_configure(&self); @@ -67,10 +64,6 @@ impl Surface for ToplevelSurface { self.alive() } - fn send_close(&self) { - self.send_close(); - } - fn initial_configure(&self) { if !self.initial_configure_sent() { self.send_configure(); @@ -123,8 +116,6 @@ impl Surface for PopupSurface { self.alive() } - fn send_close(&self) {} - fn initial_configure(&self) { if self.initial_configure_sent() { return; @@ -185,10 +176,6 @@ impl Surface for CatacombLayerSurface { self.surface.alive() } - fn send_close(&self) { - self.surface.send_close(); - } - fn initial_configure(&self) { if self.initial_configure_sent() { return; @@ -255,10 +242,6 @@ impl Surface for LockSurface { self.alive() } - fn send_close(&self) { - unreachable!("attempted to kill lock surface"); - } - fn initial_configure(&self) { // Initial configure is sent immediately after // ext_session_lock_surface_v1 is bound.