Commit 64f6c06f authored by Eisha Chen-yen-su's avatar Eisha Chen-yen-su

MediaViewer: Implement the headerbar timer

This implements the timer that will hide the headerbar after some
time of inactivity.

See https://gitlab.gnome.org/World/fractal/issues/265
parent b9142691
...@@ -57,19 +57,36 @@ impl App { ...@@ -57,19 +57,36 @@ impl App {
pub fn connect_media_viewer_box(&self) { pub fn connect_media_viewer_box(&self) {
let ui = self.ui.clone(); let ui = self.ui.clone();
let hovered: Arc<Mutex<bool>> = Arc::new(Mutex::new(false)); let header_hovered: Arc<Mutex<bool>> = Arc::new(Mutex::new(false));
let nav_hovered: Arc<Mutex<bool>> = Arc::new(Mutex::new(false));
let headerbar_revealer = ui.builder
.get_object::<gtk::Revealer>("headerbar_revealer")
.expect("Can't find headerbar_revealer in ui file.");
headerbar_revealer.connect_enter_notify_event(clone!(header_hovered => move |_, _| {
*(header_hovered.lock().unwrap()) = true;
Inhibit(false)
}));
headerbar_revealer.connect_leave_notify_event(clone!(header_hovered => move |_, _| {
*(header_hovered.lock().unwrap()) = false;
Inhibit(false)
}));
let previous_media_button = ui.builder let previous_media_button = ui.builder
.get_object::<gtk::Button>("previous_media_button") .get_object::<gtk::Button>("previous_media_button")
.expect("Cant find previous_media_button in ui file."); .expect("Cant find previous_media_button in ui file.");
previous_media_button.connect_enter_notify_event(clone!(hovered => move |_, _| { previous_media_button.connect_enter_notify_event(clone!(nav_hovered => move |_, _| {
*(hovered.lock().unwrap()) = true; *(nav_hovered.lock().unwrap()) = true;
Inhibit(false) Inhibit(false)
})); }));
previous_media_button.connect_leave_notify_event(clone!(hovered => move |_, _| { previous_media_button.connect_leave_notify_event(clone!(nav_hovered => move |_, _| {
*(hovered.lock().unwrap()) = false; *(nav_hovered.lock().unwrap()) = false;
Inhibit(false) Inhibit(false)
})); }));
...@@ -78,13 +95,13 @@ impl App { ...@@ -78,13 +95,13 @@ impl App {
.get_object::<gtk::Button>("next_media_button") .get_object::<gtk::Button>("next_media_button")
.expect("Cant find next_media_button in ui file."); .expect("Cant find next_media_button in ui file.");
next_media_button.connect_enter_notify_event(clone!(hovered => move |_, _| { next_media_button.connect_enter_notify_event(clone!(nav_hovered => move |_, _| {
*(hovered.lock().unwrap()) = true; *(nav_hovered.lock().unwrap()) = true;
Inhibit(false) Inhibit(false)
})); }));
next_media_button.connect_leave_notify_event(clone!(hovered => move |_, _| { next_media_button.connect_leave_notify_event(clone!(nav_hovered => move |_, _| {
*(hovered.lock().unwrap()) = false; *(nav_hovered.lock().unwrap()) = false;
Inhibit(false) Inhibit(false)
})); }));
...@@ -128,8 +145,15 @@ impl App { ...@@ -128,8 +145,15 @@ impl App {
.expect("Cant find next_media_revealer in ui file."); .expect("Cant find next_media_revealer in ui file.");
next_media_revealer.set_reveal_child(true); next_media_revealer.set_reveal_child(true);
let sid = gtk::timeout_add(1000, clone!(ui, hovered, source_id => move || { let sid = gtk::timeout_add(1000, clone!(ui, header_hovered, nav_hovered, source_id => move || {
if !*hovered.lock().unwrap() { if !*header_hovered.lock().unwrap() {
let headerbar_revealer = ui.builder
.get_object::<gtk::Revealer>("headerbar_revealer")
.expect("Can't find headerbar_revealer in ui file.");
headerbar_revealer.set_reveal_child(false);
}
if !*nav_hovered.lock().unwrap() {
let previous_media_revealer = ui.builder let previous_media_revealer = ui.builder
.get_object::<gtk::Revealer>("previous_media_revealer") .get_object::<gtk::Revealer>("previous_media_revealer")
.expect("Cant find previous_media_revealer in ui file."); .expect("Cant find previous_media_revealer in ui file.");
......
...@@ -222,6 +222,10 @@ impl AppOp { ...@@ -222,6 +222,10 @@ impl AppOp {
let headerbar_revealer = self.ui.builder let headerbar_revealer = self.ui.builder
.get_object::<gtk::Revealer>("headerbar_revealer") .get_object::<gtk::Revealer>("headerbar_revealer")
.expect("Can't find headerbar_revealer in ui file."); .expect("Can't find headerbar_revealer in ui file.");
// gdk::EventMask::ENTER_NOTIFY_MASK = 4096
headerbar_revealer.add_events(4096);
// gdk::EventMask::LEAVE_NOTIFY_MASK = 8192
headerbar_revealer.add_events(8192);
stack_header.remove(&media_viewer_headerbar_box); stack_header.remove(&media_viewer_headerbar_box);
headerbar_revealer.add(&media_viewer_headerbar_box); headerbar_revealer.add(&media_viewer_headerbar_box);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment