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 4 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
# Whether to set block or line/pen as the default highlighter, other mode is accessible using CTRL.
default-block-highlight = true

# 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
--default-line-highlight
Change the default highlighter to the line/pen highlighter
gabm marked this conversation as resolved.
Show resolved Hide resolved
--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
# Whether to set block or line/pen as the default highlighter, other mode is accessible using CTRL.
default-block-highlight = true

# Font to use for text annotations
[font]
family = "Roboto"
Expand Down
4 changes: 4 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>,

/// Change the default highlighter to the line/pen highlighter.
#[arg(long)]
pub default_line_highlight: 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 @@ -39,6 +39,7 @@ pub struct Configuration {
color_palette: ColorPalette,
default_hide_toolbars: bool,
font: FontConfiguration,
default_block_highlight: bool,
}

#[derive(Default)]
Expand Down Expand Up @@ -170,6 +171,9 @@ impl Configuration {
if let Some(v) = general.default_hide_toolbars {
self.default_hide_toolbars = v;
}
if let Some(v) = general.default_block_highlight {
self.default_block_highlight = 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 +223,10 @@ impl Configuration {
if let Some(v) = command_line.font_style {
self.font.style = Some(v);
}

if command_line.default_line_highlight {
self.default_block_highlight = !command_line.default_line_highlight;
}
}

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

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

#[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
13 changes: 9 additions & 4 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,16 @@ 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,
}
}

pub fn default_block_highlight(self) -> bool {
APP_CONFIG.read().default_block_highlight()
}
}
Loading
Loading