refactor(xstate): handle client_message in own fn

The `ClientMessage` case in `handle_events` was moved to its own
function (it is over 90 LoC).
This commit is contained in:
En-En 2025-11-01 14:39:39 +00:00 committed by Supreeeme
parent 2b754c3bec
commit e9ef847544

View file

@ -485,6 +485,28 @@ impl XState {
)); ));
} }
xcb::Event::X(x::Event::ClientMessage(e)) => { xcb::Event::X(x::Event::ClientMessage(e)) => {
self.handle_client_message(e, server_state);
}
xcb::Event::X(x::Event::MappingNotify(_)) => {}
xcb::Event::RandR(xcb::randr::Event::Notify(e))
if matches!(e.u(), xcb::randr::NotifyData::Rc(_)) =>
{
server_state.connection.update_outputs(self.root);
}
other => {
warn!("unhandled event: {other:?}");
}
}
server_state.run();
}
}
fn handle_client_message(
&self,
e: x::ClientMessageEvent,
server_state: &mut super::RealServerState,
) {
match e.r#type() { match e.r#type() {
x if x == self.atoms.wl_surface_id => { x if x == self.atoms.wl_surface_id => {
panic!(concat!( panic!(concat!(
@ -504,7 +526,7 @@ impl XState {
}; };
let Ok(action) = SetState::try_from(data[0]) else { let Ok(action) = SetState::try_from(data[0]) else {
warn!("unknown action for _NET_WM_STATE: {}", data[0]); warn!("unknown action for _NET_WM_STATE: {}", data[0]);
continue; return;
}; };
let prop1 = unsafe { x::Atom::new(data[1]) }; let prop1 = unsafe { x::Atom::new(data[1]) };
let prop2 = unsafe { x::Atom::new(data[2]) }; let prop2 = unsafe { x::Atom::new(data[2]) };
@ -531,14 +553,17 @@ impl XState {
let (_x_root, _y_root) = (data[0], data[1]); let (_x_root, _y_root) = (data[0], data[1]);
let Ok(direction) = MoveResizeDirection::try_from(data[2]) else { let Ok(direction) = MoveResizeDirection::try_from(data[2]) else {
warn!("unknown direction for _NET_WM_MOVERESIZE: {}", data[2]); warn!("unknown direction for _NET_WM_MOVERESIZE: {}", data[2]);
continue; return;
}; };
let button = data[3]; let button = data[3];
// XXX: This can technically be driven by keyboard events and other mouse buttons as well, // XXX: This can technically be driven by keyboard events and other mouse buttons as well,
// but I haven't found an application that does this yet. We'll cross that bridge when we get to it. // but I haven't found an application that does this yet. We'll cross that bridge when we get to it.
if button != 1 { if button != 1 {
warn!("Attempted move/resize of {:?} with non left click button ({button})", e.window()); warn!(
continue; "Attempted move/resize of {:?} with non left click button ({button})",
e.window()
);
return;
} }
match direction { match direction {
@ -558,27 +583,16 @@ impl XState {
MoveResizeDirection::SizeKeyboard MoveResizeDirection::SizeKeyboard
| MoveResizeDirection::MoveKeyboard | MoveResizeDirection::MoveKeyboard
| MoveResizeDirection::Cancel => { | MoveResizeDirection::Cancel => {
warn!("Unimplemented window move/resize action: {direction:?} ({:?})", e.window()); warn!(
"Unimplemented window move/resize action: {direction:?} ({:?})",
e.window()
);
} }
} }
} }
t => warn!("unrecognized message: {t:?}"), t => warn!("unrecognized message: {t:?}"),
} }
} }
xcb::Event::X(x::Event::MappingNotify(_)) => {}
xcb::Event::RandR(xcb::randr::Event::Notify(e))
if matches!(e.u(), xcb::randr::NotifyData::Rc(_)) =>
{
server_state.connection.update_outputs(self.root);
}
other => {
warn!("unhandled event: {other:?}");
}
}
server_state.run();
}
}
fn handle_window_properties( fn handle_window_properties(
&self, &self,