Skip to content
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
9 changes: 1 addition & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ zbus = { version = "5.11.0", default-features = false, features = ["tokio"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
tracing-log = "0.2.0"
tracing-journald = "0.3"
tokio = { version = "1.47.1", features = ["full"] }
cosmic-config = { git = "https://github.com/pop-os/libcosmic" }
serde = { version = "1.0.228", features = ["derive"] }
Expand All @@ -70,14 +71,6 @@ lto = "thin"
[workspace.metadata.cargo-machete]
ignored = ["libcosmic"]

# [patch."https://github.com/pop-os/libcosmic"]
# cosmic-config = { git = "https://github.com/pop-os/libcosmic//", branch = "" }
# libcosmic = { git = "https://github.com/pop-os/libcosmic//", branch = "" }
# iced_futures = { git = "https://github.com/pop-os/libcosmic//", branch = "" }
# cosmic-config = { path = "../libcosmic/cosmic-config" }
# libcosmic = { path = "../libcosmic" }
# iced_futures = { path = "../libcosmic/iced/futures" }

# [patch."https://github.com/pop-os/winit.git"]
# winit = { git = "https://github.com/rust-windowing/winit.git", rev = "241b7a80bba96c91fa3901729cd5dec66abb9be4" }
# winit = { path = "../winit" }
Expand Down
1 change: 1 addition & 0 deletions cosmic-app-list/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ tokio.workspace = true
tracing-log.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true
tracing-journald = "0.3"
url = "2.5.7"
zbus.workspace = true
11 changes: 10 additions & 1 deletion cosmic-app-list/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::Sta
use futures::future::pending;
use iced::{Alignment, Background, Length};
use rustc_hash::FxHashMap;
use std::{borrow::Cow, path::PathBuf, rc::Rc, str::FromStr, time::Duration};
use std::{
borrow::Cow,
cell::RefCell,
collections::HashMap,
path::{Path, PathBuf},
rc::Rc,
str::FromStr,
time::Duration,
sync::{Mutex, OnceLock},
};
use switcheroo_control::Gpu;
use tokio::time::sleep;
use url::Url;
Expand Down
24 changes: 23 additions & 1 deletion cosmic-app-list/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
// Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: GPL-3.0-only

use tracing_subscriber::{EnvFilter, fmt, prelude::*};

const VERSION: &str = env!("CARGO_PKG_VERSION");

fn main() -> cosmic::iced::Result {
tracing_subscriber::fmt::init();
let fmt_layer = fmt::layer().with_target(false);
let filter_layer = EnvFilter::try_from_default_env().unwrap_or_else(|_| {
if cfg!(debug_assertions) {
EnvFilter::new(format!("warn,{}=debug", env!("CARGO_CRATE_NAME")))
} else {
EnvFilter::new("warn")
}
});

if let Ok(journal_layer) = tracing_journald::layer() {
tracing_subscriber::registry()
.with(journal_layer)
.with(filter_layer.clone())
.init();
} else {
tracing_subscriber::registry()
.with(fmt_layer)
.with(filter_layer)
.init();
}

let _ = tracing_log::LogTracer::init();

tracing::info!("Starting cosmic-app-list with version {VERSION}");
Expand Down
57 changes: 25 additions & 32 deletions cosmic-applet-minimize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use cosmic::{
sctk::reexports::calloop, toplevel_info::ToplevelInfo,
wayland_protocols::ext::foreign_toplevel_list::v1::client::ext_foreign_toplevel_handle_v1::ExtForeignToplevelHandleV1,
},
desktop::fde,
desktop::{
DesktopEntryCache, DesktopLookupContext, DesktopResolveOptions, fde, resolve_desktop_entry,
},
iced::{
self, Length, Limits, Subscription,
id::Id as WidgetId,
Expand Down Expand Up @@ -55,7 +57,7 @@ pub struct App {
struct Minimize {
core: cosmic::app::Core,
locales: Vec<String>,
desktop_entries: Vec<fde::DesktopEntry>,
desktop_entries: DesktopEntryCache,
apps: Vec<App>,
tx: Option<calloop::channel::Sender<WaylandRequest>>,
overflow_popup: Option<window::Id>,
Expand Down Expand Up @@ -85,37 +87,26 @@ impl Minimize {
index
}

fn find_new_desktop_entry(&mut self, appid: &str) -> fde::DesktopEntry {
let unicase_appid = fde::unicase::Ascii::new(appid);

let de = if let Some(de) = fde::find_app_by_id(&self.desktop_entries, unicase_appid) {
de
} else {
// Update desktop entries in case it was not found.
self.update_desktop_entries();
if let Some(appid) = fde::find_app_by_id(&self.desktop_entries, unicase_appid) {
appid
} else {
tracing::warn!(appid, "could not find desktop entry for app");
let mut entry = fde::DesktopEntry {
appid: appid.to_owned(),
groups: Default::default(),
path: Default::default(),
ubuntu_gettext_domain: None,
};
entry.add_desktop_entry("Name".to_string(), appid.to_owned());
return entry;
}
};

de.clone()
// Proton/Wine behavior: see dock applet notes — shared resolver in libcosmic
// applies the Proton/Wine title matching and Game-category restriction.
fn find_new_desktop_entry(&mut self, info: &ToplevelInfo) -> fde::DesktopEntry {
let mut ctx = DesktopLookupContext::new(info.app_id.clone());
if !info.identifier.is_empty() {
ctx = ctx.with_identifier(info.identifier.clone());
}
if !info.title.is_empty() {
ctx = ctx.with_title(info.title.clone());
}
resolve_desktop_entry(
&mut self.desktop_entries,
&ctx,
&DesktopResolveOptions::default(),
)
}

// Cache all desktop entries to use when new apps are added to the dock.
fn update_desktop_entries(&mut self) {
self.desktop_entries = fde::Iter::new(fde::default_paths())
.filter_map(|p| fde::DesktopEntry::from_path(p, Some(&self.locales)).ok())
.collect::<Vec<_>>();
self.desktop_entries.refresh();
}
}

Expand All @@ -136,9 +127,11 @@ impl cosmic::Application for Minimize {
const APP_ID: &'static str = "com.system76.CosmicAppletMinimize";

fn init(core: cosmic::app::Core, _flags: ()) -> (Self, app::Task<Message>) {
let locales = fde::get_languages_from_env();
let mut app = Self {
core,
locales: fde::get_languages_from_env(),
desktop_entries: DesktopEntryCache::new(locales.clone()),
locales,
..Default::default()
};

Expand Down Expand Up @@ -181,7 +174,7 @@ impl cosmic::Application for Minimize {
}) {
if apps[pos].toplevel_info.app_id != toplevel_info.app_id {
apps[pos].desktop_entry =
self.find_new_desktop_entry(&toplevel_info.app_id);
self.find_new_desktop_entry(&toplevel_info);
apps[pos].icon_source = fde::IconSource::from_unknown(
apps[pos]
.desktop_entry
Expand All @@ -191,7 +184,7 @@ impl cosmic::Application for Minimize {
}
apps[pos].toplevel_info = toplevel_info;
} else {
let desktop_entry = self.find_new_desktop_entry(&toplevel_info.app_id);
let desktop_entry = self.find_new_desktop_entry(&toplevel_info);

apps.push(App {
name: desktop_entry
Expand Down
1 change: 1 addition & 0 deletions cosmic-applet-status-area/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ tracing.workspace = true
tracing-log.workspace = true
tracing-subscriber.workspace = true
zbus.workspace = true
tracing-journald.workspace = true
42 changes: 21 additions & 21 deletions cosmic-applet-status-area/src/components/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,12 @@ impl App {
let overflow_index = self.overflow_index().unwrap_or(0);
let children = self.menus.iter().skip(overflow_index).map(|(id, menu)| {
mouse_area(
match menu.icon_pixmap() {
Some(icon) if menu.icon_name() == "" => self
.core
.applet
.icon_button_from_handle(icon.clone().symbolic(true)),
_ => self.core.applet.icon_button(menu.icon_name()),
}
.on_press_down(Msg::TogglePopup(*id)),
self.icon_button_for_menu(menu)
.on_press_down(Msg::TogglePopup(*id)),
)
.on_enter(Msg::Hovered(*id))
.into()
});
let theme = self.core.system_theme();
let cosmic = theme.cosmic();
let corners = cosmic.corner_radii;
let pad = corners.radius_m[0];

self.core
.applet
.popup_container(container(
Expand All @@ -126,6 +115,23 @@ impl App {
))
.into()
}

fn icon_button_for_menu<'a>(
&self,
menu: &'a status_menu::State,
) -> cosmic::widget::Button<'a, Msg> {
if let Some(icon) = menu.icon_pixmap() {
if menu.icon_name().is_empty() {
self.core
.applet
.icon_button_from_handle(icon.clone().symbolic(true))
} else {
self.core.applet.icon_button_from_handle(icon.clone())
}
} else {
self.core.applet.icon_button(menu.icon_name())
}
}
}

impl cosmic::Application for App {
Expand Down Expand Up @@ -453,14 +459,8 @@ impl cosmic::Application for App {
.take(overflow_index.unwrap_or(self.menus.len()))
.map(|(id, menu)| {
mouse_area(
match menu.icon_pixmap() {
Some(icon) if menu.icon_name() == "" => self
.core
.applet
.icon_button_from_handle(icon.clone().symbolic(true)),
_ => self.core.applet.icon_button(menu.icon_name()),
}
.on_press_down(if menu.item.menu_proxy().is_some() {
self.icon_button_for_menu(menu).on_press_down(if menu.item.menu_proxy().is_some()
{
Msg::TogglePopup(*id)
} else {
Msg::StatusMenu((*id, status_menu::Msg::Click(0, true)))
Expand Down
Loading