ming_wm_lib/
messages.rs

1use std::boxed::Box;
2use std::vec::Vec;
3
4use crate::framebuffer_types::Dimensions;
5use crate::window_manager_types::{ WindowLike, KeyChar };
6
7/// Window manager internal usage
8pub enum WindowManagerMessage {
9  KeyChar(KeyChar),
10  Touch(usize, usize),
11  //
12}
13
14/// Window manager internal usage
15pub type WindowBox = Box<dyn WindowLike>;
16
17/*
18impl PartialEq for WindowBox {
19  fn eq(&self, _other: &Self) -> bool {
20    //lol
21    true
22  }
23}
24*/
25
26#[derive(Debug, PartialEq)]
27pub enum WindowManagerRequest {
28  OpenWindow(String),
29  //may not work in \x1E, \x1F or \x1D are in the paste string
30  ClipboardCopy(String),
31  CloseStartMenu,
32  Unlock,
33  Lock,
34  DoKeyChar(KeyChar),
35  //
36}
37
38#[derive(PartialEq, Debug)]
39pub enum WindowMessageResponse {
40  Request(WindowManagerRequest),
41  JustRedraw,
42  DoNothing,
43}
44
45impl WindowMessageResponse {
46  pub fn is_key_char_request(&self) -> bool {
47    if let WindowMessageResponse::Request(WindowManagerRequest::DoKeyChar(_)) = self {
48      true
49    } else {
50      false
51    }
52  }
53}
54
55//struct because may add more fields later (so struct is better for code backward compatibility)
56pub struct KeyPress {
57  pub key: char,
58}
59
60impl KeyPress {
61  pub fn is_enter(&self) -> bool {
62    self.key == '𐘂'
63  }
64
65  pub fn is_backspace(&self) -> bool {
66    self.key == '𐘁'
67  }
68
69  pub fn is_escape(&self) -> bool {
70    self.key == '𐘃'
71  }
72
73  pub fn is_up_arrow(&self) -> bool {
74    self.key == '𐙘'
75  }
76
77  pub fn is_down_arrow(&self) -> bool {
78    self.key == '𐘞'
79  }
80
81  pub fn is_left_arrow(&self) -> bool {
82    self.key == '𐙣'
83  }
84
85  pub fn is_right_arrow(&self) -> bool {
86    self.key == '𐙥'
87  }
88
89  pub fn is_arrow(&self) -> bool {
90    self.is_up_arrow() || self.is_down_arrow() || self.is_left_arrow() || self.is_right_arrow()
91  }
92
93  /// Is not enter, backspace, arrow keys (the Linear A stuff)
94  pub fn is_regular(&self) -> bool {
95    !self.is_enter() && !self.is_backspace() && !self.is_escape() && !self.is_arrow()
96  }
97}
98
99#[derive(Clone, Copy, PartialEq)]
100pub enum Direction {
101  Left,
102  Down,
103  Up,
104  Right,
105}
106
107//todo, rename to CommandType
108#[derive(PartialEq)]
109pub enum ShortcutType {
110  StartMenu,
111  SwitchWorkspace(u8),
112  MoveWindowToWorkspace(u8),
113  FocusPrevWindow,
114  FocusNextWindow,
115  QuitWindow,
116  MoveWindow(Direction),
117  MoveWindowToEdge(Direction),
118  ChangeWindowSize(Direction),
119  CenterWindow,
120  FullscreenWindow,
121  HalfWidthWindow, //half width, full height
122  ClipboardCopy,
123  //may not work in \x1E, \x1F or \x1D are in the paste string
124  ClipboardPaste(String),
125  //
126}
127
128pub type WindowsVec = Vec<(usize, String)>;
129
130#[non_exhaustive]
131pub enum InfoType {
132  /// Let taskbar know what the current windows in the workspace are
133  WindowsInWorkspace(WindowsVec, usize), //Vec<(id, name)>, focused id
134  //
135}
136
137pub enum WindowMessage {
138  Init(Dimensions),
139  KeyPress(KeyPress),
140  CtrlKeyPress(KeyPress),
141  Shortcut(ShortcutType),
142  Info(InfoType),
143  Focus,
144  Unfocus,
145  FocusClick,
146  ChangeDimensions(Dimensions),
147  /// For onscreen keyboard only
148  Touch(usize, usize),
149  //
150}
151