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

Set some more X11 window properties #1097

Merged
merged 2 commits into from
Jul 18, 2020
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ You can find its changes [documented below](#060---2020-06-01).
- Ensure that `update` is called after all commands. ([#1062] by [@jneem])
- X11: Support idle callbacks. ([#1072] by [@jneem])
- GTK: Don't interrupt `KeyEvent.repeat` when releasing another key. ([#1081] by [@raphlinus])
- X11: Set some more common window properties. ([#1097] by [@psychon])
psychon marked this conversation as resolved.
Show resolved Hide resolved

### Visual

Expand Down Expand Up @@ -248,6 +249,7 @@ Last release without a changelog :(
[@ForLoveOfCats]: https://github.com/ForLoveOfCats
[@chris-zen]: https://github.com/chris-zen
[@vkahl]: https://github.com/vkahl
[@psychon]: https://github.com/psychon

[#599]: https://github.com/linebender/druid/pull/599
[#611]: https://github.com/linebender/druid/pull/611
Expand Down Expand Up @@ -359,6 +361,7 @@ Last release without a changelog :(
[#1062]: https://github.com/linebender/druid/pull/1062
[#1072]: https://github.com/linebender/druid/pull/1072
[#1081]: https://github.com/linebender/druid/pull/1081
[#1097]: https://github.com/linebender/druid/pull/1097

[Unreleased]: https://github.com/linebender/druid/compare/v0.6.0...master
[0.6.0]: https://github.com/linebender/druid/compare/v0.5.0...v0.6.0
Expand Down
45 changes: 44 additions & 1 deletion druid-shell/src/platform/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use std::any::Any;
use std::cell::RefCell;
use std::convert::TryInto;
use std::convert::{TryFrom, TryInto};
use std::os::unix::io::RawFd;
use std::rc::{Rc, Weak};
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -274,6 +274,20 @@ impl WindowBuilder {
screen.root_depth,
)?);

// Initialize some properties
let pid = nix::unistd::Pid::this().as_raw();
if let Ok(pid) = u32::try_from(pid) {
conn.change_property32(
xproto::PropMode::Replace,
id,
atoms._NET_WM_PID,
AtomEnum::CARDINAL,
&[pid],
)?
.check()
.context("set _NET_WM_PID")?;
}

let window = Rc::new(Window {
id,
gc,
Expand Down Expand Up @@ -392,10 +406,29 @@ pub(crate) struct Window {
// Registering for but ignoring this event means that the window will remain open.
//
// https://www.x.org/releases/X11R7.6/doc/xorg-docs/specs/ICCCM/icccm.html#window_deletion
//
// _NET_WM_PID
//
// A property containing the PID of the process that created the window.
//
// https://specifications.freedesktop.org/wm-spec/wm-spec-1.3.html#idm45805407915360
//
// _NET_WM_NAME
//
// A version of WM_NAME supporting UTF8 text.
//
// https://specifications.freedesktop.org/wm-spec/wm-spec-1.3.html#idm45805407982336
//
// UTF8_STRING
//
// The type of _NET_WM_NAME
atom_manager! {
WindowAtoms: WindowAtomsCookie {
WM_PROTOCOLS,
WM_DELETE_WINDOW,
_NET_WM_PID,
_NET_WM_NAME,
UTF8_STRING,
}
}

Expand Down Expand Up @@ -685,13 +718,23 @@ impl Window {
}

fn set_title(&self, title: &str) {
// This is technically incorrect. STRING encoding is *not* UTF8. However, I am not sure
// what it really is. WM_LOCALE_NAME might be involved. Hopefully, nothing cares about this
// as long as _NET_WM_NAME is also set (which uses UTF8).
log_x11!(self.app.connection().change_property8(
xproto::PropMode::Replace,
self.id,
AtomEnum::WM_NAME,
AtomEnum::STRING,
title.as_bytes(),
));
log_x11!(self.app.connection().change_property8(
xproto::PropMode::Replace,
self.id,
self.atoms._NET_WM_NAME,
self.atoms.UTF8_STRING,
title.as_bytes(),
));
}

fn set_menu(&self, _menu: Menu) {
Expand Down