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/api/x11') 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/api/x11') 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