Repository navigation
Expand file tree
/
Copy pathBlipWindow.qml
More file actions
268 lines (261 loc) · 11.4 KB
/
Copy pathBlipWindow.qml
File metadata and controls
268 lines (261 loc) · 11.4 KB
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
import QtQuick
import Quickshell
import Quickshell.Io
import Quickshell.Hyprland
import qs.Commons
import qs.Commons as Commons
// Blip window — the "actual app": a Messages.app-style two-pane window.
//
// Hosted INSIDE the Omarchy shell (like the dev-gallery's FloatingWindow), so
// it shares the bar widget's poller, push watcher, and read-state ledger —
// no daemon, no second collector. `hostWidget` is injected by BarWidget.
//
// The content is the SAME BlipView the bar popout renders, in splitView:
// sidebar + conversation side by side, with every feature the popout has
// (tapbacks, receipts, inline photos, replies, search, composer,
// attachments). No PanelKeyCatcher here — a normal window keeps normal
// editor/Tab behavior; Esc unwinds the view (thread → list, search → list)
// and closes the window only when there is nothing left to unwind. Up/Down
// and Enter walk the thread list while no editor has focus.
FloatingWindow {
id: win
property var hostWidget: null
// "Blip (3)" while unread exists — selectors match the "Blip" PREFIX.
property string restorationTitle: ""
title: restorationTitle || "Blip" + (hostWidget && hostWidget.unread > 0 ? " (" + hostWidget.unread + ")" : "")
// Same fill as Omarchy's other FloatingWindow (dev gallery). A 0.70
// alpha assumed Hyprland blur, which Omarchy 4.x ships off.
color: hostWidget && hostWidget.appearance ? hostWidget.appearance.background : Commons.Color.background
implicitWidth: 1040
implicitHeight: 720
minimumSize: Qt.size(720, 480)
visible: false
// Focused = Hyprland's active toplevel is this window (title prefix "Blip").
// A visible-but-unfocused window keeps refreshing but does not mark read.
// Exact title, not a prefix: a terminal or tab titled "Blip documentation"
// used to count as this window being read (Astra A#6). The title is ours
// ("Blip" or "Blip (N)"), so equality identifies it.
readonly property bool focused: visible && Hyprland.activeToplevel !== null
&& String(Hyprland.activeToplevel.title || "") === win.title
// Proxies BarWidget relies on (same names as the popout host).
readonly property bool inThread: view.inThread
readonly property var active: view.active
readonly property bool loading: view.loading
readonly property bool rendered: view.rendered
readonly property string seenTs: view.seenTs
readonly property bool peeking: view.peeking
readonly property string activeLastTs: view.activeLastTs
function openThread(t) { view.openThread(t) }
function shareLink(url) { return view.shareLink(url) }
function pushReload() { view.pushReload() }
function navText(event) {
if (event.key === Qt.Key_Slash) return "/"
if (event.key === Qt.Key_N) return "n"
var typed = event.text
if (typed && typed.length > 0) return typed
if (event.modifiers & (Qt.ShiftModifier | Qt.ControlModifier | Qt.AltModifier | Qt.MetaModifier))
return ""
if (event.key >= Qt.Key_1 && event.key <= Qt.Key_9) return String.fromCharCode(event.key)
return typed
}
// ---- persistence: the window lives inside the shell process, so every
// omarchy-restart-shell (every plugin deploy/update) would kill it. Remember
// "was open", size and workspace in window.json; restore quietly on start.
// Idle/DPMS remaps as a new client on the focused workspace — that is not a
// new home. Only a user move updates savedWorkspace; a remap is sent back.
readonly property string stateDir: Quickshell.env("HOME") + "/.local/state/blip"
readonly property string restoreScript: Qt.resolvedUrl("window-restore.ts").toString().replace(/^file:\/\//, "")
property bool restoring: true
property bool restoreReady: false
property bool explicitShow: false
property string savedWorkspace: ""
// Match this shell process and this exact window, never another app's title.
readonly property var ownToplevel: Hyprland.toplevels.values.find(function(t) {
return Number(t.lastIpcObject.pid) === Quickshell.processId && t.title === win.title
}) || null
readonly property string currentWorkspace: ownToplevel && ownToplevel.workspace
? String(ownToplevel.workspace.name) : ""
function ourAddress() {
return ownToplevel && ownToplevel.lastIpcObject ? String(ownToplevel.lastIpcObject.address || "") : ""
}
function sameAddress(a, b) {
// Raw Hyprland IPC events give bare hex ("5b5a..."); lastIpcObject.address
// is 0x-prefixed. Strip both before comparing or a real user move is
// never recognized and gets reverted by strayReturn as a stray remap.
function norm(x) { return String(x).toLowerCase().replace(/^0x/, "") }
return !!a && !!b && norm(a) === norm(b)
}
function eventParts(event, count) {
try { if (event && event.parse) return event.parse(count) } catch (e) { }
return String(event && event.data ? event.data : "").split(",")
}
// Keep in lockstep with workspaceDecision() in window-restore.ts.
function workspaceDecision(incoming, reason) {
if (!incoming) return "ignore"
// Lockstep with window-restore.ts: only a deliberate move claims a home.
if (savedWorkspace === "") return reason === "move" ? "save" : "ignore"
if (incoming === savedWorkspace) return "ignore"
if (reason === "move") return "save"
if (reason === "map" || reason === "monitor") return "return"
return "ignore"
}
function runRestore() {
var args = ["bun", restoreScript]
for (var i = 0; i < arguments.length; i++) args.push(String(arguments[i]))
Quickshell.execDetached(args)
}
// With every output gone Hyprland 0.56 segfaults moving a floating window,
// so a stray waits for monitoradded (window-restore.ts moveIsSafe()).
function hasRealScreen() {
for (var i = 0; i < Quickshell.screens.length; i++) {
var s = Quickshell.screens[i]
if (s && s.name && s.width > 0 && s.height > 0) return true
}
return false
}
function applyWorkspaceDecision(incoming, reason, addr) {
if (restoring) return
var decision = workspaceDecision(incoming, reason)
if (decision === "save") {
savedWorkspace = incoming
saveWinState()
if (savedWorkspace !== "") runRestore("home", savedWorkspace)
} else if (decision === "return" && savedWorkspace !== "" && hasRealScreen()) {
runRestore("return", savedWorkspace, addr || ourAddress())
}
}
Connections {
target: Hyprland
function onRawEvent(event) {
var name = event.name
// New toplevels initially have no IPC metadata (including their PID).
if (name === "openwindow" || name === "movewindowv2" || name === "monitoradded" || name === "monitorremoved")
Hyprland.refreshToplevels()
if (name === "openwindow") {
var open = win.eventParts(event, 4)
var title = String(open[3] || "")
if (String(open[2] || "") === "org.quickshell" && /^Blip( \([0-9]+\))?$/.test(title))
win.applyWorkspaceDecision(String(open[1] || ""), "map", String(open[0] || ""))
} else if (name === "movewindowv2") {
var moved = win.eventParts(event, 3)
if (win.sameAddress(moved[0], win.ourAddress()))
win.applyWorkspaceDecision(String(moved[2] || ""), "move", String(moved[0] || ""))
} else if (name === "monitoradded" || name === "monitorremoved") {
Qt.callLater(function() {
if (win.currentWorkspace !== "") win.applyWorkspaceDecision(win.currentWorkspace, "monitor", win.ourAddress())
})
}
}
}
onCurrentWorkspaceChanged: {
if (restoring || currentWorkspace === "") return
if (savedWorkspace === "") applyWorkspaceDecision(currentWorkspace, "map", ourAddress())
else if (currentWorkspace !== savedWorkspace) strayReturn.restart()
}
Timer {
id: strayReturn
interval: 400
repeat: false
onTriggered: {
if (win.restoring || win.currentWorkspace === "" || win.currentWorkspace === win.savedWorkspace) return
win.applyWorkspaceDecision(win.currentWorkspace, "map", win.ourAddress())
}
}
onOwnToplevelChanged: {
if (ownToplevel && restorationTitle !== "") Qt.callLater(function() { restorationTitle = "" })
}
function requestShow() {
explicitShow = true
if (restoreReady) visible = true
}
Process {
id: prepareRestore
command: ["bun", win.restoreScript, "prepare", win.savedWorkspace]
stdout: StdioCollector {
onStreamFinished: {
try { win.restorationTitle = JSON.parse(text).title || "" } catch (e) { }
}
}
onExited: (code, status) => {
win.restoreReady = true
win.restoring = false
// Failure leaves the window closed rather than stealing the workspace.
// An explicit launch can still open it normally.
if (code === 0 || win.explicitShow) win.visible = true
if (win.hostWidget && win.visible) win.hostWidget.refresh(true, false)
}
}
FileView {
id: winState
path: win.stateDir + "/window.json"
blockLoading: true
printErrors: false
}
function saveWinState() {
if (restoring) return
var j = JSON.stringify({ visible: visible, width: Math.round(width), height: Math.round(height), workspace: savedWorkspace })
// detached: a Process object drops writes while a previous one is alive,
// and hideWindow() destroying this window mid-write lost the "hidden" state
Quickshell.execDetached(["sh", "-c",
"umask 077 && mkdir -p \"$1\" && printf '%s' \"$2\" > \"$1/window.json.tmp.$$\" && mv \"$1/window.json.tmp.$$\" \"$1/window.json\"",
"blip", stateDir, j])
}
Component.onCompleted: {
try {
var d = JSON.parse(winState.text())
if (d && d.width >= 720 && d.height >= 480) { implicitWidth = d.width; implicitHeight = d.height }
if (d && typeof d.workspace === "string") savedWorkspace = d.workspace
if (d && d.visible === true) { prepareRestore.running = true; return }
} catch (e) { /* first run */ }
Qt.callLater(function() { win.restoring = false; win.restoreReady = true; if (win.explicitShow) win.visible = true })
}
onVisibleChanged: { saveWinState(); if (visible) Qt.callLater(view.focusDefault) }
onWidthChanged: if (visible) saveWinState()
onHeightChanged: if (visible) saveWinState()
FocusScope {
id: scope
anchors.fill: parent
focus: true
Keys.priority: Keys.AfterItem
Keys.onPressed: function(event) {
if (event.key === Qt.Key_Escape) {
if (!view.unwind()) win.visible = false
event.accepted = true
return
}
if (view.catchNavText(win.navText(event))) event.accepted = true
}
Item {
id: navCatcher
anchors.fill: parent
focus: true
Keys.priority: Keys.BeforeItem
Keys.onPressed: function(event) {
if (event.key === Qt.Key_Escape && view.catchEscape()) {
event.accepted = true
return
}
if (view.catchNavKey(event.key)) {
event.accepted = true
return
}
if (view.catchNavText(win.navText(event))) event.accepted = true
}
BlipView {
id: view
anchors.fill: parent
// Inset from the window edge: Hyprland rounds the corners, and text
// flush to the border got clipped by the radius (Fred).
anchors.margins: Style.space(12)
hostWidget: win.hostWidget
splitView: true
surfaceOpen: win.visible
readActive: win.focused
foreground: Commons.Color.foreground
urgent: Commons.Color.urgent
themeFont: Style.font.family
onNavigationFocusRequested: navCatcher.forceActiveFocus()
}
}
}
}