BarWidgets: First pass on contextual widget menu accessible from right-click.

Testing on volume widget for now.
This commit is contained in:
ItsLemmy
2025-11-17 20:35:45 -05:00
parent 1b114a0c5f
commit 3283aacf9b
11 changed files with 452 additions and 124 deletions
+3 -3
View File
@@ -95,7 +95,7 @@ Variants {
}
}
// TrayMenuWindow - separate window for tray context menus
// PopupMenuWindow - reusable popup window for both tray menus and context menus
// Disabled when bar is hidden or not configured for this screen
Loader {
active: {
@@ -108,12 +108,12 @@ Variants {
}
asynchronous: false
sourceComponent: TrayMenuWindow {
sourceComponent: PopupMenuWindow {
screen: modelData
}
onLoaded: {
Logger.d("AllScreens", "TrayMenuWindow created for", modelData?.name);
Logger.d("AllScreens", "PopupMenuWindow created for", modelData?.name);
}
}
}
+92
View File
@@ -0,0 +1,92 @@
import QtQuick
import Quickshell
import Quickshell.Wayland
import qs.Commons
import qs.Services.UI
// Generic full-screen popup window for menus and context menus
// This is a top-level PanelWindow (sibling to MainScreen, not nested inside it)
// Provides click-outside-to-close functionality for any popup content
// Loads TrayMenu by default but can show context menus via showContextMenu()
PanelWindow {
id: root
required property ShellScreen screen
property string windowType: "popupmenu" // Used for namespace and registration
// Content item to display (set by the popup that uses this window)
property var contentItem: null
// Expose the trayMenu Loader directly (for backward compatibility)
readonly property alias trayMenuLoader: trayMenuLoader
anchors.top: true
anchors.left: true
anchors.right: true
anchors.bottom: true
visible: false
color: Color.transparent
// Use Top layer (same as MainScreen) for proper event handling
WlrLayershell.layer: WlrLayer.Top
WlrLayershell.keyboardFocus: WlrKeyboardFocus.None
WlrLayershell.namespace: "noctalia-" + windowType + "-" + (screen?.name || "unknown")
WlrLayershell.exclusionMode: ExclusionMode.Ignore
// Register with PanelService so widgets can find this window
Component.onCompleted: {
objectName = "popupMenuWindow-" + (screen?.name || "unknown");
PanelService.registerPopupMenuWindow(screen, root);
}
// Load TrayMenu as the default content
Loader {
id: trayMenuLoader
source: Quickshell.shellDir + "/Modules/Bar/Extras/TrayMenu.qml"
onLoaded: {
if (item) {
item.screen = root.screen;
// Set the loaded item as default content
root.contentItem = item;
}
}
}
function open() {
visible = true;
}
// Show a context menu (temporarily replaces TrayMenu as content)
function showContextMenu(menu) {
if (menu) {
contentItem = menu;
open();
}
}
function close() {
visible = false;
// Call close/hide method on current content
if (contentItem) {
if (typeof contentItem.hideMenu === "function") {
contentItem.hideMenu();
} else if (typeof contentItem.close === "function") {
contentItem.close();
}
}
// Restore TrayMenu as default content
if (trayMenuLoader.item) {
contentItem = trayMenuLoader.item;
}
}
// Full-screen click catcher - click anywhere outside content closes the window
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
onClicked: root.close()
}
// Content will be parented here by the popup
// (e.g., TrayMenu, NPopupContextMenu)
}
-63
View File
@@ -1,63 +0,0 @@
import QtQuick
import Quickshell
import Quickshell.Wayland
import qs.Commons
import qs.Modules.Bar.Extras
import qs.Services.UI
// Separate window for TrayMenu context menus
// This is a top-level PanelWindow (sibling to MainScreen, not nested inside it)
PanelWindow {
id: root
required property ShellScreen screen
anchors.top: true
anchors.left: true
anchors.right: true
anchors.bottom: true
visible: false
color: Color.transparent
// Use Top layer (same as MainScreen) for proper event handling
WlrLayershell.layer: WlrLayer.Top
WlrLayershell.keyboardFocus: WlrKeyboardFocus.None
WlrLayershell.namespace: "noctalia-traymenu-" + (screen?.name || "unknown")
WlrLayershell.exclusionMode: ExclusionMode.Ignore
// Expose the trayMenu Loader directly
readonly property alias trayMenuLoader: trayMenu
// Register with PanelService so panels can find this window
Component.onCompleted: {
objectName = "trayMenuWindow-" + (screen?.name || "unknown");
PanelService.registerTrayMenuWindow(screen, root);
}
function open() {
visible = true;
}
function close() {
visible = false;
if (trayMenu.item) {
trayMenu.item.hideMenu();
}
}
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
onClicked: root.close()
}
Loader {
id: trayMenu
source: Quickshell.shellDir + "/Modules/Bar/Extras/TrayMenu.qml"
onLoaded: {
if (item) {
item.screen = root.screen;
}
}
}
}