Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ pub struct Platform {

/// When using Wayland, this controls whether to draw the default window decorations.
pub wayland_use_fallback_decorations: bool,

/// Set the `WM_CLASS` window property on X11
// in fact `WM_CLASS` contains two strings "instance name" and "class name"
// for most purposes they are the same so we just use class name for simplicity
// https://unix.stackexchange.com/questions/494169/
pub linux_x11_wm_class: &'static str,
}

impl Default for Platform {
Expand All @@ -158,6 +164,7 @@ impl Default for Platform {
swap_interval: None,
framebuffer_alpha: false,
wayland_use_fallback_decorations: true,
linux_x11_wm_class: "miniquad-application",
}
}
}
Expand Down Expand Up @@ -196,6 +203,8 @@ pub struct Conf {
/// - On macOS, Dock/title bar icon
/// - TODO: Favicon on HTML5
/// - TODO: Taskbar/title bar icon on Linux (depends on WM)
/// - Note: on gnome (with X11), icon is determined using `WM_CLASS` (can be set under
/// `Platform`) and an external `.desktop` file
pub icon: Option<Icon>,

/// Platform-specific hints (e.g., context creation, driver settings).
Expand Down
6 changes: 6 additions & 0 deletions src/native/linux_x11/libx11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,8 @@ pub mod Xresource_h {

pub type XSetWMNormalHints = unsafe extern "C" fn(_: *mut Display, _: Window, _: *mut XSizeHints);
pub type XAllocSizeHints = unsafe extern "C" fn() -> *mut XSizeHints;
pub type XAllocClassHint = unsafe extern "C" fn() -> *mut XClassHint;
pub type XSetClassHint = unsafe extern "C" fn(_: *mut Display, _: Window, _: *mut XClassHint);
pub type Xutf8SetWMProperties = unsafe extern "C" fn(
_: *mut Display,
_: Window,
Expand Down Expand Up @@ -1025,6 +1027,8 @@ pub struct LibX11 {
pub extensions: X11Extensions,
pub XSetWMNormalHints: XSetWMNormalHints,
pub XAllocSizeHints: XAllocSizeHints,
pub XAllocClassHint: XAllocClassHint,
pub XSetClassHint: XSetClassHint,
pub Xutf8SetWMProperties: Xutf8SetWMProperties,
pub XLookupString: XLookupString,
pub XInitThreads: XInitThreads,
Expand Down Expand Up @@ -1080,6 +1084,8 @@ impl LibX11 {
.map(|module| LibX11 {
XSetWMNormalHints: module.get_symbol("XSetWMNormalHints").unwrap(),
XAllocSizeHints: module.get_symbol("XAllocSizeHints").unwrap(),
XAllocClassHint: module.get_symbol("XAllocClassHint").unwrap(),
XSetClassHint: module.get_symbol("XSetClassHint").unwrap(),
Xutf8SetWMProperties: module.get_symbol("Xutf8SetWMProperties").unwrap(),
XLookupString: module.get_symbol("XLookupString").unwrap(),
XInitThreads: module.get_symbol("XInitThreads").unwrap(),
Expand Down
9 changes: 8 additions & 1 deletion src/native/linux_x11/libx11_ex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl LibX11 {
let icons = [
(16, &icon.small[..]),
(32, &icon.medium[..]),
(65, &icon.big[..]),
(64, &icon.big[..]),
];

{
Expand Down Expand Up @@ -234,6 +234,13 @@ impl LibX11 {
(self.XSetWMNormalHints)(display, window, hints);
(self.XFree)(hints as *mut libc::c_void);

let class_hint = (self.XAllocClassHint)();
let wm_class = std::ffi::CString::new(conf.platform.linux_x11_wm_class).unwrap();
(*class_hint).res_name = wm_class.as_ptr() as _;
(*class_hint).res_class = wm_class.as_ptr() as _;
(self.XSetClassHint)(display, window, class_hint);
(self.XFree)(class_hint as *mut libc::c_void);

if let Some(ref icon) = conf.icon {
self.update_window_icon(display, window, icon);
}
Expand Down
Loading