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    matches!(self, WindowMessageResponse::Request(WindowManagerRequest::DoKeyChar(_)))
48  }
49}
50
51//struct because may add more fields later (so struct is better for code backward compatibility)
52pub struct KeyPress {
53  pub key: char,
54}
55
56impl KeyPress {
57  pub fn is_enter(&self) -> bool {
58    self.key == '𐘂'
59  }
60
61  pub fn is_backspace(&self) -> bool {
62    self.key == '𐘁'
63  }
64
65  pub fn is_escape(&self) -> bool {
66    self.key == '𐘃'
67  }
68
69  pub fn is_up_arrow(&self) -> bool {
70    self.key == '𐙘'
71  }
72
73  pub fn is_down_arrow(&self) -> bool {
74    self.key == '𐘞'
75  }
76
77  pub fn is_left_arrow(&self) -> bool {
78    self.key == '𐙣'
79  }
80
81  pub fn is_right_arrow(&self) -> bool {
82    self.key == '𐙥'
83  }
84
85  pub fn is_arrow(&self) -> bool {
86    self.is_up_arrow() || self.is_down_arrow() || self.is_left_arrow() || self.is_right_arrow()
87  }
88
89  /// Is not enter, backspace, arrow keys (the Linear A stuff)
90  pub fn is_regular(&self) -> bool {
91    !self.is_enter() && !self.is_backspace() && !self.is_escape() && !self.is_arrow()
92  }
93}
94
95#[derive(Clone, Copy, PartialEq)]
96pub enum Direction {
97  Left,
98  Down,
99  Up,
100  Right,
101}
102
103//todo, rename to CommandType
104#[derive(PartialEq)]
105pub enum ShortcutType {
106  StartMenu,
107  SwitchWorkspace(u8),
108  MoveWindowToWorkspace(u8),
109  FocusPrevWindow,
110  FocusNextWindow,
111  QuitWindow,
112  MoveWindow(Direction),
113  MoveWindowToEdge(Direction),
114  ChangeWindowSize(Direction),
115  CenterWindow,
116  FullscreenWindow,
117  HalfWidthWindow, //half width, full height
118  ClipboardCopy,
119  //may not work in \x1E, \x1F or \x1D are in the paste string
120  ClipboardPaste(String),
121  //
122}
123
124pub type WindowsVec = Vec<(usize, String)>;
125
126#[non_exhaustive]
127pub enum InfoType {
128  /// Let taskbar know what the current windows in the workspace are
129  WindowsInWorkspace(WindowsVec, usize), //Vec<(id, name)>, focused id
130  //
131}
132
133pub enum WindowMessage {
134  Init(Dimensions),
135  KeyPress(KeyPress),
136  CtrlKeyPress(KeyPress),
137  Shortcut(ShortcutType),
138  Info(InfoType),
139  Focus,
140  Unfocus,
141  FocusClick,
142  ChangeDimensions(Dimensions),
143  /// For onscreen keyboard only
144  Touch(usize, usize),
145  //
146}
147