Skip to content
Merged
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
11 changes: 11 additions & 0 deletions shell/Commons/Util.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ import QtQuick
QtObject {
id: root

// Manual click forwarding must honor the same clipping as Qt's hit test.
// Collapsed drawers keep their children laid out beyond the visible edge.
function itemContainsPoint(target, source, x, y) {
if (!target || !target.contains(target.mapFromItem(source, x, y))) return false
for (var item = target; item; item = item.parent) {
if (!item.visible || item.opacity === 0 || !item.enabled) return false
if (item.clip && !item.contains(item.mapFromItem(source, x, y))) return false
}
return true
}

function clamp(value, min, max) {
var n = Number(value)
if (!isFinite(n)) return min
Expand Down
3 changes: 1 addition & 2 deletions shell/Ui/KeyboardPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,7 @@ PanelWindow {
var target = targets[i]
if (!target || !target.triggerPress || target.visible === false || target.opacity === 0 || !target.mapToItem) continue
if (root.bar.targetBelongsToWindow && !root.bar.targetBelongsToWindow(target, root.anchorWindow)) continue
var pos = root.anchorWindow.itemPosition(target)
if (p.x >= pos.x && p.x <= pos.x + target.width && p.y >= pos.y && p.y <= pos.y + target.height) return target
if (Util.itemContainsPoint(target, root.anchorWindow.contentItem, p.x, p.y)) return target
}
return null
}
Expand Down
10 changes: 1 addition & 9 deletions shell/plugins/bar/Bar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1118,15 +1118,7 @@ Item {
var target = clickTargets[i]
if (!moduleTargetClickable(target)) continue

var targetPoint = { x: localX, y: localY }
try {
targetPoint = slot.mapToItem(target, localX, localY)
} catch (e) {
continue
}

if (targetPoint.x >= 0 && targetPoint.x <= target.width &&
targetPoint.y >= 0 && targetPoint.y <= target.height) {
if (Util.itemContainsPoint(target, slot, localX, localY)) {
return target
}
}
Expand Down
45 changes: 45 additions & 0 deletions test/shell.d/bar-click-clipping-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

run_node_test <<'JS'
const fs = require('fs')
const util = fs.readFileSync(root + '/shell/Commons/Util.qml', 'utf8')
const body = util.match(/function itemContainsPoint\(target, source, x, y\) \{([\s\S]*?)\n \}/)[1]
const hit = new Function('target', 'source', 'x', 'y', body)

function item(x, width, parent = null, clip = false) {
return {
x, width, parent, clip, visible: true, enabled: true, opacity: 1,
mapFromItem(source, x, y) {
for (let node = this; node; node = node.parent) x -= node.x
return { x, y }
},
contains(p) { return p.x >= 0 && p.x < this.width && p.y >= 0 && p.y < 24 }
}
}

const drawer = item(100, 75, null, true)
const slidingRow = item(75, 75, drawer)
const hiddenButton = item(25, 25, slidingRow)
const agents = item(200, 25)
assert(!hit(hiddenButton, null, 210, 12), 'collapsed tray button cannot intercept a click on agents')
assert(hit(agents, null, 210, 12), 'visible agent button receives the click')
slidingRow.x = 0
assert(hit(hiddenButton, null, 135, 12), 'expanded drawer button remains clickable')
slidingRow.x = 40
assert(hit(hiddenButton, null, 170, 12), 'revealed portion of an animating drawer button is clickable')
assert(!hit(hiddenButton, null, 180, 12), 'clipped portion of an animating drawer button is not clickable')
drawer.visible = false
assert(!hit(hiddenButton, null, 170, 12), 'hidden ancestors prevent forwarded clicks')
drawer.visible = true
drawer.enabled = false
assert(!hit(hiddenButton, null, 170, 12), 'disabled ancestors prevent forwarded clicks')

for (const file of ['shell/plugins/bar/Bar.qml', 'shell/Ui/KeyboardPanel.qml']) {
assert(fs.readFileSync(root + '/' + file, 'utf8').includes('Util.itemContainsPoint(target,'),
file + ' checks clipping when forwarding bar clicks')
}
JS
Loading