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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ output-filename = "/tmp/test-%Y-%m-%d_%H:%M:%S.png"
save-after-copy = false
# Hide toolbars by default
default-hide-toolbars = false
# Experimental: whether window focus shows/hides toolbars. This does not affect initial state of toolbars, see default-hide-toolbars.
focus-toggles-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"
# Disable notifications
Expand Down Expand Up @@ -166,6 +168,8 @@ Options:
Actions to perform when hitting the copy Button [possible values: save-to-clipboard, save-to-file, exit]
-d, --default-hide-toolbars
Hide toolbars by default
--focus-toggles-toolbars
Experimental: Whether to toggle toolbars based on focus. Doesn't affect initial state
--font-family <FONT_FAMILY>
Font family to use for text annotations
--font-style <FONT_STYLE>
Expand Down
4 changes: 4 additions & 0 deletions src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ pub struct CommandLine {
#[arg(short, long)]
pub default_hide_toolbars: bool,

/// Experimental: Whether to toggle toolbars based on focus. Doesn't affect initial state.
#[arg(long)]
pub focus_toggles_toolbars: bool,

/// Font family to use for text annotations
#[arg(long)]
pub font_family: Option<String>,
Expand Down
13 changes: 13 additions & 0 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub struct Configuration {
actions_on_right_click: Vec<Action>,
color_palette: ColorPalette,
default_hide_toolbars: bool,
focus_toggles_toolbars: bool,
font: FontConfiguration,
primary_highlighter: Highlighters,
disable_notifications: bool,
Expand Down Expand Up @@ -185,6 +186,9 @@ impl Configuration {
if let Some(v) = general.default_hide_toolbars {
self.default_hide_toolbars = v;
}
if let Some(v) = general.focus_toggles_toolbars {
self.focus_toggles_toolbars = v;
}
if let Some(v) = general.primary_highlighter {
self.primary_highlighter = v;
}
Expand Down Expand Up @@ -243,6 +247,9 @@ impl Configuration {
if command_line.default_hide_toolbars {
self.default_hide_toolbars = command_line.default_hide_toolbars;
}
if command_line.focus_toggles_toolbars {
self.focus_toggles_toolbars = command_line.focus_toggles_toolbars
}
if let Some(v) = command_line.initial_tool {
self.initial_tool = v.into();
}
Expand Down Expand Up @@ -360,6 +367,10 @@ impl Configuration {
self.default_hide_toolbars
}

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

pub fn primary_highlighter(&self) -> Highlighters {
self.primary_highlighter
}
Expand Down Expand Up @@ -402,6 +413,7 @@ impl Default for Configuration {
actions_on_right_click: vec![],
color_palette: ColorPalette::default(),
default_hide_toolbars: false,
focus_toggles_toolbars: false,
font: FontConfiguration::default(),
primary_highlighter: Highlighters::Block,
disable_notifications: false,
Expand Down Expand Up @@ -457,6 +469,7 @@ struct ConfigurationFileGeneral {
actions_on_escape: Option<Vec<Action>>,
actions_on_right_click: Option<Vec<Action>>,
default_hide_toolbars: Option<bool>,
focus_toggles_toolbars: Option<bool>,
primary_highlighter: Option<Highlighters>,
disable_notifications: Option<bool>,
no_window_decoration: Option<bool>,
Expand Down
23 changes: 23 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct App {
#[derive(Debug)]
enum AppInput {
Realized,
SetToolbarsDisplay(bool),
ToggleToolbarsDisplay,
}

Expand Down Expand Up @@ -231,6 +232,14 @@ impl Component for App {
fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>, root: &Self::Root) {
match message {
AppInput::Realized => self.resize_window_initial(root, sender),
AppInput::SetToolbarsDisplay(visible) => {
self.tools_toolbar
.sender()
.emit(ToolsToolbarInput::SetVisibility(visible));
self.style_toolbar
.sender()
.emit(StyleToolbarInput::SetVisibility(visible));
}
AppInput::ToggleToolbarsDisplay => {
self.tools_toolbar
.sender()
Expand Down Expand Up @@ -291,6 +300,20 @@ impl Component for App {

let widgets = view_output!();

if APP_CONFIG.read().focus_toggles_toolbars() {
let motion_controller = gtk::EventControllerMotion::builder().build();
let sender_clone = sender.clone();

motion_controller.connect_enter(move |_, _, _| {
sender.input(AppInput::SetToolbarsDisplay(true));
});
motion_controller.connect_leave(move |_| {
sender_clone.input(AppInput::SetToolbarsDisplay(false));
});

root.add_controller(motion_controller);
}

generate_profile_output!("app init end");

glib::idle_add_local_once(move || {
Expand Down
4 changes: 4 additions & 0 deletions src/ui/toolbars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub enum ToolbarEvent {

#[derive(Debug, Copy, Clone)]
pub enum ToolsToolbarInput {
SetVisibility(bool),
ToggleVisibility,
}

Expand All @@ -59,6 +60,7 @@ pub enum StyleToolbarInput {
ColorButtonSelected(ColorButtons),
ShowColorDialog,
ColorDialogFinished(Option<Color>),
SetVisibility(bool),
ToggleVisibility,
ShowAnnotationDialog,
AnnotationDialogFinished(Option<f32>),
Expand Down Expand Up @@ -245,6 +247,7 @@ impl SimpleComponent for ToolsToolbar {

fn update(&mut self, message: Self::Input, _sender: ComponentSender<Self>) {
match message {
ToolsToolbarInput::SetVisibility(visible) => self.visible = visible,
ToolsToolbarInput::ToggleVisibility => {
self.visible = !self.visible;
}
Expand Down Expand Up @@ -515,6 +518,7 @@ impl Component for StyleToolbar {
}
}

StyleToolbarInput::SetVisibility(visible) => self.visible = visible,
StyleToolbarInput::ToggleVisibility => {
self.visible = !self.visible;
}
Expand Down