server: make state's client and connection mandatory
The goal of the previous commits being to remove these unwraps. The `unwrap_or_skip_bad_window` changes needed to make a singular debug conditional
This commit is contained in:
parent
4280639df8
commit
be9d573fd6
5 changed files with 90 additions and 112 deletions
|
|
@ -157,9 +157,8 @@ impl SurfaceEvents {
|
|||
);
|
||||
if state.last_focused_toplevel == Some(*window) {
|
||||
let output = get_output_name(Some(&on_output), &state.world);
|
||||
let conn = connection.as_mut().unwrap();
|
||||
debug!("focused window changed outputs - resetting primary output");
|
||||
conn.focus_window(*window, output);
|
||||
connection.focus_window(*window, output);
|
||||
}
|
||||
|
||||
if state.fractional_scale.is_none() {
|
||||
|
|
@ -205,7 +204,7 @@ impl SurfaceEvents {
|
|||
target: Entity,
|
||||
state: &mut ServerState<C>,
|
||||
) {
|
||||
let connection = state.connection.as_mut().unwrap();
|
||||
let connection = &mut state.connection;
|
||||
let state = &mut state.inner;
|
||||
let xdg_surface::Event::Configure { serial } = event else {
|
||||
unreachable!();
|
||||
|
|
@ -308,7 +307,7 @@ impl SurfaceEvents {
|
|||
toplevel.fullscreen =
|
||||
states.contains(&(u32::from(xdg_toplevel::State::Fullscreen) as u8));
|
||||
if toplevel.fullscreen != prev_fs {
|
||||
state.connection.as_mut().unwrap().set_fullscreen(
|
||||
state.connection.set_fullscreen(
|
||||
*data.get::<&x::Window>().unwrap(),
|
||||
toplevel.fullscreen,
|
||||
);
|
||||
|
|
@ -364,8 +363,6 @@ impl SurfaceEvents {
|
|||
xdg_popup::Event::PopupDone => {
|
||||
state
|
||||
.connection
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.unmap_window(*data.get::<&x::Window>().unwrap());
|
||||
}
|
||||
other => todo!("{other:?}"),
|
||||
|
|
@ -482,7 +479,7 @@ impl Event for client::wl_pointer::Event {
|
|||
let mut do_enter = || {
|
||||
debug!("pointer entering {} ({serial} {})", surface.id(), scale.0);
|
||||
server.enter(serial, surface, surface_x * scale.0, surface_y * scale.0);
|
||||
state.connection.as_mut().unwrap().raise_to_top(*window);
|
||||
state.connection.raise_to_top(*window);
|
||||
if !surface_is_popup {
|
||||
state.inner.last_hovered = Some(*window);
|
||||
}
|
||||
|
|
@ -916,7 +913,7 @@ fn update_window_output_offsets(
|
|||
output: Entity,
|
||||
global_output_offset: &GlobalOutputOffset,
|
||||
world: &World,
|
||||
connection: &mut Option<impl XConnection>,
|
||||
connection: &mut impl XConnection,
|
||||
) {
|
||||
let dimensions = world.get::<&OutputDimensions>(output).unwrap();
|
||||
let mut query = world.query::<(&x::Window, &mut WindowData, &OnOutput)>();
|
||||
|
|
@ -940,7 +937,7 @@ pub(super) fn update_global_output_offset(
|
|||
output: Entity,
|
||||
global_output_offset: &GlobalOutputOffset,
|
||||
world: &World,
|
||||
connection: &mut Option<impl XConnection>,
|
||||
connection: &mut impl XConnection,
|
||||
) {
|
||||
let entity = world.entity(output).unwrap();
|
||||
let mut query = entity.query::<(&OutputDimensions, &WlOutput)>();
|
||||
|
|
@ -1459,8 +1456,6 @@ where
|
|||
let entity = state.world.reserve_entity();
|
||||
let server = state
|
||||
.client
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.create_resource::<_, _, InnerServerState<S>>(&state.dh, 1, entity)
|
||||
.unwrap();
|
||||
let obj_key: &LateInitObjectKey<Client> = client.data().unwrap();
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ impl WindowData {
|
|||
&mut self,
|
||||
window: x::Window,
|
||||
offset: WindowOutputOffset,
|
||||
connection: &mut Option<C>,
|
||||
connection: &mut C,
|
||||
) {
|
||||
log::trace!("offset: {offset:?}");
|
||||
if offset == self.output_offset {
|
||||
|
|
@ -150,19 +150,17 @@ impl WindowData {
|
|||
dims.y += (offset.y - self.output_offset.y) as i16;
|
||||
self.output_offset = offset;
|
||||
|
||||
if let Some(connection) = connection.as_mut() {
|
||||
connection.set_window_dims(
|
||||
window,
|
||||
PendingSurfaceState {
|
||||
x: dims.x as i32,
|
||||
y: dims.y as i32,
|
||||
width: self.attrs.dims.width as _,
|
||||
height: self.attrs.dims.height as _,
|
||||
},
|
||||
);
|
||||
if connection.set_window_dims(
|
||||
window,
|
||||
PendingSurfaceState {
|
||||
x: dims.x as i32,
|
||||
y: dims.y as i32,
|
||||
width: self.attrs.dims.width as _,
|
||||
height: self.attrs.dims.height as _,
|
||||
},
|
||||
) {
|
||||
debug!("set {:?} offset to {:?}", window, self.output_offset);
|
||||
}
|
||||
|
||||
debug!("set {:?} offset to {:?}", window, self.output_offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -415,14 +413,15 @@ impl<S: X11Selection> XConnection for EarlyConnection<S> {
|
|||
fn set_fullscreen(&mut self, _: x::Window, _: bool) {
|
||||
debug!("could not toggle fullscreen without XWayland initialized");
|
||||
}
|
||||
fn set_window_dims(&mut self, _: x::Window, _: crate::server::PendingSurfaceState) {
|
||||
fn set_window_dims(&mut self, _: x::Window, _: crate::server::PendingSurfaceState) -> bool {
|
||||
debug!("could not set window dimensions without XWayland initialized");
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ServerState<C: XConnection> {
|
||||
inner: InnerServerState<C::X11Selection>,
|
||||
pub connection: Option<C>,
|
||||
pub connection: C,
|
||||
}
|
||||
|
||||
pub struct InnerServerState<S: X11Selection> {
|
||||
|
|
@ -433,7 +432,7 @@ pub struct InnerServerState<S: X11Selection> {
|
|||
world: MyWorld,
|
||||
queue: EventQueue<MyWorld>,
|
||||
qh: QueueHandle<MyWorld>,
|
||||
client: Option<Client>,
|
||||
client: Client,
|
||||
to_focus: Option<FocusData>,
|
||||
unfocus: bool,
|
||||
last_focused_toplevel: Option<x::Window>,
|
||||
|
|
@ -453,7 +452,11 @@ pub struct InnerServerState<S: X11Selection> {
|
|||
}
|
||||
|
||||
impl<S: X11Selection> ServerState<EarlyConnection<S>> {
|
||||
pub fn new(dh: DisplayHandle, server_connection: Option<UnixStream>) -> Self {
|
||||
pub fn new(
|
||||
mut dh: DisplayHandle,
|
||||
server_connection: Option<UnixStream>,
|
||||
client: UnixStream,
|
||||
) -> Self {
|
||||
let connection = if let Some(stream) = server_connection {
|
||||
Connection::from_socket(stream).unwrap()
|
||||
} else {
|
||||
|
|
@ -508,10 +511,12 @@ impl<S: X11Selection> ServerState<EarlyConnection<S>> {
|
|||
.contents()
|
||||
.with_list(|globals| handle_globals::<S>(&dh, globals));
|
||||
|
||||
let client = dh.insert_client(client, std::sync::Arc::new(())).unwrap();
|
||||
|
||||
let inner = InnerServerState {
|
||||
windows: HashMap::new(),
|
||||
pids: HashSet::new(),
|
||||
client: None,
|
||||
client,
|
||||
queue,
|
||||
qh,
|
||||
dh,
|
||||
|
|
@ -543,9 +548,9 @@ impl<S: X11Selection> ServerState<EarlyConnection<S>> {
|
|||
};
|
||||
Self {
|
||||
inner,
|
||||
connection: Some(EarlyConnection {
|
||||
connection: EarlyConnection {
|
||||
_p: std::marker::PhantomData,
|
||||
}),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -555,7 +560,7 @@ impl<S: X11Selection> ServerState<EarlyConnection<S>> {
|
|||
{
|
||||
ServerState {
|
||||
inner: self.inner,
|
||||
connection: Some(connection),
|
||||
connection,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -569,18 +574,10 @@ impl<C: XConnection> ServerState<C> {
|
|||
self.inner.clientside_fd()
|
||||
}
|
||||
|
||||
pub fn connect(&mut self, connection: UnixStream) {
|
||||
self.inner.connect(connection)
|
||||
}
|
||||
|
||||
fn handle_new_globals(&mut self) {
|
||||
self.inner.handle_new_globals()
|
||||
}
|
||||
|
||||
pub fn set_x_connection(&mut self, connection: C) {
|
||||
self.connection = Some(connection);
|
||||
}
|
||||
|
||||
pub fn new_window(
|
||||
&mut self,
|
||||
window: x::Window,
|
||||
|
|
@ -761,13 +758,11 @@ impl<C: XConnection> ServerState<C> {
|
|||
output_name,
|
||||
}) = self.inner.to_focus.take()
|
||||
{
|
||||
let conn = self.connection.as_mut().unwrap();
|
||||
debug!("focusing window {window:?}");
|
||||
conn.focus_window(window, output_name);
|
||||
self.connection.focus_window(window, output_name);
|
||||
self.inner.last_focused_toplevel = Some(window);
|
||||
} else if self.inner.unfocus {
|
||||
let conn = self.connection.as_mut().unwrap();
|
||||
conn.focus_window(x::WINDOW_NONE, None);
|
||||
self.connection.focus_window(x::WINDOW_NONE, None);
|
||||
}
|
||||
self.inner.unfocus = false;
|
||||
}
|
||||
|
|
@ -806,7 +801,7 @@ impl<C: XConnection> ServerState<C> {
|
|||
|
||||
fn close_x_window(&mut self, window: x::Window) {
|
||||
debug!("sending close request to {window:?}");
|
||||
self.connection.as_mut().unwrap().close_window(window);
|
||||
self.connection.close_window(window);
|
||||
if self.inner.last_focused_toplevel == Some(window) {
|
||||
self.inner.last_focused_toplevel.take();
|
||||
}
|
||||
|
|
@ -821,14 +816,6 @@ impl<S: X11Selection + 'static> InnerServerState<S> {
|
|||
self.queue.as_fd()
|
||||
}
|
||||
|
||||
fn connect(&mut self, connection: UnixStream) {
|
||||
self.client = Some(
|
||||
self.dh
|
||||
.insert_client(connection, std::sync::Arc::new(()))
|
||||
.unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
fn handle_new_globals(&mut self) {
|
||||
let globals = std::mem::take(&mut self.world.new_globals);
|
||||
handle_globals::<S>(&self.dh, globals.iter());
|
||||
|
|
|
|||
|
|
@ -209,13 +209,14 @@ impl super::XConnection for FakeXConnection {
|
|||
}
|
||||
|
||||
#[track_caller]
|
||||
fn set_window_dims(&mut self, window: Window, state: super::PendingSurfaceState) {
|
||||
fn set_window_dims(&mut self, window: Window, state: super::PendingSurfaceState) -> bool {
|
||||
self.window_mut(window).dims = WindowDims {
|
||||
x: state.x as _,
|
||||
y: state.y as _,
|
||||
width: state.width as _,
|
||||
height: state.height as _,
|
||||
};
|
||||
true
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
|
|
@ -367,9 +368,8 @@ impl EarlyTestFixture {
|
|||
});
|
||||
|
||||
let (fake_client, xwls_server) = UnixStream::pair().unwrap();
|
||||
let mut satellite = EarlyServerState::new(display.handle(), Some(client_s));
|
||||
let satellite = EarlyServerState::new(display.handle(), Some(client_s), xwls_server);
|
||||
let testwl = thread.join().unwrap();
|
||||
satellite.connect(xwls_server);
|
||||
|
||||
let xwls_connection = Connection::from_socket(fake_client).unwrap();
|
||||
let registry = TestObject::<WlRegistry>::from_request(
|
||||
|
|
@ -549,7 +549,7 @@ impl TestFixture<FakeXConnection> {
|
|||
}
|
||||
|
||||
fn connection(&self) -> &FakeXConnection {
|
||||
self.satellite.connection.as_ref().unwrap()
|
||||
&self.satellite.connection
|
||||
}
|
||||
|
||||
fn object_data<P>(&self, obj: &P) -> Arc<TestObjectData<P>>
|
||||
|
|
@ -612,12 +612,7 @@ impl TestFixture<FakeXConnection> {
|
|||
}
|
||||
|
||||
fn register_window(&mut self, window: Window, data: WindowData) {
|
||||
self.satellite
|
||||
.connection
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.windows
|
||||
.insert(window, data);
|
||||
self.satellite.connection.windows.insert(window, data);
|
||||
}
|
||||
|
||||
fn new_window(&mut self, window: Window, override_redirect: bool, data: WindowData) {
|
||||
|
|
@ -940,7 +935,7 @@ fn toplevel_flow() {
|
|||
f.testwl.close_toplevel(testwl_id);
|
||||
f.run();
|
||||
|
||||
assert!(!f.satellite.connection.as_ref().unwrap().windows[&window].mapped);
|
||||
assert!(!f.satellite.connection.windows[&window].mapped);
|
||||
|
||||
assert!(
|
||||
f.testwl.get_surface_data(testwl_id).is_some(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue