Skip to content

Commit

Permalink
native/linux_wayland: Change setting for CSD
Browse files Browse the repository at this point in the history
  • Loading branch information
bolphen authored and not-fl3 committed Mar 5, 2025
1 parent 6cfd67f commit ab67ea5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
24 changes: 20 additions & 4 deletions src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ pub enum WebGLVersion {
WebGL2,
}

/// On Wayland, specify how to draw client-side decoration (CSD) if server-side decoration (SSD) is
/// not supported (e.g., on GNOME).
///
/// Defaults to ServerWithLibDecorFallback
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum WaylandDecorations {
/// If SSD is not supported, will try to load `libdecor` to draw CSD. This is the default
/// choice.
#[default]
ServerWithLibDecorFallback,
/// If SSD is not supported, draw a light gray border.
ServerWithMiniquadFallback,
/// If SSD is not supported, no CSD will be drawn.
ServerOnly,
}

/// Platform-specific settings.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct Platform {
Expand Down Expand Up @@ -143,9 +159,9 @@ pub struct Platform {
/// - TODO: Document(and check) what does it actually mean on android. Transparent window?
pub framebuffer_alpha: bool,

/// On Wayland, the decorations are either drawn by the server or via `libdecor`. If neither is
/// available, then this flag controls whether fallback window decorations should be used.
pub wayland_use_fallback_decorations: bool,
/// On Wayland, specifies how to draw client-side decoration (CSD) if server-side decoration (SSD) is
/// not supported (e.g., on GNOME).
pub wayland_decorations: WaylandDecorations,

/// Set the `WM_CLASS` window property on X11 and the `app_id` on Wayland. This is used
/// by gnome to determine the window icon (together with an external `.desktop` file).
Expand All @@ -165,7 +181,7 @@ impl Default for Platform {
blocking_event_loop: false,
swap_interval: None,
framebuffer_alpha: false,
wayland_use_fallback_decorations: true,
wayland_decorations: WaylandDecorations::default(),
linux_wm_class: "miniquad-application",
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/native/linux_wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,12 +1150,8 @@ where
(libegl.eglGetProcAddress)(name.as_ptr() as _)
});

let borderless = false;
display.decorations = decorations::Decorations::new(
&mut display,
borderless,
conf.platform.wayland_use_fallback_decorations,
);
display.decorations =
decorations::Decorations::new(&mut display, conf.platform.wayland_decorations);
assert!(!display.xdg_toplevel.is_null());

display.decorations.set_title(
Expand Down
30 changes: 17 additions & 13 deletions src/native/linux_wayland/decorations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use extensions::xdg_shell::*;
pub(super) enum Decorations {
None,
Server,
Client {
LibDecor {
libdecor: LibDecor,
context: *mut libdecor,
frame: *mut libdecor_frame,
Expand Down Expand Up @@ -60,14 +60,20 @@ unsafe fn create_xdg_toplevel(display: &mut WaylandPayload) {
}

impl Decorations {
pub(super) fn new(display: &mut WaylandPayload, borderless: bool, use_fallback: bool) -> Self {
pub(super) fn new(
display: &mut WaylandPayload,
fallback: crate::conf::WaylandDecorations,
) -> Self {
use crate::conf::WaylandDecorations::*;
unsafe {
if borderless {
Decorations::none(display)
} else if display.decoration_manager.is_null() {
Decorations::try_client(display, use_fallback)
} else {
if !display.decoration_manager.is_null() {
Decorations::server(display)
} else {
match fallback {
ServerOnly => Decorations::none(display),
ServerWithLibDecorFallback => Decorations::try_libdecor(display),
ServerWithMiniquadFallback => Decorations::fallback(display),
}
}
}
}
Expand All @@ -88,7 +94,7 @@ impl Decorations {
title.as_ptr()
);
}
Decorations::Client {
Decorations::LibDecor {
libdecor, frame, ..
} => {
(libdecor.libdecor_frame_set_title)(*frame, title.as_ptr());
Expand Down Expand Up @@ -134,7 +140,7 @@ impl Decorations {
Decorations::Server
}

unsafe fn try_client(display: &mut WaylandPayload, use_fallback: bool) -> Self {
unsafe fn try_libdecor(display: &mut WaylandPayload) -> Self {
if let Ok(libdecor) = LibDecor::try_load() {
let context = (libdecor.libdecor_new)(display.display, &mut LIBDECOR_INTERFACE as _);
let frame = (libdecor.libdecor_decorate)(
Expand All @@ -145,20 +151,18 @@ impl Decorations {
);
(libdecor.libdecor_frame_map)(frame);
display.xdg_toplevel = (libdecor.libdecor_frame_get_xdg_toplevel)(frame);
Decorations::Client {
Decorations::LibDecor {
libdecor,
context,
frame,
}
} else if use_fallback {
Decorations::fallback(display)
} else {
Decorations::none(display)
}
}

fn libdecor(&mut self) -> Option<&mut LibDecor> {
if let Decorations::Client { libdecor, .. } = self {
if let Decorations::LibDecor { libdecor, .. } = self {
Some(libdecor)
} else {
None
Expand Down

0 comments on commit ab67ea5

Please sign in to comment.