diff src/main.rs @ 12:d43c31aff57c

Split uinput helpers into another module.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 01 Nov 2020 16:01:00 +0100
parents 0193041f01d4
children 97e543f50f62
line wrap: on
line diff
--- a/src/main.rs
+++ b/src/main.rs
@@ -19,15 +19,11 @@ use glib::clone;
 use gtk::prelude::*;
 
 use std::env::args;
-use std::fs::{File, OpenOptions};
 use std::io::ErrorKind;
 use std::sync::Arc;
+use input_linux::Key;
 
-use input_linux::{
-    sys::input_event, sys::timeval, AbsoluteAxis, AbsoluteInfo, AbsoluteInfoSetup, EventKind,
-    InputId, InputProperty, Key, MiscKind, SynchronizeKind, UInputHandle,
-};
-
+mod uinput;
 mod state;
 use state::State;
 
@@ -37,180 +33,6 @@ const HEIGHT: i32 = 180;
 const MAX_X: i32 = 69920;
 const MAX_Y: i32 = 39980;
 
-fn create_uinput_device() -> std::io::Result<UInputHandle<File>> {
-    let file = OpenOptions::new().write(true).open("/dev/uinput")?;
-    let dev = UInputHandle::new(file);
-
-    dev.set_evbit(EventKind::Synchronize)?;
-    dev.set_evbit(EventKind::Key)?;
-    dev.set_evbit(EventKind::Absolute)?;
-    dev.set_evbit(EventKind::Misc)?;
-    dev.set_keybit(Key::ButtonToolPen)?;
-    dev.set_keybit(Key::ButtonToolRubber)?;
-    dev.set_keybit(Key::ButtonToolBrush)?;
-    dev.set_keybit(Key::ButtonToolPencil)?;
-    dev.set_keybit(Key::ButtonToolAirbrush)?;
-    dev.set_keybit(Key::ButtonTouch)?;
-    dev.set_keybit(Key::ButtonStylus)?;
-    dev.set_keybit(Key::ButtonStylus2)?;
-    dev.set_keybit(Key::ButtonStylus3)?;
-    dev.set_mscbit(MiscKind::Serial)?;
-    dev.set_propbit(InputProperty::Direct)?;
-
-    dev.set_absbit(AbsoluteAxis::X)?;
-    dev.set_absbit(AbsoluteAxis::Y)?;
-    dev.set_absbit(AbsoluteAxis::Z)?;
-    dev.set_absbit(AbsoluteAxis::Wheel)?;
-    dev.set_absbit(AbsoluteAxis::Pressure)?;
-    dev.set_absbit(AbsoluteAxis::Distance)?;
-    dev.set_absbit(AbsoluteAxis::TiltX)?;
-    dev.set_absbit(AbsoluteAxis::TiltY)?;
-    dev.set_absbit(AbsoluteAxis::Misc)?;
-
-    let id = InputId {
-        bustype: 3,
-        vendor: 0x56a,
-        product: 0x350,
-        version: 0xb,
-    };
-
-    let x = AbsoluteInfoSetup {
-        axis: AbsoluteAxis::X,
-        info: AbsoluteInfo {
-            value: 0,
-            minimum: 0,
-            maximum: MAX_X,
-            fuzz: 0,
-            flat: 0,
-            resolution: 200,
-        },
-    };
-    let y = AbsoluteInfoSetup {
-        axis: AbsoluteAxis::Y,
-        info: AbsoluteInfo {
-            value: 0,
-            minimum: 0,
-            maximum: MAX_Y,
-            fuzz: 0,
-            flat: 0,
-            resolution: 200,
-        },
-    };
-    let z = AbsoluteInfoSetup {
-        axis: AbsoluteAxis::Z,
-        info: AbsoluteInfo {
-            value: 0,
-            minimum: -900,
-            maximum: 899,
-            fuzz: 0,
-            flat: 0,
-            resolution: 287,
-        },
-    };
-    let wheel = AbsoluteInfoSetup {
-        axis: AbsoluteAxis::Wheel,
-        info: AbsoluteInfo {
-            value: 0,
-            minimum: 0,
-            maximum: 2047,
-            fuzz: 0,
-            flat: 0,
-            resolution: 0,
-        },
-    };
-    let pressure = AbsoluteInfoSetup {
-        axis: AbsoluteAxis::Pressure,
-        info: AbsoluteInfo {
-            value: 0,
-            minimum: 0,
-            maximum: 8196,
-            fuzz: 0,
-            flat: 0,
-            resolution: 0,
-        },
-    };
-    let distance = AbsoluteInfoSetup {
-        axis: AbsoluteAxis::Distance,
-        info: AbsoluteInfo {
-            value: 0,
-            minimum: 0,
-            maximum: 63,
-            fuzz: 0,
-            flat: 0,
-            resolution: 0,
-        },
-    };
-    let tilt_x = AbsoluteInfoSetup {
-        axis: AbsoluteAxis::TiltX,
-        info: AbsoluteInfo {
-            value: 0,
-            minimum: -64,
-            maximum: 63,
-            fuzz: 0,
-            flat: 0,
-            resolution: 57,
-        },
-    };
-    let tilt_y = AbsoluteInfoSetup {
-        axis: AbsoluteAxis::TiltY,
-        info: AbsoluteInfo {
-            value: 0,
-            minimum: -64,
-            maximum: 63,
-            fuzz: 0,
-            flat: 0,
-            resolution: 57,
-        },
-    };
-    let misc = AbsoluteInfoSetup {
-        axis: AbsoluteAxis::Misc,
-        info: AbsoluteInfo {
-            value: 0,
-            minimum: 0,
-            maximum: 0,
-            fuzz: 0,
-            flat: 0,
-            resolution: 0,
-        },
-    };
-
-    dev.create(
-        &id,
-        b"TabletEmu",
-        0,
-        &[x, y, z, wheel, pressure, distance, tilt_x, tilt_y, misc],
-    )?;
-    Ok(dev)
-}
-
-fn input_event_new(type_: EventKind, code: u16, value: i32) -> input_event {
-    input_event {
-        time: timeval {
-            tv_sec: 0,
-            tv_usec: 0,
-        },
-        type_: type_ as u16,
-        code,
-        value,
-    }
-}
-
-fn input_axis_new(code: AbsoluteAxis, value: i32) -> input_event {
-    input_event_new(EventKind::Absolute, code as u16, value)
-}
-
-fn input_key_new(code: Key, value: i32) -> input_event {
-    input_event_new(EventKind::Key, code as u16, value)
-}
-
-fn input_misc_new(code: MiscKind, value: i32) -> input_event {
-    input_event_new(EventKind::Misc, code as u16, value)
-}
-
-fn input_synchronize_new(code: SynchronizeKind, value: i32) -> input_event {
-    input_event_new(EventKind::Synchronize, code as u16, value)
-}
-
 fn build_main_menu(application: &gtk::Application) {
     let quit = gio::SimpleAction::new("quit", None);
     application.set_accels_for_action("app.quit", &["<Control>q"]);