CurrentScreenDetector: renaming for clarity

This commit is contained in:
Lemmy
2025-12-14 15:57:57 -05:00
parent fa989dd962
commit 8baad31db3
3 changed files with 75 additions and 75 deletions
+3 -3
View File
@@ -5,7 +5,7 @@ import qs.Commons
/**
* Detects which screen the cursor is currently on by creating a temporary
* invisible PanelWindow. Use withTargetScreen() to get the screen asynchronously.
* invisible PanelWindow. Use withCurrentScreen() to get the screen asynchronously.
*
* Usage:
* CurrentScreenDetector {
@@ -13,7 +13,7 @@ import qs.Commons
* }
*
* function doSomething() {
* screenDetector.withTargetScreen(function(screen) {
* screenDetector.withCurrentScreen(function(screen) {
* // screen is the ShellScreen where cursor is
* })
* }
@@ -40,7 +40,7 @@ Item {
* On single-monitor setups, executes immediately.
* On multi-monitor setups, briefly opens an invisible window to detect the screen.
*/
function withTargetScreen(callback: var): void {
function withCurrentScreen(callback: var): void {
if (root.pendingCallback) {
Logger.w("CurrentScreenDetector", "Another detection is pending, ignoring new call");
return;
+68 -68
View File
@@ -43,10 +43,10 @@ Item {
if (Settings.data.ui.settingsPanelMode === "window") {
SettingsPanelService.toggleWindow();
} else {
root.screenDetector.withTargetScreen(screen => {
var settingsPanel = PanelService.getPanel("settingsPanel", screen);
settingsPanel?.toggle();
});
root.screenDetector.withCurrentScreen(screen => {
var settingsPanel = PanelService.getPanel("settingsPanel", screen);
settingsPanel?.toggle();
});
}
}
}
@@ -54,10 +54,10 @@ Item {
IpcHandler {
target: "calendar"
function toggle() {
root.screenDetector.withTargetScreen(screen => {
var clockPanel = PanelService.getPanel("clockPanel", screen);
clockPanel?.toggle(null, "Clock");
});
root.screenDetector.withCurrentScreen(screen => {
var clockPanel = PanelService.getPanel("clockPanel", screen);
clockPanel?.toggle(null, "Clock");
});
}
}
@@ -65,10 +65,10 @@ Item {
target: "notifications"
function toggleHistory() {
// Will attempt to open the panel next to the bar button if any.
root.screenDetector.withTargetScreen(screen => {
var notificationHistoryPanel = PanelService.getPanel("notificationHistoryPanel", screen);
notificationHistoryPanel.toggle(null, "NotificationHistory");
});
root.screenDetector.withCurrentScreen(screen => {
var notificationHistoryPanel = PanelService.getPanel("notificationHistoryPanel", screen);
notificationHistoryPanel.toggle(null, "NotificationHistory");
});
}
function toggleDND() {
NotificationService.doNotDisturb = !NotificationService.doNotDisturb;
@@ -106,39 +106,39 @@ Item {
IpcHandler {
target: "launcher"
function toggle() {
root.screenDetector.withTargetScreen(screen => {
var launcherPanel = PanelService.getPanel("launcherPanel", screen);
if (!launcherPanel?.isPanelOpen || (launcherPanel?.isPanelOpen && !launcherPanel?.activePlugin))
launcherPanel?.toggle();
launcherPanel?.setSearchText("");
});
root.screenDetector.withCurrentScreen(screen => {
var launcherPanel = PanelService.getPanel("launcherPanel", screen);
if (!launcherPanel?.isPanelOpen || (launcherPanel?.isPanelOpen && !launcherPanel?.activePlugin))
launcherPanel?.toggle();
launcherPanel?.setSearchText("");
});
}
function clipboard() {
root.screenDetector.withTargetScreen(screen => {
var launcherPanel = PanelService.getPanel("launcherPanel", screen);
if (!launcherPanel?.isPanelOpen) {
launcherPanel?.toggle();
}
launcherPanel?.setSearchText(">clip ");
});
root.screenDetector.withCurrentScreen(screen => {
var launcherPanel = PanelService.getPanel("launcherPanel", screen);
if (!launcherPanel?.isPanelOpen) {
launcherPanel?.toggle();
}
launcherPanel?.setSearchText(">clip ");
});
}
function calculator() {
root.screenDetector.withTargetScreen(screen => {
var launcherPanel = PanelService.getPanel("launcherPanel", screen);
if (!launcherPanel?.isPanelOpen) {
launcherPanel?.toggle();
}
launcherPanel?.setSearchText(">calc ");
});
root.screenDetector.withCurrentScreen(screen => {
var launcherPanel = PanelService.getPanel("launcherPanel", screen);
if (!launcherPanel?.isPanelOpen) {
launcherPanel?.toggle();
}
launcherPanel?.setSearchText(">calc ");
});
}
function emoji() {
root.screenDetector.withTargetScreen(screen => {
var launcherPanel = PanelService.getPanel("launcherPanel", screen);
if (!launcherPanel?.isPanelOpen) {
launcherPanel?.toggle();
}
launcherPanel?.setSearchText(">emoji ");
});
root.screenDetector.withCurrentScreen(screen => {
var launcherPanel = PanelService.getPanel("launcherPanel", screen);
if (!launcherPanel?.isPanelOpen) {
launcherPanel?.toggle();
}
launcherPanel?.setSearchText(">emoji ");
});
}
}
@@ -209,10 +209,10 @@ Item {
IpcHandler {
target: "sessionMenu"
function toggle() {
root.screenDetector.withTargetScreen(screen => {
var sessionMenuPanel = PanelService.getPanel("sessionMenuPanel", screen);
sessionMenuPanel?.toggle();
});
root.screenDetector.withCurrentScreen(screen => {
var sessionMenuPanel = PanelService.getPanel("sessionMenuPanel", screen);
sessionMenuPanel?.toggle();
});
}
function lockAndSuspend() {
@@ -223,15 +223,15 @@ Item {
IpcHandler {
target: "controlCenter"
function toggle() {
root.screenDetector.withTargetScreen(screen => {
var controlCenterPanel = PanelService.getPanel("controlCenterPanel", screen);
if (Settings.data.controlCenter.position === "close_to_bar_button") {
// Will attempt to open the panel next to the bar button if any.
controlCenterPanel?.toggle(null, "ControlCenter");
} else {
controlCenterPanel?.toggle();
}
});
root.screenDetector.withCurrentScreen(screen => {
var controlCenterPanel = PanelService.getPanel("controlCenterPanel", screen);
if (Settings.data.controlCenter.position === "close_to_bar_button") {
// Will attempt to open the panel next to the bar button if any.
controlCenterPanel?.toggle(null, "ControlCenter");
} else {
controlCenterPanel?.toggle();
}
});
}
}
@@ -247,10 +247,10 @@ Item {
target: "wallpaper"
function toggle() {
if (Settings.data.wallpaper.enabled) {
root.screenDetector.withTargetScreen(screen => {
var wallpaperPanel = PanelService.getPanel("wallpaperPanel", screen);
wallpaperPanel?.toggle();
});
root.screenDetector.withCurrentScreen(screen => {
var wallpaperPanel = PanelService.getPanel("wallpaperPanel", screen);
wallpaperPanel?.toggle();
});
}
}
@@ -312,10 +312,10 @@ Item {
NetworkService.setWifiEnabled(false);
}
function togglePanel() {
root.screenDetector.withTargetScreen(screen => {
var wifiPanel = PanelService.getPanel("wifiPanel", screen);
wifiPanel?.toggle(null, "WiFi");
});
root.screenDetector.withCurrentScreen(screen => {
var wifiPanel = PanelService.getPanel("wifiPanel", screen);
wifiPanel?.toggle(null, "WiFi");
});
}
}
@@ -331,20 +331,20 @@ Item {
BluetoothService.setBluetoothEnabled(false);
}
function togglePanel() {
root.screenDetector.withTargetScreen(screen => {
var bluetoothPanel = PanelService.getPanel("bluetoothPanel", screen);
bluetoothPanel?.toggle(null, "Bluetooth");
});
root.screenDetector.withCurrentScreen(screen => {
var bluetoothPanel = PanelService.getPanel("bluetoothPanel", screen);
bluetoothPanel?.toggle(null, "Bluetooth");
});
}
}
IpcHandler {
target: "battery"
function togglePanel() {
root.screenDetector.withTargetScreen(screen => {
var batteryPanel = PanelService.getPanel("batteryPanel", screen);
batteryPanel?.toggle(null, "Battery");
});
root.screenDetector.withCurrentScreen(screen => {
var batteryPanel = PanelService.getPanel("batteryPanel", screen);
batteryPanel?.toggle(null, "Battery");
});
}
}
+4 -4
View File
@@ -47,7 +47,7 @@ Singleton {
// Plugin container from shell.qml (for placing Main instances in graphics scene)
property var pluginContainer: null
// Screen detector from shell.qml (for withTargetScreen in plugin API)
// Screen detector from shell.qml (for withCurrentScreen in plugin API)
property var screenDetector: null
// Track if we need to initialize once container is ready
@@ -582,7 +582,7 @@ Singleton {
property var saveSettings: null
property var openPanel: null
property var closePanel: null
property var withTargetScreen: null
property var withCurrentScreen: null
property var tr: null
property var trp: null
property var hasTranslation: null
@@ -655,14 +655,14 @@ Singleton {
};
// ----------------------------------------
api.withTargetScreen = function (callback) {
api.withCurrentScreen = function (callback) {
// Detect which screen the cursor is on and call callback with that screen
if (!root.screenDetector) {
Logger.w("PluginAPI", "Screen detector not available, using primary screen");
callback(Quickshell.screens[0]);
return;
}
root.screenDetector.withTargetScreen(callback);
root.screenDetector.withCurrentScreen(callback);
};
// ----------------------------------------