comparison src/state.rs @ 14:adab13145994

Add support for remote clients.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 02 Nov 2020 00:06:09 +0100
parents 97e543f50f62
children d103f7cca0bd
comparison
equal deleted inserted replaced
13:97e543f50f62 14:adab13145994
13 // 13 //
14 // You should have received a copy of the GNU Affero General Public License 14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <https://www.gnu.org/licenses/>. 15 // along with this program. If not, see <https://www.gnu.org/licenses/>.
16 16
17 use std::fs::File; 17 use std::fs::File;
18 use std::sync::{Arc, Mutex};
19 18
20 use input_linux::{AbsoluteAxis, Key, MiscKind, SynchronizeKind, UInputHandle}; 19 use input_linux::{AbsoluteAxis, Key, MiscKind, SynchronizeKind, UInputHandle};
21 use crate::{DEFAULT_WIDTH, DEFAULT_HEIGHT, MAX_X, MAX_Y}; 20 use crate::{DEFAULT_WIDTH, DEFAULT_HEIGHT, MAX_X, MAX_Y};
22 use crate::uinput::{create_uinput_device, input_axis_new, input_misc_new, input_key_new, input_synchronize_new}; 21 use crate::uinput::{create_uinput_device, input_axis_new, input_misc_new, input_key_new, input_synchronize_new};
23 22
28 selected_tool: Key, 27 selected_tool: Key,
29 pressed: bool, 28 pressed: bool,
30 } 29 }
31 30
32 impl State { 31 impl State {
33 pub fn new() -> std::io::Result<Arc<Mutex<State>>> { 32 pub fn new() -> std::io::Result<State> {
34 let dev = create_uinput_device()?; 33 let dev = create_uinput_device()?;
35 println!( 34 println!(
36 "New device at {:?} ({:?})", 35 "New device at {:?} ({:?})",
37 dev.evdev_path()?, 36 dev.evdev_path()?,
38 dev.sys_path()? 37 dev.sys_path()?
39 ); 38 );
40 39
41 Ok(Arc::new(Mutex::new(State { 40 Ok(State {
42 dev, 41 dev,
43 width: DEFAULT_WIDTH as f64, 42 width: DEFAULT_WIDTH as f64,
44 height: DEFAULT_HEIGHT as f64, 43 height: DEFAULT_HEIGHT as f64,
45 selected_tool: Key::ButtonToolPen, 44 selected_tool: Key::ButtonToolPen,
46 pressed: false, 45 pressed: false,
47 }))) 46 })
48 } 47 }
49 48
50 pub fn set_size(&mut self, (width, height): (u32, u32)) { 49 pub fn set_size(&mut self, (width, height): (u32, u32)) {
51 self.width = width as f64; 50 self.width = width as f64;
52 self.height = height as f64; 51 self.height = height as f64;