summaryrefslogtreecommitdiff
path: root/src/dotwm.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotwm.rs')
-rw-r--r--src/dotwm.rs37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/dotwm.rs b/src/dotwm.rs
index 2d64584..77f09b3 100644
--- a/src/dotwm.rs
+++ b/src/dotwm.rs
@@ -104,14 +104,18 @@ impl DotWM {
}
pub fn add_window(&mut self, w: xlib::Window) {
+ self.unfocus_current_window();
if let Some(w) = XWindow::new(self.display, w) {
+ w.select_input(xlib::EnterWindowMask);
self.window_list.push(w);
// Last windows get focus.
self.cw_idx = self.window_list.len() - 1;
+ self.focus_current_window();
}
}
pub fn current_window(&self) -> Option<&XWindow> {
+ println!("trying to get {} from list of len {}", self.cw_idx, self.window_list.len());
if self.cw_idx < self.window_list.len() {
self.window_list.get(self.cw_idx)
} else {
@@ -121,15 +125,46 @@ impl DotWM {
pub fn remove_window(&mut self, w: xlib::Window) {
let pos = self.window_list.iter().position(|xw| xw.inner == w);
+ println!("Removing widnow {}: pos: {:?}", w, pos);
match pos {
Some(idx) => {
+ let new_idx = if idx == 0 { usize::max_value() } else { idx - 1 };
self.window_list.remove(idx);
- self.cw_idx = usize::max_value();
+ self.cw_idx = new_idx;
+ self.focus_current_window();
},
None => (),
}
}
+
+ pub fn change_focus_of(&mut self, idx: usize) {
+ let w = &self.window_list[idx];
+ self.unfocus_current_window();
+ self.cw_idx = idx;
+ w.set_border_width(1);
+ w.set_border_color("red");
+ w.raise();
+ }
+
+ pub fn find_window(&self, w: xlib::Window) -> Option<usize> {
+ self.window_list.iter().position(|xw| xw.inner == w)
+ }
+
+
+ fn focus_current_window(&self) {
+ if let Some(win) = self.current_window() {
+ win.set_border_width(1);
+ win.set_border_color("red");
+ }
+ }
+
+ fn unfocus_current_window(&self) {
+ if let Some(win) = self.current_window() {
+ win.set_border_width(1);
+ win.set_border_color("black");
+ }
+ }
}
impl Drop for DotWM {