Actions for window source
This commit is contained in:
parent
450e13d655
commit
bfc7510b5e
4 changed files with 73 additions and 18 deletions
22
src/main.rs
22
src/main.rs
|
@ -21,9 +21,9 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
debug!{"Set up roftl"};
|
debug!{"Set up roftl"};
|
||||||
let mut roftl = roftl::Roftl::new()
|
let mut roftl = roftl::Roftl::new()
|
||||||
.add_source(sources::TestSource::new("ts1"))
|
.add_source(sources::TestSource::new("ts1"))
|
||||||
// .add_source(sources::Window::new())
|
.add_source(sources::Window::new())
|
||||||
// .add_source(sources::Apps::new())
|
.add_source(sources::Apps::new())
|
||||||
// .add_source(sources::ShellHost::new())
|
.add_source(sources::ShellHost::new())
|
||||||
.with_matcher(FuseMatcher::new());
|
.with_matcher(FuseMatcher::new());
|
||||||
|
|
||||||
debug!{"Source roftl sources"}
|
debug!{"Source roftl sources"}
|
||||||
|
@ -233,23 +233,23 @@ impl RoftlLoop {
|
||||||
|
|
||||||
fn process_action(&mut self, character: char) -> ControlFlow {
|
fn process_action(&mut self, character: char) -> ControlFlow {
|
||||||
match character {
|
match character {
|
||||||
'0' => {
|
'1' => {
|
||||||
trace!{"Retrieved action selection 0. Trigger primary action"}
|
trace!{"Retrieved action selection 1. Trigger primary action"}
|
||||||
self.roftl.action(self.selection, roftl::Action::Primary);
|
self.roftl.action(self.selection, roftl::Action::Primary);
|
||||||
ControlFlow::Exit
|
ControlFlow::Exit
|
||||||
},
|
},
|
||||||
'1' => {
|
'2' => {
|
||||||
trace!{"Retrieved action selection 1. Trigger secondary action"}
|
trace!{"Retrieved action selection 2. Trigger secondary action"}
|
||||||
self.roftl.action(self.selection, roftl::Action::Secondary);
|
self.roftl.action(self.selection, roftl::Action::Secondary);
|
||||||
ControlFlow::Exit
|
ControlFlow::Exit
|
||||||
},
|
},
|
||||||
'2' => {
|
'3' => {
|
||||||
trace!{"Retrieved action selection 2. Trigger tertiary action"}
|
trace!{"Retrieved action selection 3. Trigger tertiary action"}
|
||||||
self.roftl.action(self.selection, roftl::Action::Tertiary);
|
self.roftl.action(self.selection, roftl::Action::Tertiary);
|
||||||
ControlFlow::Exit
|
ControlFlow::Exit
|
||||||
},
|
},
|
||||||
'3' => {
|
'4' => {
|
||||||
trace!{"Retrieved action selection 2. Trigger quaternary action"}
|
trace!{"Retrieved action selection 4. Trigger quaternary action"}
|
||||||
self.roftl.action(self.selection, roftl::Action::Quaternary);
|
self.roftl.action(self.selection, roftl::Action::Quaternary);
|
||||||
ControlFlow::Exit
|
ControlFlow::Exit
|
||||||
},
|
},
|
||||||
|
|
|
@ -43,7 +43,7 @@ impl Source for TestSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn actions(&self, _entry: &Entry) -> Vec<String> {
|
fn actions(&self, _entry: &Entry) -> Vec<String> {
|
||||||
["Primary", "Secondary", "Ternary"]
|
["Primary", "Secondary", "Tertiary", "Quaternary"]
|
||||||
.iter().map(|s| (*s).into()).collect()
|
.iter().map(|s| (*s).into()).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,33 @@ impl Window {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn toggle_maximize_window(&self, con: &ewmh::Connection, window: u32, screen: i32) -> Result<(), xcb::GenericError> {
|
||||||
|
let max_horz_atom = ewmh::Connection::WM_STATE_MAXIMIZED_HORZ(con);
|
||||||
|
let max_vert_atom = ewmh::Connection::WM_STATE_MAXIMIZED_VERT(con);
|
||||||
|
let action_atom = ewmh::STATE_TOGGLE;
|
||||||
|
|
||||||
|
debug!{"Toggle maximize for {}", window}
|
||||||
|
ewmh::request_change_wm_state(con, screen, window, action_atom, max_horz_atom, max_vert_atom, 0).request_check()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn close_window(&self, con: &ewmh::Connection, window: u32, screen: i32) -> Result<(), xcb::GenericError> {
|
||||||
|
debug!{"Toggle maximize for {}", window}
|
||||||
|
ewmh::request_close_window(con, screen, window, XCB_CURRENT_TIME, 0).request_check()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn toggle_hide_window(&self, con: &ewmh::Connection, window: u32, screen: i32) -> Result<(), xcb::GenericError> {
|
||||||
|
let hidden_atom = ewmh::Connection::WM_STATE_HIDDEN(con);
|
||||||
|
let action_atom = ewmh::STATE_TOGGLE;
|
||||||
|
|
||||||
|
debug!{"Toggle hidden for {}", window}
|
||||||
|
ewmh::request_change_wm_state(con, screen, window, action_atom, hidden_atom, 0, 0).request_check()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Source for Window {
|
impl Source for Window {
|
||||||
|
@ -85,13 +112,41 @@ impl Source for Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn action(&self, entry: &Entry, action: Action) {
|
fn action(&self, entry: &Entry, action: Action) {
|
||||||
println!("Doing action {:?} for entry {}", action, entry.name);
|
debug!("Doing action {:?} for entry {}", action, entry.name);
|
||||||
|
|
||||||
let (window, screen) = *self.action_data.get(&entry.identifier).unwrap();
|
match action {
|
||||||
|
Action::Primary => {
|
||||||
|
let (window, screen) = *self.action_data.get(&entry.identifier).unwrap();
|
||||||
|
let (xcb_conn, _screen_num) = xcb::base::Connection::connect(None).expect("Could not connect to X server");
|
||||||
|
let ewmh_conn = ewmh::Connection::connect(xcb_conn).map_err(|(e,_)| e).unwrap();
|
||||||
|
self.switch_window(&ewmh_conn, window, screen).unwrap()
|
||||||
|
},
|
||||||
|
Action::Secondary => {
|
||||||
|
let (window, screen) = *self.action_data.get(&entry.identifier).unwrap();
|
||||||
|
let (xcb_conn, _screen_num) = xcb::base::Connection::connect(None).expect("Could not connect to X server");
|
||||||
|
let ewmh_conn = ewmh::Connection::connect(xcb_conn).map_err(|(e,_)| e).unwrap();
|
||||||
|
self.toggle_maximize_window(&ewmh_conn, window, screen).unwrap();
|
||||||
|
self.switch_window(&ewmh_conn, window, screen).unwrap()
|
||||||
|
},
|
||||||
|
Action::Tertiary => {
|
||||||
|
let (window, screen) = *self.action_data.get(&entry.identifier).unwrap();
|
||||||
|
let (xcb_conn, _screen_num) = xcb::base::Connection::connect(None).expect("Could not connect to X server");
|
||||||
|
let ewmh_conn = ewmh::Connection::connect(xcb_conn).map_err(|(e,_)| e).unwrap();
|
||||||
|
|
||||||
let (xcb_conn, _screen_num) = xcb::base::Connection::connect(None).expect("Could not connect to X server");
|
self.toggle_hide_window(&ewmh_conn, window, screen).unwrap();
|
||||||
let ewmh_conn = ewmh::Connection::connect(xcb_conn).map_err(|(e,_)| e).unwrap();
|
},
|
||||||
|
Action::Quaternary => {
|
||||||
|
let (window, screen) = *self.action_data.get(&entry.identifier).unwrap();
|
||||||
|
let (xcb_conn, _screen_num) = xcb::base::Connection::connect(None).expect("Could not connect to X server");
|
||||||
|
let ewmh_conn = ewmh::Connection::connect(xcb_conn).map_err(|(e,_)| e).unwrap();
|
||||||
|
|
||||||
self.switch_window(&ewmh_conn, window, screen).unwrap()
|
self.close_window(&ewmh_conn, window, screen).unwrap();
|
||||||
|
},
|
||||||
|
_ => panic!{"Unknown action {:?}", action}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn actions(&self, _entry: &Entry) -> Vec<String> {
|
||||||
|
vec!["Switch".into(), "Toggle maximize".into(), "Toggle hide".into(), "Close".into()]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,7 @@ pub fn draw_actions(window: &Window, actions: Vec<String>)
|
||||||
|
|
||||||
actions.iter().enumerate()
|
actions.iter().enumerate()
|
||||||
.for_each(|(i, r)| {
|
.for_each(|(i, r)| {
|
||||||
painter.result_box(0, 1+(i as u32), &usize::to_string(&i), r, &[], false);
|
painter.result_box(0, 1+(i as u32), &usize::to_string(&(i+1)), r, &[], false);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue