Update for toplevel-info cctk changes

This commit is contained in:
Ian Douglas Scott 2025-02-10 14:33:51 -08:00 committed by Ian Douglas Scott
parent e283cfe456
commit 4acd62abb0
9 changed files with 90 additions and 68 deletions

34
Cargo.lock generated
View file

@ -1134,7 +1134,7 @@ dependencies = [
[[package]]
name = "cosmic-client-toolkit"
version = "0.1.0"
source = "git+https://github.com/pop-os/cosmic-protocols?rev=29ab323#29ab32305c6457fccf0728caaaf79fcac4cca665"
source = "git+https://github.com/pop-os/cosmic-protocols?rev=178eb0b#178eb0b14a0e5c192f64f6dee6c40341a8e5ee51"
dependencies = [
"cosmic-protocols",
"libc",
@ -1156,7 +1156,7 @@ dependencies = [
[[package]]
name = "cosmic-config"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#9426a985c62288e996827a3560770c19271b337a"
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
dependencies = [
"atomicwrites",
"cosmic-config-derive",
@ -1175,7 +1175,7 @@ dependencies = [
[[package]]
name = "cosmic-config-derive"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#9426a985c62288e996827a3560770c19271b337a"
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
dependencies = [
"quote",
"syn 1.0.109",
@ -1197,7 +1197,7 @@ dependencies = [
[[package]]
name = "cosmic-protocols"
version = "0.1.0"
source = "git+https://github.com/pop-os/cosmic-protocols?rev=29ab323#29ab32305c6457fccf0728caaaf79fcac4cca665"
source = "git+https://github.com/pop-os/cosmic-protocols?rev=178eb0b#178eb0b14a0e5c192f64f6dee6c40341a8e5ee51"
dependencies = [
"bitflags 2.8.0",
"wayland-backend",
@ -1233,7 +1233,7 @@ dependencies = [
[[package]]
name = "cosmic-theme"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#9426a985c62288e996827a3560770c19271b337a"
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
dependencies = [
"almost",
"cosmic-config",
@ -2517,7 +2517,7 @@ dependencies = [
[[package]]
name = "iced"
version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic#9426a985c62288e996827a3560770c19271b337a"
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
dependencies = [
"dnd",
"iced_accessibility",
@ -2535,7 +2535,7 @@ dependencies = [
[[package]]
name = "iced_accessibility"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#9426a985c62288e996827a3560770c19271b337a"
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
dependencies = [
"accesskit",
"accesskit_winit",
@ -2544,7 +2544,7 @@ dependencies = [
[[package]]
name = "iced_core"
version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic#9426a985c62288e996827a3560770c19271b337a"
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
dependencies = [
"bitflags 2.8.0",
"bytes",
@ -2568,7 +2568,7 @@ dependencies = [
[[package]]
name = "iced_futures"
version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic#9426a985c62288e996827a3560770c19271b337a"
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
dependencies = [
"futures",
"iced_core",
@ -2594,7 +2594,7 @@ dependencies = [
[[package]]
name = "iced_graphics"
version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic#9426a985c62288e996827a3560770c19271b337a"
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
dependencies = [
"bitflags 2.8.0",
"bytemuck",
@ -2616,7 +2616,7 @@ dependencies = [
[[package]]
name = "iced_renderer"
version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic#9426a985c62288e996827a3560770c19271b337a"
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
dependencies = [
"iced_graphics",
"iced_tiny_skia",
@ -2628,7 +2628,7 @@ dependencies = [
[[package]]
name = "iced_runtime"
version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic#9426a985c62288e996827a3560770c19271b337a"
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
dependencies = [
"bytes",
"cosmic-client-toolkit",
@ -2643,7 +2643,7 @@ dependencies = [
[[package]]
name = "iced_tiny_skia"
version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic#9426a985c62288e996827a3560770c19271b337a"
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
dependencies = [
"bytemuck",
"cosmic-text",
@ -2659,7 +2659,7 @@ dependencies = [
[[package]]
name = "iced_wgpu"
version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic#9426a985c62288e996827a3560770c19271b337a"
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
dependencies = [
"as-raw-xcb-connection",
"bitflags 2.8.0",
@ -2690,7 +2690,7 @@ dependencies = [
[[package]]
name = "iced_widget"
version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic#9426a985c62288e996827a3560770c19271b337a"
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
dependencies = [
"cosmic-client-toolkit",
"dnd",
@ -2708,7 +2708,7 @@ dependencies = [
[[package]]
name = "iced_winit"
version = "0.14.0-dev"
source = "git+https://github.com/pop-os/libcosmic#9426a985c62288e996827a3560770c19271b337a"
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
dependencies = [
"cosmic-client-toolkit",
"dnd",
@ -3163,7 +3163,7 @@ checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
[[package]]
name = "libcosmic"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#9426a985c62288e996827a3560770c19271b337a"
source = "git+https://github.com/pop-os/libcosmic#0b7e23444afb3f351cd947c52babb6b87f30381d"
dependencies = [
"apply",
"ashpd 0.9.2",

View file

@ -89,7 +89,7 @@ impl ZcosmicWorkspaceHandleV1 {
}
#[derive(Eq, PartialEq, Clone, Debug, Hash)]
pub struct ZcosmicToplevelHandleV1(MockObjectId);
pub struct ExtForeignToplevelHandleV1(MockObjectId);
#[derive(Clone, Debug, Default)]
pub struct CaptureFilter {
@ -147,7 +147,7 @@ impl AppData {
};
// Add three toplevels for each workspace
for j in 0..=3 {
let toplevel_handle = ZcosmicToplevelHandleV1(MockObjectId::new());
let toplevel_handle = ExtForeignToplevelHandleV1(MockObjectId::new());
let toplevel_info = ToplevelInfo {
title: format!("App {}", j),
app_id: "com.example.app".to_string(),

View file

@ -18,13 +18,12 @@ use std::collections::HashSet;
mod wayland;
#[cfg(not(feature = "mock-backend"))]
pub use cosmic::cctk::{
cosmic_protocols::{
toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
workspace::v1::client::zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1,
},
toplevel_info::ToplevelInfo,
workspace::Workspace,
cosmic_protocols::workspace::v1::client::zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1,
toplevel_info::ToplevelInfo, workspace::Workspace,
};
#[cfg(not(feature = "mock-backend"))]
pub use wayland_protocols::ext::foreign_toplevel_list::v1::client::ext_foreign_toplevel_handle_v1::ExtForeignToplevelHandleV1;
#[cfg(not(feature = "mock-backend"))]
pub use wayland::subscription;
@ -33,7 +32,7 @@ pub use wayland::subscription;
mod mock;
#[cfg(feature = "mock-backend")]
pub use mock::{
subscription, ToplevelInfo, Workspace, ZcosmicToplevelHandleV1, ZcosmicWorkspaceHandleV1,
subscription, ExtForeignToplevelHandleV1, ToplevelInfo, Workspace, ZcosmicWorkspaceHandleV1,
};
#[derive(Clone, Debug, Default)]
@ -59,19 +58,19 @@ pub enum Event {
CmdSender(calloop::channel::Sender<Cmd>),
Workspaces(Vec<(HashSet<wl_output::WlOutput>, Workspace)>),
WorkspaceCapture(ZcosmicWorkspaceHandleV1, CaptureImage),
NewToplevel(ZcosmicToplevelHandleV1, ToplevelInfo),
UpdateToplevel(ZcosmicToplevelHandleV1, ToplevelInfo),
CloseToplevel(ZcosmicToplevelHandleV1),
ToplevelCapture(ZcosmicToplevelHandleV1, CaptureImage),
NewToplevel(ExtForeignToplevelHandleV1, ToplevelInfo),
UpdateToplevel(ExtForeignToplevelHandleV1, ToplevelInfo),
CloseToplevel(ExtForeignToplevelHandleV1),
ToplevelCapture(ExtForeignToplevelHandleV1, CaptureImage),
}
#[derive(Debug)]
pub enum Cmd {
CaptureFilter(CaptureFilter),
ActivateToplevel(ZcosmicToplevelHandleV1),
CloseToplevel(ZcosmicToplevelHandleV1),
ActivateToplevel(ExtForeignToplevelHandleV1),
CloseToplevel(ExtForeignToplevelHandleV1),
MoveToplevelToWorkspace(
ZcosmicToplevelHandleV1,
ExtForeignToplevelHandleV1,
ZcosmicWorkspaceHandleV1,
wl_output::WlOutput,
),

View file

@ -75,22 +75,31 @@ impl AppData {
self.invalidate_capture_filter();
}
Cmd::ActivateToplevel(toplevel_handle) => {
for seat in self.seat_state.seats() {
self.toplevel_manager_state
.manager
.activate(&toplevel_handle, &seat);
let info = self.toplevel_info_state.info(&toplevel_handle);
if let Some(cosmic_toplevel) = info.and_then(|x| x.cosmic_toplevel.as_ref()) {
for seat in self.seat_state.seats() {
self.toplevel_manager_state
.manager
.activate(&cosmic_toplevel, &seat);
}
}
}
Cmd::CloseToplevel(toplevel_handle) => {
self.toplevel_manager_state.manager.close(&toplevel_handle);
let info = self.toplevel_info_state.info(&toplevel_handle);
if let Some(cosmic_toplevel) = info.and_then(|x| x.cosmic_toplevel.as_ref()) {
self.toplevel_manager_state.manager.close(&cosmic_toplevel);
}
}
Cmd::MoveToplevelToWorkspace(toplevel_handle, workspace_handle, output) => {
if self.toplevel_manager_state.manager.version() >= 2 {
self.toplevel_manager_state.manager.move_to_workspace(
&toplevel_handle,
&workspace_handle,
&output,
);
let info = self.toplevel_info_state.info(&toplevel_handle);
if let Some(cosmic_toplevel) = info.and_then(|x| x.cosmic_toplevel.as_ref()) {
if self.toplevel_manager_state.manager.version() >= 2 {
self.toplevel_manager_state.manager.move_to_workspace(
&cosmic_toplevel,
&workspace_handle,
&output,
);
}
}
}
Cmd::ActivateWorkspace(workspace_handle) => {
@ -105,12 +114,19 @@ impl AppData {
fn matches_capture_filter(&self, source: &CaptureSource) -> bool {
match source {
CaptureSource::CosmicToplevel(toplevel) => {
let info = self.toplevel_info_state.info(toplevel).unwrap();
info.workspace.iter().any(|workspace| {
self.capture_filter
.toplevels_on_workspaces
.contains(workspace)
})
let info = self
.toplevel_info_state
.toplevels()
.find(|info| info.cosmic_toplevel.as_ref() == Some(&toplevel));
if let Some(info) = info {
info.workspace.iter().any(|workspace| {
self.capture_filter
.toplevels_on_workspaces
.contains(workspace)
})
} else {
false
}
}
CaptureSource::CosmicWorkspace(workspace) => self
.workspace_state

View file

@ -193,7 +193,13 @@ impl ScreencopyHandler for AppData {
};
match &capture.source {
CaptureSource::CosmicToplevel(toplevel) => {
self.send_event(Event::ToplevelCapture(toplevel.clone(), image))
let info = self
.toplevel_info_state
.toplevels()
.find(|info| info.cosmic_toplevel.as_ref() == Some(&toplevel));
if let Some(info) = info {
self.send_event(Event::ToplevelCapture(info.foreign_toplevel.clone(), image))
}
}
CaptureSource::CosmicWorkspace(workspace) => {
self.send_event(Event::WorkspaceCapture(workspace.clone(), image));

View file

@ -1,13 +1,11 @@
use cctk::{
cosmic_protocols::{
toplevel_info::v1::client::zcosmic_toplevel_handle_v1,
toplevel_management::v1::client::zcosmic_toplevel_manager_v1,
},
cosmic_protocols::toplevel_management::v1::client::zcosmic_toplevel_manager_v1,
toplevel_info::{ToplevelInfoHandler, ToplevelInfoState},
toplevel_management::{ToplevelManagerHandler, ToplevelManagerState},
wayland_client::{Connection, QueueHandle, WEnum},
};
use cosmic::cctk;
use wayland_protocols::ext::foreign_toplevel_list::v1::client::ext_foreign_toplevel_handle_v1::ExtForeignToplevelHandleV1;
use super::{AppData, CaptureSource, Event};
@ -21,19 +19,20 @@ impl ToplevelInfoHandler for AppData {
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
toplevel: &zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
toplevel: &ExtForeignToplevelHandleV1,
) {
let info = self.toplevel_info_state.info(toplevel).unwrap();
let cosmic_toplevel = info.cosmic_toplevel.clone().unwrap();
self.send_event(Event::NewToplevel(toplevel.clone(), info.clone()));
self.add_capture_source(CaptureSource::CosmicToplevel(toplevel.clone()));
self.add_capture_source(CaptureSource::CosmicToplevel(cosmic_toplevel));
}
fn update_toplevel(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
toplevel: &zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
toplevel: &ExtForeignToplevelHandleV1,
) {
let info = self.toplevel_info_state.info(toplevel).unwrap();
self.send_event(Event::UpdateToplevel(toplevel.clone(), info.clone()));
@ -43,11 +42,13 @@ impl ToplevelInfoHandler for AppData {
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
toplevel: &zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
toplevel: &ExtForeignToplevelHandleV1,
) {
let info = self.toplevel_info_state.info(toplevel).unwrap();
let cosmic_toplevel = info.cosmic_toplevel.clone().unwrap();
self.send_event(Event::CloseToplevel(toplevel.clone()));
self.remove_capture_source(CaptureSource::CosmicToplevel(toplevel.clone()));
self.remove_capture_source(CaptureSource::CosmicToplevel(cosmic_toplevel));
}
}

View file

@ -6,7 +6,7 @@ use cosmic::{
};
use std::{borrow::Cow, sync::LazyLock};
use crate::backend::{ZcosmicToplevelHandleV1, ZcosmicWorkspaceHandleV1};
use crate::backend::{ExtForeignToplevelHandleV1, ZcosmicWorkspaceHandleV1};
// Include `pid` in mime. Want to drag between our surfaces, but not another
// process, if we use Wayland object ids.
@ -20,7 +20,7 @@ static TOPLEVEL_MIME: LazyLock<String> =
pub enum DragSurface {
#[allow(dead_code)]
Workspace(ZcosmicWorkspaceHandleV1),
Toplevel(ZcosmicToplevelHandleV1),
Toplevel(ExtForeignToplevelHandleV1),
}
// TODO store protocol object id?

View file

@ -43,7 +43,7 @@ mod desktop_info;
mod localize;
mod backend;
mod view;
use backend::{ToplevelInfo, ZcosmicToplevelHandleV1, ZcosmicWorkspaceHandleV1};
use backend::{ExtForeignToplevelHandleV1, ToplevelInfo, ZcosmicWorkspaceHandleV1};
mod dnd;
mod utils;
mod widgets;
@ -92,8 +92,8 @@ enum Msg {
ActivateWorkspace(ZcosmicWorkspaceHandleV1),
#[allow(dead_code)]
CloseWorkspace(ZcosmicWorkspaceHandleV1),
ActivateToplevel(ZcosmicToplevelHandleV1),
CloseToplevel(ZcosmicToplevelHandleV1),
ActivateToplevel(ExtForeignToplevelHandleV1),
CloseToplevel(ExtForeignToplevelHandleV1),
StartDrag(DragSurface),
DndEnter(DropTarget, f64, f64, Vec<String>),
DndLeave(DropTarget),
@ -125,7 +125,7 @@ struct Workspace {
#[derive(Clone, Debug)]
struct Toplevel {
handle: ZcosmicToplevelHandleV1,
handle: ExtForeignToplevelHandleV1,
info: ToplevelInfo,
img: Option<backend::CaptureImage>,
icon: Option<PathBuf>,
@ -193,7 +193,7 @@ impl App {
fn toplevel_for_handle_mut(
&mut self,
handle: &ZcosmicToplevelHandleV1,
handle: &ExtForeignToplevelHandleV1,
) -> Option<&mut Toplevel> {
self.toplevels.iter_mut().find(|i| &i.handle == handle)
}

View file

@ -376,7 +376,7 @@ fn toplevel_previews_entry<'a>(
fn toplevel_previews<'a>(
toplevels: impl Iterator<Item = &'a Toplevel>,
layout: WorkspaceLayout,
drag_toplevel: Option<&'a backend::ZcosmicToplevelHandleV1>,
drag_toplevel: Option<&'a backend::ExtForeignToplevelHandleV1>,
) -> cosmic::Element<'a, Msg> {
let (width, height) = match layout {
WorkspaceLayout::Vertical => (iced::Length::FillPortion(4), iced::Length::Fill),