From 881910f1b313f905d9df2b5ffbdda9e9fc5c97a1 Mon Sep 17 00:00:00 2001 From: Byson94 Date: Thu, 2 Oct 2025 20:48:48 +0530 Subject: [PATCH] GREATEST FEAT: Achived sticky windows in x11 --- crates/ewwii/src/display_backend.rs | 46 ++++++++++++------- .../ewwii/src/widgets/widget_definitions.rs | 1 - 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/crates/ewwii/src/display_backend.rs b/crates/ewwii/src/display_backend.rs index 88c1e74..d84e376 100644 --- a/crates/ewwii/src/display_backend.rs +++ b/crates/ewwii/src/display_backend.rs @@ -173,6 +173,7 @@ mod platform_x11 { use gtk4::gdk; use gtk4::Window; use gtk4::{self, prelude::*}; + use std::rc::Rc; use x11rb::protocol::xproto::ConnectionExt; use x11rb::{ @@ -220,9 +221,9 @@ mod platform_x11 { } struct X11BackendConnection { - conn: RustConnection, + conn: Rc>, root_window: u32, - atoms: AtomCollection, + atoms: Rc, } impl X11BackendConnection { @@ -230,7 +231,11 @@ mod platform_x11 { let (conn, screen_num) = RustConnection::connect(None)?; let screen = conn.setup().roots[screen_num].clone(); let atoms = AtomCollection::new(&conn)?.reply()?; - Ok(X11BackendConnection { conn, root_window: screen.root, atoms }) + Ok(X11BackendConnection { + conn: Rc::new(conn), + root_window: screen.root, + atoms: Rc::new(atoms), + }) } fn set_xprops_for( @@ -321,13 +326,24 @@ mod platform_x11 { .check()?; // apply the stickiness and fg/bg thingy - Self::set_window_states( - &self.conn, - win_id, - &self.atoms, - window_init.backend_options.x11.sticky, - window_init.stacking, - )?; + let sticky_clone = window_init.backend_options.x11.sticky.clone(); + let stacking_clone = window_init.stacking.clone(); + let root_window = self.root_window; + let conn = Rc::clone(&self.conn); + let atoms = Rc::clone(&self.atoms); + + window.connect_show(move |_| { + if let Err(err) = Self::set_window_states( + &*conn, + win_id, + &*atoms, + sticky_clone, + stacking_clone, + root_window, + ) { + log::error!("Failed to set window state: {}", err); + } + }); self.conn.flush().context("Failed to send requests to X server") } @@ -338,6 +354,7 @@ mod platform_x11 { atoms: &AtomCollection, sticky: bool, stacking: WindowStacking, + root_window: u32, ) -> Result<()> { let mut states = Vec::new(); if sticky { @@ -356,15 +373,10 @@ mod platform_x11 { sequence: 0, window: win, type_: atoms._NET_WM_STATE, - data: ClientMessageData::from([state, 0, 0, 0, 0]), + data: ClientMessageData::from([1, state, 0, 0, 0]), }; - conn.send_event( - false, - conn.setup().roots[0].root, - EventMask::SUBSTRUCTURE_REDIRECT | EventMask::SUBSTRUCTURE_NOTIFY, - event, - )?; + conn.send_event(true, root_window, EventMask::PROPERTY_CHANGE, event)?; } conn.flush()?; diff --git a/crates/ewwii/src/widgets/widget_definitions.rs b/crates/ewwii/src/widgets/widget_definitions.rs index 0a96791..6f182cd 100644 --- a/crates/ewwii/src/widgets/widget_definitions.rs +++ b/crates/ewwii/src/widgets/widget_definitions.rs @@ -2299,7 +2299,6 @@ pub(super) fn resolve_range_attrs( // We do this so we can detect if the new value came from a scripted change or from a user input from within the value_changed handler // and only run on_change when it's caused by manual user input if let Ok(value) = get_f64_prop(&props, "value", None) { - println!("{}", range_dat.borrow().is_being_dragged); if !range_dat.borrow().is_being_dragged { range_dat.borrow_mut().last_set_value = Some(value); gtk_widget.set_value(value);