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

cosmic-workspace-v2 protocol #1225

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
119 changes: 60 additions & 59 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bytemuck = "1.12"
calloop = {version = "0.14.1", features = ["executor"]}
cosmic-comp-config = {path = "cosmic-comp-config"}
cosmic-config = {git = "https://github.com/pop-os/libcosmic/", features = ["calloop", "macro"]}
cosmic-protocols = {git = "https://github.com/pop-os/cosmic-protocols", rev = "ed2a481", default-features = false, features = ["server"]}
cosmic-protocols = {git = "https://github.com/pop-os/cosmic-protocols", rev = "e706814", default-features = false, features = ["server"]}
cosmic-settings-config = { git = "https://github.com/pop-os/cosmic-settings-daemon" }
libdisplay-info = "0.2.0"
egui = {version = "0.30.0", optional = true}
Expand Down Expand Up @@ -118,5 +118,5 @@ lto = "fat"
smithay = { git = "https://github.com/smithay/smithay.git", rev = "f93476c" }

[patch."https://github.com/pop-os/cosmic-protocols"]
cosmic-protocols = { git = "https://github.com/pop-os//cosmic-protocols", rev = "ed2a481" }
cosmic-client-toolkit = { git = "https://github.com/pop-os//cosmic-protocols", rev = "ed2a481" }
cosmic-protocols = { git = "https://github.com/pop-os//cosmic-protocols", rev = "e706814" }
cosmic-client-toolkit = { git = "https://github.com/pop-os//cosmic-protocols", rev = "e706814" }
12 changes: 9 additions & 3 deletions src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use cosmic_comp_config::{
workspace::{WorkspaceLayout, WorkspaceMode},
TileBehavior, ZoomConfig, ZoomMovement,
};
use cosmic_protocols::workspace::v1::server::zcosmic_workspace_handle_v1::TilingState;
use cosmic_protocols::workspace::v2::server::zcosmic_workspace_handle_v2::TilingState;
use cosmic_settings_config::shortcuts::action::{Direction, FocusDirection, ResizeDirection};
use cosmic_settings_config::{shortcuts, window_rules::ApplicationException};
use keyframe::{ease, functions::EaseInOutCubic};
Expand Down Expand Up @@ -361,7 +361,10 @@ fn create_workspace(
if active {
state.add_workspace_state(&workspace_handle, WState::Active);
}
state.set_workspace_capabilities(&workspace_handle, WorkspaceCapabilities::Activate);
state.set_workspace_capabilities(
&workspace_handle,
WorkspaceCapabilities::Activate | WorkspaceCapabilities::SetTilingState,
);
Workspace::new(workspace_handle, output.clone(), tiling, theme.clone())
}

Expand All @@ -383,7 +386,10 @@ fn move_workspace_to_group(
None,
)
.unwrap();
workspace_state.set_workspace_capabilities(&workspace.handle, WorkspaceCapabilities::Activate);
workspace_state.set_workspace_capabilities(
&workspace.handle,
WorkspaceCapabilities::Activate | WorkspaceCapabilities::SetTilingState,
);
for window in workspace.mapped() {
for (surface, _) in window.windows() {
toplevel_leave_workspace(&surface, &old_workspace_handle);
Expand Down
2 changes: 1 addition & 1 deletion src/shell/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
};

use cosmic::theme::CosmicTheme;
use cosmic_protocols::workspace::v1::server::zcosmic_workspace_handle_v1::TilingState;
use cosmic_protocols::workspace::v2::server::zcosmic_workspace_handle_v2::TilingState;
use id_tree::Tree;
use indexmap::IndexSet;
use keyframe::{ease, functions::EaseInOutCubic};
Expand Down
8 changes: 2 additions & 6 deletions src/wayland/handlers/toplevel_management.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-only

use cosmic_protocols::workspace::v1::server::zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1;
use smithay::{
desktop::{layer_map_for_output, WindowSurfaceType},
input::{pointer::MotionEvent, Seat},
Expand All @@ -18,6 +17,7 @@ use crate::{
delegate_toplevel_management, toplevel_rectangle_for, ManagementWindow,
ToplevelManagementHandler, ToplevelManagementState,
},
workspace::WorkspaceHandle,
},
};

Expand Down Expand Up @@ -101,13 +101,9 @@ impl ToplevelManagementHandler for State {
&mut self,
_dh: &DisplayHandle,
window: &<Self as ToplevelInfoHandler>::Window,
workspace: ZcosmicWorkspaceHandleV1,
to_handle: WorkspaceHandle,
_output: Output,
) {
let Some(to_handle) = self.common.workspace_state.get_workspace_handle(&workspace) else {
return;
};

let mut shell = self.common.shell.write().unwrap();
if let Some(mut mapped) = shell.element_for_surface(window).cloned() {
if let Some(from_workspace) = shell.space_for_mut(&mapped) {
Expand Down
2 changes: 1 addition & 1 deletion src/wayland/handlers/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
WorkspaceHandler, WorkspaceState,
},
};
use cosmic_protocols::workspace::v1::server::zcosmic_workspace_handle_v1::TilingState;
use cosmic_protocols::workspace::v2::server::zcosmic_workspace_handle_v2::TilingState;
use smithay::reexports::wayland_server::DisplayHandle;

impl WorkspaceClientHandler for ClientState {
Expand Down
92 changes: 92 additions & 0 deletions src/wayland/protocols/image_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use super::{
};
use crate::shell::CosmicSurface;
use cosmic_protocols::image_source::v1::server::{
zcosmic_ext_workspace_image_source_manager_v1::{
Request as ExtWorkspaceSourceRequest, ZcosmicExtWorkspaceImageSourceManagerV1,
},
zcosmic_image_source_v1::ZcosmicImageSourceV1,
zcosmic_output_image_source_manager_v1::{
Request as OutputSourceRequest, ZcosmicOutputImageSourceManagerV1,
Expand All @@ -27,6 +30,7 @@ use wayland_backend::server::GlobalId;
pub struct ImageSourceState {
output_source_global: GlobalId,
workspace_source_global: GlobalId,
ext_workspace_source_global: GlobalId,
toplevel_source_global: GlobalId,
}

Expand Down Expand Up @@ -57,6 +61,10 @@ impl ImageSourceState {
ZcosmicWorkspaceImageSourceManagerV1,
WorkspaceImageSourceManagerGlobalData,
> + Dispatch<ZcosmicWorkspaceImageSourceManagerV1, ()>
+ GlobalDispatch<
ZcosmicExtWorkspaceImageSourceManagerV1,
WorkspaceImageSourceManagerGlobalData,
> + Dispatch<ZcosmicExtWorkspaceImageSourceManagerV1, ()>
+ GlobalDispatch<
ZcosmicToplevelImageSourceManagerV1,
ToplevelImageSourceManagerGlobalData,
Expand All @@ -80,6 +88,13 @@ impl ImageSourceState {
filter: Box::new(client_filter.clone()),
},
),
ext_workspace_source_global: display
.create_global::<D, ZcosmicExtWorkspaceImageSourceManagerV1, _>(
1,
WorkspaceImageSourceManagerGlobalData {
filter: Box::new(client_filter.clone()),
},
),
toplevel_source_global: display
.create_global::<D, ZcosmicToplevelImageSourceManagerV1, _>(
1,
Expand All @@ -98,6 +113,10 @@ impl ImageSourceState {
&self.workspace_source_global
}

pub fn ext_workspace_source_id(&self) -> &GlobalId {
&self.ext_workspace_source_global
}

pub fn toplevel_source_id(&self) -> &GlobalId {
&self.toplevel_source_global
}
Expand Down Expand Up @@ -152,6 +171,36 @@ where
}
}

impl<D>
GlobalDispatch<
ZcosmicExtWorkspaceImageSourceManagerV1,
WorkspaceImageSourceManagerGlobalData,
D,
> for ImageSourceState
where
D: GlobalDispatch<
ZcosmicExtWorkspaceImageSourceManagerV1,
WorkspaceImageSourceManagerGlobalData,
> + Dispatch<ZcosmicExtWorkspaceImageSourceManagerV1, ()>
+ Dispatch<ZcosmicImageSourceV1, ImageSourceData>
+ 'static,
{
fn bind(
_state: &mut D,
_handle: &DisplayHandle,
_client: &Client,
resource: New<ZcosmicExtWorkspaceImageSourceManagerV1>,
_global_data: &WorkspaceImageSourceManagerGlobalData,
data_init: &mut DataInit<'_, D>,
) {
data_init.init(resource, ());
}

fn can_view(client: Client, global_data: &WorkspaceImageSourceManagerGlobalData) -> bool {
(global_data.filter)(&client)
}
}

impl<D> GlobalDispatch<ZcosmicToplevelImageSourceManagerV1, ToplevelImageSourceManagerGlobalData, D>
for ImageSourceState
where
Expand Down Expand Up @@ -249,6 +298,43 @@ where
}
}

impl<D> Dispatch<ZcosmicExtWorkspaceImageSourceManagerV1, (), D> for ImageSourceState
where
D: Dispatch<ZcosmicExtWorkspaceImageSourceManagerV1, ()>
+ Dispatch<ZcosmicImageSourceV1, ImageSourceData>
+ WorkspaceHandler
+ 'static,
{
fn request(
state: &mut D,
_client: &Client,
_resource: &ZcosmicExtWorkspaceImageSourceManagerV1,
request: <ZcosmicExtWorkspaceImageSourceManagerV1 as Resource>::Request,
_data: &(),
_dhandle: &DisplayHandle,
data_init: &mut DataInit<'_, D>,
) {
match request {
ExtWorkspaceSourceRequest::CreateSource { source, output } => {
let data = match state.workspace_state().get_ext_workspace_handle(&output) {
Some(workspace) => ImageSourceData::Workspace(workspace),
None => ImageSourceData::Destroyed,
};
data_init.init(source, data);
}
_ => {}
}
}

fn destroyed(
_state: &mut D,
_client: wayland_backend::server::ClientId,
_resource: &ZcosmicExtWorkspaceImageSourceManagerV1,
_data: &(),
) {
}
}

impl<D> Dispatch<ZcosmicToplevelImageSourceManagerV1, (), D> for ImageSourceState
where
D: Dispatch<ZcosmicToplevelImageSourceManagerV1, ()>
Expand Down Expand Up @@ -329,6 +415,12 @@ macro_rules! delegate_image_source {
smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
cosmic_protocols::image_source::v1::server::zcosmic_workspace_image_source_manager_v1::ZcosmicWorkspaceImageSourceManagerV1: ()
] => $crate::wayland::protocols::image_source::ImageSourceState);
smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
cosmic_protocols::image_source::v1::server::zcosmic_ext_workspace_image_source_manager_v1::ZcosmicExtWorkspaceImageSourceManagerV1: $crate::wayland::protocols::image_source::WorkspaceImageSourceManagerGlobalData
] => $crate::wayland::protocols::image_source::ImageSourceState);
smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
cosmic_protocols::image_source::v1::server::zcosmic_ext_workspace_image_source_manager_v1::ZcosmicExtWorkspaceImageSourceManagerV1: ()
] => $crate::wayland::protocols::image_source::ImageSourceState);
smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
cosmic_protocols::image_source::v1::server::zcosmic_toplevel_image_source_manager_v1::ZcosmicToplevelImageSourceManagerV1: $crate::wayland::protocols::image_source::ToplevelImageSourceManagerGlobalData
] => $crate::wayland::protocols::image_source::ImageSourceState);
Expand Down
10 changes: 9 additions & 1 deletion src/wayland/protocols/toplevel_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ where
F: for<'a> Fn(&'a Client) -> bool + Send + Sync + Clone + 'static,
{
let global = dh.create_global::<D, ZcosmicToplevelInfoV1, _>(
2,
3,
ToplevelInfoGlobalData {
filter: Box::new(client_filter.clone()),
},
Expand Down Expand Up @@ -594,6 +594,10 @@ where
instance.workspace_enter(&handle);
changed = true;
}
for handle in workspace_state.raw_ext_workspace_handles(&new_workspace, &instance.id()) {
instance.ext_workspace_enter(&handle);
changed = true;
}
}
for old_workspace in handle_state
.workspaces
Expand All @@ -604,6 +608,10 @@ where
instance.workspace_leave(&handle);
changed = true;
}
for handle in workspace_state.raw_ext_workspace_handles(&old_workspace, &instance.id()) {
instance.ext_workspace_leave(&handle);
changed = true;
}
}
handle_state.workspaces = state.workspaces.clone();

Expand Down
38 changes: 28 additions & 10 deletions src/wayland/protocols/toplevel_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ use smithay::{
};

pub use cosmic_protocols::toplevel_management::v1::server::zcosmic_toplevel_manager_v1::ZcosmicToplelevelManagementCapabilitiesV1 as ManagementCapabilities;
use cosmic_protocols::{
toplevel_management::v1::server::zcosmic_toplevel_manager_v1::{
self, ZcosmicToplevelManagerV1,
},
workspace::v1::server::zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1,
use cosmic_protocols::toplevel_management::v1::server::zcosmic_toplevel_manager_v1::{
self, ZcosmicToplevelManagerV1,
};

use super::toplevel_info::{window_from_handle, ToplevelInfoHandler, ToplevelState, Window};
use super::{
toplevel_info::{window_from_handle, ToplevelInfoHandler, ToplevelState, Window},
workspace::WorkspaceHandle,
};

#[derive(Debug)]
pub struct ToplevelManagementState {
Expand Down Expand Up @@ -68,7 +68,7 @@ where
&mut self,
dh: &DisplayHandle,
window: &<Self as ToplevelInfoHandler>::Window,
workspace: ZcosmicWorkspaceHandleV1,
workspace: WorkspaceHandle,
output: Output,
) {
}
Expand Down Expand Up @@ -116,7 +116,7 @@ impl ToplevelManagementState {
F: for<'a> Fn(&'a Client) -> bool + Send + Sync + 'static,
{
let global = dh.create_global::<D, ZcosmicToplevelManagerV1, _>(
3,
4,
ToplevelManagerGlobalData {
filter: Box::new(client_filter),
},
Expand Down Expand Up @@ -255,8 +255,26 @@ where
output,
} => {
let window = window_from_handle(toplevel).unwrap();
if let Some(output) = Output::from_resource(&output) {
state.move_to_workspace(dh, &window, workspace, output);
if let Some(workspace_handle) =
state.workspace_state().get_workspace_handle(&workspace)
{
if let Some(output) = Output::from_resource(&output) {
state.move_to_workspace(dh, &window, workspace_handle, output);
}
}
}
zcosmic_toplevel_manager_v1::Request::MoveToExtWorkspace {
toplevel,
workspace,
output,
} => {
let window = window_from_handle(toplevel).unwrap();
if let Some(workspace_handle) =
state.workspace_state().get_ext_workspace_handle(&workspace)
{
if let Some(output) = Output::from_resource(&output) {
state.move_to_workspace(dh, &window, workspace_handle, output);
}
}
}
_ => unreachable!(),
Expand Down
Loading
Loading