Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions src/contents/config/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
]
</default>
Expand Down
77 changes: 77 additions & 0 deletions src/contents/ui/config.ui
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@
<string>My cursor is anywhere in the zone</string>
</property>
</item>
<item>
<property name="text">
<string>My cursor is closest to the zone center</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0">
Expand Down Expand Up @@ -410,6 +415,78 @@
&quot;width&quot;: 50
}
]
},
{
&quot;name&quot;: &quot;Ultra Wide Overlapped Grid&quot;,
&quot;padding&quot;: 0,
&quot;zones&quot;: [
{
&quot;x&quot;: 0,
&quot;y&quot;: 0,
&quot;height&quot;: 100,
&quot;width&quot;: 25
},
{
&quot;x&quot;: 25,
&quot;y&quot;: 0,
&quot;height&quot;: 100,
&quot;width&quot;: 50
},
{
&quot;x&quot;: 75,
&quot;y&quot;: 0,
&quot;height&quot;: 100,
&quot;width&quot;: 25
},
{
&quot;x&quot;: 0,
&quot;y&quot;: 0,
&quot;height&quot;: 100,
&quot;width&quot;: 50
},
{
&quot;x&quot;: 50,
&quot;y&quot;: 0,
&quot;height&quot;: 100,
&quot;width&quot;: 50
},
{
&quot;x&quot;: 25,
&quot;y&quot;: 0,
&quot;height&quot;: 100,
&quot;width&quot;: 25
},
{
&quot;x&quot;: 50,
&quot;y&quot;: 0,
&quot;height&quot;: 100,
&quot;width&quot;: 25
},
{
&quot;x&quot;: 0,
&quot;y&quot;: 50,
&quot;height&quot;: 50,
&quot;width&quot;: 25
},
{
&quot;x&quot;: 0,
&quot;y&quot;: 0,
&quot;height&quot;: 50,
&quot;width&quot;: 25
},
{
&quot;x&quot;: 75,
&quot;y&quot;: 50,
&quot;height&quot;: 50,
&quot;width&quot;: 25
},
{
&quot;x&quot;: 75,
&quot;y&quot;: 0,
&quot;height&quot;: 50,
&quot;width&quot;: 25
}
]
}
]</string>
</property>
Expand Down
89 changes: 63 additions & 26 deletions src/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
});
}
}
}

Expand Down