Update Smithay, with Window that supports X11 surfaces

This commit is contained in:
Ian Douglas Scott 2024-02-21 13:24:56 -08:00 committed by Victoria Brekenfeld
parent 849882a7db
commit 3036448c19
24 changed files with 482 additions and 619 deletions

View file

@ -1,9 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
use crate::{
shell::CosmicSurface, state::ClientState, utils::prelude::*,
wayland::protocols::screencopy::SessionType,
};
use crate::{state::ClientState, utils::prelude::*, wayland::protocols::screencopy::SessionType};
use calloop::Interest;
use smithay::{
backend::renderer::utils::{on_commit_buffer_handler, with_renderer_surface_state},
@ -157,21 +154,14 @@ impl CompositorHandler for State {
.find(|(window, _, _)| window.wl_surface().as_ref() == Some(surface))
.cloned()
{
match window {
CosmicSurface::Wayland(ref wl_window) => {
let toplevel = wl_window.toplevel();
if self.toplevel_ensure_initial_configure(&toplevel)
&& with_renderer_surface_state(&surface, |state| state.buffer().is_some())
.unwrap_or(false)
{
window.on_commit();
Shell::map_window(self, &window);
} else {
return;
}
if let Some(toplevel) = window.0.toplevel() {
if self.toplevel_ensure_initial_configure(&toplevel)
&& with_renderer_surface_state(&surface, |state| state.buffer().is_some())
.unwrap_or(false)
{
window.on_commit();
Shell::map_window(self, &window);
}
CosmicSurface::X11(_) => {}
_ => unreachable!(),
}
}

View file

@ -20,10 +20,7 @@ use smithay::{
};
use wayland_backend::protocol::WEnum;
use crate::{
shell::{CosmicMapped, CosmicSurface},
state::State,
};
use crate::{shell::CosmicMapped, state::State};
pub struct PreferredDecorationMode(RefCell<Option<XdgMode>>);
@ -60,53 +57,61 @@ impl PreferredDecorationMode {
impl State {
pub fn new_decoration(mapped: &CosmicMapped, surface: &WlSurface) -> KdeMode {
if mapped.is_stack() {
if let Some((CosmicSurface::Wayland(window), _)) = mapped
if let Some((window, _)) = mapped
.windows()
.find(|(window, _)| window.wl_surface().as_ref() == Some(surface))
{
window
.toplevel()
.with_pending_state(|state| state.decoration_mode = Some(XdgMode::ServerSide));
window.toplevel().send_configure();
if let Some(toplevel) = window.0.toplevel() {
toplevel.with_pending_state(|state| {
state.decoration_mode = Some(XdgMode::ServerSide)
});
toplevel.send_configure();
}
}
KdeMode::Server
} else {
if let Some((CosmicSurface::Wayland(window), _)) = mapped
if let Some((window, _)) = mapped
.windows()
.find(|(window, _)| window.wl_surface().as_ref() == Some(surface))
{
window
.toplevel()
.with_pending_state(|state| state.decoration_mode = Some(XdgMode::ClientSide));
window.toplevel().send_configure();
if let Some(toplevel) = window.0.toplevel() {
toplevel.with_pending_state(|state| {
state.decoration_mode = Some(XdgMode::ClientSide)
});
toplevel.send_configure();
}
}
KdeMode::Client
}
}
pub fn request_mode(mapped: &CosmicMapped, surface: &WlSurface, mode: XdgMode) {
if let Some((CosmicSurface::Wayland(window), _)) = mapped
if let Some((window, _)) = mapped
.windows()
.find(|(window, _)| window.wl_surface().as_ref() == Some(surface))
{
PreferredDecorationMode::update(&window, Some(mode));
window.toplevel().with_pending_state(|state| {
state.decoration_mode = Some(mode);
});
window.toplevel().send_configure();
if let Some(toplevel) = window.0.toplevel() {
PreferredDecorationMode::update(&window.0, Some(mode));
toplevel.with_pending_state(|state| {
state.decoration_mode = Some(mode);
});
toplevel.send_configure();
}
}
}
pub fn unset_mode(mapped: &CosmicMapped, surface: &WlSurface) {
if let Some((CosmicSurface::Wayland(window), _)) = mapped
if let Some((window, _)) = mapped
.windows()
.find(|(window, _)| window.wl_surface().as_ref() == Some(surface))
{
PreferredDecorationMode::update(&window, None);
window.toplevel().with_pending_state(|state| {
state.decoration_mode = None;
});
window.toplevel().send_configure();
if let Some(toplevel) = window.0.toplevel() {
PreferredDecorationMode::update(&window.0, None);
toplevel.with_pending_state(|state| {
state.decoration_mode = None;
});
toplevel.send_configure();
}
}
}
}

View file

@ -30,7 +30,7 @@ impl DmabufHandler for State {
Ok(Some(node)) => {
// kms backend
let Ok(buffer) = import_notifier.successful::<State>() else {
return
return;
};
if let BackendData::Kms(kms_state) = &mut self.backend {

View file

@ -68,7 +68,12 @@ impl ToplevelManagementHandler for State {
workspace: ZcosmicWorkspaceHandleV1,
_output: Output,
) {
let Some(to_handle) = self.common.shell.workspace_state.get_workspace_handle(&workspace) else {
let Some(to_handle) = self
.common
.shell
.workspace_state
.get_workspace_handle(&workspace)
else {
return;
};

View file

@ -61,14 +61,16 @@ impl XdgActivationHandler for State {
// Tokens without validation aren't allowed to steal focus
let Some((serial, seat)) = data.serial else {
data.user_data.insert_if_missing(|| ActivationContext::UrgentOnly);
data.user_data
.insert_if_missing(|| ActivationContext::UrgentOnly);
debug!(?token, "created urgent-only token for missing seat/serial");
return true
return true;
};
let Some(seat) = Seat::from_resource(&seat) else {
data.user_data.insert_if_missing(|| ActivationContext::UrgentOnly);
data.user_data
.insert_if_missing(|| ActivationContext::UrgentOnly);
debug!(?token, "created urgent-only token for unknown seat");
return true
return true;
};
// At this point we don't bother with urgent-only tokens.

View file

@ -9,7 +9,7 @@ use smithay::{
delegate_xdg_shell,
desktop::{
find_popup_root_surface, PopupGrab, PopupKeyboardGrab, PopupKind, PopupPointerGrab,
PopupUngrabStrategy, Window,
PopupUngrabStrategy,
},
input::{pointer::Focus, Seat},
output::Output,
@ -43,7 +43,7 @@ impl XdgShellHandler for State {
fn new_toplevel(&mut self, surface: ToplevelSurface) {
let seat = self.common.last_active_seat().clone();
let window = CosmicSurface::Wayland(Window::new(surface));
let window = CosmicSurface::from(surface);
self.common.shell.pending_windows.push((window, seat, None));
// We will position the window after the first commit, when we know its size hints
}

View file

@ -3,7 +3,7 @@
use crate::{shell::Shell, utils::prelude::*};
use smithay::{
desktop::{
layer_map_for_output, space::SpaceElement, LayerSurface, PopupKind, PopupManager, Window,
layer_map_for_output, space::SpaceElement, LayerSurface, PopupKind, PopupManager,
WindowSurfaceType,
},
output::Output,
@ -18,8 +18,8 @@ use smithay::{
compositor::{get_role, with_states},
seat::WaylandFocus,
shell::xdg::{
PopupSurface, PositionerState, SurfaceCachedState, XdgPopupSurfaceRoleAttributes,
XDG_POPUP_ROLE,
PopupSurface, PositionerState, SurfaceCachedState, ToplevelSurface,
XdgPopupSurfaceRoleAttributes, XDG_POPUP_ROLE,
},
},
};
@ -85,12 +85,12 @@ impl Shell {
}
pub fn update_reactive_popups<'a>(
window: &Window,
toplevel: &ToplevelSurface,
loc: Point<i32, Global>,
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()) {
for (popup, _) in PopupManager::popups_for_surface(toplevel.wl_surface()) {
match popup {
PopupKind::Xdg(surface) => {
let positioner = with_states(&surface.wl_surface(), |states| {