mirror of
https://github.com/rust-windowing/winit.git
synced 2026-09-01 22:30:04 -04:00
Add get_position and get_inner_size for X11
This commit is contained in:
@@ -9,6 +9,7 @@ pub type Bool = libc::c_int;
|
|||||||
pub type Colormap = XID;
|
pub type Colormap = XID;
|
||||||
pub type Cursor = XID;
|
pub type Cursor = XID;
|
||||||
pub type Display = ();
|
pub type Display = ();
|
||||||
|
pub type Drawable = XID; // TODO: not sure
|
||||||
pub type GLXContext = *const ();
|
pub type GLXContext = *const ();
|
||||||
pub type GLXContextID = XID;
|
pub type GLXContextID = XID;
|
||||||
pub type GLXDrawable = XID;
|
pub type GLXDrawable = XID;
|
||||||
@@ -1326,6 +1327,10 @@ extern "C" {
|
|||||||
pub fn XDefaultScreen(display: *mut Display) -> libc::c_int;
|
pub fn XDefaultScreen(display: *mut Display) -> libc::c_int;
|
||||||
pub fn XDestroyWindow(display: *mut Display, w: Window);
|
pub fn XDestroyWindow(display: *mut Display, w: Window);
|
||||||
pub fn XFlush(display: *mut Display);
|
pub fn XFlush(display: *mut Display);
|
||||||
|
pub fn XGetGeometry(display: *mut Display, d: Drawable, root_return: *mut Window,
|
||||||
|
x_return: *mut libc::c_int, y_return: *mut libc::c_int,
|
||||||
|
width_return: *mut libc::c_uint, height_return: *mut libc::c_uint,
|
||||||
|
border_width_return: *mut libc::c_uint, depth_return: *mut libc::c_uint) -> Status;
|
||||||
pub fn XInternAtom(display: *mut Display, atom_name: *const libc::c_char,
|
pub fn XInternAtom(display: *mut Display, atom_name: *const libc::c_char,
|
||||||
only_if_exists: Bool) -> Atom;
|
only_if_exists: Bool) -> Atom;
|
||||||
pub fn XKeycodeToKeysym(display: *mut Display, keycode: KeyCode,
|
pub fn XKeycodeToKeysym(display: *mut Display, keycode: KeyCode,
|
||||||
|
|||||||
@@ -136,8 +136,31 @@ impl Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_geometry(&self) -> Option<(int, int, uint, uint)> {
|
||||||
|
unsafe {
|
||||||
|
use std::mem;
|
||||||
|
|
||||||
|
let mut root: ffi::Window = mem::uninitialized();
|
||||||
|
let mut x: libc::c_int = mem::uninitialized();
|
||||||
|
let mut y: libc::c_int = mem::uninitialized();
|
||||||
|
let mut width: libc::c_uint = mem::uninitialized();
|
||||||
|
let mut height: libc::c_uint = mem::uninitialized();
|
||||||
|
let mut border: libc::c_uint = mem::uninitialized();
|
||||||
|
let mut depth: libc::c_uint = mem::uninitialized();
|
||||||
|
|
||||||
|
if ffi::XGetGeometry(self.display, self.window,
|
||||||
|
&mut root, &mut x, &mut y, &mut width, &mut height,
|
||||||
|
&mut border, &mut depth) == 0
|
||||||
|
{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
Some((x as int, y as int, width as uint, height as uint))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_position(&self) -> Option<(int, int)> {
|
pub fn get_position(&self) -> Option<(int, int)> {
|
||||||
unimplemented!()
|
self.get_geometry().map(|(x, y, _, _)| (x, y))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_position(&self, x: uint, y: uint) {
|
pub fn set_position(&self, x: uint, y: uint) {
|
||||||
@@ -145,7 +168,7 @@ impl Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_inner_size(&self) -> Option<(uint, uint)> {
|
pub fn get_inner_size(&self) -> Option<(uint, uint)> {
|
||||||
unimplemented!()
|
self.get_geometry().map(|(_, _, w, h)| (w, h))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_outer_size(&self) -> Option<(uint, uint)> {
|
pub fn get_outer_size(&self) -> Option<(uint, uint)> {
|
||||||
|
|||||||
Reference in New Issue
Block a user