From f2ef09d4a0e34335fe4e9f567c1868c7b1f8fd59 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 15 Sep 2026 20:11:08 -0600 Subject: [PATCH] Add cosmic-applet-osk --- Cargo.lock | 45 ++++++++---- Cargo.toml | 2 + cosmic-applet-osk/Cargo.toml | 12 ++++ .../data/com.system76.CosmicAppletOsk.desktop | 13 ++++ cosmic-applet-osk/src/lib.rs | 72 +++++++++++++++++++ cosmic-applet-osk/src/main.rs | 13 ++++ cosmic-applets/Cargo.toml | 1 + cosmic-applets/build.rs | 6 ++ cosmic-applets/src/main.rs | 1 + data/com.system76.CosmicApplets.metainfo.xml | 2 + debian/links | 1 + i18n/en/desktop_entries.ftl | 3 + justfile | 2 +- 13 files changed, 160 insertions(+), 13 deletions(-) create mode 100644 cosmic-applet-osk/Cargo.toml create mode 100644 cosmic-applet-osk/data/com.system76.CosmicAppletOsk.desktop create mode 100644 cosmic-applet-osk/src/lib.rs create mode 100644 cosmic-applet-osk/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 03fe54d9..db8b5fab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -651,7 +651,7 @@ dependencies = [ [[package]] name = "build_helpers" version = "0.14.0" -source = "git+https://github.com/pop-os/libcosmic#a401af8b1c54a8abd393b8c5b7c8809402f83850" +source = "git+https://github.com/pop-os/libcosmic#87ab8179e1bd9880239c340855ae8862034bd0e8" dependencies = [ "cfg_aliases", ] @@ -1156,6 +1156,17 @@ dependencies = [ "zbus", ] +[[package]] +name = "cosmic-applet-osk" +version = "1.0.15" +dependencies = [ + "cosmic-osk-config", + "libcosmic", + "tracing", + "tracing-log", + "tracing-subscriber", +] + [[package]] name = "cosmic-applet-power" version = "1.0.15" @@ -1257,6 +1268,7 @@ dependencies = [ "cosmic-applet-minimize", "cosmic-applet-network", "cosmic-applet-notifications", + "cosmic-applet-osk", "cosmic-applet-power", "cosmic-applet-status-area", "cosmic-applet-tiling", @@ -1304,7 +1316,7 @@ dependencies = [ [[package]] name = "cosmic-config" version = "1.0.0" -source = "git+https://github.com/pop-os/libcosmic#a401af8b1c54a8abd393b8c5b7c8809402f83850" +source = "git+https://github.com/pop-os/libcosmic#87ab8179e1bd9880239c340855ae8862034bd0e8" dependencies = [ "atomicwrites", "cosmic-config-derive", @@ -1325,7 +1337,7 @@ dependencies = [ [[package]] name = "cosmic-config-derive" version = "1.0.0" -source = "git+https://github.com/pop-os/libcosmic#a401af8b1c54a8abd393b8c5b7c8809402f83850" +source = "git+https://github.com/pop-os/libcosmic#87ab8179e1bd9880239c340855ae8862034bd0e8" dependencies = [ "quote", "syn", @@ -1376,6 +1388,15 @@ dependencies = [ "zbus", ] +[[package]] +name = "cosmic-osk-config" +version = "0.1.0" +source = "git+https://github.com/pop-os/cosmic-osk#d7b66a24890d03e38dd8962d956bc802d4a41067" +dependencies = [ + "cosmic-config", + "serde", +] + [[package]] name = "cosmic-panel-button" version = "1.0.15" @@ -1902,7 +1923,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -2100,7 +2121,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -2911,7 +2932,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.14.0" -source = "git+https://github.com/pop-os/libcosmic#a401af8b1c54a8abd393b8c5b7c8809402f83850" +source = "git+https://github.com/pop-os/libcosmic#87ab8179e1bd9880239c340855ae8862034bd0e8" dependencies = [ "bitflags 2.13.0", "build_helpers", @@ -2947,7 +2968,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.14.0" -source = "git+https://github.com/pop-os/libcosmic#a401af8b1c54a8abd393b8c5b7c8809402f83850" +source = "git+https://github.com/pop-os/libcosmic#87ab8179e1bd9880239c340855ae8862034bd0e8" dependencies = [ "futures", "iced_core", @@ -3856,7 +3877,7 @@ version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a1886916523694cd6ea3d175f03a1e5010699a2a4cc13696d83d7bea1d80638" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -4441,7 +4462,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -5567,7 +5588,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.12.1", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -6148,7 +6169,7 @@ dependencies = [ "getrandom 0.4.3", "once_cell", "rustix 1.1.4", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -7155,7 +7176,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index ec720c7c..32a53854 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "cosmic-applet-minimize", "cosmic-applet-network", "cosmic-applet-notifications", + "cosmic-applet-osk", "cosmic-applet-power", "cosmic-applet-status-area", "cosmic-applet-tiling", @@ -27,6 +28,7 @@ resolver = "3" anyhow = "1.0.102" cctk = { git = "https://github.com/pop-os/cosmic-protocols", package = "cosmic-client-toolkit", rev = "a7d2d7a" } cosmic-applets-config = { path = "cosmic-applets-config" } +cosmic-osk-config = { git = "https://github.com/pop-os/cosmic-osk" } cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", default-features = false, features = [ "client", ], rev = "a7d2d7a" } diff --git a/cosmic-applet-osk/Cargo.toml b/cosmic-applet-osk/Cargo.toml new file mode 100644 index 00000000..3f007c58 --- /dev/null +++ b/cosmic-applet-osk/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "cosmic-applet-osk" +version = "1.0.15" +edition = "2024" +license = "GPL-3.0-only" + +[dependencies] +cosmic-osk-config.workspace = true +libcosmic.workspace = true +tracing.workspace = true +tracing-subscriber.workspace = true +tracing-log.workspace = true diff --git a/cosmic-applet-osk/data/com.system76.CosmicAppletOsk.desktop b/cosmic-applet-osk/data/com.system76.CosmicAppletOsk.desktop new file mode 100644 index 00000000..0624bdc9 --- /dev/null +++ b/cosmic-applet-osk/data/com.system76.CosmicAppletOsk.desktop @@ -0,0 +1,13 @@ +[Desktop Entry] +Name=On-screen Keyboard Button +Comment=Open the on-screen keyboard +Type=Application +Exec=cosmic-applet-osk +Terminal=false +Categories=COSMIC; +Keywords=COSMIC;Applet;OSK;Keyboard; +Icon=input-keyboard-symbolic +StartupNotify=true +NoDisplay=true +X-CosmicApplet=true +X-OverflowPriority=10 diff --git a/cosmic-applet-osk/src/lib.rs b/cosmic-applet-osk/src/lib.rs new file mode 100644 index 00000000..a1597757 --- /dev/null +++ b/cosmic-applet-osk/src/lib.rs @@ -0,0 +1,72 @@ +// Copyright 2023 System76 +// SPDX-License-Identifier: GPL-3.0-only + +use cosmic::{Task, app, cosmic_config::CosmicConfigEntry, iced}; +use cosmic_osk_config::Config; + +struct Button { + core: cosmic::app::Core, +} + +#[derive(Debug, Clone)] +enum Msg { + Press, +} + +impl cosmic::Application for Button { + type Message = Msg; + type Executor = cosmic::SingleThreadExecutor; + type Flags = (); + const APP_ID: &'static str = "com.system76.CosmicAppletOsk"; + + fn init(core: cosmic::app::Core, _: ()) -> (Self, app::Task) { + (Self { core }, Task::none()) + } + + fn core(&self) -> &cosmic::app::Core { + &self.core + } + + fn core_mut(&mut self) -> &mut cosmic::app::Core { + &mut self.core + } + + fn style(&self) -> Option { + Some(cosmic::applet::style()) + } + + fn update(&mut self, message: Msg) -> app::Task { + match message { + Msg::Press => match Config::handler() { + Ok(handler) => { + let mut config = match Config::get_entry(&handler) { + Ok(config) => config, + Err((errs, config)) => { + tracing::warn!("failed to parse OSK config: {:?}", errs); + config + } + }; + if let Err(err) = config.set_always_shown(&handler, !config.always_shown) { + tracing::error!("failed to set OSK always_shown config: {}", err); + } + } + Err(err) => { + tracing::error!("failed to create OSK config handler: {}", err); + } + }, + } + Task::none() + } + + fn view(&self) -> cosmic::Element<'_, Msg> { + self.core + .applet + .icon_button("input-keyboard-symbolic") + .on_press_down(Msg::Press) + .into() + } +} + +pub fn run() -> iced::Result { + cosmic::applet::run::