Rename and move stuff around

This commit is contained in:
Ottatop 2024-03-04 20:38:20 -06:00
parent d02c138414
commit 8bbb36f512
9 changed files with 47 additions and 31 deletions

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
use smithay::{output::Output, utils::SERIAL_COUNTER}; use smithay::{output::Output, utils::SERIAL_COUNTER};
use tracing::warn;
use crate::{ use crate::{
state::{State, WithState}, state::{State, WithState},
@ -53,12 +54,27 @@ impl State {
); );
} }
pub fn fixup_focus(&mut self) { pub fn fixup_z_layering(&mut self) {
for win in self.z_index_stack.stack.iter() { for win in self.z_index_stack.iter() {
self.space.raise_element(win, false); self.space.raise_element(win, false);
} }
} }
/// Raise a window to the top of the z-index stack.
///
/// This does nothing if the window is unmapped.
pub fn raise_window(&mut self, window: WindowElement, activate: bool) {
if self.space.elements().all(|win| win != &window) {
warn!("Tried to raise an unmapped window");
return;
}
self.space.raise_element(&window, activate);
self.z_index_stack.retain(|win| win != &window);
self.z_index_stack.push(window);
}
/// Get the currently focused output, or the first mapped output if there is none, or None. /// Get the currently focused output, or the first mapped output if there is none, or None.
pub fn focused_output(&self) -> Option<&Output> { pub fn focused_output(&self) -> Option<&Output> {
self.output_focus_stack self.output_focus_stack

View file

@ -49,7 +49,8 @@ impl PointerGrab<State> for MoveSurfaceGrab {
return; return;
} }
state.space.raise_element(&self.window, false); state.raise_window(self.window.clone(), false);
if let Some(surface) = self.window.x11_surface() { if let Some(surface) = self.window.x11_surface() {
// INFO: can you raise OR windows or no idk // INFO: can you raise OR windows or no idk
if !surface.is_override_redirect() { if !surface.is_override_redirect() {

View file

@ -143,7 +143,6 @@ impl CompositorHandler for State {
if is_mapped { if is_mapped {
self.new_windows.retain(|win| win != &new_window); self.new_windows.retain(|win| win != &new_window);
self.windows.push(new_window.clone()); self.windows.push(new_window.clone());
self.z_index_stack.set_focus(new_window.clone());
if let Some(output) = self.focused_output() { if let Some(output) = self.focused_output() {
tracing::debug!("Placing toplevel"); tracing::debug!("Placing toplevel");
@ -157,6 +156,8 @@ impl CompositorHandler for State {
self.space self.space
.map_element(new_window.clone(), (1000000, 0), true); .map_element(new_window.clone(), (1000000, 0), true);
self.raise_window(new_window.clone(), true);
self.apply_window_rules(&new_window); self.apply_window_rules(&new_window);
if let Some(focused_output) = self.focused_output().cloned() { if let Some(focused_output) = self.focused_output().cloned() {

View file

@ -56,7 +56,7 @@ impl XdgShellHandler for State {
.is_some_and(|surf| &surf != surface.wl_surface()) .is_some_and(|surf| &surf != surface.wl_surface())
}); });
self.z_index_stack.stack.retain(|window| { self.z_index_stack.retain(|window| {
window window
.wl_surface() .wl_surface()
.is_some_and(|surf| &surf != surface.wl_surface()) .is_some_and(|surf| &surf != surface.wl_surface())
@ -81,12 +81,11 @@ impl XdgShellHandler for State {
let focus = self let focus = self
.focused_window(&output) .focused_window(&output)
.map(KeyboardFocusTarget::Window); .map(KeyboardFocusTarget::Window);
if let Some(KeyboardFocusTarget::Window(win)) = &focus { if let Some(KeyboardFocusTarget::Window(window)) = &focus {
tracing::debug!("Focusing on prev win"); tracing::debug!("Focusing on prev win");
// TODO: // TODO:
self.space.raise_element(win, true); self.raise_window(window.clone(), true);
self.z_index_stack.set_focus(win.clone()); if let Some(toplevel) = window.toplevel() {
if let Some(toplevel) = win.toplevel() {
toplevel.send_configure(); toplevel.send_configure();
} }
} }

View file

@ -97,7 +97,7 @@ impl XwmHandler for State {
// TODO: will an unmap -> map duplicate the window // TODO: will an unmap -> map duplicate the window
self.windows.push(window.clone()); self.windows.push(window.clone());
self.z_index_stack.set_focus(window.clone()); self.raise_window(window.clone(), true);
self.apply_window_rules(&window); self.apply_window_rules(&window);
@ -129,7 +129,6 @@ impl XwmHandler for State {
let window = WindowElement::new(Window::new_x11_window(surface)); let window = WindowElement::new(Window::new_x11_window(surface));
self.windows.push(window.clone()); self.windows.push(window.clone());
self.z_index_stack.set_focus(window.clone());
if let Some(output) = self.focused_output() { if let Some(output) = self.focused_output() {
window.place_on_output(output); window.place_on_output(output);
@ -138,7 +137,8 @@ impl XwmHandler for State {
output.with_state_mut(|state| state.focus_stack.set_focus(window.clone())) output.with_state_mut(|state| state.focus_stack.set_focus(window.clone()))
} }
self.space.map_element(window, loc, true); self.space.map_element(window.clone(), loc, true);
self.raise_window(window.clone(), true);
} }
fn unmapped_window(&mut self, _xwm: XwmId, surface: X11Surface) { fn unmapped_window(&mut self, _xwm: XwmId, surface: X11Surface) {
@ -161,7 +161,6 @@ impl XwmHandler for State {
self.windows self.windows
.retain(|elem| win.wl_surface() != elem.wl_surface()); .retain(|elem| win.wl_surface() != elem.wl_surface());
self.z_index_stack self.z_index_stack
.stack
.retain(|elem| win.wl_surface() != elem.wl_surface()); .retain(|elem| win.wl_surface() != elem.wl_surface());
self.space.unmap_elem(&win); self.space.unmap_elem(&win);
@ -174,8 +173,7 @@ impl XwmHandler for State {
.map(KeyboardFocusTarget::Window); .map(KeyboardFocusTarget::Window);
if let Some(KeyboardFocusTarget::Window(win)) = &focus { if let Some(KeyboardFocusTarget::Window(win)) = &focus {
self.space.raise_element(win, true); self.raise_window(win.clone(), true);
self.z_index_stack.set_focus(win.clone());
if let Some(toplevel) = win.toplevel() { if let Some(toplevel) = win.toplevel() {
toplevel.send_configure(); toplevel.send_configure();
} }
@ -226,7 +224,6 @@ impl XwmHandler for State {
.retain(|elem| win.wl_surface() != elem.wl_surface()); .retain(|elem| win.wl_surface() != elem.wl_surface());
self.z_index_stack self.z_index_stack
.stack
.retain(|elem| win.wl_surface() != elem.wl_surface()); .retain(|elem| win.wl_surface() != elem.wl_surface());
if let Some(output) = win.output(self) { if let Some(output) = win.output(self) {
@ -237,8 +234,7 @@ impl XwmHandler for State {
.map(KeyboardFocusTarget::Window); .map(KeyboardFocusTarget::Window);
if let Some(KeyboardFocusTarget::Window(win)) = &focus { if let Some(KeyboardFocusTarget::Window(win)) = &focus {
self.space.raise_element(win, true); self.raise_window(win.clone(), true);
self.z_index_stack.set_focus(win.clone());
if let Some(toplevel) = win.toplevel() { if let Some(toplevel) = win.toplevel() {
toplevel.send_configure(); toplevel.send_configure();
} }

View file

@ -375,8 +375,7 @@ impl State {
// TODO: use update_keyboard_focus from anvil // TODO: use update_keyboard_focus from anvil
if let Some(window) = focus.window_for(self) { if let Some(window) = focus.window_for(self) {
self.space.raise_element(&window, true); self.raise_window(window.clone(), true);
self.z_index_stack.set_focus(window.clone());
if let Some(output) = window.output(self) { if let Some(output) = window.output(self) {
output.with_state_mut(|state| state.focus_stack.set_focus(window.clone())); output.with_state_mut(|state| state.focus_stack.set_focus(window.clone()));
} }

View file

@ -150,7 +150,7 @@ impl State {
self.space.map_element(window, loc, false); self.space.map_element(window, loc, false);
} }
self.fixup_focus(); self.fixup_z_layering();
} }
} }

View file

@ -143,13 +143,22 @@ async fn main() -> anyhow::Result<()> {
}; };
event_loop.run(None, &mut state, |state| { event_loop.run(None, &mut state, |state| {
state.fixup_focus(); state.fixup_z_layering();
state.space.refresh(); state.space.refresh();
state.popup_manager.cleanup(); state.popup_manager.cleanup();
state state
.display_handle .display_handle
.flush_clients() .flush_clients()
.expect("failed to flush client buffers"); .expect("failed to flush client buffers");
// TODO: couple these or something, this is really error-prone
assert_eq!(
state.windows.len(),
state.z_index_stack.len(),
"Length of `windows` and `z_index_stack` are different. \
If you see this, report it to the developer."
);
})?; })?;
Ok(()) Ok(())

View file

@ -1,13 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
use crate::{ use crate::{
api::signal::SignalState, api::signal::SignalState, backend::Backend, config::Config, cursor::Cursor,
backend::Backend, focus::OutputFocusStack, grab::resize_grab::ResizeSurfaceState, window::WindowElement,
config::Config,
cursor::Cursor,
focus::{OutputFocusStack, WindowKeyboardFocusStack},
grab::resize_grab::ResizeSurfaceState,
window::WindowElement,
}; };
use anyhow::Context; use anyhow::Context;
use smithay::{ use smithay::{
@ -77,7 +72,7 @@ pub struct State {
pub input_state: InputState, pub input_state: InputState,
pub output_focus_stack: OutputFocusStack, pub output_focus_stack: OutputFocusStack,
pub z_index_stack: WindowKeyboardFocusStack, pub z_index_stack: Vec<WindowElement>,
pub popup_manager: PopupManager, pub popup_manager: PopupManager,
@ -255,7 +250,7 @@ impl State {
input_state: InputState::new(), input_state: InputState::new(),
output_focus_stack: OutputFocusStack::default(), output_focus_stack: OutputFocusStack::default(),
z_index_stack: WindowKeyboardFocusStack::default(), z_index_stack: Vec::new(),
config: Config::new(no_config, config_dir), config: Config::new(no_config, config_dir),