Skip to content

Commit

Permalink
Merge pull request #190 from mahkoh/jorth/tablet
Browse files Browse the repository at this point in the history
wayland: implement tablet-v2
  • Loading branch information
mahkoh authored May 4, 2024
2 parents 06fe5b1 + 7ed499e commit ff666e2
Show file tree
Hide file tree
Showing 89 changed files with 6,231 additions and 758 deletions.
4 changes: 0 additions & 4 deletions build/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,6 @@ fn write_request_handler<W: Write>(
messages: &ParseResult,
) -> Result<()> {
writeln!(f)?;
// TODO: remove this after https://github.com/mahkoh/jay/pull/190
if camel_obj_name == "ZwpTabletToolV2" {
writeln!(f, " #[allow(dead_code)]")?;
}
writeln!(
f,
" pub trait {camel_obj_name}RequestHandler: crate::object::Object + Sized {{"
Expand Down
16 changes: 16 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,22 @@ You can use the `configure-input` action to change these settings at runtime.

See the specification for more details.

### Mapping Tablets to Outputs

You can map tablets to outputs using the `output` property:

```toml
[[outputs]]
name = "left"
match.serial-number = "33K03894SL0"

[[inputs]]
match.name = "Wacom Bamboo Comic 2FG Pen"
output.name = "left"
```

See the specification for more details.

# Theming

You can configure the colors, sizes, and fonts used by the compositor with the top-level `theme` table.
Expand Down
2 changes: 1 addition & 1 deletion docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ Jay supports the following wayland protocols:
| zwp_pointer_gestures_v1 | 3 | |
| zwp_primary_selection_device_manager_v1 | 1 | |
| zwp_relative_pointer_manager_v1 | 1 | |
| zwp_tablet_manager_v2 | 1 | |
| zwp_text_input_manager_v3 | 1 | |
| zwp_virtual_keyboard_manager_v1 | 1 | Yes |
| zxdg_decoration_manager_v1 | 1 | |
Expand All @@ -182,5 +183,4 @@ The following features are currently not supported but might get implemented in

- Fine-grained damage tracking.
- Touch support.
- Tablet support.
- Tearing updates of fullscreen games.
34 changes: 33 additions & 1 deletion jay-config/src/_private/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ pub(crate) struct Client {
response: RefCell<Vec<Response>>,
on_new_seat: RefCell<Option<Callback<Seat>>>,
on_new_input_device: RefCell<Option<Callback<InputDevice>>>,
on_input_device_removed: RefCell<Option<Callback<InputDevice>>>,
on_connector_connected: RefCell<Option<Callback<Connector>>>,
on_connector_disconnected: RefCell<Option<Callback<Connector>>>,
on_graphics_initialized: Cell<Option<Box<dyn FnOnce()>>>,
on_devices_enumerated: Cell<Option<Box<dyn FnOnce()>>>,
on_new_connector: RefCell<Option<Callback<Connector>>>,
Expand Down Expand Up @@ -216,7 +218,9 @@ pub unsafe extern "C" fn init(
response: Default::default(),
on_new_seat: Default::default(),
on_new_input_device: Default::default(),
on_input_device_removed: Default::default(),
on_connector_connected: Default::default(),
on_connector_disconnected: Default::default(),
on_graphics_initialized: Default::default(),
on_devices_enumerated: Default::default(),
on_new_connector: Default::default(),
Expand Down Expand Up @@ -605,6 +609,10 @@ impl Client {
*self.on_new_input_device.borrow_mut() = Some(cb(f));
}

pub fn on_input_device_removed<F: FnMut(InputDevice) + 'static>(&self, f: F) {
*self.on_input_device_removed.borrow_mut() = Some(cb(f));
}

pub fn on_switch_event<F: FnMut(SwitchEvent) + 'static>(
&self,
input_device: InputDevice,
Expand Down Expand Up @@ -818,6 +826,10 @@ impl Client {
*self.on_connector_connected.borrow_mut() = Some(cb(f));
}

pub fn on_connector_disconnected<F: FnMut(Connector) + 'static>(&self, f: F) {
*self.on_connector_disconnected.borrow_mut() = Some(cb(f));
}

pub fn on_graphics_initialized<F: FnOnce() + 'static>(&self, f: F) {
self.on_graphics_initialized.set(Some(Box::new(f)));
}
Expand Down Expand Up @@ -943,6 +955,17 @@ impl Client {
self.send(&ClientMessage::SetFocusFollowsMouseMode { seat, mode })
}

pub fn set_input_device_connector(&self, input_device: InputDevice, connector: Connector) {
self.send(&ClientMessage::SetInputDeviceConnector {
input_device,
connector,
})
}

pub fn remove_input_mapping(&self, input_device: InputDevice) {
self.send(&ClientMessage::RemoveInputMapping { input_device })
}

pub fn parse_keymap(&self, keymap: &str) -> Keymap {
let res = self.send_with_response(&ClientMessage::ParseKeymap { keymap });
get_response!(res, Keymap(0), ParseKeymap { keymap });
Expand Down Expand Up @@ -1272,14 +1295,23 @@ impl Client {
}
ServerMessage::DelInputDevice { device } => {
self.on_switch_event.borrow_mut().remove(&device);
let handler = self.on_input_device_removed.borrow_mut().clone();
if let Some(handler) = handler {
run_cb("input device removed", &handler, device);
}
}
ServerMessage::ConnectorConnect { device } => {
let handler = self.on_connector_connected.borrow_mut().clone();
if let Some(handler) = handler {
run_cb("connector connected", &handler, device);
}
}
ServerMessage::ConnectorDisconnect { .. } => {}
ServerMessage::ConnectorDisconnect { device } => {
let handler = self.on_connector_disconnected.borrow_mut().clone();
if let Some(handler) = handler {
run_cb("connector disconnected", &handler, device);
}
}
ServerMessage::NewConnector { device } => {
let handler = self.on_new_connector.borrow_mut().clone();
if let Some(handler) = handler {
Expand Down
7 changes: 7 additions & 0 deletions jay-config/src/_private/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,13 @@ pub enum ClientMessage<'a> {
seat: Seat,
mode: FocusFollowsMouseMode,
},
SetInputDeviceConnector {
input_device: InputDevice,
connector: Connector,
},
RemoveInputMapping {
input_device: InputDevice,
},
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down
19 changes: 19 additions & 0 deletions jay-config/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ impl InputDevice {
pub fn on_switch_event<F: FnMut(SwitchEvent) + 'static>(self, f: F) {
get!().on_switch_event(self, f)
}

/// Maps this input device to a connector.
///
/// The connector should be connected.
///
/// This should be used for touch screens and graphics tablets.
pub fn set_connector(self, connector: Connector) {
get!().set_input_device_connector(self, connector);
}

/// Removes the mapping of this device to a connector.
pub fn remove_mapping(self) {
get!().remove_input_mapping(self);
}
}

/// A seat.
Expand Down Expand Up @@ -449,6 +463,11 @@ pub fn on_new_input_device<F: FnMut(InputDevice) + 'static>(f: F) {
get!().on_new_input_device(f)
}

/// Sets a closure to run when an input device has been removed.
pub fn on_input_device_removed<F: FnMut(InputDevice) + 'static>(f: F) {
get!().on_input_device_removed(f)
}

/// Sets the maximum time between two clicks to be registered as a double click by the
/// compositor.
///
Expand Down
5 changes: 5 additions & 0 deletions jay-config/src/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ pub fn on_connector_connected<F: FnMut(Connector) + 'static>(f: F) {
get!().on_connector_connected(f)
}

/// Sets the callback to be called when a connector is disconnected from an output device.
pub fn on_connector_disconnected<F: FnMut(Connector) + 'static>(f: F) {
get!().on_connector_disconnected(f)
}

/// Sets the callback to be called when the graphics of the compositor have been initialized.
///
/// This callback is only invoked once during the lifetime of the compositor. This is a good place
Expand Down
1 change: 1 addition & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Focus-follows-mouse can now be disabled.
- Add support for pointer-gestures-unstable-v1.
- Configs can now handle switch events (laptop lid closed/opened).
- Add support for tablet-v2.

# 1.1.0 (2024-04-22)

Expand Down
64 changes: 63 additions & 1 deletion src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ use {
drm_feedback::DrmFeedback,
fixed::Fixed,
gfx_api::{GfxFramebuffer, SyncFile},
ifs::wl_seat::wl_pointer::{CONTINUOUS, FINGER, HORIZONTAL_SCROLL, VERTICAL_SCROLL, WHEEL},
ifs::wl_seat::{
tablet::{
PadButtonState, TabletInit, TabletPadId, TabletPadInit, TabletRingEventSource,
TabletStripEventSource, TabletToolChanges, TabletToolId, TabletToolInit,
ToolButtonState,
},
wl_pointer::{CONTINUOUS, FINGER, HORIZONTAL_SCROLL, VERTICAL_SCROLL, WHEEL},
},
libinput::consts::DeviceCapability,
video::drm::{ConnectorType, DrmConnector, DrmError, DrmVersion},
},
Expand Down Expand Up @@ -126,6 +133,8 @@ pub trait HardwareCursor: Debug {

pub type TransformMatrix = [[f64; 2]; 2];

linear_ids!(InputDeviceGroupIds, InputDeviceGroupId, usize);

pub trait InputDevice {
fn id(&self) -> InputDeviceId;
fn removed(&self) -> bool;
Expand Down Expand Up @@ -169,6 +178,12 @@ pub trait InputDevice {
None
}
fn set_natural_scrolling_enabled(&self, enabled: bool);
fn tablet_info(&self) -> Option<Box<TabletInit>> {
None
}
fn tablet_pad_info(&self) -> Option<Box<TabletPadInit>> {
None
}
}

#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
Expand Down Expand Up @@ -321,6 +336,53 @@ pub enum InputEvent {
time_usec: u64,
event: SwitchEvent,
},

TabletToolAdded {
time_usec: u64,
init: Box<TabletToolInit>,
},
TabletToolChanged {
time_usec: u64,
id: TabletToolId,
changes: Box<TabletToolChanges>,
},
TabletToolButton {
time_usec: u64,
id: TabletToolId,
button: u32,
state: ToolButtonState,
},
TabletToolRemoved {
time_usec: u64,
id: TabletToolId,
},

TabletPadButton {
time_usec: u64,
id: TabletPadId,
button: u32,
state: PadButtonState,
},
TabletPadModeSwitch {
time_usec: u64,
pad: TabletPadId,
group: u32,
mode: u32,
},
TabletPadRing {
time_usec: u64,
pad: TabletPadId,
ring: u32,
source: Option<TabletRingEventSource>,
angle: Option<f64>,
},
TabletPadStrip {
time_usec: u64,
pad: TabletPadId,
strip: u32,
source: Option<TabletStripEventSource>,
position: Option<f64>,
},
}

pub enum DrmEvent {
Expand Down
Loading

0 comments on commit ff666e2

Please sign in to comment.