update smithay, iced; reworked window for xwayland
This commit is contained in:
parent
47dfc85314
commit
7992ad67f6
27 changed files with 2285 additions and 1106 deletions
|
|
@ -1,6 +1,9 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::{state::BackendData, utils::prelude::*, wayland::protocols::screencopy::SessionType};
|
||||
use crate::{
|
||||
shell::CosmicSurface, state::BackendData, utils::prelude::*,
|
||||
wayland::protocols::screencopy::SessionType,
|
||||
};
|
||||
use smithay::{
|
||||
backend::renderer::utils::{on_commit_buffer_handler, with_renderer_surface_state},
|
||||
delegate_compositor,
|
||||
|
|
@ -8,6 +11,7 @@ use smithay::{
|
|||
reexports::wayland_server::protocol::wl_surface::WlSurface,
|
||||
wayland::{
|
||||
compositor::{with_states, CompositorHandler, CompositorState},
|
||||
seat::WaylandFocus,
|
||||
shell::{
|
||||
wlr_layer::LayerSurfaceAttributes,
|
||||
xdg::{
|
||||
|
|
@ -113,17 +117,28 @@ impl CompositorHandler for State {
|
|||
.shell
|
||||
.pending_windows
|
||||
.iter()
|
||||
.find(|(window, _)| window.toplevel().wl_surface() == surface)
|
||||
.find(|(window, _)| window.wl_surface().as_ref() == Some(surface))
|
||||
.cloned()
|
||||
{
|
||||
let toplevel = window.toplevel();
|
||||
if self.toplevel_ensure_initial_configure(&toplevel)
|
||||
&& with_renderer_surface_state(&surface, |state| state.wl_buffer().is_some())
|
||||
{
|
||||
let output = seat.active_output();
|
||||
Shell::map_window(self, &window, &output);
|
||||
} else {
|
||||
return;
|
||||
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.wl_buffer().is_some()
|
||||
})
|
||||
{
|
||||
let output = seat.active_output();
|
||||
Shell::map_window(self, &window, &output);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
CosmicSurface::X11(_) => {
|
||||
let output = seat.active_output();
|
||||
Shell::map_window(self, &window, &output);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use smithay::{
|
|||
Bind, Blit, BufferType, ExportMem, ImportAll, ImportMem, Offscreen, Renderer,
|
||||
},
|
||||
},
|
||||
desktop::Window,
|
||||
desktop::space::SpaceElement,
|
||||
output::Output,
|
||||
reexports::wayland_server::{
|
||||
protocol::{wl_buffer::WlBuffer, wl_shm::Format as ShmFormat, wl_surface::WlSurface},
|
||||
|
|
@ -33,6 +33,7 @@ use smithay::{
|
|||
utils::{IsAlive, Logical, Physical, Rectangle, Scale, Transform},
|
||||
wayland::{
|
||||
dmabuf::get_dmabuf,
|
||||
seat::WaylandFocus,
|
||||
shm::{with_buffer_contents, with_buffer_contents_mut},
|
||||
},
|
||||
};
|
||||
|
|
@ -43,7 +44,7 @@ use crate::{
|
|||
element::{AsGlowRenderer, CosmicElement},
|
||||
render_output, render_workspace, CursorMode, CLEAR_COLOR,
|
||||
},
|
||||
shell::CosmicMappedRenderElement,
|
||||
shell::{CosmicMappedRenderElement, CosmicSurface},
|
||||
state::{BackendData, ClientState, Common, State},
|
||||
utils::prelude::OutputExt,
|
||||
wayland::protocols::{
|
||||
|
|
@ -159,8 +160,8 @@ impl ScreencopyHandler for State {
|
|||
formats
|
||||
}
|
||||
|
||||
fn capture_toplevel(&mut self, toplevel: Window, session: Session) -> Vec<BufferInfo> {
|
||||
let surface = toplevel.toplevel().wl_surface();
|
||||
fn capture_toplevel(&mut self, toplevel: CosmicSurface, session: Session) -> Vec<BufferInfo> {
|
||||
let Some(surface) = toplevel.wl_surface() else { return Vec::new() };
|
||||
let size = toplevel.geometry().size.to_buffer(1, Transform::Normal);
|
||||
|
||||
let mut _kms_renderer = None;
|
||||
|
|
@ -843,7 +844,7 @@ pub fn render_window_to_buffer(
|
|||
state: &mut State,
|
||||
session: &Session,
|
||||
params: BufferParams,
|
||||
window: &Window,
|
||||
window: &CosmicSurface,
|
||||
) -> Result<bool, (FailureReason, anyhow::Error)> {
|
||||
let geometry = window.geometry();
|
||||
let buffer_size = buffer_dimensions(¶ms.buffer).unwrap();
|
||||
|
|
@ -858,7 +859,7 @@ pub fn render_window_to_buffer(
|
|||
age: usize,
|
||||
session: &Session,
|
||||
common: &mut Common,
|
||||
window: &Window,
|
||||
window: &CosmicSurface,
|
||||
geometry: Rectangle<i32, Logical>,
|
||||
) -> Result<
|
||||
(Option<Vec<Rectangle<i32, Physical>>>, RenderElementStates),
|
||||
|
|
@ -889,12 +890,12 @@ pub fn render_window_to_buffer(
|
|||
for seat in common.seats() {
|
||||
if let Some(location) = {
|
||||
// we need to find the mapped element in that case
|
||||
if let Some(mapped) = common
|
||||
.shell
|
||||
.element_for_surface(window.toplevel().wl_surface())
|
||||
if let Some(mapped) = window
|
||||
.wl_surface()
|
||||
.and_then(|surf| common.shell.element_for_surface(&surf))
|
||||
{
|
||||
mapped.cursor_position(seat).and_then(|mut p| {
|
||||
p -= mapped.active_window_offset().loc.to_f64();
|
||||
p -= mapped.active_window_offset().to_f64();
|
||||
if p.x < 0. || p.y < 0. {
|
||||
None
|
||||
} else {
|
||||
|
|
@ -1076,7 +1077,7 @@ impl UserdataExt for Output {
|
|||
}
|
||||
}
|
||||
|
||||
impl UserdataExt for Window {
|
||||
impl UserdataExt for CosmicSurface {
|
||||
fn sessions(&self) -> Vec<Session> {
|
||||
self.user_data()
|
||||
.get::<ScreencopySessions>()
|
||||
|
|
@ -1101,7 +1102,7 @@ impl State {
|
|||
pub fn schedule_window_session(&mut self, surface: &WlSurface) {
|
||||
if let Some(element) = self.common.shell.element_for_surface(surface).cloned() {
|
||||
let active = element.active_window();
|
||||
if active.toplevel().wl_surface() == surface {
|
||||
if active.wl_surface().as_ref() == Some(surface) {
|
||||
for (session, params) in active.pending_buffers() {
|
||||
let window = active.clone();
|
||||
self.common.event_loop_handle.insert_idle(move |data| {
|
||||
|
|
|
|||
|
|
@ -1,19 +1,54 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use smithay::utils::user_data::UserDataMap;
|
||||
|
||||
use crate::{
|
||||
shell::CosmicSurface,
|
||||
state::State,
|
||||
wayland::protocols::toplevel_info::{
|
||||
delegate_toplevel_info, ToplevelInfoHandler, ToplevelInfoState,
|
||||
delegate_toplevel_info, ToplevelInfoHandler, ToplevelInfoState, Window,
|
||||
},
|
||||
};
|
||||
|
||||
impl ToplevelInfoHandler for State {
|
||||
fn toplevel_info_state(&self) -> &ToplevelInfoState<State> {
|
||||
type Window = CosmicSurface;
|
||||
|
||||
fn toplevel_info_state(&self) -> &ToplevelInfoState<State, Self::Window> {
|
||||
&self.common.shell.toplevel_info_state
|
||||
}
|
||||
fn toplevel_info_state_mut(&mut self) -> &mut ToplevelInfoState<State> {
|
||||
fn toplevel_info_state_mut(&mut self) -> &mut ToplevelInfoState<State, Self::Window> {
|
||||
&mut self.common.shell.toplevel_info_state
|
||||
}
|
||||
}
|
||||
|
||||
delegate_toplevel_info!(State);
|
||||
impl Window for CosmicSurface {
|
||||
fn title(&self) -> String {
|
||||
CosmicSurface::title(self)
|
||||
}
|
||||
|
||||
fn app_id(&self) -> String {
|
||||
CosmicSurface::app_id(self)
|
||||
}
|
||||
|
||||
fn is_activated(&self) -> bool {
|
||||
CosmicSurface::is_activated(self)
|
||||
}
|
||||
|
||||
fn is_maximized(&self) -> bool {
|
||||
CosmicSurface::is_maximized(self)
|
||||
}
|
||||
|
||||
fn is_fullscreen(&self) -> bool {
|
||||
CosmicSurface::is_fullscreen(self)
|
||||
}
|
||||
|
||||
fn is_minimized(&self) -> bool {
|
||||
false // TODO
|
||||
}
|
||||
|
||||
fn user_data(&self) -> &UserDataMap {
|
||||
CosmicSurface::user_data(self)
|
||||
}
|
||||
}
|
||||
|
||||
delegate_toplevel_info!(State, CosmicSurface);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use smithay::{desktop::Window, input::Seat, reexports::wayland_server::DisplayHandle};
|
||||
use smithay::{input::Seat, reexports::wayland_server::DisplayHandle};
|
||||
|
||||
use crate::{
|
||||
shell::CosmicSurface,
|
||||
utils::prelude::*,
|
||||
wayland::protocols::toplevel_management::{
|
||||
delegate_toplevel_management, ToplevelManagementHandler, ToplevelManagementState,
|
||||
wayland::protocols::{
|
||||
toplevel_info::ToplevelInfoHandler,
|
||||
toplevel_management::{
|
||||
delegate_toplevel_management, ManagementWindow, ToplevelManagementHandler,
|
||||
ToplevelManagementState,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -14,7 +19,12 @@ impl ToplevelManagementHandler for State {
|
|||
&mut self.common.shell.toplevel_management_state
|
||||
}
|
||||
|
||||
fn activate(&mut self, _dh: &DisplayHandle, window: &Window, seat: Option<Seat<Self>>) {
|
||||
fn activate(
|
||||
&mut self,
|
||||
_dh: &DisplayHandle,
|
||||
window: &<Self as ToplevelInfoHandler>::Window,
|
||||
seat: Option<Seat<Self>>,
|
||||
) {
|
||||
for output in self
|
||||
.common
|
||||
.shell
|
||||
|
|
@ -47,8 +57,14 @@ impl ToplevelManagementHandler for State {
|
|||
}
|
||||
}
|
||||
|
||||
fn close(&mut self, _dh: &DisplayHandle, window: &Window) {
|
||||
window.toplevel().send_close();
|
||||
fn close(&mut self, _dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::Window) {
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
|
||||
impl ManagementWindow for CosmicSurface {
|
||||
fn close(&self) {
|
||||
CosmicSurface::close(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::{utils::prelude::*, wayland::protocols::screencopy::SessionType};
|
||||
use crate::{shell::CosmicSurface, utils::prelude::*, wayland::protocols::screencopy::SessionType};
|
||||
use smithay::{
|
||||
delegate_xdg_shell,
|
||||
desktop::{
|
||||
|
|
@ -39,7 +39,7 @@ impl XdgShellHandler for State {
|
|||
|
||||
fn new_toplevel(&mut self, surface: ToplevelSurface) {
|
||||
let seat = self.common.last_active_seat().clone();
|
||||
let window = Window::new(surface);
|
||||
let window = CosmicSurface::Wayland(Window::new(surface));
|
||||
self.common.shell.toplevel_info_state.new_toplevel(&window);
|
||||
self.common.shell.pending_windows.push((window, seat));
|
||||
// We will position the window after the first commit, when we know its size hints
|
||||
|
|
@ -149,7 +149,7 @@ impl XdgShellHandler for State {
|
|||
let output = seat.active_output();
|
||||
let (window, _) = mapped
|
||||
.windows()
|
||||
.find(|(w, _)| w.toplevel() == &surface)
|
||||
.find(|(w, _)| w.wl_surface().as_ref() == Some(surface.wl_surface()))
|
||||
.unwrap();
|
||||
if let Some(grab) =
|
||||
workspace.move_request(&window, &seat, &output, serial, start_data)
|
||||
|
|
@ -213,7 +213,7 @@ impl XdgShellHandler for State {
|
|||
if let Some(workspace) = self.common.shell.space_for_mut(&mapped) {
|
||||
let (window, _) = mapped
|
||||
.windows()
|
||||
.find(|(w, _)| w.toplevel() == &surface)
|
||||
.find(|(w, _)| w.wl_surface().as_ref() == Some(surface.wl_surface()))
|
||||
.unwrap();
|
||||
workspace.maximize_request(&window, &output)
|
||||
}
|
||||
|
|
@ -230,9 +230,9 @@ impl XdgShellHandler for State {
|
|||
if let Some(workspace) = self.common.shell.space_for_mut(&mapped) {
|
||||
let (window, _) = mapped
|
||||
.windows()
|
||||
.find(|(w, _)| w.toplevel() == &surface)
|
||||
.find(|(w, _)| w.wl_surface().as_ref() == Some(surface.wl_surface()))
|
||||
.unwrap();
|
||||
workspace.unmaximize_request(&window)
|
||||
workspace.unmaximize_request(&window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -255,7 +255,7 @@ impl XdgShellHandler for State {
|
|||
if let Some(workspace) = self.common.shell.space_for_mut(&mapped) {
|
||||
let (window, _) = mapped
|
||||
.windows()
|
||||
.find(|(w, _)| w.toplevel() == &surface)
|
||||
.find(|(w, _)| w.wl_surface().as_ref() == Some(surface.wl_surface()))
|
||||
.unwrap();
|
||||
workspace.fullscreen_request(&window, &output)
|
||||
}
|
||||
|
|
@ -272,7 +272,7 @@ impl XdgShellHandler for State {
|
|||
if let Some(workspace) = self.common.shell.space_for_mut(&mapped) {
|
||||
let (window, _) = mapped
|
||||
.windows()
|
||||
.find(|(w, _)| w.toplevel() == &surface)
|
||||
.find(|(w, _)| w.wl_surface().as_ref() == Some(surface.wl_surface()))
|
||||
.unwrap();
|
||||
workspace.unfullscreen_request(&window)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
use crate::{shell::Shell, utils::prelude::*};
|
||||
use smithay::{
|
||||
desktop::{
|
||||
layer_map_for_output, LayerSurface, PopupKind, PopupManager, Window, WindowSurfaceType,
|
||||
layer_map_for_output, space::SpaceElement, LayerSurface, PopupKind, PopupManager, Window,
|
||||
WindowSurfaceType,
|
||||
},
|
||||
output::Output,
|
||||
reexports::{
|
||||
|
|
@ -15,6 +16,7 @@ use smithay::{
|
|||
utils::{Logical, Point, Rectangle},
|
||||
wayland::{
|
||||
compositor::{get_role, with_states},
|
||||
seat::WaylandFocus,
|
||||
shell::xdg::{
|
||||
PopupSurface, PositionerState, SurfaceCachedState, XdgPopupSurfaceRoleAttributes,
|
||||
XDG_POPUP_ROLE,
|
||||
|
|
@ -31,12 +33,12 @@ impl Shell {
|
|||
let element_geo = workspace.element_geometry(elem).unwrap();
|
||||
let (window, offset) = elem
|
||||
.windows()
|
||||
.find(|(w, _)| w.toplevel().wl_surface() == &parent)
|
||||
.find(|(w, _)| w.wl_surface().as_ref() == Some(&parent))
|
||||
.unwrap();
|
||||
let window_geo_offset = window.geometry().loc;
|
||||
let window_loc = element_geo.loc + offset + window_geo_offset;
|
||||
let anchor_point = get_anchor_point(&positioner) + window_loc;
|
||||
if elem.is_tiled() {
|
||||
if elem.is_tiled().unwrap() {
|
||||
if !unconstrain_xdg_popup_tile(surface, element_geo) {
|
||||
if let Some(output) = workspace.output_under(anchor_point) {
|
||||
unconstrain_xdg_popup(surface, window_loc, output.geometry());
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ use smithay::{
|
|||
allocator::Fourcc as DrmFourcc,
|
||||
drm::{DrmNode, NodeType},
|
||||
},
|
||||
desktop::Window,
|
||||
input::{Seat, SeatHandler},
|
||||
output::Output,
|
||||
reexports::wayland_server::{
|
||||
|
|
@ -30,10 +29,10 @@ use wayland_backend::{
|
|||
server::{GlobalId, ObjectId},
|
||||
};
|
||||
|
||||
use crate::state::State;
|
||||
use crate::{shell::CosmicSurface, state::State};
|
||||
|
||||
use super::{
|
||||
toplevel_info::window_from_handle,
|
||||
toplevel_info::{window_from_handle, ToplevelInfoHandler},
|
||||
workspace::{WorkspaceHandle, WorkspaceHandler},
|
||||
};
|
||||
|
||||
|
|
@ -112,11 +111,11 @@ impl SessionDataInnerInner {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum SessionType {
|
||||
Output(Output),
|
||||
Workspace(Output, WorkspaceHandle),
|
||||
Window(Window),
|
||||
Window(CosmicSurface),
|
||||
Cursor(Seat<State>),
|
||||
#[doc(hidden)]
|
||||
Unknown,
|
||||
|
|
@ -490,7 +489,7 @@ pub trait ScreencopyHandler {
|
|||
session: Session,
|
||||
) -> Vec<BufferInfo>;
|
||||
|
||||
fn capture_toplevel(&mut self, toplevel: Window, session: Session) -> Vec<BufferInfo>;
|
||||
fn capture_toplevel(&mut self, toplevel: CosmicSurface, session: Session) -> Vec<BufferInfo>;
|
||||
|
||||
fn capture_cursor(&mut self, session: CursorSession) -> Vec<BufferInfo>;
|
||||
|
||||
|
|
@ -605,6 +604,7 @@ where
|
|||
D: GlobalDispatch<ZcosmicScreencopyManagerV1, ScreencopyGlobalData>
|
||||
+ Dispatch<ZcosmicScreencopyManagerV1, Vec<WlCursorMode>>
|
||||
+ Dispatch<ZcosmicScreencopySessionV1, SessionData>
|
||||
+ ToplevelInfoHandler<Window = CosmicSurface>
|
||||
+ ScreencopyHandler
|
||||
+ WorkspaceHandler
|
||||
+ 'static,
|
||||
|
|
@ -664,7 +664,7 @@ where
|
|||
} => {
|
||||
let Some(cursor) = check_cursor(cursor, &data, resource) else { return; };
|
||||
|
||||
match window_from_handle(toplevel) {
|
||||
match window_from_handle::<<D as ToplevelInfoHandler>::Window>(toplevel) {
|
||||
Some(window) => {
|
||||
let session = match init_session(
|
||||
data_init,
|
||||
|
|
|
|||
|
|
@ -3,18 +3,13 @@
|
|||
use std::{collections::HashMap, sync::Mutex};
|
||||
|
||||
use smithay::{
|
||||
desktop::Window,
|
||||
output::Output,
|
||||
reexports::{
|
||||
wayland_protocols::xdg::shell::server::xdg_toplevel,
|
||||
wayland_server::{
|
||||
backend::{ClientId, GlobalId, ObjectId},
|
||||
protocol::wl_surface::WlSurface,
|
||||
Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource,
|
||||
},
|
||||
reexports::wayland_server::{
|
||||
backend::{ClientId, GlobalId, ObjectId},
|
||||
protocol::wl_surface::WlSurface,
|
||||
Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource,
|
||||
},
|
||||
utils::{IsAlive, Logical, Rectangle},
|
||||
wayland::{compositor::with_states, shell::xdg::XdgToplevelSurfaceRoleAttributes},
|
||||
utils::{user_data::UserDataMap, IsAlive, Logical, Rectangle},
|
||||
};
|
||||
|
||||
use super::workspace::{WorkspaceHandle, WorkspaceHandler, WorkspaceState};
|
||||
|
|
@ -24,17 +19,28 @@ use cosmic_protocols::toplevel_info::v1::server::{
|
|||
zcosmic_toplevel_info_v1::{self, ZcosmicToplevelInfoV1},
|
||||
};
|
||||
|
||||
pub struct ToplevelInfoState<D> {
|
||||
pub trait Window: IsAlive + Clone + Send {
|
||||
fn title(&self) -> String;
|
||||
fn app_id(&self) -> String;
|
||||
fn is_activated(&self) -> bool;
|
||||
fn is_maximized(&self) -> bool;
|
||||
fn is_fullscreen(&self) -> bool;
|
||||
fn is_minimized(&self) -> bool;
|
||||
fn user_data(&self) -> &UserDataMap;
|
||||
}
|
||||
|
||||
pub struct ToplevelInfoState<D, W: Window> {
|
||||
dh: DisplayHandle,
|
||||
pub(super) toplevels: Vec<Window>,
|
||||
pub(super) toplevels: Vec<W>,
|
||||
instances: Vec<ZcosmicToplevelInfoV1>,
|
||||
global: GlobalId,
|
||||
_dispatch_data: std::marker::PhantomData<D>,
|
||||
}
|
||||
|
||||
pub trait ToplevelInfoHandler: WorkspaceHandler + Sized {
|
||||
fn toplevel_info_state(&self) -> &ToplevelInfoState<Self>;
|
||||
fn toplevel_info_state_mut(&mut self) -> &mut ToplevelInfoState<Self>;
|
||||
type Window: Window;
|
||||
fn toplevel_info_state(&self) -> &ToplevelInfoState<Self, Self::Window>;
|
||||
fn toplevel_info_state_mut(&mut self) -> &mut ToplevelInfoState<Self, Self::Window>;
|
||||
}
|
||||
|
||||
pub struct ToplevelInfoGlobalData {
|
||||
|
|
@ -46,23 +52,22 @@ pub(super) struct ToplevelStateInner {
|
|||
instances: Vec<ZcosmicToplevelHandleV1>,
|
||||
outputs: Vec<Output>,
|
||||
workspaces: Vec<WorkspaceHandle>,
|
||||
minimized: bool,
|
||||
pub(super) rectangles: HashMap<ClientId, (WlSurface, Rectangle<i32, Logical>)>,
|
||||
}
|
||||
pub(super) type ToplevelState = Mutex<ToplevelStateInner>;
|
||||
|
||||
pub struct ToplevelHandleStateInner {
|
||||
pub struct ToplevelHandleStateInner<W: Window> {
|
||||
outputs: Vec<Output>,
|
||||
workspaces: Vec<WorkspaceHandle>,
|
||||
title: String,
|
||||
app_id: String,
|
||||
states: Vec<States>,
|
||||
pub(super) window: Window,
|
||||
pub(super) window: W,
|
||||
}
|
||||
pub type ToplevelHandleState = Mutex<ToplevelHandleStateInner>;
|
||||
pub type ToplevelHandleState<W> = Mutex<ToplevelHandleStateInner<W>>;
|
||||
|
||||
impl ToplevelHandleStateInner {
|
||||
fn from_window(window: &Window) -> ToplevelHandleState {
|
||||
impl<W: Window> ToplevelHandleStateInner<W> {
|
||||
fn from_window(window: &W) -> ToplevelHandleState<W> {
|
||||
ToplevelHandleState::new(ToplevelHandleStateInner {
|
||||
outputs: Vec::new(),
|
||||
workspaces: Vec::new(),
|
||||
|
|
@ -74,13 +79,15 @@ impl ToplevelHandleStateInner {
|
|||
}
|
||||
}
|
||||
|
||||
impl<D> GlobalDispatch<ZcosmicToplevelInfoV1, ToplevelInfoGlobalData, D> for ToplevelInfoState<D>
|
||||
impl<D, W> GlobalDispatch<ZcosmicToplevelInfoV1, ToplevelInfoGlobalData, D>
|
||||
for ToplevelInfoState<D, W>
|
||||
where
|
||||
D: GlobalDispatch<ZcosmicToplevelInfoV1, ToplevelInfoGlobalData>
|
||||
+ Dispatch<ZcosmicToplevelInfoV1, ()>
|
||||
+ Dispatch<ZcosmicToplevelHandleV1, ToplevelHandleState>
|
||||
+ ToplevelInfoHandler
|
||||
+ Dispatch<ZcosmicToplevelHandleV1, ToplevelHandleState<W>>
|
||||
+ ToplevelInfoHandler<Window = W>
|
||||
+ 'static,
|
||||
W: Window + 'static,
|
||||
{
|
||||
fn bind(
|
||||
state: &mut D,
|
||||
|
|
@ -92,7 +99,7 @@ where
|
|||
) {
|
||||
let instance = data_init.init(resource, ());
|
||||
for window in &state.toplevel_info_state().toplevels {
|
||||
send_toplevel_to_client::<D>(dh, Some(state.workspace_state()), &instance, window);
|
||||
send_toplevel_to_client::<D, W>(dh, Some(state.workspace_state()), &instance, window);
|
||||
}
|
||||
state.toplevel_info_state_mut().instances.push(instance);
|
||||
}
|
||||
|
|
@ -102,13 +109,14 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<D> Dispatch<ZcosmicToplevelInfoV1, (), D> for ToplevelInfoState<D>
|
||||
impl<D, W> Dispatch<ZcosmicToplevelInfoV1, (), D> for ToplevelInfoState<D, W>
|
||||
where
|
||||
D: GlobalDispatch<ZcosmicToplevelInfoV1, ToplevelInfoGlobalData>
|
||||
+ Dispatch<ZcosmicToplevelInfoV1, ()>
|
||||
+ Dispatch<ZcosmicToplevelHandleV1, ToplevelHandleState>
|
||||
+ ToplevelInfoHandler
|
||||
+ Dispatch<ZcosmicToplevelHandleV1, ToplevelHandleState<W>>
|
||||
+ ToplevelInfoHandler<Window = W>
|
||||
+ 'static,
|
||||
W: Window,
|
||||
{
|
||||
fn request(
|
||||
state: &mut D,
|
||||
|
|
@ -138,20 +146,21 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<D> Dispatch<ZcosmicToplevelHandleV1, ToplevelHandleState, D> for ToplevelInfoState<D>
|
||||
impl<D, W> Dispatch<ZcosmicToplevelHandleV1, ToplevelHandleState<W>, D> for ToplevelInfoState<D, W>
|
||||
where
|
||||
D: GlobalDispatch<ZcosmicToplevelInfoV1, ToplevelInfoGlobalData>
|
||||
+ Dispatch<ZcosmicToplevelInfoV1, ()>
|
||||
+ Dispatch<ZcosmicToplevelHandleV1, ToplevelHandleState>
|
||||
+ ToplevelInfoHandler
|
||||
+ Dispatch<ZcosmicToplevelHandleV1, ToplevelHandleState<W>>
|
||||
+ ToplevelInfoHandler<Window = W>
|
||||
+ 'static,
|
||||
W: Window,
|
||||
{
|
||||
fn request(
|
||||
_state: &mut D,
|
||||
_client: &Client,
|
||||
_obj: &ZcosmicToplevelHandleV1,
|
||||
request: zcosmic_toplevel_handle_v1::Request,
|
||||
_data: &ToplevelHandleState,
|
||||
_data: &ToplevelHandleState<W>,
|
||||
_dh: &DisplayHandle,
|
||||
_data_init: &mut DataInit<'_, D>,
|
||||
) {
|
||||
|
|
@ -165,7 +174,7 @@ where
|
|||
state: &mut D,
|
||||
_client: ClientId,
|
||||
resource: ObjectId,
|
||||
_data: &ToplevelHandleState,
|
||||
_data: &ToplevelHandleState<W>,
|
||||
) {
|
||||
for toplevel in &state.toplevel_info_state_mut().toplevels {
|
||||
if let Some(state) = toplevel.user_data().get::<ToplevelState>() {
|
||||
|
|
@ -179,15 +188,16 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<D> ToplevelInfoState<D>
|
||||
impl<D, W> ToplevelInfoState<D, W>
|
||||
where
|
||||
D: GlobalDispatch<ZcosmicToplevelInfoV1, ToplevelInfoGlobalData>
|
||||
+ Dispatch<ZcosmicToplevelInfoV1, ()>
|
||||
+ Dispatch<ZcosmicToplevelHandleV1, ToplevelHandleState>
|
||||
+ ToplevelInfoHandler
|
||||
+ Dispatch<ZcosmicToplevelHandleV1, ToplevelHandleState<W>>
|
||||
+ ToplevelInfoHandler<Window = W>
|
||||
+ 'static,
|
||||
W: Window + 'static,
|
||||
{
|
||||
pub fn new<F>(dh: &DisplayHandle, client_filter: F) -> ToplevelInfoState<D>
|
||||
pub fn new<F>(dh: &DisplayHandle, client_filter: F) -> ToplevelInfoState<D, W>
|
||||
where
|
||||
F: for<'a> Fn(&'a Client) -> bool + Send + Sync + 'static,
|
||||
{
|
||||
|
|
@ -206,35 +216,35 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new_toplevel(&mut self, toplevel: &Window) {
|
||||
pub fn new_toplevel(&mut self, toplevel: &W) {
|
||||
toplevel
|
||||
.user_data()
|
||||
.insert_if_missing(ToplevelState::default);
|
||||
for instance in &self.instances {
|
||||
send_toplevel_to_client::<D>(&self.dh, None, instance, toplevel);
|
||||
send_toplevel_to_client::<D, W>(&self.dh, None, instance, toplevel);
|
||||
}
|
||||
self.toplevels.push(toplevel.clone());
|
||||
}
|
||||
|
||||
pub fn toplevel_enter_output(&mut self, toplevel: &Window, output: &Output) {
|
||||
pub fn toplevel_enter_output(&mut self, toplevel: &W, output: &Output) {
|
||||
if let Some(state) = toplevel.user_data().get::<ToplevelState>() {
|
||||
state.lock().unwrap().outputs.push(output.clone());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn toplevel_leave_output(&mut self, toplevel: &Window, output: &Output) {
|
||||
pub fn toplevel_leave_output(&mut self, toplevel: &W, output: &Output) {
|
||||
if let Some(state) = toplevel.user_data().get::<ToplevelState>() {
|
||||
state.lock().unwrap().outputs.retain(|o| o != output);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn toplevel_enter_workspace(&mut self, toplevel: &Window, workspace: &WorkspaceHandle) {
|
||||
pub fn toplevel_enter_workspace(&mut self, toplevel: &W, workspace: &WorkspaceHandle) {
|
||||
if let Some(state) = toplevel.user_data().get::<ToplevelState>() {
|
||||
state.lock().unwrap().workspaces.push(workspace.clone());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn toplevel_leave_workspace(&mut self, toplevel: &Window, workspace: &WorkspaceHandle) {
|
||||
pub fn toplevel_leave_workspace(&mut self, toplevel: &W, workspace: &WorkspaceHandle) {
|
||||
if let Some(state) = toplevel.user_data().get::<ToplevelState>() {
|
||||
state.lock().unwrap().workspaces.retain(|w| w != workspace);
|
||||
}
|
||||
|
|
@ -252,7 +262,7 @@ where
|
|||
if window.alive() {
|
||||
std::mem::drop(state);
|
||||
for instance in &self.instances {
|
||||
send_toplevel_to_client::<D>(&self.dh, workspace_state, instance, window);
|
||||
send_toplevel_to_client::<D, W>(&self.dh, workspace_state, instance, window);
|
||||
}
|
||||
true
|
||||
} else {
|
||||
|
|
@ -276,17 +286,18 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
fn send_toplevel_to_client<D>(
|
||||
fn send_toplevel_to_client<D, W: 'static>(
|
||||
dh: &DisplayHandle,
|
||||
workspace_state: Option<&WorkspaceState<D>>,
|
||||
info: &ZcosmicToplevelInfoV1,
|
||||
window: &Window,
|
||||
window: &W,
|
||||
) where
|
||||
D: GlobalDispatch<ZcosmicToplevelInfoV1, ToplevelInfoGlobalData>
|
||||
+ Dispatch<ZcosmicToplevelInfoV1, ()>
|
||||
+ Dispatch<ZcosmicToplevelHandleV1, ToplevelHandleState>
|
||||
+ ToplevelInfoHandler
|
||||
+ Dispatch<ZcosmicToplevelHandleV1, ToplevelHandleState<W>>
|
||||
+ ToplevelInfoHandler<Window = W>
|
||||
+ 'static,
|
||||
W: Window,
|
||||
{
|
||||
let mut state = window
|
||||
.user_data()
|
||||
|
|
@ -322,90 +333,53 @@ fn send_toplevel_to_client<D>(
|
|||
};
|
||||
|
||||
let mut handle_state = instance
|
||||
.data::<ToplevelHandleState>()
|
||||
.data::<ToplevelHandleState<W>>()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.unwrap();
|
||||
let mut changed = false;
|
||||
with_states(window.toplevel().wl_surface(), |states| {
|
||||
let attributes = states
|
||||
.data_map
|
||||
.get::<Mutex<XdgToplevelSurfaceRoleAttributes>>()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.unwrap();
|
||||
if handle_state.title != window.title() {
|
||||
handle_state.title = window.title();
|
||||
instance.title(handle_state.title.clone());
|
||||
changed = true;
|
||||
}
|
||||
if handle_state.app_id != window.app_id() {
|
||||
handle_state.app_id = window.app_id();
|
||||
instance.app_id(handle_state.app_id.clone());
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if handle_state.title != attributes.title.as_deref().unwrap_or(&"") {
|
||||
handle_state.title = attributes.title.clone().unwrap_or_else(String::new);
|
||||
instance.title(handle_state.title.clone());
|
||||
changed = true;
|
||||
if (handle_state.states.contains(&States::Maximized) != window.is_maximized())
|
||||
|| (handle_state.states.contains(&States::Fullscreen) != window.is_fullscreen())
|
||||
|| (handle_state.states.contains(&States::Activated) != window.is_activated())
|
||||
|| (handle_state.states.contains(&States::Minimized) != window.is_minimized())
|
||||
{
|
||||
let mut states = Vec::new();
|
||||
if window.is_maximized() {
|
||||
states.push(States::Maximized);
|
||||
}
|
||||
if handle_state.app_id != attributes.app_id.as_deref().unwrap_or(&"") {
|
||||
handle_state.app_id = attributes.app_id.clone().unwrap_or_else(String::new);
|
||||
instance.app_id(handle_state.app_id.clone());
|
||||
changed = true;
|
||||
if window.is_fullscreen() {
|
||||
states.push(States::Fullscreen);
|
||||
}
|
||||
if window.is_activated() {
|
||||
states.push(States::Activated);
|
||||
}
|
||||
if window.is_minimized() {
|
||||
states.push(States::Minimized);
|
||||
}
|
||||
handle_state.states = states.clone();
|
||||
|
||||
if (handle_state.states.contains(&States::Maximized)
|
||||
!= attributes
|
||||
.current
|
||||
.states
|
||||
.contains(xdg_toplevel::State::Maximized))
|
||||
|| (handle_state.states.contains(&States::Fullscreen)
|
||||
!= attributes
|
||||
.current
|
||||
.states
|
||||
.contains(xdg_toplevel::State::Fullscreen))
|
||||
|| (handle_state.states.contains(&States::Activated)
|
||||
!= attributes
|
||||
.current
|
||||
.states
|
||||
.contains(xdg_toplevel::State::Activated))
|
||||
|| (handle_state.states.contains(&States::Minimized) != state.minimized)
|
||||
{
|
||||
let mut states = Vec::new();
|
||||
if attributes
|
||||
.current
|
||||
.states
|
||||
.contains(xdg_toplevel::State::Maximized)
|
||||
{
|
||||
states.push(States::Maximized);
|
||||
}
|
||||
if attributes
|
||||
.current
|
||||
.states
|
||||
.contains(xdg_toplevel::State::Fullscreen)
|
||||
{
|
||||
states.push(States::Fullscreen);
|
||||
}
|
||||
if attributes
|
||||
.current
|
||||
.states
|
||||
.contains(xdg_toplevel::State::Activated)
|
||||
{
|
||||
states.push(States::Activated);
|
||||
}
|
||||
if attributes
|
||||
.current
|
||||
.states
|
||||
.contains(xdg_toplevel::State::Maximized)
|
||||
{
|
||||
states.push(States::Maximized);
|
||||
}
|
||||
handle_state.states = states.clone();
|
||||
|
||||
let states: Vec<u8> = {
|
||||
let ratio = std::mem::size_of::<States>() / std::mem::size_of::<u8>();
|
||||
let ptr = states.as_mut_ptr() as *mut u8;
|
||||
let len = states.len() * ratio;
|
||||
let cap = states.capacity() * ratio;
|
||||
std::mem::forget(states);
|
||||
unsafe { Vec::from_raw_parts(ptr, len, cap) }
|
||||
};
|
||||
instance.state(states);
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
let states: Vec<u8> = {
|
||||
let ratio = std::mem::size_of::<States>() / std::mem::size_of::<u8>();
|
||||
let ptr = states.as_mut_ptr() as *mut u8;
|
||||
let len = states.len() * ratio;
|
||||
let cap = states.capacity() * ratio;
|
||||
std::mem::forget(states);
|
||||
unsafe { Vec::from_raw_parts(ptr, len, cap) }
|
||||
};
|
||||
instance.state(states);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if let Ok(client) = dh.get_client(instance.id()) {
|
||||
for new_output in state
|
||||
|
|
@ -464,23 +438,23 @@ fn send_toplevel_to_client<D>(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn window_from_handle(handle: ZcosmicToplevelHandleV1) -> Option<Window> {
|
||||
pub fn window_from_handle<W: Window + 'static>(handle: ZcosmicToplevelHandleV1) -> Option<W> {
|
||||
handle
|
||||
.data::<ToplevelHandleState>()
|
||||
.data::<ToplevelHandleState<W>>()
|
||||
.map(|state| state.lock().unwrap().window.clone())
|
||||
}
|
||||
|
||||
macro_rules! delegate_toplevel_info {
|
||||
($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {
|
||||
($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty, $window: ty) => {
|
||||
smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
|
||||
cosmic_protocols::toplevel_info::v1::server::zcosmic_toplevel_info_v1::ZcosmicToplevelInfoV1: $crate::wayland::protocols::toplevel_info::ToplevelInfoGlobalData
|
||||
] => $crate::wayland::protocols::toplevel_info::ToplevelInfoState<Self>);
|
||||
] => $crate::wayland::protocols::toplevel_info::ToplevelInfoState<Self, $window>);
|
||||
smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
|
||||
cosmic_protocols::toplevel_info::v1::server::zcosmic_toplevel_info_v1::ZcosmicToplevelInfoV1: ()
|
||||
] => $crate::wayland::protocols::toplevel_info::ToplevelInfoState<Self>);
|
||||
] => $crate::wayland::protocols::toplevel_info::ToplevelInfoState<Self, $window>);
|
||||
smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
|
||||
cosmic_protocols::toplevel_info::v1::server::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1: $crate::wayland::protocols::toplevel_info::ToplevelHandleState
|
||||
] => $crate::wayland::protocols::toplevel_info::ToplevelInfoState<Self>);
|
||||
cosmic_protocols::toplevel_info::v1::server::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1: $crate::wayland::protocols::toplevel_info::ToplevelHandleState<$window>
|
||||
] => $crate::wayland::protocols::toplevel_info::ToplevelInfoState<Self, $window>);
|
||||
};
|
||||
}
|
||||
pub(crate) use delegate_toplevel_info;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use smithay::{
|
||||
desktop::Window,
|
||||
input::{Seat, SeatHandler},
|
||||
output::Output,
|
||||
reexports::wayland_server::{
|
||||
|
|
@ -17,7 +16,7 @@ use cosmic_protocols::toplevel_management::v1::server::zcosmic_toplevel_manager_
|
|||
self, ZcosmicToplevelManagerV1,
|
||||
};
|
||||
|
||||
use super::toplevel_info::{window_from_handle, ToplevelInfoHandler, ToplevelState};
|
||||
use super::toplevel_info::{window_from_handle, ToplevelInfoHandler, ToplevelState, Window};
|
||||
|
||||
pub struct ToplevelManagementState {
|
||||
instances: Vec<ZcosmicToplevelManagerV1>,
|
||||
|
|
@ -25,19 +24,39 @@ pub struct ToplevelManagementState {
|
|||
global: GlobalId,
|
||||
}
|
||||
|
||||
pub trait ManagementWindow: Window {
|
||||
fn close(&self);
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
pub trait ToplevelManagementHandler: ToplevelInfoHandler + SeatHandler {
|
||||
pub trait ToplevelManagementHandler: ToplevelInfoHandler + SeatHandler
|
||||
where
|
||||
<Self as ToplevelInfoHandler>::Window: ManagementWindow,
|
||||
{
|
||||
fn toplevel_management_state(&mut self) -> &mut ToplevelManagementState;
|
||||
|
||||
fn activate(&mut self, dh: &DisplayHandle, window: &Window, seat: Option<Seat<Self>>) {}
|
||||
fn close(&mut self, dh: &DisplayHandle, window: &Window) {}
|
||||
fn activate(
|
||||
&mut self,
|
||||
dh: &DisplayHandle,
|
||||
window: &<Self as ToplevelInfoHandler>::Window,
|
||||
seat: Option<Seat<Self>>,
|
||||
) {
|
||||
}
|
||||
fn close(&mut self, dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::Window) {}
|
||||
|
||||
fn fullscreen(&mut self, dh: &DisplayHandle, window: &Window, output: Option<Output>) {}
|
||||
fn unfullscreen(&mut self, dh: &DisplayHandle, window: &Window) {}
|
||||
fn maximize(&mut self, dh: &DisplayHandle, window: &Window) {}
|
||||
fn unmaximize(&mut self, dh: &DisplayHandle, window: &Window) {}
|
||||
fn minimize(&mut self, dh: &DisplayHandle, window: &Window) {}
|
||||
fn unminimize(&mut self, dh: &DisplayHandle, window: &Window) {}
|
||||
fn fullscreen(
|
||||
&mut self,
|
||||
dh: &DisplayHandle,
|
||||
window: &<Self as ToplevelInfoHandler>::Window,
|
||||
output: Option<Output>,
|
||||
) {
|
||||
}
|
||||
fn unfullscreen(&mut self, dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::Window) {
|
||||
}
|
||||
fn maximize(&mut self, dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::Window) {}
|
||||
fn unmaximize(&mut self, dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::Window) {}
|
||||
fn minimize(&mut self, dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::Window) {}
|
||||
fn unminimize(&mut self, dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::Window) {}
|
||||
}
|
||||
|
||||
pub struct ToplevelManagerGlobalData {
|
||||
|
|
@ -55,6 +74,7 @@ impl ToplevelManagementState {
|
|||
+ Dispatch<ZcosmicToplevelManagerV1, ()>
|
||||
+ ToplevelManagementHandler
|
||||
+ 'static,
|
||||
<D as ToplevelInfoHandler>::Window: ManagementWindow,
|
||||
F: for<'a> Fn(&'a Client) -> bool + Send + Sync + 'static,
|
||||
{
|
||||
let global = dh.create_global::<D, ZcosmicToplevelManagerV1, _>(
|
||||
|
|
@ -72,7 +92,7 @@ impl ToplevelManagementState {
|
|||
|
||||
pub fn rectangle_for(
|
||||
&mut self,
|
||||
window: &Window,
|
||||
window: &impl ManagementWindow,
|
||||
client: &ClientId,
|
||||
) -> Option<(WlSurface, Rectangle<i32, Logical>)> {
|
||||
if let Some(state) = window.user_data().get::<ToplevelState>() {
|
||||
|
|
@ -94,6 +114,7 @@ where
|
|||
+ Dispatch<ZcosmicToplevelManagerV1, ()>
|
||||
+ ToplevelManagementHandler
|
||||
+ 'static,
|
||||
<D as ToplevelInfoHandler>::Window: ManagementWindow,
|
||||
{
|
||||
fn bind(
|
||||
state: &mut D,
|
||||
|
|
@ -128,6 +149,7 @@ where
|
|||
+ Dispatch<ZcosmicToplevelManagerV1, ()>
|
||||
+ ToplevelManagementHandler
|
||||
+ 'static,
|
||||
<D as ToplevelInfoHandler>::Window: ManagementWindow,
|
||||
{
|
||||
fn request(
|
||||
state: &mut D,
|
||||
|
|
@ -179,7 +201,8 @@ where
|
|||
width,
|
||||
height,
|
||||
} => {
|
||||
let window = window_from_handle(toplevel).unwrap();
|
||||
let window =
|
||||
window_from_handle::<<D as ToplevelInfoHandler>::Window>(toplevel).unwrap();
|
||||
if let Some(toplevel_state) = window.user_data().get::<ToplevelState>() {
|
||||
let mut toplevel_state = toplevel_state.lock().unwrap();
|
||||
if let Some(client) = surface.client() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue