Add cosmic-applet-osk
This commit is contained in:
parent
0bfc3da2cb
commit
f2ef09d4a0
13 changed files with 160 additions and 13 deletions
12
cosmic-applet-osk/Cargo.toml
Normal file
12
cosmic-applet-osk/Cargo.toml
Normal file
|
|
@ -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
|
||||
13
cosmic-applet-osk/data/com.system76.CosmicAppletOsk.desktop
Normal file
13
cosmic-applet-osk/data/com.system76.CosmicAppletOsk.desktop
Normal file
|
|
@ -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
|
||||
72
cosmic-applet-osk/src/lib.rs
Normal file
72
cosmic-applet-osk/src/lib.rs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// 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<Msg>) {
|
||||
(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<iced::theme::Style> {
|
||||
Some(cosmic::applet::style())
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Msg) -> app::Task<Msg> {
|
||||
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::<Button>(())
|
||||
}
|
||||
13
cosmic-applet-osk/src/main.rs
Normal file
13
cosmic-applet-osk/src/main.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
fn main() -> cosmic::iced::Result {
|
||||
tracing_subscriber::fmt::init();
|
||||
let _ = tracing_log::LogTracer::init();
|
||||
|
||||
tracing::info!("Starting OSK applet with version {VERSION}");
|
||||
|
||||
cosmic_applet_osk::run()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue