Initial commit of the Quickshell desktop suite: bar, dock, launcher, settings, Control Center, dashboard, OSD, lock screen, desktop widgets, plugin host with the vendored Noctalia/Omarchy compatibility layer, helpers, packaging, tests and phase documentation. Includes the optimization work so far: usage widgets and dashboard gauges no longer animate continuously, desktop widgets pause while covered, system controls stop flickering on background polls, dock app matching uses an indexed catalog, and workspace ghosts are created only for occupied slots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
135 lines
4.4 KiB
QML
135 lines
4.4 KiB
QML
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Io
|
|
|
|
// glassMxrph implementation of Noctalia v4's per-plugin `pluginApi`: same
|
|
// properties and functions (settings, translations, panel control), backed by
|
|
// glassMxrph. Settings persist to settings.json in the plugin's folder, like
|
|
// in Noctalia; panels open as glassMxrph bar drawers (see PluginService).
|
|
QtObject {
|
|
id: api
|
|
|
|
required property string pluginId
|
|
required property string pluginDir
|
|
property var manifest: ({})
|
|
property var pluginSettings: ({})
|
|
|
|
property var mainInstance: null
|
|
property var barWidget: null
|
|
property var desktopWidget: null
|
|
property var launcherProvider: null
|
|
property var controlCenterWidget: null
|
|
|
|
// The screen the panel is open on (null when closed), and the button it hangs from.
|
|
property var panelOpenScreen: null
|
|
property var panelAnchor: null
|
|
property var ipcHandlers: ({})
|
|
|
|
property var pluginTranslations: ({})
|
|
property var pluginFallbackTranslations: ({})
|
|
property string currentLanguage: (Qt.locale().name || "en").split("_")[0]
|
|
property int translationVersion: 0
|
|
|
|
// Host callbacks (set by glassMxrph's PluginService).
|
|
property var _currentScreen: null
|
|
property var _requestPanel: null
|
|
|
|
function nested(obj, path) {
|
|
let current = obj;
|
|
for (const key of String(path).split(".")) {
|
|
if (current === undefined || current === null)
|
|
return undefined;
|
|
current = current[key];
|
|
}
|
|
return current;
|
|
}
|
|
|
|
function saveSettings() {
|
|
settingsFile.setText(JSON.stringify(api.pluginSettings, null, 2));
|
|
api.pluginSettings = Object.assign({}, api.pluginSettings);
|
|
}
|
|
function openPanel(screen, buttonItem) {
|
|
api.panelAnchor = buttonItem || api.barWidget || null;
|
|
api.panelOpenScreen = screen || (api._currentScreen ? api._currentScreen() : Quickshell.screens[0]);
|
|
if (api._requestPanel)
|
|
api._requestPanel(api);
|
|
return true;
|
|
}
|
|
function closePanel(screen) {
|
|
if (!api.panelOpenScreen)
|
|
return false;
|
|
api.panelOpenScreen = null;
|
|
return true;
|
|
}
|
|
// Lets glassMxrph's popout coordinator close this panel like any other.
|
|
function close() {
|
|
api.closePanel(null);
|
|
}
|
|
function togglePanel(screen, buttonItem) {
|
|
if (api.panelOpenScreen && (!screen || screen === api.panelOpenScreen))
|
|
return api.closePanel(screen);
|
|
return api.openPanel(screen, buttonItem);
|
|
}
|
|
function openLauncher(screen) {
|
|
}
|
|
function closeLauncher(screen) {
|
|
}
|
|
function toggleLauncher(screen) {
|
|
}
|
|
function withCurrentScreen(callback) {
|
|
callback(api._currentScreen ? api._currentScreen() : Quickshell.screens[0]);
|
|
}
|
|
|
|
function tr(key, interpolations) {
|
|
let translation = api.nested(api.pluginTranslations, key);
|
|
if (typeof translation !== "string")
|
|
translation = api.nested(api.pluginFallbackTranslations, key);
|
|
if (typeof translation !== "string")
|
|
return "!!" + key + "!!";
|
|
for (const placeholder in (interpolations || {}))
|
|
translation = translation.replace(new RegExp("\\{" + placeholder + "\\}", "g"), interpolations[placeholder]);
|
|
return translation;
|
|
}
|
|
function trp(key, count, interpolations) {
|
|
return api.tr(count === 1 ? key : key + "-plural", Object.assign({
|
|
"count": count
|
|
}, interpolations || {}));
|
|
}
|
|
function hasTranslation(key) {
|
|
return api.nested(api.pluginTranslations, key) !== undefined || api.nested(api.pluginFallbackTranslations, key) !== undefined;
|
|
}
|
|
|
|
function parse(text) {
|
|
try {
|
|
return JSON.parse(text);
|
|
} catch (e) {
|
|
return {};
|
|
}
|
|
}
|
|
property FileView settingsFile: FileView {
|
|
path: api.pluginDir + "/settings.json"
|
|
blockLoading: true
|
|
printErrors: false
|
|
onLoaded: api.pluginSettings = Object.assign({}, (api.manifest.metadata && api.manifest.metadata.defaultSettings) || {}, api.parse(text()))
|
|
onLoadFailed: api.pluginSettings = Object.assign({}, (api.manifest.metadata && api.manifest.metadata.defaultSettings) || {})
|
|
}
|
|
property FileView languageFile: FileView {
|
|
path: api.pluginDir + "/i18n/" + api.currentLanguage + ".json"
|
|
blockLoading: true
|
|
printErrors: false
|
|
onLoaded: {
|
|
api.pluginTranslations = api.parse(text());
|
|
api.translationVersion++;
|
|
}
|
|
}
|
|
property FileView fallbackFile: FileView {
|
|
path: api.pluginDir + "/i18n/en.json"
|
|
blockLoading: true
|
|
printErrors: false
|
|
onLoaded: {
|
|
api.pluginFallbackTranslations = api.parse(text());
|
|
api.translationVersion++;
|
|
}
|
|
}
|
|
}
|