diff --git a/qubes_menu/appmenu.py b/qubes_menu/appmenu.py index 9b7f2e9..3ee603e 100644 --- a/qubes_menu/appmenu.py +++ b/qubes_menu/appmenu.py @@ -113,6 +113,7 @@ def __init__(self, qapp, dispatcher): self.highlight_tag: Optional[str] = None self.tasks = [] + self.appmenu_position: str = 'mouse' def _add_cli_options(self): self.add_main_option( @@ -199,6 +200,7 @@ def reposition(self): """ Helper function to reposition Appmenu based on 'menu_position' feature """ + assert self.main_window match self.appmenu_position: case 'top-left': self.main_window.move(0, 0) diff --git a/qubes_menu/tests/test_appmenu.py b/qubes_menu/tests/test_appmenu.py index 247fab1..766582e 100644 --- a/qubes_menu/tests/test_appmenu.py +++ b/qubes_menu/tests/test_appmenu.py @@ -28,6 +28,7 @@ def test_app_menu_conffeatures(): features={'menu-favorites': ''}) qapp._qubes['dom0'].features['menu-initial-page'] = 'favorites_page' qapp._qubes['dom0'].features['menu-sort-running'] = '1' + qapp._qubes['dom0'].features['menu-position'] = '' qapp.update_vm_calls() dispatcher = MockDispatcher(qapp) @@ -38,6 +39,7 @@ def test_app_menu_conffeatures(): # check that initial page is correct assert app_menu.initial_page == "favorites_page" assert app_menu.sort_running + assert app_menu.appmenu_position == "mouse" def test_app_menu_conffeatures_default(): @@ -48,7 +50,8 @@ def test_app_menu_conffeatures_default(): name="test-vm2", qapp=qapp, features={'menu-favorites': '', 'menu-initial-page': 'fake', - 'menu-sort-running': 'fake'}) + 'menu-sort-running': 'fake', + 'menu-position': 'fake'}) qapp.update_vm_calls() dispatcher = MockDispatcher(qapp) @@ -59,6 +62,7 @@ def test_app_menu_conffeatures_default(): # check that default configuration is correct assert app_menu.initial_page == "app_page" assert not app_menu.sort_running + assert app_menu.appmenu_position == "mouse" def test_appmenu_options(): @@ -68,6 +72,7 @@ def test_appmenu_options(): features={'menu-favorites': ''}) qapp._qubes['dom0'].features['menu-initial-page'] = 'app_page' qapp._qubes['dom0'].features['menu-sort-running'] = '1' + qapp._qubes['dom0'].features['menu-position'] = 'top-left' qapp.update_vm_calls() dispatcher = MockDispatcher(qapp) @@ -86,3 +91,44 @@ def test_appmenu_options(): assert app_menu.initial_page == "favorites_page" assert app_menu.keep_visible + assert app_menu.appmenu_position == "top-left" + +def test_appmenu_positioning(): + qapp = MockQubesComplete() + + qapp._qubes['test-vm2'] = MockQube(name="test-vm2", qapp=qapp, + features={'menu-favorites': ''}) + qapp._qubes['dom0'].features['menu-initial-page'] = 'app_page' + qapp._qubes['dom0'].features['menu-sort-running'] = '1' + qapp._qubes['dom0'].features['menu-position'] = '' + qapp.update_vm_calls() + + dispatcher = MockDispatcher(qapp) + app_menu = AppMenu(qapp, dispatcher) + + app_menu.perform_setup() + + # Note: Relying on gravity is to assert changes is useless here. + assert app_menu.main_window + app_menu.appmenu_position = "mouse" + app_menu.reposition() + app_menu.appmenu_position = "top-left" + app_menu.reposition() + assert app_menu.main_window.get_position() == (0, 0) + app_menu.appmenu_position = "top-right" + app_menu.reposition() + assert app_menu.main_window.get_position() == ( \ + app_menu.main_window.get_screen().get_width() - \ + app_menu.main_window.get_size().width, 0) + app_menu.appmenu_position = "bottom-left" + app_menu.reposition() + assert app_menu.main_window.get_position() == (0, \ + app_menu.main_window.get_screen().get_height() - \ + app_menu.main_window.get_size().height) + app_menu.appmenu_position = "bottom-right" + app_menu.reposition() + assert app_menu.main_window.get_position() == ( \ + app_menu.main_window.get_screen().get_width() - \ + app_menu.main_window.get_size().width, \ + app_menu.main_window.get_screen().get_height() - \ + app_menu.main_window.get_size().height) diff --git a/qubes_menu_settings/test_menu_settings.py b/qubes_menu_settings/test_menu_settings.py index e98e9c2..daf5bc0 100644 --- a/qubes_menu_settings/test_menu_settings.py +++ b/qubes_menu_settings/test_menu_settings.py @@ -27,6 +27,7 @@ def test_menu_settings_load(): qapp._qubes['dom0'].features['menu-initial-page'] = 'favorites_page' qapp._qubes['dom0'].features['menu-sort-running'] = '1' qapp._qubes['dom0'].features['menu-favorites'] = '' + qapp._qubes['dom0'].features['menu-position'] = '' qapp.update_vm_calls() @@ -35,6 +36,7 @@ def test_menu_settings_load(): app.perform_setup() assert app.initial_page_model.get_selected() == "favorites_page" + assert app.menu_position_model.get_selected() == "mouse" assert app.sort_running_check.get_active() @@ -43,6 +45,7 @@ def test_menu_settings_change(): qapp._qubes['dom0'].features['menu-initial-page'] = 'app_page' qapp._qubes['dom0'].features['menu-sort-running'] = '' qapp._qubes['dom0'].features['menu-favorites'] = '' + qapp._qubes['dom0'].features['menu-position'] = 'mouse' qapp.update_vm_calls() @@ -51,13 +54,16 @@ def test_menu_settings_change(): app.perform_setup() assert app.initial_page_model.get_selected() == "app_page" + assert app.menu_position_model.get_selected() == "mouse" assert not app.sort_running_check.get_active() app.starting_page_combo.set_active_id("Search") # the first option is search + app.menu_position_combo.set_active_id("Top Left") # the first option is Top Left app.sort_running_check.set_active(True) qapp.expected_calls[('dom0', 'admin.vm.feature.Set', 'menu-sort-running', b'1')] = b'0\0' qapp.expected_calls[('dom0', 'admin.vm.feature.Set', 'menu-initial-page', b'search_page')] = b'0\0' + qapp.expected_calls[('dom0', 'admin.vm.feature.Set', 'menu-position', b'top-left')] = b'0\0' app._save() @@ -67,6 +73,7 @@ def test_menu_settings_change2(): qapp._qubes['dom0'].features['menu-initial-page'] = 'app_page' qapp._qubes['dom0'].features['menu-sort-running'] = '' qapp._qubes['dom0'].features['menu-favorites'] = '' + qapp._qubes['dom0'].features['menu-position'] = 'mouse' qapp.update_vm_calls() diff --git a/rpm_spec/qubes-desktop-linux-menu.spec.in b/rpm_spec/qubes-desktop-linux-menu.spec.in index d5c3ddc..a5cbe15 100644 --- a/rpm_spec/qubes-desktop-linux-menu.spec.in +++ b/rpm_spec/qubes-desktop-linux-menu.spec.in @@ -133,6 +133,10 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || : /usr/share/icons/hicolor/scalable/apps/qappmenu-pause.svg /usr/share/icons/hicolor/scalable/apps/qappmenu-shutdown.svg /usr/share/icons/hicolor/scalable/apps/qappmenu-start.svg +/usr/share/icons/hicolor/scalable/apps/qappmenu-top-left.svg +/usr/share/icons/hicolor/scalable/apps/qappmenu-top-right.svg +/usr/share/icons/hicolor/scalable/apps/qappmenu-bottom-left.svg +/usr/share/icons/hicolor/scalable/apps/qappmenu-bottom-right.svg /usr/share/icons/hicolor/scalable/apps/appmenu-settings-program-icon.svg /usr/share/icons/hicolor/scalable/apps/settings-black.svg /usr/share/icons/hicolor/scalable/apps/settings-blue.svg