summaryrefslogtreecommitdiffstats
path: root/src/compositor/qmlfiles/WaylandCursorItem.qml
blob: 1153038b9e26980a27d14ab184d6ea607553eb11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

import QtQuick
import QtWayland.Compositor

WaylandQuickItem {
    id: cursorItem
    property QtObject seat
    property int hotspotX: 0
    property int hotspotY: 0

    visible: cursorItem.surface != null
    inputEventsEnabled: false
    enabled: false
    transform: Translate {
        // If we've set an output scale factor different from the device pixel ratio
        // then the item will be rendered scaled, so we need to shift the hotspot accordingly
        x: -hotspotX * (output ? output.scaleFactor / Screen.devicePixelRatio : 1)
        y: -hotspotY * (output ? output.scaleFactor / Screen.devicePixelRatio : 1)
    }

    Connections {
        target: seat
        onCursorSurfaceRequest: {
            cursorItem.surface = surface;
            cursorItem.hotspotX = hotspotX;
            cursorItem.hotspotY = hotspotY;
        }
    }

    WaylandQuickItem {
        id: dragIcon
        property point offset
        inputEventsEnabled: false

        x: cursorItem.hotspotX + offset.x
        y: cursorItem.hotspotY + offset.y
        z: -1
        surface: cursorItem.seat ? cursorItem.seat.drag.icon : null

        Connections {
            target: dragIcon.surface
            onOffsetForNextFrame: dragIcon.offset = offset;
        }
    }
}