1
0
Fork 0
forked from wry/wry

backend: add ButtonState

This commit is contained in:
Julian Orth 2025-10-16 19:50:21 +02:00
parent e22e6680b6
commit 0e1be7544f
17 changed files with 75 additions and 66 deletions

View file

@ -317,6 +317,12 @@ pub enum KeyState {
Pressed,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum ButtonState {
Released,
Pressed,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Linearize)]
pub enum ScrollAxis {
Horizontal = HORIZONTAL_SCROLL as _,
@ -369,7 +375,7 @@ pub enum InputEvent {
Button {
time_usec: u64,
button: u32,
state: KeyState,
state: ButtonState,
},
AxisPx {

View file

@ -8,7 +8,7 @@ use {
crate::{
async_engine::SpawnedFuture,
backend::{
Backend, InputDevice, InputDeviceAccelProfile, InputDeviceCapability,
Backend, ButtonState, InputDevice, InputDeviceAccelProfile, InputDeviceCapability,
InputDeviceClickMethod, InputDeviceGroupId, InputDeviceId, InputEvent, KeyState, Leds,
TransformMatrix, transaction::BackendConnectorTransactionError,
},
@ -598,7 +598,7 @@ impl MetalInputDevice {
self.event(InputEvent::Button {
time_usec,
button,
state: KeyState::Released,
state: ButtonState::Released,
});
}
}

View file

@ -1,6 +1,6 @@
use {
crate::{
backend::{AxisSource, InputEvent, KeyState, ScrollAxis},
backend::{AxisSource, ButtonState, InputEvent, KeyState, ScrollAxis},
backends::metal::MetalBackend,
fixed::Fixed,
ifs::wl_seat::tablet::{
@ -216,12 +216,12 @@ impl MetalBackend {
if dev.pressed_buttons.insert(event.button(), ()).is_some() {
return;
}
KeyState::Pressed
ButtonState::Pressed
} else {
if dev.pressed_buttons.remove(&event.button()).is_none() {
return;
}
KeyState::Released
ButtonState::Released
};
dev.event(InputEvent::Button {
time_usec: event.time_usec(),

View file

@ -4,9 +4,10 @@ use {
async_engine::{Phase, SpawnedFuture},
backend::{
AXIS_120, AxisSource, Backend, BackendConnectorState, BackendDrmDevice, BackendEvent,
Connector, ConnectorEvent, ConnectorId, ConnectorKernelId, DrmDeviceId, DrmEvent,
InputDevice, InputDeviceAccelProfile, InputDeviceCapability, InputDeviceClickMethod,
InputDeviceId, InputEvent, KeyState, Mode, MonitorInfo, ScrollAxis, TransformMatrix,
ButtonState, Connector, ConnectorEvent, ConnectorId, ConnectorKernelId, DrmDeviceId,
DrmEvent, InputDevice, InputDeviceAccelProfile, InputDeviceCapability,
InputDeviceClickMethod, InputDeviceId, InputEvent, KeyState, Mode, MonitorInfo,
ScrollAxis, TransformMatrix,
transaction::{
BackendAppliedConnectorTransaction, BackendConnectorTransaction,
BackendConnectorTransactionError, BackendConnectorTransactionType,
@ -817,8 +818,8 @@ impl XBackend {
match event.code() {
XiMotion::OPCODE => self.handle_input_motion(event),
XiEnter::OPCODE => self.handle_input_enter(event),
XiButtonPress::OPCODE => self.handle_input_button_press(event, KeyState::Pressed),
XiButtonRelease::OPCODE => self.handle_input_button_press(event, KeyState::Released),
XiButtonPress::OPCODE => self.handle_input_button_press(event, ButtonState::Pressed),
XiButtonRelease::OPCODE => self.handle_input_button_press(event, ButtonState::Released),
XiKeyPress::OPCODE => self.handle_input_key_press(event, KeyState::Pressed),
XiKeyRelease::OPCODE => self.handle_input_key_press(event, KeyState::Released),
XiHierarchy::OPCODE => self.handle_input_hierarchy(event).await,
@ -829,14 +830,14 @@ impl XBackend {
fn handle_input_button_press(
self: &Rc<Self>,
event: &Event,
state: KeyState,
state: ButtonState,
) -> Result<(), XBackendError> {
let event: XiButtonPress = event.parse()?;
if let Some(seat) = self.mouse_seats.get(&event.deviceid) {
let button = event.detail;
// let button = seat.button_map.get(&event.detail).unwrap_or(event.detail);
if matches!(button, 4..=7) {
if state == KeyState::Pressed {
if state == ButtonState::Pressed {
let (axis, val) = match button {
4 => (ScrollAxis::Vertical, -1),
5 => (ScrollAxis::Vertical, 1),

View file

@ -1,6 +1,6 @@
use {
crate::{
backend::KeyState,
backend::ButtonState,
ei::{
ei_client::{EiClient, EiClientError},
ei_ifs::ei_device::{EiDevice, EiDeviceInterface},
@ -27,7 +27,7 @@ pub struct EiButton {
ei_device_interface!(EiButton, ei_button, button);
impl EiButton {
pub fn send_button(&self, button: u32, state: KeyState) {
pub fn send_button(&self, button: u32, state: ButtonState) {
self.client.event(ServerButton {
self_id: self.id,
button,
@ -46,8 +46,8 @@ impl EiButtonRequestHandler for EiButton {
fn client_button(&self, req: ClientButton, _slf: &Rc<Self>) -> Result<(), Self::Error> {
let pressed = match req.state {
0 => KeyState::Released,
1 => KeyState::Pressed,
0 => ButtonState::Released,
1 => ButtonState::Pressed,
_ => return Err(EiButtonError::InvalidButtonState(req.state)),
};
self.device.button_changes.push((req.button, pressed));

View file

@ -1,6 +1,6 @@
use {
crate::{
backend::{KeyState, ScrollAxis},
backend::{ButtonState, KeyState, ScrollAxis},
ei::{
ei_client::{EiClient, EiClientError},
ei_ifs::{ei_seat::EiSeat, ei_touchscreen::TouchChange},
@ -40,7 +40,7 @@ pub struct EiDevice {
pub version: EiVersion,
pub seat: Rc<EiSeat>,
pub button_changes: SyncQueue<(u32, KeyState)>,
pub button_changes: SyncQueue<(u32, ButtonState)>,
pub touch_changes: CopyHashMap<u32, TouchChange>,
pub scroll_px: [Cell<Option<f32>>; 2],
pub scroll_v120: [Cell<Option<i32>>; 2],

View file

@ -1,6 +1,6 @@
use {
crate::{
backend::KeyState,
backend::{ButtonState, KeyState},
ei::{
EiContext,
ei_client::{EiClient, EiClientError},
@ -150,7 +150,7 @@ impl EiSeat {
}
}
pub fn handle_button(&self, time_usec: u64, button: u32, state: KeyState) {
pub fn handle_button(&self, time_usec: u64, button: u32, state: ButtonState) {
if self.is_sender() {
return;
}

View file

@ -1,6 +1,6 @@
use {
crate::{
backend::{InputDeviceId, KeyState, ScrollAxis},
backend::{ButtonState, InputDeviceId, KeyState, ScrollAxis},
client::Client,
fixed::Fixed,
ifs::wl_seat::{
@ -79,7 +79,7 @@ impl JaySeatEvents {
});
}
pub fn send_button(&self, seat: SeatId, time_usec: u64, button: u32, state: KeyState) {
pub fn send_button(&self, seat: SeatId, time_usec: u64, button: u32, state: ButtonState) {
self.client.event(Button {
self_id: self.id,
seat: seat.raw(),

View file

@ -24,7 +24,7 @@ pub mod zwp_virtual_keyboard_v1;
use {
crate::{
async_engine::SpawnedFuture,
backend::{KeyState, Leds},
backend::{ButtonState, Leds},
client::{Client, ClientError, ClientId},
cursor_user::{CursorUser, CursorUserGroup, CursorUserOwner},
ei::ei_ifs::ei_seat::EiSeat,
@ -1387,10 +1387,10 @@ impl WlSeatGlobal {
node: Rc<dyn Node>,
time_usec: u64,
button: u32,
state: KeyState,
state: ButtonState,
serial: u64,
) {
if self.tray_popups.is_not_empty() && state == KeyState::Pressed {
if self.tray_popups.is_not_empty() && state == ButtonState::Pressed {
let id = node.node_tray_item();
self.tray_popups.lock().retain(|&(tray_item_id, _), item| {
let retain = Some(tray_item_id) == id;

View file

@ -1,7 +1,8 @@
use {
crate::{
backend::{
AXIS_120, AxisSource, ConnectorId, InputDeviceId, InputEvent, KeyState, ScrollAxis,
AXIS_120, AxisSource, ButtonState, ConnectorId, InputDeviceId, InputEvent, KeyState,
ScrollAxis,
},
client::ClientId,
config::InvokedShortcut,
@ -672,7 +673,7 @@ impl WlSeatGlobal {
self.motion_event_abs(time_usec, x, y, false);
}
pub fn button_event(self: &Rc<Self>, time_usec: u64, button: u32, state: KeyState) {
pub fn button_event(self: &Rc<Self>, time_usec: u64, button: u32, state: ButtonState) {
self.for_each_ei_seat(|ei_seat| {
ei_seat.handle_button(time_usec, button, state);
});
@ -1314,12 +1315,12 @@ impl WlSeatGlobal {
surface: &Rc<WlSurface>,
time_usec: u64,
button: u32,
state: KeyState,
state: ButtonState,
serial: u64,
) {
let (state, pressed) = match state {
KeyState::Released => (wl_pointer::RELEASED, false),
KeyState::Pressed => {
ButtonState::Released => (wl_pointer::RELEASED, false),
ButtonState::Pressed => {
surface.client.focus_stealing_serial.set(Some(serial));
(wl_pointer::PRESSED, true)
}

View file

@ -1,6 +1,6 @@
use {
crate::{
backend::{AXIS_120, AxisSource, KeyState, ScrollAxis},
backend::{AXIS_120, AxisSource, ButtonState, ScrollAxis},
cursor::KnownCursor,
fixed::Fixed,
ifs::{
@ -57,7 +57,7 @@ impl Default for PointerOwnerHolder {
}
impl PointerOwnerHolder {
pub fn button(&self, seat: &Rc<WlSeatGlobal>, time_usec: u64, button: u32, state: KeyState) {
pub fn button(&self, seat: &Rc<WlSeatGlobal>, time_usec: u64, button: u32, state: ButtonState) {
self.owner.get().button(seat, time_usec, button, state)
}
@ -221,7 +221,7 @@ impl PointerOwnerHolder {
}
trait PointerOwner {
fn button(&self, seat: &Rc<WlSeatGlobal>, time_usec: u64, button: u32, state: KeyState);
fn button(&self, seat: &Rc<WlSeatGlobal>, time_usec: u64, button: u32, state: ButtonState);
fn axis_node(&self, seat: &Rc<WlSeatGlobal>) -> Option<Rc<dyn Node>> {
let _ = seat;
None
@ -318,8 +318,8 @@ struct SelectWorkspaceUsecase<S: ?Sized> {
struct WindowManagementUsecase;
impl<T: SimplePointerOwnerUsecase> PointerOwner for SimplePointerOwner<T> {
fn button(&self, seat: &Rc<WlSeatGlobal>, time_usec: u64, button: u32, state: KeyState) {
if state != KeyState::Pressed {
fn button(&self, seat: &Rc<WlSeatGlobal>, time_usec: u64, button: u32, state: ButtonState) {
if state != ButtonState::Pressed {
return;
}
let pn = match seat.pointer_node() {
@ -436,9 +436,9 @@ impl<T: SimplePointerOwnerUsecase> PointerOwner for SimplePointerOwner<T> {
}
impl<T: SimplePointerOwnerUsecase> PointerOwner for SimpleGrabPointerOwner<T> {
fn button(&self, seat: &Rc<WlSeatGlobal>, time_usec: u64, button: u32, state: KeyState) {
fn button(&self, seat: &Rc<WlSeatGlobal>, time_usec: u64, button: u32, state: ButtonState) {
match state {
KeyState::Released => {
ButtonState::Released => {
if self.buttons.remove(&button).is_none() {
return;
}
@ -449,7 +449,7 @@ impl<T: SimplePointerOwnerUsecase> PointerOwner for SimpleGrabPointerOwner<T> {
seat.tree_changed.trigger();
}
}
KeyState::Pressed => {
ButtonState::Pressed => {
if self.buttons.insert(button, ()).is_some() {
return;
}
@ -493,7 +493,7 @@ impl<T: SimplePointerOwnerUsecase> PointerOwner for SimpleGrabPointerOwner<T> {
self.node.clone(),
time_usec,
button,
KeyState::Released,
ButtonState::Released,
serial,
);
}
@ -511,8 +511,8 @@ impl<T: SimplePointerOwnerUsecase> PointerOwner for SimpleGrabPointerOwner<T> {
}
impl PointerOwner for DndPointerOwner {
fn button(&self, seat: &Rc<WlSeatGlobal>, _time_usec: u64, button: u32, state: KeyState) {
if button != self.button || state != KeyState::Released {
fn button(&self, seat: &Rc<WlSeatGlobal>, _time_usec: u64, button: u32, state: ButtonState) {
if button != self.button || state != ButtonState::Released {
return;
}
let target = self.target.get();
@ -1068,8 +1068,8 @@ impl<T> PointerOwner for ToplevelGrabPointerOwner<T>
where
T: WindowManagementGrabUsecase,
{
fn button(&self, seat: &Rc<WlSeatGlobal>, _time_usec: u64, button: u32, state: KeyState) {
if button != T::BUTTON || state != KeyState::Released {
fn button(&self, seat: &Rc<WlSeatGlobal>, _time_usec: u64, button: u32, state: ButtonState) {
if button != T::BUTTON || state != ButtonState::Released {
return;
}
self.tl.node_seat_state().remove_pointer_grab(seat);
@ -1238,12 +1238,12 @@ impl<T> PointerOwner for UiDragPointerOwner<T>
where
T: UiDragUsecase,
{
fn button(&self, seat: &Rc<WlSeatGlobal>, _time_usec: u64, button: u32, state: KeyState) {
fn button(&self, seat: &Rc<WlSeatGlobal>, _time_usec: u64, button: u32, state: ButtonState) {
if button == BTN_RIGHT {
self.do_revert_to_default(seat, false);
return;
}
if button != BTN_LEFT || state != KeyState::Released {
if button != BTN_LEFT || state != ButtonState::Released {
return;
}
self.apply_changes(seat);

View file

@ -21,7 +21,7 @@ pub mod zwp_input_popup_surface_v2;
use {
crate::{
backend::KeyState,
backend::{ButtonState, KeyState},
client::{Client, ClientError},
cmm::cmm_description::ColorDescription,
cursor_user::{CursorUser, CursorUserId},
@ -1907,7 +1907,7 @@ impl Node for WlSurface {
seat: &Rc<WlSeatGlobal>,
time_usec: u64,
button: u32,
state: KeyState,
state: ButtonState,
serial: u64,
) {
seat.button_surface(&self, time_usec, button, state, serial);

View file

@ -3,10 +3,10 @@ use {
allocator::{Allocator, AllocatorError},
async_engine::SpawnedFuture,
backend::{
AxisSource, Backend, BackendConnectorState, BackendEvent, Connector, ConnectorEvent,
ConnectorId, ConnectorKernelId, DrmDeviceId, InputDevice, InputDeviceAccelProfile,
InputDeviceCapability, InputDeviceClickMethod, InputDeviceId, InputEvent, KeyState,
Mode, MonitorInfo, ScrollAxis, TransformMatrix,
AxisSource, Backend, BackendConnectorState, BackendEvent, ButtonState, Connector,
ConnectorEvent, ConnectorId, ConnectorKernelId, DrmDeviceId, InputDevice,
InputDeviceAccelProfile, InputDeviceCapability, InputDeviceClickMethod, InputDeviceId,
InputEvent, KeyState, Mode, MonitorInfo, ScrollAxis, TransformMatrix,
transaction::{
BackendAppliedConnectorTransaction, BackendConnectorTransaction,
BackendConnectorTransactionError, BackendConnectorTransactionType,
@ -423,7 +423,7 @@ impl Drop for TestMouseClick {
self.mouse.common.event(InputEvent::Button {
time_usec: self.mouse.common.state.now_usec(),
button: self.button,
state: KeyState::Released,
state: ButtonState::Released,
});
}
}
@ -460,7 +460,7 @@ impl TestBackendMouse {
self.common.event(InputEvent::Button {
time_usec: self.common.state.now_usec(),
button,
state: KeyState::Pressed,
state: ButtonState::Pressed,
});
TestMouseClick {
mouse: self.clone(),

View file

@ -1,6 +1,6 @@
use {
crate::{
backend::KeyState,
backend::{ButtonState, KeyState},
client::{Client, ClientId},
fixed::Fixed,
ifs::{
@ -346,7 +346,7 @@ pub trait Node: 'static {
seat: &Rc<WlSeatGlobal>,
time_usec: u64,
button: u32,
state: KeyState,
state: ButtonState,
serial: u64,
) {
let _ = seat;

View file

@ -1,6 +1,6 @@
use {
crate::{
backend::KeyState,
backend::ButtonState,
cursor::KnownCursor,
cursor_user::CursorUser,
fixed::Fixed,
@ -1700,11 +1700,11 @@ impl Node for ContainerNode {
seat: &Rc<WlSeatGlobal>,
time_usec: u64,
button: u32,
state: KeyState,
state: ButtonState,
_serial: u64,
) {
let id = CursorType::Seat(seat.id());
self.button(id, seat, time_usec, state == KeyState::Pressed, button);
self.button(id, seat, time_usec, state == ButtonState::Pressed, button);
}
fn node_on_axis_event(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, event: &PendingScroll) {

View file

@ -1,6 +1,6 @@
use {
crate::{
backend::KeyState,
backend::ButtonState,
cursor::KnownCursor,
cursor_user::CursorUser,
fixed::Fixed,
@ -776,10 +776,10 @@ impl Node for FloatNode {
seat: &Rc<WlSeatGlobal>,
time_usec: u64,
button: u32,
state: KeyState,
state: ButtonState,
_serial: u64,
) {
if button == BTN_RIGHT && state == KeyState::Pressed {
if button == BTN_RIGHT && state == ButtonState::Pressed {
self.toggle_pinned();
}
if button != BTN_LEFT {
@ -790,7 +790,7 @@ impl Node for FloatNode {
seat.pointer_cursor(),
seat,
time_usec,
state == KeyState::Pressed,
state == ButtonState::Pressed,
);
}

View file

@ -1,7 +1,8 @@
use {
crate::{
backend::{
BackendColorSpace, BackendConnectorState, BackendEotfs, HardwareCursor, KeyState, Mode,
BackendColorSpace, BackendConnectorState, BackendEotfs, ButtonState, HardwareCursor,
Mode,
},
client::ClientId,
cmm::cmm_description::ColorDescription,
@ -1685,13 +1686,13 @@ impl Node for OutputNode {
seat: &Rc<WlSeatGlobal>,
_time_usec: u64,
button: u32,
state: KeyState,
state: ButtonState,
_serial: u64,
) {
if button != BTN_LEFT {
return;
}
if state != KeyState::Pressed {
if state != ButtonState::Pressed {
self.pointer_down.remove(&seat.id());
return;
}