Commit 6999de57 authored by Daniel García Moreno's avatar Daniel García Moreno

Merge branch 'media-viewer-headerbar-fullscreen'

parents a305429a 03b3366d
Pipeline #17934 failed with stage
in 14 seconds
......@@ -29,6 +29,27 @@
<property name="index">-1</property>
</packing>
</child>
<child type="overlay">
<object class="GtkOverlay" id="headerbar_overlay">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">fill</property>
<property name="valign">start</property>
<child>
<object class="GtkRevealer" id="headerbar_revealer">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="index">-1</property>
</packing>
</child>
</object>
</child>
<child type="overlay">
<object class="GtkOverlay" id="previous_media_overlay">
<property name="visible">True</property>
......
......@@ -4,6 +4,8 @@ extern crate gdk;
use self::gtk::prelude::*;
use self::gdk::WindowExt;
use self::gdk::DisplayExt;
use self::gdk::SeatExt;
use glib;
use std::sync::{Arc, Mutex};
......@@ -37,11 +39,21 @@ impl App {
});
let op = self.op.clone();
let ui = self.ui.clone();
let full_screen_button = self.ui.builder
.get_object::<gtk::Button>("full_screen_button")
.expect("Cant find full_screen_button in ui file.");
full_screen_button.connect_clicked(move |_| {
op.lock().unwrap().enter_full_screen();
let main_window = ui.builder
.get_object::<gtk::Window>("main_window")
.expect("Cant find main_window in ui file.");
if let Some(win) = main_window.get_window() {
if !win.get_state().contains(gdk::WindowState::FULLSCREEN) {
op.lock().unwrap().enter_full_screen();
} else {
op.lock().unwrap().leave_full_screen()
}
}
});
let op = self.op.clone();
......@@ -55,19 +67,36 @@ impl App {
pub fn connect_media_viewer_box(&self) {
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
.get_object::<gtk::Button>("previous_media_button")
.expect("Cant find previous_media_button in ui file.");
previous_media_button.connect_enter_notify_event(clone!(hovered => move |_, _| {
*(hovered.lock().unwrap()) = true;
previous_media_button.connect_enter_notify_event(clone!(nav_hovered => move |_, _| {
*(nav_hovered.lock().unwrap()) = true;
Inhibit(false)
}));
previous_media_button.connect_leave_notify_event(clone!(hovered => move |_, _| {
*(hovered.lock().unwrap()) = false;
previous_media_button.connect_leave_notify_event(clone!(nav_hovered => move |_, _| {
*(nav_hovered.lock().unwrap()) = false;
Inhibit(false)
}));
......@@ -76,13 +105,13 @@ impl App {
.get_object::<gtk::Button>("next_media_button")
.expect("Cant find next_media_button in ui file.");
next_media_button.connect_enter_notify_event(clone!(hovered => move |_, _| {
*(hovered.lock().unwrap()) = true;
next_media_button.connect_enter_notify_event(clone!(nav_hovered => move |_, _| {
*(nav_hovered.lock().unwrap()) = true;
Inhibit(false)
}));
next_media_button.connect_leave_notify_event(clone!(hovered => move |_, _| {
*(hovered.lock().unwrap()) = false;
next_media_button.connect_leave_notify_event(clone!(nav_hovered => move |_, _| {
*(nav_hovered.lock().unwrap()) = false;
Inhibit(false)
}));
......@@ -100,6 +129,22 @@ impl App {
}
}
let main_window = ui.builder
.get_object::<gtk::Window>("main_window")
.expect("Cant find main_window in ui file.");
gdk::Display::get_default()
.and_then(|disp| disp.get_default_seat())
.and_then(|seat| seat.get_pointer())
.map(|ptr| {
let win = main_window.get_window()?;
let (_, _, y, _) = win.get_device_position(&ptr);
if y <= 6 && win.get_state().contains(gdk::WindowState::FULLSCREEN) {
headerbar_revealer.set_reveal_child(true);
}
Some(true)
});
let previous_media_revealer = ui.builder
.get_object::<gtk::Revealer>("previous_media_revealer")
.expect("Cant find previous_media_revealer in ui file.");
......@@ -110,8 +155,15 @@ impl App {
.expect("Cant find next_media_revealer in ui file.");
next_media_revealer.set_reveal_child(true);
let sid = gtk::timeout_add(1000, clone!(ui, hovered, source_id => move || {
if !*hovered.lock().unwrap() {
let sid = gtk::timeout_add(1000, clone!(ui, header_hovered, nav_hovered, source_id => move || {
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
.get_object::<gtk::Revealer>("previous_media_revealer")
.expect("Cant find previous_media_revealer in ui file.");
......
......@@ -213,6 +213,34 @@ impl AppOp {
.expect("Cant find main_window in ui file.");
main_window.fullscreen();
let stack_header = self.ui.builder
.get_object::<gtk::Stack>("headerbar_stack")
.expect("Can't find headerbar_stack in ui file.");
let media_viewer_headerbar_box = self.ui.builder
.get_object::<gtk::Box>("media_viewer_headerbar_box")
.expect("Can't find media_viewer_headerbar_box in ui file.");
let headerbar_revealer = self.ui.builder
.get_object::<gtk::Revealer>("headerbar_revealer")
.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);
let media_viewer_headerbar = self.ui.builder
.get_object::<gtk::HeaderBar>("media_viewer_headerbar")
.expect("Can't find media_viewer_headerbar in ui file.");
let media_viewer_back_button = self.ui.builder
.get_object::<gtk::Button>("media_viewer_back_button")
.expect("Can't find media_viewer_back_button in ui file.");
media_viewer_headerbar.remove(&media_viewer_back_button);
media_viewer_headerbar.set_show_close_button(false);
headerbar_revealer.add(&media_viewer_headerbar_box);
self.update_media_viewport();
}
......@@ -222,6 +250,34 @@ impl AppOp {
.expect("Cant find main_window in ui file.");
main_window.unfullscreen();
let stack_header = self.ui.builder
.get_object::<gtk::Stack>("headerbar_stack")
.expect("Can't find headerbar_stack in ui file.");
let media_viewer_headerbar_box = self.ui.builder
.get_object::<gtk::Box>("media_viewer_headerbar_box")
.expect("Can't find media_viewer_headerbar_box in ui file.");
let headerbar_revealer = self.ui.builder
.get_object::<gtk::Revealer>("headerbar_revealer")
.expect("Can't find headerbar_revealer in ui file.");
if let Some(ch) = headerbar_revealer.get_child() {
headerbar_revealer.remove(&ch);
}
let media_viewer_headerbar = self.ui.builder
.get_object::<gtk::HeaderBar>("media_viewer_headerbar")
.expect("Can't find media_viewer_headerbar in ui file.");
let media_viewer_back_button = self.ui.builder
.get_object::<gtk::Button>("media_viewer_back_button")
.expect("Can't find media_viewer_back_button in ui file.");
media_viewer_headerbar.pack_start(&media_viewer_back_button);
media_viewer_headerbar.set_child_position(&media_viewer_back_button, 0);
media_viewer_headerbar.set_show_close_button(true);
stack_header.add_named(&media_viewer_headerbar_box, "media-viewer");
stack_header.set_visible_child_name("media-viewer");
self.update_media_viewport();
}
......
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