diff --git a/src/contents/config/main.xml b/src/contents/config/main.xml index b7691a0..feffb8c 100644 --- a/src/contents/config/main.xml +++ b/src/contents/config/main.xml @@ -116,6 +116,78 @@ "width": 50 } ] + }, + { + "name": "Ultra Wide Overlapped Grid", + "padding": 0, + "zones": [ + { + "x": 0, + "y": 0, + "height": 100, + "width": 25 + }, + { + "x": 25, + "y": 0, + "height": 100, + "width": 50 + }, + { + "x": 75, + "y": 0, + "height": 100, + "width": 25 + }, + { + "x": 0, + "y": 0, + "height": 100, + "width": 50 + }, + { + "x": 50, + "y": 0, + "height": 100, + "width": 50 + }, + { + "x": 25, + "y": 0, + "height": 100, + "width": 25 + }, + { + "x": 50, + "y": 0, + "height": 100, + "width": 25 + }, + { + "x": 0, + "y": 50, + "height": 50, + "width": 25 + }, + { + "x": 0, + "y": 0, + "height": 50, + "width": 25 + }, + { + "x": 75, + "y": 50, + "height": 50, + "width": 25 + }, + { + "x": 75, + "y": 0, + "height": 50, + "width": 25 + } + ] } ] diff --git a/src/contents/ui/config.ui b/src/contents/ui/config.ui index 7ab49bf..49414bf 100644 --- a/src/contents/ui/config.ui +++ b/src/contents/ui/config.ui @@ -168,6 +168,11 @@ My cursor is anywhere in the zone + + + My cursor is closest to the zone center + + @@ -410,6 +415,78 @@ "width": 50 } ] + }, + { + "name": "Ultra Wide Overlapped Grid", + "padding": 0, + "zones": [ + { + "x": 0, + "y": 0, + "height": 100, + "width": 25 + }, + { + "x": 25, + "y": 0, + "height": 100, + "width": 50 + }, + { + "x": 75, + "y": 0, + "height": 100, + "width": 25 + }, + { + "x": 0, + "y": 0, + "height": 100, + "width": 50 + }, + { + "x": 50, + "y": 0, + "height": 100, + "width": 50 + }, + { + "x": 25, + "y": 0, + "height": 100, + "width": 25 + }, + { + "x": 50, + "y": 0, + "height": 100, + "width": 25 + }, + { + "x": 0, + "y": 50, + "height": 50, + "width": 25 + }, + { + "x": 0, + "y": 0, + "height": 50, + "width": 25 + }, + { + "x": 75, + "y": 50, + "height": 50, + "width": 25 + }, + { + "x": 75, + "y": 0, + "height": 50, + "width": 25 + } + ] } ] diff --git a/src/contents/ui/main.qml b/src/contents/ui/main.qml index 722a22d..9e198ad 100644 --- a/src/contents/ui/main.qml +++ b/src/contents/ui/main.qml @@ -29,6 +29,7 @@ PlasmaCore.Dialog { property var activeScreen: null property var config: ({}) property bool showZoneOverlay: config.zoneOverlayShowWhen == 0 + property bool useClosestZoneCenter: config.zoneOverlayHighlightTarget == 2 property var errors: [] title: "KZones Overlay" @@ -147,6 +148,31 @@ PlasmaCore.Dialog { }); } + function findClosestZone(zones, cursorPos, clientArea) { + let closestZone = -1; + let closestDistance = Infinity; + + for (let zoneIndex = 0; zoneIndex < zones.length; zoneIndex++) { + const zone = zones[zoneIndex]; + const zoneCenter = { + x: (zone.x + zone.width / 2) / 100 * clientArea.width + clientArea.x, + y: (zone.y + zone.height / 2) / 100 * clientArea.height + clientArea.y + }; + + const distance = Math.sqrt( + Math.pow(cursorPos.x - zoneCenter.x, 2) + + Math.pow(cursorPos.y - zoneCenter.y, 2) + ); + + if (distance < closestDistance) { + closestDistance = distance; + closestZone = zoneIndex; + } + } + + return closestZone; + } + function checkFilter(client) { if (!client) return false; @@ -719,11 +745,16 @@ PlasmaCore.Dialog { // zone overlay const currentZones = repeaterLayout.itemAt(currentLayout) if (config.enableZoneOverlay && showZoneOverlay && !zoneSelector.expanded) { - currentZones.repeater.model.forEach((zone, zoneIndex) => { - if (isHovering(currentZones.repeater.itemAt(zoneIndex).children[config.zoneOverlayHighlightTarget])) { - hoveringZone = zoneIndex; - } - }); + if (useClosestZoneCenter) { + const zones = config.layouts[currentLayout].zones; + hoveringZone = findClosestZone(zones, Workspace.cursorPos, clientArea); + } else { + currentZones.repeater.model.forEach((zone, zoneIndex) => { + if (isHovering(currentZones.repeater.itemAt(zoneIndex).children[config.zoneOverlayHighlightTarget])) { + hoveringZone = zoneIndex; + } + }); + } } // zone selector @@ -753,27 +784,33 @@ PlasmaCore.Dialog { if (Workspace.cursorPos.x <= clientArea.x + triggerDistance || Workspace.cursorPos.x >= clientArea.x + clientArea.width - triggerDistance || Workspace.cursorPos.y <= clientArea.y + triggerDistance || Workspace.cursorPos.y >= clientArea.y + clientArea.height - triggerDistance) { const padding = config.layouts[currentLayout].padding || 0; const halfPadding = padding/2; - currentZones.repeater.model.forEach((zone, zoneIndex) => { - const zoneItem = currentZones.repeater.itemAt(zoneIndex); - const itemGlobal = zoneItem.mapToGlobal(Qt.point(0, 0)); - let zoneGeometry = { - x: itemGlobal.x - padding/2, - y: itemGlobal.y - padding/2, - width: zoneItem.width + padding, - height: zoneItem.height + padding - }; - if(zoneGeometry.x <= halfPadding ) { zoneGeometry.x = 0; zoneGeometry.width += padding; } //adjust most left edge - if(zoneGeometry.y <= halfPadding ) { zoneGeometry.y = 0; zoneGeometry.height += padding; } //adjust most top edge - if(zoneGeometry.x + zoneGeometry.width >= clientArea.width - halfPadding ) { //adjust most right edge - zoneGeometry.width += halfPadding; - } - if(zoneGeometry.y + zoneGeometry.height >= clientArea.height - halfPadding ) { //adjust most bottom edge - zoneGeometry.height += halfPadding; - } - if (isPointInside(Workspace.cursorPos.x, Workspace.cursorPos.y, zoneGeometry)) { - hoveringZone = zoneIndex; - } - }); + + if (useClosestZoneCenter) { + const zones = config.layouts[currentLayout].zones; + hoveringZone = findClosestZone(zones, Workspace.cursorPos, clientArea); + } else { + currentZones.repeater.model.forEach((zone, zoneIndex) => { + const zoneItem = currentZones.repeater.itemAt(zoneIndex); + const itemGlobal = zoneItem.mapToGlobal(Qt.point(0, 0)); + let zoneGeometry = { + x: itemGlobal.x - padding/2, + y: itemGlobal.y - padding/2, + width: zoneItem.width + padding, + height: zoneItem.height + padding + }; + if(zoneGeometry.x <= halfPadding ) { zoneGeometry.x = 0; zoneGeometry.width += padding; } //adjust most left edge + if(zoneGeometry.y <= halfPadding ) { zoneGeometry.y = 0; zoneGeometry.height += padding; } //adjust most top edge + if(zoneGeometry.x + zoneGeometry.width >= clientArea.width - halfPadding ) { //adjust most right edge + zoneGeometry.width += halfPadding; + } + if(zoneGeometry.y + zoneGeometry.height >= clientArea.height - halfPadding ) { //adjust most bottom edge + zoneGeometry.height += halfPadding; + } + if (isPointInside(Workspace.cursorPos.x, Workspace.cursorPos.y, zoneGeometry)) { + hoveringZone = zoneIndex; + } + }); + } } }