Skip to main content

jay_config/
input.rs

1//! Tools for configuring input devices.
2
3pub mod acceleration;
4pub mod capability;
5pub mod clickmethod;
6
7use {
8    crate::{
9        _private::{DEFAULT_SEAT_NAME, ipc::WorkspaceSource},
10        Axis, Direction, ModifiedKeySym, Workspace,
11        input::{acceleration::AccelProfile, capability::Capability, clickmethod::ClickMethod},
12        keyboard::{Keymap, mods::Modifiers, syms::KeySym},
13        video::Connector,
14        window::Window,
15    },
16    serde::{Deserialize, Serialize},
17    std::time::Duration,
18};
19
20/// An input device.
21#[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
22pub struct InputDevice(pub u64);
23
24impl InputDevice {
25    /// Assigns the input device to a seat.
26    pub fn set_seat(self, seat: Seat) {
27        get!().set_seat(self, seat)
28    }
29
30    /// Sets the keymap of the device.
31    ///
32    /// This overrides the keymap set for the seat. The keymap becomes active when a key
33    /// on the device is pressed.
34    ///
35    /// Setting the invalid keymap reverts to the seat keymap.
36    pub fn set_keymap(self, keymap: Keymap) {
37        get!().set_device_keymap(self, keymap)
38    }
39
40    /// Returns whether the device has the specified capability.
41    pub fn has_capability(self, cap: Capability) -> bool {
42        get!(false).has_capability(self, cap)
43    }
44
45    /// Sets the device to be left handed.
46    ///
47    /// This has the effect of swapping the left and right mouse button. See the libinput
48    /// documentation for more details.
49    pub fn set_left_handed(self, left_handed: bool) {
50        get!().set_left_handed(self, left_handed);
51    }
52
53    /// Sets the acceleration profile of the device.
54    ///
55    /// This corresponds to the libinput setting of the same name.
56    pub fn set_accel_profile(self, profile: AccelProfile) {
57        get!().set_accel_profile(self, profile);
58    }
59
60    /// Sets the acceleration speed of the device.
61    ///
62    /// This corresponds to the libinput setting of the same name.
63    pub fn set_accel_speed(self, speed: f64) {
64        get!().set_accel_speed(self, speed);
65    }
66
67    /// Sets the transformation matrix of the device.
68    ///
69    /// This is not a libinput setting but a setting of the compositor. It currently affects
70    /// relative mouse motions in that the matrix is applied to the motion. To reduce the mouse
71    /// speed to 35%, use the following matrix:
72    ///
73    /// ```text
74    /// [
75    ///     [0.35, 1.0],
76    ///     [1.0, 0.35],
77    /// ]
78    /// ```
79    ///
80    /// This might give you better results than using `set_accel_profile` and `set_accel_speed`.
81    pub fn set_transform_matrix(self, matrix: [[f64; 2]; 2]) {
82        get!().set_transform_matrix(self, matrix);
83    }
84
85    /// Sets the calibration matrix of the device.
86    ///
87    /// This corresponds to the libinput setting of the same name.
88    pub fn set_calibration_matrix(self, matrix: [[f32; 3]; 2]) {
89        get!().set_calibration_matrix(self, matrix);
90    }
91
92    /// Returns the name of the device.
93    pub fn name(self) -> String {
94        get!(String::new()).device_name(self)
95    }
96
97    /// Sets how many pixel to scroll per scroll wheel dedent.
98    ///
99    /// Default: `15.0`
100    ///
101    /// This setting has no effect on non-wheel input such as touchpads.
102    ///
103    /// Some mouse wheels support high-resolution scrolling without discrete steps. In
104    /// this case a value proportional to this setting will be used.
105    pub fn set_px_per_wheel_scroll(self, px: f64) {
106        get!().set_px_per_wheel_scroll(self, px);
107    }
108
109    /// Sets whether tap-to-click is enabled for this device.
110    ///
111    /// See <https://wayland.freedesktop.org/libinput/doc/latest/tapping.html>
112    pub fn set_tap_enabled(self, enabled: bool) {
113        get!().set_input_tap_enabled(self, enabled);
114    }
115
116    /// Sets whether tap-and-drag is enabled for this device.
117    ///
118    /// See <https://wayland.freedesktop.org/libinput/doc/latest/tapping.html>
119    pub fn set_drag_enabled(self, enabled: bool) {
120        get!().set_input_drag_enabled(self, enabled);
121    }
122
123    /// Sets whether drag lock is enabled for this device.
124    ///
125    /// See <https://wayland.freedesktop.org/libinput/doc/latest/tapping.html>
126    pub fn set_drag_lock_enabled(self, enabled: bool) {
127        get!().set_input_drag_lock_enabled(self, enabled);
128    }
129
130    /// Sets whether natural scrolling is enabled for this device.
131    ///
132    /// See <https://wayland.freedesktop.org/libinput/doc/latest/scrolling.html>
133    pub fn set_natural_scrolling_enabled(self, enabled: bool) {
134        get!().set_input_natural_scrolling_enabled(self, enabled);
135    }
136
137    /// Sets the click method of the device.
138    ///
139    /// See <https://wayland.freedesktop.org/libinput/doc/latest/configuration.html#click-method>
140    pub fn set_click_method(self, method: ClickMethod) {
141        get!().set_input_click_method(self, method);
142    }
143
144    /// Sets whether middle button emulation is enabled for this device.
145    ///
146    /// See <https://wayland.freedesktop.org/libinput/doc/latest/configuration.html#middle-button-emulation>
147    pub fn set_middle_button_emulation_enabled(self, enabled: bool) {
148        get!().set_input_middle_button_emulation_enabled(self, enabled);
149    }
150
151    /// Returns the syspath of this device.
152    ///
153    /// E.g. `/sys/devices/pci0000:00/0000:00:08.1/0000:14:00.4/usb5/5-1/5-1.1/5-1.1.3/5-1.1.3:1.0`.
154    pub fn syspath(self) -> String {
155        get!(String::new()).input_device_syspath(self)
156    }
157
158    /// Returns the devnode of this device.
159    ///
160    /// E.g. `/dev/input/event7`.
161    pub fn devnode(self) -> String {
162        get!(String::new()).input_device_devnode(self)
163    }
164
165    /// Sets a callback that will be run if this device triggers a switch event.
166    pub fn on_switch_event<F: FnMut(SwitchEvent) + 'static>(self, f: F) {
167        get!().on_switch_event(self, f)
168    }
169
170    /// Maps this input device to a connector.
171    ///
172    /// The connector should be connected.
173    ///
174    /// This should be used for touch screens and graphics tablets.
175    pub fn set_connector(self, connector: Connector) {
176        get!().set_input_device_connector(self, connector);
177    }
178
179    /// Removes the mapping of this device to a connector.
180    pub fn remove_mapping(self) {
181        get!().remove_input_mapping(self);
182    }
183}
184
185/// A direction in a timeline.
186#[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
187pub enum Timeline {
188    Older,
189    Newer,
190}
191
192/// A direction for layer traversal.
193#[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
194pub enum LayerDirection {
195    Below,
196    Above,
197}
198
199/// A seat.
200#[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
201pub struct Seat(pub u64);
202
203impl Seat {
204    pub const INVALID: Self = Self(0);
205
206    /// Returns whether the seat is invalid.
207    pub fn is_invalid(self) -> bool {
208        self == Self::INVALID
209    }
210
211    #[doc(hidden)]
212    pub fn raw(self) -> u64 {
213        self.0
214    }
215
216    #[doc(hidden)]
217    pub fn from_raw(raw: u64) -> Self {
218        Self(raw)
219    }
220
221    /// Sets whether this seat's cursor uses the hardware cursor if available.
222    ///
223    /// Only one seat at a time can use the hardware cursor. Setting this to `true` for a
224    /// seat automatically unsets it for all other seats.
225    ///
226    /// By default, the first created seat uses the hardware cursor.
227    pub fn use_hardware_cursor(self, use_hardware_cursor: bool) {
228        get!().set_use_hardware_cursor(self, use_hardware_cursor);
229    }
230
231    /// Sets the size of the cursor theme.
232    ///
233    /// Default: 16.
234    pub fn set_cursor_size(self, size: i32) {
235        get!().set_cursor_size(self, size)
236    }
237
238    /// Creates a compositor-wide hotkey.
239    ///
240    /// The closure is invoked when the user presses the last key of the modified keysym.
241    /// Note that the keysym is calculated without modifiers applied. To perform an action
242    /// when `SHIFT+k` is pressed, use `SHIFT | SYM_k` not `SHIFT | SYM_K`.
243    ///
244    /// CapsLock and NumLock are ignored during modifier evaluation. Therefore, bindings
245    /// containing these modifiers will never be invoked.
246    pub fn bind<T: Into<ModifiedKeySym>, F: FnMut() + 'static>(self, mod_sym: T, f: F) {
247        self.bind_masked(Modifiers(!0), mod_sym, f)
248    }
249
250    /// Creates a compositor-wide hotkey while ignoring some modifiers.
251    ///
252    /// This is similar to `bind` except that only the masked modifiers are considered.
253    ///
254    /// For example, if this function is invoked with `mod_mask = Modifiers::NONE` and
255    /// `mod_sym = SYM_XF86AudioRaiseVolume`, then the callback will be invoked whenever
256    /// `SYM_XF86AudioRaiseVolume` is pressed. Even if the user is simultaneously holding
257    /// the shift key which would otherwise prevent the callback from taking effect.
258    ///
259    /// For example, if this function is invoked with `mod_mask = CTRL | SHIFT` and
260    /// `mod_sym = CTRL | SYM_x`, then the callback will be invoked whenever the user
261    /// presses `ctrl+x` without pressing the shift key. Even if the user is
262    /// simultaneously holding the alt key.
263    ///
264    /// If `mod_sym` contains any modifiers, then these modifiers are automatically added
265    /// to the mask. The synthetic `RELEASE` modifier is always added to the mask.
266    pub fn bind_masked<T: Into<ModifiedKeySym>, F: FnMut() + 'static>(
267        self,
268        mod_mask: Modifiers,
269        mod_sym: T,
270        f: F,
271    ) {
272        get!().bind_masked(self, mod_mask, mod_sym.into(), f)
273    }
274
275    /// Registers a callback to be executed when the currently pressed key is released.
276    ///
277    /// This should only be called in callbacks for key-press binds.
278    ///
279    /// The callback will be executed once when the key is released regardless of any
280    /// modifiers.
281    pub fn latch<F: FnOnce() + 'static>(self, f: F) {
282        get!().latch(self, f)
283    }
284
285    /// Unbinds a hotkey.
286    pub fn unbind<T: Into<ModifiedKeySym>>(self, mod_sym: T) {
287        get!().unbind(self, mod_sym.into())
288    }
289
290    /// Moves the focus in the focus history.
291    pub fn focus_history(self, timeline: Timeline) {
292        get!().seat_focus_history(self, timeline)
293    }
294
295    /// Configures whether the focus history only includes visible windows.
296    ///
297    /// If this is `false`, then hidden windows will be made visible before moving the
298    /// focus to them.
299    ///
300    /// The default is `false`.
301    pub fn focus_history_set_only_visible(self, only_visible: bool) {
302        get!().seat_focus_history_set_only_visible(self, only_visible)
303    }
304
305    /// Configures whether the focus history only includes windows on the same workspace
306    /// as the currently focused window.
307    ///
308    /// The default is `false`.
309    pub fn focus_history_set_same_workspace(self, same_workspace: bool) {
310        get!().seat_focus_history_set_same_workspace(self, same_workspace)
311    }
312
313    /// Moves the keyboard focus of the seat to the layer above or below the current
314    /// layer.
315    pub fn focus_layer_rel(self, direction: LayerDirection) {
316        get!().seat_focus_layer_rel(self, direction)
317    }
318
319    /// Moves the keyboard focus to the tile layer.
320    pub fn focus_tiles(self) {
321        get!().seat_focus_tiles(self)
322    }
323
324    /// Moves the keyboard focus of the seat in the specified direction.
325    pub fn focus(self, direction: Direction) {
326        get!().seat_focus(self, direction)
327    }
328
329    /// Moves the focused window in the specified direction.
330    pub fn move_(self, direction: Direction) {
331        get!().seat_move(self, direction)
332    }
333
334    /// Sets the keymap of the seat.
335    pub fn set_keymap(self, keymap: Keymap) {
336        get!().seat_set_keymap(self, keymap)
337    }
338
339    /// Returns the repeat rate of the seat.
340    ///
341    /// The returned tuple is `(rate, delay)` where `rate` is the number of times keys repeat per second
342    /// and `delay` is the time after the button press after which keys start repeating.
343    pub fn repeat_rate(self) -> (i32, i32) {
344        get!((25, 250)).seat_get_repeat_rate(self)
345    }
346
347    /// Sets the repeat rate of the seat.
348    pub fn set_repeat_rate(self, rate: i32, delay: i32) {
349        get!().seat_set_repeat_rate(self, rate, delay)
350    }
351
352    /// Returns whether the parent-container of the currently focused window is in mono-mode.
353    pub fn mono(self) -> bool {
354        get!(false).seat_mono(self)
355    }
356
357    /// Sets whether the parent-container of the currently focused window is in mono-mode.
358    pub fn set_mono(self, mono: bool) {
359        get!().set_seat_mono(self, mono)
360    }
361
362    /// Toggles whether the parent-container of the currently focused window is in mono-mode.
363    pub fn toggle_mono(self) {
364        self.set_mono(!self.mono());
365    }
366
367    /// Returns the split axis of the parent-container of the currently focused window.
368    pub fn split(self) -> Axis {
369        get!(Axis::Horizontal).seat_split(self)
370    }
371
372    /// Sets the split axis of the parent-container of the currently focused window.
373    pub fn set_split(self, axis: Axis) {
374        get!().set_seat_split(self, axis)
375    }
376
377    /// Toggles the split axis of the parent-container of the currently focused window.
378    pub fn toggle_split(self) {
379        self.set_split(self.split().other());
380    }
381
382    /// Returns the input devices assigned to this seat.
383    pub fn input_devices(self) -> Vec<InputDevice> {
384        get!().get_input_devices(Some(self))
385    }
386
387    /// Creates a new container with the specified split in place of the currently focused window.
388    pub fn create_split(self, axis: Axis) {
389        get!().create_seat_split(self, axis);
390    }
391
392    /// Focuses the parent node of the currently focused window.
393    pub fn focus_parent(self) {
394        get!().focus_seat_parent(self);
395    }
396
397    /// Requests the currently focused window to be closed.
398    pub fn close(self) {
399        get!().seat_close(self);
400    }
401
402    /// Returns whether the currently focused window is floating.
403    pub fn get_floating(self) -> bool {
404        get!().get_seat_floating(self)
405    }
406    /// Sets whether the currently focused window is floating.
407    pub fn set_floating(self, floating: bool) {
408        get!().set_seat_floating(self, floating);
409    }
410
411    /// Toggles whether the currently focused window is floating.
412    ///
413    /// You can do the same by double-clicking on the header.
414    pub fn toggle_floating(self) {
415        get!().toggle_seat_floating(self);
416    }
417
418    /// Returns the workspace that is currently active on the output that contains the seat's
419    /// cursor.
420    ///
421    /// If no such workspace exists, `exists` returns `false` for the returned workspace.
422    pub fn get_workspace(self) -> Workspace {
423        get!(Workspace(0)).get_seat_cursor_workspace(self)
424    }
425
426    /// Returns the workspace that is currently active on the output that contains the seat's
427    /// keyboard focus.
428    ///
429    /// If no such workspace exists, `exists` returns `false` for the returned workspace.
430    pub fn get_keyboard_workspace(self) -> Workspace {
431        get!(Workspace(0)).get_seat_keyboard_workspace(self)
432    }
433
434    /// Shows the workspace and sets the keyboard focus of the seat to that workspace.
435    ///
436    /// If the workspace doesn't currently exist, it is created on the output that contains the
437    /// seat's cursor.
438    pub fn show_workspace(self, workspace: Workspace) {
439        get!().show_workspace(self, workspace)
440    }
441
442    /// Shows the workspace and sets the keyboard focus of the seat to that workspace.
443    ///
444    /// If the workspace doesn't currently exist and the connector is connected, the
445    /// workspace is created on the given connector. If the connector is not connected,
446    /// the workspace is created on the output that contains the seat's cursor.
447    pub fn show_workspace_on(self, workspace: Workspace, connector: Connector) {
448        get!().show_workspace_on(self, workspace, connector)
449    }
450
451    /// Moves the currently focused window to the workspace.
452    pub fn set_workspace(self, workspace: Workspace) {
453        get!().set_seat_workspace(self, workspace)
454    }
455
456    /// Toggles whether the currently focused window is fullscreen.
457    pub fn toggle_fullscreen(self) {
458        let c = get!();
459        c.set_seat_fullscreen(self, !c.get_seat_fullscreen(self));
460    }
461    /// Returns whether the currently focused window is fullscreen.
462    pub fn fullscreen(self) -> bool {
463        get!(false).get_seat_fullscreen(self)
464    }
465
466    /// Sets whether the currently focused window is fullscreen.
467    pub fn set_fullscreen(self, fullscreen: bool) {
468        get!().set_seat_fullscreen(self, fullscreen)
469    }
470
471    /// Disables the currently active pointer constraint on this seat.
472    pub fn disable_pointer_constraint(self) {
473        get!().disable_pointer_constraint(self)
474    }
475
476    /// Moves the currently focused workspace to another output.
477    pub fn move_to_output(self, connector: Connector) {
478        get!().move_to_output(WorkspaceSource::Seat(self), connector);
479    }
480
481    /// Set whether the current key event is forwarded to the focused client.
482    ///
483    /// This only has an effect if called from a keyboard shortcut.
484    ///
485    /// By default, release events are forwarded and press events are consumed. Note that
486    /// consuming release events can cause clients to get stuck in the pressed state.
487    pub fn set_forward(self, forward: bool) {
488        get!().set_forward(self, forward);
489    }
490
491    /// This is a shorthand for `set_forward(true)`.
492    pub fn forward(self) {
493        self.set_forward(true)
494    }
495
496    /// This is a shorthand for `set_forward(false)`.
497    pub fn consume(self) {
498        self.set_forward(false)
499    }
500
501    /// Sets the focus-follows-mouse mode.
502    pub fn set_focus_follows_mouse_mode(self, mode: FocusFollowsMouseMode) {
503        get!().set_focus_follows_mouse_mode(self, mode);
504    }
505
506    /// Sets the fallback output mode.
507    ///
508    /// The default is `Cursor`.
509    pub fn set_fallback_output_mode(self, mode: FallbackOutputMode) {
510        get!().set_fallback_output_mode(self, mode);
511    }
512
513    /// Enables or disable window management mode.
514    ///
515    /// In window management mode, floating windows can be moved by pressing the left
516    /// mouse button and all windows can be resize by pressing the right mouse button.
517    pub fn set_window_management_enabled(self, enabled: bool) {
518        get!().set_window_management_enabled(self, enabled);
519    }
520
521    /// Sets a key that enables window management mode while pressed.
522    ///
523    /// This is a shorthand for
524    ///
525    /// ```rust,ignore
526    /// self.bind(mod_sym, move || {
527    ///     self.set_window_management_enabled(true);
528    ///     self.forward();
529    ///     self.latch(move || {
530    ///         self.set_window_management_enabled(false);
531    ///     });
532    /// });
533    /// ```
534    pub fn set_window_management_key<T: Into<ModifiedKeySym>>(self, mod_sym: T) {
535        self.bind(mod_sym, move || {
536            self.set_window_management_enabled(true);
537            self.forward();
538            self.latch(move || {
539                self.set_window_management_enabled(false);
540            });
541        });
542    }
543
544    /// Gets whether the currently focused window is pinned.
545    ///
546    /// If a floating window is pinned, it will stay visible even when switching to a
547    /// different workspace.
548    pub fn float_pinned(self) -> bool {
549        get!().get_pinned(self)
550    }
551
552    /// Sets whether the currently focused window is pinned.
553    pub fn set_float_pinned(self, pinned: bool) {
554        get!().set_pinned(self, pinned);
555    }
556
557    /// Toggles whether the currently focused window is pinned.
558    pub fn toggle_float_pinned(self) {
559        self.set_float_pinned(!self.float_pinned());
560    }
561
562    /// Returns the focused window.
563    ///
564    /// If no window is focused, [`Window::exists`] returns false.
565    pub fn window(self) -> Window {
566        get!(Window(0)).get_seat_keyboard_window(self)
567    }
568
569    /// Puts the keyboard focus on the window.
570    ///
571    /// This has no effect if the window is not visible.
572    pub fn focus_window(self, window: Window) {
573        get!().focus_window(self, window)
574    }
575
576    /// Sets the key that can be used to revert the pointer to the default state.
577    ///
578    /// Pressing this key cancels any grabs, drags, selections, etc.
579    ///
580    /// The default is `SYM_Escape`. Setting this to `SYM_NoSymbol` effectively disables
581    /// this functionality.
582    pub fn set_pointer_revert_key(self, sym: KeySym) {
583        get!().set_pointer_revert_key(self, sym);
584    }
585
586    /// Creates a mark for the currently focused window.
587    ///
588    /// `kc` should be an evdev keycode. If `kc` is none, then the keycode will be
589    /// inferred from the next key press. Pressing escape during this interactive
590    /// selection aborts the process.
591    ///
592    /// Currently very few `u32` are valid keycodes. Large numbers can therefore be used
593    /// to create marks that do not correspond to a key. However, `kc` should always be
594    /// less than `u32::MAX - 8`.
595    pub fn create_mark(self, kc: Option<u32>) {
596        get!().seat_create_mark(self, kc);
597    }
598
599    /// Moves the keyboard focus to a window identified by a mark.
600    ///
601    /// See [`Seat::create_mark`] for information about the `kc` parameter.
602    pub fn jump_to_mark(self, kc: Option<u32>) {
603        get!().seat_jump_to_mark(self, kc);
604    }
605
606    /// Copies a mark from one keycode to another.
607    ///
608    /// If the `src` keycode identifies a mark before this function is called, the `dst`
609    /// keycode will identify the same mark afterwards.
610    pub fn copy_mark(self, src: u32, dst: u32) {
611        get!().seat_copy_mark(self, src, dst);
612    }
613
614    /// Sets whether the simple, XCompose based input method is enabled.
615    ///
616    /// Regardless of this setting, this input method is not used if an external input
617    /// method is running.
618    ///
619    /// The default is `true`.
620    pub fn set_simple_im_enabled(self, enabled: bool) {
621        get!().seat_set_simple_im_enabled(self, enabled);
622    }
623
624    /// Returns whether the simple, XCompose based input method is enabled.
625    pub fn simple_im_enabled(self) -> bool {
626        get!(true).seat_get_simple_im_enabled(self)
627    }
628
629    /// Toggles whether the simple, XCompose based input method is enabled.
630    pub fn toggle_simple_im_enabled(self) {
631        let get = get!();
632        get.seat_set_simple_im_enabled(self, !get.seat_get_simple_im_enabled(self));
633    }
634
635    /// Reloads the simple, XCompose based input method.
636    ///
637    /// This is useful if you change the XCompose files after starting the compositor.
638    pub fn reload_simple_im(self) {
639        get!().seat_reload_simple_im(self);
640    }
641
642    /// Enables Unicode input in the simple, XCompose based input method.
643    ///
644    /// This has no effect if the simple IM is not currently active.
645    pub fn enable_unicode_input(self) {
646        get!().seat_enable_unicode_input(self);
647    }
648}
649
650/// A focus-follows-mouse mode.
651#[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
652pub enum FocusFollowsMouseMode {
653    /// When the mouse moves and enters a toplevel, that toplevel gets the keyboard focus.
654    True,
655    /// The keyboard focus changes only when clicking on a window or the previously
656    /// focused window becomes invisible.
657    False,
658}
659
660/// Defines which output is used when no particular output is specified.
661///
662/// This configures where to place a newly opened window or workspace, what window to focus when a
663/// window is closed, which workspace is moved with [`Seat::move_to_output`], and similar actions.
664#[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
665#[non_exhaustive]
666pub enum FallbackOutputMode {
667    /// Use the output the cursor is on.
668    Cursor,
669    /// Use the output the focus is on (highlighted window).
670    Focus,
671}
672
673/// Returns all seats.
674pub fn get_seats() -> Vec<Seat> {
675    get!().seats()
676}
677
678/// Returns all input devices.
679pub fn input_devices() -> Vec<InputDevice> {
680    get!().get_input_devices(None)
681}
682
683/// Returns or creates a seat.
684///
685/// Seats are identified by their name. If no seat with the name exists, a new seat will be created.
686///
687/// NOTE: You should prefer [`get_default_seat`] instead. Most applications cannot handle more than
688/// one seat and will only process input from one of the seats.
689pub fn get_seat(name: &str) -> Seat {
690    get!(Seat(0)).get_seat(name)
691}
692
693/// Returns or creates the default seat.
694///
695/// This is equivalent to `get_seat("default")`.
696pub fn get_default_seat() -> Seat {
697    get_seat(DEFAULT_SEAT_NAME)
698}
699
700/// Sets a closure to run when a new seat has been created.
701pub fn on_new_seat<F: FnMut(Seat) + 'static>(f: F) {
702    get!().on_new_seat(f)
703}
704
705/// Sets a closure to run when a new input device has been added.
706pub fn on_new_input_device<F: FnMut(InputDevice) + 'static>(f: F) {
707    get!().on_new_input_device(f)
708}
709
710/// Sets a closure to run when an input device has been removed.
711pub fn on_input_device_removed<F: FnMut(InputDevice) + 'static>(f: F) {
712    get!().on_input_device_removed(f)
713}
714
715/// Sets the maximum time between two clicks to be registered as a double click by the
716/// compositor.
717///
718/// This only affects interactions with the compositor UI and has no effect on
719/// applications.
720///
721/// The default is 400 ms.
722pub fn set_double_click_time(duration: Duration) {
723    let usec = duration.as_micros().min(u64::MAX as u128);
724    get!().set_double_click_interval(usec as u64)
725}
726
727/// Sets the maximum distance between two clicks to be registered as a double click by the
728/// compositor.
729///
730/// This only affects interactions with the compositor UI and has no effect on
731/// applications.
732///
733/// Setting a negative distance disables double clicks.
734///
735/// The default is 5.
736pub fn set_double_click_distance(distance: i32) {
737    get!().set_double_click_distance(distance)
738}
739
740/// Disables the creation of a default seat.
741///
742/// Unless this function is called at startup of the compositor, a seat called `default`
743/// will automatically be created.
744///
745/// When a new input device is attached and a seat called `default` exists, the input
746/// device is initially attached to this seat.
747pub fn disable_default_seat() {
748    get!().disable_default_seat();
749}
750
751/// An event generated by a switch.
752#[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
753pub enum SwitchEvent {
754    /// The lid of the device (usually a laptop) has been opened.
755    ///
756    /// This is the default state.
757    LidOpened,
758    /// The lid of the device (usually a laptop) has been closed.
759    ///
760    /// If the device is already in this state when the device is discovered, a synthetic
761    /// event of this kind is generated.
762    LidClosed,
763    /// The device has been converted from tablet to laptop mode.
764    ///
765    /// This is the default state.
766    ConvertedToLaptop,
767    /// The device has been converted from laptop to tablet mode.
768    ///
769    /// If the device is already in this state when the device is discovered, a synthetic
770    /// event of this kind is generated.
771    ConvertedToTablet,
772}
773
774/// Enables or disables the unauthenticated libei socket.
775///
776/// Even if the socket is disabled, application can still request access via the portal.
777///
778/// The default is `false`.
779pub fn set_libei_socket_enabled(enabled: bool) {
780    get!().set_ei_socket_enabled(enabled);
781}