Merge branch 'master' into bulgarian
This commit is contained in:
commit
055befb30a
272 changed files with 4273 additions and 4972 deletions
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
|
@ -19,11 +19,11 @@ jobs:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
- uses: dtolnay/rust-toolchain@master
|
- uses: dtolnay/rust-toolchain@master
|
||||||
with:
|
with:
|
||||||
toolchain: 1.85.1
|
toolchain: 1.90.0
|
||||||
components: clippy
|
components: clippy
|
||||||
- name: install dependencies
|
- name: install dependencies
|
||||||
run: sudo apt update && sudo apt install -y libxkbcommon-dev libwayland-dev libdbus-1-dev libpulse-dev libpipewire-0.3-dev libinput-dev
|
run: sudo apt update && sudo apt install -y libxkbcommon-dev libwayland-dev libdbus-1-dev libpulse-dev libpipewire-0.3-dev libinput-dev
|
||||||
- uses: actions-rs-plus/clippy-check@v2
|
- uses: actions-rs-plus/clippy-check@v2
|
||||||
with:
|
with:
|
||||||
toolchain: 1.85.1
|
toolchain: 1.90.0
|
||||||
args: --all --all-targets --all-features
|
args: --all --all-targets --all-features
|
||||||
|
|
|
||||||
1962
Cargo.lock
generated
1962
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
20
Cargo.toml
20
Cargo.toml
|
|
@ -30,8 +30,6 @@ cosmic-applets-config = { path = "cosmic-applets-config" }
|
||||||
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", default-features = false, features = [
|
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", default-features = false, features = [
|
||||||
"client",
|
"client",
|
||||||
], rev = "d0e95be" }
|
], rev = "d0e95be" }
|
||||||
cosmic-settings-subscriptions = { git = "https://github.com/pop-os/cosmic-settings-subscriptions" }
|
|
||||||
|
|
||||||
cosmic-time = { git = "https://github.com/pop-os/cosmic-time", default-features = false }
|
cosmic-time = { git = "https://github.com/pop-os/cosmic-time", default-features = false }
|
||||||
# cosmic-time = { path = "../cosmic-time", default-features = false ] }
|
# cosmic-time = { path = "../cosmic-time", default-features = false ] }
|
||||||
|
|
||||||
|
|
@ -52,15 +50,15 @@ libcosmic = { git = "https://github.com/pop-os/libcosmic", default-features = fa
|
||||||
"desktop-systemd-scope",
|
"desktop-systemd-scope",
|
||||||
"winit",
|
"winit",
|
||||||
] }
|
] }
|
||||||
rust-embed = "8.7.2"
|
rust-embed = "8.9.0"
|
||||||
rust-embed-utils = "8.7.2"
|
rust-embed-utils = "8.9.0"
|
||||||
rustc-hash = "2.1"
|
rustc-hash = "2.1"
|
||||||
rustix = { version = "1.1", features = ["fs", "process"] }
|
rustix = { version = "1.1", features = ["fs", "process"] }
|
||||||
zbus = { version = "5.11.0", default-features = false, features = ["tokio"] }
|
zbus = { version = "5.13.1", default-features = false, features = ["tokio"] }
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.22", features = ["env-filter"] }
|
||||||
tracing-log = "0.2.0"
|
tracing-log = "0.2.0"
|
||||||
tokio = { version = "1.47.1", features = ["full"] }
|
tokio = { version = "1.49.0", features = ["full"] }
|
||||||
cosmic-config = { git = "https://github.com/pop-os/libcosmic" }
|
cosmic-config = { git = "https://github.com/pop-os/libcosmic" }
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
|
|
||||||
|
|
@ -73,6 +71,9 @@ lto = "thin"
|
||||||
ignored = ["libcosmic"]
|
ignored = ["libcosmic"]
|
||||||
|
|
||||||
# [patch."https://github.com/pop-os/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" }
|
# cosmic-config = { path = "../libcosmic/cosmic-config" }
|
||||||
# libcosmic = { path = "../libcosmic" }
|
# libcosmic = { path = "../libcosmic" }
|
||||||
# iced_futures = { path = "../libcosmic/iced/futures" }
|
# iced_futures = { path = "../libcosmic/iced/futures" }
|
||||||
|
|
@ -87,3 +88,8 @@ sctk = { package = "smithay-client-toolkit", version = "0.20.0" }
|
||||||
[patch."https://github.com/pop-os/cosmic-protocols"]
|
[patch."https://github.com/pop-os/cosmic-protocols"]
|
||||||
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols//", branch = "main" }
|
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols//", branch = "main" }
|
||||||
cosmic-client-toolkit = { git = "https://github.com/pop-os/cosmic-protocols//", branch = "main" }
|
cosmic-client-toolkit = { git = "https://github.com/pop-os/cosmic-protocols//", branch = "main" }
|
||||||
|
|
||||||
|
# [patch.'https://github.com/pop-os/dbus-settings-bindings']
|
||||||
|
# cosmic-dbus-networkmanager = { path = "../dbus-settings-bindings/networkmanager" }
|
||||||
|
# upower_dbus = { path = "../dbus-settings-bindings/upower" }
|
||||||
|
# nm-secret-agent-manager = { path = "../dbus-settings-bindings/nm-secret-agent-manager" }
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "cosmic-app-list"
|
name = "cosmic-app-list"
|
||||||
version = "0.1.0"
|
version = "1.0.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "GPL-3.0-only"
|
license = "GPL-3.0-only"
|
||||||
|
|
||||||
|
|
@ -12,10 +12,9 @@ cosmic-protocols.workspace = true
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
i18n-embed.workspace = true
|
i18n-embed.workspace = true
|
||||||
i18n-embed-fl.workspace = true
|
i18n-embed-fl.workspace = true
|
||||||
image = { version = "0.25.8", default-features = false }
|
image = { version = "0.25.9", default-features = false }
|
||||||
itertools = "0.14.0"
|
|
||||||
libcosmic.workspace = true
|
libcosmic.workspace = true
|
||||||
memmap2 = "0.9.8"
|
memmap2 = "0.9.9"
|
||||||
fastrand = "2.3.0"
|
fastrand = "2.3.0"
|
||||||
rust-embed.workspace = true
|
rust-embed.workspace = true
|
||||||
rustix.workspace = true
|
rustix.workspace = true
|
||||||
|
|
@ -25,5 +24,5 @@ tokio.workspace = true
|
||||||
tracing-log.workspace = true
|
tracing-log.workspace = true
|
||||||
tracing-subscriber.workspace = true
|
tracing-subscriber.workspace = true
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
url = "2.5.7"
|
url = "2.5.8"
|
||||||
zbus.workspace = true
|
zbus.workspace = true
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "cosmic-app-list-config"
|
name = "cosmic-app-list-config"
|
||||||
version = "0.1.0"
|
version = "1.0.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use std::fmt::Debug;
|
||||||
pub const APP_ID: &str = "com.system76.CosmicAppList";
|
pub const APP_ID: &str = "com.system76.CosmicAppList";
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq, Eq)]
|
#[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq, Eq)]
|
||||||
pub enum TopLevelFilter {
|
pub enum ToplevelFilter {
|
||||||
#[default]
|
#[default]
|
||||||
ActiveWorkspace,
|
ActiveWorkspace,
|
||||||
ConfiguredOutput,
|
ConfiguredOutput,
|
||||||
|
|
@ -18,7 +18,7 @@ pub enum TopLevelFilter {
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, CosmicConfigEntry)]
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, CosmicConfigEntry)]
|
||||||
#[version = 1]
|
#[version = 1]
|
||||||
pub struct AppListConfig {
|
pub struct AppListConfig {
|
||||||
pub filter_top_levels: Option<TopLevelFilter>,
|
pub filter_top_levels: Option<ToplevelFilter>,
|
||||||
pub favorites: Vec<String>,
|
pub favorites: Vec<String>,
|
||||||
pub enable_drag_source: bool,
|
pub enable_drag_source: bool,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ Name[nl]=App-Tray
|
||||||
Name[sk]=Panel aplikácií
|
Name[sk]=Panel aplikácií
|
||||||
Name[sv]=Programfält
|
Name[sv]=Programfält
|
||||||
Name[es]=Bandeja de aplicaciones
|
Name[es]=Bandeja de aplicaciones
|
||||||
|
Name[it]=Area applicazioni
|
||||||
Type=Application
|
Type=Application
|
||||||
Exec=cosmic-app-list
|
Exec=cosmic-app-list
|
||||||
Terminal=false
|
Terminal=false
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
cosmic-app-list = درج التطبيقات
|
cosmic-app-list = درج التطبيقات
|
||||||
pin = ثبت في درج التطبيقات
|
pin = ثبِّت في درج التطبيقات
|
||||||
quit = إنهاء
|
quit = أنهِ
|
||||||
quit-all = إنهاء الكل
|
quit-all = أنهِ الكل
|
||||||
new-window = نافذة جديدة
|
new-window = نافذة جديدة
|
||||||
run = تشغيل
|
run = شغِّل
|
||||||
run-on = تشغيل على {$gpu}
|
run-on = شغِّل على { $gpu }
|
||||||
run-on-default = (الافتراضي)
|
run-on-default = (المبدئي)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
cosmic-app-list = Тава за програми
|
cosmic-app-list = Меню за програми
|
||||||
pin = Добавяне в тавата за програми
|
pin = Добавяне в менюто за програми
|
||||||
quit = Спиране на програмата
|
quit = Спиране на програмата
|
||||||
quit-all = Спиране на всички програми
|
quit-all = Спиране на всички програми
|
||||||
new-window = Нов прозорец
|
new-window = Нов прозорец
|
||||||
|
|
|
||||||
0
cosmic-app-list/i18n/bn/cosmic_app_list.ftl
Normal file
0
cosmic-app-list/i18n/bn/cosmic_app_list.ftl
Normal file
|
|
@ -1,8 +1,8 @@
|
||||||
cosmic-app-list = Barre des applications
|
cosmic-app-list = Barre des applications
|
||||||
pin = Fixer à la barre
|
pin = Épingler à la barre d'applis
|
||||||
quit = Quitter
|
quit = Quitter
|
||||||
quit-all = Tout quitter
|
quit-all = Tout quitter
|
||||||
new-window = Nouvelle fenêtre
|
new-window = Nouvelle fenêtre
|
||||||
run = Lancer
|
run = Lancer
|
||||||
run-on = Lancer avec {$gpu}
|
run-on = Lancer avec { $gpu }
|
||||||
run-on-default = (Défaut)
|
run-on-default = (Défaut)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
cosmic-app-list = Tráidire Aipeanna
|
cosmic-app-list = Tráidire aipeanna
|
||||||
pin = Bioráin go tráidire aipeanna
|
pin = Bioráin go tráidire aipeanna
|
||||||
quit = Scoir
|
quit = Scoir
|
||||||
quit-all = Scoir Uile
|
quit-all = Scoir uile
|
||||||
new-window = Fuinneog Nua
|
new-window = Fuinneog nua
|
||||||
run = Rith
|
run = Rith
|
||||||
run-on = Rith ar {$gpu}
|
run-on = Rith ar { $gpu }
|
||||||
run-on-default = (Réamhshocrú)
|
run-on-default = (Réamhshocrú)
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,5 @@ quit = Kilépés
|
||||||
quit-all = Kilépés az összesből
|
quit-all = Kilépés az összesből
|
||||||
new-window = Új ablak
|
new-window = Új ablak
|
||||||
run = Futtatás
|
run = Futtatás
|
||||||
run-on = Futtatás ezen: {$gpu}
|
run-on = Futtatás ezen: { $gpu }
|
||||||
run-on-default = (Alapértelmezett)
|
run-on-default = (Alapértelmezett)
|
||||||
|
|
|
||||||
0
cosmic-app-list/i18n/ka/cosmic_app_list.ftl
Normal file
0
cosmic-app-list/i18n/ka/cosmic_app_list.ftl
Normal file
0
cosmic-app-list/i18n/kab/cosmic_app_list.ftl
Normal file
0
cosmic-app-list/i18n/kab/cosmic_app_list.ftl
Normal file
8
cosmic-app-list/i18n/kk/cosmic_app_list.ftl
Normal file
8
cosmic-app-list/i18n/kk/cosmic_app_list.ftl
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
quit = Шығу
|
||||||
|
run = Іске қосу
|
||||||
|
run-on = { $gpu } арқылы іске қосу
|
||||||
|
run-on-default = (Әдепкі)
|
||||||
|
cosmic-app-list = Қолданбалар сөресі
|
||||||
|
pin = Таңдамалыларға қосу
|
||||||
|
quit-all = Барлығының жұмысын аяқтау
|
||||||
|
new-window = Жаңа терезе
|
||||||
0
cosmic-app-list/i18n/kmr/cosmic_app_list.ftl
Normal file
0
cosmic-app-list/i18n/kmr/cosmic_app_list.ftl
Normal file
|
|
@ -1,5 +1,8 @@
|
||||||
cosmic-app-list = 코스믹 독 앱 목록
|
cosmic-app-list = 앱 트레이
|
||||||
pin = 즐겨찾기
|
pin = 즐겨찾기
|
||||||
quit = 끝내기
|
quit = 종료
|
||||||
quit-all = 모두 끝내기
|
quit-all = 모두 끝내기
|
||||||
new-window = 새 창
|
new-window = 새 창
|
||||||
|
run = 실행
|
||||||
|
run-on = { $gpu } 에서 실행
|
||||||
|
run-on-default = (기본값)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
new-window = Naujas Langas
|
||||||
|
quit = Išeiti
|
||||||
|
run = Paleisti
|
||||||
|
run-on = Paleisti naudojantis { $gpu }
|
||||||
|
run-on-default = (Numatytas)
|
||||||
|
cosmic-app-list = Aplikacijų Dėtuvė
|
||||||
|
pin = Prisegti prie aplikacijų dėtuvės
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
cosmic-app-list = Toepassingsbalk
|
cosmic-app-list = Toepassingsbalk
|
||||||
pin = Aan de toepassingsbalk vastmaken
|
pin = Aan de toepassingsbalk vastmaken
|
||||||
quit = Toepassing sluiten
|
quit = Beëindig
|
||||||
quit-all = Alles sluiten
|
quit-all = Sluit alles
|
||||||
new-window = Nieuw venster
|
new-window = Nieuw venster
|
||||||
run = Uitvoeren
|
run = Voer uit
|
||||||
run-on = Op {$gpu} uitvoeren
|
run-on = Voer uit op { $gpu }
|
||||||
run-on-default = (Standaard)
|
run-on-default = (Standaard)
|
||||||
|
|
|
||||||
0
cosmic-app-list/i18n/pa/cosmic_app_list.ftl
Normal file
0
cosmic-app-list/i18n/pa/cosmic_app_list.ftl
Normal file
|
|
@ -1,5 +1,5 @@
|
||||||
cosmic-app-list = Bandeja de Aplicativos
|
cosmic-app-list = Bandeja de Aplicativos
|
||||||
pin = Fixar em aplicativos favoritos
|
pin = Fixar no painel
|
||||||
quit = Sair
|
quit = Sair
|
||||||
quit-all = Sair de Todos
|
quit-all = Sair de Todos
|
||||||
new-window = Nova Janela
|
new-window = Nova Janela
|
||||||
|
|
|
||||||
0
cosmic-app-list/i18n/ti/cosmic_app_list.ftl
Normal file
0
cosmic-app-list/i18n/ti/cosmic_app_list.ftl
Normal file
|
|
@ -1,8 +1,8 @@
|
||||||
cosmic-app-list = Лоток застосунків
|
cosmic-app-list = Панель застосунків
|
||||||
pin = Пришпилити до лотка застосунків
|
pin = Пришпилити до панелі застосунків
|
||||||
quit = Вийти
|
quit = Вийти
|
||||||
quit-all = Закрити всі
|
quit-all = Закрити всі
|
||||||
new-window = Нове вікно
|
new-window = Нове вікно
|
||||||
run = Запустити
|
run = Запустити
|
||||||
run-on = Запустити на { $gpu }
|
run-on = Запустити на { $gpu }
|
||||||
run-on-default = (звичайній)
|
run-on-default = (звичайний)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
cosmic-app-list = 应用托盘
|
cosmic-app-list = 应用托盘
|
||||||
pin = 固定
|
pin = 固定到应用托盘
|
||||||
quit = 退出
|
quit = 退出
|
||||||
quit-all = 全部退出
|
quit-all = 全部退出
|
||||||
new-window = 新窗口
|
new-window = 新建窗口
|
||||||
run = 运行
|
run = 运行
|
||||||
run-on = 在 {$gpu} 上运行
|
run-on = 在 { $gpu } 上运行
|
||||||
run-on-default = (Default)
|
run-on-default = (默认)
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,7 @@ use cctk::{
|
||||||
workspace::v1::client::ext_workspace_handle_v1::ExtWorkspaceHandleV1,
|
workspace::v1::client::ext_workspace_handle_v1::ExtWorkspaceHandleV1,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use cosmic::desktop::fde::unicase::Ascii;
|
use cosmic::desktop::fde::{self, DesktopEntry, get_languages_from_env, unicase::Ascii};
|
||||||
use cosmic::desktop::fde::{self, DesktopEntry, get_languages_from_env};
|
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
Apply, Element, Task, app,
|
Apply, Element, Task, app,
|
||||||
applet::{
|
applet::{
|
||||||
|
|
@ -30,14 +29,16 @@ use cosmic::{
|
||||||
cosmic_config::{Config, CosmicConfigEntry},
|
cosmic_config::{Config, CosmicConfigEntry},
|
||||||
desktop::IconSourceExt,
|
desktop::IconSourceExt,
|
||||||
iced::{
|
iced::{
|
||||||
self, Limits, Subscription,
|
self, Alignment, Background, Border, Length, Limits, Padding, Subscription,
|
||||||
clipboard::mime::{AllowedMimeTypes, AsMimeTypes},
|
clipboard::mime::{AllowedMimeTypes, AsMimeTypes},
|
||||||
event::listen_with,
|
event::listen_with,
|
||||||
platform_specific::shell::commands::popup::{destroy_popup, get_popup},
|
platform_specific::shell::commands::popup::{destroy_popup, get_popup},
|
||||||
widget::{Column, Row, column, mouse_area, row, vertical_rule, vertical_space},
|
widget::{
|
||||||
|
Column, Row, column, mouse_area, row, stack, text::Wrapping, vertical_rule,
|
||||||
|
vertical_space,
|
||||||
|
},
|
||||||
window,
|
window,
|
||||||
},
|
},
|
||||||
iced_core::{Border, Padding},
|
|
||||||
iced_runtime::{core::event, dnd::peek_dnd},
|
iced_runtime::{core::event, dnd::peek_dnd},
|
||||||
surface,
|
surface,
|
||||||
theme::{self, Button, Container},
|
theme::{self, Button, Container},
|
||||||
|
|
@ -52,7 +53,6 @@ use cosmic::{
|
||||||
use cosmic_app_list_config::{APP_ID, AppListConfig};
|
use cosmic_app_list_config::{APP_ID, AppListConfig};
|
||||||
use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::State;
|
use cosmic_protocols::toplevel_info::v1::client::zcosmic_toplevel_handle_v1::State;
|
||||||
use futures::future::pending;
|
use futures::future::pending;
|
||||||
use iced::{Alignment, Background, Length};
|
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use std::{borrow::Cow, path::PathBuf, rc::Rc, str::FromStr, time::Duration};
|
use std::{borrow::Cow, path::PathBuf, rc::Rc, str::FromStr, time::Duration};
|
||||||
use switcheroo_control::Gpu;
|
use switcheroo_control::Gpu;
|
||||||
|
|
@ -79,8 +79,13 @@ static DND_FAVORITES: u64 = u64::MAX;
|
||||||
impl AppletIconData {
|
impl AppletIconData {
|
||||||
fn new(applet: &Context) -> Self {
|
fn new(applet: &Context) -> Self {
|
||||||
let icon_size = applet.suggested_size(false).0;
|
let icon_size = applet.suggested_size(false).0;
|
||||||
let padding = applet.suggested_padding(false);
|
let (major_padding, cross_padding) = applet.suggested_padding(false);
|
||||||
let icon_spacing = 4.0;
|
let (h_padding, v_padding) = if applet.is_horizontal() {
|
||||||
|
(major_padding as f32, cross_padding as f32)
|
||||||
|
} else {
|
||||||
|
(cross_padding as f32, major_padding as f32)
|
||||||
|
};
|
||||||
|
let icon_spacing = applet.spacing as f32;
|
||||||
|
|
||||||
let (dot_radius, bar_size) = match applet.size {
|
let (dot_radius, bar_size) = match applet.size {
|
||||||
Size::Hardcoded(_) => (2.0, 8.0),
|
Size::Hardcoded(_) => (2.0, 8.0),
|
||||||
|
|
@ -98,14 +103,31 @@ impl AppletIconData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let padding = padding as f32;
|
|
||||||
|
|
||||||
let padding = match applet.anchor {
|
let padding = match applet.anchor {
|
||||||
PanelAnchor::Top => [padding - (dot_radius * 2. + 1.), padding, padding, padding],
|
PanelAnchor::Top => [
|
||||||
PanelAnchor::Bottom => [padding, padding, padding - (dot_radius * 2. + 1.), padding],
|
v_padding - (dot_radius * 2. + 1.),
|
||||||
PanelAnchor::Left => [padding, padding, padding, padding - (dot_radius * 2. + 1.)],
|
h_padding,
|
||||||
PanelAnchor::Right => [padding, padding - (dot_radius * 2. + 1.), padding, padding],
|
v_padding,
|
||||||
|
h_padding,
|
||||||
|
],
|
||||||
|
PanelAnchor::Bottom => [
|
||||||
|
v_padding,
|
||||||
|
h_padding,
|
||||||
|
v_padding - (dot_radius * 2. + 1.),
|
||||||
|
h_padding,
|
||||||
|
],
|
||||||
|
PanelAnchor::Left => [
|
||||||
|
v_padding,
|
||||||
|
h_padding,
|
||||||
|
v_padding,
|
||||||
|
h_padding - (dot_radius * 2. + 1.),
|
||||||
|
],
|
||||||
|
PanelAnchor::Right => [
|
||||||
|
v_padding,
|
||||||
|
h_padding - (dot_radius * 2. + 1.),
|
||||||
|
v_padding,
|
||||||
|
h_padding,
|
||||||
|
],
|
||||||
};
|
};
|
||||||
AppletIconData {
|
AppletIconData {
|
||||||
icon_size,
|
icon_size,
|
||||||
|
|
@ -170,12 +192,13 @@ impl DockItem {
|
||||||
|
|
||||||
let app_icon = AppletIconData::new(applet);
|
let app_icon = AppletIconData::new(applet);
|
||||||
|
|
||||||
let cosmic_icon = fde::IconSource::from_unknown(desktop_info.icon().unwrap_or_default())
|
let cosmic_icon = cosmic::widget::icon(
|
||||||
.as_cosmic_icon()
|
fde::IconSource::from_unknown(desktop_info.icon().unwrap_or_default()).as_cosmic_icon(),
|
||||||
// sets the preferred icon size variant
|
)
|
||||||
.size(128)
|
// sets the preferred icon size variant
|
||||||
.width(app_icon.icon_size.into())
|
.size(128)
|
||||||
.height(app_icon.icon_size.into());
|
.width(app_icon.icon_size.into())
|
||||||
|
.height(app_icon.icon_size.into());
|
||||||
|
|
||||||
let indicator = {
|
let indicator = {
|
||||||
let container = if toplevels.len() <= 1 {
|
let container = if toplevels.len() <= 1 {
|
||||||
|
|
@ -257,7 +280,7 @@ impl DockItem {
|
||||||
.first()
|
.first()
|
||||||
.map(|t| Message::Toggle(t.0.foreign_toplevel.clone()))
|
.map(|t| Message::Toggle(t.0.foreign_toplevel.clone()))
|
||||||
} else {
|
} else {
|
||||||
Some(Message::TopLevelListPopup(*id, window_id))
|
Some(Message::ToplevelListPopup(*id, window_id))
|
||||||
})
|
})
|
||||||
.width(Length::Shrink)
|
.width(Length::Shrink)
|
||||||
.height(Length::Shrink),
|
.height(Length::Shrink),
|
||||||
|
|
@ -335,6 +358,7 @@ struct CosmicAppList {
|
||||||
active_workspaces: Vec<ExtWorkspaceHandleV1>,
|
active_workspaces: Vec<ExtWorkspaceHandleV1>,
|
||||||
output_list: FxHashMap<WlOutput, OutputInfo>,
|
output_list: FxHashMap<WlOutput, OutputInfo>,
|
||||||
locales: Vec<String>,
|
locales: Vec<String>,
|
||||||
|
hovered_toplevel: Option<ExtForeignToplevelHandleV1>,
|
||||||
overflow_favorites_popup: Option<window::Id>,
|
overflow_favorites_popup: Option<window::Id>,
|
||||||
overflow_active_popup: Option<window::Id>,
|
overflow_active_popup: Option<window::Id>,
|
||||||
}
|
}
|
||||||
|
|
@ -342,7 +366,7 @@ struct CosmicAppList {
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum PopupType {
|
pub enum PopupType {
|
||||||
RightClickMenu,
|
RightClickMenu,
|
||||||
TopLevelList,
|
ToplevelList,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|
@ -352,13 +376,15 @@ enum Message {
|
||||||
UnpinApp(u32),
|
UnpinApp(u32),
|
||||||
Popup(u32, window::Id),
|
Popup(u32, window::Id),
|
||||||
Pressed(window::Id),
|
Pressed(window::Id),
|
||||||
TopLevelListPopup(u32, window::Id),
|
ToplevelListPopup(u32, window::Id),
|
||||||
|
ToplevelHoverChanged(ExtForeignToplevelHandleV1, bool),
|
||||||
GpuRequest(Option<Vec<Gpu>>),
|
GpuRequest(Option<Vec<Gpu>>),
|
||||||
CloseRequested(window::Id),
|
CloseRequested(window::Id),
|
||||||
ClosePopup,
|
ClosePopup,
|
||||||
Activate(ExtForeignToplevelHandleV1),
|
Activate(ExtForeignToplevelHandleV1),
|
||||||
Toggle(ExtForeignToplevelHandleV1),
|
Toggle(ExtForeignToplevelHandleV1),
|
||||||
Exec(String, Option<usize>, bool),
|
Exec(String, Option<usize>, bool),
|
||||||
|
CloseToplevel(ExtForeignToplevelHandleV1),
|
||||||
Quit(String),
|
Quit(String),
|
||||||
NewSeat(WlSeat),
|
NewSeat(WlSeat),
|
||||||
RemovedSeat,
|
RemovedSeat,
|
||||||
|
|
@ -435,58 +461,76 @@ async fn try_get_gpus() -> Option<Vec<Gpu>> {
|
||||||
Some(gpus)
|
Some(gpus)
|
||||||
}
|
}
|
||||||
|
|
||||||
const TOPLEVEL_BUTTON_WIDTH: f32 = 160.0;
|
const TOPLEVEL_BUTTON_WIDTH: f32 = 192.0;
|
||||||
const TOPLEVEL_BUTTON_HEIGHT: f32 = 130.0;
|
const TOPLEVEL_BUTTON_HEIGHT: f32 = 156.0;
|
||||||
|
|
||||||
pub fn toplevel_button<'a, Msg>(
|
fn toplevel_button<'a>(
|
||||||
img: Option<WaylandImage>,
|
img: Option<WaylandImage>,
|
||||||
on_press: Msg,
|
|
||||||
title: String,
|
title: String,
|
||||||
|
handle: ExtForeignToplevelHandleV1,
|
||||||
is_focused: bool,
|
is_focused: bool,
|
||||||
) -> cosmic::widget::Button<'a, Msg>
|
is_hovered: bool,
|
||||||
where
|
) -> Element<'a, Message> {
|
||||||
Msg: 'static + Clone,
|
let title = if title.len() > 22 {
|
||||||
{
|
format!("{:.20}...", title)
|
||||||
|
} else {
|
||||||
|
title
|
||||||
|
};
|
||||||
let border = 1.0;
|
let border = 1.0;
|
||||||
button::custom(
|
let preview = column![
|
||||||
container(
|
container(if let Some(img) = img {
|
||||||
column![
|
Element::from(Image::new(Handle::from_rgba(
|
||||||
container(if let Some(img) = img {
|
img.width,
|
||||||
Element::from(Image::new(Handle::from_rgba(
|
img.height,
|
||||||
img.width,
|
img.img.clone(),
|
||||||
img.height,
|
)))
|
||||||
img.img.clone(),
|
} else {
|
||||||
)))
|
Image::new(Handle::from_rgba(1, 1, [0u8, 0u8, 0u8, 255u8].as_slice())).into()
|
||||||
} else {
|
})
|
||||||
Image::new(Handle::from_rgba(1, 1, [0u8, 0u8, 0u8, 255u8].as_slice())).into()
|
.class(Container::custom(move |theme| container::Style {
|
||||||
})
|
border: Border {
|
||||||
.class(Container::Custom(Box::new(move |theme| {
|
color: theme.cosmic().bg_divider().into(),
|
||||||
container::Style {
|
width: border,
|
||||||
border: Border {
|
radius: 1.0.into(),
|
||||||
color: theme.cosmic().bg_divider().into(),
|
},
|
||||||
width: border,
|
..Default::default()
|
||||||
radius: 0.0.into(),
|
}))
|
||||||
},
|
.padding(border as u16)
|
||||||
..Default::default()
|
.apply(container)
|
||||||
}
|
|
||||||
})))
|
|
||||||
.padding(border as u16)
|
|
||||||
.height(Length::Shrink)
|
|
||||||
.width(Length::Shrink)
|
|
||||||
.apply(container)
|
|
||||||
.center_y(Length::Fixed(90.0)),
|
|
||||||
text::body(title),
|
|
||||||
]
|
|
||||||
.spacing(4)
|
|
||||||
.align_x(Alignment::Center),
|
|
||||||
)
|
|
||||||
.center(Length::Fill),
|
.center(Length::Fill),
|
||||||
)
|
text::body(title)
|
||||||
.on_press(on_press)
|
.wrapping(Wrapping::None)
|
||||||
.class(window_menu_style(is_focused))
|
.width(Length::Fill)
|
||||||
.width(Length::Fixed(TOPLEVEL_BUTTON_WIDTH))
|
.center()
|
||||||
.height(Length::Fixed(TOPLEVEL_BUTTON_HEIGHT))
|
]
|
||||||
.selected(is_focused)
|
.spacing(4)
|
||||||
|
.padding([4, 4, 0, 4]);
|
||||||
|
let close_button_overlay = if is_hovered {
|
||||||
|
row![
|
||||||
|
horizontal_space(),
|
||||||
|
button::custom(icon::from_name("window-close-symbolic").size(16))
|
||||||
|
.class(Button::Destructive)
|
||||||
|
.on_press(Message::CloseToplevel(handle.clone()))
|
||||||
|
.padding(4)
|
||||||
|
]
|
||||||
|
} else {
|
||||||
|
row![]
|
||||||
|
}
|
||||||
|
.width(Length::Fill)
|
||||||
|
.height(Length::Fill);
|
||||||
|
|
||||||
|
stack![preview, close_button_overlay]
|
||||||
|
.apply(button::custom)
|
||||||
|
.on_press(Message::Toggle(handle.clone()))
|
||||||
|
.class(window_menu_style(is_focused))
|
||||||
|
.width(Length::Fixed(TOPLEVEL_BUTTON_WIDTH))
|
||||||
|
.height(Length::Fixed(TOPLEVEL_BUTTON_HEIGHT))
|
||||||
|
.padding(4)
|
||||||
|
.selected(is_focused)
|
||||||
|
.apply(mouse_area)
|
||||||
|
.on_enter(Message::ToplevelHoverChanged(handle.clone(), true))
|
||||||
|
.on_exit(Message::ToplevelHoverChanged(handle, false))
|
||||||
|
.apply(Element::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn window_menu_style(selected: bool) -> cosmic::theme::Button {
|
fn window_menu_style(selected: bool) -> cosmic::theme::Button {
|
||||||
|
|
@ -567,7 +611,7 @@ fn app_list_icon_style(selected: bool) -> cosmic::theme::Button {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn menu_control_padding() -> Padding {
|
pub fn menu_control_padding() -> Padding {
|
||||||
let spacing = cosmic::theme::spacing();
|
let spacing = theme::spacing();
|
||||||
[spacing.space_xxs, spacing.space_s].into()
|
[spacing.space_xxs, spacing.space_s].into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -605,6 +649,158 @@ impl CosmicAppList {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Close any open popups.
|
||||||
|
fn close_popups(&mut self) -> Task<cosmic::Action<Message>> {
|
||||||
|
let mut commands = Vec::new();
|
||||||
|
if let Some(popup) = self.popup.take() {
|
||||||
|
commands.push(destroy_popup(popup.id));
|
||||||
|
}
|
||||||
|
if let Some(popup) = self.overflow_active_popup.take() {
|
||||||
|
commands.push(destroy_popup(popup));
|
||||||
|
}
|
||||||
|
if let Some(popup) = self.overflow_favorites_popup.take() {
|
||||||
|
commands.push(destroy_popup(popup));
|
||||||
|
}
|
||||||
|
Task::batch(commands)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the length of the group in the favorite list after which items are displayed in a popup.
|
||||||
|
/// Shrink the favorite list until it only has active windows, or until it fits in the length provided.
|
||||||
|
fn panel_overflow_lengths(&self) -> (Option<usize>, Option<usize>) {
|
||||||
|
let mut favorite_index;
|
||||||
|
let mut active_index = None;
|
||||||
|
let Some(mut max_major_axis_len) = self.core.applet.suggested_bounds.as_ref().map(|c| {
|
||||||
|
// if we have a configure for width and height, we're in a overflow popup
|
||||||
|
match self.core.applet.anchor {
|
||||||
|
PanelAnchor::Top | PanelAnchor::Bottom => c.width as u32,
|
||||||
|
PanelAnchor::Left | PanelAnchor::Right => c.height as u32,
|
||||||
|
}
|
||||||
|
}) else {
|
||||||
|
return (None, active_index);
|
||||||
|
};
|
||||||
|
// tracing::error!("{} {}", max_major_axis_len, self.pinned_list.len());
|
||||||
|
// subtract the divider width
|
||||||
|
max_major_axis_len -= 1;
|
||||||
|
let applet_icon = AppletIconData::new(&self.core.applet);
|
||||||
|
|
||||||
|
let button_total_size = self.core.applet.suggested_size(true).0
|
||||||
|
+ self.core.applet.suggested_padding(true).0 * 2
|
||||||
|
+ applet_icon.icon_spacing as u16;
|
||||||
|
|
||||||
|
let favorite_active_cnt = self
|
||||||
|
.pinned_list
|
||||||
|
.iter()
|
||||||
|
.filter(|t| !t.toplevels.is_empty())
|
||||||
|
.count();
|
||||||
|
|
||||||
|
// initial calculation of favorite_index
|
||||||
|
let btn_count = max_major_axis_len / button_total_size as u32;
|
||||||
|
if btn_count >= self.pinned_list.len() as u32 + self.active_list.len() as u32 {
|
||||||
|
return (None, active_index);
|
||||||
|
} else {
|
||||||
|
favorite_index = (btn_count as usize).min(favorite_active_cnt).max(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculation of active_index based on favorite_index if there is still not enough space
|
||||||
|
let active_index_max = (btn_count as i32)
|
||||||
|
- (self.pinned_list.len() as i32).saturating_sub(favorite_index as i32);
|
||||||
|
if active_index_max >= self.active_list.len() as i32 {
|
||||||
|
active_index = Some(self.active_list.len());
|
||||||
|
} else {
|
||||||
|
active_index = Some((active_index_max.max(2) as usize).min(self.active_list.len()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// final calculation of favorite_index if there is still not enough space
|
||||||
|
if let Some(active_index) = active_index {
|
||||||
|
let favorite_index_max = (btn_count as i32) - active_index as i32;
|
||||||
|
favorite_index = favorite_index_max.max(2) as usize;
|
||||||
|
} else {
|
||||||
|
favorite_index = (btn_count as usize).min(self.pinned_list.len());
|
||||||
|
}
|
||||||
|
// tracing::error!("{} {} {:?}", btn_count, favorite_index, active_index);
|
||||||
|
(Some(favorite_index), active_index)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn currently_active_toplevel(&self) -> Vec<ExtForeignToplevelHandleV1> {
|
||||||
|
if self.active_workspaces.is_empty() {
|
||||||
|
return Vec::new();
|
||||||
|
}
|
||||||
|
let current_output = &self.core.applet.output_name;
|
||||||
|
let mut focused_toplevels: Vec<ExtForeignToplevelHandleV1> = Vec::new();
|
||||||
|
let active_workspaces = &self.active_workspaces;
|
||||||
|
for toplevel_list in self.active_list.iter().chain(self.pinned_list.iter()) {
|
||||||
|
for (t_info, _) in &toplevel_list.toplevels {
|
||||||
|
if t_info.state.contains(&State::Activated)
|
||||||
|
&& active_workspaces
|
||||||
|
.iter()
|
||||||
|
.any(|workspace| t_info.workspace.contains(workspace))
|
||||||
|
&& t_info.output.iter().any(|x| {
|
||||||
|
self.output_list.get(x).is_some_and(|val| {
|
||||||
|
val.name.as_ref().is_some_and(|n| n == current_output)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
{
|
||||||
|
focused_toplevels.push(t_info.foreign_toplevel.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
focused_toplevels
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_desktop_entry_for_toplevel(
|
||||||
|
&mut self,
|
||||||
|
info: &ToplevelInfo,
|
||||||
|
unicase_appid: Ascii<&str>,
|
||||||
|
) -> DesktopEntry {
|
||||||
|
if let Some(appid) = fde::find_app_by_id(&self.desktop_entries, unicase_appid) {
|
||||||
|
appid.clone()
|
||||||
|
} 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.clone()
|
||||||
|
} else {
|
||||||
|
tracing::error!(id = info.app_id, "could not find desktop entry for app");
|
||||||
|
let mut fallback_entry = fde::DesktopEntry::from_appid(info.app_id.clone());
|
||||||
|
// proton opens games as steam_app_X, where X is either
|
||||||
|
// the steam appid or "default". games with a steam appid
|
||||||
|
// can have a desktop entry generated elsewhere; this
|
||||||
|
// specifically handles non-steam games opened
|
||||||
|
// under proton
|
||||||
|
// in addition, try to match WINE entries who have its
|
||||||
|
// appid = the full name of the executable (incl. .exe)
|
||||||
|
let is_proton_game = info.app_id == "steam_app_default";
|
||||||
|
if is_proton_game || info.app_id.ends_with(".exe") {
|
||||||
|
for entry in &self.desktop_entries {
|
||||||
|
let localised_name = entry.name(&self.locales).unwrap_or_default();
|
||||||
|
if localised_name == info.title {
|
||||||
|
// if this is a proton game, we only want
|
||||||
|
// to look for game entries
|
||||||
|
if is_proton_game
|
||||||
|
&& !entry.categories().unwrap_or_default().contains(&"Game")
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fallback_entry = entry.clone();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fallback_entry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a specific toplevel is focused
|
||||||
|
fn is_focused(&self, handle: &ExtForeignToplevelHandleV1) -> bool {
|
||||||
|
self.currently_active_toplevel().contains(handle)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a specific toplevel button is currently hovered
|
||||||
|
fn is_hovered(&self, handle: &ExtForeignToplevelHandleV1) -> bool {
|
||||||
|
self.hovered_toplevel.as_ref() == Some(handle)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl cosmic::Application for CosmicAppList {
|
impl cosmic::Application for CosmicAppList {
|
||||||
|
|
@ -709,7 +905,7 @@ impl cosmic::Application for CosmicAppList {
|
||||||
return Task::batch([gpu_update, get_popup(popup_settings)]);
|
return Task::batch([gpu_update, get_popup(popup_settings)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::TopLevelListPopup(id, parent_window_id) => {
|
Message::ToplevelListPopup(id, parent_window_id) => {
|
||||||
if let Some(Popup {
|
if let Some(Popup {
|
||||||
parent,
|
parent,
|
||||||
id: popup_id,
|
id: popup_id,
|
||||||
|
|
@ -746,7 +942,7 @@ impl cosmic::Application for CosmicAppList {
|
||||||
parent: parent_window_id,
|
parent: parent_window_id,
|
||||||
id: new_id,
|
id: new_id,
|
||||||
dock_item: toplevel_group.clone(),
|
dock_item: toplevel_group.clone(),
|
||||||
popup_type: PopupType::TopLevelList,
|
popup_type: PopupType::ToplevelList,
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut popup_settings = self.core.applet.get_popup_settings(
|
let mut popup_settings = self.core.applet.get_popup_settings(
|
||||||
|
|
@ -792,6 +988,14 @@ impl cosmic::Application for CosmicAppList {
|
||||||
return get_popup(popup_settings);
|
return get_popup(popup_settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Message::ToplevelHoverChanged(handle, entering) => {
|
||||||
|
match (entering, &self.hovered_toplevel) {
|
||||||
|
(true, _) => self.hovered_toplevel = Some(handle),
|
||||||
|
// prevents race condition
|
||||||
|
(false, Some(h)) if h == &handle => self.hovered_toplevel = None,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
Message::PinApp(id) => {
|
Message::PinApp(id) => {
|
||||||
if let Some(i) = self.active_list.iter().position(|t| t.id == id) {
|
if let Some(i) = self.active_list.iter().position(|t| t.id == id) {
|
||||||
let entry = self.active_list.remove(i);
|
let entry = self.active_list.remove(i);
|
||||||
|
|
@ -833,18 +1037,21 @@ impl cosmic::Application for CosmicAppList {
|
||||||
}
|
}
|
||||||
Message::Toggle(handle) => {
|
Message::Toggle(handle) => {
|
||||||
if let Some(tx) = self.wayland_sender.as_ref() {
|
if let Some(tx) = self.wayland_sender.as_ref() {
|
||||||
let _ = tx.send(WaylandRequest::Toplevel(
|
let _ = tx.send(WaylandRequest::Toplevel(if self.is_focused(&handle) {
|
||||||
if self.currently_active_toplevel().contains(&handle) {
|
ToplevelRequest::Minimize(handle)
|
||||||
ToplevelRequest::Minimize(handle)
|
} else {
|
||||||
} else {
|
ToplevelRequest::Activate(handle)
|
||||||
ToplevelRequest::Activate(handle)
|
}));
|
||||||
},
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
if let Some(p) = self.popup.take() {
|
if let Some(p) = self.popup.take() {
|
||||||
return destroy_popup(p.id);
|
return destroy_popup(p.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Message::CloseToplevel(handle) => {
|
||||||
|
if let Some(tx) = self.wayland_sender.as_ref() {
|
||||||
|
let _ = tx.send(WaylandRequest::Toplevel(ToplevelRequest::Quit(handle)));
|
||||||
|
}
|
||||||
|
}
|
||||||
Message::Quit(id) => {
|
Message::Quit(id) => {
|
||||||
if let Some(toplevel_group) = self
|
if let Some(toplevel_group) = self
|
||||||
.active_list
|
.active_list
|
||||||
|
|
@ -920,7 +1127,7 @@ impl cosmic::Application for CosmicAppList {
|
||||||
}
|
}
|
||||||
Message::DndEnter(x, y) => {
|
Message::DndEnter(x, y) => {
|
||||||
let item_size = self.core.applet.suggested_size(false).0
|
let item_size = self.core.applet.suggested_size(false).0
|
||||||
+ 2 * self.core.applet.suggested_padding(false);
|
+ 2 * self.core.applet.suggested_padding(false).0;
|
||||||
let pos_in_list = match self.core.applet.anchor {
|
let pos_in_list = match self.core.applet.anchor {
|
||||||
PanelAnchor::Top | PanelAnchor::Bottom => x as f32,
|
PanelAnchor::Top | PanelAnchor::Bottom => x as f32,
|
||||||
PanelAnchor::Left | PanelAnchor::Right => y as f32,
|
PanelAnchor::Left | PanelAnchor::Right => y as f32,
|
||||||
|
|
@ -942,7 +1149,7 @@ impl cosmic::Application for CosmicAppList {
|
||||||
}
|
}
|
||||||
Message::DndMotion(x, y) => {
|
Message::DndMotion(x, y) => {
|
||||||
let item_size = self.core.applet.suggested_size(false).0
|
let item_size = self.core.applet.suggested_size(false).0
|
||||||
+ 2 * self.core.applet.suggested_padding(false);
|
+ 2 * self.core.applet.suggested_padding(false).0;
|
||||||
let pos_in_list = match self.core.applet.anchor {
|
let pos_in_list = match self.core.applet.anchor {
|
||||||
PanelAnchor::Top | PanelAnchor::Bottom => x as f32,
|
PanelAnchor::Top | PanelAnchor::Bottom => x as f32,
|
||||||
PanelAnchor::Left | PanelAnchor::Right => y as f32,
|
PanelAnchor::Left | PanelAnchor::Right => y as f32,
|
||||||
|
|
@ -1122,6 +1329,21 @@ impl cosmic::Application for CosmicAppList {
|
||||||
.retain(|(info, _)| info.foreign_toplevel != handle);
|
.retain(|(info, _)| info.foreign_toplevel != handle);
|
||||||
}
|
}
|
||||||
self.active_list.retain(|t| !t.toplevels.is_empty());
|
self.active_list.retain(|t| !t.toplevels.is_empty());
|
||||||
|
|
||||||
|
if let Some(popup) = &mut self.popup
|
||||||
|
&& popup.popup_type == PopupType::ToplevelList
|
||||||
|
{
|
||||||
|
popup
|
||||||
|
.dock_item
|
||||||
|
.toplevels
|
||||||
|
.retain(|(info, _)| info.foreign_toplevel != handle);
|
||||||
|
|
||||||
|
if popup.dock_item.toplevels.is_empty() {
|
||||||
|
let id = popup.id;
|
||||||
|
self.popup = None;
|
||||||
|
return destroy_popup(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ToplevelUpdate::Update(info) => {
|
ToplevelUpdate::Update(info) => {
|
||||||
// TODO probably want to make sure it is removed
|
// TODO probably want to make sure it is removed
|
||||||
|
|
@ -1350,7 +1572,7 @@ impl cosmic::Application for CosmicAppList {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let applet_suggested_size = self.core.applet.suggested_size(false).0
|
let applet_suggested_size = self.core.applet.suggested_size(false).0
|
||||||
+ 2 * self.core.applet.suggested_padding(false);
|
+ 2 * self.core.applet.suggested_padding(false).0;
|
||||||
let (_favorite_popup_cutoff, active_popup_cutoff) =
|
let (_favorite_popup_cutoff, active_popup_cutoff) =
|
||||||
self.panel_overflow_lengths();
|
self.panel_overflow_lengths();
|
||||||
let popup_applet_count =
|
let popup_applet_count =
|
||||||
|
|
@ -1407,7 +1629,7 @@ impl cosmic::Application for CosmicAppList {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let applet_suggested_size = self.core.applet.suggested_size(false).0
|
let applet_suggested_size = self.core.applet.suggested_size(false).0
|
||||||
+ 2 * self.core.applet.suggested_padding(false);
|
+ 2 * self.core.applet.suggested_padding(false).0;
|
||||||
let (favorite_popup_cutoff, _active_popup_cutoff) =
|
let (favorite_popup_cutoff, _active_popup_cutoff) =
|
||||||
self.panel_overflow_lengths();
|
self.panel_overflow_lengths();
|
||||||
let popup_applet_count =
|
let popup_applet_count =
|
||||||
|
|
@ -1573,7 +1795,7 @@ impl cosmic::Application for CosmicAppList {
|
||||||
icon::from_name("starred-symbolic.symbolic")
|
icon::from_name("starred-symbolic.symbolic")
|
||||||
.size(self.core.applet.suggested_size(false).0),
|
.size(self.core.applet.suggested_size(false).0),
|
||||||
)
|
)
|
||||||
.padding(self.core.applet.suggested_padding(false))
|
.padding(self.core.applet.suggested_padding(false).1) // TODO
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -1643,13 +1865,13 @@ impl cosmic::Application for CosmicAppList {
|
||||||
let window_size = self.core.applet.suggested_bounds.as_ref();
|
let window_size = self.core.applet.suggested_bounds.as_ref();
|
||||||
let max_num = if self.core.applet.is_horizontal() {
|
let max_num = if self.core.applet.is_horizontal() {
|
||||||
let suggested_width = self.core.applet.suggested_size(false).0
|
let suggested_width = self.core.applet.suggested_size(false).0
|
||||||
+ self.core.applet.suggested_padding(false) * 2;
|
+ self.core.applet.suggested_padding(false).0 * 2;
|
||||||
window_size
|
window_size
|
||||||
.map(|w| w.width)
|
.map(|w| w.width)
|
||||||
.map_or(u32::MAX, |b| (b / suggested_width as f32) as u32) as usize
|
.map_or(u32::MAX, |b| (b / suggested_width as f32) as u32) as usize
|
||||||
} else {
|
} else {
|
||||||
let suggested_height = self.core.applet.suggested_size(false).1
|
let suggested_height = self.core.applet.suggested_size(false).1
|
||||||
+ self.core.applet.suggested_padding(false) * 2;
|
+ self.core.applet.suggested_padding(false).0 * 2;
|
||||||
window_size
|
window_size
|
||||||
.map(|w| w.height)
|
.map(|w| w.height)
|
||||||
.map_or(u32::MAX, |b| (b / suggested_height as f32) as u32) as usize
|
.map_or(u32::MAX, |b| (b / suggested_height as f32) as u32) as usize
|
||||||
|
|
@ -1756,10 +1978,12 @@ impl cosmic::Application for CosmicAppList {
|
||||||
let theme = self.core.system_theme();
|
let theme = self.core.system_theme();
|
||||||
|
|
||||||
if let Some((_, item, _, _)) = self.dnd_source.as_ref().filter(|s| s.0 == id) {
|
if let Some((_, item, _, _)) = self.dnd_source.as_ref().filter(|s| s.0 == id) {
|
||||||
fde::IconSource::from_unknown(item.desktop_info.icon().unwrap_or_default())
|
cosmic::widget::icon(
|
||||||
.as_cosmic_icon()
|
fde::IconSource::from_unknown(item.desktop_info.icon().unwrap_or_default())
|
||||||
.size(self.core.applet.suggested_size(false).0)
|
.as_cosmic_icon(),
|
||||||
.into()
|
)
|
||||||
|
.size(self.core.applet.suggested_size(false).0)
|
||||||
|
.into()
|
||||||
} else if let Some(Popup {
|
} else if let Some(Popup {
|
||||||
dock_item: DockItem { id, .. },
|
dock_item: DockItem { id, .. },
|
||||||
popup_type,
|
popup_type,
|
||||||
|
|
@ -1787,7 +2011,7 @@ impl cosmic::Application for CosmicAppList {
|
||||||
content: impl Into<Element<'a, Message>>,
|
content: impl Into<Element<'a, Message>>,
|
||||||
) -> cosmic::widget::Button<'a, Message> {
|
) -> cosmic::widget::Button<'a, Message> {
|
||||||
button::custom(content)
|
button::custom(content)
|
||||||
.height(20 + 2 * theme::active().cosmic().space_xxs())
|
.height(20 + 2 * theme::spacing().space_xxs)
|
||||||
.class(Button::MenuItem)
|
.class(Button::MenuItem)
|
||||||
.padding(menu_control_padding())
|
.padding(menu_control_padding())
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
|
|
@ -1935,22 +2159,17 @@ impl cosmic::Application for CosmicAppList {
|
||||||
)
|
)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
PopupType::TopLevelList => match self.core.applet.anchor {
|
PopupType::ToplevelList => match self.core.applet.anchor {
|
||||||
PanelAnchor::Left | PanelAnchor::Right => {
|
PanelAnchor::Left | PanelAnchor::Right => {
|
||||||
let mut content =
|
let mut content =
|
||||||
column![].padding(8).align_x(Alignment::Center).spacing(8);
|
column![].padding(8).align_x(Alignment::Center).spacing(8);
|
||||||
for (info, img) in toplevels {
|
for (info, img) in toplevels {
|
||||||
let title = if info.title.len() > 18 {
|
|
||||||
format!("{:.16}...", &info.title)
|
|
||||||
} else {
|
|
||||||
info.title.clone()
|
|
||||||
};
|
|
||||||
content = content.push(toplevel_button(
|
content = content.push(toplevel_button(
|
||||||
img.clone(),
|
img.clone(),
|
||||||
Message::Toggle(info.foreign_toplevel.clone()),
|
info.title.clone(),
|
||||||
title,
|
info.foreign_toplevel.clone(),
|
||||||
self.currently_active_toplevel()
|
self.is_focused(&info.foreign_toplevel),
|
||||||
.contains(&info.foreign_toplevel),
|
self.is_hovered(&info.foreign_toplevel),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
self.core
|
self.core
|
||||||
|
|
@ -1962,17 +2181,12 @@ impl cosmic::Application for CosmicAppList {
|
||||||
PanelAnchor::Bottom | PanelAnchor::Top => {
|
PanelAnchor::Bottom | PanelAnchor::Top => {
|
||||||
let mut content = row![].padding(8).align_y(Alignment::Center).spacing(8);
|
let mut content = row![].padding(8).align_y(Alignment::Center).spacing(8);
|
||||||
for (info, img) in toplevels {
|
for (info, img) in toplevels {
|
||||||
let title = if info.title.len() > 18 {
|
|
||||||
format!("{:.16}...", &info.title)
|
|
||||||
} else {
|
|
||||||
info.title.clone()
|
|
||||||
};
|
|
||||||
content = content.push(toplevel_button(
|
content = content.push(toplevel_button(
|
||||||
img.clone(),
|
img.clone(),
|
||||||
Message::Toggle(info.foreign_toplevel.clone()),
|
info.title.clone(),
|
||||||
title,
|
info.foreign_toplevel.clone(),
|
||||||
self.currently_active_toplevel()
|
self.is_focused(&info.foreign_toplevel),
|
||||||
.contains(&info.foreign_toplevel),
|
self.is_hovered(&info.foreign_toplevel),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
self.core
|
self.core
|
||||||
|
|
@ -1993,44 +2207,46 @@ impl cosmic::Application for CosmicAppList {
|
||||||
let focused_item = self.currently_active_toplevel();
|
let focused_item = self.currently_active_toplevel();
|
||||||
let dot_radius = theme.cosmic().radius_xs();
|
let dot_radius = theme.cosmic().radius_xs();
|
||||||
// show the overflow popup for active list
|
// show the overflow popup for active list
|
||||||
let active: Vec<_> =
|
let active: Vec<_> = self
|
||||||
self.active_list[..active_popup_cutoff.map_or(self.active_list.len(), |n| {
|
.active_list
|
||||||
|
.iter()
|
||||||
|
.rev()
|
||||||
|
.take(active_popup_cutoff.map_or(self.active_list.len(), |n| {
|
||||||
if n < self.active_list.len() {
|
if n < self.active_list.len() {
|
||||||
n.saturating_sub(1)
|
self.active_list.len() - n + 1
|
||||||
} else {
|
} else {
|
||||||
n - 1
|
0
|
||||||
}
|
}
|
||||||
})]
|
}))
|
||||||
.iter()
|
.map(|dock_item| {
|
||||||
.map(|dock_item| {
|
self.core
|
||||||
self.core
|
.applet
|
||||||
.applet
|
.applet_tooltip(
|
||||||
.applet_tooltip(
|
dock_item.as_icon(
|
||||||
dock_item.as_icon(
|
&self.core.applet,
|
||||||
&self.core.applet,
|
self.rectangle_tracker.as_ref(),
|
||||||
self.rectangle_tracker.as_ref(),
|
self.popup.is_none(),
|
||||||
self.popup.is_none(),
|
self.config.enable_drag_source,
|
||||||
self.config.enable_drag_source,
|
self.gpus.as_deref(),
|
||||||
self.gpus.as_deref(),
|
|
||||||
dock_item
|
|
||||||
.toplevels
|
|
||||||
.iter()
|
|
||||||
.any(|y| focused_item.contains(&y.0.foreign_toplevel)),
|
|
||||||
dot_radius,
|
|
||||||
self.core.main_window_id().unwrap(),
|
|
||||||
),
|
|
||||||
dock_item
|
dock_item
|
||||||
.desktop_info
|
.toplevels
|
||||||
.full_name(&self.locales)
|
.iter()
|
||||||
.unwrap_or_default()
|
.any(|y| focused_item.contains(&y.0.foreign_toplevel)),
|
||||||
.into_owned(),
|
dot_radius,
|
||||||
self.popup.is_some(),
|
id,
|
||||||
Message::Surface,
|
),
|
||||||
None,
|
dock_item
|
||||||
)
|
.desktop_info
|
||||||
.into()
|
.full_name(&self.locales)
|
||||||
})
|
.unwrap_or_default()
|
||||||
.collect();
|
.into_owned(),
|
||||||
|
self.popup.is_some(),
|
||||||
|
Message::Surface,
|
||||||
|
Some(id),
|
||||||
|
)
|
||||||
|
.into()
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
let content = match &self.core.applet.anchor {
|
let content = match &self.core.applet.anchor {
|
||||||
PanelAnchor::Left | PanelAnchor::Right => container(
|
PanelAnchor::Left | PanelAnchor::Right => container(
|
||||||
Column::with_children(active)
|
Column::with_children(active)
|
||||||
|
|
@ -2212,155 +2428,6 @@ impl cosmic::Application for CosmicAppList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CosmicAppList {
|
|
||||||
/// Close any open popups.
|
|
||||||
fn close_popups(&mut self) -> Task<cosmic::Action<Message>> {
|
|
||||||
let mut commands = Vec::new();
|
|
||||||
if let Some(popup) = self.popup.take() {
|
|
||||||
commands.push(destroy_popup(popup.id));
|
|
||||||
}
|
|
||||||
if let Some(popup) = self.overflow_active_popup.take() {
|
|
||||||
commands.push(destroy_popup(popup));
|
|
||||||
}
|
|
||||||
if let Some(popup) = self.overflow_favorites_popup.take() {
|
|
||||||
commands.push(destroy_popup(popup));
|
|
||||||
}
|
|
||||||
Task::batch(commands)
|
|
||||||
}
|
|
||||||
/// Returns the length of the group in the favorite list after which items are displayed in a popup.
|
|
||||||
/// Shrink the favorite list until it only has active windows, or until it fits in the length provided.
|
|
||||||
fn panel_overflow_lengths(&self) -> (Option<usize>, Option<usize>) {
|
|
||||||
let mut favorite_index;
|
|
||||||
let mut active_index = None;
|
|
||||||
let Some(mut max_major_axis_len) = self.core.applet.suggested_bounds.as_ref().map(|c| {
|
|
||||||
// if we have a configure for width and height, we're in a overflow popup
|
|
||||||
match self.core.applet.anchor {
|
|
||||||
PanelAnchor::Top | PanelAnchor::Bottom => c.width as u32,
|
|
||||||
PanelAnchor::Left | PanelAnchor::Right => c.height as u32,
|
|
||||||
}
|
|
||||||
}) else {
|
|
||||||
return (None, active_index);
|
|
||||||
};
|
|
||||||
// tracing::error!("{} {}", max_major_axis_len, self.pinned_list.len());
|
|
||||||
// subtract the divider width
|
|
||||||
max_major_axis_len -= 1;
|
|
||||||
let applet_icon = AppletIconData::new(&self.core.applet);
|
|
||||||
|
|
||||||
let button_total_size = self.core.applet.suggested_size(true).0
|
|
||||||
+ self.core.applet.suggested_padding(true) * 2
|
|
||||||
+ applet_icon.icon_spacing as u16;
|
|
||||||
|
|
||||||
let favorite_active_cnt = self
|
|
||||||
.pinned_list
|
|
||||||
.iter()
|
|
||||||
.filter(|t| !t.toplevels.is_empty())
|
|
||||||
.count();
|
|
||||||
|
|
||||||
// initial calculation of favorite_index
|
|
||||||
let btn_count = max_major_axis_len / button_total_size as u32;
|
|
||||||
if btn_count >= self.pinned_list.len() as u32 + self.active_list.len() as u32 {
|
|
||||||
return (None, active_index);
|
|
||||||
} else {
|
|
||||||
favorite_index = (btn_count as usize).min(favorite_active_cnt).max(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculation of active_index based on favorite_index if there is still not enough space
|
|
||||||
let active_index_max = (btn_count as i32)
|
|
||||||
- (self.pinned_list.len() as i32).saturating_sub(favorite_index as i32);
|
|
||||||
if active_index_max >= self.active_list.len() as i32 {
|
|
||||||
active_index = Some(self.active_list.len());
|
|
||||||
} else {
|
|
||||||
active_index = Some((active_index_max.max(2) as usize).min(self.active_list.len()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// final calculation of favorite_index if there is still not enough space
|
|
||||||
if let Some(active_index) = active_index {
|
|
||||||
let favorite_index_max = (btn_count as i32) - active_index as i32;
|
|
||||||
favorite_index = favorite_index_max.max(2) as usize;
|
|
||||||
} else {
|
|
||||||
favorite_index = (btn_count as usize).min(self.pinned_list.len());
|
|
||||||
}
|
|
||||||
// tracing::error!("{} {} {:?}", btn_count, favorite_index, active_index);
|
|
||||||
(Some(favorite_index), active_index)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn currently_active_toplevel(&self) -> Vec<ExtForeignToplevelHandleV1> {
|
|
||||||
if self.active_workspaces.is_empty() {
|
|
||||||
return Vec::new();
|
|
||||||
}
|
|
||||||
let current_output = &self.core.applet.output_name;
|
|
||||||
let mut focused_toplevels: Vec<ExtForeignToplevelHandleV1> = Vec::new();
|
|
||||||
let active_workspaces = &self.active_workspaces;
|
|
||||||
for toplevel_list in self.active_list.iter().chain(self.pinned_list.iter()) {
|
|
||||||
for (t_info, _) in &toplevel_list.toplevels {
|
|
||||||
if t_info.state.contains(&State::Activated)
|
|
||||||
&& active_workspaces
|
|
||||||
.iter()
|
|
||||||
.any(|workspace| t_info.workspace.contains(workspace))
|
|
||||||
&& t_info.output.iter().any(|x| {
|
|
||||||
self.output_list.get(x).is_some_and(|val| {
|
|
||||||
val.name.as_ref().is_some_and(|n| n == current_output)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
{
|
|
||||||
focused_toplevels.push(t_info.foreign_toplevel.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
focused_toplevels
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_desktop_entry_for_toplevel(
|
|
||||||
&mut self,
|
|
||||||
info: &ToplevelInfo,
|
|
||||||
unicase_appid: Ascii<&str>,
|
|
||||||
) -> DesktopEntry {
|
|
||||||
if let Some(appid) = fde::find_app_by_id(&self.desktop_entries, unicase_appid) {
|
|
||||||
appid.clone()
|
|
||||||
} 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.clone()
|
|
||||||
} else {
|
|
||||||
tracing::error!(id = info.app_id, "could not find desktop entry for app");
|
|
||||||
|
|
||||||
let mut fallback_entry = fde::DesktopEntry::from_appid(info.app_id.clone());
|
|
||||||
|
|
||||||
// proton opens games as steam_app_X, where X is either
|
|
||||||
// the steam appid or "default". games with a steam appid
|
|
||||||
// can have a desktop entry generated elsewhere; this
|
|
||||||
// specifically handles non-steam games opened
|
|
||||||
// under proton
|
|
||||||
// in addition, try to match WINE entries who have its
|
|
||||||
// appid = the full name of the executable (incl. .exe)
|
|
||||||
let is_proton_game = info.app_id == "steam_app_default";
|
|
||||||
if is_proton_game || info.app_id.ends_with(".exe") {
|
|
||||||
for entry in &self.desktop_entries {
|
|
||||||
let localised_name = entry.name(&self.locales).unwrap_or_default();
|
|
||||||
|
|
||||||
if localised_name == info.title {
|
|
||||||
// if this is a proton game, we only want
|
|
||||||
// to look for game entries
|
|
||||||
if is_proton_game
|
|
||||||
&& !entry.categories().unwrap_or_default().contains(&"Game")
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
fallback_entry = entry.clone();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fallback_entry
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn launch_on_preferred_gpu(desktop_info: &DesktopEntry, gpus: Option<&[Gpu]>) -> Option<Message> {
|
fn launch_on_preferred_gpu(desktop_info: &DesktopEntry, gpus: Option<&[Gpu]>) -> Option<Message> {
|
||||||
let exec = desktop_info.exec()?;
|
let exec = desktop_info.exec()?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -506,9 +506,9 @@ impl AppData {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
// resize to 128x128
|
// resize to 256x256
|
||||||
let max = img.width().max(img.height());
|
let max = img.width().max(img.height());
|
||||||
let ratio = max as f32 / 128.0;
|
let ratio = max as f32 / 256.0;
|
||||||
|
|
||||||
let img = if ratio > 1.0 {
|
let img = if ratio > 1.0 {
|
||||||
let new_width = (img.width() as f32 / ratio).round();
|
let new_width = (img.width() as f32 / ratio).round();
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,9 @@
|
||||||
[package]
|
[package]
|
||||||
name = "cosmic-applet-a11y"
|
name = "cosmic-applet-a11y"
|
||||||
version = "0.1.0"
|
version = "1.0.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# cosmic-dbus-a11y = { git = "https://github.com/pop-os/dbus-settings-bindings" }
|
|
||||||
cosmic-settings-subscriptions = { workspace = true, features = [
|
|
||||||
"accessibility",
|
|
||||||
"cosmic_a11y_manager",
|
|
||||||
] }
|
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
cctk.workspace = true
|
cctk.workspace = true
|
||||||
cosmic-protocols.workspace = true
|
cosmic-protocols.workspace = true
|
||||||
|
|
@ -21,3 +16,9 @@ tokio.workspace = true
|
||||||
tracing-log.workspace = true
|
tracing-log.workspace = true
|
||||||
tracing-subscriber.workspace = true
|
tracing-subscriber.workspace = true
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
|
|
||||||
|
[dependencies.cosmic-settings-a11y-manager-subscription]
|
||||||
|
git = "https://github.com/pop-os/cosmic-settings"
|
||||||
|
|
||||||
|
[dependencies.cosmic-settings-accessibility-subscription]
|
||||||
|
git = "https://github.com/pop-os/cosmic-settings"
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ Name[de]= Zugänglichkeit
|
||||||
Name[sk]=Zjednodušenie ovládania
|
Name[sk]=Zjednodušenie ovládania
|
||||||
Name[sv]=Tillgänglighet
|
Name[sv]=Tillgänglighet
|
||||||
Name[es]=Accesibilidad
|
Name[es]=Accesibilidad
|
||||||
|
Name[it]=Accessibilità
|
||||||
Type=Application
|
Type=Application
|
||||||
Exec=cosmic-applet-a11y
|
Exec=cosmic-applet-a11y
|
||||||
Terminal=false
|
Terminal=false
|
||||||
|
|
@ -22,6 +23,7 @@ Icon=preferences-desktop-accessibility-symbolic
|
||||||
StartupNotify=true
|
StartupNotify=true
|
||||||
NoDisplay=true
|
NoDisplay=true
|
||||||
X-CosmicApplet=true
|
X-CosmicApplet=true
|
||||||
|
X-CosmicShrinkable=true
|
||||||
# Indicates that the auto-hover click should go to the "end" of the hover popup
|
# Indicates that the auto-hover click should go to the "end" of the hover popup
|
||||||
X-CosmicHoverPopup=Auto
|
X-CosmicHoverPopup=Auto
|
||||||
X-OverflowPriority=10
|
X-OverflowPriority=10
|
||||||
|
|
|
||||||
0
cosmic-applet-a11y/i18n/bn/cosmic_applet_a11y.ftl
Normal file
0
cosmic-applet-a11y/i18n/bn/cosmic_applet_a11y.ftl
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
screen-reader = Lecteur d'écran
|
||||||
|
invert-colors = Inverser les couleurs
|
||||||
|
high-contrast = Contraste élevé
|
||||||
|
filter-colors = Filtre de couleurs
|
||||||
|
settings = Paramètres d'accessibilité...
|
||||||
|
magnifier = Loupe
|
||||||
|
|
@ -3,4 +3,4 @@ magnifier = Formhéadaitheoir
|
||||||
invert-colors = Inbhéartaigh dathanna
|
invert-colors = Inbhéartaigh dathanna
|
||||||
settings = Socruithe inrochtaineachta...
|
settings = Socruithe inrochtaineachta...
|
||||||
filter-colors = Dathanna scagaire
|
filter-colors = Dathanna scagaire
|
||||||
high-contrast = Ardchodarsnacht
|
high-contrast = Ard chodarsnacht
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
screen-reader = Képernyőolvasó
|
screen-reader = Képernyőolvasó
|
||||||
magnifier = Nagyító
|
magnifier = Nagyító
|
||||||
invert-colors = Színek invertálása
|
invert-colors = Színek invertálása
|
||||||
settings = Akadálymentességi beállítások...
|
settings = Akadálymentességi beállítások…
|
||||||
filter-colors = Színek szűrése
|
filter-colors = Színek szűrése
|
||||||
high-contrast = Magas kontraszt
|
high-contrast = Magas kontraszt
|
||||||
|
|
|
||||||
0
cosmic-applet-a11y/i18n/ka/cosmic_applet_a11y.ftl
Normal file
0
cosmic-applet-a11y/i18n/ka/cosmic_applet_a11y.ftl
Normal file
0
cosmic-applet-a11y/i18n/kab/cosmic_applet_a11y.ftl
Normal file
0
cosmic-applet-a11y/i18n/kab/cosmic_applet_a11y.ftl
Normal file
6
cosmic-applet-a11y/i18n/kk/cosmic_applet_a11y.ftl
Normal file
6
cosmic-applet-a11y/i18n/kk/cosmic_applet_a11y.ftl
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
screen-reader = Экраннан оқу қолданбасы
|
||||||
|
magnifier = Экрандық ұлғайтқыш
|
||||||
|
invert-colors = Түстерді терістеу
|
||||||
|
settings = Қолжетімділік баптаулары...
|
||||||
|
filter-colors = Түстерді сүзгілеу
|
||||||
|
high-contrast = Жоғары контраст
|
||||||
0
cosmic-applet-a11y/i18n/kmr/cosmic_applet_a11y.ftl
Normal file
0
cosmic-applet-a11y/i18n/kmr/cosmic_applet_a11y.ftl
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
screen-reader = 스크린 리더
|
||||||
|
invert-colors = 색상 반전
|
||||||
|
high-contrast = 고대비
|
||||||
|
filter-colors = 색상 필터
|
||||||
|
settings = 접근성 설정...
|
||||||
|
magnifier = 돋보기
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
screen-reader = Ekrano skaitytuvas
|
||||||
|
invert-colors = Invertuoti spalvas
|
||||||
|
high-contrast = Didelis kontrastas
|
||||||
|
filter-colors = Spalvų filtras
|
||||||
|
settings = Pritaikomumo nustatymai...
|
||||||
|
magnifier = Didinamasis Stiklas
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
screen-reader = Schermverteller
|
screen-reader = Schermlezer
|
||||||
magnifier = Vergrootglas
|
magnifier = Vergrootglas
|
||||||
invert-colors = Kleuren omkeren
|
invert-colors = Keer kleuren om
|
||||||
settings = Toegankelijkheidsinstellingen...
|
settings = Toegankelijkheidsinstellingen...
|
||||||
filter-colors = filterkleuren
|
filter-colors = filterkleuren
|
||||||
high-contrast = Hoog contrast
|
high-contrast = Hoog contrast
|
||||||
|
|
|
||||||
0
cosmic-applet-a11y/i18n/pa/cosmic_applet_a11y.ftl
Normal file
0
cosmic-applet-a11y/i18n/pa/cosmic_applet_a11y.ftl
Normal file
0
cosmic-applet-a11y/i18n/ti/cosmic_applet_a11y.ftl
Normal file
0
cosmic-applet-a11y/i18n/ti/cosmic_applet_a11y.ftl
Normal file
|
|
@ -2,5 +2,5 @@ screen-reader = Читач екрана
|
||||||
magnifier = Лупа
|
magnifier = Лупа
|
||||||
invert-colors = Інверсія кольорів
|
invert-colors = Інверсія кольорів
|
||||||
settings = Налаштування доступності...
|
settings = Налаштування доступності...
|
||||||
filter-colors = Виправлення кольорової сліпоти
|
filter-colors = Фільтрувати кольори
|
||||||
high-contrast = Висока контрастність
|
high-contrast = Висока контрастність
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
screen-reader = 屏幕阅读器
|
screen-reader = 屏幕阅读器
|
||||||
magnifier = 放大镜
|
magnifier = 放大镜
|
||||||
invert-colors = 反转颜色
|
invert-colors = 颜色反转
|
||||||
settings = 无障碍设置...
|
settings = 无障碍设置...
|
||||||
filter-colors = 滤镜颜色
|
filter-colors = 颜色滤镜
|
||||||
high-contrast = 高对比度
|
high-contrast = 高对比度模式
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,11 @@ use cosmic::{
|
||||||
theme::{self, CosmicTheme},
|
theme::{self, CosmicTheme},
|
||||||
widget::{Column, divider, text},
|
widget::{Column, divider, text},
|
||||||
};
|
};
|
||||||
use cosmic_settings_subscriptions::{
|
|
||||||
accessibility::{self, DBusRequest, DBusUpdate},
|
use cosmic_settings_a11y_manager_subscription::{
|
||||||
cosmic_a11y_manager::{AccessibilityEvent, AccessibilityRequest, ColorFilter},
|
self as cosmic_a11y_manager, AccessibilityEvent, AccessibilityRequest, ColorFilter,
|
||||||
};
|
};
|
||||||
|
use cosmic_settings_accessibility_subscription::{self as accessibility};
|
||||||
use cosmic_time::{Instant, Timeline, anim, chain, id};
|
use cosmic_time::{Instant, Timeline, anim, chain, id};
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
use tokio::sync::mpsc::UnboundedSender;
|
use tokio::sync::mpsc::UnboundedSender;
|
||||||
|
|
@ -50,7 +51,7 @@ struct CosmicA11yApplet {
|
||||||
magnifier_enabled: bool,
|
magnifier_enabled: bool,
|
||||||
inverted_colors_enabled: bool,
|
inverted_colors_enabled: bool,
|
||||||
popup: Option<window::Id>,
|
popup: Option<window::Id>,
|
||||||
dbus_sender: Option<UnboundedSender<DBusRequest>>,
|
dbus_sender: Option<UnboundedSender<accessibility::Request>>,
|
||||||
wayland_sender: Option<calloop::channel::Sender<AccessibilityRequest>>,
|
wayland_sender: Option<calloop::channel::Sender<AccessibilityRequest>>,
|
||||||
wayland_protocol_version: Option<u32>,
|
wayland_protocol_version: Option<u32>,
|
||||||
timeline: Timeline,
|
timeline: Timeline,
|
||||||
|
|
@ -70,7 +71,7 @@ enum Message {
|
||||||
Frame(Instant),
|
Frame(Instant),
|
||||||
Token(TokenUpdate),
|
Token(TokenUpdate),
|
||||||
OpenSettings,
|
OpenSettings,
|
||||||
DBusUpdate(DBusUpdate),
|
DBusUpdate(accessibility::Response),
|
||||||
WaylandUpdate(WaylandUpdate),
|
WaylandUpdate(WaylandUpdate),
|
||||||
Surface(surface::Action),
|
Surface(surface::Action),
|
||||||
}
|
}
|
||||||
|
|
@ -108,7 +109,7 @@ impl cosmic::Application for CosmicA11yApplet {
|
||||||
if let Some(tx) = &self.dbus_sender {
|
if let Some(tx) = &self.dbus_sender {
|
||||||
self.timeline.set_chain(chain).start();
|
self.timeline.set_chain(chain).start();
|
||||||
self.reader_enabled = enabled;
|
self.reader_enabled = enabled;
|
||||||
let _ = tx.send(DBusRequest::Status(enabled));
|
let _ = tx.send(accessibility::Request::ScreenReader(enabled));
|
||||||
} else {
|
} else {
|
||||||
self.reader_enabled = false;
|
self.reader_enabled = false;
|
||||||
}
|
}
|
||||||
|
|
@ -255,18 +256,19 @@ impl cosmic::Application for CosmicA11yApplet {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Message::DBusUpdate(update) => match update {
|
Message::DBusUpdate(update) => match update {
|
||||||
DBusUpdate::Error(err) => {
|
accessibility::Response::Error(err) => {
|
||||||
tracing::error!("{err}");
|
tracing::error!("{err}");
|
||||||
let _ = self.dbus_sender.take();
|
let _ = self.dbus_sender.take();
|
||||||
self.reader_enabled = false;
|
self.reader_enabled = false;
|
||||||
}
|
}
|
||||||
DBusUpdate::Status(enabled) => {
|
accessibility::Response::ScreenReader(enabled) => {
|
||||||
self.reader_enabled = enabled;
|
self.reader_enabled = enabled;
|
||||||
}
|
}
|
||||||
DBusUpdate::Init(enabled, tx) => {
|
accessibility::Response::Init(enabled, tx) => {
|
||||||
self.reader_enabled = enabled;
|
self.reader_enabled = enabled;
|
||||||
self.dbus_sender = Some(tx);
|
self.dbus_sender = Some(tx);
|
||||||
}
|
}
|
||||||
|
_ => (),
|
||||||
},
|
},
|
||||||
Message::WaylandUpdate(update) => match update {
|
Message::WaylandUpdate(update) => match update {
|
||||||
WaylandUpdate::Errored => {
|
WaylandUpdate::Errored => {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use cosmic::iced::{
|
||||||
stream,
|
stream,
|
||||||
};
|
};
|
||||||
use cosmic_protocols::a11y::v1::client::cosmic_a11y_manager_v1::Filter;
|
use cosmic_protocols::a11y::v1::client::cosmic_a11y_manager_v1::Filter;
|
||||||
use cosmic_settings_subscriptions::cosmic_a11y_manager::{
|
use cosmic_settings_a11y_manager_subscription::{
|
||||||
self as thread, AccessibilityEvent, AccessibilityRequest,
|
self as thread, AccessibilityEvent, AccessibilityRequest,
|
||||||
};
|
};
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,16 @@
|
||||||
[package]
|
[package]
|
||||||
name = "cosmic-applet-audio"
|
name = "cosmic-applet-audio"
|
||||||
version = "0.1.1"
|
version = "1.0.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "GPL-3.0-only"
|
license = "GPL-3.0-only"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cosmic-settings-subscriptions.workspace = true
|
|
||||||
cosmic-time.workspace = true
|
cosmic-time.workspace = true
|
||||||
i18n-embed-fl.workspace = true
|
i18n-embed-fl.workspace = true
|
||||||
i18n-embed.workspace = true
|
i18n-embed.workspace = true
|
||||||
libcosmic.workspace = true
|
libcosmic.workspace = true
|
||||||
libpulse-binding = "2.30.1"
|
|
||||||
mpris2-zbus = { git = "https://github.com/pop-os/dbus-settings-bindings" }
|
mpris2-zbus = { git = "https://github.com/pop-os/dbus-settings-bindings" }
|
||||||
|
# mpris2-zbus = { path = "../../dbus-settings-bindings/mpris2" }
|
||||||
rust-embed.workspace = true
|
rust-embed.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
|
|
@ -21,3 +20,6 @@ tracing.workspace = true
|
||||||
url = "2"
|
url = "2"
|
||||||
urlencoding = "2.1.3"
|
urlencoding = "2.1.3"
|
||||||
zbus.workspace = true
|
zbus.workspace = true
|
||||||
|
|
||||||
|
[dependencies.cosmic-settings-sound-subscription]
|
||||||
|
git = "https://github.com/pop-os/cosmic-settings"
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ Name[de]=Klang
|
||||||
Name[sk]=Zvuk
|
Name[sk]=Zvuk
|
||||||
Name[sv]=Ljud
|
Name[sv]=Ljud
|
||||||
Name[es]=Sonido
|
Name[es]=Sonido
|
||||||
|
Name[it]=Audio
|
||||||
Type=Application
|
Type=Application
|
||||||
Exec=cosmic-applet-audio
|
Exec=cosmic-applet-audio
|
||||||
Terminal=false
|
Terminal=false
|
||||||
|
|
@ -23,6 +24,7 @@ Icon=com.system76.CosmicAppletAudio-symbolic
|
||||||
StartupNotify=true
|
StartupNotify=true
|
||||||
NoDisplay=true
|
NoDisplay=true
|
||||||
X-CosmicApplet=true
|
X-CosmicApplet=true
|
||||||
|
X-CosmicShrinkable=true
|
||||||
# Indicates that the auto-hover click should go to the "end" of the hover popup
|
# Indicates that the auto-hover click should go to the "end" of the hover popup
|
||||||
X-CosmicHoverPopup=End
|
X-CosmicHoverPopup=End
|
||||||
X-OverflowPriority=10
|
X-OverflowPriority=10
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
output = الإخراج
|
output = الإخراج
|
||||||
input = الإدخال
|
input = الإدخال
|
||||||
show-media-controls = إظهار عناصر التحكم بالوسائط على اللوحة
|
show-media-controls = أظهِر عناصر التحكم بالوسائط على اللوحة
|
||||||
sound-settings = إعدادات الصوت...
|
sound-settings = إعدادات الصوت...
|
||||||
disconnected = غير متصل ببولس أوديو
|
disconnected = غير متصل ببولس أوديو
|
||||||
no-device = لم يتم اختيار جهاز
|
no-device = لا جهاز محدّد
|
||||||
unknown-artist = فنان غير معروف
|
unknown-artist = مجهول
|
||||||
|
|
|
||||||
0
cosmic-applet-audio/i18n/bn/cosmic_applet_audio.ftl
Normal file
0
cosmic-applet-audio/i18n/bn/cosmic_applet_audio.ftl
Normal file
|
|
@ -1,7 +1,7 @@
|
||||||
output = Sortie
|
output = Sortie
|
||||||
input = Entrée
|
input = Entrée
|
||||||
show-media-controls = Afficher les contrôles média sur le panel supérieur
|
show-media-controls = Afficher les contrôles média sur le panneau
|
||||||
sound-settings = Paramètres sonores...
|
sound-settings = Paramètres audio...
|
||||||
disconnected = PulseAudio est déconnecté
|
disconnected = PulseAudio est déconnecté
|
||||||
no-device = Pas de périphérique sélectionné
|
no-device = Aucun périphérique sélectionné
|
||||||
unknown-artist = Inconnu(e)
|
unknown-artist = Inconnu(e)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
output = Aschur
|
output = Aschur
|
||||||
input = Ionchur
|
input = Ionchur
|
||||||
show-media-controls = Taispeáin rialuithe meán ar an bpanéal
|
show-media-controls = Taispeáin rialuithe meán ar an bpanéal
|
||||||
sound-settings = Socruithe Fuaime...
|
sound-settings = Socruithe fuaime...
|
||||||
disconnected = Dícheangailte le PulseAudio
|
disconnected = PulseAudio dícheangailte
|
||||||
no-device = Níl aon ghléas roghnaithe
|
no-device = Níl aon ghléas roghnaithe
|
||||||
unknown-artist = Anaithnid
|
unknown-artist = Anaithnid
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
output = Kimenet
|
output = Kimenet
|
||||||
input = Bemenet
|
input = Bemenet
|
||||||
show-media-controls = Médiavezérlők megjelenítése a panelen
|
show-media-controls = Médiavezérlők megjelenítése a panelen
|
||||||
sound-settings = Hangbeállítások...
|
sound-settings = Hangbeállítások…
|
||||||
disconnected = PulseAudio lecsatlakozott
|
disconnected = PulseAudio nincs csatlakozva
|
||||||
no-device = Nincs kiválasztott eszköz
|
no-device = Nincs kiválasztott eszköz
|
||||||
unknown-artist = Ismeretlen
|
unknown-artist = Ismeretlen
|
||||||
|
|
|
||||||
0
cosmic-applet-audio/i18n/ka/cosmic_applet_audio.ftl
Normal file
0
cosmic-applet-audio/i18n/ka/cosmic_applet_audio.ftl
Normal file
0
cosmic-applet-audio/i18n/kab/cosmic_applet_audio.ftl
Normal file
0
cosmic-applet-audio/i18n/kab/cosmic_applet_audio.ftl
Normal file
7
cosmic-applet-audio/i18n/kk/cosmic_applet_audio.ftl
Normal file
7
cosmic-applet-audio/i18n/kk/cosmic_applet_audio.ftl
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
output = Шығару
|
||||||
|
input = Енгізу
|
||||||
|
show-media-controls = Панельде медиа басқару элементтерін көрсету
|
||||||
|
sound-settings = Дыбыс баптаулары...
|
||||||
|
disconnected = PulseAudio ажыратылған
|
||||||
|
no-device = Құрылғы таңдалмаған
|
||||||
|
unknown-artist = Белгісіз
|
||||||
0
cosmic-applet-audio/i18n/kmr/cosmic_applet_audio.ftl
Normal file
0
cosmic-applet-audio/i18n/kmr/cosmic_applet_audio.ftl
Normal file
|
|
@ -1,6 +1,7 @@
|
||||||
output = 출력
|
output = 출력
|
||||||
input = 입력
|
input = 입력
|
||||||
show-media-controls = 상단 패널에 미디어 제어기 표시
|
show-media-controls = 패널에 미디어 제어기 표시
|
||||||
sound-settings = 소리 설정...
|
sound-settings = 소리 설정...
|
||||||
disconnected = PulseAudio 연결 끊김
|
disconnected = PulseAudio 연결끊김
|
||||||
no-device = 선택된 장치가 없습니다
|
no-device = 선택된 장치가 없습니다
|
||||||
|
unknown-artist = 알 수 없음
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
show-media-controls = Rodyti medijos valdymo mygtukus skydelyje
|
||||||
|
disconnected = PulseAudio Atjungtas
|
||||||
|
no-device = Nepasirinktas įrenginys
|
||||||
|
input = Įvestis
|
||||||
|
output = Išvestis
|
||||||
|
unknown-artist = Nežinomas atlikėjas
|
||||||
|
sound-settings = Garso Nustatymai...
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
output = Uitvoer
|
output = Uitvoer
|
||||||
input = Invoer
|
input = Invoer
|
||||||
show-media-controls = Media-applet aan paneel vastmaken
|
show-media-controls = Toon mediabeheerder op het paneel
|
||||||
sound-settings = Geluidsinstellingen...
|
sound-settings = Geluid instellingen…
|
||||||
disconnected = PulseAudio niet meer verbonden
|
disconnected = PulseAudio niet meer verbonden
|
||||||
no-device = Geen apparaat geselecteerd
|
no-device = Geen apparaat geselecteerd
|
||||||
unknown-artist = Onbekend
|
unknown-artist = Onbekend
|
||||||
|
|
|
||||||
0
cosmic-applet-audio/i18n/pa/cosmic_applet_audio.ftl
Normal file
0
cosmic-applet-audio/i18n/pa/cosmic_applet_audio.ftl
Normal file
|
|
@ -1,7 +1,7 @@
|
||||||
output = Utgång
|
output = Utgång
|
||||||
input = Ingång
|
input = Ingång
|
||||||
show-media-controls = Visa mediakontroller på panelen
|
show-media-controls = Visa mediakontroller på panelen
|
||||||
sound-settings = Ljudinställningar…
|
sound-settings = Ljudinställningar...
|
||||||
disconnected = PulseAudio frånkopplad
|
disconnected = PulseAudio frånkopplad
|
||||||
no-device = Ingen enhet vald
|
no-device = Ingen enhet vald
|
||||||
unknown-artist = Okänd
|
unknown-artist = Okänd
|
||||||
|
|
|
||||||
0
cosmic-applet-audio/i18n/ti/cosmic_applet_audio.ftl
Normal file
0
cosmic-applet-audio/i18n/ti/cosmic_applet_audio.ftl
Normal file
|
|
@ -4,4 +4,4 @@ show-media-controls = Показувати елементи керування
|
||||||
sound-settings = Налаштування звуку...
|
sound-settings = Налаштування звуку...
|
||||||
disconnected = PulseAudio відʼєднано
|
disconnected = PulseAudio відʼєднано
|
||||||
no-device = Не вибрано жодного пристрою
|
no-device = Не вибрано жодного пристрою
|
||||||
unknown-artist = Невідоме
|
unknown-artist = Невідомо
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
output = 输出
|
output = 输出
|
||||||
input = 输入
|
input = 输入
|
||||||
show-media-controls = 在顶栏显示媒体控制
|
show-media-controls = 在面板上显示媒体控制
|
||||||
sound-settings = 声音设置...
|
sound-settings = 声音设置...
|
||||||
disconnected = PulseAudio 服务器已断开连接
|
disconnected = PulseAudio 服务器已断开连接
|
||||||
no-device = 未选择设备
|
no-device = 未选择设备
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,14 @@
|
||||||
mod localize;
|
mod localize;
|
||||||
mod mouse_area;
|
mod mouse_area;
|
||||||
|
|
||||||
use std::sync::LazyLock;
|
use crate::localize::localize;
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use crate::{localize::localize, pulse::DeviceInfo};
|
|
||||||
use config::{AudioAppletConfig, amplification_sink, amplification_source};
|
use config::{AudioAppletConfig, amplification_sink, amplification_source};
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
Element, Renderer, Task, Theme, app,
|
Element, Renderer, Task, Theme, app,
|
||||||
applet::{
|
applet::{
|
||||||
|
column as applet_column,
|
||||||
cosmic_panel_config::PanelAnchor,
|
cosmic_panel_config::PanelAnchor,
|
||||||
menu_button, menu_control_padding, padded_control,
|
menu_button, menu_control_padding, padded_control, row as applet_row,
|
||||||
token::subscription::{TokenRequest, TokenUpdate, activation_token_subscription},
|
token::subscription::{TokenRequest, TokenUpdate, activation_token_subscription},
|
||||||
},
|
},
|
||||||
cctk::sctk::reexports::calloop,
|
cctk::sctk::reexports::calloop,
|
||||||
|
|
@ -21,28 +19,22 @@ use cosmic::{
|
||||||
cosmic_theme::Spacing,
|
cosmic_theme::Spacing,
|
||||||
iced::{
|
iced::{
|
||||||
self, Alignment, Length, Subscription,
|
self, Alignment, Length, Subscription,
|
||||||
|
futures::StreamExt,
|
||||||
widget::{self, column, row, slider},
|
widget::{self, column, row, slider},
|
||||||
window,
|
window,
|
||||||
},
|
},
|
||||||
surface, theme,
|
surface, theme,
|
||||||
widget::{Column, Row, button, container, divider, horizontal_space, icon, text},
|
widget::{Row, button, container, divider, horizontal_space, icon, text},
|
||||||
};
|
};
|
||||||
use cosmic_settings_subscriptions::pulse as sub_pulse;
|
use cosmic_settings_sound_subscription as css;
|
||||||
use cosmic_time::{Instant, Timeline, anim, chain, id};
|
use cosmic_time::{Instant, Timeline, anim, chain, id};
|
||||||
use iced::platform_specific::shell::wayland::commands::popup::{destroy_popup, get_popup};
|
use iced::platform_specific::shell::wayland::commands::popup::{destroy_popup, get_popup};
|
||||||
use libpulse_binding::volume::Volume;
|
|
||||||
use mpris_subscription::{MprisRequest, MprisUpdate};
|
use mpris_subscription::{MprisRequest, MprisUpdate};
|
||||||
use mpris2_zbus::player::PlaybackStatus;
|
use mpris2_zbus::player::PlaybackStatus;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
mod mpris_subscription;
|
mod mpris_subscription;
|
||||||
mod pulse;
|
|
||||||
|
|
||||||
// Full, in this case, means 100%.
|
|
||||||
static FULL_VOLUME: f64 = Volume::NORMAL.0 as f64;
|
|
||||||
|
|
||||||
// Max volume is 150% volume.
|
|
||||||
static MAX_VOLUME: f64 = FULL_VOLUME + (FULL_VOLUME * 0.5);
|
|
||||||
|
|
||||||
static SHOW_MEDIA_CONTROLS: LazyLock<id::Toggler> = LazyLock::new(id::Toggler::unique);
|
static SHOW_MEDIA_CONTROLS: LazyLock<id::Toggler> = LazyLock::new(id::Toggler::unique);
|
||||||
|
|
||||||
|
|
@ -58,72 +50,57 @@ pub fn run() -> cosmic::iced::Result {
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Audio {
|
pub struct Audio {
|
||||||
|
/// For interfacing with libcosmic.
|
||||||
core: cosmic::app::Core,
|
core: cosmic::app::Core,
|
||||||
is_open: IsOpen,
|
/// Track the applet's popup window.
|
||||||
output_volume: f64,
|
|
||||||
output_volume_debounce: bool,
|
|
||||||
output_volume_text: String,
|
|
||||||
output_amplification: bool,
|
|
||||||
input_volume: f64,
|
|
||||||
input_volume_debounce: bool,
|
|
||||||
input_volume_text: String,
|
|
||||||
input_amplification: bool,
|
|
||||||
current_output: Option<DeviceInfo>,
|
|
||||||
current_input: Option<DeviceInfo>,
|
|
||||||
outputs: Vec<DeviceInfo>,
|
|
||||||
inputs: Vec<DeviceInfo>,
|
|
||||||
pulse_state: PulseState,
|
|
||||||
popup: Option<window::Id>,
|
popup: Option<window::Id>,
|
||||||
|
/// The model from cosmic-settings for managing pipewire devices.
|
||||||
|
model: css::Model,
|
||||||
|
/// Whether to expand the revealer of a source or sink device.
|
||||||
|
is_open: IsOpen,
|
||||||
|
/// Max slider volume for the sink device, as determined by the amplification property.
|
||||||
|
max_sink_volume: u32,
|
||||||
|
/// Max slider volume for the source device, as determined by the amplification property.
|
||||||
|
max_source_volume: u32,
|
||||||
|
/// Breakpoints for the sink volume slider.
|
||||||
|
sink_breakpoints: &'static [u32],
|
||||||
|
/// Breakpoitns for the source volume slider.
|
||||||
|
source_breakpoints: &'static [u32],
|
||||||
|
/// Track animations used by the revealers.
|
||||||
timeline: Timeline,
|
timeline: Timeline,
|
||||||
|
/// Config file specific to this applet.
|
||||||
config: AudioAppletConfig,
|
config: AudioAppletConfig,
|
||||||
|
/// mpris player status
|
||||||
player_status: Option<mpris_subscription::PlayerStatus>,
|
player_status: Option<mpris_subscription::PlayerStatus>,
|
||||||
|
/// Used to request an activation token for opening cosmic-settings.
|
||||||
token_tx: Option<calloop::channel::Sender<TokenRequest>>,
|
token_tx: Option<calloop::channel::Sender<TokenRequest>>,
|
||||||
channels: Option<sub_pulse::PulseChannels>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Audio {
|
impl Audio {
|
||||||
fn update_output(&mut self, output: Option<DeviceInfo>) {
|
|
||||||
self.current_output = output;
|
|
||||||
|
|
||||||
if let Some(device) = self.current_output.as_ref() {
|
|
||||||
self.output_volume = volume_to_percent(device.volume.avg());
|
|
||||||
self.output_volume_text = format!("{}%", self.output_volume.round());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn output_icon_name(&self) -> &'static str {
|
fn output_icon_name(&self) -> &'static str {
|
||||||
let volume = self.output_volume;
|
let volume = self.model.sink_volume;
|
||||||
let mute = self.current_output_mute();
|
let mute = self.model.sink_mute;
|
||||||
if mute || volume == 0. {
|
if mute || volume == 0 {
|
||||||
"audio-volume-muted-symbolic"
|
"audio-volume-muted-symbolic"
|
||||||
} else if volume < 33. {
|
} else if volume < 33 {
|
||||||
"audio-volume-low-symbolic"
|
"audio-volume-low-symbolic"
|
||||||
} else if volume < 66. {
|
} else if volume < 66 {
|
||||||
"audio-volume-medium-symbolic"
|
"audio-volume-medium-symbolic"
|
||||||
} else if volume <= 100. {
|
} else if volume <= 100 {
|
||||||
"audio-volume-high-symbolic"
|
"audio-volume-high-symbolic"
|
||||||
} else {
|
} else {
|
||||||
"audio-volume-overamplified-symbolic"
|
"audio-volume-overamplified-symbolic"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_input(&mut self, input: Option<DeviceInfo>) {
|
|
||||||
self.current_input = input;
|
|
||||||
|
|
||||||
if let Some(device) = self.current_input.as_ref() {
|
|
||||||
self.input_volume = volume_to_percent(device.volume.avg());
|
|
||||||
self.input_volume_text = format!("{}%", self.input_volume.round());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn input_icon_name(&self) -> &'static str {
|
fn input_icon_name(&self) -> &'static str {
|
||||||
let volume = self.input_volume;
|
let volume = self.model.source_volume;
|
||||||
let mute = self.current_input_mute();
|
let mute = self.model.source_mute;
|
||||||
if mute || volume == 0. {
|
if mute || volume == 0 {
|
||||||
"microphone-sensitivity-muted-symbolic"
|
"microphone-sensitivity-muted-symbolic"
|
||||||
} else if volume < 33. {
|
} else if volume < 33 {
|
||||||
"microphone-sensitivity-low-symbolic"
|
"microphone-sensitivity-low-symbolic"
|
||||||
} else if volume < 66. {
|
} else if volume < 66 {
|
||||||
"microphone-sensitivity-medium-symbolic"
|
"microphone-sensitivity-medium-symbolic"
|
||||||
} else {
|
} else {
|
||||||
"microphone-sensitivity-high-symbolic"
|
"microphone-sensitivity-high-symbolic"
|
||||||
|
|
@ -142,17 +119,14 @@ enum IsOpen {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Message {
|
pub enum Message {
|
||||||
Ignore,
|
Ignore,
|
||||||
ApplyOutputVolume,
|
SetSinkVolume(u32),
|
||||||
ApplyInputVolume,
|
SetSourceVolume(u32),
|
||||||
SetOutputVolume(f64),
|
ToggleSinkMute,
|
||||||
SetInputVolume(f64),
|
ToggleSourceMute,
|
||||||
SetOutputMute(bool),
|
SetDefaultSink(usize),
|
||||||
SetInputMute(bool),
|
SetDefaultSource(usize),
|
||||||
OutputToggle,
|
OutputToggle,
|
||||||
InputToggle,
|
InputToggle,
|
||||||
OutputChanged(String),
|
|
||||||
InputChanged(String),
|
|
||||||
Pulse(pulse::Event),
|
|
||||||
TogglePopup,
|
TogglePopup,
|
||||||
CloseRequested(window::Id),
|
CloseRequested(window::Id),
|
||||||
ToggleMediaControlsInTopPanel(chain::Toggler, bool),
|
ToggleMediaControlsInTopPanel(chain::Toggler, bool),
|
||||||
|
|
@ -162,14 +136,20 @@ pub enum Message {
|
||||||
MprisRequest(MprisRequest),
|
MprisRequest(MprisRequest),
|
||||||
Token(TokenUpdate),
|
Token(TokenUpdate),
|
||||||
OpenSettings,
|
OpenSettings,
|
||||||
PulseSub(sub_pulse::Event),
|
Subscription(css::Message),
|
||||||
Surface(surface::Action),
|
Surface(surface::Action),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// mouse area with on enter and a stack widget for all buttons
|
||||||
|
// most recently entered button is on top
|
||||||
|
// position is a multiple of button size
|
||||||
|
// on leave of applet, popup button is on top again
|
||||||
|
|
||||||
impl Audio {
|
impl Audio {
|
||||||
fn playback_buttons(&self) -> Option<Element<'_, Message>> {
|
fn playback_buttons(&self) -> Vec<Element<'_, Message>> {
|
||||||
|
let mut elements: Vec<Element<'_, Message>> = Vec::new();
|
||||||
if self.player_status.is_some() && self.config.show_media_controls_in_top_panel {
|
if self.player_status.is_some() && self.config.show_media_controls_in_top_panel {
|
||||||
let mut elements = Vec::with_capacity(3);
|
|
||||||
if self
|
if self
|
||||||
.player_status
|
.player_status
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|
@ -205,18 +185,8 @@ impl Audio {
|
||||||
.into(),
|
.into(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(match self.core.applet.anchor {
|
|
||||||
PanelAnchor::Left | PanelAnchor::Right => Column::with_children(elements)
|
|
||||||
.align_x(Alignment::Center)
|
|
||||||
.into(),
|
|
||||||
PanelAnchor::Top | PanelAnchor::Bottom => Row::with_children(elements)
|
|
||||||
.align_y(Alignment::Center)
|
|
||||||
.into(),
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
elements
|
||||||
}
|
}
|
||||||
|
|
||||||
fn go_previous(&self, icon_size: u16) -> Option<Element<'_, Message>> {
|
fn go_previous(&self, icon_size: u16) -> Option<Element<'_, Message>> {
|
||||||
|
|
@ -270,14 +240,6 @@ impl Audio {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn current_output_mute(&self) -> bool {
|
|
||||||
self.current_output.as_ref().is_some_and(|o| o.mute)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn current_input_mute(&self) -> bool {
|
|
||||||
self.current_input.as_ref().is_some_and(|o| o.mute)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl cosmic::Application for Audio {
|
impl cosmic::Application for Audio {
|
||||||
|
|
@ -287,9 +249,15 @@ impl cosmic::Application for Audio {
|
||||||
const APP_ID: &'static str = "com.system76.CosmicAppletAudio";
|
const APP_ID: &'static str = "com.system76.CosmicAppletAudio";
|
||||||
|
|
||||||
fn init(core: cosmic::app::Core, _flags: ()) -> (Self, app::Task<Message>) {
|
fn init(core: cosmic::app::Core, _flags: ()) -> (Self, app::Task<Message>) {
|
||||||
|
let mut model = css::Model::default();
|
||||||
|
model.unplugged_text = "Unplugged".into();
|
||||||
|
model.hd_audio_text = "HD Audio".into();
|
||||||
|
model.usb_audio_text = "USB Audio".into();
|
||||||
|
|
||||||
(
|
(
|
||||||
Self {
|
Self {
|
||||||
core,
|
core,
|
||||||
|
model,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
Task::none(),
|
Task::none(),
|
||||||
|
|
@ -316,15 +284,21 @@ impl cosmic::Application for Audio {
|
||||||
if let Some(p) = self.popup.take() {
|
if let Some(p) = self.popup.take() {
|
||||||
return destroy_popup(p);
|
return destroy_popup(p);
|
||||||
} else {
|
} else {
|
||||||
if let Some(conn) = self.pulse_state.connection() {
|
|
||||||
conn.send(pulse::Message::UpdateConnection);
|
|
||||||
}
|
|
||||||
let new_id = window::Id::unique();
|
let new_id = window::Id::unique();
|
||||||
self.popup.replace(new_id);
|
self.popup.replace(new_id);
|
||||||
self.timeline = Timeline::new();
|
self.timeline = Timeline::new();
|
||||||
|
|
||||||
self.output_amplification = amplification_sink();
|
(self.max_sink_volume, self.sink_breakpoints) = if amplification_sink() {
|
||||||
self.input_amplification = amplification_source();
|
(150, &[100][..])
|
||||||
|
} else {
|
||||||
|
(100, &[][..])
|
||||||
|
};
|
||||||
|
|
||||||
|
(self.max_source_volume, self.source_breakpoints) = if amplification_source() {
|
||||||
|
(150, &[100][..])
|
||||||
|
} else {
|
||||||
|
(100, &[][..])
|
||||||
|
};
|
||||||
|
|
||||||
let popup_settings = self.core.applet.get_popup_settings(
|
let popup_settings = self.core.applet.get_popup_settings(
|
||||||
self.core.main_window_id().unwrap(),
|
self.core.main_window_id().unwrap(),
|
||||||
|
|
@ -334,130 +308,14 @@ impl cosmic::Application for Audio {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(conn) = self.pulse_state.connection() {
|
|
||||||
conn.send(pulse::Message::GetDefaultSink);
|
|
||||||
conn.send(pulse::Message::GetDefaultSource);
|
|
||||||
conn.send(pulse::Message::GetSinks);
|
|
||||||
conn.send(pulse::Message::GetSources);
|
|
||||||
}
|
|
||||||
|
|
||||||
return get_popup(popup_settings);
|
return get_popup(popup_settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::SetOutputVolume(vol) => {
|
|
||||||
if self.output_volume == vol {
|
|
||||||
return Task::none();
|
|
||||||
}
|
|
||||||
|
|
||||||
self.output_volume = vol;
|
|
||||||
self.output_volume_text = format!("{}%", self.output_volume.round());
|
|
||||||
|
|
||||||
if self.output_volume_debounce {
|
|
||||||
return Task::none();
|
|
||||||
}
|
|
||||||
|
|
||||||
self.output_volume_debounce = true;
|
|
||||||
|
|
||||||
return cosmic::task::future(async move {
|
|
||||||
tokio::time::sleep(Duration::from_millis(64)).await;
|
|
||||||
Message::ApplyOutputVolume
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Message::SetInputVolume(vol) => {
|
|
||||||
if self.input_volume == vol {
|
|
||||||
return Task::none();
|
|
||||||
}
|
|
||||||
|
|
||||||
self.input_volume = vol;
|
|
||||||
self.input_volume_text = format!("{}%", self.input_volume.round());
|
|
||||||
|
|
||||||
if self.input_volume_debounce {
|
|
||||||
return Task::none();
|
|
||||||
}
|
|
||||||
|
|
||||||
self.input_volume_debounce = true;
|
|
||||||
|
|
||||||
return cosmic::task::future(async move {
|
|
||||||
tokio::time::sleep(Duration::from_millis(64)).await;
|
|
||||||
Message::ApplyInputVolume
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Message::ApplyOutputVolume => {
|
|
||||||
self.output_volume_debounce = false;
|
|
||||||
|
|
||||||
if let Some(channel) = self.channels.as_mut() {
|
|
||||||
channel.set_volume(self.output_volume as f32 / 100.);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Message::ApplyInputVolume => {
|
|
||||||
self.input_volume_debounce = false;
|
|
||||||
|
|
||||||
self.current_input.as_mut().map(|i| {
|
|
||||||
i.volume
|
|
||||||
.set(i.volume.len(), percent_to_volume(self.input_volume))
|
|
||||||
});
|
|
||||||
|
|
||||||
if let PulseState::Connected(connection) = &mut self.pulse_state {
|
|
||||||
if let Some(device) = &self.current_input {
|
|
||||||
if let Some(name) = &device.name {
|
|
||||||
tracing::info!("increasing volume of {}", name);
|
|
||||||
connection.send(pulse::Message::SetSourceVolumeByName(
|
|
||||||
name.clone(),
|
|
||||||
device.volume,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Message::SetOutputMute(mute) => {
|
|
||||||
if let Some(output) = self.current_output.as_mut() {
|
|
||||||
output.mute = mute;
|
|
||||||
}
|
|
||||||
if let PulseState::Connected(connection) = &mut self.pulse_state {
|
|
||||||
if let Some(device) = &self.current_output {
|
|
||||||
if let Some(name) = &device.name {
|
|
||||||
connection
|
|
||||||
.send(pulse::Message::SetSinkMuteByName(name.clone(), device.mute));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Message::SetInputMute(mute) => {
|
|
||||||
if let Some(input) = self.current_input.as_mut() {
|
|
||||||
input.mute = mute;
|
|
||||||
}
|
|
||||||
if let PulseState::Connected(connection) = &mut self.pulse_state {
|
|
||||||
if let Some(device) = &self.current_input {
|
|
||||||
if let Some(name) = &device.name {
|
|
||||||
connection.send(pulse::Message::SetSourceMuteByName(
|
|
||||||
name.clone(),
|
|
||||||
device.mute,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Message::OutputChanged(val) => {
|
|
||||||
if let Some(conn) = self.pulse_state.connection() {
|
|
||||||
if let Some(val) = self.outputs.iter().find(|o| o.name.as_ref() == Some(&val)) {
|
|
||||||
conn.send(pulse::Message::SetDefaultSink(val.clone()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Message::InputChanged(val) => {
|
|
||||||
if let Some(conn) = self.pulse_state.connection() {
|
|
||||||
if let Some(val) = self.inputs.iter().find(|i| i.name.as_ref() == Some(&val)) {
|
|
||||||
conn.send(pulse::Message::SetDefaultSource(val.clone()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Message::OutputToggle => {
|
Message::OutputToggle => {
|
||||||
self.is_open = if self.is_open == IsOpen::Output {
|
self.is_open = if self.is_open == IsOpen::Output {
|
||||||
IsOpen::None
|
IsOpen::None
|
||||||
} else {
|
} else {
|
||||||
if let Some(conn) = self.pulse_state.connection() {
|
|
||||||
conn.send(pulse::Message::GetSinks);
|
|
||||||
}
|
|
||||||
IsOpen::Output
|
IsOpen::Output
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -465,61 +323,48 @@ impl cosmic::Application for Audio {
|
||||||
self.is_open = if self.is_open == IsOpen::Input {
|
self.is_open = if self.is_open == IsOpen::Input {
|
||||||
IsOpen::None
|
IsOpen::None
|
||||||
} else {
|
} else {
|
||||||
if let Some(conn) = self.pulse_state.connection() {
|
|
||||||
conn.send(pulse::Message::GetSources);
|
|
||||||
}
|
|
||||||
IsOpen::Input
|
IsOpen::Input
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::Pulse(event) => match event {
|
Message::Subscription(message) => {
|
||||||
pulse::Event::Init(mut conn) => {
|
return self
|
||||||
conn.send(pulse::Message::UpdateConnection);
|
.model
|
||||||
self.pulse_state = PulseState::Disconnected(conn);
|
.update(message)
|
||||||
}
|
.map(|message| Message::Subscription(message).into());
|
||||||
pulse::Event::Connected => {
|
}
|
||||||
self.pulse_state.connected();
|
|
||||||
|
Message::SetDefaultSink(pos) => {
|
||||||
|
return self
|
||||||
|
.model
|
||||||
|
.set_default_sink(pos)
|
||||||
|
.map(|message| Message::Subscription(message).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
Message::SetDefaultSource(pos) => {
|
||||||
|
return self
|
||||||
|
.model
|
||||||
|
.set_default_source(pos)
|
||||||
|
.map(|message| Message::Subscription(message).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
Message::ToggleSinkMute => self.model.toggle_sink_mute(),
|
||||||
|
|
||||||
|
Message::ToggleSourceMute => self.model.toggle_source_mute(),
|
||||||
|
|
||||||
|
Message::SetSinkVolume(volume) => {
|
||||||
|
return self
|
||||||
|
.model
|
||||||
|
.set_sink_volume(volume)
|
||||||
|
.map(|message| Message::Subscription(message).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
Message::SetSourceVolume(volume) => {
|
||||||
|
return self
|
||||||
|
.model
|
||||||
|
.set_source_volume(volume)
|
||||||
|
.map(|message| Message::Subscription(message).into());
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(conn) = self.pulse_state.connection() {
|
|
||||||
conn.send(pulse::Message::GetSinks);
|
|
||||||
conn.send(pulse::Message::GetSources);
|
|
||||||
conn.send(pulse::Message::GetDefaultSink);
|
|
||||||
conn.send(pulse::Message::GetDefaultSource);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pulse::Event::MessageReceived(msg) => {
|
|
||||||
match msg {
|
|
||||||
// This is where we match messages from the subscription to app state
|
|
||||||
pulse::Message::SetSinks(sinks) => self.outputs = sinks,
|
|
||||||
pulse::Message::SetSources(mut sources) => {
|
|
||||||
sources.retain(|source| {
|
|
||||||
!source.name.as_ref().is_some_and(|n| n.contains("monitor"))
|
|
||||||
});
|
|
||||||
self.inputs = sources;
|
|
||||||
}
|
|
||||||
pulse::Message::SetDefaultSink(sink) => {
|
|
||||||
self.update_output(Some(sink));
|
|
||||||
}
|
|
||||||
pulse::Message::SetDefaultSource(source) => {
|
|
||||||
self.update_input(Some(source));
|
|
||||||
}
|
|
||||||
pulse::Message::Disconnected => {
|
|
||||||
panic!("Subscription error handling is bad. This should never happen.")
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
tracing::trace!("Received misc message")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pulse::Event::Disconnected => {
|
|
||||||
self.pulse_state.disconnected();
|
|
||||||
if let Some(mut conn) = self.pulse_state.connection().cloned() {
|
|
||||||
_ = tokio::spawn(async move {
|
|
||||||
tokio::time::sleep(tokio::time::Duration::from_secs(30)).await;
|
|
||||||
conn.send(pulse::Message::UpdateConnection);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Message::ToggleMediaControlsInTopPanel(chain, enabled) => {
|
Message::ToggleMediaControlsInTopPanel(chain, enabled) => {
|
||||||
self.timeline.set_chain(chain).start();
|
self.timeline.set_chain(chain).start();
|
||||||
self.config.show_media_controls_in_top_panel = enabled;
|
self.config.show_media_controls_in_top_panel = enabled;
|
||||||
|
|
@ -621,45 +466,6 @@ impl cosmic::Application for Audio {
|
||||||
tokio::spawn(cosmic::process::spawn(cmd));
|
tokio::spawn(cosmic::process::spawn(cmd));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Message::PulseSub(event) => match event {
|
|
||||||
sub_pulse::Event::SinkVolume(value) => {
|
|
||||||
self.current_output.as_mut().map(|output| {
|
|
||||||
output
|
|
||||||
.volume
|
|
||||||
.set(output.volume.len(), percent_to_volume(value as f64))
|
|
||||||
});
|
|
||||||
|
|
||||||
self.output_volume = value as f64;
|
|
||||||
self.output_volume_text = format!("{}%", self.output_volume.round());
|
|
||||||
}
|
|
||||||
sub_pulse::Event::SinkMute(value) => {
|
|
||||||
if let Some(output) = self.current_output.as_mut() {
|
|
||||||
output.mute = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sub_pulse::Event::SourceVolume(value) => {
|
|
||||||
self.current_input.as_mut().map(|input| {
|
|
||||||
input
|
|
||||||
.volume
|
|
||||||
.set(input.volume.len(), percent_to_volume(value as f64))
|
|
||||||
});
|
|
||||||
|
|
||||||
self.input_volume = value as f64;
|
|
||||||
self.input_volume_text = format!("{}%", self.input_volume.round());
|
|
||||||
}
|
|
||||||
sub_pulse::Event::SourceMute(value) => {
|
|
||||||
if let Some(input) = self.current_input.as_mut() {
|
|
||||||
input.mute = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sub_pulse::Event::Channels(c) => {
|
|
||||||
self.channels = Some(c);
|
|
||||||
}
|
|
||||||
sub_pulse::Event::DefaultSink(_) => {}
|
|
||||||
sub_pulse::Event::DefaultSource(_) => {}
|
|
||||||
sub_pulse::Event::CardInfo(_) => {}
|
|
||||||
sub_pulse::Event::Balance(_) => {}
|
|
||||||
},
|
|
||||||
Message::Surface(a) => {
|
Message::Surface(a) => {
|
||||||
return cosmic::task::message(cosmic::Action::Cosmic(
|
return cosmic::task::message(cosmic::Action::Cosmic(
|
||||||
cosmic::app::Action::Surface(a),
|
cosmic::app::Action::Surface(a),
|
||||||
|
|
@ -672,7 +478,6 @@ impl cosmic::Application for Audio {
|
||||||
|
|
||||||
fn subscription(&self) -> Subscription<Message> {
|
fn subscription(&self) -> Subscription<Message> {
|
||||||
Subscription::batch([
|
Subscription::batch([
|
||||||
pulse::connect().map(Message::Pulse),
|
|
||||||
self.timeline
|
self.timeline
|
||||||
.as_subscription()
|
.as_subscription()
|
||||||
.map(|(_, now)| Message::Frame(now)),
|
.map(|(_, now)| Message::Frame(now)),
|
||||||
|
|
@ -684,7 +489,7 @@ impl cosmic::Application for Audio {
|
||||||
}),
|
}),
|
||||||
mpris_subscription::mpris_subscription(0).map(Message::Mpris),
|
mpris_subscription::mpris_subscription(0).map(Message::Mpris),
|
||||||
activation_token_subscription(0).map(Message::Token),
|
activation_token_subscription(0).map(Message::Token),
|
||||||
sub_pulse::subscription().map(Message::PulseSub),
|
Subscription::run(|| css::watch().map(Message::Subscription)),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -705,15 +510,9 @@ impl cosmic::Application for Audio {
|
||||||
return Message::Ignore;
|
return Message::Ignore;
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_volume = (self.output_volume + (scroll_vector as f64)).clamp(
|
let new_volume = (self.model.sink_volume as f64 + (scroll_vector as f64))
|
||||||
0.0,
|
.clamp(0.0, self.max_sink_volume as f64);
|
||||||
if self.output_amplification {
|
Message::SetSinkVolume(new_volume as u32)
|
||||||
150.0
|
|
||||||
} else {
|
|
||||||
100.0
|
|
||||||
},
|
|
||||||
);
|
|
||||||
Message::SetOutputVolume(new_volume)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let playback_buttons = (!self.core.applet.suggested_bounds.as_ref().is_some_and(|c| {
|
let playback_buttons = (!self.core.applet.suggested_bounds.as_ref().is_some_and(|c| {
|
||||||
|
|
@ -724,21 +523,37 @@ impl cosmic::Application for Audio {
|
||||||
|
|
||||||
self.core
|
self.core
|
||||||
.applet
|
.applet
|
||||||
.autosize_window(if let Some(Some(playback_buttons)) = playback_buttons {
|
.autosize_window(
|
||||||
match self.core.applet.anchor {
|
if let Some(playback_buttons) = playback_buttons
|
||||||
PanelAnchor::Left | PanelAnchor::Right => Element::from(
|
&& !playback_buttons.is_empty()
|
||||||
Column::with_children([playback_buttons, btn.into()])
|
{
|
||||||
.align_x(Alignment::Center),
|
match self.core.applet.anchor {
|
||||||
),
|
PanelAnchor::Left | PanelAnchor::Right => Element::from(
|
||||||
PanelAnchor::Top | PanelAnchor::Bottom => {
|
applet_column::Column::with_children(playback_buttons)
|
||||||
Row::with_children([playback_buttons, btn.into()])
|
.push(btn)
|
||||||
.align_y(Alignment::Center)
|
.align_x(Alignment::Center)
|
||||||
.into()
|
// TODO configurable variable from the panel?
|
||||||
|
.spacing(
|
||||||
|
-(self.core.applet.suggested_padding(true).0 as f32)
|
||||||
|
* self.core.applet.padding_overlap,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
PanelAnchor::Top | PanelAnchor::Bottom => {
|
||||||
|
applet_row::Row::with_children(playback_buttons)
|
||||||
|
.push(btn)
|
||||||
|
.align_y(Alignment::Center)
|
||||||
|
// TODO configurable variable from the panel?
|
||||||
|
.spacing(
|
||||||
|
-(self.core.applet.suggested_padding(true).0 as f32)
|
||||||
|
* self.core.applet.padding_overlap,
|
||||||
|
)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
btn.into()
|
||||||
btn.into()
|
},
|
||||||
})
|
)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -747,33 +562,31 @@ impl cosmic::Application for Audio {
|
||||||
space_xxs, space_s, ..
|
space_xxs, space_s, ..
|
||||||
} = theme::active().cosmic().spacing;
|
} = theme::active().cosmic().spacing;
|
||||||
|
|
||||||
let audio_disabled = matches!(self.pulse_state, PulseState::Disconnected(_));
|
let sink = self
|
||||||
let out_mute = self.current_output_mute();
|
.model
|
||||||
let in_mute = self.current_input_mute();
|
.active_sink()
|
||||||
|
.and_then(|pos| self.model.sinks().get(pos));
|
||||||
|
let source = self
|
||||||
|
.model
|
||||||
|
.active_source()
|
||||||
|
.and_then(|pos| self.model.sources().get(pos));
|
||||||
|
|
||||||
let mut audio_content = if audio_disabled {
|
let mut audio_content = {
|
||||||
column![padded_control(
|
let output_slider = slider(
|
||||||
text::title3(fl!("disconnected"))
|
0..=self.max_sink_volume,
|
||||||
.width(Length::Fill)
|
self.model.sink_volume,
|
||||||
.align_x(Alignment::Center)
|
Message::SetSinkVolume,
|
||||||
)]
|
)
|
||||||
} else {
|
.width(Length::FillPortion(5))
|
||||||
let output_slider = if self.output_amplification {
|
.breakpoints(self.sink_breakpoints);
|
||||||
slider(0.0..=150.0, self.output_volume, Message::SetOutputVolume)
|
|
||||||
.width(Length::FillPortion(5))
|
let input_slider = slider(
|
||||||
.breakpoints(&[100.])
|
0..=self.max_source_volume,
|
||||||
} else {
|
self.model.source_volume,
|
||||||
slider(0.0..=100.0, self.output_volume, Message::SetOutputVolume)
|
Message::SetSourceVolume,
|
||||||
.width(Length::FillPortion(5))
|
)
|
||||||
};
|
.width(Length::FillPortion(5))
|
||||||
let input_slider = if self.input_amplification {
|
.breakpoints(self.source_breakpoints);
|
||||||
slider(0.0..=150.0, self.input_volume, Message::SetInputVolume)
|
|
||||||
.width(Length::FillPortion(5))
|
|
||||||
.breakpoints(&[100.])
|
|
||||||
} else {
|
|
||||||
slider(0.0..=100.0, self.input_volume, Message::SetInputVolume)
|
|
||||||
.width(Length::FillPortion(5))
|
|
||||||
};
|
|
||||||
|
|
||||||
column![
|
column![
|
||||||
padded_control(
|
padded_control(
|
||||||
|
|
@ -786,9 +599,9 @@ impl cosmic::Application for Audio {
|
||||||
.class(cosmic::theme::Button::Icon)
|
.class(cosmic::theme::Button::Icon)
|
||||||
.icon_size(24)
|
.icon_size(24)
|
||||||
.line_height(24)
|
.line_height(24)
|
||||||
.on_press(Message::SetOutputMute(!out_mute)),
|
.on_press(Message::ToggleSinkMute),
|
||||||
output_slider,
|
output_slider,
|
||||||
container(text(&self.output_volume_text).size(16))
|
container(text(&self.model.sink_volume_text).size(16))
|
||||||
.width(Length::FillPortion(1))
|
.width(Length::FillPortion(1))
|
||||||
.align_x(Alignment::End)
|
.align_x(Alignment::End)
|
||||||
]
|
]
|
||||||
|
|
@ -805,9 +618,9 @@ impl cosmic::Application for Audio {
|
||||||
.class(cosmic::theme::Button::Icon)
|
.class(cosmic::theme::Button::Icon)
|
||||||
.icon_size(24)
|
.icon_size(24)
|
||||||
.line_height(24)
|
.line_height(24)
|
||||||
.on_press(Message::SetInputMute(!in_mute)),
|
.on_press(Message::ToggleSourceMute),
|
||||||
input_slider,
|
input_slider,
|
||||||
container(text(&self.input_volume_text).size(16))
|
container(text(&self.model.source_volume_text).size(16))
|
||||||
.width(Length::FillPortion(1))
|
.width(Length::FillPortion(1))
|
||||||
.align_x(Alignment::End)
|
.align_x(Alignment::End)
|
||||||
]
|
]
|
||||||
|
|
@ -818,24 +631,24 @@ impl cosmic::Application for Audio {
|
||||||
revealer(
|
revealer(
|
||||||
self.is_open == IsOpen::Output,
|
self.is_open == IsOpen::Output,
|
||||||
fl!("output"),
|
fl!("output"),
|
||||||
match &self.current_output {
|
match sink {
|
||||||
Some(output) => pretty_name(output.description.clone()),
|
Some(sink) => sink.to_owned(),
|
||||||
None => String::from("No device selected"),
|
None => fl!("no-device"),
|
||||||
},
|
},
|
||||||
self.outputs.as_slice(),
|
self.model.sinks(),
|
||||||
Message::OutputToggle,
|
Message::OutputToggle,
|
||||||
Message::OutputChanged,
|
Message::SetDefaultSink,
|
||||||
),
|
),
|
||||||
revealer(
|
revealer(
|
||||||
self.is_open == IsOpen::Input,
|
self.is_open == IsOpen::Input,
|
||||||
fl!("input"),
|
fl!("input"),
|
||||||
match &self.current_input {
|
match source {
|
||||||
Some(input) => pretty_name(input.description.clone()),
|
Some(source) => source.to_owned(),
|
||||||
None => fl!("no-device"),
|
None => fl!("no-device"),
|
||||||
},
|
},
|
||||||
self.inputs.as_slice(),
|
self.model.sources(),
|
||||||
Message::InputToggle,
|
Message::InputToggle,
|
||||||
Message::InputChanged,
|
Message::SetDefaultSource,
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
.align_x(Alignment::Start)
|
.align_x(Alignment::Start)
|
||||||
|
|
@ -961,18 +774,12 @@ fn revealer(
|
||||||
open: bool,
|
open: bool,
|
||||||
title: String,
|
title: String,
|
||||||
selected: String,
|
selected: String,
|
||||||
device_info: &[DeviceInfo],
|
devices: &[String],
|
||||||
toggle: Message,
|
toggle: Message,
|
||||||
mut change: impl FnMut(String) -> Message + 'static,
|
mut change: impl FnMut(usize) -> Message + 'static,
|
||||||
) -> widget::Column<'static, Message, crate::Theme, Renderer> {
|
) -> widget::Column<'static, Message, crate::Theme, Renderer> {
|
||||||
if open {
|
if open {
|
||||||
let options = device_info.iter().map(|device| {
|
devices.iter().cloned().enumerate().fold(
|
||||||
(
|
|
||||||
device.name.clone().unwrap_or_default(),
|
|
||||||
pretty_name(device.description.clone()),
|
|
||||||
)
|
|
||||||
});
|
|
||||||
options.fold(
|
|
||||||
column![revealer_head(open, title, selected, toggle)].width(Length::Fill),
|
column![revealer_head(open, title, selected, toggle)].width(Length::Fill),
|
||||||
|col, (id, name)| {
|
|col, (id, name)| {
|
||||||
col.push(
|
col.push(
|
||||||
|
|
@ -1000,48 +807,3 @@ fn revealer_head(
|
||||||
])
|
])
|
||||||
.on_press(toggle)
|
.on_press(toggle)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pretty_name(name: Option<String>) -> String {
|
|
||||||
match name {
|
|
||||||
Some(n) => n,
|
|
||||||
None => String::from("Generic"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
enum PulseState {
|
|
||||||
#[default]
|
|
||||||
Init,
|
|
||||||
Disconnected(pulse::Connection),
|
|
||||||
Connected(pulse::Connection),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PulseState {
|
|
||||||
fn connection(&mut self) -> Option<&mut pulse::Connection> {
|
|
||||||
match self {
|
|
||||||
Self::Disconnected(c) => Some(c),
|
|
||||||
Self::Connected(c) => Some(c),
|
|
||||||
Self::Init => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn connected(&mut self) {
|
|
||||||
if let Self::Disconnected(c) = self {
|
|
||||||
*self = Self::Connected(c.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn disconnected(&mut self) {
|
|
||||||
if let Self::Connected(c) = self {
|
|
||||||
*self = Self::Disconnected(c.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn volume_to_percent(volume: Volume) -> f64 {
|
|
||||||
volume.0 as f64 * 100. / FULL_VOLUME
|
|
||||||
}
|
|
||||||
|
|
||||||
fn percent_to_volume(percent: f64) -> Volume {
|
|
||||||
Volume((percent / 100. * FULL_VOLUME).clamp(0., MAX_VOLUME).round() as u32)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,840 +0,0 @@
|
||||||
// Copyright 2023 System76 <info@system76.com>
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
|
||||||
|
|
||||||
use std::{cell::RefCell, mem, rc::Rc, sync::LazyLock, thread, time::Duration};
|
|
||||||
|
|
||||||
extern crate libpulse_binding as pulse;
|
|
||||||
|
|
||||||
use cosmic::{
|
|
||||||
iced::{self, Subscription, stream},
|
|
||||||
iced_futures::futures::{self, SinkExt},
|
|
||||||
};
|
|
||||||
|
|
||||||
use libpulse_binding::{
|
|
||||||
callbacks::ListResult,
|
|
||||||
context::{
|
|
||||||
Context,
|
|
||||||
introspect::{Introspector, SinkInfo, SourceInfo},
|
|
||||||
},
|
|
||||||
error::PAErr,
|
|
||||||
mainloop::standard::{IterateResult, Mainloop},
|
|
||||||
proplist::Proplist,
|
|
||||||
volume::ChannelVolumes,
|
|
||||||
};
|
|
||||||
|
|
||||||
use tokio::sync::{Mutex, mpsc};
|
|
||||||
|
|
||||||
pub static FROM_PULSE: LazyLock<Mutex<Option<(mpsc::Receiver<Message>, mpsc::Sender<Message>)>>> =
|
|
||||||
LazyLock::new(|| Mutex::new(None));
|
|
||||||
|
|
||||||
pub fn connect() -> iced::Subscription<Event> {
|
|
||||||
struct SomeWorker;
|
|
||||||
|
|
||||||
Subscription::run_with_id(
|
|
||||||
std::any::TypeId::of::<SomeWorker>(),
|
|
||||||
stream::channel(50, move |mut output| async move {
|
|
||||||
let mut state = State::Connecting(0);
|
|
||||||
|
|
||||||
loop {
|
|
||||||
state = start_listening(state, &mut output).await;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn start_listening(
|
|
||||||
state: State,
|
|
||||||
output: &mut futures::channel::mpsc::Sender<Event>,
|
|
||||||
) -> State {
|
|
||||||
match state {
|
|
||||||
// Waiting for Connection to succeed
|
|
||||||
State::Connecting(mut disconnect_count) => {
|
|
||||||
let mut guard = FROM_PULSE.lock().await;
|
|
||||||
let (from_pulse, to_pulse) = {
|
|
||||||
if guard.is_none() {
|
|
||||||
let PulseHandle {
|
|
||||||
to_pulse,
|
|
||||||
from_pulse,
|
|
||||||
} = PulseHandle::new();
|
|
||||||
_ = output.send(Event::Init(Connection(to_pulse.clone()))).await;
|
|
||||||
|
|
||||||
*guard = Some((from_pulse, to_pulse));
|
|
||||||
}
|
|
||||||
guard.as_mut().unwrap()
|
|
||||||
};
|
|
||||||
to_pulse
|
|
||||||
.send(Message::UpdateConnection)
|
|
||||||
.await
|
|
||||||
.expect("Failed to request connection update");
|
|
||||||
|
|
||||||
match from_pulse.recv().await {
|
|
||||||
Some(Message::Connected) => {
|
|
||||||
disconnect_count = 0;
|
|
||||||
_ = output.send(Event::Connected).await;
|
|
||||||
State::Connected
|
|
||||||
}
|
|
||||||
Some(Message::Disconnected) => {
|
|
||||||
disconnect_count += 1;
|
|
||||||
_ = output.send(Event::Disconnected).await;
|
|
||||||
tokio::time::sleep(Duration::from_millis(
|
|
||||||
2_usize
|
|
||||||
.saturating_pow(disconnect_count.try_into().unwrap_or(u32::MAX))
|
|
||||||
.try_into()
|
|
||||||
.unwrap_or(u64::MAX),
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
State::Connecting(1)
|
|
||||||
}
|
|
||||||
Some(m) => {
|
|
||||||
tracing::error!("Unexpected message: {:?}", m);
|
|
||||||
State::Connecting(1)
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
panic!("Pulse Sender dropped, something has gone wrong!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
State::Connected => {
|
|
||||||
let mut guard = FROM_PULSE.lock().await;
|
|
||||||
let Some((from_pulse, _)) = guard.as_mut() else {
|
|
||||||
return State::Connecting(1);
|
|
||||||
};
|
|
||||||
// This is where we match messages from the pulse server to pass to the gui
|
|
||||||
match from_pulse.recv().await {
|
|
||||||
Some(Message::SetSinks(sinks)) => {
|
|
||||||
_ = output
|
|
||||||
.send(Event::MessageReceived(Message::SetSinks(sinks)))
|
|
||||||
.await;
|
|
||||||
|
|
||||||
State::Connected
|
|
||||||
}
|
|
||||||
Some(Message::SetSources(sources)) => {
|
|
||||||
_ = output
|
|
||||||
.send(Event::MessageReceived(Message::SetSources(sources)))
|
|
||||||
.await;
|
|
||||||
State::Connected
|
|
||||||
}
|
|
||||||
Some(Message::SetDefaultSink(sink)) => {
|
|
||||||
_ = output
|
|
||||||
.send(Event::MessageReceived(Message::SetDefaultSink(sink)))
|
|
||||||
.await;
|
|
||||||
State::Connected
|
|
||||||
}
|
|
||||||
Some(Message::SetDefaultSource(source)) => {
|
|
||||||
_ = output
|
|
||||||
.send(Event::MessageReceived(Message::SetDefaultSource(source)))
|
|
||||||
.await;
|
|
||||||
State::Connected
|
|
||||||
}
|
|
||||||
Some(Message::Disconnected) => {
|
|
||||||
_ = output.send(Event::Disconnected).await;
|
|
||||||
State::Connecting(1)
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
_ = output.send(Event::Disconnected).await;
|
|
||||||
State::Connecting(1)
|
|
||||||
}
|
|
||||||
_ => State::Connected,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// #[derive(Debug)]
|
|
||||||
enum State {
|
|
||||||
Connecting(usize),
|
|
||||||
Connected,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub enum Event {
|
|
||||||
Init(Connection),
|
|
||||||
Connected,
|
|
||||||
Disconnected,
|
|
||||||
MessageReceived(Message),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct Connection(mpsc::Sender<Message>);
|
|
||||||
|
|
||||||
impl Connection {
|
|
||||||
pub fn send(&mut self, message: Message) {
|
|
||||||
if let Err(e) = self.0.try_send(message) {
|
|
||||||
match e {
|
|
||||||
mpsc::error::TrySendError::Closed(_) => {
|
|
||||||
tracing::error!(
|
|
||||||
"Failed to send message: PulseAudio server communication closed"
|
|
||||||
);
|
|
||||||
panic!();
|
|
||||||
}
|
|
||||||
mpsc::error::TrySendError::Full(_) => {
|
|
||||||
tracing::warn!("Failed to send message to PulseAudio server: channel is full");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
pub enum Message {
|
|
||||||
Connected,
|
|
||||||
Disconnected,
|
|
||||||
GetSinks,
|
|
||||||
GetSources,
|
|
||||||
UpdateConnection,
|
|
||||||
SetSinks(Vec<DeviceInfo>),
|
|
||||||
SetSources(Vec<DeviceInfo>),
|
|
||||||
GetDefaultSink,
|
|
||||||
GetDefaultSource,
|
|
||||||
SetDefaultSink(DeviceInfo),
|
|
||||||
SetDefaultSource(DeviceInfo),
|
|
||||||
SetSinkVolumeByName(String, ChannelVolumes),
|
|
||||||
SetSourceVolumeByName(String, ChannelVolumes),
|
|
||||||
SetSinkMuteByName(String, bool),
|
|
||||||
SetSourceMuteByName(String, bool),
|
|
||||||
}
|
|
||||||
|
|
||||||
struct PulseHandle {
|
|
||||||
to_pulse: tokio::sync::mpsc::Sender<Message>,
|
|
||||||
from_pulse: tokio::sync::mpsc::Receiver<Message>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PulseHandle {
|
|
||||||
// Create pulse server thread, and bidirectional comms
|
|
||||||
pub fn new() -> Self {
|
|
||||||
let (to_pulse, mut to_pulse_recv) = tokio::sync::mpsc::channel(50);
|
|
||||||
let (from_pulse_send, from_pulse) = tokio::sync::mpsc::channel(50);
|
|
||||||
|
|
||||||
// this thread should complete by pushing a completed message,
|
|
||||||
// or fail message. This should never complete/fail without pushing
|
|
||||||
// a message. This lets the iced subscription go to sleep while init
|
|
||||||
// finishes. TLDR: be very careful with error handling
|
|
||||||
thread::spawn(move || {
|
|
||||||
let rt = tokio::runtime::Builder::new_current_thread()
|
|
||||||
.enable_all()
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// take `PulseServer` and handle reciver into async context
|
|
||||||
// to listen for messages that need to be passed to the pulseserver
|
|
||||||
// this lets us put the thread to sleep, but keep hold a single
|
|
||||||
// thread, because pulse audio's API is not multithreaded... at all
|
|
||||||
rt.block_on(async {
|
|
||||||
let mut server: Option<PulseServer> = None;
|
|
||||||
|
|
||||||
let mut msgs = Vec::new();
|
|
||||||
|
|
||||||
loop {
|
|
||||||
if let Some(msg) = to_pulse_recv.recv().await {
|
|
||||||
msgs.push(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Consume any additional messages in the channel.
|
|
||||||
while let Ok(msg) = to_pulse_recv.try_recv() {
|
|
||||||
// Deduplicate volume change messages.
|
|
||||||
if matches!(
|
|
||||||
msg,
|
|
||||||
Message::SetSinkVolumeByName(..) | Message::SetSourceVolumeByName(..)
|
|
||||||
) {
|
|
||||||
let last_msg = msgs.last_mut().unwrap(); //
|
|
||||||
if mem::discriminant(last_msg) == mem::discriminant(&msg) {
|
|
||||||
*last_msg = msg;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
msgs.push(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
for msg in msgs.drain(..) {
|
|
||||||
match msg {
|
|
||||||
Message::GetDefaultSink => {
|
|
||||||
let Some(server) = server.as_mut() else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
match server.get_default_sink() {
|
|
||||||
Ok(sink) => {
|
|
||||||
if let Err(err) = from_pulse_send
|
|
||||||
.send(Message::SetDefaultSink(sink))
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
tracing::error!("ERROR! {}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(_) => Self::send_disconnected(&from_pulse_send).await,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Message::GetDefaultSource => {
|
|
||||||
let Some(server) = server.as_mut() else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
match server.get_default_source() {
|
|
||||||
Ok(source) => {
|
|
||||||
if let Err(err) = from_pulse_send
|
|
||||||
.send(Message::SetDefaultSource(source))
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
tracing::error!("ERROR! {}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
tracing::error!("ERROR! {:?}", e);
|
|
||||||
Self::send_disconnected(&from_pulse_send).await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Message::GetSinks => {
|
|
||||||
let Some(server) = server.as_mut() else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
match server.get_sinks() {
|
|
||||||
Ok(sinks) => {
|
|
||||||
if let Err(err) =
|
|
||||||
from_pulse_send.send(Message::SetSinks(sinks)).await
|
|
||||||
{
|
|
||||||
tracing::error!("ERROR! {}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(_) => Self::send_disconnected(&from_pulse_send).await,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Message::GetSources => {
|
|
||||||
let Some(server) = server.as_mut() else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
match server.get_sources() {
|
|
||||||
Ok(sinks) => {
|
|
||||||
if let Err(err) =
|
|
||||||
from_pulse_send.send(Message::SetSources(sinks)).await
|
|
||||||
{
|
|
||||||
tracing::error!("ERROR! {}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(_) => Self::send_disconnected(&from_pulse_send).await,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Message::SetSinkVolumeByName(name, channel_volumes) => {
|
|
||||||
let Some(server) = server.as_mut() else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
server.set_sink_volume_by_name(&name, &channel_volumes);
|
|
||||||
}
|
|
||||||
Message::SetSourceVolumeByName(name, channel_volumes) => {
|
|
||||||
let Some(server) = server.as_mut() else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
server.set_source_volume_by_name(&name, &channel_volumes);
|
|
||||||
}
|
|
||||||
Message::SetSinkMuteByName(name, mute) => {
|
|
||||||
let Some(server) = server.as_mut() else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
let op =
|
|
||||||
server.introspector.set_sink_mute_by_name(&name, mute, None);
|
|
||||||
server.wait_for_result(op).ok();
|
|
||||||
}
|
|
||||||
Message::SetSourceMuteByName(name, mute) => {
|
|
||||||
let Some(server) = server.as_mut() else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
let op = server
|
|
||||||
.introspector
|
|
||||||
.set_source_mute_by_name(&name, mute, None);
|
|
||||||
server.wait_for_result(op).ok();
|
|
||||||
}
|
|
||||||
Message::UpdateConnection => {
|
|
||||||
tracing::info!(
|
|
||||||
"Updating Connection, server exists: {:?}",
|
|
||||||
server.is_some()
|
|
||||||
);
|
|
||||||
if let Some(mut cur_server) = server.take() {
|
|
||||||
if cur_server.get_server_info().is_err() {
|
|
||||||
tracing::warn!("got error, server must be disconnected...");
|
|
||||||
Self::send_disconnected(&from_pulse_send).await;
|
|
||||||
} else {
|
|
||||||
tracing::info!("got server info, still connected...");
|
|
||||||
server = Some(cur_server);
|
|
||||||
Self::send_connected(&from_pulse_send).await;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
match PulseServer::connect().and_then(PulseServer::init) {
|
|
||||||
Ok(new_server) => {
|
|
||||||
tracing::info!("Connected to server");
|
|
||||||
Self::send_connected(&from_pulse_send).await;
|
|
||||||
server = Some(new_server);
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
tracing::error!(
|
|
||||||
"Failed to connect to server: {:?}",
|
|
||||||
err
|
|
||||||
);
|
|
||||||
Self::send_disconnected(&from_pulse_send).await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Message::SetDefaultSink(device) => {
|
|
||||||
let Some(server) = server.as_mut() else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
let Ok(default_sink) = server.get_default_sink() else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
let to_move = server.get_sink_inputs(default_sink.index);
|
|
||||||
if let Some(name) = device.name.as_ref() {
|
|
||||||
if server.set_default_sink(name, to_move) {
|
|
||||||
if let Err(err) = from_pulse_send
|
|
||||||
.send(Message::SetDefaultSink(device))
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
tracing::error!("ERROR! {:?}", err);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Message::SetDefaultSource(device) => {
|
|
||||||
let Some(server) = server.as_mut() else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
let Ok(default_source) = server.get_default_source() else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
let to_move = server.get_source_outputs(default_source.index);
|
|
||||||
if let Some(name) = device.name.as_ref() {
|
|
||||||
if server.set_default_source(name, to_move) {
|
|
||||||
if let Err(err) = from_pulse_send
|
|
||||||
.send(Message::SetDefaultSource(device))
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
tracing::error!("ERROR! {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
tracing::warn!("message doesn't match");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Self {
|
|
||||||
to_pulse,
|
|
||||||
from_pulse,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn send_disconnected(sender: &tokio::sync::mpsc::Sender<Message>) {
|
|
||||||
sender.send(Message::Disconnected).await.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
async fn send_connected(sender: &tokio::sync::mpsc::Sender<Message>) {
|
|
||||||
sender.send(Message::Connected).await.unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct PulseServer {
|
|
||||||
mainloop: Rc<RefCell<Mainloop>>,
|
|
||||||
context: Rc<RefCell<Context>>,
|
|
||||||
introspector: Introspector,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
enum PulseServerError<'a> {
|
|
||||||
IterateErr(IterateResult),
|
|
||||||
ContextErr(pulse::context::State),
|
|
||||||
OperationErr(pulse::operation::State),
|
|
||||||
PAErr(PAErr),
|
|
||||||
Connect,
|
|
||||||
Misc(&'a str),
|
|
||||||
}
|
|
||||||
|
|
||||||
// `PulseServer` code is heavily inspired by Dave Patrick Caberto's pulsectl-rs (SeaDve)
|
|
||||||
// https://crates.io/crates/pulsectl-rs
|
|
||||||
impl PulseServer {
|
|
||||||
// connect() requires init() to be run after
|
|
||||||
pub fn connect() -> Result<Self, PulseServerError<'static>> {
|
|
||||||
// TODO: fix app name, should be variable
|
|
||||||
let mut proplist = Proplist::new().unwrap();
|
|
||||||
proplist
|
|
||||||
.set_str(
|
|
||||||
pulse::proplist::properties::APPLICATION_NAME,
|
|
||||||
"com.system76",
|
|
||||||
)
|
|
||||||
.or(Err(PulseServerError::Connect))?;
|
|
||||||
|
|
||||||
let mainloop = Rc::new(RefCell::new(
|
|
||||||
pulse::mainloop::standard::Mainloop::new().ok_or(PulseServerError::Connect)?,
|
|
||||||
));
|
|
||||||
|
|
||||||
let context = Rc::new(RefCell::new(
|
|
||||||
Context::new_with_proplist(&*mainloop.borrow(), "MainConn", &proplist)
|
|
||||||
.ok_or(PulseServerError::Connect)?,
|
|
||||||
));
|
|
||||||
|
|
||||||
let introspector = context.borrow_mut().introspect();
|
|
||||||
|
|
||||||
context
|
|
||||||
.borrow_mut()
|
|
||||||
.connect(None, pulse::context::FlagSet::NOFLAGS, None)
|
|
||||||
.map_err(PulseServerError::PAErr)?;
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
mainloop,
|
|
||||||
context,
|
|
||||||
introspector,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for pulse audio connection to complete
|
|
||||||
pub fn init(self) -> Result<Self, PulseServerError<'static>> {
|
|
||||||
loop {
|
|
||||||
match self.mainloop.borrow_mut().iterate(false) {
|
|
||||||
IterateResult::Success(_) => {}
|
|
||||||
IterateResult::Err(e) => {
|
|
||||||
return Err(PulseServerError::IterateErr(IterateResult::Err(e)));
|
|
||||||
}
|
|
||||||
IterateResult::Quit(e) => {
|
|
||||||
return Err(PulseServerError::IterateErr(IterateResult::Quit(e)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match self.context.borrow().get_state() {
|
|
||||||
pulse::context::State::Ready => break,
|
|
||||||
pulse::context::State::Failed => {
|
|
||||||
return Err(PulseServerError::ContextErr(pulse::context::State::Failed));
|
|
||||||
}
|
|
||||||
pulse::context::State::Terminated => {
|
|
||||||
return Err(PulseServerError::ContextErr(
|
|
||||||
pulse::context::State::Terminated,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get a list of output devices
|
|
||||||
pub fn get_sinks(&self) -> Result<Vec<DeviceInfo>, PulseServerError<'_>> {
|
|
||||||
let list: Rc<RefCell<Option<Vec<DeviceInfo>>>> = Rc::new(RefCell::new(Some(Vec::new())));
|
|
||||||
let list_ref = list.clone();
|
|
||||||
|
|
||||||
let operation = self.introspector.get_sink_info_list(
|
|
||||||
move |sink_list: ListResult<&pulse::context::introspect::SinkInfo>| {
|
|
||||||
if let ListResult::Item(item) = sink_list {
|
|
||||||
list_ref.borrow_mut().as_mut().unwrap().push(item.into());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
self.wait_for_result(operation).and_then(|()| {
|
|
||||||
list.borrow_mut().take().ok_or(PulseServerError::Misc(
|
|
||||||
"get_sinks(): failed to wait for operation",
|
|
||||||
))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get a list of input devices
|
|
||||||
pub fn get_sources(&self) -> Result<Vec<DeviceInfo>, PulseServerError<'_>> {
|
|
||||||
let list: Rc<RefCell<Option<Vec<DeviceInfo>>>> = Rc::new(RefCell::new(Some(Vec::new())));
|
|
||||||
let list_ref = list.clone();
|
|
||||||
|
|
||||||
let operation = self.introspector.get_source_info_list(
|
|
||||||
move |sink_list: ListResult<&pulse::context::introspect::SourceInfo>| {
|
|
||||||
if let ListResult::Item(item) = sink_list {
|
|
||||||
list_ref.borrow_mut().as_mut().unwrap().push(item.into());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
self.wait_for_result(operation).and_then(|()| {
|
|
||||||
list.borrow_mut().take().ok_or(PulseServerError::Misc(
|
|
||||||
"get_sources(): Failed to wait for operation",
|
|
||||||
))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_server_info(&mut self) -> Result<ServerInfo, PulseServerError<'_>> {
|
|
||||||
let info = Rc::new(RefCell::new(Some(None)));
|
|
||||||
let info_ref = info.clone();
|
|
||||||
|
|
||||||
let op = self.introspector.get_server_info(move |res| {
|
|
||||||
info_ref.borrow_mut().as_mut().unwrap().replace(res.into());
|
|
||||||
});
|
|
||||||
self.wait_for_result(op)?;
|
|
||||||
info.take()
|
|
||||||
.flatten()
|
|
||||||
.ok_or(PulseServerError::Misc("get_server_info(): failed"))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_default_sink(&mut self, sink: &str, to_move: Vec<u32>) -> bool {
|
|
||||||
let set_default_success = Rc::new(RefCell::new(false));
|
|
||||||
let set_default_success_ref = set_default_success.clone();
|
|
||||||
let op = self
|
|
||||||
.context
|
|
||||||
.borrow_mut()
|
|
||||||
.set_default_sink(sink, move |ret| {
|
|
||||||
*set_default_success.borrow_mut() = ret;
|
|
||||||
});
|
|
||||||
self.wait_for_result(op).ok();
|
|
||||||
if !set_default_success_ref.replace(true) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for index in to_move {
|
|
||||||
let move_success = Rc::new(RefCell::new(false));
|
|
||||||
let op = self.introspector.move_sink_input_by_name(
|
|
||||||
index,
|
|
||||||
sink,
|
|
||||||
Some(Box::new(move |ret| {
|
|
||||||
*move_success.borrow_mut() = ret;
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
|
|
||||||
self.wait_for_result(op).ok();
|
|
||||||
}
|
|
||||||
// TODO handle errors
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_default_source(&mut self, sink: &str, to_move: Vec<u32>) -> bool {
|
|
||||||
let set_default_success = Rc::new(RefCell::new(false));
|
|
||||||
let set_default_success_ref = set_default_success.clone();
|
|
||||||
let op = self
|
|
||||||
.context
|
|
||||||
.borrow_mut()
|
|
||||||
.set_default_source(sink, move |ret| {
|
|
||||||
*set_default_success.borrow_mut() = ret;
|
|
||||||
});
|
|
||||||
self.wait_for_result(op).ok();
|
|
||||||
|
|
||||||
if !set_default_success_ref.replace(true) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for index in to_move {
|
|
||||||
let move_success = Rc::new(RefCell::new(false));
|
|
||||||
let op = self.introspector.move_source_output_by_name(
|
|
||||||
index,
|
|
||||||
sink,
|
|
||||||
Some(Box::new(move |ret| {
|
|
||||||
*move_success.borrow_mut() = ret;
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
|
|
||||||
self.wait_for_result(op).ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_default_sink(&mut self) -> Result<DeviceInfo, PulseServerError<'_>> {
|
|
||||||
let server_info = self.get_server_info();
|
|
||||||
match server_info {
|
|
||||||
Ok(info) => {
|
|
||||||
let name = &info.default_sink_name.unwrap_or_default();
|
|
||||||
let device = Rc::new(RefCell::new(Some(None)));
|
|
||||||
let dev_ref = device.clone();
|
|
||||||
let op = self.introspector.get_sink_info_by_name(
|
|
||||||
name,
|
|
||||||
move |sink_list: ListResult<&SinkInfo>| {
|
|
||||||
if let ListResult::Item(item) = sink_list {
|
|
||||||
dev_ref.borrow_mut().as_mut().unwrap().replace(item.into());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
self.wait_for_result(op)?;
|
|
||||||
let mut result = device.borrow_mut();
|
|
||||||
result.take().unwrap().ok_or({
|
|
||||||
PulseServerError::Misc("get_default_sink(): Error getting requested device")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
Err(_) => Err(PulseServerError::Misc("get_default_sink() failed")),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_default_source(&mut self) -> Result<DeviceInfo, PulseServerError<'_>> {
|
|
||||||
let server_info = self.get_server_info();
|
|
||||||
match server_info {
|
|
||||||
Ok(info) => {
|
|
||||||
let name = &info.default_source_name.unwrap_or_default();
|
|
||||||
let device = Rc::new(RefCell::new(Some(None)));
|
|
||||||
let dev_ref = device.clone();
|
|
||||||
let op = self.introspector.get_source_info_by_name(
|
|
||||||
name,
|
|
||||||
move |sink_list: ListResult<&SourceInfo>| {
|
|
||||||
if let ListResult::Item(item) = sink_list {
|
|
||||||
dev_ref.borrow_mut().as_mut().unwrap().replace(item.into());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
self.wait_for_result(op)?;
|
|
||||||
let mut result = device.borrow_mut();
|
|
||||||
result.take().unwrap().ok_or({
|
|
||||||
PulseServerError::Misc("get_default_source(): Error getting requested device")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
Err(_) => Err(PulseServerError::Misc("get_default_source() failed")),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_sink_volume_by_name(&mut self, name: &str, volume: &ChannelVolumes) {
|
|
||||||
let op = self
|
|
||||||
.introspector
|
|
||||||
.set_sink_mute_by_name(name, volume.is_muted(), None);
|
|
||||||
self.wait_for_result(op).ok();
|
|
||||||
|
|
||||||
let op = self
|
|
||||||
.introspector
|
|
||||||
.set_sink_volume_by_name(name, volume, None);
|
|
||||||
self.wait_for_result(op).ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_source_volume_by_name(&mut self, name: &str, volume: &ChannelVolumes) {
|
|
||||||
let op = self
|
|
||||||
.introspector
|
|
||||||
.set_source_mute_by_name(name, volume.is_muted(), None);
|
|
||||||
let _ = self.wait_for_result(op);
|
|
||||||
|
|
||||||
let op = self
|
|
||||||
.introspector
|
|
||||||
.set_source_volume_by_name(name, volume, None);
|
|
||||||
let _ = self.wait_for_result(op);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_source_outputs(&mut self, source: u32) -> Vec<u32> {
|
|
||||||
let result = Rc::new(RefCell::new(Vec::new()));
|
|
||||||
let result_ref = Rc::new(RefCell::new(Vec::new()));
|
|
||||||
let op = self.introspector.get_source_output_info_list(move |list| {
|
|
||||||
if let ListResult::Item(item) = list {
|
|
||||||
if source == item.source {
|
|
||||||
result.borrow_mut().push(item.index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let _ = self.wait_for_result(op);
|
|
||||||
result_ref.replace(Vec::new())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_sink_inputs(&mut self, sink: u32) -> Vec<u32> {
|
|
||||||
let result = Rc::new(RefCell::new(Vec::new()));
|
|
||||||
let result_ref = Rc::new(RefCell::new(Vec::new()));
|
|
||||||
let op = self.introspector.get_sink_input_info_list(move |list| {
|
|
||||||
if let ListResult::Item(item) = list {
|
|
||||||
if sink == item.sink {
|
|
||||||
result.borrow_mut().push(item.index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let _ = self.wait_for_result(op);
|
|
||||||
result_ref.replace(Vec::new())
|
|
||||||
}
|
|
||||||
|
|
||||||
// after building an operation such as get_devices() we need to keep polling
|
|
||||||
// the pulse audio server to "wait" for the operation to complete
|
|
||||||
fn wait_for_result<G: ?Sized>(
|
|
||||||
&self,
|
|
||||||
operation: pulse::operation::Operation<G>,
|
|
||||||
) -> Result<(), PulseServerError<'_>> {
|
|
||||||
// TODO: make this loop async. It is already in an async context, so
|
|
||||||
// we could make this thread sleep while waiting for the pulse server's
|
|
||||||
// response.
|
|
||||||
loop {
|
|
||||||
match self.mainloop.borrow_mut().iterate(false) {
|
|
||||||
IterateResult::Err(e) => {
|
|
||||||
return Err(PulseServerError::IterateErr(IterateResult::Err(e)));
|
|
||||||
}
|
|
||||||
IterateResult::Quit(e) => {
|
|
||||||
return Err(PulseServerError::IterateErr(IterateResult::Quit(e)));
|
|
||||||
}
|
|
||||||
IterateResult::Success(_) => {}
|
|
||||||
}
|
|
||||||
match operation.get_state() {
|
|
||||||
pulse::operation::State::Done => return Ok(()),
|
|
||||||
pulse::operation::State::Running => {}
|
|
||||||
pulse::operation::State::Cancelled => {
|
|
||||||
return Err(PulseServerError::OperationErr(
|
|
||||||
pulse::operation::State::Cancelled,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
pub struct DeviceInfo {
|
|
||||||
pub name: Option<String>,
|
|
||||||
pub description: Option<String>,
|
|
||||||
pub volume: ChannelVolumes,
|
|
||||||
pub mute: bool,
|
|
||||||
pub index: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&SinkInfo<'a>> for DeviceInfo {
|
|
||||||
fn from(info: &SinkInfo<'a>) -> Self {
|
|
||||||
Self {
|
|
||||||
name: info.name.as_deref().map(str::to_string),
|
|
||||||
description: info.description.as_deref().map(str::to_string),
|
|
||||||
volume: info.volume,
|
|
||||||
mute: info.mute,
|
|
||||||
index: info.index,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&SourceInfo<'a>> for DeviceInfo {
|
|
||||||
fn from(info: &SourceInfo<'a>) -> Self {
|
|
||||||
Self {
|
|
||||||
name: info.name.as_deref().map(str::to_string),
|
|
||||||
description: info.description.as_deref().map(str::to_string),
|
|
||||||
volume: info.volume,
|
|
||||||
mute: info.mute,
|
|
||||||
index: info.index,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Eq for DeviceInfo {}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ServerInfo {
|
|
||||||
/// User name of the daemon process.
|
|
||||||
pub user_name: Option<String>,
|
|
||||||
/// Host name the daemon is running on.
|
|
||||||
pub host_name: Option<String>,
|
|
||||||
/// Version string of the daemon.
|
|
||||||
pub server_version: Option<String>,
|
|
||||||
/// Server package name (usually “pulseaudio”).
|
|
||||||
pub server_name: Option<String>,
|
|
||||||
// Default sample specification.
|
|
||||||
//pub sample_spec: sample::Spec,
|
|
||||||
/// Name of default sink.
|
|
||||||
pub default_sink_name: Option<String>,
|
|
||||||
/// Name of default source.
|
|
||||||
pub default_source_name: Option<String>,
|
|
||||||
/// A random cookie for identifying this instance of PulseAudio.
|
|
||||||
pub cookie: u32,
|
|
||||||
// Default channel map.
|
|
||||||
//pub channel_map: channelmap::Map,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&'a pulse::context::introspect::ServerInfo<'a>> for ServerInfo {
|
|
||||||
fn from(info: &'a pulse::context::introspect::ServerInfo<'a>) -> Self {
|
|
||||||
use std::borrow::Cow;
|
|
||||||
Self {
|
|
||||||
user_name: info.user_name.as_ref().map(Cow::to_string),
|
|
||||||
host_name: info.host_name.as_ref().map(Cow::to_string),
|
|
||||||
server_version: info.server_version.as_ref().map(Cow::to_string),
|
|
||||||
server_name: info.server_name.as_ref().map(Cow::to_string),
|
|
||||||
//sample_spec: info.sample_spec,
|
|
||||||
default_sink_name: info.default_sink_name.as_ref().map(Cow::to_string),
|
|
||||||
default_source_name: info.default_source_name.as_ref().map(Cow::to_string),
|
|
||||||
cookie: info.cookie,
|
|
||||||
//channel_map: info.channel_map,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +1,11 @@
|
||||||
[package]
|
[package]
|
||||||
name = "cosmic-applet-battery"
|
name = "cosmic-applet-battery"
|
||||||
version = "0.1.0"
|
version = "1.0.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "GPL-3.0-only"
|
license = "GPL-3.0-only"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
cosmic-settings-subscriptions = { workspace = true, features = [
|
|
||||||
"upower",
|
|
||||||
"settings_daemon",
|
|
||||||
] }
|
|
||||||
cosmic-time.workspace = true
|
cosmic-time.workspace = true
|
||||||
drm = "0.14.1"
|
drm = "0.14.1"
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
|
|
@ -24,3 +20,9 @@ tracing-subscriber.workspace = true
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
udev = "0.9"
|
udev = "0.9"
|
||||||
zbus.workspace = true
|
zbus.workspace = true
|
||||||
|
|
||||||
|
[dependencies.cosmic-settings-upower-subscription]
|
||||||
|
git = "https://github.com/pop-os/cosmic-settings"
|
||||||
|
|
||||||
|
[dependencies.cosmic-settings-daemon-subscription]
|
||||||
|
git = "https://github.com/pop-os/cosmic-settings"
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ Name[nl]=Energie en batterij
|
||||||
Name[de]=Energie und Akku
|
Name[de]=Energie und Akku
|
||||||
Name[sk]=Napájanie a batéria
|
Name[sk]=Napájanie a batéria
|
||||||
Name[sv]=Ström & batteri
|
Name[sv]=Ström & batteri
|
||||||
|
Name[it]=Alimentazione e batteria
|
||||||
Type=Application
|
Type=Application
|
||||||
Exec=cosmic-applet-battery
|
Exec=cosmic-applet-battery
|
||||||
Terminal=false
|
Terminal=false
|
||||||
|
|
@ -22,5 +23,6 @@ Icon=com.system76.CosmicAppletBattery-symbolic
|
||||||
StartupNotify=true
|
StartupNotify=true
|
||||||
NoDisplay=true
|
NoDisplay=true
|
||||||
X-CosmicApplet=true
|
X-CosmicApplet=true
|
||||||
|
X-CosmicShrinkable=true
|
||||||
X-CosmicHoverPopup=Start
|
X-CosmicHoverPopup=Start
|
||||||
X-OverflowPriority=10
|
X-OverflowPriority=10
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
battery = المُدَّخرة
|
battery = المُدَّخرة
|
||||||
battery-desc = الأداء وخفض استهلاك الطاقة.
|
battery-desc = أداء واستهلاك طاقة مخفض.
|
||||||
balanced = متوازن
|
balanced = متوازن
|
||||||
balanced-desc = مُعايرة الأداء واستهلاك المُدَّخرة.
|
balanced-desc = أداء واستهلاك المُدَّخرة قياسي.
|
||||||
performance = أداء عالٍ
|
performance = أداء عالي
|
||||||
performance-desc = أداء واستهلاك طاقة مرتفعان.
|
performance-desc = أداء واستهلاك طاقة عالٍ.
|
||||||
max-charge = زِد من مدة صلاحية مُدَّخرتك بوضع حد أقصى للشحن على 80٪
|
max-charge = زِد من مدة صلاحية مُدَّخرتك بوضع حد أقصى للشحن على 80٪
|
||||||
seconds = ث
|
seconds = ث
|
||||||
minutes = د
|
minutes = د
|
||||||
|
|
@ -11,4 +11,4 @@ hours = س
|
||||||
until-empty = حتى النفاد
|
until-empty = حتى النفاد
|
||||||
power-settings = إعدادات الطاقة والمُدَّخرة...
|
power-settings = إعدادات الطاقة والمُدَّخرة...
|
||||||
dgpu-running = وحدة معالجة رسوميات مُنفردة نشطة قد تقلل من عمر المُدَّخرة
|
dgpu-running = وحدة معالجة رسوميات مُنفردة نشطة قد تقلل من عمر المُدَّخرة
|
||||||
dgpu-applications = التطبيقات التي تستخدم وحدة { $gpu_name } المنفصلة
|
dgpu-applications = التطبيقات التي تستخدم معالج الرسوميات { $gpu_name } المُنفردة
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
battery = Батерия
|
battery = Батерия
|
||||||
battery-desc = Намалено потребление на енергия и тиха работа.
|
battery-desc = Намалена производителност и ниско потребление на енергия.
|
||||||
balanced = Баланс
|
balanced = Балансиран
|
||||||
balanced-desc = Тиха работа и умерено потребление на енергия.
|
balanced-desc = Умерена производителност и стандартно потребление на енергия.
|
||||||
performance = Бързина
|
performance = Висока Производителност
|
||||||
performance-desc = Максимална производителност и потребление на енергия.
|
performance-desc = Максимална производителност и потребление на енергия.
|
||||||
max-charge = Увеличете живота на батерията, като зададете максимална стойност на зареждане от 80%
|
max-charge = Увеличете живота на батерията, като зададете максимална стойност на зареждане от 80%
|
||||||
seconds = с
|
seconds = с
|
||||||
|
|
|
||||||
0
cosmic-applet-battery/i18n/bn/cosmic_applet_battery.ftl
Normal file
0
cosmic-applet-battery/i18n/bn/cosmic_applet_battery.ftl
Normal file
|
|
@ -1,14 +1,14 @@
|
||||||
battery = Batterie
|
battery = Batterie
|
||||||
battery-desc = Performance et consommation réduites.
|
battery-desc = Consommation et performances réduites.
|
||||||
balanced = Équilibré
|
balanced = Équilibré
|
||||||
balanced-desc = Performance et usage de la batterie standard.
|
balanced-desc = Performances et usage de la batterie standard.
|
||||||
performance = Hautes performances
|
performance = Hautes performances
|
||||||
performance-desc = Performances et consommation élevées.
|
performance-desc = Performances et consommation élevées.
|
||||||
max-charge = Augmente la durée de vie de votre batterie en mettant la charge maximale à 80%
|
max-charge = Prolongez la durée de vie de votre batterie en arrêtant la charge à 80%
|
||||||
seconds = s
|
seconds = s
|
||||||
minutes = m
|
minutes = m
|
||||||
hours = h
|
hours = h
|
||||||
until-empty = avant la décharge totale
|
until-empty = avant décharge complète
|
||||||
power-settings = Paramètres d'alimentation...
|
power-settings = Paramètres d'alimentation...
|
||||||
dgpu-running = Le GPU dédié est actif et peu réduire l'autonomie de la batterie
|
dgpu-running = Le GPU dédié est actif et peut réduire la durée de vie de la batterie
|
||||||
dgpu-applications = Applications utilisant le GPU dédié {$gpu_name}
|
dgpu-applications = Applications utilisant le GPU dédié { $gpu_name }
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ battery = Ceallraí
|
||||||
battery-desc = Ídiú cumhachta agus feidhmíocht laghdaithe.
|
battery-desc = Ídiú cumhachta agus feidhmíocht laghdaithe.
|
||||||
balanced = Cothromaithe
|
balanced = Cothromaithe
|
||||||
balanced-desc = Feidhmíocht chaighdeánach agus úsáid ceallraí.
|
balanced-desc = Feidhmíocht chaighdeánach agus úsáid ceallraí.
|
||||||
performance = Ard-Fheidhmíocht
|
performance = Ard fheidhmíocht
|
||||||
performance-desc = Ard-fheidhmíocht agus ard-úsáid cumhachta.
|
performance-desc = Ard fheidhmíocht agus úsáid cumhachta.
|
||||||
max-charge = Méadaigh saolré do cheallraí trí uasmhuirear 80% a shocrú
|
max-charge = Méadaigh saolré do cheallraí trí uasluach muirir 80% a shocrú
|
||||||
seconds = s
|
seconds = s
|
||||||
minutes = nóim
|
minutes = n
|
||||||
hours = u
|
hours = u
|
||||||
until-empty = go dtí go mbeidh sé folamh
|
until-empty = go dtí go mbeidh sé folamh
|
||||||
power-settings = Socruithe Cumhachta & Ceallraí...
|
power-settings = Socruithe cumhachta & ceallraí...
|
||||||
dgpu-running = Tá an GPU ar leith gníomhach agus féadfaidh sé saol ceallraí a laghdú
|
dgpu-running = Tá an GPU ar leith gníomhach agus féadfaidh sé saol ceallraí a laghdú
|
||||||
dgpu-applications = Aipeanna ag úsáid {$gpu_name} GPU ar leith
|
dgpu-applications = Aipeanna ag úsáid { $gpu_name } GPU ar leith
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
battery = Akkumulátor
|
battery = Akkumulátor
|
||||||
battery-desc = Csökkentett energiafogyasztás és teljesítmény.
|
battery-desc = Csökkentett energiafogyasztás és teljesítmény
|
||||||
balanced = Kiegyensúlyozott
|
balanced = Kiegyensúlyozott
|
||||||
balanced-desc = Normál teljesítmény és akkumulátorhasználat.
|
balanced-desc = Normál teljesítmény és akkumulátorhasználat
|
||||||
performance = Nagy teljesítmény
|
performance = Nagy teljesítmény
|
||||||
performance-desc = Nagy teljesítmény és energiafogyasztás.
|
performance-desc = Nagy teljesítmény és energiafogyasztás
|
||||||
max-charge = Az akkumulátor élettartamának növelése érdekében állítsa a maximális töltési szintet 80%-ra
|
max-charge = Az akkumulátor élettartamának növelése érdekében állítsa a maximális töltési szintet 80%-ra
|
||||||
seconds = másodperc
|
seconds = másodperc
|
||||||
minutes = perc
|
minutes = perc
|
||||||
hours = óra
|
hours = óra
|
||||||
until-empty = a lemerülésig
|
until-empty = a lemerülésig
|
||||||
power-settings = Energia- és akkumulátorbeállítások...
|
power-settings = Energia- és akkumulátorbeállítások…
|
||||||
dgpu-running = A dedikált GPU aktív, ami csökkentheti az akkumulátor élettartamát
|
dgpu-running = A dedikált GPU aktív, ami csökkentheti az akkumulátor élettartamát
|
||||||
dgpu-applications = A {$gpu_name} dedikált GPU-t használó alkalmazások
|
dgpu-applications = A(z) { $gpu_name } dedikált GPU-t használó alkalmazások
|
||||||
|
|
|
||||||
0
cosmic-applet-battery/i18n/ka/cosmic_applet_battery.ftl
Normal file
0
cosmic-applet-battery/i18n/ka/cosmic_applet_battery.ftl
Normal file
0
cosmic-applet-battery/i18n/kab/cosmic_applet_battery.ftl
Normal file
0
cosmic-applet-battery/i18n/kab/cosmic_applet_battery.ftl
Normal file
14
cosmic-applet-battery/i18n/kk/cosmic_applet_battery.ftl
Normal file
14
cosmic-applet-battery/i18n/kk/cosmic_applet_battery.ftl
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
battery = Батарея
|
||||||
|
battery-desc = Азайтылған қуат тұтынуы және өнімділігі.
|
||||||
|
balanced = Теңгерілген
|
||||||
|
balanced-desc = Стандартты өнімділік және батареяны тұтыну.
|
||||||
|
performance = Жоғары өнімділік
|
||||||
|
performance-desc = Жоғары өнімділік және қуатты тұтыну.
|
||||||
|
max-charge = Максималды заряд мәнін 80% етіп орнату арқылы батареяңыздың қызмет ету мерзімін ұзартыңыз
|
||||||
|
seconds = с
|
||||||
|
minutes = м
|
||||||
|
hours = сағ
|
||||||
|
until-empty = таусылғанша
|
||||||
|
power-settings = Қуат және батарея баптаулары...
|
||||||
|
dgpu-running = Дискретті GPU белсенді және батареяның жұмыс уақытын азайтуы мүмкін
|
||||||
|
dgpu-applications = { $gpu_name } дискретті видеокартасын пайдаланатын қолданбалар
|
||||||
0
cosmic-applet-battery/i18n/kmr/cosmic_applet_battery.ftl
Normal file
0
cosmic-applet-battery/i18n/kmr/cosmic_applet_battery.ftl
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
power-settings = 전원 & 배터리 설정...
|
||||||
|
hours = 시간
|
||||||
|
until-empty = 남음
|
||||||
|
battery-desc = 감소된 성능과 전력 사용량.
|
||||||
|
max-charge = 배터리 최대 충전값을 80%로 설정하여 배터리 수명을 연장합니다
|
||||||
|
balanced = 균형
|
||||||
|
battery = 배터리
|
||||||
|
seconds = 초
|
||||||
|
dgpu-running = 외장 GPU가 활성화되어 배터리 사용 시간이 단축될 수 있습니다
|
||||||
|
performance = 고성능
|
||||||
|
performance-desc = 높은 성능과 전력 사용량.
|
||||||
|
minutes = 분
|
||||||
|
balanced-desc = 표준적인 성능과 배터리 사용량.
|
||||||
|
dgpu-applications = { $gpu_name } 외장 GPU를 사용하는 앱
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
power-settings = Energijos ir Baterijos nustatymai...
|
||||||
|
hours = val
|
||||||
|
until-empty = kol bus iškrauta
|
||||||
|
battery-desc = Sumažintas energijos vartojimas ir našumas.
|
||||||
|
max-charge = Padidinti baterijo gyvavimo trukmę nustatydami 80% pakrovimo ribą
|
||||||
|
balanced = Subalansuotas
|
||||||
|
battery = Baterija
|
||||||
|
seconds = sek
|
||||||
|
dgpu-running = Dedikuotas GPU yra aktyvus ir gali sumažinti baterijos gyvavimo trukmę
|
||||||
|
performance = Didelis Našumas
|
||||||
|
performance-desc = Didelis našumas ir energijos vartojimas.
|
||||||
|
minutes = min
|
||||||
|
balanced-desc = Įprastas našumas ir baterijos naudojimas.
|
||||||
|
dgpu-applications = Aplikacijos naudojančios { $gpu_name } dedikuotą GPU
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
battery = Batterijbesparing
|
battery = Batterij
|
||||||
battery-desc = Batterijbesparing met verlaagde prestaties.
|
battery-desc = Verminderd energieverbruik en prestaties.
|
||||||
balanced = Gebalanceerd
|
balanced = Gebalanceerd
|
||||||
balanced-desc = Normale prestaties en batterijverbruik.
|
balanced-desc = Normale prestaties en batterijverbruik.
|
||||||
performance = Verhoogde prestaties
|
performance = Verhoogde prestaties
|
||||||
|
|
@ -9,6 +9,6 @@ seconds = s
|
||||||
minutes = m
|
minutes = m
|
||||||
hours = u
|
hours = u
|
||||||
until-empty = tot leeg
|
until-empty = tot leeg
|
||||||
power-settings = Energie- en batterijbeheer...
|
power-settings = Energie- en batterijbeheer…
|
||||||
dgpu-running = De discrete GPU is actief en kan de batterijduur verkorten
|
dgpu-running = De discrete GPU is actief en kan de batterijduur verkorten
|
||||||
dgpu-applications = Toepassingen die de {$gpu_name} discrete GPU gebruiken
|
dgpu-applications = Toepassingen die de { $gpu_name } discrete GPU gebruiken
|
||||||
|
|
|
||||||
0
cosmic-applet-battery/i18n/pa/cosmic_applet_battery.ftl
Normal file
0
cosmic-applet-battery/i18n/pa/cosmic_applet_battery.ftl
Normal file
|
|
@ -1,14 +1,14 @@
|
||||||
battery = Bateria
|
battery = Bateria
|
||||||
battery-desc = Uso reduzido de energia e desempenho.
|
battery-desc = Uso reduzido de energia e desempenho limitado.
|
||||||
balanced = Equilibrado
|
balanced = Balanceado
|
||||||
balanced-desc = Desempenho padrão e uso de bateria.
|
balanced-desc = Desempenho padrão e uso de bateria moderado.
|
||||||
performance = Alto Desempenho
|
performance = Alto Desempenho
|
||||||
performance-desc = Alto desempenho e uso de energia.
|
performance-desc = Máximo desempenho e alto uso de energia.
|
||||||
max-charge = Aumente a vida útil da sua bateria definindo um valor máximo de carga de 80%
|
max-charge = Aumente a vida útil da sua bateria definindo um valor máximo de carga de 80%
|
||||||
seconds = s
|
seconds = s
|
||||||
minutes = m
|
minutes = m
|
||||||
hours = h
|
hours = h
|
||||||
until-empty = até vazio
|
until-empty = até esvaziar
|
||||||
power-settings = Configurações de Energia e Bateria...
|
power-settings = Configurações de energia e bateria...
|
||||||
dgpu-running = GPU discreta está ativa e pode reduzir a vida útil da bateria
|
dgpu-running = GPU discreta está ativa e pode reduzir a vida útil da bateria
|
||||||
dgpu-applications = Aplicativos usando GPU discreta {$gpu_name}
|
dgpu-applications = Aplicativos usando GPU discreta { $gpu_name }
|
||||||
|
|
|
||||||
0
cosmic-applet-battery/i18n/ti/cosmic_applet_battery.ftl
Normal file
0
cosmic-applet-battery/i18n/ti/cosmic_applet_battery.ftl
Normal file
|
|
@ -3,12 +3,12 @@ battery-desc = Зменшене енергоспоживання та проду
|
||||||
balanced = Збалансований
|
balanced = Збалансований
|
||||||
balanced-desc = Стандартна продуктивність та енергоспоживання.
|
balanced-desc = Стандартна продуктивність та енергоспоживання.
|
||||||
performance = Висока продуктивність
|
performance = Висока продуктивність
|
||||||
performance-desc = Висока продуктивність та енергоспоживання.
|
performance-desc = Висока продуктивність і енергоспоживання.
|
||||||
max-charge = Подовжити термін служби акумулятора, обмеживши максимальний заряд до 80%
|
max-charge = Подовжте термін служби акумулятора, обмеживши максимальне наснаження до 80%
|
||||||
seconds = сек
|
seconds = с
|
||||||
minutes = хв
|
minutes = хв
|
||||||
hours = год
|
hours = год
|
||||||
until-empty = доки не розрядиться
|
until-empty = доки не виснажиться
|
||||||
power-settings = Налаштування живлення та акумулятора...
|
power-settings = Налаштування живлення та акумулятора...
|
||||||
dgpu-running = Активна дискретна відеокарта, це може скоротити час роботи акумулятора
|
dgpu-running = Дискретна відеокарта активна, що може скоротити час роботи від акумулятора
|
||||||
dgpu-applications = Застосунки використовують дискретну відеокарту { $gpu_name }
|
dgpu-applications = Застосунки використовують дискретну відеокарту { $gpu_name }
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
battery = 省电
|
battery = 电池
|
||||||
battery-desc = 降低功耗和性能。
|
battery-desc = 降低功耗和性能。
|
||||||
balanced = 平衡
|
balanced = 平衡
|
||||||
balanced-desc = 标准性能和电池使用。
|
balanced-desc = 标准性能和电池使用。
|
||||||
performance = 高性能
|
performance = 高性能
|
||||||
performance-desc = 高性能和功耗。
|
performance-desc = 高性能和功耗。
|
||||||
max-charge = 最多充电到 80% 以增加电池寿命
|
max-charge = 最多充电到 80% 以增加电池寿命
|
||||||
seconds = s
|
seconds = 秒
|
||||||
minutes = m
|
minutes = 分钟
|
||||||
hours = h
|
hours = 小时
|
||||||
until-empty = 直到电池耗尽
|
until-empty = 直到电池耗尽
|
||||||
power-settings = 电源和电池设置...
|
power-settings = 电源和电池设置...
|
||||||
dgpu-running = 独立显卡正在运行,可能会降低电池寿命
|
dgpu-running = 独立显卡正在运行,可能会降低电池寿命
|
||||||
|
|
|
||||||
|
|
@ -29,15 +29,12 @@ use cosmic::{
|
||||||
surface, theme,
|
surface, theme,
|
||||||
widget::{divider, horizontal_space, icon, scrollable, slider, text, vertical_space},
|
widget::{divider, horizontal_space, icon, scrollable, slider, text, vertical_space},
|
||||||
};
|
};
|
||||||
use cosmic_settings_subscriptions::{
|
use cosmic_settings_daemon_subscription as settings_daemon;
|
||||||
settings_daemon,
|
use cosmic_settings_upower_subscription::{
|
||||||
upower::{
|
device::{DeviceDbusEvent, device_subscription},
|
||||||
device::{DeviceDbusEvent, device_subscription},
|
kbdbacklight::{KeyboardBacklightRequest, KeyboardBacklightUpdate, kbd_backlight_subscription},
|
||||||
kbdbacklight::{
|
|
||||||
KeyboardBacklightRequest, KeyboardBacklightUpdate, kbd_backlight_subscription,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use cosmic_time::{Instant, Timeline, anim, chain, id};
|
use cosmic_time::{Instant, Timeline, anim, chain, id};
|
||||||
|
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
@ -136,10 +133,16 @@ impl CosmicBatteryApplet {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn screen_brightness_percent(&self) -> Option<f64> {
|
fn screen_brightness_percent(&self) -> Option<f64> {
|
||||||
Some(
|
let raw = self.screen_brightness? as i64;
|
||||||
(self.screen_brightness? as f64 / self.max_screen_brightness?.max(1) as f64)
|
let max = self.max_screen_brightness?.max(1) as i64;
|
||||||
.clamp(0.01, 1.0),
|
if max <= 20 {
|
||||||
)
|
// Coarse panels (<=20 brightness levels)
|
||||||
|
let rung = (raw.saturating_add(1)).min(20);
|
||||||
|
Some((5 * rung) as f64 / 100.0)
|
||||||
|
} else {
|
||||||
|
let p = ((raw * 100 + max / 2) / max).clamp(1, 100) as f64;
|
||||||
|
Some(p / 100.0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_display(&mut self) {
|
fn update_display(&mut self) {
|
||||||
|
|
@ -242,8 +245,21 @@ impl cosmic::Application for CosmicBatteryApplet {
|
||||||
return cosmic::task::message(Message::SetKbdBrightnessDebounced);
|
return cosmic::task::message(Message::SetKbdBrightnessDebounced);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Matching brightness calculation logic from cosmic-osd and cosmic-settings-daemon
|
||||||
Message::SetScreenBrightness(brightness) => {
|
Message::SetScreenBrightness(brightness) => {
|
||||||
self.screen_brightness = Some(brightness);
|
let snapped = if let Some(max) = self.max_screen_brightness {
|
||||||
|
if max > 0 && max <= 20 {
|
||||||
|
// Coarse: map raw→k by round, then back to raw setpoint round(k*max/20)
|
||||||
|
let k = ((brightness as i64 * 20 + (max as i64) / 2) / (max as i64))
|
||||||
|
.clamp(0, 20);
|
||||||
|
(((k * (max as i64)) + 10) / 20) as i32
|
||||||
|
} else {
|
||||||
|
brightness
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
brightness
|
||||||
|
};
|
||||||
|
self.screen_brightness = Some(snapped);
|
||||||
if !self.dragging_screen_brightness {
|
if !self.dragging_screen_brightness {
|
||||||
self.dragging_screen_brightness = true;
|
self.dragging_screen_brightness = true;
|
||||||
self.update_display();
|
self.update_display();
|
||||||
|
|
@ -484,7 +500,7 @@ impl cosmic::Application for CosmicBatteryApplet {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Element<'_, Message> {
|
fn view(&self) -> Element<'_, Message> {
|
||||||
let btn = self
|
let btn: Element<'_, Message> = self
|
||||||
.core
|
.core
|
||||||
.applet
|
.applet
|
||||||
.icon_button(&self.icon_name)
|
.icon_button(&self.icon_name)
|
||||||
|
|
@ -508,17 +524,24 @@ impl cosmic::Application for CosmicBatteryApplet {
|
||||||
shadow: Shadow::default(),
|
shadow: Shadow::default(),
|
||||||
icon_color: Some(Color::TRANSPARENT),
|
icon_color: Some(Color::TRANSPARENT),
|
||||||
}
|
}
|
||||||
})))
|
})));
|
||||||
.into();
|
let (dot_align_x, dot_align_y) = match self.core.applet.anchor {
|
||||||
|
PanelAnchor::Left => (Alignment::Start, Alignment::Center),
|
||||||
|
PanelAnchor::Right => (Alignment::End, Alignment::Center),
|
||||||
|
PanelAnchor::Top => (Alignment::Center, Alignment::Start),
|
||||||
|
PanelAnchor::Bottom => (Alignment::Center, Alignment::End),
|
||||||
|
};
|
||||||
|
|
||||||
match self.core.applet.anchor {
|
cosmic::iced::widget::stack![
|
||||||
PanelAnchor::Left | PanelAnchor::Right => Column::with_children([btn, dot])
|
btn,
|
||||||
.align_x(Alignment::Center)
|
container(dot)
|
||||||
.into(),
|
.width(Length::Fill)
|
||||||
PanelAnchor::Top | PanelAnchor::Bottom => Row::with_children([btn, dot])
|
.height(Length::Fill)
|
||||||
.align_y(Alignment::Center)
|
.align_y(dot_align_y)
|
||||||
.into(),
|
.align_x(dot_align_x)
|
||||||
}
|
.padding(2.0)
|
||||||
|
]
|
||||||
|
.into()
|
||||||
};
|
};
|
||||||
|
|
||||||
self.core.applet.autosize_window(content).into()
|
self.core.applet.autosize_window(content).into()
|
||||||
|
|
@ -656,7 +679,7 @@ impl cosmic::Application for CosmicBatteryApplet {
|
||||||
.size(24)
|
.size(24)
|
||||||
.symbolic(true),
|
.symbolic(true),
|
||||||
slider(
|
slider(
|
||||||
1..=max_screen_brightness,
|
0..=max_screen_brightness,
|
||||||
screen_brightness,
|
screen_brightness,
|
||||||
Message::SetScreenBrightness
|
Message::SetScreenBrightness
|
||||||
)
|
)
|
||||||
|
|
@ -790,7 +813,7 @@ impl cosmic::Application for CosmicBatteryApplet {
|
||||||
if gpu.toggled
|
if gpu.toggled
|
||||||
&& !self.core.applet.suggested_bounds.as_ref().is_some_and(|c| {
|
&& !self.core.applet.suggested_bounds.as_ref().is_some_and(|c| {
|
||||||
let suggested_size = self.core.applet.suggested_size(true);
|
let suggested_size = self.core.applet.suggested_size(true);
|
||||||
let padding = self.core.applet.suggested_padding(true);
|
let padding = self.core.applet.suggested_padding(true).1;
|
||||||
let w = suggested_size.0 + 2 * padding;
|
let w = suggested_size.0 + 2 * padding;
|
||||||
let h = suggested_size.1 + 2 * padding;
|
let h = suggested_size.1 + 2 * padding;
|
||||||
// if we have a configure for width and height, we're in a overflow popup
|
// if we have a configure for width and height, we're in a overflow popup
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "cosmic-applet-bluetooth"
|
name = "cosmic-applet-bluetooth"
|
||||||
version = "0.1.0"
|
version = "1.0.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "GPL-3.0-only"
|
license = "GPL-3.0-only"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,5 +12,6 @@ Icon=com.system76.CosmicAppletBluetooth-symbolic
|
||||||
StartupNotify=true
|
StartupNotify=true
|
||||||
NoDisplay=true
|
NoDisplay=true
|
||||||
X-CosmicApplet=true
|
X-CosmicApplet=true
|
||||||
|
X-CosmicShrinkable=true
|
||||||
X-CosmicHoverPopup=Auto
|
X-CosmicHoverPopup=Auto
|
||||||
X-OverflowPriority=10
|
X-OverflowPriority=10
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ other-devices = أجهزة بلوتوث أخرى
|
||||||
settings = إعدادات البلوتوث...
|
settings = إعدادات البلوتوث...
|
||||||
connected = متصل
|
connected = متصل
|
||||||
confirm-pin = يرجى تأكيد أن رمز PIN التالي يطابق المعروض على { $deviceName }
|
confirm-pin = يرجى تأكيد أن رمز PIN التالي يطابق المعروض على { $deviceName }
|
||||||
confirm = تأكيد
|
confirm = أكِّد
|
||||||
cancel = إلغاء
|
cancel = ألغِ
|
||||||
unsuccessful = فشل الاقتران
|
unsuccessful = فشل الاقتران
|
||||||
check-device = تأكد من أن { $deviceName } قيد التشغيل، وفي النطاق، وجاهز للاقتران.
|
check-device = تأكد من أن { $deviceName } قيد التشغيل، وفي النطاق، وجاهز للاقتران.
|
||||||
try-again = حاول مرة أخرى
|
try-again = حاول مجددًا
|
||||||
discoverable = قابل للاكتشاف
|
discoverable = قابل للاكتشاف
|
||||||
pairable = قابل للاقتران
|
pairable = قابل للاقتران
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@ bluetooth = Bluetooth
|
||||||
other-devices = Autres périphériques Bluetooth
|
other-devices = Autres périphériques Bluetooth
|
||||||
settings = Paramètres Bluetooth...
|
settings = Paramètres Bluetooth...
|
||||||
connected = Connecté
|
connected = Connecté
|
||||||
confirm-pin = Veuillez confirmer que le PIN suivant correspond à celui affiché sur {$deviceName}
|
confirm-pin = Veuillez confirmer que le PIN suivant correspond à celui affiché sur { $deviceName }
|
||||||
confirm = Confirmer
|
confirm = Confirmer
|
||||||
cancel = Annuler
|
cancel = Annuler
|
||||||
unsuccessful = L'appairage a échoué
|
unsuccessful = L'appairage a échoué
|
||||||
check-device = Vérifiez que {$deviceName} est allumé, à proximité, et prêt à s'appairer.
|
check-device = Vérifiez que { $deviceName } est allumé, à proximité, et prêt à s'appairer.
|
||||||
try-again = Essayez à nouveau
|
try-again = Essayez à nouveau
|
||||||
discoverable = Visible
|
discoverable = Visible
|
||||||
pairable = Appairable
|
pairable = Appairable
|
||||||
|
|
@ -2,11 +2,11 @@ bluetooth = Bluetooth
|
||||||
other-devices = Gléasanna Bluetooth eile
|
other-devices = Gléasanna Bluetooth eile
|
||||||
settings = Socruithe Bluetooth...
|
settings = Socruithe Bluetooth...
|
||||||
connected = Ceangailte
|
connected = Ceangailte
|
||||||
confirm-pin = Deimhnigh le do thoil go bhfuil an PIN seo a leanas ag teacht leis an gceann ar taispeáint ar {$deviceName}
|
confirm-pin = Deimhnigh le do thoil go bhfuil an PIN seo a leanas ag teacht leis an gceann ar taispeáint ar { $deviceName }
|
||||||
confirm = Deimhnigh
|
confirm = Deimhnigh
|
||||||
cancel = Cealaigh
|
cancel = Cealaigh
|
||||||
unsuccessful = Níor éirigh leis an bpéireáil
|
unsuccessful = Níor éirigh leis an bpéireáil
|
||||||
check-device = Cinntigh go bhfuil {$deviceName} ar siúl, laistigh den raon, agus réidh le péireáil.
|
check-device = Cinntigh go bhfuil { $deviceName } ar siúl, laistigh den raon, agus réidh le péireáil.
|
||||||
try-again = Bain triail eile as
|
try-again = Bain triail arís
|
||||||
discoverable = Infheicthe
|
discoverable = Infheicthe
|
||||||
pairable = Péireálach
|
pairable = Péireálach
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
bluetooth = Bluetooth
|
bluetooth = Bluetooth
|
||||||
other-devices = Egyéb Bluetooth-eszközök
|
other-devices = Egyéb Bluetooth-eszközök
|
||||||
settings = Bluetooth beállítások...
|
settings = Bluetooth-beállítások…
|
||||||
connected = Csatlakoztatva
|
connected = Csatlakozva
|
||||||
confirm-pin = Ellenőrizd, hogy a következő PIN-kód megegyezik-e a(z) {$deviceName} eszközön megjelenő PIN-kóddal
|
confirm-pin = Ellenőrizd, hogy a következő PIN-kód megegyezik-e a(z) { $deviceName } eszközön megjelenő PIN-kóddal
|
||||||
confirm = Megerősítés
|
confirm = Megerősítés
|
||||||
cancel = Mégse
|
cancel = Mégse
|
||||||
unsuccessful = A párosítás sikertelen
|
unsuccessful = Nem sikerült a párosítás
|
||||||
check-device = Győződj meg arról, hogy a(z) {$deviceName} be van kapcsolva, hatótávolságon belül van, és készen áll a párosításra.
|
check-device = Győződj meg arról, hogy a(z) { $deviceName } be van kapcsolva, hatótávolságon belül van, és készen áll a párosításra.
|
||||||
try-again = Próbáld újra
|
try-again = Próbáld újra
|
||||||
discoverable = Felfedezhető
|
discoverable = Felfedezhető
|
||||||
pairable = Párosítható
|
pairable = Párosítható
|
||||||
|
|
|
||||||
12
cosmic-applet-bluetooth/i18n/kk/cosmic_applet_bluetooth.ftl
Normal file
12
cosmic-applet-bluetooth/i18n/kk/cosmic_applet_bluetooth.ftl
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
cancel = Бас тарту
|
||||||
|
connected = Қосылды
|
||||||
|
confirm = Растау
|
||||||
|
bluetooth = Bluetooth
|
||||||
|
other-devices = Басқа Bluetooth құрылғылары
|
||||||
|
settings = Bluetooth баптаулары...
|
||||||
|
confirm-pin = Келесі PIN коды { $deviceName } құрылғысында көрсетілген кодқа сәйкес келетінін растаңыз
|
||||||
|
unsuccessful = Жұптастыру сәтсіз аяқталды
|
||||||
|
check-device = { $deviceName } қосулы екенін, ауқым ішінде екенін және жұптастыруға дайын екенін тексеріңіз.
|
||||||
|
try-again = Қайтадан көру
|
||||||
|
discoverable = Көрінетін
|
||||||
|
pairable = Жұптастыруға болады
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
bluetooth = 블루투스
|
bluetooth = 블루투스
|
||||||
other-devices = Other Bluetooth Devices
|
other-devices = 기타 블루투스 장치
|
||||||
settings = 블루투스 설정...
|
settings = 블루투스 설정...
|
||||||
connected = 연결됨
|
connected = 연결됨
|
||||||
confirm-pin = {$deviceName}에 표시되는 PIN과 화면에 표시되는 PIN이 일치하는지 확인하십시오
|
confirm-pin = 다음 PIN이 { $deviceName }에 표시된 것과 일치하는지 확인해 주세요
|
||||||
confirm = 확인
|
confirm = 확인
|
||||||
cancel = 취소
|
cancel = 취소
|
||||||
unsuccessful = 페어링 실패
|
unsuccessful = 페어링 실패
|
||||||
check-device = {$deviceName}(이)가 켜저 있는지 확인하십시오. 만약 범위에 있다면 페어링 준비를 하십시오.
|
check-device = { $deviceName }(이)가 켜져 있고, 범위 내에 있으며, 페어링 준비가 되어있는지 확인하세요.
|
||||||
try-again = 다시 시도
|
try-again = 다시 시도
|
||||||
discoverable = 찾을 수 있음
|
discoverable = 검색 가능
|
||||||
pairable = 페어링 가능
|
pairable = 페어링 가능
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue