Switched to qmlformat.

This commit is contained in:
ItsLemmy
2025-11-16 17:07:03 -05:00
parent 32905224b9
commit 3ff5b7639f
223 changed files with 9970 additions and 9658 deletions
+87 -87
View File
@@ -1,7 +1,7 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Effects
import QtQuick.Layouts
import Quickshell
import Quickshell.Wayland
import Quickshell.Widgets
@@ -26,7 +26,7 @@ Loader {
target: BarService
function onBarReadyChanged(screenName) {
if (screenName === modelData.name) {
barIsReady = true
barIsReady = true;
}
}
}
@@ -35,7 +35,7 @@ Loader {
Connections {
target: ToplevelManager ? ToplevelManager.toplevels : null
function onValuesChanged() {
updateDockApps()
updateDockApps();
}
}
@@ -43,17 +43,17 @@ Loader {
Connections {
target: Settings.data.dock
function onPinnedAppsChanged() {
updateDockApps()
updateDockApps();
}
function onOnlySameOutputChanged() {
updateDockApps()
updateDockApps();
}
}
// Initial update when component is ready
Component.onCompleted: {
if (ToplevelManager) {
updateDockApps()
updateDockApps();
}
}
@@ -93,33 +93,33 @@ Loader {
// Function to close any open context menu
function closeAllContextMenus() {
if (currentContextMenu && currentContextMenu.visible) {
currentContextMenu.hide()
currentContextMenu.hide();
}
}
// Function to update the combined dock apps model
function updateDockApps() {
const runningApps = ToplevelManager ? (ToplevelManager.toplevels.values || []) : []
const pinnedApps = Settings.data.dock.pinnedApps || []
const combined = []
const processedAppIds = new Set()
const runningApps = ToplevelManager ? (ToplevelManager.toplevels.values || []) : [];
const pinnedApps = Settings.data.dock.pinnedApps || [];
const combined = [];
const processedAppIds = new Set();
// Strategy: Maintain app positions as much as possible
// 1. First pass: Add all running apps (both pinned and non-pinned) in their current order
runningApps.forEach(toplevel => {
if (toplevel && toplevel.appId && !(Settings.data.dock.onlySameOutput && toplevel.screens && !toplevel.screens.includes(modelData))) {
const isPinned = pinnedApps.includes(toplevel.appId)
const appType = isPinned ? "pinned-running" : "running"
const isPinned = pinnedApps.includes(toplevel.appId);
const appType = isPinned ? "pinned-running" : "running";
combined.push({
"type": appType,
"toplevel": toplevel,
"appId": toplevel.appId,
"title": toplevel.title
})
processedAppIds.add(toplevel.appId)
});
processedAppIds.add(toplevel.appId);
}
})
});
// 2. Second pass: Add non-running pinned apps at the end
pinnedApps.forEach(pinnedAppId => {
@@ -130,11 +130,11 @@ Loader {
"toplevel": null,
"appId": pinnedAppId,
"title": pinnedAppId
})
});
}
})
});
dockApps = combined
dockApps = combined;
}
// Timer to unload dock after hide animation completes
@@ -143,7 +143,7 @@ Loader {
interval: hideAnimationDuration + 50 // Add small buffer
onTriggered: {
if (hidden && autoHide) {
dockLoaded = false
dockLoaded = false;
}
}
}
@@ -155,14 +155,14 @@ Loader {
onTriggered: {
// Force menuHovered to false if no menu is current or visible
if (!root.currentContextMenu || !root.currentContextMenu.visible) {
menuHovered = false
menuHovered = false;
}
if (autoHide && !dockHovered && !anyAppHovered && !peekHovered && !menuHovered) {
hidden = true
unloadTimer.restart() // Start unload timer when hiding
hidden = true;
unloadTimer.restart(); // Start unload timer when hiding
} else if (autoHide && !dockHovered && !peekHovered) {
// Restart timer if menu is closing (handles race condition)
restart()
restart();
}
}
}
@@ -173,9 +173,9 @@ Loader {
interval: showDelay
onTriggered: {
if (autoHide) {
dockLoaded = true // Load dock immediately
hidden = false // Then trigger show animation
unloadTimer.stop() // Cancel any pending unload
dockLoaded = true; // Load dock immediately
hidden = false; // Then trigger show animation
unloadTimer.stop(); // Cancel any pending unload
}
}
}
@@ -183,14 +183,14 @@ Loader {
// Watch for autoHide setting changes
onAutoHideChanged: {
if (!autoHide) {
hidden = false
dockLoaded = true
hideTimer.stop()
showTimer.stop()
unloadTimer.stop()
hidden = false;
dockLoaded = true;
hideTimer.stop();
showTimer.stop();
unloadTimer.stop();
} else {
hidden = true
unloadTimer.restart() // Schedule unload after animation
hidden = true;
unloadTimer.restart(); // Schedule unload after animation
}
}
@@ -218,16 +218,16 @@ Loader {
hoverEnabled: true
onEntered: {
peekHovered = true
peekHovered = true;
if (hidden) {
showTimer.start()
showTimer.start();
}
}
onExited: {
peekHovered = false
peekHovered = false;
if (!hidden && !dockHovered && !anyAppHovered && !menuHovered) {
hideTimer.restart()
hideTimer.restart();
}
}
}
@@ -260,9 +260,9 @@ Loader {
margins.bottom: {
switch (Settings.data.bar.position) {
case "bottom":
return (Style.barHeight + Style.marginM) + (Settings.data.bar.floating ? Settings.data.bar.marginVertical * Style.marginXL + floatingMargin : floatingMargin)
return (Style.barHeight + Style.marginM) + (Settings.data.bar.floating ? Settings.data.bar.marginVertical * Style.marginXL + floatingMargin : floatingMargin);
default:
return floatingMargin
return floatingMargin;
}
}
@@ -313,24 +313,24 @@ Loader {
hoverEnabled: true
onEntered: {
dockHovered = true
dockHovered = true;
if (autoHide) {
showTimer.stop()
hideTimer.stop()
unloadTimer.stop() // Cancel unload if hovering
showTimer.stop();
hideTimer.stop();
unloadTimer.stop(); // Cancel unload if hovering
}
}
onExited: {
dockHovered = false
dockHovered = false;
if (autoHide && !anyAppHovered && !peekHovered && !menuHovered) {
hideTimer.restart()
hideTimer.restart();
}
}
onClicked: {
// Close any open context menu when clicking on the dock background
closeAllContextMenus()
closeAllContextMenus();
}
}
@@ -342,8 +342,8 @@ Loader {
function getAppIcon(appData): string {
if (!appData || !appData.appId)
return ""
return ThemeIcons.iconForAppId(appData.appId?.toLowerCase())
return "";
return ThemeIcons.iconForAppId(appData.appId?.toLowerCase());
}
RowLayout {
@@ -371,7 +371,7 @@ Loader {
Connections {
target: modelData?.toplevel
function onClosed() {
Qt.callLater(root.updateDockApps)
Qt.callLater(root.updateDockApps);
}
}
@@ -452,9 +452,9 @@ Loader {
onHoveredChanged: {
// Only update menuHovered if this menu is current and visible
if (root.currentContextMenu === contextMenu && contextMenu.visible) {
menuHovered = hovered
menuHovered = hovered;
} else {
menuHovered = false
menuHovered = false;
}
}
@@ -462,26 +462,26 @@ Loader {
target: contextMenu
function onRequestClose() {
// Clear current menu immediately to prevent hover updates
root.currentContextMenu = null
hideTimer.stop()
contextMenu.hide()
menuHovered = false
anyAppHovered = false
root.currentContextMenu = null;
hideTimer.stop();
contextMenu.hide();
menuHovered = false;
anyAppHovered = false;
}
}
onAppClosed: root.updateDockApps // Force immediate dock update when app is closed
onVisibleChanged: {
if (visible) {
root.currentContextMenu = contextMenu
anyAppHovered = false
root.currentContextMenu = contextMenu;
anyAppHovered = false;
} else if (root.currentContextMenu === contextMenu) {
root.currentContextMenu = null
hideTimer.stop()
menuHovered = false
anyAppHovered = false
root.currentContextMenu = null;
hideTimer.stop();
menuHovered = false;
anyAppHovered = false;
// Restart hide timer after menu closes
if (autoHide && !dockHovered && !anyAppHovered && !peekHovered && !menuHovered) {
hideTimer.restart()
hideTimer.restart();
}
}
}
@@ -496,28 +496,28 @@ Loader {
acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
onEntered: {
anyAppHovered = true
const appName = appButton.appTitle || appButton.appId || "Unknown"
const tooltipText = appName.length > 40 ? appName.substring(0, 37) + "..." : appName
anyAppHovered = true;
const appName = appButton.appTitle || appButton.appId || "Unknown";
const tooltipText = appName.length > 40 ? appName.substring(0, 37) + "..." : appName;
if (!contextMenu.visible) {
TooltipService.show(Screen, appButton, tooltipText, "top")
TooltipService.show(Screen, appButton, tooltipText, "top");
}
if (autoHide) {
showTimer.stop()
hideTimer.stop()
unloadTimer.stop() // Cancel unload if hovering app
showTimer.stop();
hideTimer.stop();
unloadTimer.stop(); // Cancel unload if hovering app
}
}
onExited: {
anyAppHovered = false
TooltipService.hide()
anyAppHovered = false;
TooltipService.hide();
// Clear menuHovered if no current menu or menu not visible
if (!root.currentContextMenu || !root.currentContextMenu.visible) {
menuHovered = false
menuHovered = false;
}
if (autoHide && !dockHovered && !peekHovered && !menuHovered) {
hideTimer.restart()
hideTimer.restart();
}
}
@@ -525,33 +525,33 @@ Loader {
if (mouse.button === Qt.RightButton) {
// If right-clicking on the same app with an open context menu, close it
if (root.currentContextMenu === contextMenu && contextMenu.visible) {
root.closeAllContextMenus()
return
root.closeAllContextMenus();
return;
}
// Close any other existing context menu first
root.closeAllContextMenus()
root.closeAllContextMenus();
// Hide tooltip when showing context menu
TooltipService.hideImmediately()
contextMenu.show(appButton, modelData.toplevel || modelData)
return
TooltipService.hideImmediately();
contextMenu.show(appButton, modelData.toplevel || modelData);
return;
}
// Close any existing context menu for non-right-click actions
root.closeAllContextMenus()
root.closeAllContextMenus();
// Check if toplevel is still valid (not a stale reference)
const isValidToplevel = modelData?.toplevel && ToplevelManager && ToplevelManager.toplevels.values.includes(modelData.toplevel)
const isValidToplevel = modelData?.toplevel && ToplevelManager && ToplevelManager.toplevels.values.includes(modelData.toplevel);
if (mouse.button === Qt.MiddleButton && isValidToplevel && modelData.toplevel.close) {
modelData.toplevel.close()
Qt.callLater(root.updateDockApps) // Force immediate dock update
modelData.toplevel.close();
Qt.callLater(root.updateDockApps); // Force immediate dock update
} else if (mouse.button === Qt.LeftButton) {
if (isValidToplevel && modelData.toplevel.activate) {
// Running app - activate it
modelData.toplevel.activate()
modelData.toplevel.activate();
} else if (modelData?.appId) {
// Pinned app not running - launch it
Quickshell.execDetached(["gtk-launch", modelData.appId])
Quickshell.execDetached(["gtk-launch", modelData.appId]);
}
}
}
+56 -57
View File
@@ -31,21 +31,21 @@ PopupWindow {
function initItems() {
// Is this a running app?
const isRunning = root.toplevel && ToplevelManager && ToplevelManager.toplevels.values.includes(root.toplevel)
const isRunning = root.toplevel && ToplevelManager && ToplevelManager.toplevels.values.includes(root.toplevel);
// Is this a pinned app?
const isPinned = root.toplevel && root.isAppPinned(root.toplevel.appId)
const isPinned = root.toplevel && root.isAppPinned(root.toplevel.appId);
var next = []
var next = [];
if (isRunning) {
// Focus item
next.push({
"icon": "eye",
"text": I18n.tr("dock.menu.focus"),
"action": function () {
handleFocus()
handleFocus();
}
})
});
}
// Pin/Unpin item
@@ -53,9 +53,9 @@ PopupWindow {
"icon": !isPinned ? "pin" : "unpin",
"text": !isPinned ? I18n.tr("dock.menu.pin") : I18n.tr("dock.menu.unpin"),
"action": function () {
handlePin()
handlePin();
}
})
});
if (isRunning) {
// Close item
@@ -63,55 +63,54 @@ PopupWindow {
"icon": "close",
"text": I18n.tr("dock.menu.close"),
"action": function () {
handleClose()
handleClose();
}
})
});
}
// Create a menu entry for each app-specific action definied in its .desktop file
if (typeof DesktopEntries !== 'undefined' && DesktopEntries.byId) {
const entry = (DesktopEntries.heuristicLookup) ? DesktopEntries.heuristicLookup(appId) : DesktopEntries.byId(appId)
const entry = (DesktopEntries.heuristicLookup) ? DesktopEntries.heuristicLookup(appId) : DesktopEntries.byId(appId);
if (entry != null) {
entry.actions.forEach(function (action) {
next.push({
"icon": "",
"text": action.name,
"action": function () {
action.execute()
action.execute();
}
})
})
});
});
}
}
root.items = next
root.items = next;
}
// Helper functions for pin/unpin functionality
function isAppPinned(appId) {
if (!appId)
return false
const pinnedApps = Settings.data.dock.pinnedApps || []
return pinnedApps.includes(appId)
return false;
const pinnedApps = Settings.data.dock.pinnedApps || [];
return pinnedApps.includes(appId);
}
function toggleAppPin(appId) {
if (!appId)
return
let pinnedApps = (Settings.data.dock.pinnedApps || []).slice() // Create a copy
const isPinned = pinnedApps.includes(appId)
return;
let pinnedApps = (Settings.data.dock.pinnedApps || []).slice(); // Create a copy
const isPinned = pinnedApps.includes(appId);
if (isPinned) {
// Unpin: remove from array
pinnedApps = pinnedApps.filter(id => id !== appId)
pinnedApps = pinnedApps.filter(id => id !== appId);
} else {
// Pin: add to array
pinnedApps.push(appId)
pinnedApps.push(appId);
}
// Update the settings
Settings.data.dock.pinnedApps = pinnedApps
Settings.data.dock.pinnedApps = pinnedApps;
}
anchor.item: anchorItem
@@ -120,62 +119,62 @@ PopupWindow {
function show(item, toplevelData) {
if (!item) {
return
return;
}
anchorItem = item
toplevel = toplevelData
initItems()
visible = true
canAutoClose = false
gracePeriodTimer.restart()
anchorItem = item;
toplevel = toplevelData;
initItems();
visible = true;
canAutoClose = false;
gracePeriodTimer.restart();
}
function hide() {
visible = false
root.items.length = 0
visible = false;
root.items.length = 0;
}
// Helper function to determine which menu item is under the mouse
function getHoveredItem(mouseY) {
const itemHeight = 32
const startY = Style.marginM
const relativeY = mouseY - startY
const itemHeight = 32;
const startY = Style.marginM;
const relativeY = mouseY - startY;
if (relativeY < 0)
return -1
return -1;
const itemIndex = Math.floor(relativeY / itemHeight)
return itemIndex >= 0 && itemIndex < root.items.length ? itemIndex : -1
const itemIndex = Math.floor(relativeY / itemHeight);
return itemIndex >= 0 && itemIndex < root.items.length ? itemIndex : -1;
}
function handleFocus() {
if (root.toplevel?.activate) {
root.toplevel.activate()
root.toplevel.activate();
}
root.requestClose()
root.requestClose();
}
function handlePin() {
if (root.toplevel?.appId) {
root.toggleAppPin(root.toplevel.appId)
root.toggleAppPin(root.toplevel.appId);
}
root.requestClose()
root.requestClose();
}
function handleClose() {
// Check if toplevel is still valid before trying to close it
const isValidToplevel = root.toplevel && ToplevelManager && ToplevelManager.toplevels.values.includes(root.toplevel)
const isValidToplevel = root.toplevel && ToplevelManager && ToplevelManager.toplevels.values.includes(root.toplevel);
if (isValidToplevel && root.toplevel.close) {
root.toplevel.close()
root.toplevel.close();
// Trigger immediate dock update callback if provided
if (root.onAppClosed && typeof root.onAppClosed === "function") {
Qt.callLater(root.onAppClosed)
Qt.callLater(root.onAppClosed);
}
}
root.hide()
root.requestClose()
root.hide();
root.requestClose();
}
// Short delay to ignore spurious events
@@ -184,9 +183,9 @@ PopupWindow {
interval: 1500
repeat: false
onTriggered: {
root.canAutoClose = true
root.canAutoClose = true;
if (!menuMouseArea.containsMouse) {
closeTimer.start()
closeTimer.start();
}
}
}
@@ -197,7 +196,7 @@ PopupWindow {
repeat: false
running: false
onTriggered: {
root.hide()
root.hide();
}
}
@@ -216,25 +215,25 @@ PopupWindow {
cursorShape: root.hoveredItem >= 0 ? Qt.PointingHandCursor : Qt.ArrowCursor
onEntered: {
closeTimer.stop()
closeTimer.stop();
}
onExited: {
root.hoveredItem = -1
root.hoveredItem = -1;
if (root.canAutoClose) {
// Only close if grace period has passed
closeTimer.start()
closeTimer.start();
}
}
onPositionChanged: mouse => {
root.hoveredItem = root.getHoveredItem(mouse.y)
root.hoveredItem = root.getHoveredItem(mouse.y);
}
onClicked: mouse => {
const clickedItem = root.getHoveredItem(mouse.y)
const clickedItem = root.getHoveredItem(mouse.y);
if (clickedItem >= 0) {
root.items[clickedItem].action.call()
root.items[clickedItem].action.call();
}
}
}