Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better integration of floating stacks #273

Merged
merged 7 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 130 additions & 23 deletions src/shell/element/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ use smithay::{
renderer::{
element::{
memory::MemoryRenderBufferRenderElement, surface::WaylandSurfaceRenderElement,
AsRenderElements,
AsRenderElements, Element, Id as ElementId, Kind, RenderElement,
},
utils::CommitCounter,
ImportAll, ImportMem, Renderer,
},
},
Expand All @@ -42,7 +43,7 @@ use smithay::{
},
output::Output,
render_elements,
utils::{IsAlive, Logical, Point, Rectangle, Serial, Size},
utils::{Buffer, IsAlive, Logical, Physical, Point, Rectangle, Scale, Serial, Size, Transform},
wayland::seat::WaylandFocus,
};
use std::{
Expand Down Expand Up @@ -516,24 +517,24 @@ impl CosmicStack {
pub fn split_render_elements<R, C>(
&self,
renderer: &mut R,
location: smithay::utils::Point<i32, smithay::utils::Physical>,
scale: smithay::utils::Scale<f64>,
location: Point<i32, Physical>,
scale: Scale<f64>,
alpha: f32,
) -> (Vec<C>, Vec<C>)
where
R: Renderer + ImportAll + ImportMem,
<R as Renderer>::TextureId: 'static,
C: From<CosmicStackRenderElement<R>>,
{
let stack_loc = location
+ self
.0
.with_program(|p| {
p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)]
.geometry()
.loc
})
.to_physical_precise_round(scale);
let offset = self
.0
.with_program(|p| {
p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)]
.geometry()
.loc
})
.to_physical_precise_round(scale);
let stack_loc = location + offset;
let window_loc = location + Point::from((0, (TAB_HEIGHT as f64 * scale.y) as i32));

let elements = AsRenderElements::<R>::render_elements::<CosmicStackRenderElement<R>>(
Expand All @@ -549,17 +550,24 @@ impl CosmicStack {
renderer, window_loc, scale, alpha,
);
// preparing the other windows will fix their x11 stacking order.
// they won't actually be drawn, but discarded due to the overlap anyway,
// the performance impact is neglible.
// they won't actually be drawn due to the placeholder element.
for window in windows
.iter()
.enumerate()
.filter(|(i, _)| *i != active)
.map(|(_, w)| w)
{
let (elements, _) =
window.split_render_elements(renderer, window_loc, scale, alpha);
window_elements.extend(elements);
let location =
window_loc + offset - window.geometry().loc.to_physical_precise_round(scale);
let (elements, _) = window
.split_render_elements::<R, WaylandSurfaceRenderElement<R>>(
renderer, location, scale, alpha,
);
window_elements.extend(
elements
.into_iter()
.map(|e| PlaceholderElement(e.id().clone()).into()),
);
}

(window_elements, popup_elements)
Expand Down Expand Up @@ -865,7 +873,7 @@ impl Program for CosmicStackInternal {
fn foreground(
&self,
pixels: &mut tiny_skia::PixmapMut<'_>,
damage: &[Rectangle<i32, smithay::utils::Buffer>],
damage: &[Rectangle<i32, Buffer>],
scale: f32,
) {
if self.group_focused.load(Ordering::SeqCst) {
Expand Down Expand Up @@ -918,7 +926,12 @@ impl SpaceElement for CosmicStack {
}
fn is_in_input_region(&self, point: &Point<f64, Logical>) -> bool {
let mut point = *point;
if point.y < TAB_HEIGHT as f64 {
let offset = self.0.with_program(|p| {
p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)]
.geometry()
.loc
});
if (point.y.round() as i32 - offset.y) < TAB_HEIGHT {
return true;
}
point.y -= TAB_HEIGHT as f64;
Expand Down Expand Up @@ -1152,12 +1165,43 @@ impl PointerTarget<State> for CosmicStack {
}
}) {
event.location.y += TAB_HEIGHT as f64;
event.location -= self
let active_window_geo = self
.0
.with_program(|p| p.windows.lock().unwrap()[active].geometry().loc.to_f64());
.with_program(|p| p.windows.lock().unwrap()[active].geometry());
event.location -= active_window_geo.loc.to_f64();
match (previous, next) {
(Focus::Header, Focus::Header) => {
PointerTarget::motion(&self.0, seat, data, &event)
PointerTarget::motion(&self.0, seat, data, &event);
if event.location.y < 0.0
|| event.location.x < 64.0
|| event.location.x > (active_window_geo.size.w as f64 - 64.0)
{
if let Some(dragged_out) = self
.0
.with_program(|p| p.potential_drag.lock().unwrap().take())
{
if let Some(surface) = self.0.with_program(|p| {
p.windows.lock().unwrap().get(dragged_out).cloned()
}) {
let seat = seat.clone();
surface.try_force_undecorated(false);
surface.send_configure();
if let Some(surface) = surface.wl_surface() {
let _ =
data.common.event_loop_handle.insert_idle(move |state| {
Shell::move_request(
state,
&surface,
&seat,
None,
ReleaseMode::NoMouseButtons,
true,
)
});
}
}
}
}
}
(_, Focus::Header) => PointerTarget::enter(&self.0, seat, data, &event),
(Focus::Header, _) => {
Expand All @@ -1171,6 +1215,8 @@ impl PointerTarget<State> for CosmicStack {
.with_program(|p| p.windows.lock().unwrap().get(dragged_out).cloned())
{
let seat = seat.clone();
surface.try_force_undecorated(false);
surface.send_configure();
if let Some(surface) = surface.wl_surface() {
let _ = data.common.event_loop_handle.insert_idle(move |state| {
Shell::move_request(
Expand Down Expand Up @@ -1427,8 +1473,69 @@ impl PointerTarget<State> for CosmicStack {
}
}

pub struct PlaceholderElement(ElementId);

impl Element for PlaceholderElement {
fn id(&self) -> &ElementId {
&self.0
}

fn current_commit(&self) -> CommitCounter {
0.into()
}

fn src(&self) -> Rectangle<f64, Buffer> {
Rectangle::from_loc_and_size((0., 0.), (0., 0.))
}

fn geometry(&self, _: Scale<f64>) -> Rectangle<i32, Physical> {
Rectangle::from_loc_and_size((0, 0), (0, 0))
}

fn location(&self, _: Scale<f64>) -> Point<i32, Physical> {
(0, 0).into()
}

fn transform(&self) -> Transform {
Transform::Normal
}

fn damage_since(
&self,
_: Scale<f64>,
_: Option<CommitCounter>,
) -> Vec<Rectangle<i32, Physical>> {
vec![]
}

fn opaque_regions(&self, _scale: Scale<f64>) -> Vec<Rectangle<i32, Physical>> {
vec![]
}

fn alpha(&self) -> f32 {
1.0
}

fn kind(&self) -> Kind {
Kind::default()
}
}

impl<R: Renderer> RenderElement<R> for PlaceholderElement {
fn draw(
&self,
_: &mut <R as Renderer>::Frame<'_>,
_: Rectangle<f64, Buffer>,
_: Rectangle<i32, Physical>,
_: &[Rectangle<i32, Physical>],
) -> Result<(), <R as Renderer>::Error> {
Ok(())
}
}

render_elements! {
pub CosmicStackRenderElement<R> where R: ImportAll + ImportMem;
Header = MemoryRenderBufferRenderElement<R>,
Window = WaylandSurfaceRenderElement<R>,
Placeholder = PlaceholderElement,
}
2 changes: 1 addition & 1 deletion src/shell/grabs/menu/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub fn tab_items(
let focus_stack = workspace.focus_stack.get(&seat);
workspace
.tiling_layer
.map(mapped, Some(focus_stack.iter()), None, false);
.map(mapped, Some(focus_stack.iter()), None);
} else {
workspace.floating_layer.map(mapped, None)
}
Expand Down
65 changes: 28 additions & 37 deletions src/shell/grabs/moving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,33 +293,28 @@ impl PointerGrab<State> for MoveGrab {
}
}

if self.previous == ManagedLayer::Tiling {
let indicator_location = state
.common
.shell
.active_space(&current_output)
.tiling_layer
.stacking_indicator();

if indicator_location.is_some() != grab_state.stacking_indicator.is_some() {
grab_state.stacking_indicator = indicator_location.map(|geo| {
let element = stack_hover(
state.common.event_loop_handle.clone(),
geo.size.as_logical(),
state.common.theme.clone(),
let indicator_location = state
.common
.shell
.stacking_indicator(&current_output, self.previous);
if indicator_location.is_some() != grab_state.stacking_indicator.is_some() {
grab_state.stacking_indicator = indicator_location.map(|geo| {
let element = stack_hover(
state.common.event_loop_handle.clone(),
geo.size.as_logical(),
state.common.theme.clone(),
);
for output in &self.window_outputs {
element.output_enter(
output,
Rectangle::from_loc_and_size(
(0, 0),
output.geometry().size.as_logical(),
),
);
for output in &self.window_outputs {
element.output_enter(
output,
Rectangle::from_loc_and_size(
(0, 0),
output.geometry().size.as_logical(),
),
);
}
(element, geo.loc.as_logical())
});
}
}
(element, geo.loc.as_logical())
});
}
}
drop(borrow);
Expand Down Expand Up @@ -566,27 +561,23 @@ impl Drop for MoveGrab {
grab_state.window.geometry().size.as_global(),
));
let workspace = state.common.shell.active_space_mut(&output);
workspace.floating_layer.map_internal(
let (window, location) = workspace.floating_layer.drop_window(
grab_state.window,
Some(window_location.to_local(&workspace.output)),
None,
window_location.to_local(&workspace.output),
);

Some((window.clone(), window_location))
Some((window, location.to_global(&output)))
}
ManagedLayer::Sticky => {
grab_state.window.set_geometry(Rectangle::from_loc_and_size(
window_location,
grab_state.window.geometry().size.as_global(),
));
let set = state.common.shell.workspaces.sets.get_mut(&output).unwrap();
set.sticky_layer.map_internal(
grab_state.window,
Some(window_location.to_local(&output)),
None,
);
let (window, location) = set
.sticky_layer
.drop_window(grab_state.window, window_location.to_local(&output));

Some((window.clone(), window_location))
Some((window, location.to_global(&output)))
}
}
} else {
Expand Down
Loading