Skip to content

Commit

Permalink
Implemented "click away to close"
Browse files Browse the repository at this point in the history
  • Loading branch information
AMNatty committed Feb 3, 2025
1 parent dd8a9bf commit a34cf6f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use std::time::Duration;

use gtk4::gdk::{Cursor, Display, Key};
use gtk4::glib::{timeout_add_local_once, Propagation};
use gtk4::{gio, Application, ApplicationWindow, CssProvider, Label};
use gtk4::{
gio, Application, ApplicationWindow, CssProvider, EventControllerMotion, GestureClick, Label,
PropagationPhase,
};
use gtk4::{prelude::*, EventControllerKey};
use gtk4_layer_shell::{KeyboardMode, LayerShell};
use serde::Deserialize;
Expand Down Expand Up @@ -271,6 +274,23 @@ fn app_main(config: &Arc<AppConfig>, app: &Application) {
});
}

let click_away_controller = GestureClick::new();
click_away_controller.set_propagation_phase(PropagationPhase::Target);
click_away_controller.set_button(gtk4::gdk::BUTTON_PRIMARY);
click_away_controller.connect_pressed(clone!(
#[weak]
window,
#[upgrade_or_panic]
move |_, n, _, _| {
if n != 1 {
return;
}

window.close();
}
));
window.add_controller(click_away_controller);

let key_controller = EventControllerKey::new();
key_controller.connect_key_pressed(clone!(
#[strong]
Expand Down

0 comments on commit a34cf6f

Please sign in to comment.