From 221d4f68bad57c610d44f643e1bd7dc7d927ae18 Mon Sep 17 00:00:00 2001 From: "Rene D. Obermueller" Date: Mon, 26 Jan 2026 23:20:01 +0100 Subject: [PATCH] feat: expose title and app_id via config and command line Closes: #397 --- README.md | 9 +++++++++ cli/src/command_line.rs | 8 ++++++++ src/configuration.rs | 27 +++++++++++++++++++++++++++ src/main.rs | 26 +++++++++++++++++++------- 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 23529b2..722f301 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,11 @@ text-move-length = 50.0 # This may be more useful to set via the command line. # Note, this is ignored with explicit resize. input-scale = 2.0 +# experimental feature (NEXTRELEASE): set window title +title = "Satty" +# experimental feature (NEXTRELEASE): set app_id, note this has to match D-Bus well-known name format, otherwise GTK does not accept it. +app-id = "org.satty.satty" + # Tool selection keyboard shortcuts (since 0.20.0) [keybinds] @@ -287,6 +292,10 @@ Options: Experimental feature (0.20.1): The length to move the text when using the arrow keys. defaults to 50.0 --input-scale Experimental feature (0.20.1): Scale the default window size to fit different displays. Note that this is ignored with explicit resize + --title + Experimental feature (NEXTRELEASE): Set window title + --app-id <APP_ID> + Experimental feature (NEXTRELEASE): Set toplevel app_id. Note that this applies gtk format expectations --right-click-copy Right click to copy. Preferably use the `action_on_right_click` option instead --action-on-enter <ACTION_ON_ENTER> diff --git a/cli/src/command_line.rs b/cli/src/command_line.rs index c16f9a5..6a83731 100644 --- a/cli/src/command_line.rs +++ b/cli/src/command_line.rs @@ -143,6 +143,14 @@ pub struct CommandLine { #[arg(long)] pub input_scale: Option<f32>, + /// Experimental feature (NEXTRELEASE): Set window title + #[arg(long)] + pub title: Option<String>, + + /// Experimental feature (NEXTRELEASE): Set toplevel app_id. Note that this has to match D-Bus well known name format, otherwise GTK does not accept it. + #[arg(long)] + pub app_id: Option<String>, + // --- deprecated options --- /// Right click to copy. /// Preferably use the `action_on_right_click` option instead. diff --git a/src/configuration.rs b/src/configuration.rs index 0a793f8..5f5dbba 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -66,6 +66,8 @@ pub struct Configuration { pan_step_size: f32, text_move_length: f32, input_scale: f32, + title: Option<String>, + app_id: Option<String>, } pub struct Keybinds { @@ -343,6 +345,12 @@ impl Configuration { if let Some(v) = general.input_scale { self.input_scale = v; } + if let Some(v) = general.title { + self.title = Some(v); + } + if let Some(v) = general.app_id { + self.app_id = Some(v); + } // --- deprecated options --- if let Some(v) = general.right_click_copy { @@ -464,6 +472,12 @@ impl Configuration { if let Some(v) = command_line.input_scale { self.input_scale = v; } + if let Some(v) = command_line.title { + self.title = Some(v); + } + if let Some(v) = command_line.app_id { + self.app_id = Some(v); + } // --- deprecated options --- if command_line.right_click_copy @@ -595,9 +609,18 @@ impl Configuration { pub fn text_move_length(&self) -> f32 { self.text_move_length } + pub fn input_scale(&self) -> f32 { self.input_scale } + + pub fn title(&self) -> Option<&String> { + self.title.as_ref() + } + + pub fn app_id(&self) -> Option<&String> { + self.app_id.as_ref() + } } impl Default for Configuration { @@ -633,6 +656,8 @@ impl Default for Configuration { pan_step_size: 50., text_move_length: 50.0, input_scale: 1.0, + title: None, + app_id: None, } } } @@ -714,6 +739,8 @@ struct ConfigurationFileGeneral { pan_step_size: Option<f32>, text_move_length: Option<f32>, input_scale: Option<f32>, + title: Option<String>, + app_id: Option<String>, // --- deprecated options --- right_click_copy: Option<bool>, diff --git a/src/main.rs b/src/main.rs index 1b40fee..6380412 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,13 @@ +use configuration::{Configuration, APP_CONFIG}; +use gdk_pixbuf::gio::{Application, ApplicationFlags}; +use gdk_pixbuf::{Pixbuf, PixbufLoader}; +use gtk::prelude::*; use std::io::Read; +use std::ops::Deref; use std::sync::LazyLock; use std::{fs, ptr}; use std::{io, time::Duration}; -use configuration::{Configuration, APP_CONFIG}; -use gdk_pixbuf::gio::ApplicationFlags; -use gdk_pixbuf::{Pixbuf, PixbufLoader}; -use gtk::prelude::*; - use relm4::gtk::gdk::Rectangle; use relm4::{ @@ -211,6 +211,10 @@ impl Component for App { set_decorated: !APP_CONFIG.read().no_window_decoration(), set_default_size: (500, 500), add_css_class: "root", + set_title: match APP_CONFIG.read().title() { + Some(s) => Some(s.as_ref()), + None => None + }, connect_show[sender] => move |_| { generate_profile_output!("gui show event"); @@ -283,7 +287,6 @@ impl Component for App { sender: ComponentSender<Self>, ) -> ComponentParts<Self> { Self::apply_style(); - let image_dimensions = (image.width(), image.height()); // SketchBoard @@ -423,7 +426,16 @@ fn run_satty() -> Result<()> { generate_profile_output!("image loaded, starting gui"); // start GUI let app = relm4::main_application(); - app.set_application_id(Some("com.gabm.satty")); + let app_id = match config.app_id() { + Some(app_id) if Application::id_is_valid(app_id) => Some(app_id.deref()), + o => { + if let Some(app_id) = o { + eprintln!("Invalid app id: {}, using fallback", app_id); + } + Some("com.gabm.satty") + } + }; + app.set_application_id(app_id); // set flag to allow to run multiple instances app.set_flags(ApplicationFlags::NON_UNIQUE); // create relm app and run