From c923b27caddf6a18aae89a3ed629753638bdceb7 Mon Sep 17 00:00:00 2001 From: Damjan Georgievski Date: Sun, 17 Jan 2016 18:02:40 +0100 Subject: support utf8 window titles via _NET_WM_NAME standard based on this freerdp patch https://github.com/FreeRDP/FreeRDP/commit/9767f7f042a58aae876e0ad3b2e7bde356c8fda9 thanks to emiliocobos on irc --- src/api/x11/window.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs index de9cfb6..e258926 100644 --- a/src/api/x11/window.rs +++ b/src/api/x11/window.rs @@ -672,12 +672,27 @@ impl Window { } pub fn set_title(&self, title: &str) { - with_c_str(title, |title| unsafe { - (self.x.display.xlib.XStoreName)(self.x.display.display, self.x.window, title); + let wm_name = unsafe { + (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.check_errors().expect("Failed to set window title"); - self.x.display.check_errors().expect("Failed to call XStoreName"); } pub fn show(&self) { -- cgit v1.2.3 From e9fc0eeb876fca962b7f4a8a1c55ec42bb27e196 Mon Sep 17 00:00:00 2001 From: Damjan Georgievski Date: Sun, 17 Jan 2016 18:40:31 +0100 Subject: call set_title() in new() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …instead of low-level X11 calls that don't work with utf8 --- src/api/x11/window.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs index e258926..252af75 100644 --- a/src/api/x11/window.rs +++ b/src/api/x11/window.rs @@ -472,10 +472,6 @@ impl Window { display.check_errors().expect("Failed to call XInternAtom"); (display.xlib.XSetWMProtocols)(display.display, window, &mut wm_delete_window, 1); 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.check_errors().expect("Failed to call XFlush"); @@ -639,6 +635,8 @@ impl Window { input_handler: Mutex::new(XInputEventHandler::new(display, window, ic, window_attrs)) }; + window.set_title(&window_attrs.title); + if window_attrs.visible { unsafe { let ref x_window: &XWindow = window.x.borrow(); -- cgit v1.2.3 From 99073eec7b1549ead1a62b67e205a80d02053dba Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Tue, 2 Feb 2016 10:25:26 +0100 Subject: osx: scroll delta should take hidpi factor into account --- src/api/cocoa/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index 138a448..66244d8 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -881,10 +881,13 @@ unsafe fn NSEventToEvent(window: &Window, nsevent: id) -> Option { }, NSScrollWheel => { use events::MouseScrollDelta::{LineDelta, PixelDelta}; + let scale_factor = window.hidpi_factor(); 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 { - 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)) }, -- cgit v1.2.3 From 202f8c5a2dbeaa606f01985a0cf9a972eaf331e9 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Mon, 8 Feb 2016 14:42:44 +0100 Subject: allow non ascii character in ReceivedCharacter --- src/api/cocoa/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index 66244d8..d35182e 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -837,9 +837,7 @@ unsafe fn NSEventToEvent(window: &Window, nsevent: id) -> Option { let received_c_str = nsevent.characters().UTF8String(); let received_str = CStr::from_ptr(received_c_str); 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)); -- cgit v1.2.3 From 982279bc39737af0ba8ee712b744cc3335b001b0 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Sat, 5 Dec 2015 11:54:56 +0100 Subject: Update the emscripten port of glutin --- Cargo.toml | 3 --- examples/support/mod.rs | 4 ++-- src/api/caca/mod.rs | 2 +- src/api/emscripten/mod.rs | 39 +++++++++++++++++++++++++++++++-------- src/api/osmesa/mod.rs | 2 +- src/lib.rs | 2 +- src/platform/emscripten/mod.rs | 11 +++++++++-- src/platform/mod.rs | 5 ++++- 8 files changed, 49 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/Cargo.toml b/Cargo.toml index 95d135e..0c73c6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,9 +19,6 @@ shared_library = "0.1.0" gl_generator = "0.4" khronos_api = "1.0" -[dev-dependencies] -clock_ticks = "0.1.0" - [target.arm-linux-androideabi.dependencies.android_glue] version = "0.1" diff --git a/examples/support/mod.rs b/examples/support/mod.rs index ebbe379..a51ca24 100644 --- a/examples/support/mod.rs +++ b/examples/support/mod.rs @@ -24,11 +24,11 @@ pub fn load(window: &glutin::Window) -> Context { unsafe { 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); 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); let program = gl.CreateProgram(); diff --git a/src/api/caca/mod.rs b/src/api/caca/mod.rs index 687c66f..e73fa6c 100644 --- a/src/api/caca/mod.rs +++ b/src/api/caca/mod.rs @@ -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)] use libc; diff --git a/src/api/emscripten/mod.rs b/src/api/emscripten/mod.rs index 61d8c8c..67f57d1 100644 --- a/src/api/emscripten/mod.rs +++ b/src/api/emscripten/mod.rs @@ -2,11 +2,17 @@ use std::ffi::CString; use libc; -use {Event, BuilderAttribs, CreationError, MouseCursor}; use Api; -use PixelFormat; +use Event; +use CreationError; use ContextError; +use CursorState; +use GlAttributes; use GlContext; +use MouseCursor; +use PixelFormat; +use PixelFormatRequirements; +use WindowAttributes; use std::collections::VecDeque; @@ -52,6 +58,7 @@ impl WindowProxy { } } +#[derive(Clone)] pub struct MonitorId; #[inline] @@ -72,6 +79,11 @@ impl MonitorId { Some("Canvas".to_owned()) } + #[inline] + pub fn get_native_identifier(&self) -> ::native_monitor::NativeMonitorId { + ::native_monitor::NativeMonitorId::Unavailable + } + #[inline] pub fn get_dimensions(&self) -> (u32, u32) { unimplemented!() @@ -79,7 +91,9 @@ impl MonitorId { } impl Window { - pub fn new(builder: BuilderAttribs) -> Result { + pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements, + opengl: &GlAttributes<&Window>) -> Result + { // getting the default values of attributes let mut attributes = unsafe { use std::mem; @@ -198,14 +212,23 @@ impl Window { } #[inline] - pub fn set_cursor(&self, _cursor: MouseCursor) { - unimplemented!() + pub fn set_cursor(&self, cursor: MouseCursor) { + } + + #[inline] + pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> { + Ok(()) } #[inline] pub fn hidpi_factor(&self) -> f32 { 1.0 } + + #[inline] + pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { + Ok(()) + } } impl GlContext for Window { @@ -222,11 +245,11 @@ impl GlContext for Window { } fn get_proc_address(&self, addr: &str) -> *const () { - let addr = CString::new(addr.as_bytes()).unwrap(); - let addr = addr.as_ptr(); + let addr = CString::new(addr).unwrap(); 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 _ } } diff --git a/src/api/osmesa/mod.rs b/src/api/osmesa/mod.rs index 02c43a1..7ef243a 100644 --- a/src/api/osmesa/mod.rs +++ b/src/api/osmesa/mod.rs @@ -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; diff --git a/src/lib.rs b/src/lib.rs index 2bd7fe3..a27aa72 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,7 +54,7 @@ extern crate cocoa; extern crate core_foundation; #[cfg(target_os = "macos")] 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; #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly"))] #[macro_use(wayland_env)] diff --git a/src/platform/emscripten/mod.rs b/src/platform/emscripten/mod.rs index 270cdaf..1a78dfb 100644 --- a/src/platform/emscripten/mod.rs +++ b/src/platform/emscripten/mod.rs @@ -1,7 +1,12 @@ #![cfg(target_os = "emscripten")] +use Api; use ContextError; +use CreationError; +use GlAttributes; use GlContext; +use PixelFormat; +use PixelFormatRequirements; pub use api::emscripten::{Window, WindowProxy, MonitorId, get_available_monitors}; pub use api::emscripten::{get_primary_monitor, WaitEventsIterator, PollEventsIterator}; @@ -11,8 +16,10 @@ pub struct HeadlessContext(Window); impl HeadlessContext { /// See the docs in the crate root file. #[inline] - pub fn new(builder: BuilderAttribs) -> Result { - Window::new(builder).map(|w| HeadlessContext(w)) + pub fn new(_: (u32, u32), _: &PixelFormatRequirements, _: &GlAttributes<&HeadlessContext>) + -> Result + { + unimplemented!() } } diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 4855765..8527da2 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -15,8 +15,11 @@ mod platform; #[cfg(target_os = "ios")] #[path="ios/mod.rs"] 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"), 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; -- cgit v1.2.3