Remove ExtraData type from XConnection trait

This was being used to pass the X11 atoms all over the place, but I
realize this is no longer necessary - we can just pass them directly to
our RealConnection when creating it.
This commit is contained in:
Shawn Wallace 2025-03-12 00:55:39 -04:00
parent 54a7ad9e13
commit 7df3daba70
5 changed files with 60 additions and 91 deletions

View file

@ -139,11 +139,10 @@ impl SurfaceData {
let window = win_data.window;
output.windows.insert(window);
if self.window.is_some() && state.last_focused_toplevel == self.window {
let data = C::ExtraData::create(state);
let output = self.get_output_name(state);
let conn = state.connection.as_mut().unwrap();
debug!("focused window changed outputs - resetting primary output");
conn.focus_window(window, output, data);
conn.focus_window(window, output);
}
}
}
@ -233,12 +232,11 @@ impl SurfaceData {
states.contains(&(u32::from(xdg_toplevel::State::Fullscreen) as u8));
if toplevel.fullscreen != prev_fs {
let window = state.associated_windows[self.key];
let data = C::ExtraData::create(state);
state.connection.as_mut().unwrap().set_fullscreen(
window,
toplevel.fullscreen,
data,
);
state
.connection
.as_mut()
.unwrap()
.set_fullscreen(window, toplevel.fullscreen);
}
};

View file

@ -5,9 +5,8 @@ mod event;
mod tests;
use self::event::*;
use super::FromServerState;
use crate::clientside::*;
use crate::xstate::{Atoms, WindowDims, WmHints, WmName, WmNormalHints};
use crate::xstate::{WindowDims, WmHints, WmName, WmNormalHints};
use crate::{X11Selection, XConnection};
use log::{debug, warn};
use rustix::event::{poll, PollFd, PollFlags};
@ -475,7 +474,6 @@ struct FocusData {
}
pub struct ServerState<C: XConnection> {
pub atoms: Option<Atoms>,
dh: DisplayHandle,
clientside: ClientState,
objects: ObjectMap,
@ -531,7 +529,6 @@ impl<C: XConnection> ServerState<C> {
windows: HashMap::new(),
clientside,
client: None,
atoms: None,
qh,
dh,
to_focus: None,
@ -862,15 +859,13 @@ impl<C: XConnection> ServerState<C> {
output_name,
}) = self.to_focus.take()
{
let data = C::ExtraData::create(self);
let conn = self.connection.as_mut().unwrap();
debug!("focusing window {window:?}");
conn.focus_window(window, output_name, data);
conn.focus_window(window, output_name);
self.last_focused_toplevel = Some(window);
} else if self.unfocus {
let data = C::ExtraData::create(self);
let conn = self.connection.as_mut().unwrap();
conn.focus_window(x::WINDOW_NONE, None, data);
conn.focus_window(x::WINDOW_NONE, None);
}
self.unfocus = false;
}
@ -1099,8 +1094,7 @@ impl<C: XConnection> ServerState<C> {
fn close_x_window(&mut self, window: x::Window) {
debug!("sending close request to {window:?}");
let data = C::ExtraData::create(self);
self.connection.as_mut().unwrap().close_window(window, data);
self.connection.as_mut().unwrap().close_window(window);
if self.last_focused_toplevel == Some(window) {
self.last_focused_toplevel.take();
}

View file

@ -179,10 +179,6 @@ impl Default for FakeXConnection {
}
}
impl super::FromServerState<FakeXConnection> for () {
fn create(_: &FakeServerState) -> Self {}
}
impl crate::X11Selection for Vec<testwl::PasteData> {
fn mime_types(&self) -> Vec<&str> {
self.iter().map(|data| data.mime_type.as_str()).collect()
@ -205,20 +201,19 @@ impl crate::X11Selection for Vec<testwl::PasteData> {
}
impl super::XConnection for FakeXConnection {
type ExtraData = ();
type X11Selection = Vec<testwl::PasteData>;
fn root_window(&self) -> Window {
self.root
}
#[track_caller]
fn close_window(&mut self, window: Window, _: ()) {
fn close_window(&mut self, window: Window) {
log::debug!("closing window {window:?}");
self.window(window).mapped = false;
}
#[track_caller]
fn set_fullscreen(&mut self, window: xcb::x::Window, fullscreen: bool, _: ()) {
fn set_fullscreen(&mut self, window: xcb::x::Window, fullscreen: bool) {
self.window(window).fullscreen = fullscreen;
}
@ -233,7 +228,7 @@ impl super::XConnection for FakeXConnection {
}
#[track_caller]
fn focus_window(&mut self, window: Window, _output_name: Option<String>, _: ()) {
fn focus_window(&mut self, window: Window, _output_name: Option<String>) {
assert!(
self.windows.contains_key(&window),
"Unknown window: {window:?}"