Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 <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 <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>
Expand Down
8 changes: 8 additions & 0 deletions cli/src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 27 additions & 0 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
}
}
Expand Down Expand Up @@ -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>,
Expand Down
26 changes: 19 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -283,7 +287,6 @@ impl Component for App {
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
Self::apply_style();

let image_dimensions = (image.width(), image.height());

// SketchBoard
Expand Down Expand Up @@ -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
Expand Down