From d3afc30cebcbc24f633f9eb70cfd3cd0f60571b5 Mon Sep 17 00:00:00 2001 From: Janis Date: Fri, 26 Nov 2021 22:50:47 +0100 Subject: [PATCH] moved backend trait to own file --- src/backends/mod.rs | 33 ++------------------------- src/backends/traits.rs | 51 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 31 deletions(-) create mode 100644 src/backends/traits.rs diff --git a/src/backends/mod.rs b/src/backends/mod.rs index ca6b653..73f4ef0 100644 --- a/src/backends/mod.rs +++ b/src/backends/mod.rs @@ -1,35 +1,6 @@ -use self::window_event::KeyBind; - pub mod keycodes; +pub mod traits; pub mod window_event; pub mod xlib; -pub trait WindowServerBackend { - type Window; - - fn new() -> Self; - - fn next_event(&mut self) -> window_event::WindowEvent; - fn add_keybind(&mut self, keybind: KeyBind, window: Option); - fn remove_keybind( - &mut self, - keybind: KeyBind, - window: Option, - ); - fn add_mousebind(&mut self, keybind: KeyBind, window: Option); - fn remove_mousebind( - &mut self, - keybind: KeyBind, - window: Option, - ); - fn focus_window(&self, window: Self::Window); - fn unfocus_window(&self, window: Self::Window); - fn move_window(&self, window: Self::Window, new_pos: (i32, i32)); - fn resize_window(&self, window: Self::Window, new_size: (i32, i32)); - fn raise_window(&self, window: Self::Window); - fn get_parent_window(&self, window: Self::Window) -> Option; - fn hide_window(&self, window: Self::Window); - fn screen_size(&self) -> (i32, i32); - fn kill_window(&self, window: Self::Window); - fn get_window_size(&self, window: Self::Window) -> Option<(i32, i32)>; -} +pub use traits::*; diff --git a/src/backends/traits.rs b/src/backends/traits.rs new file mode 100644 index 0000000..c13299c --- /dev/null +++ b/src/backends/traits.rs @@ -0,0 +1,51 @@ +use super::{ + window_event, + window_event::{KeyBind, Point}, +}; + +pub trait WindowServerBackend { + type Window; + + fn new() -> Self; + + fn next_event(&mut self) -> window_event::WindowEvent; + fn handle_event(&mut self, event: window_event::WindowEvent); + + fn add_keybind(&mut self, keybind: KeyBind, window: Option); + fn remove_keybind( + &mut self, + keybind: KeyBind, + window: Option, + ); + + fn add_mousebind(&mut self, keybind: KeyBind, window: Option); + fn remove_mousebind( + &mut self, + keybind: KeyBind, + window: Option, + ); + + fn focus_window(&self, window: Self::Window); + fn unfocus_window(&self, window: Self::Window); + fn raise_window(&self, window: Self::Window); + fn hide_window(&self, window: Self::Window); + fn kill_window(&self, window: Self::Window); + fn get_parent_window(&self, window: Self::Window) -> Option; + fn configure_window( + &self, + window: Self::Window, + new_size: Option>, + new_pos: Option>, + ); + + fn screen_size(&self) -> Point; + fn get_window_size(&self, window: Self::Window) -> Option>; + + fn resize_window(&self, window: Self::Window, new_size: Point) { + self.configure_window(window, Some(new_size), None); + } + + fn move_window(&self, window: Self::Window, new_pos: Point) { + self.configure_window(window, None, Some(new_pos)); + } +}