mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2024-12-27 21:58:18 +01:00
Tidy up stuff
This commit is contained in:
parent
0acffbf79d
commit
76ef7580c2
2 changed files with 50 additions and 36 deletions
|
@ -25,7 +25,8 @@ pub struct FocusState {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
/// Get the currently focused window on `output`, if any.
|
/// Get the currently focused window on `output`
|
||||||
|
/// that isn't an override redirect window, if any.
|
||||||
pub fn focused_window(&mut self, output: &Output) -> Option<WindowElement> {
|
pub fn focused_window(&mut self, output: &Output) -> Option<WindowElement> {
|
||||||
self.focus_state.focus_stack.retain(|win| win.alive());
|
self.focus_state.focus_stack.retain(|win| win.alive());
|
||||||
|
|
||||||
|
|
|
@ -38,17 +38,8 @@ impl XwmHandler for CalloopData {
|
||||||
|
|
||||||
fn map_window_request(&mut self, _xwm: XwmId, window: X11Surface) {
|
fn map_window_request(&mut self, _xwm: XwmId, window: X11Surface) {
|
||||||
tracing::trace!("map_window_request");
|
tracing::trace!("map_window_request");
|
||||||
let win_type = window.window_type();
|
|
||||||
tracing::debug!("window type is {win_type:?}");
|
|
||||||
|
|
||||||
// INFO: This check is here because it happened while launching Ori and the Will of the Wisps
|
assert!(!window.is_override_redirect());
|
||||||
if window.is_override_redirect() {
|
|
||||||
tracing::warn!("Dealt with override redirect window in map_window_request");
|
|
||||||
let loc = window.geometry().loc;
|
|
||||||
let window = WindowElement::X11(window);
|
|
||||||
self.state.space.map_element(window, loc, true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let window = WindowElement::X11(window);
|
let window = WindowElement::X11(window);
|
||||||
self.state.space.map_element(window.clone(), (0, 0), true);
|
self.state.space.map_element(window.clone(), (0, 0), true);
|
||||||
|
@ -87,9 +78,10 @@ impl XwmHandler for CalloopData {
|
||||||
let WindowElement::X11(surface) = &window else {
|
let WindowElement::X11(surface) = &window else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
surface.set_mapped(true).expect("failed to map x11 window");
|
|
||||||
|
|
||||||
self.state.space.map_element(window.clone(), loc, true);
|
self.state.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);
|
let bbox = Rectangle::from_loc_and_size(loc, bbox.size);
|
||||||
|
|
||||||
tracing::debug!("map_window_request, configuring with bbox {bbox:?}");
|
tracing::debug!("map_window_request, configuring with bbox {bbox:?}");
|
||||||
|
@ -121,10 +113,6 @@ impl XwmHandler for CalloopData {
|
||||||
self.state.update_windows(&output);
|
self.state.update_windows(&output);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let WindowElement::X11(s) = &window {
|
|
||||||
tracing::debug!("new x11 win geo is {:?}", s.geometry());
|
|
||||||
}
|
|
||||||
|
|
||||||
self.state.loop_handle.insert_idle(move |data| {
|
self.state.loop_handle.insert_idle(move |data| {
|
||||||
data.state
|
data.state
|
||||||
.seat
|
.seat
|
||||||
|
@ -139,11 +127,11 @@ impl XwmHandler for CalloopData {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mapped_override_redirect_window(&mut self, _xwm: XwmId, window: X11Surface) {
|
fn mapped_override_redirect_window(&mut self, _xwm: XwmId, window: X11Surface) {
|
||||||
tracing::debug!("mapped override redirect window");
|
tracing::trace!("mapped_override_redirect_window");
|
||||||
let win_type = window.window_type();
|
|
||||||
tracing::debug!("window type is {win_type:?}");
|
assert!(window.is_override_redirect());
|
||||||
|
|
||||||
let loc = window.geometry().loc;
|
let loc = window.geometry().loc;
|
||||||
tracing::debug!("or win geo is {:?}", window.geometry());
|
|
||||||
|
|
||||||
let window = WindowElement::X11OverrideRedirect(window);
|
let window = WindowElement::X11OverrideRedirect(window);
|
||||||
self.state.windows.push(window.clone());
|
self.state.windows.push(window.clone());
|
||||||
|
@ -155,35 +143,38 @@ impl XwmHandler for CalloopData {
|
||||||
window.place_on_output(output);
|
window.place_on_output(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
// tracing::debug!("mapped_override_redirect_window to loc {loc:?}");
|
|
||||||
self.state.space.map_element(window.clone(), loc, true);
|
self.state.space.map_element(window.clone(), loc, true);
|
||||||
self.state.focus_state.set_focus(window);
|
self.state.focus_state.set_focus(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unmapped_window(&mut self, _xwm: XwmId, window: X11Surface) {
|
fn unmapped_window(&mut self, _xwm: XwmId, window: X11Surface) {
|
||||||
tracing::debug!("UNMAPPED WINDOW");
|
|
||||||
self.state.focus_state.focus_stack.retain(|win| {
|
self.state.focus_state.focus_stack.retain(|win| {
|
||||||
win.wl_surface()
|
win.wl_surface()
|
||||||
.is_some_and(|surf| Some(surf) != window.wl_surface())
|
.is_some_and(|surf| Some(surf) != window.wl_surface())
|
||||||
});
|
});
|
||||||
|
|
||||||
let win = self
|
let win = self
|
||||||
.state
|
.state
|
||||||
.space
|
.space
|
||||||
.elements()
|
.elements()
|
||||||
.find(|elem| matches!(elem, WindowElement::X11(surface) if surface == &window))
|
.find(|elem| matches!(elem, WindowElement::X11(surface) if surface == &window))
|
||||||
.cloned();
|
.cloned();
|
||||||
|
|
||||||
if let Some(win) = win {
|
if let Some(win) = win {
|
||||||
self.state.space.unmap_elem(&win);
|
self.state.space.unmap_elem(&win);
|
||||||
|
|
||||||
if let Some(output) = win.output(&self.state) {
|
if let Some(output) = win.output(&self.state) {
|
||||||
self.state.update_windows(&output);
|
self.state.update_windows(&output);
|
||||||
|
|
||||||
let focus = self.state.focused_window(&output).map(FocusTarget::Window);
|
let focus = self.state.focused_window(&output).map(FocusTarget::Window);
|
||||||
|
|
||||||
if let Some(FocusTarget::Window(win)) = &focus {
|
if let Some(FocusTarget::Window(win)) = &focus {
|
||||||
tracing::debug!("Focusing on prev win");
|
|
||||||
self.state.space.raise_element(win, true);
|
self.state.space.raise_element(win, true);
|
||||||
if let WindowElement::Wayland(win) = &win {
|
if let WindowElement::Wayland(win) = &win {
|
||||||
win.toplevel().send_configure();
|
win.toplevel().send_configure();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.state
|
self.state
|
||||||
.seat
|
.seat
|
||||||
.get_keyboard()
|
.get_keyboard()
|
||||||
|
@ -193,6 +184,7 @@ impl XwmHandler for CalloopData {
|
||||||
self.state.schedule_render(&output);
|
self.state.schedule_render(&output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !window.is_override_redirect() {
|
if !window.is_override_redirect() {
|
||||||
tracing::debug!("set mapped to false");
|
tracing::debug!("set mapped to false");
|
||||||
window.set_mapped(false).expect("failed to unmap x11 win");
|
window.set_mapped(false).expect("failed to unmap x11 win");
|
||||||
|
@ -204,31 +196,37 @@ impl XwmHandler for CalloopData {
|
||||||
win.wl_surface()
|
win.wl_surface()
|
||||||
.is_some_and(|surf| Some(surf) != window.wl_surface())
|
.is_some_and(|surf| Some(surf) != window.wl_surface())
|
||||||
});
|
});
|
||||||
|
|
||||||
let win = self
|
let win = self
|
||||||
.state
|
.state
|
||||||
.windows
|
.windows
|
||||||
.iter()
|
.iter()
|
||||||
.find(|elem| {
|
.find(|elem| {
|
||||||
matches!(elem, WindowElement::X11(surface) if surface.wl_surface() == window.wl_surface())
|
matches!(
|
||||||
|
elem,
|
||||||
|
WindowElement::X11(surface)
|
||||||
|
| WindowElement::X11OverrideRedirect(surface)
|
||||||
|
if surface.wl_surface() == window.wl_surface()
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.cloned();
|
.cloned();
|
||||||
tracing::debug!("{win:?}");
|
|
||||||
if let Some(win) = win {
|
if let Some(win) = win {
|
||||||
tracing::debug!("removing x11 window from windows");
|
tracing::debug!("removing x11 window from windows");
|
||||||
self.state
|
self.state.windows.retain(|elem| &win != elem);
|
||||||
.windows
|
|
||||||
.retain(|elem| win.wl_surface() != elem.wl_surface());
|
|
||||||
|
|
||||||
if let Some(output) = win.output(&self.state) {
|
if let Some(output) = win.output(&self.state) {
|
||||||
self.state.update_windows(&output);
|
self.state.update_windows(&output);
|
||||||
|
|
||||||
let focus = self.state.focused_window(&output).map(FocusTarget::Window);
|
let focus = self.state.focused_window(&output).map(FocusTarget::Window);
|
||||||
|
|
||||||
if let Some(FocusTarget::Window(win)) = &focus {
|
if let Some(FocusTarget::Window(win)) = &focus {
|
||||||
tracing::debug!("Focusing on prev win");
|
|
||||||
self.state.space.raise_element(win, true);
|
self.state.space.raise_element(win, true);
|
||||||
if let WindowElement::Wayland(win) = &win {
|
if let WindowElement::Wayland(win) = &win {
|
||||||
win.toplevel().send_configure();
|
win.toplevel().send_configure();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.state
|
self.state
|
||||||
.seat
|
.seat
|
||||||
.get_keyboard()
|
.get_keyboard()
|
||||||
|
@ -258,7 +256,7 @@ impl XwmHandler for CalloopData {
|
||||||
if let Some(h) = h {
|
if let Some(h) = h {
|
||||||
geo.size.h = h as i32;
|
geo.size.h = h as i32;
|
||||||
}
|
}
|
||||||
tracing::debug!("configure_request with geo {geo:?}");
|
|
||||||
if let Err(err) = window.configure(geo) {
|
if let Err(err) = window.configure(geo) {
|
||||||
tracing::error!("Failed to configure x11 win: {err}");
|
tracing::error!("Failed to configure x11 win: {err}");
|
||||||
}
|
}
|
||||||
|
@ -280,7 +278,7 @@ impl XwmHandler for CalloopData {
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
tracing::debug!("configure notify with geo: {geometry:?}");
|
|
||||||
self.state.space.map_element(win, geometry.loc, true);
|
self.state.space.map_element(win, geometry.loc, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +286,11 @@ impl XwmHandler for CalloopData {
|
||||||
window
|
window
|
||||||
.set_maximized(true)
|
.set_maximized(true)
|
||||||
.expect("failed to set x11 win to maximized");
|
.expect("failed to set x11 win to maximized");
|
||||||
let Some(window) = (|| self.state.window_for_surface(&window.wl_surface()?))() else {
|
|
||||||
|
let Some(window) = window
|
||||||
|
.wl_surface()
|
||||||
|
.and_then(|surf| self.state.window_for_surface(&surf))
|
||||||
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -301,7 +303,11 @@ impl XwmHandler for CalloopData {
|
||||||
window
|
window
|
||||||
.set_maximized(false)
|
.set_maximized(false)
|
||||||
.expect("failed to set x11 win to maximized");
|
.expect("failed to set x11 win to maximized");
|
||||||
let Some(window) = (|| self.state.window_for_surface(&window.wl_surface()?))() else {
|
|
||||||
|
let Some(window) = window
|
||||||
|
.wl_surface()
|
||||||
|
.and_then(|surf| self.state.window_for_surface(&surf))
|
||||||
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -314,8 +320,11 @@ impl XwmHandler for CalloopData {
|
||||||
window
|
window
|
||||||
.set_fullscreen(true)
|
.set_fullscreen(true)
|
||||||
.expect("failed to set x11 win to fullscreen");
|
.expect("failed to set x11 win to fullscreen");
|
||||||
// TODO: fix this mess
|
|
||||||
let Some(window) = (|| self.state.window_for_surface(&window.wl_surface()?))() else {
|
let Some(window) = window
|
||||||
|
.wl_surface()
|
||||||
|
.and_then(|surf| self.state.window_for_surface(&surf))
|
||||||
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -328,7 +337,11 @@ impl XwmHandler for CalloopData {
|
||||||
window
|
window
|
||||||
.set_fullscreen(false)
|
.set_fullscreen(false)
|
||||||
.expect("failed to set x11 win to unfullscreen");
|
.expect("failed to set x11 win to unfullscreen");
|
||||||
let Some(window) = (|| self.state.window_for_surface(&window.wl_surface()?))() else {
|
|
||||||
|
let Some(window) = window
|
||||||
|
.wl_surface()
|
||||||
|
.and_then(|surf| self.state.window_for_surface(&surf))
|
||||||
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue