mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2025-01-29 20:34:46 +01:00
Fix floating windows not responding to tag changes
This commit is contained in:
parent
5f45e42111
commit
b0c52c0861
6 changed files with 56 additions and 47 deletions
|
@ -19,7 +19,10 @@ use smithay::{
|
|||
use crate::{
|
||||
backend::Backend,
|
||||
state::{State, WithState},
|
||||
window::{window_state::WindowResizeState, WindowElement},
|
||||
window::{
|
||||
window_state::{Float, WindowResizeState},
|
||||
WindowElement,
|
||||
},
|
||||
};
|
||||
|
||||
pub struct MoveSurfaceGrab<S: SeatHandler> {
|
||||
|
@ -97,12 +100,16 @@ impl<B: Backend> PointerGrab<State<B>> for MoveSurfaceGrab<State<B>> {
|
|||
}
|
||||
} else {
|
||||
let delta = event.location - self.start_data.location;
|
||||
let new_loc = self.initial_window_loc.to_f64() + delta;
|
||||
data.space
|
||||
.map_element(self.window.clone(), new_loc.to_i32_round(), true);
|
||||
let new_loc = (self.initial_window_loc.to_f64() + delta).to_i32_round();
|
||||
data.space.map_element(self.window.clone(), new_loc, true);
|
||||
self.window.with_state(|state| {
|
||||
if state.floating.is_floating() {
|
||||
state.floating = Float::Floating(new_loc);
|
||||
}
|
||||
});
|
||||
if let WindowElement::X11(surface) = &self.window {
|
||||
let geo = surface.geometry();
|
||||
let new_geo = Rectangle::from_loc_and_size(new_loc.to_i32_round(), geo.size);
|
||||
let new_geo = Rectangle::from_loc_and_size(new_loc, geo.size);
|
||||
surface
|
||||
.configure(new_geo)
|
||||
.expect("failed to configure x11 win");
|
||||
|
|
|
@ -18,7 +18,7 @@ use smithay::{
|
|||
use crate::{
|
||||
backend::Backend,
|
||||
state::{State, WithState},
|
||||
window::WindowElement,
|
||||
window::{window_state::Float, WindowElement},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
|
@ -332,6 +332,12 @@ pub fn handle_commit<B: Backend>(state: &mut State<B>, surface: &WlSurface) -> O
|
|||
if new_loc.x.is_some() || new_loc.y.is_some() {
|
||||
state.space.map_element(window.clone(), window_loc, false);
|
||||
|
||||
window.with_state(|state| {
|
||||
if state.floating.is_floating() {
|
||||
state.floating = Float::Floating(window_loc);
|
||||
}
|
||||
});
|
||||
|
||||
if let WindowElement::X11(surface) = window {
|
||||
let geo = surface.geometry();
|
||||
let new_geo = Rectangle::from_loc_and_size(window_loc, geo.size);
|
||||
|
|
|
@ -114,7 +114,7 @@ impl<B: Backend> XwmHandler for CalloopData<B> {
|
|||
|
||||
if should_float(surface) {
|
||||
window.with_state(|state| {
|
||||
state.floating = Float::Floating;
|
||||
state.floating = Float::Floating(loc);
|
||||
// TODO: this doesn't correctly tile intellij idea
|
||||
});
|
||||
}
|
||||
|
|
52
src/state.rs
52
src/state.rs
|
@ -20,7 +20,10 @@ use crate::{
|
|||
focus::FocusState,
|
||||
grab::resize_grab::ResizeSurfaceState,
|
||||
tag::Tag,
|
||||
window::{window_state::WindowResizeState, WindowElement},
|
||||
window::{
|
||||
window_state::{Float, WindowResizeState},
|
||||
WindowElement,
|
||||
},
|
||||
};
|
||||
use calloop::futures::Scheduler;
|
||||
use futures_lite::AsyncBufReadExt;
|
||||
|
@ -645,15 +648,10 @@ impl<B: Backend> State<B> {
|
|||
|
||||
windows.iter().cloned().partition::<Vec<_>, _>(|win| {
|
||||
win.with_state(|win_state| {
|
||||
if win_state.floating.is_floating() {
|
||||
return true;
|
||||
}
|
||||
for tag in win_state.tags.iter() {
|
||||
if state.focused_tags().any(|tg| tg == tag) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
win_state
|
||||
.tags
|
||||
.iter()
|
||||
.any(|tag| state.focused_tags().any(|tg| tag == tg))
|
||||
})
|
||||
})
|
||||
});
|
||||
|
@ -666,7 +664,7 @@ impl<B: Backend> State<B> {
|
|||
|
||||
let clone = render.clone();
|
||||
self.loop_handle.insert_idle(|data| {
|
||||
schedule_on_commit(data, clone, |dt| {
|
||||
schedule_on_commit(data, clone.clone(), |dt| {
|
||||
for win in do_not_render {
|
||||
dt.state.space.unmap_elem(&win);
|
||||
if let WindowElement::X11(surface) = win {
|
||||
|
@ -675,28 +673,22 @@ impl<B: Backend> State<B> {
|
|||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
for (win, loc) in clone.into_iter().filter_map(|win| {
|
||||
match win.with_state(|state| state.floating.clone()) {
|
||||
Float::Tiled(_) => None,
|
||||
Float::Floating(loc) => Some((win, loc)),
|
||||
}
|
||||
}) {
|
||||
// TODO: store location in state
|
||||
tracing::debug!("------MAPPING FLOATING TO {loc:?}");
|
||||
dt.state.space.map_element(win, loc, false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// let blocker = WindowBlockerAll::new(render.clone());
|
||||
// blocker.insert_into_loop(self);
|
||||
// for win in render.iter() {
|
||||
// compositor::add_blocker(win.toplevel().wl_surface(), blocker.clone());
|
||||
// }
|
||||
|
||||
// let (blocker, source) = WindowBlocker::block_all::<B>(render.clone());
|
||||
// for win in render.iter() {
|
||||
// compositor::add_blocker(win.toplevel().wl_surface(), blocker.clone());
|
||||
// }
|
||||
// self.loop_handle.insert_idle(move |data| source(render.clone(), data));
|
||||
|
||||
// let (blocker, source) = WindowBlocker::new::<B>(render.clone());
|
||||
// for win in render.iter() {
|
||||
// compositor::add_blocker(win.toplevel().wl_surface(), blocker.clone());
|
||||
// }
|
||||
// self.loop_handle.insert_idle(move |data| source(render.clone(), render.clone(), data));
|
||||
}
|
||||
}
|
||||
|
||||
/// Schedule something to be done when windows have finished committing and have become
|
||||
/// idle.
|
||||
pub fn schedule_on_commit<F, B: Backend>(
|
||||
|
|
|
@ -488,7 +488,14 @@ pub fn toggle_floating<B: Backend>(state: &mut State<B>, window: &WindowElement)
|
|||
resize = Some((prev_loc, prev_size));
|
||||
}
|
||||
|
||||
window_state.floating = Float::Floating;
|
||||
window_state.floating =
|
||||
Float::Floating(resize.map(|(point, _)| point).unwrap_or_else(|| {
|
||||
state
|
||||
.space
|
||||
.element_location(window)
|
||||
.unwrap_or((0, 0).into())
|
||||
}));
|
||||
// TODO: TOMORROW: come up with a better way to keep window location
|
||||
if let WindowElement::Wayland(window) = window {
|
||||
window.toplevel().with_pending_state(|tl_state| {
|
||||
tl_state.states.unset(xdg_toplevel::State::TiledTop);
|
||||
|
@ -498,16 +505,13 @@ pub fn toggle_floating<B: Backend>(state: &mut State<B>, window: &WindowElement)
|
|||
});
|
||||
} // TODO: tiled states for x11
|
||||
}
|
||||
Float::Floating => {
|
||||
Float::Floating(current_loc) => {
|
||||
window_state.floating = Float::Tiled(Some((
|
||||
// We get the location this way because window.geometry().loc
|
||||
// doesn't seem to be the actual location
|
||||
|
||||
// TODO: remove the expect, maybe store the location in state
|
||||
state
|
||||
.space
|
||||
.element_location(window)
|
||||
.expect("toggled float on an unmapped floating window"),
|
||||
// TODO: maybe store the location in state
|
||||
current_loc,
|
||||
window.geometry().size,
|
||||
)));
|
||||
|
||||
|
|
|
@ -124,11 +124,11 @@ impl fmt::Debug for WindowResizeState {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Float {
|
||||
/// The previous location and size of the window when it was floating, if any.
|
||||
Tiled(Option<(Point<i32, Logical>, Size<i32, Logical>)>),
|
||||
Floating,
|
||||
Floating(Point<i32, Logical>),
|
||||
}
|
||||
|
||||
impl Float {
|
||||
|
@ -145,7 +145,7 @@ impl Float {
|
|||
/// [`Floating`]: Float::Floating
|
||||
#[must_use]
|
||||
pub fn is_floating(&self) -> bool {
|
||||
matches!(self, Self::Floating)
|
||||
matches!(self, Self::Floating(_))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue