Merge pull request #791 from gpodder/gnome3-header-bar-csd

Gtk UI: Add support for GtkHeaderBar / GNOME3 CSDs
This commit is contained in:
Eric Le Lay 2020-05-14 21:39:35 +02:00 committed by GitHub
commit cbb5104185
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 3 deletions

View file

@ -218,6 +218,7 @@
<object class="GtkGrid" id="vbox42">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="hexpand">True</property>
<child>
<object class="GtkButton" id="btnUpdateFeeds">
<property name="label" translatable="yes">Check for new episodes</property>

View file

@ -80,6 +80,10 @@ class gPodderApplication(Gtk.Application):
action.connect('activate', self.on_check_for_updates_activate)
self.add_action(action)
action = Gio.SimpleAction.new('menu', None)
action.connect('activate', self.on_menu)
self.add_action(action)
def do_startup(self):
Gtk.Application.do_startup(self)
@ -102,7 +106,29 @@ class gPodderApplication(Gtk.Application):
self.menu_view_columns = builder.get_object('menuViewColumns')
self.set_menubar(menubar)
self.set_app_menu(builder.get_object('app-menu'))
# If $XDG_CURRENT_DESKTOP is set then it contains a colon-separated list of strings.
# https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
# See https://askubuntu.com/a/227669 for a list of values in different environments
xdg_current_desktops = os.environ.get('XDG_CURRENT_DESKTOP', '').split(':')
# See https://developer.gnome.org/gtk3/stable/gtk-running.html
# GTK_CSD=0 is used to disable client side decorations
csd_disabled = os.environ.get('GTK_CSD') == '0'
self.want_headerbar = ('GNOME' in xdg_current_desktops) and not gpodder.ui.osx and not csd_disabled
self.app_menu = builder.get_object('app-menu')
if self.want_headerbar:
# Use GtkHeaderBar for client-side decorations on recent GNOME 3 versions
self.header_bar_menu_button = Gtk.Button.new_from_icon_name('open-menu-symbolic', Gtk.IconSize.SMALL_TOOLBAR)
self.header_bar_menu_button.set_action_name('app.menu')
self.header_bar_refresh_button = Gtk.Button.new_from_icon_name('view-refresh-symbolic', Gtk.IconSize.SMALL_TOOLBAR)
self.header_bar_refresh_button.set_action_name('win.updateChannel')
self.menu_popover = Gtk.Popover.new_from_model(self.header_bar_menu_button, self.app_menu)
self.menu_popover.set_position(Gtk.PositionType.BOTTOM)
else:
self.set_app_menu(self.app_menu)
Gtk.Window.set_default_icon_name('gpodder')
@ -137,6 +163,9 @@ class gPodderApplication(Gtk.Application):
self.window.gPodder.present()
def on_menu(self, action, param):
self.menu_popover.popup()
def on_about(self, action, param):
dlg = Gtk.Dialog(_('About gPodder'), self.window.gPodder,
Gtk.DialogFlags.MODAL)

View file

@ -89,6 +89,18 @@ class gPodder(BuilderWidget, dbus.service.Object):
BuilderWidget.__init__(self, None, _builder_expose={'app': app})
def new(self):
if self.application.want_headerbar:
self.header_bar = Gtk.HeaderBar()
self.header_bar.pack_end(self.application.header_bar_menu_button)
self.header_bar.pack_start(self.application.header_bar_refresh_button)
self.header_bar.set_show_close_button(True)
self.header_bar.show_all()
# Tweaks to the UI since we moved the refresh button into the header bar
self.vboxChannelNavigator.set_row_spacing(0)
self.main_window.set_titlebar(self.header_bar)
gpodder.user_extensions.on_ui_object_available('gpodder-gtk', self)
self.toolbar.set_property('visible', self.config.show_toolbar)
@ -197,7 +209,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
util.run_in_background(self.user_apps_reader.read)
# Now, update the feed cache, when everything's in place
self.btnUpdateFeeds.show()
if not self.application.want_headerbar:
self.btnUpdateFeeds.show()
self.feed_cache_update_cancelled = False
self.update_podcast_list_model()
@ -2523,7 +2536,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
# Make sure that the buttons for updating feeds
# appear - this should happen after a feed update
self.hboxUpdateFeeds.hide()
self.btnUpdateFeeds.show()
if not self.application.want_headerbar:
self.btnUpdateFeeds.show()
self.update_action.set_enabled(True)
self.update_channel_action.set_enabled(True)