Skip to content

Commit d92bc1f

Browse files
authored
Merge branch 'master' into serde_impl
2 parents e499f5f + 808638f commit d92bc1f

File tree

7 files changed

+44
-12
lines changed

7 files changed

+44
-12
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# Unreleased
22

3+
- On Wayland, windows will use server-side decorations when available.
34
- Added support for F16-F24 keys.
45
- Fixed graphical glitches when resizing on Wayland.
56
- On Windows, fix freezes when performing certain actions after a window resize has been triggered. Reintroduces some visual artifacts when resizing.
67
- 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).
8+
- Added `WindowBuilderExt::with_gtk_theme_variant` to X11-specific `WindowBuilder` functions.
9+
- Fixed UTF8 handling bug in X11 `set_title` function.
10+
- On Windows, `Window::set_cursor` now applies immediately instead of requiring specific events to occur first.
711
- Add optional `serde` feature with implementations of `Serialize`/`Deserialize` for DPI types, various event types, and `WindowAttributes`.
812
- Add `PartialEq`, `Eq`, and `Hash` implementations on public types that could have them but were missing them.
913

src/os/unix.rs

+8
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ pub trait WindowBuilderExt {
219219
fn with_override_redirect(self, override_redirect: bool) -> WindowBuilder;
220220
/// Build window with `_NET_WM_WINDOW_TYPE` hint; defaults to `Normal`. Only relevant on X11.
221221
fn with_x11_window_type(self, x11_window_type: XWindowType) -> WindowBuilder;
222+
/// Build window with `_GTK_THEME_VARIANT` hint set to the specified value. Currently only relevant on X11.
223+
fn with_gtk_theme_variant(self, variant: String) -> WindowBuilder;
222224
/// Build window with resize increment hint. Only implemented on X11.
223225
fn with_resize_increments(self, increments: LogicalSize) -> WindowBuilder;
224226
/// Build window with base size hint. Only implemented on X11.
@@ -269,6 +271,12 @@ impl WindowBuilderExt for WindowBuilder {
269271
self.platform_specific.base_size = Some(base_size.into());
270272
self
271273
}
274+
275+
#[inline]
276+
fn with_gtk_theme_variant(mut self, variant: String) -> WindowBuilder {
277+
self.platform_specific.gtk_theme_variant = Some(variant);
278+
self
279+
}
272280
}
273281

274282
/// Additional methods on `MonitorId` that are specific to Linux.

src/platform/linux/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub struct PlatformSpecificWindowBuilderAttributes {
4545
pub class: Option<(String, String)>,
4646
pub override_redirect: bool,
4747
pub x11_window_type: x11::util::WindowType,
48+
pub gtk_theme_variant: Option<String>,
4849
}
4950

5051
lazy_static!(

src/platform/linux/wayland/window.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,10 @@ impl Window {
6969

7070
let window_store = evlp.store.clone();
7171
let my_surface = surface.clone();
72-
let mut frame = SWindow::<BasicFrame>::init(
72+
let mut frame = SWindow::<BasicFrame>::init_from_env(
73+
&evlp.env,
7374
surface.clone(),
7475
(width, height),
75-
&evlp.env.compositor,
76-
&evlp.env.subcompositor,
77-
&evlp.env.shm,
78-
&evlp.env.shell,
7976
move |event, ()| match event {
8077
WEvent::Configure { new_size, .. } => {
8178
let mut store = window_store.lock().unwrap();

src/platform/linux/x11/window.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ impl UnownedWindow {
272272
window.set_window_type(pl_attribs.x11_window_type).queue();
273273
}
274274

275+
if let Some(variant) = pl_attribs.gtk_theme_variant {
276+
window.set_gtk_theme_variant(variant).queue();
277+
}
278+
275279
// set size hints
276280
{
277281
let mut min_dimensions = window_attrs.min_dimensions;
@@ -457,6 +461,19 @@ impl UnownedWindow {
457461
)
458462
}
459463

464+
fn set_gtk_theme_variant(&self, variant: String) -> util::Flusher {
465+
let hint_atom = unsafe { self.xconn.get_atom_unchecked(b"_GTK_THEME_VARIANT\0") };
466+
let utf8_atom = unsafe { self.xconn.get_atom_unchecked(b"UTF8_STRING\0") };
467+
let variant = CString::new(variant).expect("`_GTK_THEME_VARIANT` contained null byte");
468+
self.xconn.change_property(
469+
self.xwindow,
470+
hint_atom,
471+
utf8_atom,
472+
util::PropMode::Replace,
473+
variant.as_bytes(),
474+
)
475+
}
476+
460477
#[inline]
461478
pub fn set_urgent(&self, is_urgent: bool) {
462479
let mut wm_hints = self.xconn.get_wm_hints(self.xwindow).expect("`XGetWMHints` failed");
@@ -583,7 +600,7 @@ impl UnownedWindow {
583600
wm_name_atom,
584601
utf8_atom,
585602
util::PropMode::Replace,
586-
title.as_bytes_with_nul(),
603+
title.as_bytes(),
587604
)
588605
}
589606
}

src/platform/windows/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ unsafe impl Send for PlatformSpecificWindowBuilderAttributes {}
1818
unsafe impl Sync for PlatformSpecificWindowBuilderAttributes {}
1919

2020
// Cursor name in UTF-16. Used to set cursor in `WM_SETCURSOR`.
21-
#[derive(Debug, Clone)]
21+
#[derive(Debug, Clone, Copy)]
2222
pub struct Cursor(pub *const winapi::ctypes::wchar_t);
2323
unsafe impl Send for Cursor {}
2424
unsafe impl Sync for Cursor {}

src/platform/windows/window.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl Window {
301301

302302
#[inline]
303303
pub fn set_cursor(&self, cursor: MouseCursor) {
304-
let cursor_id = match cursor {
304+
let cursor_id = Cursor(match cursor {
305305
MouseCursor::Arrow | MouseCursor::Default => winuser::IDC_ARROW,
306306
MouseCursor::Hand => winuser::IDC_HAND,
307307
MouseCursor::Crosshair => winuser::IDC_CROSS,
@@ -321,10 +321,15 @@ impl Window {
321321
MouseCursor::Progress => winuser::IDC_APPSTARTING,
322322
MouseCursor::Help => winuser::IDC_HELP,
323323
_ => winuser::IDC_ARROW, // use arrow for the missing cases.
324-
};
325-
326-
let mut cur = self.window_state.lock().unwrap();
327-
cur.cursor = Cursor(cursor_id);
324+
});
325+
self.window_state.lock().unwrap().cursor = cursor_id;
326+
self.events_loop_proxy.execute_in_thread(move |_| unsafe {
327+
let cursor = winuser::LoadCursorW(
328+
ptr::null_mut(),
329+
cursor_id.0,
330+
);
331+
winuser::SetCursor(cursor);
332+
});
328333
}
329334

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

0 commit comments

Comments
 (0)