summaryrefslogtreecommitdiff
path: root/raveos-theme/hyprland/theme-data/DankMaterialShell/quickshell/Modules/AppDrawer/AppDrawerPopout.qml
blob: ba07d3745f19d6d47ecbb8cc4c665bb15debc6fe (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import QtQuick
import qs.Common
import qs.Modals.DankLauncherV2
import qs.Widgets

DankPopout {
    id: appDrawerPopout

    layerNamespace: "dms:app-launcher"

    readonly property real screenWidth: screen?.width ?? 1920
    readonly property real screenHeight: screen?.height ?? 1080

    property string _pendingMode: ""
    property string _pendingQuery: ""

    function show() {
        open();
    }

    function openWithMode(mode) {
        _pendingMode = mode || "";
        open();
    }

    function toggleWithMode(mode) {
        if (shouldBeVisible) {
            close();
            return;
        }
        openWithMode(mode);
    }

    function openWithQuery(query) {
        _pendingQuery = query || "";
        open();
    }

    function toggleWithQuery(query) {
        if (shouldBeVisible) {
            close();
            return;
        }
        openWithQuery(query);
    }

    readonly property int _baseWidth: {
        switch (SettingsData.dankLauncherV2Size) {
        case "micro":
            return 500;
        case "medium":
            return 720;
        case "large":
            return 860;
        default:
            return 620;
        }
    }

    readonly property int _baseHeight: {
        switch (SettingsData.dankLauncherV2Size) {
        case "micro":
            return 480;
        case "medium":
            return 720;
        case "large":
            return 860;
        default:
            return 600;
        }
    }

    popupWidth: Math.min(_baseWidth, screenWidth - 100)
    popupHeight: Math.min(_baseHeight, screenHeight - 100)

    triggerWidth: 40
    positioning: ""
    contentHandlesKeys: contentLoader.item?.launcherContent?.editMode ?? false

    onBackgroundClicked: {
        if (contentLoader.item?.launcherContent?.editMode) {
            contentLoader.item.launcherContent.closeEditMode();
            return;
        }
        close();
    }

    onOpened: {
        var lc = contentLoader.item?.launcherContent;
        if (!lc)
            return;

        const query = _pendingQuery || (SettingsData.rememberLastQuery ? SessionData.launcherLastQuery : "") || "";
        const mode = _pendingMode || SessionData.appDrawerLastMode || "apps";
        _pendingMode = "";
        _pendingQuery = "";

        if (lc.searchField) {
            lc.searchField.text = query;
            lc.searchField.forceActiveFocus();
        }
        if (lc.controller) {
            lc.controller.searchMode = mode;
            lc.controller.pluginFilter = "";
            lc.controller.searchQuery = query;

            lc.controller.performSearch();
        }
        lc.resetScroll?.();
        lc.actionPanel?.hide();
    }

    Connections {
        target: contentLoader.item?.launcherContent?.controller ?? null
        function onModeChanged(mode) {
            if (contentLoader.item.launcherContent.controller.autoSwitchedToFiles)
                return;
            SessionData.setAppDrawerLastMode(mode);
        }
    }

    content: Component {
        Rectangle {
            id: contentContainer

            LayoutMirroring.enabled: I18n.isRtl
            LayoutMirroring.childrenInherit: true

            property alias launcherContent: launcherContent

            color: "transparent"

            QtObject {
                id: modalAdapter
                property bool spotlightOpen: appDrawerPopout.shouldBeVisible
                readonly property bool isClosing: !appDrawerPopout.shouldBeVisible

                function hide() {
                    appDrawerPopout.close();
                }
            }

            FocusScope {
                anchors.fill: parent
                focus: true

                LauncherContent {
                    id: launcherContent
                    anchors.fill: parent
                    parentModal: modalAdapter
                    viewModeContext: "appDrawer"
                }

                Keys.onEscapePressed: event => {
                    if (launcherContent.editMode) {
                        launcherContent.closeEditMode();
                        event.accepted = true;
                        return;
                    }
                    appDrawerPopout.close();
                    event.accepted = true;
                }
            }
        }
    }
}