-
Notifications
You must be signed in to change notification settings - Fork 4
/
bar.jsx
179 lines (158 loc) · 5.7 KB
/
bar.jsx
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
import styles from "./lib/styles.jsx";
import settings from "./lib/settings.jsx";
import parse from "./lib/parse.jsx";
import symbols from "./lib/symbols.jsx";
import Error from "./lib/Error.jsx";
import { applyBarHeight, getAutoBarHeight } from "./lib/autoBarHeight.jsx";
const style = {
backgroundColor: styles.colors.bgTint,
position: "fixed",
...(settings.bar.alignBottom ? {bottom: "0px"} : {top: "0px"}),
left: "0px",
right: "0px",
height : styles.height + "px",
lineHeight: styles.height + "px",
width: "auto",
WebkitBackdropFilter: "blur(20px)",
WebkitUserSelect: "none",
cursor: "default",
fontFamily: styles.fontFamily,
fontWeight: styles.fontWeight,
fontSize: styles.fontSize,
textAlign: "center",
transition: "all 100ms ease-out",
color: styles.colors.fg,
zIndex: 100,
}
const dimmedStyle = {
color: styles.colors.dim,
}
const getWallpaperBlurStyle = (screenWidth, screenHeight, screenUUID) => (settings.backgroundBlurOnWindowOpen ? {
backgroundColor: "#0002",
WebkitBackdropFilter: "blur(8px)",
position: "fixed",
...(settings.bar.alignBottom ? {
bottom: getAutoBarHeight(screenWidth, screenHeight, screenUUID) + "px",
top: "0"
} : {
top: getAutoBarHeight(screenWidth, screenHeight, screenUUID) + "px",
bottom: "0"
}),
left: "0",
right: "0",
zIndex: 99,
transition: "opacity 1s ease-out",
} : {display: "none"});
export const refreshFrequency = false;
export const command = settings.bar.info ? "./clarity/scripts/spaces.sh" : "";
export const render = ({ output }) => {
if (settings.bar.fontSize > settings.bar.height || !settings.bar.info) {
return (
<div style={style}/>
);
}
if (typeof output === "undefined" || !output) {
return (
<div style={style}>Loading...</div>
)
}
const data = parse(output);
if (typeof data === "undefined") {
return (
<div style={style}>
<Error msg="Invalid Status Data!" />
</div>
);
}
if (typeof data.error !== "undefined" || !data.spaces || !data.displays) {
return (
<div style={style}>
<Error msg={data.error} />
</div>
);
}
const numDisplays = data.displays.length;
const displayId = Number(window.location.pathname.split("/")[1]);
const displayData = data.displays.find(d => d.id === displayId) || data.displays[0];
const visibleSpaceData = displayData && data.spaces.filter(s => s.display === displayData.index && s["is-visible"])[0];
const focusedWindowData = data.focusedWindow;
const [dw, dh, duuid] = [displayData.frame.w, displayData.frame.h, displayData.uuid];
if (!displayData || !visibleSpaceData) {
return (
<div style={style}>
<Error msg="No visible space!" />
</div>
);
}
let currentStyle = {...style};
let backgroundStyle = getWallpaperBlurStyle(dw, dh, duuid);
applyBarHeight(displayData.frame.w, displayData.frame.h, displayData.uuid)(currentStyle);
if (!visibleSpaceData["has-focus"]) currentStyle = {...currentStyle, ...dimmedStyle};
if (visibleSpaceData.windows.length == 0) backgroundStyle.opacity = 0;
let outComps = [];
let windowStr = "";
if (focusedWindowData) {
if (settings.bar.info.appName && focusedWindowData.app) {
if (typeof settings.bar.status.appName !== 'number') {
windowStr += focusedWindowData.app;
} else {
windowStr += focusedWindowData.app.substring(0, settings.bar.status.appName);
}
}
if (settings.bar.info.windowTitle && focusedWindowData.title) {
if (windowStr) {
windowStr += " - ";
}
if (typeof settings.bar.status.windowTitle !== 'number') {
windowStr += focusedWindowData.title;
} else {
windowStr += focusedWindowData.title.substring(0, +settings.bar.status.windowTitle);
}
}
}
if (settings.bar.info.display && numDisplays > 1) {
outComps.push(symbols.display + " " + displayData.index);
}
if (settings.bar.info.yabaiMode && visibleSpaceData) {
let type = visibleSpaceData.type;
let modePref = settings.bar.info.yabaiMode;
let iconOnly = modePref === "icon";
let auto = modePref === true;
switch (visibleSpaceData.type) {
case "bsp":
case "float":
case "stack":
if (windowStr && (auto || iconOnly)) {
windowStr = symbols[type] + " " + windowStr;
} else if (iconOnly) {
outComps.push(symbols[type]);
} else {
outComps.push(symbols[type] + " " + type);
}
break;
default:
if (windowStr && (auto || iconOnly)) {
windowStr = symbols.macWindow + " " + windowStr;
} else if (iconOnly) {
outComps.push(symbols.float);
} else {
outComps.push(symbols.float + " " + type);
}
break;
}
}
if (windowStr) {
outComps.push(windowStr);
}
if (settings.bar.info.space && typeof visibleSpaceData?.index !== undefined) {
outComps.push(symbols.space + " " + visibleSpaceData.index)
}
let outStr = outComps.join(" • ");
return (
<div>
<div style={backgroundStyle}></div>
<div style={currentStyle}>{outStr}</div>
</div>
);
};
export default null;