1use crate::{atoms::AtomCollection, WmCtlError, WmCtlResult};
2use std::fmt;
3
4#[allow(dead_code)]
6#[derive(Debug, Clone, PartialEq)]
7pub enum Kind {
8 Combo,
9 Desktop,
10 Dialog,
11 DND,
12 Dock,
13 DropDownMenu,
14 Menu,
15 Normal,
16 Notification,
17 PopupMenu,
18 Splash,
19 Toolbar,
20 ToolTip,
21 Utility,
22 Invalid, }
24
25impl Kind {
27 pub fn from(atoms: &AtomCollection, val: u32) -> WmCtlResult<Kind> {
28 if val == atoms._NET_WM_WINDOW_TYPE_COMBO {
29 Ok(Kind::Combo)
30 } else if val == atoms._NET_WM_WINDOW_TYPE_DESKTOP {
31 Ok(Kind::Desktop)
32 } else if val == atoms._NET_WM_WINDOW_TYPE_DIALOG {
33 Ok(Kind::Dialog)
34 } else if val == atoms._NET_WM_WINDOW_TYPE_DND {
35 Ok(Kind::DND)
36 } else if val == atoms._NET_WM_WINDOW_TYPE_DOCK {
37 Ok(Kind::Dock)
38 } else if val == atoms._NET_WM_WINDOW_TYPE_DROPDOWN_MENU {
39 Ok(Kind::DropDownMenu)
40 } else if val == atoms._NET_WM_WINDOW_TYPE_MENU {
41 Ok(Kind::Menu)
42 } else if val == atoms._NET_WM_WINDOW_TYPE_NORMAL {
43 Ok(Kind::Normal)
44 } else if val == atoms._NET_WM_WINDOW_TYPE_NOTIFICATION {
45 Ok(Kind::Notification)
46 } else if val == atoms._NET_WM_WINDOW_TYPE_POPUP_MENU {
47 Ok(Kind::PopupMenu)
48 } else if val == atoms._NET_WM_WINDOW_TYPE_SPLASH {
49 Ok(Kind::Splash)
50 } else if val == atoms._NET_WM_WINDOW_TYPE_TOOLBAR {
51 Ok(Kind::Toolbar)
52 } else if val == atoms._NET_WM_WINDOW_TYPE_TOOLTIP {
53 Ok(Kind::ToolTip)
54 } else if val == atoms._NET_WM_WINDOW_TYPE_UTILITY {
55 Ok(Kind::Utility)
56 } else {
57 Err(WmCtlError::InvalidWinType(val).into())
58 }
59 }
60}
61
62impl fmt::Display for Kind {
64 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
65 match self {
66 Kind::Invalid => write!(f, ""),
67 _ => write!(f, "{}", format!("{:?}", self).to_lowercase()),
68 }
69 }
70}