mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 06:11:30 +11:00
Merge pull request #65 from glennw/x-threads
Add an interface for providing system wide initialization options to the windowing system.
This commit is contained in:
commit
2c9eaf8651
|
@ -37,6 +37,8 @@ extern crate libc;
|
||||||
extern crate cocoa;
|
extern crate cocoa;
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
extern crate core_foundation;
|
extern crate core_foundation;
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
extern crate sync;
|
||||||
|
|
||||||
pub use events::*;
|
pub use events::*;
|
||||||
|
|
||||||
|
|
|
@ -1410,6 +1410,7 @@ extern "C" {
|
||||||
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 XNextEvent(display: *mut Display, event_return: *mut XEvent);
|
pub fn XNextEvent(display: *mut Display, event_return: *mut XEvent);
|
||||||
|
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;
|
||||||
pub fn XPeekEvent(display: *mut Display, event_return: *mut XEvent);
|
pub fn XPeekEvent(display: *mut Display, event_return: *mut XEvent);
|
||||||
pub fn XRefreshKeyboardMapping(event_map: *const XEvent);
|
pub fn XRefreshKeyboardMapping(event_map: *const XEvent);
|
||||||
|
|
|
@ -3,12 +3,23 @@ use libc;
|
||||||
use std::{mem, ptr};
|
use std::{mem, ptr};
|
||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
use super::ffi;
|
use super::ffi;
|
||||||
|
use sync::one::{Once, ONCE_INIT};
|
||||||
|
|
||||||
pub use self::monitor::{MonitorID, get_available_monitors, get_primary_monitor};
|
pub use self::monitor::{MonitorID, get_available_monitors, get_primary_monitor};
|
||||||
|
|
||||||
mod events;
|
mod events;
|
||||||
mod monitor;
|
mod monitor;
|
||||||
|
|
||||||
|
static THREAD_INIT: Once = ONCE_INIT;
|
||||||
|
|
||||||
|
fn ensure_thread_init() {
|
||||||
|
THREAD_INIT.doit(|| {
|
||||||
|
unsafe {
|
||||||
|
ffi::XInitThreads();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
display: *mut ffi::Display,
|
display: *mut ffi::Display,
|
||||||
window: ffi::Window,
|
window: ffi::Window,
|
||||||
|
@ -24,6 +35,7 @@ pub struct Window {
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(builder: WindowBuilder) -> Result<Window, String> {
|
pub fn new(builder: WindowBuilder) -> Result<Window, String> {
|
||||||
|
ensure_thread_init();
|
||||||
let dimensions = builder.dimensions.unwrap_or((800, 600));
|
let dimensions = builder.dimensions.unwrap_or((800, 600));
|
||||||
|
|
||||||
// calling XOpenDisplay
|
// calling XOpenDisplay
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
use std::{ptr};
|
use std::{ptr};
|
||||||
use super::super::ffi;
|
use super::super::ffi;
|
||||||
|
use super::ensure_thread_init;
|
||||||
|
|
||||||
pub struct MonitorID(pub uint);
|
pub struct MonitorID(pub uint);
|
||||||
|
|
||||||
pub fn get_available_monitors() -> Vec<MonitorID> {
|
pub fn get_available_monitors() -> Vec<MonitorID> {
|
||||||
|
ensure_thread_init();
|
||||||
let nb_monitors = unsafe {
|
let nb_monitors = unsafe {
|
||||||
let display = ffi::XOpenDisplay(ptr::null());
|
let display = ffi::XOpenDisplay(ptr::null());
|
||||||
if display.is_null() {
|
if display.is_null() {
|
||||||
|
@ -20,6 +22,7 @@ pub fn get_available_monitors() -> Vec<MonitorID> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_primary_monitor() -> MonitorID {
|
pub fn get_primary_monitor() -> MonitorID {
|
||||||
|
ensure_thread_init();
|
||||||
let primary_monitor = unsafe {
|
let primary_monitor = unsafe {
|
||||||
let display = ffi::XOpenDisplay(ptr::null());
|
let display = ffi::XOpenDisplay(ptr::null());
|
||||||
if display.is_null() {
|
if display.is_null() {
|
||||||
|
|
Loading…
Reference in a new issue