diff options
author | Matias Linares <matiaslina@openmailbox.org> | 2015-11-09 01:33:33 -0300 |
---|---|---|
committer | Matias Linares <matiaslina@openmailbox.org> | 2015-11-09 01:33:33 -0300 |
commit | 05bfd598a060beafe1a20ff759e499987f1ce87b (patch) | |
tree | dba0e6ddc3c8d110ece5bbdd4b3f7f12063eb0a5 /src/dotwm.rs | |
parent | a92f31598c7f5c5be971d643435193c52080b4dc (diff) | |
download | dotwm-05bfd598a060beafe1a20ff759e499987f1ce87b.tar.gz |
Focus handling.
For now this have some bugs. Some complex programs (i.e. thunar, firefox) will spawn
a lot of XCreateEvents and the last window it's not focused correctly.
Also the enter notify should work on an input instead hovering the window
Diffstat (limited to 'src/dotwm.rs')
-rw-r--r-- | src/dotwm.rs | 37 |
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 { |