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:
parent
54a7ad9e13
commit
7df3daba70
5 changed files with 60 additions and 91 deletions
16
src/lib.rs
16
src/lib.rs
|
|
@ -16,27 +16,17 @@ use wayland_server::{Display, ListeningSocket};
|
||||||
use xcb::x;
|
use xcb::x;
|
||||||
|
|
||||||
pub trait XConnection: Sized + 'static {
|
pub trait XConnection: Sized + 'static {
|
||||||
type ExtraData: FromServerState<Self>;
|
|
||||||
type X11Selection: X11Selection;
|
type X11Selection: X11Selection;
|
||||||
|
|
||||||
fn root_window(&self) -> x::Window;
|
fn root_window(&self) -> x::Window;
|
||||||
fn set_window_dims(&mut self, window: x::Window, dims: PendingSurfaceState);
|
fn set_window_dims(&mut self, window: x::Window, dims: PendingSurfaceState);
|
||||||
fn set_fullscreen(&mut self, window: x::Window, fullscreen: bool, data: Self::ExtraData);
|
fn set_fullscreen(&mut self, window: x::Window, fullscreen: bool);
|
||||||
fn focus_window(
|
fn focus_window(&mut self, window: x::Window, output_name: Option<String>);
|
||||||
&mut self,
|
fn close_window(&mut self, window: x::Window);
|
||||||
window: x::Window,
|
|
||||||
output_name: Option<String>,
|
|
||||||
data: Self::ExtraData,
|
|
||||||
);
|
|
||||||
fn close_window(&mut self, window: x::Window, data: Self::ExtraData);
|
|
||||||
fn unmap_window(&mut self, window: x::Window);
|
fn unmap_window(&mut self, window: x::Window);
|
||||||
fn raise_to_top(&mut self, window: x::Window);
|
fn raise_to_top(&mut self, window: x::Window);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FromServerState<C: XConnection> {
|
|
||||||
fn create(state: &ServerState<C>) -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait X11Selection {
|
pub trait X11Selection {
|
||||||
fn mime_types(&self) -> Vec<&str>;
|
fn mime_types(&self) -> Vec<&str>;
|
||||||
fn write_to(&self, mime: &str, pipe: WritePipe);
|
fn write_to(&self, mime: &str, pipe: WritePipe);
|
||||||
|
|
|
||||||
|
|
@ -139,11 +139,10 @@ impl SurfaceData {
|
||||||
let window = win_data.window;
|
let window = win_data.window;
|
||||||
output.windows.insert(window);
|
output.windows.insert(window);
|
||||||
if self.window.is_some() && state.last_focused_toplevel == self.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 output = self.get_output_name(state);
|
||||||
let conn = state.connection.as_mut().unwrap();
|
let conn = state.connection.as_mut().unwrap();
|
||||||
debug!("focused window changed outputs - resetting primary output");
|
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));
|
states.contains(&(u32::from(xdg_toplevel::State::Fullscreen) as u8));
|
||||||
if toplevel.fullscreen != prev_fs {
|
if toplevel.fullscreen != prev_fs {
|
||||||
let window = state.associated_windows[self.key];
|
let window = state.associated_windows[self.key];
|
||||||
let data = C::ExtraData::create(state);
|
state
|
||||||
state.connection.as_mut().unwrap().set_fullscreen(
|
.connection
|
||||||
window,
|
.as_mut()
|
||||||
toplevel.fullscreen,
|
.unwrap()
|
||||||
data,
|
.set_fullscreen(window, toplevel.fullscreen);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,8 @@ mod event;
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
use self::event::*;
|
use self::event::*;
|
||||||
use super::FromServerState;
|
|
||||||
use crate::clientside::*;
|
use crate::clientside::*;
|
||||||
use crate::xstate::{Atoms, WindowDims, WmHints, WmName, WmNormalHints};
|
use crate::xstate::{WindowDims, WmHints, WmName, WmNormalHints};
|
||||||
use crate::{X11Selection, XConnection};
|
use crate::{X11Selection, XConnection};
|
||||||
use log::{debug, warn};
|
use log::{debug, warn};
|
||||||
use rustix::event::{poll, PollFd, PollFlags};
|
use rustix::event::{poll, PollFd, PollFlags};
|
||||||
|
|
@ -475,7 +474,6 @@ struct FocusData {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ServerState<C: XConnection> {
|
pub struct ServerState<C: XConnection> {
|
||||||
pub atoms: Option<Atoms>,
|
|
||||||
dh: DisplayHandle,
|
dh: DisplayHandle,
|
||||||
clientside: ClientState,
|
clientside: ClientState,
|
||||||
objects: ObjectMap,
|
objects: ObjectMap,
|
||||||
|
|
@ -531,7 +529,6 @@ impl<C: XConnection> ServerState<C> {
|
||||||
windows: HashMap::new(),
|
windows: HashMap::new(),
|
||||||
clientside,
|
clientside,
|
||||||
client: None,
|
client: None,
|
||||||
atoms: None,
|
|
||||||
qh,
|
qh,
|
||||||
dh,
|
dh,
|
||||||
to_focus: None,
|
to_focus: None,
|
||||||
|
|
@ -862,15 +859,13 @@ impl<C: XConnection> ServerState<C> {
|
||||||
output_name,
|
output_name,
|
||||||
}) = self.to_focus.take()
|
}) = self.to_focus.take()
|
||||||
{
|
{
|
||||||
let data = C::ExtraData::create(self);
|
|
||||||
let conn = self.connection.as_mut().unwrap();
|
let conn = self.connection.as_mut().unwrap();
|
||||||
debug!("focusing window {window:?}");
|
debug!("focusing window {window:?}");
|
||||||
conn.focus_window(window, output_name, data);
|
conn.focus_window(window, output_name);
|
||||||
self.last_focused_toplevel = Some(window);
|
self.last_focused_toplevel = Some(window);
|
||||||
} else if self.unfocus {
|
} else if self.unfocus {
|
||||||
let data = C::ExtraData::create(self);
|
|
||||||
let conn = self.connection.as_mut().unwrap();
|
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;
|
self.unfocus = false;
|
||||||
}
|
}
|
||||||
|
|
@ -1099,8 +1094,7 @@ impl<C: XConnection> ServerState<C> {
|
||||||
|
|
||||||
fn close_x_window(&mut self, window: x::Window) {
|
fn close_x_window(&mut self, window: x::Window) {
|
||||||
debug!("sending close request to {window:?}");
|
debug!("sending close request to {window:?}");
|
||||||
let data = C::ExtraData::create(self);
|
self.connection.as_mut().unwrap().close_window(window);
|
||||||
self.connection.as_mut().unwrap().close_window(window, data);
|
|
||||||
if self.last_focused_toplevel == Some(window) {
|
if self.last_focused_toplevel == Some(window) {
|
||||||
self.last_focused_toplevel.take();
|
self.last_focused_toplevel.take();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -179,10 +179,6 @@ impl Default for FakeXConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl super::FromServerState<FakeXConnection> for () {
|
|
||||||
fn create(_: &FakeServerState) -> Self {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl crate::X11Selection for Vec<testwl::PasteData> {
|
impl crate::X11Selection for Vec<testwl::PasteData> {
|
||||||
fn mime_types(&self) -> Vec<&str> {
|
fn mime_types(&self) -> Vec<&str> {
|
||||||
self.iter().map(|data| data.mime_type.as_str()).collect()
|
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 {
|
impl super::XConnection for FakeXConnection {
|
||||||
type ExtraData = ();
|
|
||||||
type X11Selection = Vec<testwl::PasteData>;
|
type X11Selection = Vec<testwl::PasteData>;
|
||||||
fn root_window(&self) -> Window {
|
fn root_window(&self) -> Window {
|
||||||
self.root
|
self.root
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn close_window(&mut self, window: Window, _: ()) {
|
fn close_window(&mut self, window: Window) {
|
||||||
log::debug!("closing window {window:?}");
|
log::debug!("closing window {window:?}");
|
||||||
self.window(window).mapped = false;
|
self.window(window).mapped = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[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;
|
self.window(window).fullscreen = fullscreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,7 +228,7 @@ impl super::XConnection for FakeXConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[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!(
|
assert!(
|
||||||
self.windows.contains_key(&window),
|
self.windows.contains_key(&window),
|
||||||
"Unknown window: {window:?}"
|
"Unknown window: {window:?}"
|
||||||
|
|
|
||||||
|
|
@ -209,10 +209,9 @@ impl XState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn server_state_setup(&self, server_state: &mut super::RealServerState) {
|
pub fn server_state_setup(&self, server_state: &mut super::RealServerState) {
|
||||||
let mut c = RealConnection::new(self.connection.clone());
|
let mut c = RealConnection::new(self.connection.clone(), self.atoms.clone());
|
||||||
c.update_outputs(self.root);
|
c.update_outputs(self.root);
|
||||||
server_state.set_x_connection(c);
|
server_state.set_x_connection(c);
|
||||||
server_state.atoms = Some(self.atoms.clone());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_root_property<P: x::PropEl>(&self, property: x::Atom, r#type: x::Atom, data: &[P]) {
|
fn set_root_property<P: x::PropEl>(&self, property: x::Atom, r#type: x::Atom, data: &[P]) {
|
||||||
|
|
@ -359,11 +358,11 @@ impl XState {
|
||||||
let active_win: &[x::Window] = active_win.value();
|
let active_win: &[x::Window] = active_win.value();
|
||||||
if active_win[0] == e.window() {
|
if active_win[0] == e.window() {
|
||||||
// The connection on the server state stores state.
|
// The connection on the server state stores state.
|
||||||
server_state.connection.as_mut().unwrap().focus_window(
|
server_state
|
||||||
x::Window::none(),
|
.connection
|
||||||
None,
|
.as_mut()
|
||||||
self.atoms.clone(),
|
.unwrap()
|
||||||
);
|
.focus_window(x::Window::none(), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
unwrap_or_skip_bad_window_cont!(self.connection.send_and_check_request(
|
unwrap_or_skip_bad_window_cont!(self.connection.send_and_check_request(
|
||||||
|
|
@ -707,28 +706,28 @@ impl XState {
|
||||||
|
|
||||||
xcb::atoms_struct! {
|
xcb::atoms_struct! {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Atoms {
|
struct Atoms {
|
||||||
pub wl_surface_id => b"WL_SURFACE_ID" only_if_exists = false,
|
wl_surface_id => b"WL_SURFACE_ID" only_if_exists = false,
|
||||||
pub wl_surface_serial => b"WL_SURFACE_SERIAL" only_if_exists = false,
|
wl_surface_serial => b"WL_SURFACE_SERIAL" only_if_exists = false,
|
||||||
pub wm_protocols => b"WM_PROTOCOLS" only_if_exists = false,
|
wm_protocols => b"WM_PROTOCOLS" only_if_exists = false,
|
||||||
pub wm_delete_window => b"WM_DELETE_WINDOW" only_if_exists = false,
|
wm_delete_window => b"WM_DELETE_WINDOW" only_if_exists = false,
|
||||||
pub wm_transient_for => b"WM_TRANSIENT_FOR" only_if_exists = false,
|
wm_transient_for => b"WM_TRANSIENT_FOR" only_if_exists = false,
|
||||||
pub wm_check => b"_NET_SUPPORTING_WM_CHECK" only_if_exists = false,
|
wm_check => b"_NET_SUPPORTING_WM_CHECK" only_if_exists = false,
|
||||||
pub net_wm_name => b"_NET_WM_NAME" only_if_exists = false,
|
net_wm_name => b"_NET_WM_NAME" only_if_exists = false,
|
||||||
pub wm_pid => b"_NET_WM_PID" only_if_exists = false,
|
wm_pid => b"_NET_WM_PID" only_if_exists = false,
|
||||||
pub net_wm_state => b"_NET_WM_STATE" only_if_exists = false,
|
net_wm_state => b"_NET_WM_STATE" only_if_exists = false,
|
||||||
pub wm_fullscreen => b"_NET_WM_STATE_FULLSCREEN" only_if_exists = false,
|
wm_fullscreen => b"_NET_WM_STATE_FULLSCREEN" only_if_exists = false,
|
||||||
pub active_win => b"_NET_ACTIVE_WINDOW" only_if_exists = false,
|
active_win => b"_NET_ACTIVE_WINDOW" only_if_exists = false,
|
||||||
pub client_list => b"_NET_CLIENT_LIST" only_if_exists = false,
|
client_list => b"_NET_CLIENT_LIST" only_if_exists = false,
|
||||||
pub supported => b"_NET_SUPPORTED" only_if_exists = false,
|
supported => b"_NET_SUPPORTED" only_if_exists = false,
|
||||||
pub utf8_string => b"UTF8_STRING" only_if_exists = false,
|
utf8_string => b"UTF8_STRING" only_if_exists = false,
|
||||||
pub clipboard => b"CLIPBOARD" only_if_exists = false,
|
clipboard => b"CLIPBOARD" only_if_exists = false,
|
||||||
pub targets => b"TARGETS" only_if_exists = false,
|
targets => b"TARGETS" only_if_exists = false,
|
||||||
pub save_targets => b"SAVE_TARGETS" only_if_exists = false,
|
save_targets => b"SAVE_TARGETS" only_if_exists = false,
|
||||||
pub multiple => b"MULTIPLE" only_if_exists = false,
|
multiple => b"MULTIPLE" only_if_exists = false,
|
||||||
pub timestamp => b"TIMESTAMP" only_if_exists = false,
|
timestamp => b"TIMESTAMP" only_if_exists = false,
|
||||||
pub selection_reply => b"_selection_reply" only_if_exists = false,
|
selection_reply => b"_selection_reply" only_if_exists = false,
|
||||||
pub incr => b"INCR" only_if_exists = false,
|
incr => b"INCR" only_if_exists = false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -840,14 +839,16 @@ impl TryFrom<u32> for SetState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct RealConnection {
|
pub struct RealConnection {
|
||||||
|
atoms: Atoms,
|
||||||
connection: Rc<xcb::Connection>,
|
connection: Rc<xcb::Connection>,
|
||||||
outputs: HashMap<String, xcb::randr::Output>,
|
outputs: HashMap<String, xcb::randr::Output>,
|
||||||
primary_output: xcb::randr::Output,
|
primary_output: xcb::randr::Output,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RealConnection {
|
impl RealConnection {
|
||||||
fn new(connection: Rc<xcb::Connection>) -> Self {
|
fn new(connection: Rc<xcb::Connection>, atoms: Atoms) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
atoms,
|
||||||
connection,
|
connection,
|
||||||
outputs: Default::default(),
|
outputs: Default::default(),
|
||||||
primary_output: Xid::none(),
|
primary_output: Xid::none(),
|
||||||
|
|
@ -896,7 +897,6 @@ impl RealConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XConnection for RealConnection {
|
impl XConnection for RealConnection {
|
||||||
type ExtraData = Atoms;
|
|
||||||
type X11Selection = Selection;
|
type X11Selection = Selection;
|
||||||
|
|
||||||
fn root_window(&self) -> x::Window {
|
fn root_window(&self) -> x::Window {
|
||||||
|
|
@ -916,9 +916,9 @@ impl XConnection for RealConnection {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_fullscreen(&mut self, window: x::Window, fullscreen: bool, atoms: Self::ExtraData) {
|
fn set_fullscreen(&mut self, window: x::Window, fullscreen: bool) {
|
||||||
let data = if fullscreen {
|
let data = if fullscreen {
|
||||||
std::slice::from_ref(&atoms.wm_fullscreen)
|
std::slice::from_ref(&self.atoms.wm_fullscreen)
|
||||||
} else {
|
} else {
|
||||||
&[]
|
&[]
|
||||||
};
|
};
|
||||||
|
|
@ -928,7 +928,7 @@ impl XConnection for RealConnection {
|
||||||
.send_and_check_request(&x::ChangeProperty::<x::Atom> {
|
.send_and_check_request(&x::ChangeProperty::<x::Atom> {
|
||||||
mode: x::PropMode::Replace,
|
mode: x::PropMode::Replace,
|
||||||
window,
|
window,
|
||||||
property: atoms.net_wm_state,
|
property: self.atoms.net_wm_state,
|
||||||
r#type: x::ATOM_ATOM,
|
r#type: x::ATOM_ATOM,
|
||||||
data,
|
data,
|
||||||
})
|
})
|
||||||
|
|
@ -937,12 +937,7 @@ impl XConnection for RealConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn focus_window(
|
fn focus_window(&mut self, window: x::Window, output_name: Option<String>) {
|
||||||
&mut self,
|
|
||||||
window: x::Window,
|
|
||||||
output_name: Option<String>,
|
|
||||||
atoms: Self::ExtraData,
|
|
||||||
) {
|
|
||||||
trace!("{window:?} {output_name:?}");
|
trace!("{window:?} {output_name:?}");
|
||||||
if let Err(e) = self.connection.send_and_check_request(&x::SetInputFocus {
|
if let Err(e) = self.connection.send_and_check_request(&x::SetInputFocus {
|
||||||
focus: window,
|
focus: window,
|
||||||
|
|
@ -955,7 +950,7 @@ impl XConnection for RealConnection {
|
||||||
if let Err(e) = self.connection.send_and_check_request(&x::ChangeProperty {
|
if let Err(e) = self.connection.send_and_check_request(&x::ChangeProperty {
|
||||||
mode: x::PropMode::Replace,
|
mode: x::PropMode::Replace,
|
||||||
window: self.root_window(),
|
window: self.root_window(),
|
||||||
property: atoms.active_win,
|
property: self.atoms.active_win,
|
||||||
r#type: x::ATOM_WINDOW,
|
r#type: x::ATOM_WINDOW,
|
||||||
data: &[window],
|
data: &[window],
|
||||||
}) {
|
}) {
|
||||||
|
|
@ -992,22 +987,25 @@ impl XConnection for RealConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close_window(&mut self, window: x::Window, atoms: Self::ExtraData) {
|
fn close_window(&mut self, window: x::Window) {
|
||||||
let cookie = self.connection.send_request(&x::GetProperty {
|
let cookie = self.connection.send_request(&x::GetProperty {
|
||||||
window,
|
window,
|
||||||
delete: false,
|
delete: false,
|
||||||
property: atoms.wm_protocols,
|
property: self.atoms.wm_protocols,
|
||||||
r#type: x::ATOM_ATOM,
|
r#type: x::ATOM_ATOM,
|
||||||
long_offset: 0,
|
long_offset: 0,
|
||||||
long_length: 10,
|
long_length: 10,
|
||||||
});
|
});
|
||||||
let reply = unwrap_or_skip_bad_window!(self.connection.wait_for_reply(cookie));
|
let reply = unwrap_or_skip_bad_window!(self.connection.wait_for_reply(cookie));
|
||||||
|
|
||||||
if reply.value::<x::Atom>().contains(&atoms.wm_delete_window) {
|
if reply
|
||||||
let data = [atoms.wm_delete_window.resource_id(), 0, 0, 0, 0];
|
.value::<x::Atom>()
|
||||||
|
.contains(&self.atoms.wm_delete_window)
|
||||||
|
{
|
||||||
|
let data = [self.atoms.wm_delete_window.resource_id(), 0, 0, 0, 0];
|
||||||
let event = &x::ClientMessageEvent::new(
|
let event = &x::ClientMessageEvent::new(
|
||||||
window,
|
window,
|
||||||
atoms.wm_protocols,
|
self.atoms.wm_protocols,
|
||||||
x::ClientMessageData::Data32(data),
|
x::ClientMessageData::Data32(data),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -1038,12 +1036,6 @@ impl XConnection for RealConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl super::FromServerState<RealConnection> for Atoms {
|
|
||||||
fn create(state: &super::RealServerState) -> Self {
|
|
||||||
state.atoms.as_ref().unwrap().clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_atom_name(connection: &xcb::Connection, atom: x::Atom) -> String {
|
fn get_atom_name(connection: &xcb::Connection, atom: x::Atom) -> String {
|
||||||
match connection.wait_for_reply(connection.send_request(&x::GetAtomName { atom })) {
|
match connection.wait_for_reply(connection.send_request(&x::GetAtomName { atom })) {
|
||||||
Ok(reply) => reply.name().to_string(),
|
Ok(reply) => reply.name().to_string(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue