Skip to content

Commit

Permalink
x11: implement set_override_redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
lunixbochs committed Feb 19, 2025
1 parent c09160d commit 72dc152
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
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`.

### Changed

Expand Down
13 changes: 11 additions & 2 deletions src/platform/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,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 @@ -13,7 +13,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 @@ -1829,6 +1829,20 @@ impl UnownedWindow {
}
}

#[inline]
pub fn set_override_redirect(&self, value: bool) {
let mut swa = ChangeWindowAttributesAux::default();
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

0 comments on commit 72dc152

Please sign in to comment.