Add support for with_visibility(), show(), hide() on X11.

This commit is contained in:
Glenn Watson 2014-11-18 10:27:45 +10:00
parent 0dc5086efb
commit c9e1912eb7
2 changed files with 18 additions and 1 deletions

View file

@ -1426,6 +1426,8 @@ extern "C" {
index: libc::c_int) -> KeySym; index: libc::c_int) -> KeySym;
pub fn XMoveWindow(display: *mut Display, w: Window, x: libc::c_int, y: libc::c_int); pub fn XMoveWindow(display: *mut Display, w: Window, x: libc::c_int, y: libc::c_int);
pub fn XMapWindow(display: *mut Display, w: Window); pub fn XMapWindow(display: *mut Display, w: Window);
pub fn XMapRaised(display: *mut Display, w: Window);
pub fn XUnmapWindow(display: *mut Display, w: Window);
pub fn XNextEvent(display: *mut Display, event_return: *mut XEvent); pub fn XNextEvent(display: *mut Display, event_return: *mut XEvent);
pub fn XInitThreads() -> Status; pub fn XInitThreads() -> Status;
pub fn XOpenDisplay(display_name: *const libc::c_char) -> *mut Display; pub fn XOpenDisplay(display_name: *const libc::c_char) -> *mut Display;

View file

@ -163,12 +163,19 @@ impl Window {
win win
}; };
// set visibility
if builder.visible {
unsafe {
ffi::XMapRaised(display, window);
ffi::XFlush(display);
}
}
// creating window, step 2 // creating window, step 2
let wm_delete_window = unsafe { let wm_delete_window = unsafe {
use std::c_str::ToCStr; use std::c_str::ToCStr;
let delete_window = "WM_DELETE_WINDOW".to_c_str(); let delete_window = "WM_DELETE_WINDOW".to_c_str();
ffi::XMapWindow(display, window);
let mut wm_delete_window = ffi::XInternAtom(display, delete_window.as_ptr(), 0); let mut wm_delete_window = ffi::XInternAtom(display, delete_window.as_ptr(), 0);
ffi::XSetWMProtocols(display, window, &mut wm_delete_window, 1); ffi::XSetWMProtocols(display, window, &mut wm_delete_window, 1);
let c_title = builder.title.to_c_str(); let c_title = builder.title.to_c_str();
@ -287,9 +294,17 @@ impl Window {
} }
pub fn show(&self) { pub fn show(&self) {
unsafe {
ffi::XMapRaised(self.display, self.window);
ffi::XFlush(self.display);
}
} }
pub fn hide(&self) { pub fn hide(&self) {
unsafe {
ffi::XUnmapWindow(self.display, self.window);
ffi::XFlush(self.display);
}
} }
fn get_geometry(&self) -> Option<(int, int, uint, uint)> { fn get_geometry(&self) -> Option<(int, int, uint, uint)> {