Replace appmenu with window-local menu

There's an initiave in GNOME to replace app menus with "in-window"
menus: https://gitlab.gnome.org/GNOME/Initiatives/issues/4

This commit brings Piper in line with this new approach.

Fixes #267.
This commit is contained in:
Jente Hidskes
2019-01-09 11:59:28 +01:00
committed by Peter Hutterer
parent 19755f1e91
commit 41cafa4b4d
4 changed files with 20 additions and 19 deletions

View File

@@ -18,7 +18,5 @@
<file preprocess="xml-stripblanks">ui/ResolutionsPage.ui</file>
<file preprocess="xml-stripblanks">ui/WelcomePerspective.ui</file>
<file preprocess="xml-stripblanks">ui/Window.ui</file>
<!-- Using this alias, GtkApplication will automatically pick it up for us. -->
<file alias="gtk/menus.ui" preprocess="xml-stripblanks">ui/Menus.ui</file>
</gresource>
</gresources>

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<menu id="app-menu">
<section>
<item>
<attribute name="action">app.about</attribute>
<attribute name="label" translatable="yes">_About</attribute>
</item>
<item>
<attribute name="action">app.quit</attribute>
<attribute name="label" translatable="yes">_Quit</attribute>
<attribute name="accel">&lt;Primary&gt;q</attribute>
</item>
</section>
</menu>
</interface>

View File

@@ -2,6 +2,12 @@
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<menu id="primary_menu">
<item>
<attribute name="action">app.about</attribute>
<attribute name="label" translatable="yes">_About Piper</attribute>
</item>
</menu>
<template class="Window" parent="GtkApplicationWindow">
<!-- This size is determined to be the best one with the current set of
device SVGs in libratbag. It is set to ensure that the jump in size

View File

@@ -36,6 +36,7 @@ class Window(Gtk.ApplicationWindow):
stack_titlebar = GtkTemplate.Child()
stack_perspectives = GtkTemplate.Child()
primary_menu = GtkTemplate.Child()
def __init__(self, ratbag, *args, **kwargs):
"""Instantiates a new Window.
@@ -128,6 +129,7 @@ class Window(Gtk.ApplicationWindow):
self.stack_titlebar.add_named(perspective.titlebar, perspective.name)
if perspective.can_go_back:
self._perspective_add_back_button(perspective, ratbag)
self._perspective_add_primary_menu(perspective)
def _present_welcome_perspective(self, devices):
# Present the welcome perspective for the user to select one of their
@@ -186,3 +188,15 @@ class Window(Gtk.ApplicationWindow):
perspective.titlebar.add(button_back)
# Place the button first in the titlebar.
perspective.titlebar.child_set_property(button_back, "position", 0)
def _perspective_add_primary_menu(self, perspective):
hamburger = Gtk.Image.new_from_icon_name("open-menu-symbolic",
Gtk.IconSize.BUTTON)
hamburger.set_visible(True)
button_primary_menu = Gtk.MenuButton.new()
button_primary_menu.add(hamburger)
button_primary_menu.set_visible(True)
button_primary_menu.set_menu_model(self.primary_menu)
perspective.titlebar.pack_end(button_primary_menu)
# Place the button last in the titlebar.
perspective.titlebar.child_set_property(button_primary_menu, "position", 0)