wip: New shell logic

This commit is contained in:
Victoria Brekenfeld 2022-09-28 12:01:29 +02:00
parent 146a4893ca
commit 00f1b029da
39 changed files with 3922 additions and 2503 deletions

View file

@ -121,7 +121,7 @@ impl CompositorHandler for State {
state.wl_buffer().is_some()
})
{
let output = active_output(&seat, &self.common);
let output = seat.active_output();
Shell::map_window(self, &window, &output);
} else {
return;
@ -147,6 +147,7 @@ impl CompositorHandler for State {
self.xdg_popup_ensure_initial_configure(&popup);
}
/*
// at last handle some special cases, like grabs and changing layer surfaces
// If we would re-position the window inside the grab we would get a weird jittery animation.
@ -182,6 +183,7 @@ impl CompositorHandler for State {
}
}
}
*/
// We need to know every potential output for importing to the right gpu and scheduling a render,
// so call this only after every potential surface map operation has been done.
@ -189,8 +191,8 @@ impl CompositorHandler for State {
// and refresh smithays internal state
self.common.shell.popups.commit(surface);
for workspace in &self.common.shell.spaces {
workspace.space.commit(surface);
for workspace in self.common.shell.workspaces.spaces_mut() {
workspace.commit(surface);
}
// re-arrange layer-surfaces (commits may change size and positioning)
@ -199,8 +201,7 @@ impl CompositorHandler for State {
map.layer_for_surface(surface, WindowSurfaceType::ALL)
.is_some()
}) {
let dh = &self.common.display_handle;
layer_map_for_output(output).arrange(dh);
layer_map_for_output(output).arrange();
}
// schedule a new render

View file

@ -213,7 +213,7 @@ impl ExportDmabufHandler for State {
if cursor_status != CursorImageStatus::Hidden {
let workspace = workspace.as_deref()?;
let loc = seat.get_pointer().map(|ptr| ptr.current_location())?;
let output = active_output(seat, &self.common);
let output = seat.active_output();
if self.common.shell.active_space(&output).idx == workspace.idx {
let relative = self

View file

@ -27,11 +27,11 @@ impl WlrLayerShellHandler for State {
namespace: String,
) {
super::mark_dirty_on_drop(&self.common, surface.wl_surface());
let seat = self.common.last_active_seat.clone();
let seat = self.common.last_active_seat().clone();
let output = wl_output
.as_ref()
.and_then(Output::from_resource)
.unwrap_or_else(|| active_output(&seat, &self.common));
.unwrap_or_else(|| seat.active_output());
self.common.shell.pending_layers.push((
LayerSurface::new(surface, namespace),
output,

View file

@ -4,7 +4,7 @@ pub mod buffer;
pub mod compositor;
pub mod data_device;
pub mod dmabuf;
pub mod export_dmabuf;
//pub mod export_dmabuf;
pub mod keyboard_shortcuts_inhibit;
pub mod layer_shell;
pub mod output;

View file

@ -1,17 +1,23 @@
// SPDX-License-Identifier: GPL-3.0-only
use crate::state::State;
use crate::{
shell::focus::target::{KeyboardFocusTarget, PointerFocusTarget},
state::State,
};
use smithay::{
delegate_seat,
input::{pointer::CursorImageStatus, SeatHandler, SeatState},
reexports::wayland_server::{protocol::wl_surface::WlSurface, Resource},
wayland::{data_device::set_data_device_focus, primary_selection::set_primary_focus},
reexports::wayland_server::Resource,
wayland::{
data_device::set_data_device_focus, primary_selection::set_primary_focus,
seat::WaylandFocus,
},
};
use std::cell::RefCell;
impl SeatHandler for State {
type KeyboardFocus = WlSurface;
type PointerFocus = WlSurface;
type KeyboardFocus = KeyboardFocusTarget;
type PointerFocus = PointerFocusTarget;
fn seat_state(&mut self) -> &mut SeatState<Self> {
&mut self.common.seat_state
@ -35,10 +41,12 @@ impl SeatHandler for State {
focused: Option<&Self::KeyboardFocus>,
) {
let dh = &self.common.display_handle;
if let Some(client) = focused.and_then(|s| dh.get_client(s.id()).ok()) {
set_data_device_focus(dh, seat, Some(client));
let client2 = focused.and_then(|s| dh.get_client(s.id()).ok()).unwrap();
set_primary_focus(dh, seat, Some(client2))
if let Some(client) = focused
.and_then(|t| t.wl_surface())
.and_then(|s| dh.get_client(s.id()).ok())
{
set_data_device_focus(dh, seat, Some(client.clone()));
set_primary_focus(dh, seat, Some(client))
}
}
}

View file

@ -19,18 +19,35 @@ impl ToplevelManagementHandler for State {
}
fn activate(&mut self, _dh: &DisplayHandle, window: &Window, seat: Option<Seat<Self>>) {
if let Some(idx) = self
for output in self
.common
.shell
.space_for_window(window.toplevel().wl_surface())
.map(|w| w.idx)
.outputs()
.cloned()
.collect::<Vec<_>>()
.iter()
{
let seat = seat.unwrap_or(self.common.last_active_seat.clone());
let output = active_output(&seat, &self.common);
if self.common.shell.active_space(&output).idx != idx {
self.common.shell.activate(&seat, &output, idx as usize);
let maybe = self
.common
.shell
.workspaces
.spaces_for_output(output)
.enumerate()
.find(|(_, w)| w.windows().any(|w| &w == window));
if let Some((idx, workspace)) = maybe {
let seat = seat.unwrap_or(self.common.last_active_seat().clone());
let mapped = workspace
.mapped()
.find(|m| m.windows().any(|(w, _)| &w == window))
.unwrap()
.clone();
std::mem::drop(workspace);
self.common.shell.activate(&output, idx as usize);
mapped.focus_window(window);
Common::set_focus(self, Some(&mapped.clone().into()), &seat, None);
return;
}
Common::set_focus(self, Some(window.toplevel().wl_surface()), &seat, None);
}
}

View file

@ -29,16 +29,15 @@ impl WorkspaceHandler for State {
for request in requests.into_iter() {
match request {
Request::Activate(handle) => {
if let Some(idx) = self
let output = self.common.last_active_seat().active_output();
let maybe_idx = self
.common
.shell
.spaces
.iter()
.position(|w| w.handle == handle)
{
let seat = &self.common.last_active_seat;
let output = active_output(seat, &self.common);
self.common.shell.activate(seat, &output, idx);
.workspaces
.spaces_for_output(&output)
.position(|w| w.handle == handle);
if let Some(idx) = maybe_idx {
self.common.shell.activate(&output, idx);
}
}
_ => {}

View file

@ -5,7 +5,7 @@ use smithay::{
delegate_xdg_shell,
desktop::{
find_popup_root_surface, Kind, PopupGrab, PopupKeyboardGrab, PopupKind, PopupPointerGrab,
PopupUngrabStrategy, Window, WindowSurfaceType,
PopupUngrabStrategy, Window,
},
input::{
pointer::{Focus, GrabStartData as PointerGrabStartData},
@ -17,8 +17,12 @@ use smithay::{
wayland_server::protocol::{wl_output::WlOutput, wl_seat::WlSeat, wl_surface::WlSurface},
},
utils::Serial,
wayland::shell::xdg::{
Configure, PopupSurface, PositionerState, ToplevelSurface, XdgShellHandler, XdgShellState,
wayland::{
seat::WaylandFocus,
shell::xdg::{
Configure, PopupSurface, PositionerState, ToplevelSurface, XdgShellHandler,
XdgShellState,
},
},
};
use std::cell::Cell;
@ -35,13 +39,10 @@ impl XdgShellHandler for State {
fn new_toplevel(&mut self, surface: ToplevelSurface) {
super::mark_dirty_on_drop(&self.common, surface.wl_surface());
let seat = &self.common.last_active_seat;
let seat = self.common.last_active_seat().clone();
let window = Window::new(Kind::Xdg(surface));
self.common.shell.toplevel_info_state.new_toplevel(&window);
self.common
.shell
.pending_windows
.push((window, seat.clone()));
self.common.shell.pending_windows.push((window, seat));
// We will position the window after the first commit, when we know its size hints
}
@ -72,17 +73,9 @@ impl XdgShellHandler for State {
// If we would re-position the window inside the grab we would get a weird jittery animation.
// We only want to resize once the client has acknoledged & commited the new size,
// so we need to carefully track the state through different handlers.
if let Some(window) =
self.common
.shell
.space_for_window(&surface)
.and_then(|workspace| {
workspace
.space
.window_for_surface(&surface, WindowSurfaceType::TOPLEVEL)
})
{
crate::shell::layout::floating::ResizeSurfaceGrab::ack_configure(window, configure)
if let Some(mapped) = self.common.shell.element_for_surface(&surface) {
//TODO
//crate::shell::layout::floating::ResizeSurfaceGrab::ack_configure(window, configure)
}
}
}
@ -90,12 +83,16 @@ impl XdgShellHandler for State {
fn grab(&mut self, surface: PopupSurface, seat: WlSeat, serial: Serial) {
let seat = Seat::from_resource(&seat).unwrap();
let kind = PopupKind::Xdg(surface);
if let Ok(root) = find_popup_root_surface(&kind) {
if let Some(root) = find_popup_root_surface(&kind)
.ok()
.and_then(|root| self.common.shell.element_for_surface(&root))
{
let target = root.clone().into();
let ret = self
.common
.shell
.popups
.grab_popup(root, kind, &seat, serial);
.grab_popup(target, kind, &seat, serial);
if let Ok(mut grab) = ret {
if let Some(keyboard) = seat.get_keyboard() {
@ -157,18 +154,9 @@ impl XdgShellHandler for State {
fn move_request(&mut self, surface: ToplevelSurface, seat: WlSeat, serial: Serial) {
let seat = Seat::from_resource(&seat).unwrap();
if let Some(start_data) = check_grab_preconditions(&seat, surface.wl_surface(), serial) {
let workspace = self
.common
.shell
.space_for_window_mut(surface.wl_surface())
.unwrap();
let window = workspace
.space
.window_for_surface(surface.wl_surface(), WindowSurfaceType::TOPLEVEL)
.unwrap()
.clone();
Shell::move_request(self, &window, &seat, serial, start_data);
if let Some(mapped) = self.common.shell.element_for_surface(surface.wl_surface()) {
// Shell::move_request(self, &window, &seat, serial, start_data);
}
}
}
@ -181,35 +169,31 @@ impl XdgShellHandler for State {
) {
let seat = Seat::from_resource(&seat).unwrap();
if let Some(start_data) = check_grab_preconditions(&seat, surface.wl_surface(), serial) {
Workspace::resize_request(self, surface.wl_surface(), &seat, serial, start_data, edges);
if let Some(mapped) = self.common.shell.element_for_surface(surface.wl_surface()) {
// Shell::resize_request(self, mapped, &seat, serial, start_data, edges);
}
}
}
fn maximize_request(&mut self, surface: ToplevelSurface) {
let surface = surface.wl_surface();
let seat = &self.common.last_active_seat;
let output = active_output(seat, &self.common);
let seat = self.common.last_active_seat();
let output = seat.active_output();
if let Some(workspace) = self.common.shell.space_for_window_mut(surface) {
let window = workspace
.space
.window_for_surface(surface, WindowSurfaceType::TOPLEVEL)
.unwrap()
.clone();
workspace.maximize_request(&window, &output)
if let Some(mapped) = self.common.shell.element_for_surface(surface).cloned() {
if let Some(workspace) = self.common.shell.space_for_mut(&mapped) {
//workspace.maximize_request(mapped, &output)
}
}
}
fn unmaximize_request(&mut self, surface: ToplevelSurface) {
let surface = surface.wl_surface();
if let Some(workspace) = self.common.shell.space_for_window_mut(surface) {
let window = workspace
.space
.window_for_surface(surface, WindowSurfaceType::TOPLEVEL)
.unwrap()
.clone();
workspace.unmaximize_request(&window)
if let Some(mapped) = self.common.shell.element_for_surface(surface).cloned() {
if let Some(workspace) = self.common.shell.space_for_mut(&mapped) {
//workspace.unmaximize_request(mapped, &output)
}
}
}
@ -218,29 +202,25 @@ impl XdgShellHandler for State {
.as_ref()
.and_then(Output::from_resource)
.unwrap_or_else(|| {
let seat = &self.common.last_active_seat;
active_output(seat, &self.common)
let seat = self.common.last_active_seat();
seat.active_output()
});
let surface = surface.wl_surface();
if let Some(workspace) = self.common.shell.space_for_window_mut(surface) {
let window = workspace
.space
.window_for_surface(surface, WindowSurfaceType::TOPLEVEL)
.unwrap()
.clone();
workspace.fullscreen_request(&window, &output)
if let Some(mapped) = self.common.shell.element_for_surface(surface).cloned() {
if let Some(workspace) = self.common.shell.space_for_mut(&mapped) {
workspace.fullscreen_request(&mapped.active_window(), &output)
}
}
}
fn unfullscreen_request(&mut self, surface: ToplevelSurface) {
let surface = surface.wl_surface();
if let Some(workspace) = self.common.shell.space_for_window_mut(surface) {
let window = workspace
.space
.window_for_surface(surface, WindowSurfaceType::TOPLEVEL)
.unwrap()
.clone();
if let Some((workspace, window)) = self.common.shell.workspaces.spaces_mut().find_map(|w| {
let window = w
.windows()
.find(|w| w.toplevel().wl_surface() == surface.wl_surface());
window.map(|win| (w, win))
}) {
workspace.unfullscreen_request(&window)
}
}
@ -270,7 +250,6 @@ fn check_grab_preconditions(
.as_ref()
.unwrap()
.0
.id()
.same_client_as(&surface.id())
{
return None;

View file

@ -3,8 +3,7 @@
use crate::{shell::Shell, utils::prelude::*};
use smithay::{
desktop::{
layer_map_for_output, LayerSurface, PopupKind, PopupManager, Space, Window,
WindowSurfaceType,
layer_map_for_output, LayerSurface, PopupKind, PopupManager, Window, WindowSurfaceType,
},
output::Output,
reexports::{
@ -27,12 +26,19 @@ use std::sync::Mutex;
impl Shell {
pub fn unconstrain_popup(&self, surface: &PopupSurface, positioner: &PositionerState) {
if let Some(parent) = get_popup_toplevel(&surface) {
if let Some(workspace) = self.space_for_window(&parent) {
let window = workspace
.space
.window_for_surface(&parent, WindowSurfaceType::ALL)
if let Some(elem) = self.element_for_surface(&parent) {
let workspace = self.space_for(elem).unwrap();
let element_loc = workspace.element_geometry(elem).unwrap().loc;
let (window, offset) = elem
.windows()
.find(|(w, _)| w.toplevel().wl_surface() == &parent)
.unwrap();
unconstrain_xdg_popup(surface, positioner, &workspace.space, window);
let window_geo_offset = window.geometry().loc;
let window_loc = element_loc + offset + window_geo_offset;
let anchor_point = get_anchor_point(&positioner) + window_loc;
if let Some(output) = workspace.output_under(anchor_point) {
unconstrain_xdg_popup(surface, positioner, window_loc, output.geometry());
}
} else if let Some((output, layer_surface)) = self.outputs().find_map(|o| {
let map = layer_map_for_output(o);
map.layer_for_surface(&parent, WindowSurfaceType::ALL)
@ -42,15 +48,14 @@ impl Shell {
}
}
}
pub fn update_reactive_popups(&self, window: &Window) {
if let Some(workspace) = self.space_for_window(window.toplevel().wl_surface()) {
update_reactive_popups(&workspace.space, window);
}
}
}
pub fn update_reactive_popups(space: &Space, window: &Window) {
pub fn update_reactive_popups<'a>(
window: &Window,
loc: Point<i32, Logical>,
outputs: impl Iterator<Item = &'a Output>,
) {
let output_geo = outputs.map(|o| o.geometry()).collect::<Vec<_>>();
for (popup, _) in PopupManager::popups_for_surface(window.toplevel().wl_surface()) {
match popup {
PopupKind::Xdg(surface) => {
@ -64,12 +69,19 @@ pub fn update_reactive_popups(space: &Space, window: &Window) {
attributes.current.positioner.clone()
});
if positioner.reactive {
unconstrain_xdg_popup(&surface, &positioner, space, window);
if let Err(err) = surface.send_configure() {
slog_scope::warn!(
"Compositor bug: Unable to re-configure reactive popup: {}",
err
);
let anchor_point = get_anchor_point(&positioner) + loc;
if let Some(rect) = output_geo
.iter()
.find(|geo| geo.contains(anchor_point))
.copied()
{
unconstrain_xdg_popup(&surface, &positioner, loc, rect);
if let Err(err) = surface.send_configure() {
slog_scope::warn!(
"Compositor bug: Unable to re-configure reactive popup: {}",
err
);
}
}
}
}
@ -80,32 +92,18 @@ pub fn update_reactive_popups(space: &Space, window: &Window) {
fn unconstrain_xdg_popup(
surface: &PopupSurface,
positioner: &PositionerState,
space: &Space,
window: &Window,
window_loc: Point<i32, Logical>,
rect: Rectangle<i32, Logical>,
) {
let anchor_point = get_anchor_point(&positioner) + space.window_location(&window).unwrap();
if let Some(output_rect) = space
.outputs_for_window(window)
.into_iter()
.find(|o| {
space
.output_geometry(o)
.map(|rect| rect.contains(anchor_point))
.unwrap_or(false)
})
.map(|o| space.output_geometry(&o).unwrap())
{
// the output_rect represented relative to the parents coordinate system
let mut relative = output_rect;
relative.loc -= space.window_location(&window).unwrap();
let offset = check_constrained(&surface, positioner.get_geometry(), relative);
let mut relative = rect;
relative.loc -= window_loc;
let offset = check_constrained(&surface, positioner.get_geometry(), relative);
if offset.x != 0 || offset.y != 0 {
slog_scope::debug!("Unconstraining popup: {:?}", surface);
if !unconstrain_flip(&surface, &positioner, relative) {
if !unconstrain_slide(&surface, &positioner, relative) {
unconstrain_resize(&surface, &positioner, relative);
}
if offset.x != 0 || offset.y != 0 {
slog_scope::debug!("Unconstraining popup: {:?}", surface);
if !unconstrain_flip(&surface, &positioner, relative) {
if !unconstrain_slide(&surface, &positioner, relative) {
unconstrain_resize(&surface, &positioner, relative);
}
}
}

View file

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
pub mod drm;
pub mod export_dmabuf;
//pub mod export_dmabuf;
pub mod output_configuration;
pub mod toplevel_info;
pub mod toplevel_management;

View file

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
use smithay::{
output::{Mode, Output, OutputData},
output::{Mode, Output},
reexports::{
wayland_protocols_wlr::output_management::v1::server::{
zwlr_output_configuration_head_v1::{self, ZwlrOutputConfigurationHeadV1},
@ -17,6 +17,7 @@ use smithay::{
},
},
utils::{Logical, Physical, Point, Size, Transform},
wayland::output::WlOutputData,
};
use std::{
convert::{TryFrom, TryInto},
@ -498,7 +499,7 @@ where
impl<D> OutputConfigurationState<D>
where
D: GlobalDispatch<ZwlrOutputManagerV1, OutputMngrGlobalData>
+ GlobalDispatch<WlOutput, OutputData>
+ GlobalDispatch<WlOutput, WlOutputData>
+ Dispatch<ZwlrOutputManagerV1, OutputMngrInstanceData>
+ Dispatch<ZwlrOutputHeadV1, Output>
+ Dispatch<ZwlrOutputModeV1, Mode>

View file

@ -413,7 +413,7 @@ fn send_toplevel_to_client<D>(
.iter()
.filter(|o| !handle_state.outputs.contains(o))
{
new_output.with_client_outputs(dh, &client, |_dh, wl_output| {
new_output.with_client_outputs(&client, |wl_output| {
instance.output_enter(wl_output);
});
changed = true;
@ -423,7 +423,7 @@ fn send_toplevel_to_client<D>(
.iter()
.filter(|o| !state.outputs.contains(o))
{
old_output.with_client_outputs(dh, &client, |_dh, wl_output| {
old_output.with_client_outputs(&client, |wl_output| {
instance.output_leave(wl_output);
});
changed = true;

View file

@ -821,7 +821,7 @@ where
.iter()
.filter(|o| !handle_state.outputs.contains(o))
{
new_output.with_client_outputs(dh, &client, |_dh, wl_output| {
new_output.with_client_outputs(&client, |wl_output| {
instance.output_enter(wl_output);
});
changed = true;
@ -831,7 +831,7 @@ where
.iter()
.filter(|o| !group.outputs.contains(o))
{
old_output.with_client_outputs(dh, &client, |_dh, wl_output| {
old_output.with_client_outputs(&client, |wl_output| {
instance.output_leave(wl_output);
});
changed = true;