mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 21:31:29 +11:00
Get the monitors attached to the display, and their resolution for X11
This commit is contained in:
parent
bd3b06e1a5
commit
ac74db979c
|
@ -29,6 +29,7 @@ pub type XrmDatabase = *const (); // TODO: not sure
|
|||
pub type XIC = *mut ();
|
||||
pub type XID = uint;
|
||||
pub type XIM = *mut ();
|
||||
pub type Screen = ();
|
||||
|
||||
pub static AllocNone: libc::c_int = 0;
|
||||
pub static AllocAll: libc::c_int = 1;
|
||||
|
@ -1393,6 +1394,10 @@ extern "C" {
|
|||
pub fn XSetWMProtocols(display: *mut Display, w: Window, protocols: *mut Atom,
|
||||
count: libc::c_int) -> Status;
|
||||
pub fn XStoreName(display: *mut Display, w: Window, window_name: *const libc::c_char);
|
||||
pub fn XScreenCount(display: *mut Display) -> libc::c_int;
|
||||
pub fn XScreenOfDisplay(display: *mut Display, screen_number: libc::c_int) -> *const Screen;
|
||||
pub fn XWidthOfScreen(screen: *const Screen) -> libc::c_int;
|
||||
pub fn XHeightOfScreen(screen: *const Screen) -> libc::c_int;
|
||||
|
||||
pub fn XCloseIM(im: XIM) -> Status;
|
||||
pub fn XOpenIM(display: *mut Display, db: XrmDatabase, res_name: *mut libc::c_char,
|
||||
|
|
|
@ -3,8 +3,11 @@ use libc;
|
|||
use std::{mem, ptr};
|
||||
use std::sync::atomics::AtomicBool;
|
||||
|
||||
pub use self::monitor::{MonitorID, get_available_monitors, get_primary_monitor};
|
||||
|
||||
mod events;
|
||||
mod ffi;
|
||||
mod monitor;
|
||||
|
||||
pub struct Window {
|
||||
display: *mut ffi::Display,
|
||||
|
@ -19,28 +22,6 @@ pub struct Window {
|
|||
is_fullscreen: bool,
|
||||
}
|
||||
|
||||
pub struct MonitorID(uint);
|
||||
|
||||
pub fn get_available_monitors() -> Vec<MonitorID> {
|
||||
vec![get_primary_monitor()]
|
||||
}
|
||||
|
||||
pub fn get_primary_monitor() -> MonitorID {
|
||||
MonitorID(0u)
|
||||
}
|
||||
|
||||
impl MonitorID {
|
||||
pub fn get_name(&self) -> Option<String> {
|
||||
Some("<Unknown>".to_string())
|
||||
}
|
||||
|
||||
pub fn get_dimensions(&self) -> (uint, uint) {
|
||||
//unimplemented!()
|
||||
// TODO: Get the real dimensions from the monitor
|
||||
(1024, 768)
|
||||
}
|
||||
}
|
||||
|
||||
impl Window {
|
||||
pub fn new(builder: WindowBuilder) -> Result<Window, String> {
|
||||
let dimensions = builder.dimensions.unwrap_or((800, 600));
|
||||
|
@ -159,7 +140,7 @@ impl Window {
|
|||
|
||||
// finally creating the window
|
||||
let window = unsafe {
|
||||
let win = ffi::XCreateWindow(display, root, 50, 50, dimensions.val0() as libc::c_uint,
|
||||
let win = ffi::XCreateWindow(display, root, 0, 0, dimensions.val0() as libc::c_uint,
|
||||
dimensions.val1() as libc::c_uint, 0, visual_infos.depth, ffi::InputOutput,
|
||||
visual_infos.visual, window_attributes,
|
||||
&mut set_win_attr);
|
||||
|
|
54
src/x11/monitor.rs
Normal file
54
src/x11/monitor.rs
Normal file
|
@ -0,0 +1,54 @@
|
|||
use std::{ptr};
|
||||
use super::ffi;
|
||||
|
||||
pub struct MonitorID(uint);
|
||||
|
||||
pub fn get_available_monitors() -> Vec<MonitorID> {
|
||||
let nb_monitors = unsafe {
|
||||
let display = ffi::XOpenDisplay(ptr::null());
|
||||
if display.is_null() {
|
||||
fail!("get_available_monitors failed");
|
||||
}
|
||||
let nb_monitors = ffi::XScreenCount(display);
|
||||
ffi::XCloseDisplay(display);
|
||||
nb_monitors
|
||||
};
|
||||
|
||||
let mut vec = Vec::new();
|
||||
vec.grow_fn(nb_monitors as uint, |i| MonitorID(i));
|
||||
vec
|
||||
}
|
||||
|
||||
pub fn get_primary_monitor() -> MonitorID {
|
||||
let primary_monitor = unsafe {
|
||||
let display = ffi::XOpenDisplay(ptr::null());
|
||||
if display.is_null() {
|
||||
fail!("get_available_monitors failed");
|
||||
}
|
||||
let primary_monitor = ffi::XDefaultScreen(display);
|
||||
ffi::XCloseDisplay(display);
|
||||
primary_monitor
|
||||
};
|
||||
|
||||
MonitorID(primary_monitor as uint)
|
||||
}
|
||||
|
||||
impl MonitorID {
|
||||
pub fn get_name(&self) -> Option<String> {
|
||||
Some("<Unknown>".to_string())
|
||||
}
|
||||
|
||||
pub fn get_dimensions(&self) -> (uint, uint) {
|
||||
let dimensions = unsafe {
|
||||
let display = ffi::XOpenDisplay(ptr::null());
|
||||
let MonitorID(screen_num) = *self;
|
||||
let screen = ffi::XScreenOfDisplay(display, screen_num as i32);
|
||||
let width = ffi::XWidthOfScreen(screen);
|
||||
let height = ffi::XHeightOfScreen(screen);
|
||||
(width as uint, height as uint)
|
||||
};
|
||||
|
||||
dimensions
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue