Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x11: Set WM_CLASS on windows #1868

Merged
merged 2 commits into from
Jul 10, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ You can find its changes [documented below](#070---2021-01-01).
- x11: Add support for getting and setting clipboard contents ([#1805], [#1851], and [#1866] by [@psychon])
- Linux extension: primary_clipboard ([#1843] by [@Maan2003])
- x11: Implement primary_clipboard ([#1867] by [@psychon])
- x11: Set WM_CLASS property ([#1868] by [@psychon])

### Changed

Expand Down Expand Up @@ -754,6 +755,7 @@ Last release without a changelog :(
[#1865]: https://github.com/linebender/druid/pull/1865
[#1866]: https://github.com/linebender/druid/pull/1866
[#1867]: https://github.com/linebender/druid/pull/1867
[#1868]: https://github.com/linebender/druid/pull/1868

[Unreleased]: https://github.com/linebender/druid/compare/v0.7.0...master
[0.7.0]: https://github.com/linebender/druid/compare/v0.6.0...v0.7.0
Expand Down
36 changes: 36 additions & 0 deletions druid-shell/src/backend/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,42 @@ impl WindowBuilder {
.context("set _NET_WM_PID")?;
}

if let Some(name) = std::env::args_os().next() {
// ICCCM § 4.1.2.5:
// The WM_CLASS property (of type STRING without control characters) contains two
// consecutive null-terminated strings. These specify the Instance and Class names.
//
// The code below just imitates what happens on the gtk backend:
// - instance: The program's name
// - class: The program's name with first letter in upper case

// Get the name of the running binary
let path: &std::path::Path = name.as_ref();
let name = path
.file_name()
.and_then(|name| name.to_str())
.unwrap_or("");

// Build the contents of WM_CLASS
let mut wm_class = Vec::with_capacity(2 * (name.len() + 1));
wm_class.extend(name.as_bytes());
wm_class.push(0);
if let Some(&first) = wm_class.get(0) {
wm_class.push(first.to_ascii_uppercase());
wm_class.extend(&name.as_bytes()[1..]);
}
wm_class.push(0);
conn.change_property8(
PropMode::REPLACE,
id,
AtomEnum::WM_CLASS,
AtomEnum::STRING,
&wm_class,
)?;
} else {
// GTK (actually glib) goes fishing in /proc (platform_get_argv0()). We pass.
}

// Replace the window's WM_PROTOCOLS with the following.
let protocols = [atoms.WM_DELETE_WINDOW];
conn.change_property32(
Expand Down