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(MV): remove headerbar in fullscreen and reveal fabs on single click #913

Merged
merged 4 commits into from
Jun 15, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 24 additions & 2 deletions data/ui/views/media_viewer.ui
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
</object>
</child>
<property name="content">

<object class="GtkOverlay">
<property name="hexpand">1</property>
<property name="vexpand">1</property>
Expand Down Expand Up @@ -115,6 +114,30 @@
</property>
</object>
</child>
<child type="overlay">
<object class="GtkRevealer" id="toggle_fs_revealer">
<property name="overflow">visible</property>
<property name="transition_type">crossfade</property>
<property name="reveal-child">0</property>
<property name="visible">0</property>
<property name="valign">start</property>
<property name="halign">end</property>
<property name="margin-end">18</property>
<property name="margin-top">18</property>
<property name="child">
<object class="GtkButton">
<property name="icon-name">view-restore-symbolic</property>
<property name="tooltip-text" translatable="yes">Toggle Fullscreen</property>
<signal name="clicked" handler="toggle_fullscreen" swapped="no" />
<style>
<class name="osd" />
<class name="media-viewer-fab" />
<class name="circular" />
</style>
</object>
</property>
</object>
</child>
<child type="overlay">
<object class="GtkRevealer" id="zoom_buttons_revealer">
<property name="overflow">visible</property>
Expand Down Expand Up @@ -164,7 +187,6 @@
</object>
</property>
</object>

</property>
</object>
</property>
Expand Down
41 changes: 29 additions & 12 deletions src/Views/MediaViewer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,14 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
if (value) {
app.main_window.fullscreen ();
fullscreen_btn.icon_name = "view-restore-symbolic";
_fullscreen = true;
} else {
app.main_window.unfullscreen ();
fullscreen_btn.icon_name = "view-fullscreen-symbolic";
_fullscreen = false;
}

_fullscreen =
toggle_fs_revealer.visible = value;
headerbar.visible = !value;
}
get { return app.main_window.fullscreened; }
}
Expand All @@ -320,6 +322,7 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
[GtkChild] unowned Gtk.Button fullscreen_btn;
[GtkChild] unowned Adw.HeaderBar headerbar;
[GtkChild] unowned Gtk.Button back_btn;
[GtkChild] unowned Gtk.Revealer toggle_fs_revealer;

[GtkChild] unowned Gtk.Revealer page_buttons_revealer;
[GtkChild] unowned Gtk.Button prev_btn;
Expand All @@ -336,6 +339,7 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
set {
headerbar.opacity =
page_buttons_revealer.opacity =
toggle_fs_revealer.opacity =
zoom_buttons_revealer.opacity = value;
}
}
Expand Down Expand Up @@ -461,7 +465,7 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
context_menu.set_parent (this);

setup_mouse_previous_click ();
setup_double_click ();
setup_mouse1_click ();
setup_mouse_secondary_click ();
setup_swipe_close ();
}
Expand Down Expand Up @@ -638,14 +642,21 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
old_width = null;
}

double on_motion_last_x = 0.0;
double on_motion_last_y = 0.0;
protected void on_motion (double x, double y) {
if (on_motion_last_x == x && on_motion_last_y == y) return;
on_motion_last_x = x;
on_motion_last_y = y;

on_reveal_media_buttons ();
}

uint revealer_timeout = 0;
protected void on_reveal_media_buttons () {
page_buttons_revealer.set_reveal_child (true);
zoom_buttons_revealer.set_reveal_child (true);
toggle_fs_revealer.set_reveal_child (true);

if (revealer_timeout > 0) GLib.Source.remove (revealer_timeout);
revealer_timeout = Timeout.add (5 * 1000, on_hide_media_buttons, Priority.LOW);
Expand All @@ -654,6 +665,7 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
protected bool on_hide_media_buttons () {
page_buttons_revealer.set_reveal_child (false);
zoom_buttons_revealer.set_reveal_child (false);
toggle_fs_revealer.set_reveal_child (false);
revealer_timeout = 0;

return GLib.Source.REMOVE;
Expand Down Expand Up @@ -760,11 +772,11 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
add_controller (gesture);
}

private void setup_double_click () {
private void setup_mouse1_click () {
var gesture = new Gtk.GestureClick () {
button = 1
};
gesture.pressed.connect (on_double_click);
gesture.pressed.connect (on_mouse1_click);
add_controller (gesture);
}

Expand All @@ -786,13 +798,18 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
clear ();
}

private void on_double_click (int n_press, double x, double y) {
if (n_press != 2) return;

Item? page = safe_get ((int) carousel.position);
if (page == null) return;

page.on_double_click ();
private void on_mouse1_click (int n_press, double x, double y) {
switch (n_press) {
case 1:
on_reveal_media_buttons ();
break;
case 2:
Item? page = safe_get ((int) carousel.position);
if (page == null) break;

page.on_double_click ();
break;
}
}

private void reset_media_viewer () {
Expand Down