summaryrefslogtreecommitdiff
path: root/modules/drawers/Interactions.qml
blob: 884d36c844d0168f2f4211700d3a4b6cd9473c91 (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
48
49
50
51
52
53
54
55
56
import "root:/services"
import "root:/config"
import "root:/modules/osd" as Osd
import Quickshell
import QtQuick

MouseArea {
    id: root

    required property ShellScreen screen
    required property PersistentProperties visibilities

    property bool osdHovered
    property point dragStart

    function withinPanelHeight(panel: Item, x: real, y: real): bool {
        return y >= panel.y && y <= panel.y + panel.height;
    }

    function inRightPanel(panel: Item, x: real, y: real): bool {
        return x > panel.x && withinPanelHeight(panel, x, y);
    }

    anchors.fill: parent
    hoverEnabled: true

    onPressed: event => dragStart = Qt.point(event.x, event.y)

    Connections {
        target: Hyprland

        function onCursorPosChanged(): void {
            const {x, y} = Hyprland.cursorPos;

            // Show osd on hover
            const showOsd = root.inRightPanel(panels.osd, x, y);
            root.visibilities.osd = showOsd;
            root.osdHovered = showOsd;

            // Show/hide session on drag
            if (root.pressed && root.withinPanelHeight(panels.session, x, y)) {
                const dragX = x - root.dragStart.x;
                if (dragX < -SessionConfig.dragThreshold)
                    root.visibilities.session = true;
                else if (dragX > SessionConfig.dragThreshold)
                    root.visibilities.session = false;
            }
        }
    }

    Osd.Interactions {
        screen: root.screen
        visibilities: root.visibilities
        hovered: root.osdHovered
    }
}