Update to workspace v2, based on ext-workspace

In the workspace applet, this now uses `Workspace` in the front-end code
instead of a tuple with unnamed fields. Handling of scrolling is also
moved to the frontend, which uses less code and seems more natural. It
would be good to have a helper in libcosmic for this. It also changes
`ObjectId` to `ExtWorkspaceHandleV1`, which is a little simpler and I
see no reason here to avoid the more strongly typed object.

At some point we may want a shared subscription for workspaces in
multiple applets. As well as a higher-level abstraction for screen
capture.
This commit is contained in:
Ian Douglas Scott 2025-03-06 14:13:01 -08:00 committed by Ian Douglas Scott
parent f08d80a891
commit 7ba2ed0c53
12 changed files with 196 additions and 269 deletions

View file

@ -14,7 +14,10 @@ use cctk::{
wayland_client::protocol::{
wl_data_device_manager::DndAction, wl_output::WlOutput, wl_seat::WlSeat,
},
wayland_protocols::ext::foreign_toplevel_list::v1::client::ext_foreign_toplevel_handle_v1::ExtForeignToplevelHandleV1,
wayland_protocols::ext::{
foreign_toplevel_list::v1::client::ext_foreign_toplevel_handle_v1::ExtForeignToplevelHandleV1,
workspace::v1::client::ext_workspace_handle_v1::ExtWorkspaceHandleV1,
},
};
use cosmic::{
applet::{
@ -44,10 +47,7 @@ use cosmic::{
Apply, Element, Task,
};
use cosmic_app_list_config::{AppListConfig, APP_ID};
use cosmic_protocols::{
toplevel_info::v1::client::zcosmic_toplevel_handle_v1::State,
workspace::v1::client::zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1,
};
use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::State;
use freedesktop_desktop_entry as fde;
use freedesktop_desktop_entry::{get_languages_from_env, DesktopEntry};
use futures::future::pending;
@ -327,7 +327,7 @@ struct CosmicAppList {
dnd_offer: Option<DndOffer>,
is_listening_for_dnd: bool,
gpus: Option<Vec<Gpu>>,
active_workspaces: Vec<ZcosmicWorkspaceHandleV1>,
active_workspaces: Vec<ExtWorkspaceHandleV1>,
output_list: HashMap<WlOutput, OutputInfo>,
locales: Vec<String>,
overflow_favorites_popup: Option<window::Id>,

View file

@ -39,13 +39,15 @@ use cctk::{
},
Connection, Dispatch, QueueHandle, WEnum,
},
wayland_protocols::ext::foreign_toplevel_list::v1::client::ext_foreign_toplevel_handle_v1::ExtForeignToplevelHandleV1,
wayland_protocols::ext::{
foreign_toplevel_list::v1::client::ext_foreign_toplevel_handle_v1::ExtForeignToplevelHandleV1,
workspace::v1::client::ext_workspace_handle_v1::State as WorkspaceUpdateState,
},
workspace::{WorkspaceHandler, WorkspaceState},
};
use cosmic_protocols::{
toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
toplevel_management::v1::client::zcosmic_toplevel_manager_v1,
workspace::v1::client::zcosmic_workspace_handle_v1::State as WorkspaceUpdateState,
};
use futures::channel::mpsc::UnboundedSender;
use sctk::{
@ -129,12 +131,11 @@ impl WorkspaceHandler for AppData {
let active_workspaces = self
.workspace_state
.workspace_groups()
.iter()
.filter_map(|x| {
x.workspaces.iter().find(|w| {
w.state
.contains(&WEnum::Value(WorkspaceUpdateState::Active))
})
x.workspaces
.iter()
.filter_map(|handle| self.workspace_state.workspace_info(handle))
.find(|w| w.state.contains(WorkspaceUpdateState::Active))
})
.map(|workspace| workspace.handle.clone())
.collect::<Vec<_>>();
@ -364,7 +365,7 @@ impl CaptureData {
pub fn capture_source_shm_fd<Fd: AsFd>(
&self,
overlay_cursor: bool,
source: ZcosmicToplevelHandleV1,
source: &ExtForeignToplevelHandleV1,
fd: Fd,
len: Option<u32>,
) -> Option<ShmImage<Fd>> {
@ -379,7 +380,7 @@ impl CaptureData {
let capture_session = self
.capturer
.create_session(
&CaptureSource::CosmicToplevel(source),
&CaptureSource::Toplevel(source.clone()),
CaptureOptions::empty(),
&self.qh,
SessionData {
@ -494,9 +495,6 @@ impl AppData {
wl_shm: self.shm_state.wl_shm().clone(),
capturer: self.screencopy_state.capturer().clone(),
};
let Some(cosmic_toplevel) = self.cosmic_toplevel(&handle) else {
return;
};
std::thread::spawn(move || {
use std::ffi::CStr;
let name = unsafe { CStr::from_bytes_with_nul_unchecked(b"app-list-screencopy\0") };
@ -506,7 +504,7 @@ impl AppData {
};
// XXX is this going to use to much memory?
let img = capture_data.capture_source_shm_fd(false, cosmic_toplevel, fd, None);
let img = capture_data.capture_source_shm_fd(false, &handle, fd, None);
if let Some(img) = img {
let Ok(img) = img.image() else {
tracing::error!("Failed to get RgbaImage");

View file

@ -6,13 +6,15 @@ use cctk::{
sctk::{output::OutputInfo, reexports::calloop},
toplevel_info::ToplevelInfo,
wayland_client::protocol::wl_output::WlOutput,
wayland_protocols::ext::foreign_toplevel_list::v1::client::ext_foreign_toplevel_handle_v1::ExtForeignToplevelHandleV1,
wayland_protocols::ext::{
foreign_toplevel_list::v1::client::ext_foreign_toplevel_handle_v1::ExtForeignToplevelHandleV1,
workspace::v1::client::ext_workspace_handle_v1::ExtWorkspaceHandleV1,
},
};
use cosmic::{
iced::{self, stream, Subscription},
iced_core::image::Bytes,
};
use cosmic_protocols::workspace::v1::client::zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1;
use image::EncodableLayout;
use futures::{
@ -110,7 +112,7 @@ pub enum WaylandUpdate {
Init(calloop::channel::Sender<WaylandRequest>),
Finished,
Toplevel(ToplevelUpdate),
Workspace(Vec<ZcosmicWorkspaceHandleV1>),
Workspace(Vec<ExtWorkspaceHandleV1>),
Output(OutputUpdate),
ActivationToken {
token: Option<String>,