diff options
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 |