summaryrefslogtreecommitdiff
path: root/raveos-hyprland-theme/theme-data/dms/Modules/Settings/DisplayConfig/NiriOutputSettings.qml
blob: da9a4a71c3a7e1d717d09ac57c1dc4403fe0523b (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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
import QtQuick
import qs.Common
import qs.Widgets

Column {
    id: root

    property string outputName: ""
    property var outputData: null
    property bool expanded: false

    width: parent.width
    spacing: 0

    Rectangle {
        width: parent.width
        height: headerRow.implicitHeight + Theme.spacingS * 2
        color: headerMouse.containsMouse ? Theme.withAlpha(Theme.primary, 0.1) : "transparent"
        radius: Theme.cornerRadius / 2

        Row {
            id: headerRow
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.verticalCenter: parent.verticalCenter
            anchors.leftMargin: Theme.spacingS
            anchors.rightMargin: Theme.spacingS
            spacing: Theme.spacingS

            DankIcon {
                name: root.expanded ? "expand_more" : "chevron_right"
                size: Theme.iconSize
                color: Theme.primary
                anchors.verticalCenter: parent.verticalCenter
            }

            StyledText {
                text: I18n.tr("Compositor Settings")
                font.pixelSize: Theme.fontSizeMedium
                font.weight: Font.Medium
                color: Theme.primary
                anchors.verticalCenter: parent.verticalCenter
            }
        }

        MouseArea {
            id: headerMouse
            anchors.fill: parent
            hoverEnabled: true
            cursorShape: Qt.PointingHandCursor
            onClicked: root.expanded = !root.expanded
        }
    }

    Column {
        width: parent.width
        spacing: Theme.spacingS
        visible: root.expanded
        topPadding: Theme.spacingS

        DankToggle {
            width: parent.width
            text: I18n.tr("Disable Output")
            checked: DisplayConfigState.getNiriSetting(root.outputData, root.outputName, "disabled", false)
            onToggled: checked => DisplayConfigState.setNiriSetting(root.outputData, root.outputName, "disabled", checked)
        }

        DankToggle {
            width: parent.width
            text: I18n.tr("Focus at Startup")
            checked: DisplayConfigState.getNiriSetting(root.outputData, root.outputName, "focusAtStartup", false)
            onToggled: checked => DisplayConfigState.setNiriSetting(root.outputData, root.outputName, "focusAtStartup", checked)
        }

        DankDropdown {
            width: parent.width
            text: I18n.tr("Hot Corners")
            addHorizontalPadding: true

            property var hotCornersData: {
                void (DisplayConfigState.pendingNiriChanges);
                return DisplayConfigState.getNiriSetting(root.outputData, root.outputName, "hotCorners", null);
            }

            currentValue: {
                if (!hotCornersData)
                    return I18n.tr("Inherit");
                if (hotCornersData.off)
                    return I18n.tr("Off");
                const corners = hotCornersData.corners || [];
                if (corners.length === 0)
                    return I18n.tr("Inherit");
                if (corners.length === 4)
                    return I18n.tr("All");
                return I18n.tr("Select...");
            }
            options: [I18n.tr("Inherit"), I18n.tr("Off"), I18n.tr("All"), I18n.tr("Select...")]

            onValueChanged: value => {
                switch (value) {
                case I18n.tr("Inherit"):
                    DisplayConfigState.setNiriSetting(root.outputData, root.outputName, "hotCorners", null);
                    break;
                case I18n.tr("Off"):
                    DisplayConfigState.setNiriSetting(root.outputData, root.outputName, "hotCorners", {
                        "off": true
                    });
                    break;
                case I18n.tr("All"):
                    DisplayConfigState.setNiriSetting(root.outputData, root.outputName, "hotCorners", {
                        "corners": ["top-left", "top-right", "bottom-left", "bottom-right"]
                    });
                    break;
                case I18n.tr("Select..."):
                    DisplayConfigState.setNiriSetting(root.outputData, root.outputName, "hotCorners", {
                        "corners": []
                    });
                    break;
                }
            }
        }

        Item {
            width: parent.width
            height: hotCornersGroup.implicitHeight
            clip: true

            property var hotCornersData: {
                void (DisplayConfigState.pendingNiriChanges);
                return DisplayConfigState.getNiriSetting(root.outputData, root.outputName, "hotCorners", null);
            }

            visible: hotCornersData && !hotCornersData.off && hotCornersData.corners !== undefined

            DankButtonGroup {
                id: hotCornersGroup
                anchors.horizontalCenter: parent.horizontalCenter
                selectionMode: "multi"
                checkEnabled: false
                buttonHeight: 32
                buttonPadding: parent.width < 400 ? Theme.spacingXS : Theme.spacingM
                minButtonWidth: parent.width < 400 ? 28 : 56
                textSize: parent.width < 400 ? 11 : Theme.fontSizeMedium
                model: [I18n.tr("Top Left"), I18n.tr("Top Right"), I18n.tr("Bottom Left"), I18n.tr("Bottom Right")]

                property var cornerKeys: ["top-left", "top-right", "bottom-left", "bottom-right"]

                currentSelection: {
                    const hcData = parent.hotCornersData;
                    if (!hcData?.corners)
                        return [];
                    return hcData.corners.map(key => {
                        const idx = cornerKeys.indexOf(key);
                        return idx >= 0 ? model[idx] : null;
                    }).filter(v => v !== null);
                }

                onSelectionChanged: (index, selected) => {
                    const corners = currentSelection.map(label => {
                        const idx = model.indexOf(label);
                        return idx >= 0 ? cornerKeys[idx] : null;
                    }).filter(v => v !== null);
                    DisplayConfigState.setNiriSetting(root.outputData, root.outputName, "hotCorners", {
                        "corners": corners
                    });
                }
            }
        }

        Rectangle {
            width: parent.width
            height: 1
            color: Theme.withAlpha(Theme.outline, 0.15)
        }

        Item {
            width: parent.width
            height: layoutColumn.implicitHeight

            Column {
                id: layoutColumn
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.leftMargin: Theme.spacingM
                anchors.rightMargin: Theme.spacingM
                spacing: Theme.spacingS

                Column {
                    width: parent.width
                    spacing: Theme.spacingXS

                    StyledText {
                        text: I18n.tr("Layout Overrides")
                        font.pixelSize: Theme.fontSizeSmall
                        font.weight: Font.Medium
                        color: Theme.surfaceVariantText
                    }

                    StyledText {
                        text: I18n.tr("Override global layout settings for this output")
                        font.pixelSize: Theme.fontSizeSmall
                        color: Theme.withAlpha(Theme.surfaceVariantText, 0.7)
                        wrapMode: Text.WordWrap
                        width: parent.width
                    }
                }

                Row {
                    width: parent.width
                    spacing: Theme.spacingM

                    Column {
                        width: (parent.width - Theme.spacingM) / 2
                        spacing: Theme.spacingXS

                        StyledText {
                            text: I18n.tr("Window Gaps (px)")
                            font.pixelSize: Theme.fontSizeSmall
                            color: Theme.surfaceVariantText
                        }

                        DankTextField {
                            width: parent.width
                            height: 40
                            placeholderText: I18n.tr("Inherit")
                            text: {
                                const layout = DisplayConfigState.getNiriSetting(root.outputData, root.outputName, "layout", null);
                                if (layout?.gaps === undefined)
                                    return "";
                                return layout.gaps.toString();
                            }
                            onEditingFinished: {
                                const layout = DisplayConfigState.getNiriSetting(root.outputData, root.outputName, "layout", {}) || {};
                                const trimmed = text.trim();
                                if (!trimmed) {
                                    delete layout.gaps;
                                    DisplayConfigState.setNiriSetting(root.outputData, root.outputName, "layout", Object.keys(layout).length > 0 ? layout : null);
                                    return;
                                }
                                const val = parseInt(trimmed);
                                if (isNaN(val) || val < 0)
                                    return;
                                layout.gaps = val;
                                DisplayConfigState.setNiriSetting(root.outputData, root.outputName, "layout", layout);
                            }
                        }
                    }

                    Column {
                        width: (parent.width - Theme.spacingM) / 2
                        spacing: Theme.spacingXS

                        StyledText {
                            text: I18n.tr("Default Width (%)")
                            font.pixelSize: Theme.fontSizeSmall
                            color: Theme.surfaceVariantText
                        }

                        DankTextField {
                            width: parent.width
                            height: 40
                            placeholderText: I18n.tr("Inherit")
                            text: {
                                const layout = DisplayConfigState.getNiriSetting(root.outputData, root.outputName, "layout", null);
                                if (!layout?.defaultColumnWidth)
                                    return "";
                                if (layout.defaultColumnWidth.type !== "proportion")
                                    return "";
                                const percent = layout.defaultColumnWidth.value * 100;
                                return parseFloat(percent.toFixed(4)).toString();
                            }
                            onEditingFinished: {
                                const layout = DisplayConfigState.getNiriSetting(root.outputData, root.outputName, "layout", {}) || {};
                                const trimmed = text.trim().replace("%", "");
                                if (!trimmed) {
                                    delete layout.defaultColumnWidth;
                                    DisplayConfigState.setNiriSetting(root.outputData, root.outputName, "layout", Object.keys(layout).length > 0 ? layout : null);
                                    return;
                                }
                                const val = parseFloat(trimmed);
                                if (isNaN(val) || val <= 0 || val > 100)
                                    return;
                                layout.defaultColumnWidth = {
                                    "type": "proportion",
                                    "value": parseFloat((val / 100).toFixed(6))
                                };
                                DisplayConfigState.setNiriSetting(root.outputData, root.outputName, "layout", layout);
                            }
                        }
                    }
                }

                Column {
                    width: parent.width
                    spacing: Theme.spacingXS

                    StyledText {
                        text: I18n.tr("Preset Widths (%)")
                        font.pixelSize: Theme.fontSizeSmall
                        color: Theme.surfaceVariantText
                    }

                    StyledText {
                        text: "e.g. 33.33, 50, 66.67"
                        font.pixelSize: Theme.fontSizeSmall
                        color: Theme.withAlpha(Theme.surfaceVariantText, 0.7)
                    }

                    DankTextField {
                        width: parent.width
                        height: 40
                        placeholderText: I18n.tr("Inherit")
                        text: {
                            const layout = DisplayConfigState.getNiriSetting(root.outputData, root.outputName, "layout", null);
                            const presets = layout?.presetColumnWidths || [];
                            if (presets.length === 0)
                                return "";
                            return presets.filter(p => p.type === "proportion").map(p => parseFloat((p.value * 100).toFixed(4))).join(", ");
                        }
                        onEditingFinished: {
                            const layout = DisplayConfigState.getNiriSetting(root.outputData, root.outputName, "layout", {}) || {};
                            const trimmed = text.trim();
                            if (!trimmed) {
                                delete layout.presetColumnWidths;
                                DisplayConfigState.setNiriSetting(root.outputData, root.outputName, "layout", Object.keys(layout).length > 0 ? layout : null);
                                return;
                            }
                            const parts = trimmed.split(/[,\s]+/).filter(s => s);
                            const presets = [];
                            for (const part of parts) {
                                const val = parseFloat(part.replace("%", ""));
                                if (!isNaN(val) && val > 0 && val <= 100)
                                    presets.push({
                                        "type": "proportion",
                                        "value": parseFloat((val / 100).toFixed(6))
                                    });
                            }
                            if (presets.length === 0) {
                                delete layout.presetColumnWidths;
                                DisplayConfigState.setNiriSetting(root.outputData, root.outputName, "layout", Object.keys(layout).length > 0 ? layout : null);
                                return;
                            }
                            presets.sort((a, b) => a.value - b.value);
                            layout.presetColumnWidths = presets;
                            DisplayConfigState.setNiriSetting(root.outputData, root.outputName, "layout", layout);
                        }
                    }
                }
            }
        }

        DankToggle {
            width: parent.width
            text: I18n.tr("Center Single Column")
            property var layoutData: DisplayConfigState.getNiriSetting(root.outputData, root.outputName, "layout", null)
            checked: layoutData?.alwaysCenterSingleColumn ?? false
            onToggled: checked => {
                const layout = DisplayConfigState.getNiriSetting(root.outputData, root.outputName, "layout", {}) || {};
                if (checked) {
                    layout.alwaysCenterSingleColumn = true;
                } else {
                    delete layout.alwaysCenterSingleColumn;
                }
                DisplayConfigState.setNiriSetting(root.outputData, root.outputName, "layout", Object.keys(layout).length > 0 ? layout : null);
            }
        }
    }
}