Skip to content

Commit

Permalink
BottomBar and PlayerPage: GTK4 preparations (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Jul 9, 2023
1 parent 99f4876 commit 00ca561
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 108 deletions.
90 changes: 32 additions & 58 deletions src/Widgets/Player/BottomBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,83 +18,71 @@
* Artem Anufrij <artem.anufrij@live.de>
*/

public class Audience.Widgets.BottomBar : Gtk.Revealer {
public PlaylistPopover playlist_popover { get; private set; }
public Videos.SeekBar time_widget { get; private set; }

private SettingsPopover preferences_popover;
private Gtk.Button play_button;
private Gtk.MenuButton playlist_button;
private uint hiding_timer = 0;

private bool _hovered = false;
private bool hovered {
public class Audience.Widgets.BottomBar : Gtk.EventBox {
public bool should_stay_revealed {
get {
return _hovered;
}
set {
_hovered = value;
if (value) {
if (hiding_timer != 0) {
Source.remove (hiding_timer);
hiding_timer = 0;
}
} else {
reveal_control ();
}
var play_pause_action = Application.get_default ().lookup_action (Audience.App.ACTION_PLAY_PAUSE);
return hovered || playlist_popover.visible || settings_popover.visible ||
!play_pause_action.get_state ().get_boolean ();
}
}

public BottomBar () {
play_button = new Gtk.Button.from_icon_name ("media-playback-start-symbolic", Gtk.IconSize.BUTTON) {
private Videos.SeekBar seek_bar;
private PlaylistPopover playlist_popover;
private SettingsPopover settings_popover;
private bool hovered;

construct {
var play_button = new Gtk.Button.from_icon_name ("media-playback-start-symbolic", Gtk.IconSize.BUTTON) {
action_name = App.ACTION_PREFIX + App.ACTION_PLAY_PAUSE,
tooltip_text = _("Play")
};

playlist_popover = new PlaylistPopover ();

playlist_button = new Gtk.MenuButton () {
var playlist_button = new Gtk.MenuButton () {
image = new Gtk.Image.from_icon_name ("view-list-symbolic", Gtk.IconSize.SMALL_TOOLBAR),
popover = playlist_popover,
tooltip_text = _("Playlist")
};

preferences_popover = new SettingsPopover ();
settings_popover = new SettingsPopover ();

var preferences_button = new Gtk.MenuButton () {
var settings_button = new Gtk.MenuButton () {
image = new Gtk.Image.from_icon_name ("open-menu-symbolic", Gtk.IconSize.SMALL_TOOLBAR),
popover = preferences_popover,
popover = settings_popover,
tooltip_text = _("Settings")
};

time_widget = new Videos.SeekBar ();
seek_bar = new Videos.SeekBar ();

var main_actionbar = new Gtk.ActionBar ();
main_actionbar.pack_start (play_button);
main_actionbar.set_center_widget (time_widget);
main_actionbar.pack_end (preferences_button);
main_actionbar.set_center_widget (seek_bar);
main_actionbar.pack_end (settings_button);
main_actionbar.pack_end (playlist_button);

add (main_actionbar);

child = main_actionbar;
show_all ();

transition_type = Gtk.RevealerTransitionType.SLIDE_UP;

events |= Gdk.EventMask.POINTER_MOTION_MASK;
events |= Gdk.EventMask.LEAVE_NOTIFY_MASK;
events |= Gdk.EventMask.ENTER_NOTIFY_MASK;

playlist_popover.notify["visible"].connect (() => notify_property ("should-stay-revealed"));
settings_popover.notify["visible"].connect (() => notify_property ("should-stay-revealed"));

enter_notify_event.connect ((event) => {
if (event.window == get_window ()) {
hovered = true;
notify_property ("should-stay-revealed");
}
return false;
});

leave_notify_event.connect ((event) => {
if (event.window == get_window ()) {
if (event.window == get_window () && event.detail != INFERIOR) {
hovered = false;
notify_property ("should-stay-revealed");
}
return false;
});
Expand All @@ -104,35 +92,21 @@ public class Audience.Widgets.BottomBar : Gtk.Revealer {
if (new_state.get_boolean () == false) {
((Gtk.Image) play_button.image).icon_name = "media-playback-start-symbolic";
play_button.tooltip_text = _("Play");
reveal_child = true;
} else {
((Gtk.Image) play_button.image).icon_name = "media-playback-pause-symbolic";
play_button.tooltip_text = _("Pause");
reveal_control ();
}
notify_property ("should-stay-revealed");
}
});
}

public void reveal_control () {
if (child_revealed == false) {
set_reveal_child (true);
}
public void hide_popovers () {
playlist_popover.popdown ();

if (hiding_timer != 0) {
Source.remove (hiding_timer);
var popover = seek_bar.preview_popover;
if (popover != null) {
popover.schedule_hide ();
}

var play_pause_action = Application.get_default ().lookup_action (Audience.App.ACTION_PLAY_PAUSE);

hiding_timer = GLib.Timeout.add (2000, () => {
if (hovered || preferences_popover.visible || playlist_popover.visible || !play_pause_action.get_state ().get_boolean ()) {
hiding_timer = 0;
return false;
}
set_reveal_child (false);
hiding_timer = 0;
return false;
});
}
}
91 changes: 41 additions & 50 deletions src/Widgets/Player/PlayerPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ namespace Audience {
private Hdy.HeaderBar header_bar;
private Audience.Widgets.BottomBar bottom_bar;
private Gtk.Revealer unfullscreen_revealer;
private Gtk.Revealer bottom_bar_revealer;

private uint hiding_timer = 0;
private bool mouse_primary_down = false;

private bool _fullscreened = false;
Expand All @@ -46,10 +48,8 @@ namespace Audience {
header_bar.show ();
}

if (value && bottom_bar.child_revealed) {
unfullscreen_revealer.reveal_child = true;
} else if (!value && bottom_bar.child_revealed) {
unfullscreen_revealer.reveal_child = false;
if (bottom_bar_revealer.child_revealed) {
reveal_control ();
}
}
}
Expand All @@ -69,10 +69,6 @@ namespace Audience {
header_bar.pack_start (navigation_button);
header_bar.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);

bottom_bar = new Widgets.BottomBar () {
valign = END
};

var unfullscreen_button = new Gtk.Button.from_icon_name ("view-restore-symbolic", Gtk.IconSize.BUTTON) {
tooltip_text = _("Unfullscreen")
};
Expand All @@ -85,11 +81,19 @@ namespace Audience {
unfullscreen_revealer.add (unfullscreen_button);
unfullscreen_revealer.show_all ();

bottom_bar = new Widgets.BottomBar ();

bottom_bar_revealer = new Gtk.Revealer () {
transition_type = SLIDE_UP,
valign = END,
child = bottom_bar
};

var overlay = new Gtk.Overlay () {
child = playback_manager.gst_video_widget
};
overlay.add_overlay (unfullscreen_revealer);
overlay.add_overlay (bottom_bar);
overlay.add_overlay (bottom_bar_revealer);

var event_box = new Gtk.EventBox () {
child = overlay,
Expand Down Expand Up @@ -120,9 +124,9 @@ namespace Audience {
(int)event.x_root, (int)event.y_root, event.time);
}

Gtk.Allocation allocation;
get_allocation (out allocation);
return update_pointer_position (event.y, allocation.height);
reveal_control ();

return false;
});

event_box.button_press_event.connect (event => {
Expand All @@ -141,38 +145,11 @@ namespace Audience {
return false;
});

bottom_bar.notify["child-revealed"].connect (() => {
if (bottom_bar.child_revealed && fullscreened) {
unfullscreen_revealer.reveal_child = bottom_bar.child_revealed;
} else if (!bottom_bar.child_revealed) {
unfullscreen_revealer.reveal_child = bottom_bar.child_revealed;
}
});
bottom_bar.notify["should-stay-revealed"].connect (reveal_control);

unfullscreen_button.clicked.connect (() => {
((Gtk.Window) get_toplevel ()).unfullscreen ();
});

event_box.leave_notify_event.connect (event => {
Gtk.Allocation allocation;
get_allocation (out allocation);

if (event.x == event.window.get_width ()) {
return update_pointer_position (event.window.get_height (), allocation.height);
} else if (event.x == 0) {
return update_pointer_position (event.window.get_height (), allocation.height);
}

return update_pointer_position (event.y, allocation.height);
});

bottom_bar.notify["child-revealed"].connect (() => {
if (bottom_bar.child_revealed == true) {
((Audience.Window) App.get_instance ().active_window).show_mouse_cursor ();
} else {
((Audience.Window) App.get_instance ().active_window).hide_mouse_cursor ();
}
});
}

public void seek_jump_seconds (int seconds) {
Expand All @@ -182,24 +159,38 @@ namespace Audience {
new_position = 0;
}
playback_manager.seek (new_position);
bottom_bar.reveal_control ();
reveal_control ();
}

public void hide_popovers () {
bottom_bar.playlist_popover.popdown ();
bottom_bar.hide_popovers ();
}

var popover = bottom_bar.time_widget.preview_popover;
if (popover != null) {
popover.schedule_hide ();
private void reveal_control () {
if (hiding_timer != 0) {
Source.remove (hiding_timer);
hiding_timer = 0;
}

bottom_bar_revealer.reveal_child = true;
((Audience.Window) App.get_instance ().active_window).show_mouse_cursor ();
if (fullscreened) {
unfullscreen_revealer.reveal_child = true;
}
}

private bool update_pointer_position (double y, int window_height) {
App.get_instance ().active_window.get_window ().set_cursor (null);
if (bottom_bar.should_stay_revealed) {
return;
}

hiding_timer = Timeout.add (2000, () => {
hiding_timer = 0;

bottom_bar.reveal_control ();
unfullscreen_revealer.reveal_child = false;
bottom_bar_revealer.reveal_child = false;
((Audience.Window) App.get_instance ().active_window).hide_mouse_cursor ();

return false;
return Source.REMOVE;
});
}
}
}

0 comments on commit 00ca561

Please sign in to comment.