diff options
author | Matias Linares <matiaslina@openmailbox.org> | 2016-09-04 14:01:37 -0300 |
---|---|---|
committer | Matias Linares <matiaslina@openmailbox.org> | 2016-09-04 14:01:37 -0300 |
commit | 5bcdb566c69523edb1ceb857cbf6d0a676cc318d (patch) | |
tree | d3506fee02510999128fdfb5ec6a84ca99c9962b /src/desktop.rs | |
parent | 67306a1f063f15bc8127cdc2f72f971f2d06dd69 (diff) | |
download | dotwm-5bcdb566c69523edb1ceb857cbf6d0a676cc318d.tar.gz |
Add Mouse drag support.
This concludes the first 'release' :p.
Diffstat (limited to 'src/desktop.rs')
-rw-r--r-- | src/desktop.rs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/desktop.rs b/src/desktop.rs index 454c05b..20502e0 100644 --- a/src/desktop.rs +++ b/src/desktop.rs @@ -35,6 +35,7 @@ impl Desktop { self.cw_idx != usize::max_value() } + /// Get the current window focused on this desktop. pub fn current_window(&self) -> Option<&XWindow> { if self.cw_idx < self.window_list.len() { self.window_list.get(self.cw_idx) @@ -43,6 +44,7 @@ impl Desktop { } } + /// Same as `current_window` but getting a mut reference. pub fn current_window_mut(&mut self) -> Option<&mut XWindow> { if self.cw_idx < self.window_list.len() { self.window_list.get_mut(self.cw_idx) @@ -53,11 +55,16 @@ impl Desktop { /// Add a window to the current desktop pub fn add_window(&mut self, w: xlib::Window) { - if self.find_window(w).is_some() { + if self.window_idx(w).is_some() { return; } self.unfocus_current_window(); if let Some(w) = XWindow::new(self.display, w) { + // Throw an event when: + // * We enter a window + // * The window is exposed + // * We move around the window + //w.select_input(xlib::EnterWindowMask | xlib::ExposureMask | xlib::PointerMotionMask); w.select_input(xlib::EnterWindowMask | xlib::ExposureMask); self.window_list.push(w); // Last windows get focus. @@ -100,10 +107,27 @@ impl Desktop { } /// Find a given window and returns it's position on the window_list. - pub fn find_window(&self, w: xlib::Window) -> Option<usize> { + pub fn window_idx(&self, w: xlib::Window) -> Option<usize> { self.window_list.iter().position(|xw| xw.inner == w) } + /// Find a `XWindow` given a `xlib::Window`. + pub fn find_window(&self, w: xlib::Window) -> Option<&XWindow> { + if let Some(idx) = self.window_idx(w) { + self.window_list.get(idx) + } else { + None + } + } + /// Same as `find_window` but returning a mut reference. + pub fn find_window_mut(&mut self, w: xlib::Window) -> Option<&mut XWindow> { + if let Some(idx) = self.window_idx(w) { + self.window_list.get_mut(idx) + } else { + None + } + } + /// Focus the next window. /// /// There're 3 posibilities. There's no window, there's one window or there |