repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
quickshell/nuguland/SurfaceManager.qml
Rawimport QtQuick
Item {
id: root
property bool popoutOpen: false
property bool popoutClosing: false
property string popoutPhase: "closed"
property string popoutName: ""
property string activeLoaderName: ""
property string pendingLoaderName: ""
property string removingLoaderName: ""
property var previousContent: ({
})
property string lastInteraction: ""
property string lastCloseReason: ""
property rect popoutAnchor: Qt.rect(0, 0, 0, 0)
property real popoutProgress: 0
property int screenWidth: 0
property int screenHeight: 0
property int barHeight: 34
property var anchorRegistry: ({
})
readonly property int closeRetentionMs: 0
readonly property real goldenRatio: 1.61803
function parseRect(text) {
const parts = String(text).split(/[, x]+/).filter((p) => {
return p.length > 0;
}).map(Number);
if (parts.length !== 4 || parts.some((n) => {
return !Number.isFinite(n);
}))
return Qt.rect(0, 0, 0, 0);
return Qt.rect(parts[0], parts[1], parts[2], parts[3]);
}
function rectObject(rect) {
return {
"x": Math.round(rect.x),
"y": Math.round(rect.y),
"width": Math.round(rect.width),
"height": Math.round(rect.height)
};
}
function popoutWidth() {
if (screenWidth <= 0)
return 844;
return Math.max(520, Math.min(920, Math.round(screenWidth / goldenRatio)));
}
function heightBudget(wanted) {
const maxHeight = screenHeight > 0 ? Math.max(260, screenHeight - barHeight - 48) : 680;
return Math.min(maxHeight, Math.max(220, Number(wanted)));
}
function popoutContentSize(name) {
const width = popoutWidth();
switch (String(name)) {
case "clock":
return {
"width": width,
"height": heightBudget(260)
};
case "system":
return {
"width": width,
"height": heightBudget(520)
};
case "notifications":
return {
"width": width,
"height": heightBudget(460)
};
case "tray":
return {
"width": width,
"height": heightBudget(440)
};
case "media":
return {
"width": width,
"height": heightBudget(420)
};
case "clipboard":
return {
"width": width,
"height": heightBudget(500)
};
case "launcher":
return {
"width": width,
"height": heightBudget(560)
};
case "audio":
return {
"width": width,
"height": heightBudget(520)
};
case "brightness":
return {
"width": width,
"height": heightBudget(260)
};
case "connectivity":
return {
"width": width,
"height": heightBudget(540)
};
case "power":
return {
"width": width,
"height": heightBudget(480)
};
default:
return {
"width": width,
"height": heightBudget(300)
};
}
}
function popupWindowAnchorRect() {
return {
"x": 0,
"y": Math.max(1, Math.round(barHeight)),
"width": screenWidth > 0 ? screenWidth : popoutContentSize(popoutName).width,
"height": 1
};
}
function popupCardFrame(progress) {
const t = Math.max(0, Math.min(1, Number(progress)));
const contentSize = popoutContentSize(popoutName);
const surfaceWidth = screenWidth > 0 ? screenWidth : contentSize.width;
return {
"source": "simple-center-slide-fade",
"progress": t,
"currentRect": {
"x": Math.max(8, Math.round((surfaceWidth - contentSize.width) / 2) + 8),
"y": Math.round(barHeight - 18 + 26 * t),
"width": Math.max(1, Math.round(contentSize.width - 16)),
"height": Math.max(1, Math.round(contentSize.height - 16))
},
"opacity": t
};
}
function popoutContentCatalog() {
return JSON.stringify({
"host": "PopoutHost.qml",
"loaderPolicy": "single-active-loader-with-close-retention",
"completeContent": true,
"entries": {
"clock": {
"component": "calendar-agenda",
"source": "Time.qml",
"visual": ["clock", "date", "calendar-grid", "agenda"]
},
"system": {
"component": "system-resources",
"source": "Resources.qml",
"visual": ["cpu", "memory", "swap", "disk-rate", "temperature", "process-table", "btm-launch"]
},
"notifications": {
"component": "notification-history",
"source": "Notifications.qml",
"visual": ["summary", "attention", "actions"]
},
"tray": {
"component": "tray-menu-host",
"source": "Tray.qml",
"visual": ["items", "attention", "native-menu-host"]
},
"media": {
"component": "media-controls",
"source": "Media.qml",
"visual": ["active-player", "transport", "progress", "selection"]
},
"clipboard": {
"component": "clipboard-history",
"source": "Clipboard.qml",
"visual": ["search", "pinned", "private-mode", "launcher-rows"]
},
"launcher": {
"component": "launcher-search",
"source": "Launcher.qml",
"visual": ["provider-chips", "single-list", "preview", "bottom-search"]
},
"audio": {
"component": "audio-mixer",
"source": "Audio.qml",
"visual": ["sinks", "sources", "streams", "mute"]
},
"brightness": {
"component": "brightness-control",
"source": "Brightness.qml",
"visual": ["level", "luminance-shader", "osd"]
},
"connectivity": {
"component": "connectivity-panel",
"source": "Network.qml+Bluetooth.qml",
"visual": ["network", "wifi", "bluetooth", "devices"]
},
"power": {
"component": "power-battery",
"source": "Power.qml",
"visual": ["battery", "profile", "session", "confirmation"]
}
}
});
}
function registerAnchor(name, anchorText) {
const next = Object.assign({
}, anchorRegistry);
next[String(name)] = rectObject(parseRect(anchorText));
anchorRegistry = next;
return registeredAnchors();
}
function registeredAnchors() {
return JSON.stringify(anchorRegistry);
}
function setPopoutScreen(width, height, topBarHeight) {
screenWidth = Math.max(0, Number(width));
screenHeight = Math.max(0, Number(height));
barHeight = Math.max(1, Number(topBarHeight || barHeight));
return popoutState();
}
function clampedTarget(origin, contentSize) {
let x = Math.round(origin.x - contentSize.width / 2);
const edges = [];
if (x < 0) {
x = 0;
edges.push("left");
}
if (screenWidth > 0 && x + contentSize.width > screenWidth) {
x = Math.max(0, screenWidth - contentSize.width);
edges.length = 0;
edges.push("right");
}
return {
"rect": {
"x": x,
"y": origin.y,
"width": contentSize.width,
"height": contentSize.height
},
"edges": edges
};
}
function openPopout(name, anchorText) {
const nextName = String(name);
const wasOpen = popoutOpen && !popoutClosing;
unloadTimer.stop();
openTimer.stop();
popoutClosing = false;
lastInteraction = "";
lastCloseReason = "";
popoutName = nextName;
activeLoaderName = nextName;
pendingLoaderName = "";
removingLoaderName = "";
previousContent = ({
});
popoutAnchor = parseRect(anchorText);
popoutOpen = true;
if (wasOpen) {
popoutProgress = 1;
popoutPhase = "open";
} else {
popoutPhase = "opening";
popoutProgress = 0;
openTimer.restart();
}
return popoutState();
}
function openRegisteredPopout(name) {
const anchor = anchorRegistry[String(name)] || {
"x": 0,
"y": 0,
"width": 0,
"height": 0
};
return openPopout(name, `${anchor.x},${anchor.y},${anchor.width},${anchor.height}`);
}
function hoverRegisteredPopout(name) {
if (!popoutOpen)
return popoutState();
openRegisteredPopout(name);
lastInteraction = "hover-switch";
return popoutState();
}
function closePopout(reason) {
if (!popoutOpen && !popoutClosing)
return popoutState();
openTimer.stop();
if (reason && String(reason).length > 0)
lastCloseReason = String(reason);
popoutOpen = false;
popoutClosing = false;
popoutProgress = 0;
popoutPhase = "closed";
popoutName = "";
activeLoaderName = "";
pendingLoaderName = "";
removingLoaderName = "";
previousContent = ({
});
return popoutState();
}
function popoutInteraction(kind) {
lastInteraction = String(kind);
if (lastInteraction === "inside")
return popoutState();
if (lastInteraction === "outside" || lastInteraction === "escape" || lastInteraction === "focus-grab-outside" || lastInteraction === "escape-key")
return closePopout(lastInteraction);
return popoutState();
}
function popoutState() {
const contentSize = popoutContentSize(popoutName);
const origin = {
"x": Math.round(popoutAnchor.x + popoutAnchor.width / 2),
"y": Math.round(popoutAnchor.y + popoutAnchor.height)
};
const target = clampedTarget(origin, contentSize);
return JSON.stringify({
"open": popoutOpen,
"closing": popoutClosing,
"phase": popoutPhase,
"name": popoutName,
"lastInteraction": lastInteraction,
"lastCloseReason": lastCloseReason,
"anchor": rectObject(popoutAnchor),
"origin": origin,
"contentSize": contentSize,
"popupAnchorRect": popupWindowAnchorRect(),
"popupCardFrame": popupCardFrame(popoutProgress),
"activeLoaderName": activeLoaderName,
"pendingLoaderName": pendingLoaderName,
"removingLoaderName": removingLoaderName,
"previousContent": previousContent,
"screen": {
"width": screenWidth,
"height": screenHeight,
"barHeight": barHeight
},
"progress": popoutProgress,
"transition": {
"host": "bar",
"animation": "simple-center-slide-fade",
"direction": popoutClosing ? "up-out" : "down-in",
"loaderActive": popoutOpen,
"targetRect": popupWindowAnchorRect()
}
});
}
Timer {
id: openTimer
interval: root.closeRetentionMs
repeat: false
onTriggered: {
if (!root.popoutOpen || root.popoutClosing)
return ;
root.popoutProgress = 1;
root.popoutPhase = "open";
}
}
Timer {
id: unloadTimer
interval: root.closeRetentionMs
repeat: false
onTriggered: {
root.popoutClosing = false;
root.popoutPhase = "closed";
root.popoutName = "";
root.activeLoaderName = "";
root.pendingLoaderName = "";
root.removingLoaderName = "";
root.previousContent = ({
});
}
}
}