Skip to content

Commit

Permalink
Update for toplevel-info cctk changes
Browse files Browse the repository at this point in the history
Requires pop-os/cosmic-protocols#49.

The duplication between applets, and
cosmic-workspace/xdg-desktop-portal-cosmic, should be moved to shared
abstractions. But that can be done after moving to
`ext-image-copy-capture`.
  • Loading branch information
ids1024 committed Feb 12, 2025
1 parent c133152 commit f81df52
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 72 deletions.
34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,11 @@ ignored = ["libcosmic"]
# winit = { path = "../winit" }
[patch."https://github.com/smithay/client-toolkit.git"]
sctk = { package = "smithay-client-toolkit", version = "=0.19.2" }

[patch."https://github.com/pop-os/cosmic-protocols"]
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols//", branch = "toplevel" }
cosmic-client-toolkit = { git = "https://github.com/pop-os/cosmic-protocols//", branch = "toplevel" }
[patch."https://github.com/pop-os/libcosmic"]
libcosmic = { git = "https://github.com/pop-os/libcosmic//", branch = "toplevel" }
cosmic-config = { git = "https://github.com/pop-os/libcosmic//", branch = "toplevel" }
iced_futures = { git = "https://github.com/pop-os/libcosmic//", branch = "toplevel" }
17 changes: 11 additions & 6 deletions cosmic-app-list/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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,
};
use cosmic::{
applet::{
Expand Down Expand Up @@ -44,7 +45,7 @@ use cosmic::{
};
use cosmic_app_list_config::{AppListConfig, APP_ID};
use cosmic_protocols::{
toplevel_info::v1::client::zcosmic_toplevel_handle_v1::{State, ZcosmicToplevelHandleV1},
toplevel_info::v1::client::zcosmic_toplevel_handle_v1::State,
workspace::v1::client::zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1,
};
use freedesktop_desktop_entry as fde;
Expand Down Expand Up @@ -127,7 +128,11 @@ struct DockItem {
// ID used internally in the applet. Each dock item
// have an unique id
id: u32,
toplevels: Vec<(ZcosmicToplevelHandleV1, ToplevelInfo, Option<WaylandImage>)>,
toplevels: Vec<(
ExtForeignToplevelHandleV1,
ToplevelInfo,
Option<WaylandImage>,
)>,
// Information found in the .desktop file
desktop_info: DesktopEntry<'static>,
// We must use this because the id in `DesktopEntry` is an estimation.
Expand Down Expand Up @@ -348,8 +353,8 @@ enum Message {
GpuRequest(Option<Vec<Gpu>>),
CloseRequested(window::Id),
ClosePopup,
Activate(ZcosmicToplevelHandleV1),
Toggle(ZcosmicToplevelHandleV1),
Activate(ExtForeignToplevelHandleV1),
Toggle(ExtForeignToplevelHandleV1),
Exec(String, Option<usize>),
Quit(String),
NewSeat(WlSeat),
Expand Down Expand Up @@ -2129,12 +2134,12 @@ impl CosmicAppList {
return (Some(favorite_index), active_index);
}

fn currently_active_toplevel(&self) -> Vec<ZcosmicToplevelHandleV1> {
fn currently_active_toplevel(&self) -> Vec<ExtForeignToplevelHandleV1> {
if self.active_workspaces.is_empty() {
return Vec::new();
}
let current_output = self.core.applet.output_name.clone();
let mut focused_toplevels: Vec<ZcosmicToplevelHandleV1> = Vec::new();
let mut focused_toplevels: Vec<ExtForeignToplevelHandleV1> = Vec::new();
let active_workspaces = self.active_workspaces.clone();
for toplevel_list in self.active_list.iter().chain(self.pinned_list.iter()) {
for (t_handle, t_info, _) in &toplevel_list.toplevels {
Expand Down
46 changes: 33 additions & 13 deletions cosmic-app-list/src/wayland_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ use cctk::{
},
Connection, Dispatch, QueueHandle, WEnum,
},
wayland_protocols::ext::foreign_toplevel_list::v1::client::ext_foreign_toplevel_handle_v1::ExtForeignToplevelHandleV1,
workspace::{WorkspaceHandler, WorkspaceState},
};
use cosmic_protocols::{
toplevel_info::v1::client::zcosmic_toplevel_handle_v1::{self, ZcosmicToplevelHandleV1},
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,
};
Expand Down Expand Up @@ -235,7 +236,7 @@ impl ToplevelInfoHandler for AppData {
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
toplevel: &zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
toplevel: &ExtForeignToplevelHandleV1,
) {
if let Some(info) = self.toplevel_info_state.info(toplevel) {
let _ = self
Expand All @@ -251,7 +252,7 @@ impl ToplevelInfoHandler for AppData {
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
toplevel: &zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
toplevel: &ExtForeignToplevelHandleV1,
) {
if let Some(info) = self.toplevel_info_state.info(toplevel) {
let _ = self
Expand All @@ -267,7 +268,7 @@ impl ToplevelInfoHandler for AppData {
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
toplevel: &zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
toplevel: &ExtForeignToplevelHandleV1,
) {
let _ = self
.tx
Expand Down Expand Up @@ -479,14 +480,27 @@ impl<T: AsFd> ShmImage<T> {
}

impl AppData {
fn send_image(&self, handle: ZcosmicToplevelHandleV1) {
fn cosmic_toplevel(
&self,
handle: &ExtForeignToplevelHandleV1,
) -> Option<ZcosmicToplevelHandleV1> {
self.toplevel_info_state
.info(&handle)?
.cosmic_toplevel
.clone()
}

fn send_image(&self, handle: ExtForeignToplevelHandleV1) {
let tx = self.tx.clone();
let capture_data = CaptureData {
qh: self.queue_handle.clone(),
conn: self.conn.clone(),
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") };
Expand All @@ -496,7 +510,7 @@ impl AppData {
};

// XXX is this going to use to much memory?
let img = capture_data.capture_source_shm_fd(false, handle.clone(), fd, None);
let img = capture_data.capture_source_shm_fd(false, cosmic_toplevel, fd, None);
if let Some(img) = img {
let Ok(img) = img.image() else {
tracing::error!("Failed to get RgbaImage");
Expand Down Expand Up @@ -621,18 +635,24 @@ pub(crate) fn wayland_handler(
}
WaylandRequest::Toplevel(req) => match req {
ToplevelRequest::Activate(handle) => {
if let Some(seat) = state.seat_state.seats().next() {
let manager = &state.toplevel_manager_state.manager;
manager.activate(&handle, &seat);
if let Some(cosmic_toplevel) = state.cosmic_toplevel(&handle) {
if let Some(seat) = state.seat_state.seats().next() {
let manager = &state.toplevel_manager_state.manager;
manager.activate(&cosmic_toplevel, &seat);
}
}
}
ToplevelRequest::Minimize(handle) => {
let manager = &state.toplevel_manager_state.manager;
manager.set_minimized(&handle);
if let Some(cosmic_toplevel) = state.cosmic_toplevel(&handle) {
let manager = &state.toplevel_manager_state.manager;
manager.set_minimized(&cosmic_toplevel);
}
}
ToplevelRequest::Quit(handle) => {
let manager = &state.toplevel_manager_state.manager;
manager.close(&handle);
if let Some(cosmic_toplevel) = state.cosmic_toplevel(&handle) {
let manager = &state.toplevel_manager_state.manager;
manager.close(&cosmic_toplevel);
}
}
},
WaylandRequest::TokenRequest {
Expand Down
22 changes: 10 additions & 12 deletions cosmic-app-list/src/wayland_subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ 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,
};
use cosmic::{
iced::{self, stream, Subscription},
iced_core::image::Bytes,
};
use cosmic_protocols::{
toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
workspace::v1::client::zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1,
};
use cosmic_protocols::workspace::v1::client::zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1;
use image::EncodableLayout;

use futures::{
Expand Down Expand Up @@ -120,14 +118,14 @@ pub enum WaylandUpdate {
exec: String,
gpu_idx: Option<usize>,
},
Image(ZcosmicToplevelHandleV1, WaylandImage),
Image(ExtForeignToplevelHandleV1, WaylandImage),
}

#[derive(Clone, Debug)]
pub enum ToplevelUpdate {
Add(ZcosmicToplevelHandleV1, ToplevelInfo),
Update(ZcosmicToplevelHandleV1, ToplevelInfo),
Remove(ZcosmicToplevelHandleV1),
Add(ExtForeignToplevelHandleV1, ToplevelInfo),
Update(ExtForeignToplevelHandleV1, ToplevelInfo),
Remove(ExtForeignToplevelHandleV1),
}

#[derive(Clone, Debug)]
Expand All @@ -145,12 +143,12 @@ pub enum WaylandRequest {
exec: String,
gpu_idx: Option<usize>,
},
Screencopy(ZcosmicToplevelHandleV1),
Screencopy(ExtForeignToplevelHandleV1),
}

#[derive(Debug, Clone)]
pub enum ToplevelRequest {
Activate(ZcosmicToplevelHandleV1),
Minimize(ZcosmicToplevelHandleV1),
Quit(ZcosmicToplevelHandleV1),
Activate(ExtForeignToplevelHandleV1),
Minimize(ExtForeignToplevelHandleV1),
Quit(ExtForeignToplevelHandleV1),
}
2 changes: 1 addition & 1 deletion cosmic-applet-bluetooth/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
.request_confirmation
.as_ref()
.map_or(false, |(dev, _, _)| d.address == dev.address)
&& (d.has_name() || d.is_known_device_type())
&& (d.has_name() || d.is_known_device_type())
}) {
let row = row![
icon::from_name(dev.icon.as_str()).size(16).symbolic(true),
Expand Down
Loading

0 comments on commit f81df52

Please sign in to comment.