diff options
Diffstat (limited to 'src/safe_x11/window.rs')
-rw-r--r-- | src/safe_x11/window.rs | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/safe_x11/window.rs b/src/safe_x11/window.rs index 8a3bab4..78b73f7 100644 --- a/src/safe_x11/window.rs +++ b/src/safe_x11/window.rs @@ -38,6 +38,7 @@ pub struct XWindow { /// xlib::Window that wraps this struct. pub inner: Window, fullscreen: bool, + prev_attribs: XWindowAttributes, } fn fixed_with_ratio(x: i32, ratio: f32) -> i32 { @@ -51,10 +52,12 @@ impl XWindow { /// `None` if the window is the root window. pub fn new(d: *mut xlib::Display, w: Window) -> Option<XWindow> { if w != 0 { + let attrs: XWindowAttributes = unsafe { uninitialized() }; Some(XWindow { display: d, inner: w, fullscreen: false, + prev_attribs: attrs, }) } else { None @@ -210,30 +213,36 @@ impl XWindow { } /// Fullscreen toggle - pub fn toggle_fullscreen(&mut self, wm_state_atom: Atom, - fs_atom: Atom, fullscreen: bool) { + pub fn fullscreen(&mut self, wm_state_atom: Atom, fs_atom: Atom) { let screen = unsafe { XDefaultScreen(self.display) }; let dh: u32 = unsafe { XDisplayHeight(self.display, screen) as u32 }; let dw: u32 = unsafe { XDisplayWidth(self.display, screen) as u32 }; - if fullscreen != self.fullscreen { - self.fullscreen = fullscreen; - let fs_atom_slice: &[Atom; 1] = &[fs_atom]; - let fs_atom_ptr: *const u8 = unsafe { transmute(fs_atom_slice) }; + if !self.fullscreen { + // First, store the XWindowAttributes to query later. + self.prev_attribs = self.attributes(); - unsafe { - XChangeProperty(self.display, self.inner, wm_state_atom, - XA_ATOM, 32, PropModeReplace, fs_atom_ptr, - fullscreen as i32); - } - } - - if fullscreen { + self.fullscreen = true; self.move_resize(0, 0, dw, dh); self.set_border_width(0); } else { + self.fullscreen = false; + self.move_resize(self.prev_attribs.x, + self.prev_attribs.y, + self.prev_attribs.width as u32, + self.prev_attribs.height as u32); self.set_border_width(1); } + + // EWMH for fullscreen (Don't know how to test it.) + let fs_atom_slice: &[Atom; 1] = &[fs_atom]; + let fs_atom_ptr: *const u8 = unsafe { transmute(fs_atom_slice) }; + + unsafe { + XChangeProperty(self.display, self.inner, wm_state_atom, + XA_ATOM, 32, PropModeReplace, fs_atom_ptr, + self.fullscreen as i32); + } } pub fn map(&self) { |