mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 21:31:29 +11:00
Merge branch 'master' of http://github.com/tomaka/gl-init-rs
This commit is contained in:
commit
9238a48ffc
12
Cargo.toml
12
Cargo.toml
|
@ -2,7 +2,7 @@
|
||||||
name = "glutin"
|
name = "glutin"
|
||||||
version = "0.4.7"
|
version = "0.4.7"
|
||||||
authors = ["tomaka <pierre.krieger1708@gmail.com>"]
|
authors = ["tomaka <pierre.krieger1708@gmail.com>"]
|
||||||
description = "Cross-plaform OpenGL context provider."
|
description = "Cross-platform OpenGL context provider."
|
||||||
keywords = ["windowing", "opengl"]
|
keywords = ["windowing", "opengl"]
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -19,9 +19,6 @@ shared_library = "0.1.0"
|
||||||
gl_generator = "0.4"
|
gl_generator = "0.4"
|
||||||
khronos_api = "1.0"
|
khronos_api = "1.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
clock_ticks = "0.1.0"
|
|
||||||
|
|
||||||
[target.arm-linux-androideabi.dependencies.android_glue]
|
[target.arm-linux-androideabi.dependencies.android_glue]
|
||||||
version = "0.1"
|
version = "0.1"
|
||||||
|
|
||||||
|
@ -100,6 +97,13 @@ wayland-kbd = "0.3.3"
|
||||||
wayland-window = "0.2.2"
|
wayland-window = "0.2.2"
|
||||||
x11-dl = "~2.3"
|
x11-dl = "~2.3"
|
||||||
|
|
||||||
|
[target.armv7-unknown-linux-gnueabihf.dependencies]
|
||||||
|
osmesa-sys = "0.0.5"
|
||||||
|
wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] }
|
||||||
|
wayland-kbd = "0.3.3"
|
||||||
|
wayland-window = "0.2.2"
|
||||||
|
x11-dl = "~2.3"
|
||||||
|
|
||||||
[target.aarch64-unknown-linux-gnu.dependencies]
|
[target.aarch64-unknown-linux-gnu.dependencies]
|
||||||
osmesa-sys = "0.0.5"
|
osmesa-sys = "0.0.5"
|
||||||
wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] }
|
wayland-client = { version = "0.5.4", features = ["egl", "dlopen"] }
|
||||||
|
|
|
@ -24,11 +24,11 @@ pub fn load(window: &glutin::Window) -> Context {
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let vs = gl.CreateShader(gl::VERTEX_SHADER);
|
let vs = gl.CreateShader(gl::VERTEX_SHADER);
|
||||||
gl.ShaderSource(vs, 1, [VS_SRC.as_ptr() as *const i8].as_ptr(), ptr::null());
|
gl.ShaderSource(vs, 1, [VS_SRC.as_ptr() as *const _].as_ptr(), ptr::null());
|
||||||
gl.CompileShader(vs);
|
gl.CompileShader(vs);
|
||||||
|
|
||||||
let fs = gl.CreateShader(gl::FRAGMENT_SHADER);
|
let fs = gl.CreateShader(gl::FRAGMENT_SHADER);
|
||||||
gl.ShaderSource(fs, 1, [FS_SRC.as_ptr() as *const i8].as_ptr(), ptr::null());
|
gl.ShaderSource(fs, 1, [FS_SRC.as_ptr() as *const _].as_ptr(), ptr::null());
|
||||||
gl.CompileShader(fs);
|
gl.CompileShader(fs);
|
||||||
|
|
||||||
let program = gl.CreateProgram();
|
let program = gl.CreateProgram();
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![cfg(any(target_os = "linux", target_os = "freebsd"))]
|
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))]
|
||||||
#![allow(unused_variables, dead_code)]
|
#![allow(unused_variables, dead_code)]
|
||||||
|
|
||||||
use libc;
|
use libc;
|
||||||
|
|
|
@ -837,9 +837,7 @@ unsafe fn NSEventToEvent(window: &Window, nsevent: id) -> Option<Event> {
|
||||||
let received_c_str = nsevent.characters().UTF8String();
|
let received_c_str = nsevent.characters().UTF8String();
|
||||||
let received_str = CStr::from_ptr(received_c_str);
|
let received_str = CStr::from_ptr(received_c_str);
|
||||||
for received_char in from_utf8(received_str.to_bytes()).unwrap().chars() {
|
for received_char in from_utf8(received_str.to_bytes()).unwrap().chars() {
|
||||||
if received_char.is_ascii() {
|
events.push_back(ReceivedCharacter(received_char));
|
||||||
events.push_back(ReceivedCharacter(received_char));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let vkey = event::vkeycode_to_element(NSEvent::keyCode(nsevent));
|
let vkey = event::vkeycode_to_element(NSEvent::keyCode(nsevent));
|
||||||
|
@ -881,10 +879,13 @@ unsafe fn NSEventToEvent(window: &Window, nsevent: id) -> Option<Event> {
|
||||||
},
|
},
|
||||||
NSScrollWheel => {
|
NSScrollWheel => {
|
||||||
use events::MouseScrollDelta::{LineDelta, PixelDelta};
|
use events::MouseScrollDelta::{LineDelta, PixelDelta};
|
||||||
|
let scale_factor = window.hidpi_factor();
|
||||||
let delta = if nsevent.hasPreciseScrollingDeltas() == YES {
|
let delta = if nsevent.hasPreciseScrollingDeltas() == YES {
|
||||||
PixelDelta(nsevent.scrollingDeltaX() as f32, nsevent.scrollingDeltaY() as f32)
|
PixelDelta(scale_factor * nsevent.scrollingDeltaX() as f32,
|
||||||
|
scale_factor * nsevent.scrollingDeltaY() as f32)
|
||||||
} else {
|
} else {
|
||||||
LineDelta(nsevent.scrollingDeltaX() as f32, nsevent.scrollingDeltaY() as f32)
|
LineDelta(scale_factor * nsevent.scrollingDeltaX() as f32,
|
||||||
|
scale_factor * nsevent.scrollingDeltaY() as f32)
|
||||||
};
|
};
|
||||||
Some(MouseWheel(delta))
|
Some(MouseWheel(delta))
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,11 +2,17 @@
|
||||||
|
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use libc;
|
use libc;
|
||||||
use {Event, BuilderAttribs, CreationError, MouseCursor};
|
|
||||||
use Api;
|
use Api;
|
||||||
use PixelFormat;
|
use Event;
|
||||||
|
use CreationError;
|
||||||
use ContextError;
|
use ContextError;
|
||||||
|
use CursorState;
|
||||||
|
use GlAttributes;
|
||||||
use GlContext;
|
use GlContext;
|
||||||
|
use MouseCursor;
|
||||||
|
use PixelFormat;
|
||||||
|
use PixelFormatRequirements;
|
||||||
|
use WindowAttributes;
|
||||||
|
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
|
@ -52,6 +58,7 @@ impl WindowProxy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct MonitorId;
|
pub struct MonitorId;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -72,6 +79,11 @@ impl MonitorId {
|
||||||
Some("Canvas".to_owned())
|
Some("Canvas".to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_native_identifier(&self) -> ::native_monitor::NativeMonitorId {
|
||||||
|
::native_monitor::NativeMonitorId::Unavailable
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_dimensions(&self) -> (u32, u32) {
|
pub fn get_dimensions(&self) -> (u32, u32) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
|
@ -79,7 +91,9 @@ impl MonitorId {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
|
pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
|
||||||
|
opengl: &GlAttributes<&Window>) -> Result<Window, CreationError>
|
||||||
|
{
|
||||||
// getting the default values of attributes
|
// getting the default values of attributes
|
||||||
let mut attributes = unsafe {
|
let mut attributes = unsafe {
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
@ -198,14 +212,23 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_cursor(&self, _cursor: MouseCursor) {
|
pub fn set_cursor(&self, cursor: MouseCursor) {
|
||||||
unimplemented!()
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> {
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn hidpi_factor(&self) -> f32 {
|
pub fn hidpi_factor(&self) -> f32 {
|
||||||
1.0
|
1.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlContext for Window {
|
impl GlContext for Window {
|
||||||
|
@ -222,11 +245,11 @@ impl GlContext for Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_proc_address(&self, addr: &str) -> *const () {
|
fn get_proc_address(&self, addr: &str) -> *const () {
|
||||||
let addr = CString::new(addr.as_bytes()).unwrap();
|
let addr = CString::new(addr).unwrap();
|
||||||
let addr = addr.as_ptr();
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::emscripten_GetProcAddress(addr) as *const _
|
// FIXME: if `as_ptr()` is used, then wrong data is passed to emscripten
|
||||||
|
ffi::emscripten_GetProcAddress(addr.into_raw() as *const _) as *const _
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly"))]
|
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))]
|
||||||
|
|
||||||
extern crate osmesa_sys;
|
extern crate osmesa_sys;
|
||||||
|
|
||||||
|
|
|
@ -469,10 +469,6 @@ impl Window {
|
||||||
display.check_errors().expect("Failed to call XInternAtom");
|
display.check_errors().expect("Failed to call XInternAtom");
|
||||||
(display.xlib.XSetWMProtocols)(display.display, window, &mut wm_delete_window, 1);
|
(display.xlib.XSetWMProtocols)(display.display, window, &mut wm_delete_window, 1);
|
||||||
display.check_errors().expect("Failed to call XSetWMProtocols");
|
display.check_errors().expect("Failed to call XSetWMProtocols");
|
||||||
with_c_str(&*window_attrs.title, |title| {;
|
|
||||||
(display.xlib.XStoreName)(display.display, window, title);
|
|
||||||
});
|
|
||||||
display.check_errors().expect("Failed to call XStoreName");
|
|
||||||
(display.xlib.XFlush)(display.display);
|
(display.xlib.XFlush)(display.display);
|
||||||
display.check_errors().expect("Failed to call XFlush");
|
display.check_errors().expect("Failed to call XFlush");
|
||||||
|
|
||||||
|
@ -636,6 +632,8 @@ impl Window {
|
||||||
input_handler: Mutex::new(XInputEventHandler::new(display, window, ic, window_attrs))
|
input_handler: Mutex::new(XInputEventHandler::new(display, window, ic, window_attrs))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
window.set_title(&window_attrs.title);
|
||||||
|
|
||||||
if window_attrs.visible {
|
if window_attrs.visible {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ref x_window: &XWindow = window.x.borrow();
|
let ref x_window: &XWindow = window.x.borrow();
|
||||||
|
@ -669,12 +667,27 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_title(&self, title: &str) {
|
pub fn set_title(&self, title: &str) {
|
||||||
with_c_str(title, |title| unsafe {
|
let wm_name = unsafe {
|
||||||
(self.x.display.xlib.XStoreName)(self.x.display.display, self.x.window, title);
|
(self.x.display.xlib.XInternAtom)(self.x.display.display, b"_NET_WM_NAME\0".as_ptr() as *const _, 0)
|
||||||
|
};
|
||||||
|
self.x.display.check_errors().expect("Failed to call XInternAtom");
|
||||||
|
|
||||||
|
let wm_utf8_string = unsafe {
|
||||||
|
(self.x.display.xlib.XInternAtom)(self.x.display.display, b"UTF8_STRING\0".as_ptr() as *const _, 0)
|
||||||
|
};
|
||||||
|
self.x.display.check_errors().expect("Failed to call XInternAtom");
|
||||||
|
|
||||||
|
with_c_str(title, |c_title| unsafe {
|
||||||
|
(self.x.display.xlib.XStoreName)(self.x.display.display, self.x.window, c_title);
|
||||||
|
|
||||||
|
let len = title.as_bytes().len();
|
||||||
|
(self.x.display.xlib.XChangeProperty)(self.x.display.display, self.x.window,
|
||||||
|
wm_name, wm_utf8_string, 8, ffi::PropModeReplace,
|
||||||
|
c_title as *const u8, len as libc::c_int);
|
||||||
(self.x.display.xlib.XFlush)(self.x.display.display);
|
(self.x.display.xlib.XFlush)(self.x.display.display);
|
||||||
});
|
});
|
||||||
|
self.x.display.check_errors().expect("Failed to set window title");
|
||||||
|
|
||||||
self.x.display.check_errors().expect("Failed to call XStoreName");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show(&self) {
|
pub fn show(&self) {
|
||||||
|
|
|
@ -54,7 +54,7 @@ extern crate cocoa;
|
||||||
extern crate core_foundation;
|
extern crate core_foundation;
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
extern crate core_graphics;
|
extern crate core_graphics;
|
||||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly"))]
|
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))]
|
||||||
extern crate x11_dl;
|
extern crate x11_dl;
|
||||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly"))]
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly"))]
|
||||||
#[macro_use(wayland_env)]
|
#[macro_use(wayland_env)]
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
#![cfg(target_os = "emscripten")]
|
#![cfg(target_os = "emscripten")]
|
||||||
|
|
||||||
|
use Api;
|
||||||
use ContextError;
|
use ContextError;
|
||||||
|
use CreationError;
|
||||||
|
use GlAttributes;
|
||||||
use GlContext;
|
use GlContext;
|
||||||
|
use PixelFormat;
|
||||||
|
use PixelFormatRequirements;
|
||||||
|
|
||||||
pub use api::emscripten::{Window, WindowProxy, MonitorId, get_available_monitors};
|
pub use api::emscripten::{Window, WindowProxy, MonitorId, get_available_monitors};
|
||||||
pub use api::emscripten::{get_primary_monitor, WaitEventsIterator, PollEventsIterator};
|
pub use api::emscripten::{get_primary_monitor, WaitEventsIterator, PollEventsIterator};
|
||||||
|
@ -11,8 +16,10 @@ pub struct HeadlessContext(Window);
|
||||||
impl HeadlessContext {
|
impl HeadlessContext {
|
||||||
/// See the docs in the crate root file.
|
/// See the docs in the crate root file.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> {
|
pub fn new(_: (u32, u32), _: &PixelFormatRequirements, _: &GlAttributes<&HeadlessContext>)
|
||||||
Window::new(builder).map(|w| HeadlessContext(w))
|
-> Result<HeadlessContext, CreationError>
|
||||||
|
{
|
||||||
|
unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,11 @@ mod platform;
|
||||||
#[cfg(target_os = "ios")]
|
#[cfg(target_os = "ios")]
|
||||||
#[path="ios/mod.rs"]
|
#[path="ios/mod.rs"]
|
||||||
mod platform;
|
mod platform;
|
||||||
|
#[cfg(target_os = "emscripten")]
|
||||||
|
#[path="emscripten/mod.rs"]
|
||||||
|
mod platform;
|
||||||
|
|
||||||
#[cfg(all(not(target_os = "ios"), not(target_os = "windows"), not(target_os = "linux"),
|
#[cfg(all(not(target_os = "ios"), not(target_os = "windows"), not(target_os = "linux"),
|
||||||
not(target_os = "macos"), not(target_os = "android"), not(target_os = "dragonfly"),
|
not(target_os = "macos"), not(target_os = "android"), not(target_os = "dragonfly"),
|
||||||
not(target_os = "freebsd")))]
|
not(target_os = "freebsd"), not(target_os = "emscripten")))]
|
||||||
use this_platform_is_not_supported;
|
use this_platform_is_not_supported;
|
||||||
|
|
Loading…
Reference in a new issue