aboutsummaryrefslogtreecommitdiff
path: root/users/ryan/modules/simple-bar/simple-bar-source/lib/components/yabai/spaces.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'users/ryan/modules/simple-bar/simple-bar-source/lib/components/yabai/spaces.jsx')
-rwxr-xr-xusers/ryan/modules/simple-bar/simple-bar-source/lib/components/yabai/spaces.jsx109
1 files changed, 109 insertions, 0 deletions
diff --git a/users/ryan/modules/simple-bar/simple-bar-source/lib/components/yabai/spaces.jsx b/users/ryan/modules/simple-bar/simple-bar-source/lib/components/yabai/spaces.jsx
new file mode 100755
index 0000000..e3a69d0
--- /dev/null
+++ b/users/ryan/modules/simple-bar/simple-bar-source/lib/components/yabai/spaces.jsx
@@ -0,0 +1,109 @@
1import * as Uebersicht from "uebersicht";
2import Space from "./space.jsx";
3import Stickies from "./stickies.jsx";
4import * as Icons from "../icons/icons.jsx";
5import { SuspenseIcon } from "../icons/icon.jsx";
6import { useYabaiContext } from "../yabai-context.jsx";
7import { useSimpleBarContext } from "../simple-bar-context.jsx";
8import * as Utils from "../../utils";
9import * as Yabai from "../../yabai";
10
11export { spacesStyles as styles } from "../../styles/components/spaces/spaces";
12
13const { React } = Uebersicht;
14
15/**
16 * Spaces component to display spaces and manage space-related actions.
17 * @returns {JSX.Element|null} The rendered component.
18 */
19const Component = React.memo(() => {
20 // Get spaces and windows data from Yabai context
21 const { spaces, windows } = useYabaiContext();
22 // Get various settings and display information from simple-bar context
23 const { SIPDisabled, displayIndex, displays, settings } =
24 useSimpleBarContext();
25 const { spacesDisplay, process } = settings;
26 const {
27 displayStickyWindowsSeparately,
28 spacesExclusions,
29 exclusionsAsRegex,
30 hideCreateSpaceButton,
31 showOnDisplay,
32 } = spacesDisplay;
33 // Determine if the component should be visible on the current display
34 const visible = Utils.isVisibleOnDisplay(displayIndex, showOnDisplay);
35 const isProcessVisible = Utils.isVisibleOnDisplay(
36 displayIndex,
37 process.showOnDisplay,
38 );
39
40 if (!visible) return null;
41
42 if (!spaces && !windows) {
43 return <div className="spaces spaces--empty" />;
44 }
45
46 // Find the current space index
47 const { index: currentSpaceIndex } =
48 spaces.find((space) => {
49 const { "has-focus": hasFocus, focused: __legacyHasFocus } = space;
50 return hasFocus ?? __legacyHasFocus;
51 }) || {};
52
53 return displays.map((display, i) => {
54 if (display.index !== displayIndex) return null;
55
56 /**
57 * Handle click event to create a new space.
58 * @param {Event} e - The click event.
59 */
60 const onClick = async (e) => {
61 Utils.clickEffect(e);
62 await Yabai.createSpace(displayIndex);
63 };
64
65 return (
66 <div key={i} className="spaces">
67 {displayStickyWindowsSeparately && <Stickies display={display} />}
68 {spaces.map((space, i) => {
69 const { label, index } = space;
70 const lastOfSpace =
71 i !== 0 && space.display !== spaces[i - 1].display;
72
73 const key = label?.length ? label : index;
74 const spacesExclusionsList = spacesExclusions.replace(/ /g, "").split(",");
75 const isExcluded = Utils.isSpaceExcluded(
76 key,
77 spacesExclusionsList,
78 exclusionsAsRegex,
79 );
80
81 if (isExcluded) return null;
82
83 return (
84 <Space
85 key={key}
86 display={display}
87 space={space}
88 currentSpaceIndex={currentSpaceIndex}
89 lastOfSpace={lastOfSpace}
90 />
91 );
92 })}
93 {SIPDisabled && !hideCreateSpaceButton ? (
94 <button className="spaces__add" onClick={onClick}>
95 <SuspenseIcon>
96 <Icons.Add />
97 </SuspenseIcon>
98 </button>
99 ) : (
100 isProcessVisible && <div className="spaces__end-separator" />
101 )}
102 </div>
103 );
104 });
105});
106
107Component.displayName = "Spaces";
108
109export default Component;