mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2025-01-30 20:34:49 +01:00
Remove CalloopData
This was a remnant of Anvil
This commit is contained in:
parent
fa2eed1adc
commit
8a2a6a3185
6 changed files with 137 additions and 180 deletions
|
@ -76,7 +76,7 @@ use crate::{
|
|||
config::ConnectorSavedState,
|
||||
output::OutputName,
|
||||
render::{pointer::PointerElement, take_presentation_feedback},
|
||||
state::{CalloopData, State, SurfaceDmabufFeedback, WithState},
|
||||
state::{State, SurfaceDmabufFeedback, WithState},
|
||||
window::WindowElement,
|
||||
};
|
||||
|
||||
|
@ -131,7 +131,7 @@ impl Backend {
|
|||
|
||||
impl Udev {
|
||||
/// Schedule a new render that will cause the compositor to redraw everything.
|
||||
pub fn schedule_render(&mut self, loop_handle: &LoopHandle<CalloopData>, output: &Output) {
|
||||
pub fn schedule_render(&mut self, loop_handle: &LoopHandle<State>, output: &Output) {
|
||||
// tracing::debug!("schedule_render on output {}", output.name());
|
||||
|
||||
let Some(surface) = render_surface_for_output(output, &mut self.backends) else {
|
||||
|
@ -141,8 +141,8 @@ impl Udev {
|
|||
match &surface.render_state {
|
||||
RenderState::Idle => {
|
||||
let output = output.clone();
|
||||
let token = loop_handle.insert_idle(move |data| {
|
||||
data.state.render_surface(&output);
|
||||
let token = loop_handle.insert_idle(move |state| {
|
||||
state.render_surface(&output);
|
||||
});
|
||||
|
||||
surface.render_state = RenderState::Scheduled(token);
|
||||
|
@ -189,8 +189,8 @@ impl State {
|
|||
|
||||
// Wait for the clear to commit before switching
|
||||
self.schedule(
|
||||
|data| {
|
||||
let udev = data.state.backend.udev();
|
||||
|state| {
|
||||
let udev = state.backend.udev();
|
||||
!udev
|
||||
.backends
|
||||
.values()
|
||||
|
@ -198,8 +198,8 @@ impl State {
|
|||
.map(|surface| surface.compositor.surface())
|
||||
.any(|drm_surf| drm_surf.commit_pending())
|
||||
},
|
||||
move |data| {
|
||||
let udev = data.state.backend.udev_mut();
|
||||
move |state| {
|
||||
let udev = state.backend.udev_mut();
|
||||
if let Err(err) = udev.session.change_vt(vt) {
|
||||
tracing::error!("Failed to switch to vt {vt}: {err}");
|
||||
}
|
||||
|
@ -301,25 +301,25 @@ pub fn run_udev() -> anyhow::Result<()> {
|
|||
|
||||
event_loop
|
||||
.handle()
|
||||
.insert_source(udev_backend, move |event, _, data| match event {
|
||||
.insert_source(udev_backend, move |event, _, state| match event {
|
||||
// GPU connected
|
||||
UdevEvent::Added { device_id, path } => {
|
||||
if let Err(err) = DrmNode::from_dev_id(device_id)
|
||||
.map_err(DeviceAddError::DrmNode)
|
||||
.and_then(|node| data.state.device_added(node, &path))
|
||||
.and_then(|node| state.device_added(node, &path))
|
||||
{
|
||||
tracing::error!("Skipping device {device_id}: {err}");
|
||||
}
|
||||
}
|
||||
UdevEvent::Changed { device_id } => {
|
||||
if let Ok(node) = DrmNode::from_dev_id(device_id) {
|
||||
data.state.device_changed(node)
|
||||
state.device_changed(node)
|
||||
}
|
||||
}
|
||||
// GPU disconnected
|
||||
UdevEvent::Removed { device_id } => {
|
||||
if let Ok(node) = DrmNode::from_dev_id(device_id) {
|
||||
data.state.device_removed(node)
|
||||
state.device_removed(node)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -338,9 +338,9 @@ pub fn run_udev() -> anyhow::Result<()> {
|
|||
|
||||
let insert_ret = event_loop
|
||||
.handle()
|
||||
.insert_source(libinput_backend, move |event, _, data| {
|
||||
data.state.apply_libinput_settings(&event);
|
||||
data.state.process_input_event(event);
|
||||
.insert_source(libinput_backend, move |event, _, state| {
|
||||
state.apply_libinput_settings(&event);
|
||||
state.process_input_event(event);
|
||||
});
|
||||
|
||||
if let Err(err) = insert_ret {
|
||||
|
@ -349,8 +349,8 @@ pub fn run_udev() -> anyhow::Result<()> {
|
|||
|
||||
event_loop
|
||||
.handle()
|
||||
.insert_source(notifier, move |event, _, data| {
|
||||
let udev = data.state.backend.udev_mut();
|
||||
.insert_source(notifier, move |event, _, state| {
|
||||
let udev = state.backend.udev_mut();
|
||||
|
||||
match event {
|
||||
session::Event::PauseSession => {
|
||||
|
@ -398,13 +398,12 @@ pub fn run_udev() -> anyhow::Result<()> {
|
|||
|
||||
for (node, connectors) in connectors {
|
||||
for (connector, crtc) in connectors {
|
||||
data.state
|
||||
.connector_disconnected(node, connector.clone(), crtc);
|
||||
data.state.connector_connected(node, connector, crtc);
|
||||
state.connector_disconnected(node, connector.clone(), crtc);
|
||||
state.connector_connected(node, connector, crtc);
|
||||
}
|
||||
}
|
||||
for output in data.state.space.outputs().cloned().collect::<Vec<_>>() {
|
||||
data.state.schedule_render(&output);
|
||||
for output in state.space.outputs().cloned().collect::<Vec<_>>() {
|
||||
state.schedule_render(&output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -515,18 +514,16 @@ pub fn run_udev() -> anyhow::Result<()> {
|
|||
|
||||
event_loop.run(
|
||||
Some(Duration::from_micros(((1.0 / 144.0) * 1000000.0) as u64)),
|
||||
&mut CalloopData {
|
||||
state,
|
||||
display_handle,
|
||||
},
|
||||
|data| {
|
||||
data.state.space.refresh();
|
||||
data.state.popup_manager.cleanup();
|
||||
data.display_handle
|
||||
&mut state,
|
||||
|state| {
|
||||
state.space.refresh();
|
||||
state.popup_manager.cleanup();
|
||||
state
|
||||
.display_handle
|
||||
.flush_clients()
|
||||
.expect("failed to flush_clients");
|
||||
|
||||
data.state.focus_state.fix_up_focus(&mut data.state.space);
|
||||
state.focus_state.fix_up_focus(&mut state.space);
|
||||
},
|
||||
)?;
|
||||
|
||||
|
@ -743,7 +740,7 @@ impl State {
|
|||
|
||||
let registration_token = self
|
||||
.loop_handle
|
||||
.insert_source(notifier, move |event, metadata, data| match event {
|
||||
.insert_source(notifier, move |event, metadata, state| match event {
|
||||
DrmEvent::VBlank(crtc) => {
|
||||
// { TODO:
|
||||
// let udev = data.state.backend.udev_mut();
|
||||
|
@ -753,7 +750,7 @@ impl State {
|
|||
// // tracing::debug!(time = diff.as_secs_f64(), "Time since last vblank");
|
||||
// udev.last_vblank_time = now;
|
||||
// }
|
||||
data.state.on_vblank(node, crtc, metadata);
|
||||
state.on_vblank(node, crtc, metadata);
|
||||
}
|
||||
DrmEvent::Error(error) => {
|
||||
tracing::error!("{:?}", error);
|
||||
|
|
|
@ -30,7 +30,7 @@ use smithay::{
|
|||
|
||||
use crate::{
|
||||
render::{pointer::PointerElement, take_presentation_feedback},
|
||||
state::{CalloopData, State},
|
||||
state::State,
|
||||
};
|
||||
|
||||
use super::{Backend, BackendData};
|
||||
|
@ -63,7 +63,7 @@ impl Backend {
|
|||
|
||||
/// Start Pinnacle as a window in a graphical environment.
|
||||
pub fn run_winit() -> anyhow::Result<()> {
|
||||
let mut event_loop: EventLoop<CalloopData> = EventLoop::try_new()?;
|
||||
let mut event_loop: EventLoop<State> = EventLoop::try_new()?;
|
||||
|
||||
let display: Display<State> = Display::new()?;
|
||||
let display_handle = display.handle();
|
||||
|
@ -190,9 +190,7 @@ pub fn run_winit() -> anyhow::Result<()> {
|
|||
let insert_ret =
|
||||
state
|
||||
.loop_handle
|
||||
.insert_source(Timer::immediate(), move |_instant, _metadata, data| {
|
||||
let state = &mut data.state;
|
||||
|
||||
.insert_source(Timer::immediate(), move |_instant, _metadata, state| {
|
||||
let status = winit_evt_loop.dispatch_new_events(|event| match event {
|
||||
WinitEvent::Resized {
|
||||
size,
|
||||
|
@ -237,14 +235,12 @@ pub fn run_winit() -> anyhow::Result<()> {
|
|||
|
||||
event_loop.run(
|
||||
Some(Duration::from_micros(((1.0 / 144.0) * 1000000.0) as u64)),
|
||||
&mut CalloopData {
|
||||
display_handle,
|
||||
state,
|
||||
},
|
||||
|data| {
|
||||
data.state.space.refresh();
|
||||
data.state.popup_manager.cleanup();
|
||||
data.display_handle
|
||||
&mut state,
|
||||
|state| {
|
||||
state.space.refresh();
|
||||
state.popup_manager.cleanup();
|
||||
state
|
||||
.display_handle
|
||||
.flush_clients()
|
||||
.expect("failed to flush client buffers");
|
||||
},
|
||||
|
|
|
@ -4,7 +4,6 @@ use crate::{
|
|||
},
|
||||
input::ModifierMask,
|
||||
output::OutputName,
|
||||
state::CalloopData,
|
||||
tag::Tag,
|
||||
window::rules::{WindowRule, WindowRuleCondition},
|
||||
};
|
||||
|
@ -173,7 +172,7 @@ pub struct Config {
|
|||
}
|
||||
|
||||
impl Config {
|
||||
pub fn clear(&mut self, loop_handle: &LoopHandle<CalloopData>) {
|
||||
pub fn clear(&mut self, loop_handle: &LoopHandle<State>) {
|
||||
self.window_rules.clear();
|
||||
self.output_callback_senders.clear();
|
||||
self.connector_saved_states.clear();
|
||||
|
@ -358,9 +357,9 @@ impl State {
|
|||
|
||||
let token = self
|
||||
.loop_handle
|
||||
.insert_source(ping_source, move |_, _, data| {
|
||||
.insert_source(ping_source, move |_, _, state| {
|
||||
tracing::error!("Config crashed! Falling back to default Lua config");
|
||||
data.state
|
||||
state
|
||||
.start_config(&default_lua_config_dir)
|
||||
.expect("failed to start default lua config");
|
||||
})?;
|
||||
|
@ -435,8 +434,8 @@ impl State {
|
|||
calloop::channel::channel::<Box<dyn FnOnce(&mut Self) + Send>>();
|
||||
|
||||
self.loop_handle
|
||||
.insert_source(grpc_receiver, |msg, _, data| match msg {
|
||||
Event::Msg(f) => f(&mut data.state),
|
||||
.insert_source(grpc_receiver, |msg, _, state| match msg {
|
||||
Event::Msg(f) => f(state),
|
||||
Event::Closed => tracing::error!("grpc receiver was closed"),
|
||||
})
|
||||
.expect("failed to insert grpc_receiver into loop");
|
||||
|
@ -490,9 +489,9 @@ impl State {
|
|||
// | fast at startup then I think there's a chance that the gRPC server
|
||||
// | could get started twice.
|
||||
None => self.schedule(
|
||||
|data| data.state.xdisplay.is_some(),
|
||||
move |data| {
|
||||
data.state.grpc_server_join_handle = Some(tokio::spawn(async move {
|
||||
|state| state.xdisplay.is_some(),
|
||||
move |state| {
|
||||
state.grpc_server_join_handle = Some(tokio::spawn(async move {
|
||||
if let Err(err) = grpc_server.serve_with_incoming(uds_stream).await {
|
||||
tracing::error!("gRPC server error: {err}");
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ use smithay::{
|
|||
|
||||
use crate::{
|
||||
focus::FocusTarget,
|
||||
state::{CalloopData, ClientState, State, WithState},
|
||||
state::{ClientState, State, WithState},
|
||||
window::WindowElement,
|
||||
};
|
||||
|
||||
|
@ -90,10 +90,10 @@ impl CompositorHandler for State {
|
|||
let client = surface
|
||||
.client()
|
||||
.expect("Surface has no client/is no longer alive");
|
||||
let res = state.loop_handle.insert_source(source, move |_, _, data| {
|
||||
data.state
|
||||
let res = state.loop_handle.insert_source(source, move |_, _, state| {
|
||||
state
|
||||
.client_compositor_state(&client)
|
||||
.blocker_cleared(&mut data.state, &data.display_handle);
|
||||
.blocker_cleared(state, &state.display_handle.clone());
|
||||
Ok(())
|
||||
});
|
||||
if res.is_ok() {
|
||||
|
@ -107,9 +107,9 @@ impl CompositorHandler for State {
|
|||
fn commit(&mut self, surface: &WlSurface) {
|
||||
tracing::trace!("commit on surface {surface:?}");
|
||||
|
||||
X11Wm::commit_hook::<CalloopData>(surface);
|
||||
X11Wm::commit_hook::<State>(surface);
|
||||
|
||||
utils::on_commit_buffer_handler::<Self>(surface);
|
||||
utils::on_commit_buffer_handler::<State>(surface);
|
||||
self.backend.early_import(surface);
|
||||
|
||||
let mut root = surface.clone();
|
||||
|
@ -167,13 +167,13 @@ impl CompositorHandler for State {
|
|||
);
|
||||
}
|
||||
|
||||
self.loop_handle.insert_idle(move |data| {
|
||||
data.state
|
||||
self.loop_handle.insert_idle(move |state| {
|
||||
state
|
||||
.seat
|
||||
.get_keyboard()
|
||||
.expect("Seat had no keyboard") // FIXME: actually handle error
|
||||
.set_focus(
|
||||
&mut data.state,
|
||||
state,
|
||||
Some(FocusTarget::Window(new_window)),
|
||||
SERIAL_COUNTER.next_serial(),
|
||||
);
|
||||
|
@ -527,8 +527,8 @@ impl WlrLayerShellHandler for State {
|
|||
.expect("failed to map layer surface");
|
||||
drop(map); // wow i really love refcells haha
|
||||
|
||||
self.loop_handle.insert_idle(move |data| {
|
||||
data.state.update_windows(&output);
|
||||
self.loop_handle.insert_idle(move |state| {
|
||||
state.update_windows(&output);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -547,8 +547,8 @@ impl WlrLayerShellHandler for State {
|
|||
}
|
||||
|
||||
if let Some(output) = output {
|
||||
self.loop_handle.insert_idle(move |data| {
|
||||
data.state.update_windows(&output);
|
||||
self.loop_handle.insert_idle(move |state| {
|
||||
state.update_windows(&output);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,13 +23,13 @@ use smithay::{
|
|||
|
||||
use crate::{
|
||||
focus::FocusTarget,
|
||||
state::{CalloopData, WithState},
|
||||
state::{State, WithState},
|
||||
window::{window_state::FloatingOrTiled, WindowElement},
|
||||
};
|
||||
|
||||
impl XwmHandler for CalloopData {
|
||||
impl XwmHandler for State {
|
||||
fn xwm_state(&mut self, _xwm: XwmId) -> &mut X11Wm {
|
||||
self.state.xwm.as_mut().expect("xwm not in state")
|
||||
self.xwm.as_mut().expect("xwm not in state")
|
||||
}
|
||||
|
||||
fn new_window(&mut self, _xwm: XwmId, _window: X11Surface) {}
|
||||
|
@ -42,24 +42,21 @@ impl XwmHandler for CalloopData {
|
|||
assert!(!window.is_override_redirect());
|
||||
|
||||
let window = WindowElement::X11(window);
|
||||
self.state.space.map_element(window.clone(), (0, 0), true);
|
||||
self.space.map_element(window.clone(), (0, 0), true);
|
||||
let bbox = self
|
||||
.state
|
||||
.space
|
||||
.element_bbox(&window)
|
||||
.expect("called element_bbox on an unmapped window");
|
||||
|
||||
let output_size = self
|
||||
.state
|
||||
.focus_state
|
||||
.focused_output
|
||||
.as_ref()
|
||||
.and_then(|op| self.state.space.output_geometry(op))
|
||||
.and_then(|op| self.space.output_geometry(op))
|
||||
.map(|geo| geo.size)
|
||||
.unwrap_or((2, 2).into());
|
||||
|
||||
let output_loc = self
|
||||
.state
|
||||
.focus_state
|
||||
.focused_output
|
||||
.as_ref()
|
||||
|
@ -79,7 +76,7 @@ impl XwmHandler for CalloopData {
|
|||
unreachable!()
|
||||
};
|
||||
|
||||
self.state.space.map_element(window.clone(), loc, true);
|
||||
self.space.map_element(window.clone(), loc, true);
|
||||
surface.set_mapped(true).expect("failed to map x11 window");
|
||||
|
||||
let bbox = Rectangle::from_loc_and_size(loc, bbox.size);
|
||||
|
@ -91,8 +88,8 @@ impl XwmHandler for CalloopData {
|
|||
// TODO: ssd
|
||||
|
||||
if let (Some(output), _) | (None, Some(output)) = (
|
||||
&self.state.focus_state.focused_output,
|
||||
self.state.space.outputs().next(),
|
||||
&self.focus_state.focused_output,
|
||||
self.space.outputs().next(),
|
||||
) {
|
||||
window.place_on_output(output);
|
||||
}
|
||||
|
@ -103,23 +100,23 @@ impl XwmHandler for CalloopData {
|
|||
});
|
||||
}
|
||||
|
||||
self.state.windows.push(window.clone());
|
||||
self.windows.push(window.clone());
|
||||
|
||||
self.state.focus_state.set_focus(window.clone());
|
||||
self.focus_state.set_focus(window.clone());
|
||||
|
||||
self.state.apply_window_rules(&window);
|
||||
self.apply_window_rules(&window);
|
||||
|
||||
if let Some(output) = window.output(&self.state) {
|
||||
self.state.update_windows(&output);
|
||||
if let Some(output) = window.output(self) {
|
||||
self.update_windows(&output);
|
||||
}
|
||||
|
||||
self.state.loop_handle.insert_idle(move |data| {
|
||||
data.state
|
||||
self.loop_handle.insert_idle(move |state| {
|
||||
state
|
||||
.seat
|
||||
.get_keyboard()
|
||||
.expect("Seat had no keyboard") // FIXME: actually handle error
|
||||
.set_focus(
|
||||
&mut data.state,
|
||||
state,
|
||||
Some(FocusTarget::Window(window)),
|
||||
SERIAL_COUNTER.next_serial(),
|
||||
);
|
||||
|
@ -134,54 +131,52 @@ impl XwmHandler for CalloopData {
|
|||
let loc = window.geometry().loc;
|
||||
|
||||
let window = WindowElement::X11OverrideRedirect(window);
|
||||
self.state.windows.push(window.clone());
|
||||
self.windows.push(window.clone());
|
||||
|
||||
if let (Some(output), _) | (None, Some(output)) = (
|
||||
&self.state.focus_state.focused_output,
|
||||
self.state.space.outputs().next(),
|
||||
&self.focus_state.focused_output,
|
||||
self.space.outputs().next(),
|
||||
) {
|
||||
window.place_on_output(output);
|
||||
}
|
||||
|
||||
self.state.space.map_element(window.clone(), loc, true);
|
||||
self.state.focus_state.set_focus(window);
|
||||
self.space.map_element(window.clone(), loc, true);
|
||||
self.focus_state.set_focus(window);
|
||||
}
|
||||
|
||||
fn unmapped_window(&mut self, _xwm: XwmId, window: X11Surface) {
|
||||
self.state.focus_state.focus_stack.retain(|win| {
|
||||
self.focus_state.focus_stack.retain(|win| {
|
||||
win.wl_surface()
|
||||
.is_some_and(|surf| Some(surf) != window.wl_surface())
|
||||
});
|
||||
|
||||
let win = self
|
||||
.state
|
||||
.space
|
||||
.elements()
|
||||
.find(|elem| matches!(elem, WindowElement::X11(surface) if surface == &window))
|
||||
.cloned();
|
||||
|
||||
if let Some(win) = win {
|
||||
self.state.space.unmap_elem(&win);
|
||||
self.space.unmap_elem(&win);
|
||||
|
||||
if let Some(output) = win.output(&self.state) {
|
||||
self.state.update_windows(&output);
|
||||
if let Some(output) = win.output(self) {
|
||||
self.update_windows(&output);
|
||||
|
||||
let focus = self.state.focused_window(&output).map(FocusTarget::Window);
|
||||
let focus = self.focused_window(&output).map(FocusTarget::Window);
|
||||
|
||||
if let Some(FocusTarget::Window(win)) = &focus {
|
||||
self.state.space.raise_element(win, true);
|
||||
self.space.raise_element(win, true);
|
||||
if let WindowElement::Wayland(win) = &win {
|
||||
win.toplevel().send_configure();
|
||||
}
|
||||
}
|
||||
|
||||
self.state
|
||||
.seat
|
||||
self.seat
|
||||
.get_keyboard()
|
||||
.expect("Seat had no keyboard")
|
||||
.set_focus(&mut self.state, focus, SERIAL_COUNTER.next_serial());
|
||||
.set_focus(self, focus, SERIAL_COUNTER.next_serial());
|
||||
|
||||
self.state.schedule_render(&output);
|
||||
self.schedule_render(&output);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,13 +187,12 @@ impl XwmHandler for CalloopData {
|
|||
}
|
||||
|
||||
fn destroyed_window(&mut self, _xwm: XwmId, window: X11Surface) {
|
||||
self.state.focus_state.focus_stack.retain(|win| {
|
||||
self.focus_state.focus_stack.retain(|win| {
|
||||
win.wl_surface()
|
||||
.is_some_and(|surf| Some(surf) != window.wl_surface())
|
||||
});
|
||||
|
||||
let win = self
|
||||
.state
|
||||
.windows
|
||||
.iter()
|
||||
.find(|elem| {
|
||||
|
@ -215,30 +209,28 @@ impl XwmHandler for CalloopData {
|
|||
tracing::debug!("removing x11 window from windows");
|
||||
|
||||
// INFO: comparing the windows doesn't work so wlsurface it is
|
||||
// self.state.windows.retain(|elem| &win != elem);
|
||||
self.state
|
||||
.windows
|
||||
// self.windows.retain(|elem| &win != elem);
|
||||
self.windows
|
||||
.retain(|elem| win.wl_surface() != elem.wl_surface());
|
||||
|
||||
if let Some(output) = win.output(&self.state) {
|
||||
self.state.update_windows(&output);
|
||||
if let Some(output) = win.output(self) {
|
||||
self.update_windows(&output);
|
||||
|
||||
let focus = self.state.focused_window(&output).map(FocusTarget::Window);
|
||||
let focus = self.focused_window(&output).map(FocusTarget::Window);
|
||||
|
||||
if let Some(FocusTarget::Window(win)) = &focus {
|
||||
self.state.space.raise_element(win, true);
|
||||
self.space.raise_element(win, true);
|
||||
if let WindowElement::Wayland(win) = &win {
|
||||
win.toplevel().send_configure();
|
||||
}
|
||||
}
|
||||
|
||||
self.state
|
||||
.seat
|
||||
self.seat
|
||||
.get_keyboard()
|
||||
.expect("Seat had no keyboard")
|
||||
.set_focus(&mut self.state, focus, SERIAL_COUNTER.next_serial());
|
||||
.set_focus(self, focus, SERIAL_COUNTER.next_serial());
|
||||
|
||||
self.state.schedule_render(&output);
|
||||
self.schedule_render(&output);
|
||||
}
|
||||
}
|
||||
tracing::debug!("destroyed x11 window");
|
||||
|
@ -275,7 +267,6 @@ impl XwmHandler for CalloopData {
|
|||
_above: Option<smithay::reexports::x11rb::protocol::xproto::Window>,
|
||||
) {
|
||||
let Some(win) = self
|
||||
.state
|
||||
.space
|
||||
.elements()
|
||||
.find(|elem| matches!(elem, WindowElement::X11(surface) if surface == &window))
|
||||
|
@ -284,7 +275,7 @@ impl XwmHandler for CalloopData {
|
|||
return;
|
||||
};
|
||||
|
||||
self.state.space.map_element(win, geometry.loc, true);
|
||||
self.space.map_element(win, geometry.loc, true);
|
||||
}
|
||||
|
||||
fn maximize_request(&mut self, _xwm: XwmId, window: X11Surface) {
|
||||
|
@ -294,7 +285,7 @@ impl XwmHandler for CalloopData {
|
|||
|
||||
let Some(window) = window
|
||||
.wl_surface()
|
||||
.and_then(|surf| self.state.window_for_surface(&surf))
|
||||
.and_then(|surf| self.window_for_surface(&surf))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
@ -311,7 +302,7 @@ impl XwmHandler for CalloopData {
|
|||
|
||||
let Some(window) = window
|
||||
.wl_surface()
|
||||
.and_then(|surf| self.state.window_for_surface(&surf))
|
||||
.and_then(|surf| self.window_for_surface(&surf))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
@ -328,7 +319,7 @@ impl XwmHandler for CalloopData {
|
|||
|
||||
let Some(window) = window
|
||||
.wl_surface()
|
||||
.and_then(|surf| self.state.window_for_surface(&surf))
|
||||
.and_then(|surf| self.window_for_surface(&surf))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
@ -345,7 +336,7 @@ impl XwmHandler for CalloopData {
|
|||
|
||||
let Some(window) = window
|
||||
.wl_surface()
|
||||
.and_then(|surf| self.state.window_for_surface(&surf))
|
||||
.and_then(|surf| self.window_for_surface(&surf))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
@ -363,12 +354,12 @@ impl XwmHandler for CalloopData {
|
|||
resize_edge: smithay::xwayland::xwm::ResizeEdge,
|
||||
) {
|
||||
let Some(wl_surf) = window.wl_surface() else { return };
|
||||
let seat = self.state.seat.clone();
|
||||
let seat = self.seat.clone();
|
||||
|
||||
// We use the server one and not the client because windows like Steam don't provide
|
||||
// GrabStartData, so we need to create it ourselves.
|
||||
crate::grab::resize_grab::resize_request_server(
|
||||
&mut self.state,
|
||||
self,
|
||||
&wl_surf,
|
||||
&seat,
|
||||
SERIAL_COUNTER.next_serial(),
|
||||
|
@ -379,12 +370,12 @@ impl XwmHandler for CalloopData {
|
|||
|
||||
fn move_request(&mut self, _xwm: XwmId, window: X11Surface, button: u32) {
|
||||
let Some(wl_surf) = window.wl_surface() else { return };
|
||||
let seat = self.state.seat.clone();
|
||||
let seat = self.seat.clone();
|
||||
|
||||
// We use the server one and not the client because windows like Steam don't provide
|
||||
// GrabStartData, so we need to create it ourselves.
|
||||
crate::grab::move_grab::move_request_server(
|
||||
&mut self.state,
|
||||
self,
|
||||
&wl_surf,
|
||||
&seat,
|
||||
SERIAL_COUNTER.next_serial(),
|
||||
|
@ -393,8 +384,7 @@ impl XwmHandler for CalloopData {
|
|||
}
|
||||
|
||||
fn allow_selection_access(&mut self, xwm: XwmId, _selection: SelectionTarget) -> bool {
|
||||
self.state
|
||||
.seat
|
||||
self.seat
|
||||
.get_keyboard()
|
||||
.and_then(|kb| kb.current_focus())
|
||||
.is_some_and(|focus| {
|
||||
|
@ -415,9 +405,7 @@ impl XwmHandler for CalloopData {
|
|||
) {
|
||||
match selection {
|
||||
SelectionTarget::Clipboard => {
|
||||
if let Err(err) =
|
||||
request_data_device_client_selection(&self.state.seat, mime_type, fd)
|
||||
{
|
||||
if let Err(err) = request_data_device_client_selection(&self.seat, mime_type, fd) {
|
||||
tracing::error!(
|
||||
?err,
|
||||
"Failed to request current wayland clipboard for XWayland"
|
||||
|
@ -425,8 +413,7 @@ impl XwmHandler for CalloopData {
|
|||
}
|
||||
}
|
||||
SelectionTarget::Primary => {
|
||||
if let Err(err) = request_primary_client_selection(&self.state.seat, mime_type, fd)
|
||||
{
|
||||
if let Err(err) = request_primary_client_selection(&self.seat, mime_type, fd) {
|
||||
tracing::error!(
|
||||
?err,
|
||||
"Failed to request current wayland primary selection for XWayland"
|
||||
|
@ -439,15 +426,10 @@ impl XwmHandler for CalloopData {
|
|||
fn new_selection(&mut self, _xwm: XwmId, selection: SelectionTarget, mime_types: Vec<String>) {
|
||||
match selection {
|
||||
SelectionTarget::Clipboard => {
|
||||
set_data_device_selection(
|
||||
&self.state.display_handle,
|
||||
&self.state.seat,
|
||||
mime_types,
|
||||
(),
|
||||
);
|
||||
set_data_device_selection(&self.display_handle, &self.seat, mime_types, ());
|
||||
}
|
||||
SelectionTarget::Primary => {
|
||||
set_primary_selection(&self.state.display_handle, &self.state.seat, mime_types, ());
|
||||
set_primary_selection(&self.display_handle, &self.seat, mime_types, ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -455,13 +437,13 @@ impl XwmHandler for CalloopData {
|
|||
fn cleared_selection(&mut self, _xwm: XwmId, selection: SelectionTarget) {
|
||||
match selection {
|
||||
SelectionTarget::Clipboard => {
|
||||
if current_data_device_selection_userdata(&self.state.seat).is_some() {
|
||||
clear_data_device_selection(&self.state.display_handle, &self.state.seat);
|
||||
if current_data_device_selection_userdata(&self.seat).is_some() {
|
||||
clear_data_device_selection(&self.display_handle, &self.seat);
|
||||
}
|
||||
}
|
||||
SelectionTarget::Primary => {
|
||||
if current_primary_selection_userdata(&self.state.seat).is_some() {
|
||||
clear_primary_selection(&self.state.display_handle, &self.state.seat);
|
||||
if current_primary_selection_userdata(&self.seat).is_some() {
|
||||
clear_primary_selection(&self.display_handle, &self.seat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
53
src/state.rs
53
src/state.rs
|
@ -43,7 +43,7 @@ pub struct State {
|
|||
/// A loop signal used to stop the compositor
|
||||
pub loop_signal: LoopSignal,
|
||||
/// A handle to the event loop
|
||||
pub loop_handle: LoopHandle<'static, CalloopData>,
|
||||
pub loop_handle: LoopHandle<'static, Self>,
|
||||
pub display_handle: DisplayHandle,
|
||||
pub clock: Clock<Monotonic>,
|
||||
|
||||
|
@ -99,7 +99,7 @@ impl State {
|
|||
backend: Backend,
|
||||
display: Display<Self>,
|
||||
loop_signal: LoopSignal,
|
||||
loop_handle: LoopHandle<'static, CalloopData>,
|
||||
loop_handle: LoopHandle<'static, Self>,
|
||||
) -> anyhow::Result<Self> {
|
||||
let socket = ListeningSocketSource::new_auto()?;
|
||||
let socket_name = socket.socket_name().to_os_string();
|
||||
|
@ -137,20 +137,20 @@ impl State {
|
|||
|
||||
loop_handle.insert_source(
|
||||
Generic::new(display, Interest::READ, Mode::Level),
|
||||
|_readiness, display, data| {
|
||||
|_readiness, display, state| {
|
||||
// Safety: we don't drop the display
|
||||
unsafe {
|
||||
display
|
||||
.get_mut()
|
||||
.dispatch_clients(&mut data.state)
|
||||
.dispatch_clients(state)
|
||||
.expect("failed to dispatch clients");
|
||||
}
|
||||
Ok(PostAction::Continue)
|
||||
},
|
||||
)?;
|
||||
|
||||
loop_handle.insert_idle(|data| {
|
||||
if let Err(err) = data.state.start_config(crate::config::get_config_dir()) {
|
||||
loop_handle.insert_idle(|state| {
|
||||
if let Err(err) = state.start_config(crate::config::get_config_dir()) {
|
||||
panic!("failed to start config: {err}");
|
||||
}
|
||||
});
|
||||
|
@ -166,7 +166,7 @@ impl State {
|
|||
let (xwayland, channel) = XWayland::new(&display_handle);
|
||||
let clone = display_handle.clone();
|
||||
tracing::debug!("inserting into loop");
|
||||
let res = loop_handle.insert_source(channel, move |event, _, data| match event {
|
||||
let res = loop_handle.insert_source(channel, move |event, _, state| match event {
|
||||
XWaylandEvent::Ready {
|
||||
connection,
|
||||
client,
|
||||
|
@ -174,7 +174,7 @@ impl State {
|
|||
display,
|
||||
} => {
|
||||
let mut wm = X11Wm::start_wm(
|
||||
data.state.loop_handle.clone(),
|
||||
state.loop_handle.clone(),
|
||||
clone.clone(),
|
||||
connection,
|
||||
client,
|
||||
|
@ -192,13 +192,13 @@ impl State {
|
|||
|
||||
tracing::debug!("setting xwm and xdisplay");
|
||||
|
||||
data.state.xwm = Some(wm);
|
||||
data.state.xdisplay = Some(display);
|
||||
state.xwm = Some(wm);
|
||||
state.xdisplay = Some(display);
|
||||
|
||||
std::env::set_var("DISPLAY", format!(":{display}"));
|
||||
}
|
||||
XWaylandEvent::Exited => {
|
||||
data.state.xwm.take();
|
||||
state.xwm.take();
|
||||
}
|
||||
});
|
||||
if let Err(err) = res {
|
||||
|
@ -274,28 +274,16 @@ impl State {
|
|||
/// This will continually reschedule `run` in the event loop if `condition` returns false.
|
||||
pub fn schedule<F1, F2>(&self, condition: F1, run: F2)
|
||||
where
|
||||
F1: Fn(&mut CalloopData) -> bool + 'static,
|
||||
F2: FnOnce(&mut CalloopData) + 'static,
|
||||
F1: Fn(&mut Self) -> bool + 'static,
|
||||
F2: FnOnce(&mut Self) + 'static,
|
||||
{
|
||||
self.loop_handle.insert_idle(|data| {
|
||||
Self::schedule_inner(data, condition, run);
|
||||
});
|
||||
self.loop_handle.insert_idle(|state| {
|
||||
if !condition(state) {
|
||||
state.schedule(condition, run);
|
||||
} else {
|
||||
run(state);
|
||||
}
|
||||
|
||||
/// Schedule something to be done when `condition` returns true.
|
||||
fn schedule_inner<F1, F2>(data: &mut CalloopData, condition: F1, run: F2)
|
||||
where
|
||||
F1: Fn(&mut CalloopData) -> bool + 'static,
|
||||
F2: FnOnce(&mut CalloopData) + 'static,
|
||||
{
|
||||
if !condition(data) {
|
||||
data.state.loop_handle.insert_idle(|data| {
|
||||
Self::schedule_inner(data, condition, run);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
run(data);
|
||||
}
|
||||
|
||||
pub fn shutdown(&self) {
|
||||
|
@ -304,11 +292,6 @@ impl State {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct CalloopData {
|
||||
pub display_handle: DisplayHandle,
|
||||
pub state: State,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ClientState {
|
||||
pub compositor_state: CompositorClientState,
|
||||
|
|
Loading…
Add table
Reference in a new issue