Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# <img src="assets/satty.svg" height="42"> Satty: Modern Screenshot Annotation.
# <img src="assets/satty.svg" height="42"> Satty: Modern Screenshot Annotation.

Satty is a screenshot annotation tool inspired by [Swappy](https://github.com/jtheoof/swappy) and [Flameshot](https://flameshot.org/).

Expand Down Expand Up @@ -69,6 +69,8 @@ copy-command = "wl-copy"
annotation-size-factor = 2
# Filename to use for saving action. Omit to disable saving to file. Might contain format specifiers: https://docs.rs/chrono/latest/chrono/format/strftime/index.html
output-filename = "/tmp/test-%Y-%m-%d_%H:%M:%S.png"
# After copying the screenshot, save it to a file as well
save-after-copy = false

# custom colours for the colour palette
[color-palette]
Expand All @@ -83,7 +85,7 @@ custom= "#008000"
### Command Line

```sh
» satty --help
» satty --help
Modern Screenshot Annotation. A Screenshot Annotation Tool inspired by Swappy and Flameshot.

Usage: satty [OPTIONS] --filename <FILENAME>
Expand All @@ -105,6 +107,8 @@ Options:
Configure the command to be called on copy, for example `wl-copy`
--annotation-size-factor <ANNOTATION_SIZE_FACTOR>
Increase or decrease the size of the annotations
--save-after-copy
After copying the screenshot, save it to a file as well
-h, --help
Print help
-V, --version
Expand Down Expand Up @@ -135,7 +139,7 @@ PREFIX=/use/local make install
PREFIX=/use/local make uninstall
```

## Dependencies
## Dependencies

Satty is based on GTK-4 and Adwaita.

Expand All @@ -146,7 +150,7 @@ Satty is based on GTK-4 and Adwaita.

### Arch Linux & Gentoo

- pango
- pango
- glib2
- cairo
- libadwaita
Expand Down
2 changes: 2 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ copy-command = "wl-copy"
annotation-size-factor = 2
# Filename to use for saving action. Omit to disable saving to file. Might contain format specifiers: https://docs.rs/chrono/latest/chrono/format/strftime/index.html
output-filename = "/tmp/test-%Y-%m-%d_%H:%M:%S.png"
# After copying the screenshot, save it to a file as well
save-after-copy = false

# custom colours for the colour palette
[color-palette]
Expand Down
4 changes: 4 additions & 0 deletions src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ pub struct CommandLine {
/// Increase or decrease the size of the annotations
#[arg(long)]
pub annotation_size_factor: Option<f64>,

/// After copying the screenshot, save it to a file as well
#[arg(long)]
pub save_after_copy: bool,
}

#[derive(Debug, Clone, Copy, Default, ValueEnum)]
Expand Down
13 changes: 13 additions & 0 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct Configuration {
initial_tool: Tools,
copy_command: Option<String>,
annotation_size_factor: f64,
save_after_copy: bool,
color_palette: ColorPalette,
}

Expand Down Expand Up @@ -138,6 +139,9 @@ impl Configuration {
if let Some(v) = general.annotation_size_factor {
self.annotation_size_factor = v;
}
if let Some(v) = general.save_after_copy {
self.save_after_copy = v;
}
}
fn merge(&mut self, file: Option<ConfigurationFile>, command_line: CommandLine) {
// input_filename is required and needs to be overwritten
Expand Down Expand Up @@ -172,6 +176,9 @@ impl Configuration {
if let Some(v) = command_line.annotation_size_factor {
self.annotation_size_factor = v;
}
if command_line.save_after_copy {
self.save_after_copy = command_line.save_after_copy;
}
}

pub fn early_exit(&self) -> bool {
Expand Down Expand Up @@ -202,6 +209,10 @@ impl Configuration {
self.annotation_size_factor
}

pub fn save_after_copy(&self) -> bool {
self.save_after_copy
}

pub fn color_palette(&self) -> &ColorPalette {
&self.color_palette
}
Expand All @@ -217,6 +228,7 @@ impl Default for Configuration {
initial_tool: Tools::Pointer,
copy_command: None,
annotation_size_factor: 1.0f64,
save_after_copy: false,
color_palette: ColorPalette::default(),
}
}
Expand Down Expand Up @@ -251,6 +263,7 @@ struct ConfiguationFileGeneral {
copy_command: Option<String>,
annotation_size_factor: Option<f64>,
output_filename: Option<String>,
save_after_copy: Option<bool>,
}

#[derive(Deserialize)]
Expand Down
32 changes: 21 additions & 11 deletions src/sketch_board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ impl SketchBoard {
}

fn handle_save(&self, sender: ComponentSender<Self>) {
let texture = match self.renderer.render_to_texture(&self.active_tool) {
Ok(t) => t,
Err(e) => {
println!("Error while creating texture: {e}");
return;
}
};

self.handle_save_texture(sender, &texture);
}

fn handle_save_texture(&self, sender: ComponentSender<Self>, texture: &MemoryTexture) {
let output_filename = match APP_CONFIG.read().output_filename() {
None => {
println!("No Output filename specified!");
Expand All @@ -164,14 +176,6 @@ impl SketchBoard {
return;
}

let texture = match self.renderer.render_to_texture(&self.active_tool) {
Ok(t) => t,
Err(e) => {
println!("Error while creating texture: {e}");
return;
}
};

let data = texture.save_to_png_bytes();

let msg = match fs::write(&output_filename, data) {
Expand Down Expand Up @@ -230,9 +234,15 @@ impl SketchBoard {

match result {
Err(e) => println!("Error saving {e}"),
Ok(()) => sender.output_sender().emit(SketchBoardOutput::ShowToast(
"Copied to clipboard.".to_string(),
)),
Ok(()) => {
sender.output_sender().emit(SketchBoardOutput::ShowToast(
"Copied to clipboard.".to_string(),
));

if APP_CONFIG.read().save_after_copy() {
self.handle_save_texture(sender, &texture);
};
}
}
}

Expand Down