Skip to content

Commit

Permalink
Allow Appmenu custom positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
alimirjamali committed Sep 13, 2024
1 parent 1ee90aa commit 1d57f47
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 209 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ ENV/
*.swp

*.~undo-tree~
*.glade~
33 changes: 31 additions & 2 deletions qubes_menu/appmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
from .custom_widgets import SelfAwareMenu
from .vm_manager import VMManager
from .page_handler import MenuPage
from .constants import INITIAL_PAGE_FEATURE, SORT_RUNNING_FEATURE
from .constants import INITIAL_PAGE_FEATURE, SORT_RUNNING_FEATURE, \
POSITION_FEATURE

import gi
gi.require_version('Gtk', '3.0')
Expand All @@ -36,6 +37,10 @@
"search_page", "app_page", "favorites_page", "settings_page"
]

POSITION_LIST = [
"mouse", "left", "right", "center"
]

logger = logging.getLogger('qubes-appmenu')

def load_theme(widget: Gtk.Widget, light_theme_path: str,
Expand Down Expand Up @@ -190,6 +195,22 @@ def _do_power_button(_widget):
else:
subprocess.Popen('xfce4-session-logout', stdin=subprocess.DEVNULL)

def reposition(self):
"""
Helper function to reposition Appmenu based on 'menu_position' feature
"""
match self.appmenu_position:
case 'left':
self.main_window.move(0, 0)
case 'center':
self.main_window.move(int(
(self.main_window.get_screen().get_width() - \
self.main_window.get_size().width) / 2), 0)
case 'right':
self.main_window.move(
self.main_window.get_screen().get_width() - \
self.main_window.get_size().width, 0)

def do_activate(self, *args, **kwargs):
"""
Method called whenever this program is run; it executes actual setup
Expand All @@ -202,6 +223,7 @@ def do_activate(self, *args, **kwargs):
assert self.main_window
assert self.main_notebook
if not self.start_in_background:
self.reposition()
self.main_window.show_all()
self.initialize_state()
# set size if too big
Expand Down Expand Up @@ -231,6 +253,7 @@ def do_activate(self, *args, **kwargs):
if self.main_window.is_visible() and not self.keep_visible:
self.main_window.hide()
else:
self.reposition()
self.main_window.present()

def hide_menu(self):
Expand Down Expand Up @@ -330,7 +353,8 @@ def perform_setup(self):
self.load_settings()

# monitor for settings changes
for feature in [INITIAL_PAGE_FEATURE, SORT_RUNNING_FEATURE]:
for feature in [INITIAL_PAGE_FEATURE, SORT_RUNNING_FEATURE, \
POSITION_FEATURE]:
self.dispatcher.add_handler(
'domain-feature-set:' + feature,
self._update_settings)
Expand Down Expand Up @@ -375,6 +399,11 @@ def load_settings(self):
self.sort_running = \
bool(local_vm.features.get(SORT_RUNNING_FEATURE, False))

position = local_vm.features.get(POSITION_FEATURE, "mouse")
if position not in POSITION_LIST:
position = "mouse"
self.appmenu_position = position

for handler in self.handlers.values():
handler.set_sorting_order(self.sort_running)

Expand Down
1 change: 1 addition & 0 deletions qubes_menu/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

INITIAL_PAGE_FEATURE = 'menu-initial-page'
SORT_RUNNING_FEATURE = 'menu-sort-running'
POSITION_FEATURE = 'menu-position'

FAVORITES_FEATURE = 'menu-favorites'
DISPOSABLE_PREFIX = '@disp:'
Expand Down
59 changes: 57 additions & 2 deletions qubes_menu_settings/menu_settings.glade
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,61 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="spacing">3</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Default menu position: </property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Where to show Appmenu (useful for Hotkeys).</property>
<property name="xalign">0.5</property>
<property name="yalign">0.6000000238418579</property>
<property name="pixel-size">20</property>
<property name="icon-name">qubes-question</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">3</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="menu_position_combo">
<property name="name">menu_position_combo</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-left">10</property>
<property name="margin-start">10</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
Expand Down Expand Up @@ -128,7 +183,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">3</property>
</packing>
</child>
<child>
Expand Down Expand Up @@ -195,7 +250,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
<property name="position">4</property>
</packing>
</child>
</object>
Expand Down
204 changes: 0 additions & 204 deletions qubes_menu_settings/menu_settings.glade~

This file was deleted.

Loading

0 comments on commit 1d57f47

Please sign in to comment.