Skip to content

Commit

Permalink
Merge branch 'master' into serde_impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Osspial authored Oct 6, 2018
2 parents e499f5f + 808638f commit d92bc1f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Unreleased

- On Wayland, windows will use server-side decorations when available.
- Added support for F16-F24 keys.
- Fixed graphical glitches when resizing on Wayland.
- On Windows, fix freezes when performing certain actions after a window resize has been triggered. Reintroduces some visual artifacts when resizing.
- Updated window manager hints under X11 to v1.5 of [Extended Window Manager Hints](https://specifications.freedesktop.org/wm-spec/wm-spec-1.5.html#idm140200472629520).
- Added `WindowBuilderExt::with_gtk_theme_variant` to X11-specific `WindowBuilder` functions.
- Fixed UTF8 handling bug in X11 `set_title` function.
- On Windows, `Window::set_cursor` now applies immediately instead of requiring specific events to occur first.
- Add optional `serde` feature with implementations of `Serialize`/`Deserialize` for DPI types, various event types, and `WindowAttributes`.
- Add `PartialEq`, `Eq`, and `Hash` implementations on public types that could have them but were missing them.

Expand Down
8 changes: 8 additions & 0 deletions src/os/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ pub trait WindowBuilderExt {
fn with_override_redirect(self, override_redirect: bool) -> WindowBuilder;
/// Build window with `_NET_WM_WINDOW_TYPE` hint; defaults to `Normal`. Only relevant on X11.
fn with_x11_window_type(self, x11_window_type: XWindowType) -> WindowBuilder;
/// Build window with `_GTK_THEME_VARIANT` hint set to the specified value. Currently only relevant on X11.
fn with_gtk_theme_variant(self, variant: String) -> WindowBuilder;
/// Build window with resize increment hint. Only implemented on X11.
fn with_resize_increments(self, increments: LogicalSize) -> WindowBuilder;
/// Build window with base size hint. Only implemented on X11.
Expand Down Expand Up @@ -269,6 +271,12 @@ impl WindowBuilderExt for WindowBuilder {
self.platform_specific.base_size = Some(base_size.into());
self
}

#[inline]
fn with_gtk_theme_variant(mut self, variant: String) -> WindowBuilder {
self.platform_specific.gtk_theme_variant = Some(variant);
self
}
}

/// Additional methods on `MonitorId` that are specific to Linux.
Expand Down
1 change: 1 addition & 0 deletions src/platform/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct PlatformSpecificWindowBuilderAttributes {
pub class: Option<(String, String)>,
pub override_redirect: bool,
pub x11_window_type: x11::util::WindowType,
pub gtk_theme_variant: Option<String>,
}

lazy_static!(
Expand Down
7 changes: 2 additions & 5 deletions src/platform/linux/wayland/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,10 @@ impl Window {

let window_store = evlp.store.clone();
let my_surface = surface.clone();
let mut frame = SWindow::<BasicFrame>::init(
let mut frame = SWindow::<BasicFrame>::init_from_env(
&evlp.env,
surface.clone(),
(width, height),
&evlp.env.compositor,
&evlp.env.subcompositor,
&evlp.env.shm,
&evlp.env.shell,
move |event, ()| match event {
WEvent::Configure { new_size, .. } => {
let mut store = window_store.lock().unwrap();
Expand Down
19 changes: 18 additions & 1 deletion src/platform/linux/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ impl UnownedWindow {
window.set_window_type(pl_attribs.x11_window_type).queue();
}

if let Some(variant) = pl_attribs.gtk_theme_variant {
window.set_gtk_theme_variant(variant).queue();
}

// set size hints
{
let mut min_dimensions = window_attrs.min_dimensions;
Expand Down Expand Up @@ -457,6 +461,19 @@ impl UnownedWindow {
)
}

fn set_gtk_theme_variant(&self, variant: String) -> util::Flusher {
let hint_atom = unsafe { self.xconn.get_atom_unchecked(b"_GTK_THEME_VARIANT\0") };
let utf8_atom = unsafe { self.xconn.get_atom_unchecked(b"UTF8_STRING\0") };
let variant = CString::new(variant).expect("`_GTK_THEME_VARIANT` contained null byte");
self.xconn.change_property(
self.xwindow,
hint_atom,
utf8_atom,
util::PropMode::Replace,
variant.as_bytes(),
)
}

#[inline]
pub fn set_urgent(&self, is_urgent: bool) {
let mut wm_hints = self.xconn.get_wm_hints(self.xwindow).expect("`XGetWMHints` failed");
Expand Down Expand Up @@ -583,7 +600,7 @@ impl UnownedWindow {
wm_name_atom,
utf8_atom,
util::PropMode::Replace,
title.as_bytes_with_nul(),
title.as_bytes(),
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ unsafe impl Send for PlatformSpecificWindowBuilderAttributes {}
unsafe impl Sync for PlatformSpecificWindowBuilderAttributes {}

// Cursor name in UTF-16. Used to set cursor in `WM_SETCURSOR`.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Copy)]
pub struct Cursor(pub *const winapi::ctypes::wchar_t);
unsafe impl Send for Cursor {}
unsafe impl Sync for Cursor {}
Expand Down
15 changes: 10 additions & 5 deletions src/platform/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ impl Window {

#[inline]
pub fn set_cursor(&self, cursor: MouseCursor) {
let cursor_id = match cursor {
let cursor_id = Cursor(match cursor {
MouseCursor::Arrow | MouseCursor::Default => winuser::IDC_ARROW,
MouseCursor::Hand => winuser::IDC_HAND,
MouseCursor::Crosshair => winuser::IDC_CROSS,
Expand All @@ -321,10 +321,15 @@ impl Window {
MouseCursor::Progress => winuser::IDC_APPSTARTING,
MouseCursor::Help => winuser::IDC_HELP,
_ => winuser::IDC_ARROW, // use arrow for the missing cases.
};

let mut cur = self.window_state.lock().unwrap();
cur.cursor = Cursor(cursor_id);
});
self.window_state.lock().unwrap().cursor = cursor_id;
self.events_loop_proxy.execute_in_thread(move |_| unsafe {
let cursor = winuser::LoadCursorW(
ptr::null_mut(),
cursor_id.0,
);
winuser::SetCursor(cursor);
});
}

unsafe fn cursor_is_grabbed(&self) -> Result<bool, String> {
Expand Down

0 comments on commit d92bc1f

Please sign in to comment.