libwmctl/model/
position.rs1use crate::WmCtlError;
2use std::{convert, fmt};
3
4#[derive(Debug, Clone, PartialEq)]
7pub enum Position {
8 Center,
9 Left,
10 Right,
11 Top,
12 Bottom,
13 TopLeft,
14 TopRight,
15 BottomLeft,
16 BottomRight,
17 LeftCenter,
18 RightCenter,
19 TopCenter,
20 BottomCenter,
21 Static(i32, i32),
22}
23
24impl fmt::Display for Position {
26 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27 match self {
28 _ => write!(f, "{}", format!("{:?}", self).to_lowercase()),
29 }
30 }
31}
32
33impl convert::TryFrom<&str> for Position {
35 type Error = WmCtlError;
36
37 fn try_from(val: &str) -> Result<Self, Self::Error> {
38 match val.to_lowercase().as_ref() {
39 "center" => Ok(Position::Center),
40 "left" => Ok(Position::Left),
41 "right" => Ok(Position::Right),
42 "top" => Ok(Position::Top),
43 "bottom" => Ok(Position::Bottom),
44 "top-left" => Ok(Position::TopLeft),
45 "top-right" => Ok(Position::TopRight),
46 "bottom-left" => Ok(Position::BottomLeft),
47 "bottom-right" => Ok(Position::BottomRight),
48 "left-center" => Ok(Position::LeftCenter),
49 "right-center" => Ok(Position::RightCenter),
50 "top-center" => Ok(Position::TopCenter),
51 "bottom-center" => Ok(Position::BottomCenter),
52 _ => Err(WmCtlError::InvalidWinPosition(val.to_string()).into()),
53 }
54 }
55}
56
57impl convert::TryFrom<String> for Position {
59 type Error = WmCtlError;
60
61 fn try_from(val: String) -> Result<Self, Self::Error> {
62 Position::try_from(val.as_str())
63 }
64}