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: implement set_override_redirect #4125

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/changelog/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ changelog entry.
- Added `Window::safe_area`, which describes the area of the surface that is unobstructed.
- On X11, Wayland, Windows and macOS, improved scancode conversions for more obscure key codes.
- Add ability to make non-activating window on macOS using `NSPanel` with `NSWindowStyleMask::NonactivatingPanel`.
- Add ability to set `override_redirect` on X11 windows after creation with `WindowExtX11::set_override_redirect`.
- On Windows, add `IconExtWindows::from_resource_name`.
- Implement `MonitorHandleProvider` for `MonitorHandle` to access common monitor API.

Expand Down
13 changes: 11 additions & 2 deletions src/platform/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,18 @@ impl EventLoopBuilderExtX11 for EventLoopBuilder {
/// Additional methods on [`Window`] that are specific to X11.
///
/// [`Window`]: crate::window::Window
pub trait WindowExtX11 {}
pub trait WindowExtX11 {
/// Modify override-redirect flag.
fn set_override_redirect(&self, value: bool);
}

impl WindowExtX11 for dyn CoreWindow {}
impl WindowExtX11 for dyn CoreWindow {
fn set_override_redirect(&self, value: bool) {
let window =
self.as_any().downcast_ref::<crate::platform_impl::x11::window::Window>().unwrap();
window.set_override_redirect(value);
}
}

/// Additional methods on [`WindowAttributes`] that are specific to X11.
pub trait WindowAttributesExtX11 {
Expand Down
16 changes: 15 additions & 1 deletion src/platform_impl/linux/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use x11rb::properties::{WmHints, WmSizeHints, WmSizeHintsSpecification};
use x11rb::protocol::shape::SK;
use x11rb::protocol::sync::{ConnectionExt as _, Int64};
use x11rb::protocol::xfixes::{ConnectionExt, RegionWrapper};
use x11rb::protocol::xproto::{self, ConnectionExt as _, Rectangle};
use x11rb::protocol::xproto::{self, ChangeWindowAttributesAux, ConnectionExt as _, Rectangle};
use x11rb::protocol::{randr, xinput};

use super::util::{self, SelectedCursor};
Expand Down Expand Up @@ -1827,6 +1827,20 @@ impl UnownedWindow {
}
}

#[inline]
pub fn set_override_redirect(&self, value: bool) {
let mut swa = ChangeWindowAttributesAux::new();
swa.override_redirect = Some(value as u32);
if let Err(err) = self
.xconn
.xcb_connection()
.change_window_attributes(self.xwindow, &swa)
.map(|cookie| cookie.ignore_error())
{
tracing::error!("failed to set override-redirect: {err}");
}
}

#[inline]
pub fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError> {
// We don't support the locked cursor yet, so ignore it early on.
Expand Down