aboutsummaryrefslogtreecommitdiff
path: root/users/ryan/modules/simple-bar/simple-bar-source/lib/components/aerospace/space.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'users/ryan/modules/simple-bar/simple-bar-source/lib/components/aerospace/space.jsx')
-rwxr-xr-xusers/ryan/modules/simple-bar/simple-bar-source/lib/components/aerospace/space.jsx84
1 files changed, 84 insertions, 0 deletions
diff --git a/users/ryan/modules/simple-bar/simple-bar-source/lib/components/aerospace/space.jsx b/users/ryan/modules/simple-bar/simple-bar-source/lib/components/aerospace/space.jsx
new file mode 100755
index 0000000..ab91bbb
--- /dev/null
+++ b/users/ryan/modules/simple-bar/simple-bar-source/lib/components/aerospace/space.jsx
@@ -0,0 +1,84 @@
1import * as Uebersicht from "uebersicht";
2import OpenedApps from "./opened-apps.jsx";
3import { useSimpleBarContext } from "../simple-bar-context.jsx";
4import * as Utils from "../../utils.js";
5import * as Aerospace from "../../aerospace.js";
6
7const { React } = Uebersicht;
8
9/**
10 * Space component to display a single space.
11 * @param {Object} props - The component props.
12 * @param {Object} props.space - The space object.
13 * @param {boolean} props.lastOfSpace - Indicates if this is the last space of the monitor.
14 * @returns {JSX.Element|null} The rendered component.
15 */
16export default function Space({ space, lastOfSpace }) {
17 const { windows } = space;
18 const { settings } = useSimpleBarContext();
19 const { spacesDisplay } = settings;
20 const {
21 displayAllSpacesOnAllScreens,
22 exclusionsAsRegex,
23 hideDuplicateAppsInSpaces,
24 } = spacesDisplay;
25 const { workspace, focused } = space;
26
27 /**
28 * Handle click event to switch to the clicked space.
29 * @param {Event} e - The click event.
30 */
31 const onClick = (e) => {
32 if (focused) return;
33 Aerospace.goToSpace(workspace);
34 Utils.clickEffect(e);
35 };
36
37 // Determine if the space should be hidden
38 const hidden = !focused && !windows.length && spacesDisplay.hideEmptySpaces;
39
40 if (hidden) return null;
41
42 // Get exclusions and title exclusions based on settings
43 const exclusions = exclusionsAsRegex
44 ? spacesDisplay.exclusions
45 : spacesDisplay.exclusions.split(", ");
46 const titleExclusions = exclusionsAsRegex
47 ? spacesDisplay.titleExclusions
48 : spacesDisplay.titleExclusions.split(", ");
49
50 // Filter windows based on exclusions
51 const filteredWindows = windows.filter((window) =>
52 Utils.filterApps(window, exclusions, titleExclusions, exclusionsAsRegex),
53 );
54
55 // Remove duplicate apps if the setting is enabled
56 const displayedWindows = hideDuplicateAppsInSpaces
57 ? filteredWindows.reduce((acc, window) => {
58 const isDuplicate = acc.find(
59 (w) => w["app-name"] === window["app-name"],
60 );
61 return isDuplicate ? acc : [...acc, window];
62 }, [])
63 : filteredWindows;
64
65 // Determine the CSS classes for the space
66 const classes = Utils.classNames("space", {
67 "space--focused": focused,
68 "space--empty": windows.length,
69 });
70
71 return (
72 <React.Fragment>
73 {displayAllSpacesOnAllScreens && lastOfSpace && (
74 <div className="spaces__separator" />
75 )}
76 <div className={classes}>
77 <button className="space__inner" onClick={onClick}>
78 {workspace}
79 <OpenedApps apps={displayedWindows} />
80 </button>
81 </div>
82 </React.Fragment>
83 );
84}