Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: draft freehand highlighter #77

Merged
merged 6 commits into from
Jun 20, 2024
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
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ apk add satty

You can download a prebuilt binary for x86-64 on the [Satty Releases](https://github.com/gabm/satty/releases) page.


## Usage

Start by providing a filename or a screenshot via stdin and annotate using the available tools. Save to clipboard or file when finished. Tools and Interface have been kept simple.
Expand All @@ -78,6 +77,9 @@ output-filename = "/tmp/test-%Y-%m-%d_%H:%M:%S.png"
save-after-copy = false
# Hide toolbars by default
default-hide-toolbars = false
# The primary highlighter to use, the other is accessible by holding CTRL at the start of a highlight [possible values: block, freehand]
primary-highlighter = "block"

# Font to use for text annotations
[font]
family = "Roboto"
Expand Down Expand Up @@ -122,6 +124,8 @@ Options:
After copying the screenshot, save it to a file as well
-d, --default-hide-toolbars
Hide toolbars by default
--primary-highlighter <PRIMARY_HIGHLIGHTER>
The primary highlighter to use, secondary is accessible with CTRL [possible values: block, freehand]
--font-family <FONT_FAMILY>
Font family to use for text annotations
--font-style <FONT_STYLE>
Expand All @@ -140,7 +144,6 @@ You can bind a key to the following command:
grim -g "$(slurp -o -r -c '#ff0000ff')" - | satty --filename - --fullscreen --output-filename ~/Pictures/Screenshots/satty-$(date '+%Y%m%d-%H:%M:%S').png
```


## Build from source

You first need to install the native dependencies of Satty (see below) and then run:
Expand Down
3 changes: 3 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ output-filename = "/tmp/test-%Y-%m-%d_%H:%M:%S.png"
save-after-copy = false
# Hide toolbars by default
default-hide-toolbars = false
# The primary highlighter to use, the other is accessible by holding CTRL at the start of a highlight [possible values: block, freehand]
primary-highlighter = "block"

# Font to use for text annotations
[font]
family = "Roboto"
Expand Down
11 changes: 11 additions & 0 deletions src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ pub struct CommandLine {
/// Font style to use for text annotations
#[arg(long)]
pub font_style: Option<String>,

/// The primary highlighter to use, secondary is accessible with CTRL.
#[arg(long)]
pub primary_highlighter: Option<Highlighters>,
}

#[derive(Debug, Clone, Copy, Default, ValueEnum)]
Expand All @@ -68,6 +72,13 @@ pub enum Tools {
Brush,
}

#[derive(Debug, Clone, Copy, Default, ValueEnum)]
pub enum Highlighters {
#[default]
Block,
Freehand,
}

impl std::fmt::Display for Tools {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use Tools::*;
Expand Down
19 changes: 18 additions & 1 deletion src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ use serde_derive::Deserialize;
use thiserror::Error;
use xdg::{BaseDirectories, BaseDirectoriesError};

use crate::{command_line::CommandLine, style::Color, tools::Tools};
use crate::{
command_line::CommandLine,
style::Color,
tools::{Highlighters, Tools},
};

pub static APP_CONFIG: SharedState<Configuration> = SharedState::new();

Expand Down Expand Up @@ -39,6 +43,7 @@ pub struct Configuration {
color_palette: ColorPalette,
default_hide_toolbars: bool,
font: FontConfiguration,
primary_highlighter: Highlighters,
}

#[derive(Default)]
Expand Down Expand Up @@ -170,6 +175,9 @@ impl Configuration {
if let Some(v) = general.default_hide_toolbars {
self.default_hide_toolbars = v;
}
if let Some(v) = general.primary_highlighter {
self.primary_highlighter = v;
}
}
fn merge(&mut self, file: Option<ConfigurationFile>, command_line: CommandLine) {
// input_filename is required and needs to be overwritten
Expand Down Expand Up @@ -219,6 +227,10 @@ impl Configuration {
if let Some(v) = command_line.font_style {
self.font.style = Some(v);
}

if let Some(v) = command_line.primary_highlighter {
self.primary_highlighter = v.into();
}
}

pub fn early_exit(&self) -> bool {
Expand Down Expand Up @@ -261,6 +273,9 @@ impl Configuration {
self.default_hide_toolbars
}

pub fn primary_highlighter(&self) -> Highlighters {
self.primary_highlighter
}
pub fn font(&self) -> &FontConfiguration {
&self.font
}
Expand All @@ -280,6 +295,7 @@ impl Default for Configuration {
color_palette: ColorPalette::default(),
default_hide_toolbars: false,
font: FontConfiguration::default(),
primary_highlighter: Highlighters::Block,
}
}
}
Expand Down Expand Up @@ -323,6 +339,7 @@ struct ConfiguationFileGeneral {
output_filename: Option<String>,
save_after_copy: Option<bool>,
default_hide_toolbars: Option<bool>,
primary_highlighter: Option<Highlighters>,
}

#[derive(Deserialize)]
Expand Down
11 changes: 11 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ impl Component for App {
glib::Propagation::Stop
},

connect_key_released[sketch_board_sender] => move |controller, key, code, modifier | {
if let Some(im_context) = controller.im_context() {
im_context.focus_in();
if !im_context.filter_keypress(controller.current_event().unwrap()) {
sketch_board_sender.emit(SketchBoardInput::new_key_release_event(KeyEventMsg::new(key, code, modifier)));
}
} else {
sketch_board_sender.emit(SketchBoardInput::new_key_release_event(KeyEventMsg::new(key, code, modifier)));
}
},

#[wrap(Some)]
set_im_context = &gtk::IMMulticontext {
connect_commit[sketch_board_sender] => move |_cx, txt| {
Expand Down
5 changes: 5 additions & 0 deletions src/sketch_board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub enum SketchBoardOutput {
pub enum InputEvent {
Mouse(MouseEventMsg),
Key(KeyEventMsg),
KeyRelease(KeyEventMsg),
Text(TextEventMsg),
}

Expand Down Expand Up @@ -105,6 +106,10 @@ impl SketchBoardInput {
SketchBoardInput::InputEvent(InputEvent::Key(event))
}

pub fn new_key_release_event(event: KeyEventMsg) -> SketchBoardInput {
SketchBoardInput::InputEvent(InputEvent::KeyRelease(event))
}

pub fn new_text_event(event: TextEventMsg) -> SketchBoardInput {
SketchBoardInput::InputEvent(InputEvent::Text(event))
}
Expand Down
9 changes: 5 additions & 4 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,12 @@ impl Size {
}
}

pub fn to_highlight_opacity(self) -> u8 {
pub fn to_highlight_width(self) -> f32 {
let size_factor = APP_CONFIG.read().annotation_size_factor();
match self {
Size::Small => 50,
Size::Medium => 100,
Size::Large => 150,
Size::Small => 15.0 * size_factor,
Size::Medium => 30.0 * size_factor,
Size::Large => 45.0 * size_factor,
}
}
}
Loading
Loading