Skip to content

Commit

Permalink
Misc cleanup & refacto (add more clarity in code)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Tinland committed Dec 29, 2023
1 parent 31fd732 commit a904651
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions lib/components/error.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const message = {
noData: "JSON error...",
};

export const Component = ({ type, classes }) => {
export function Component({ type, classes }) {
const errorClasses = Utils.classNames("simple-bar--empty", classes, {
"simple-bar--loading": type === "noOutput",
});
Expand All @@ -27,4 +27,4 @@ export const Component = ({ type, classes }) => {
<Settings.Wrapper />
</div>
);
};
}
27 changes: 10 additions & 17 deletions lib/components/spaces/stickies.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import * as Uebersicht from "uebersicht";
import OpenedApps from "./opened-apps.jsx";
import { useYabaiContext } from "../yabai-context.jsx";
import { useSimpleBarContext } from "../simple-bar-context.jsx";
import * as Utils from "../../utils";

const { React } = Uebersicht;

export default function Stickies({ display }) {
const { windows } = useYabaiContext();
const { settings } = useSimpleBarContext();
Expand All @@ -28,22 +25,18 @@ export default function Stickies({ display }) {
exclusionsAsRegex,
});

if (
!apps.filter((app) => {
const { "is-minimized": isMinimized, minimized: __legacyIsMinimized } =
app;
return !(isMinimized || __legacyIsMinimized);
})?.length
)
return null;
const notMinimizedStikies = apps.filter((app) => {
const { "is-minimized": isMinimized, minimized: __legacyIsMinimized } = app;
return !(isMinimized || __legacyIsMinimized);
});

if (!notMinimizedStikies?.length) return null;

return (
<React.Fragment>
<div className="stickies">
<button className="stickies__inner">
<OpenedApps apps={apps} />
</button>
<div className="stickies">
<div className="stickies__inner">
<OpenedApps apps={apps} />
</div>
</React.Fragment>
</div>
);
}
36 changes: 22 additions & 14 deletions lib/components/spaces/window.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as Yabai from "../../yabai";

const { React } = Uebersicht;

const Window = ({ window }) => {
export default function Window({ window }) {
const { settings } = useSimpleBarContext();
const ref = React.useRef();
const {
Expand All @@ -26,26 +26,36 @@ const Window = ({ window }) => {
title,
id,
} = window;

const isFocused = hasFocus ?? __legacyHasFocus;

if (
(isMinimized ?? __legacyIsMinimized) ||
(displayOnlyCurrent && !(hasFocus ?? __legacyHasFocus))
)
(displayOnlyCurrent && !isFocused)
) {
return null;
const isFocused = hasFocus ?? __legacyHasFocus;
}

const Icon = AppIcons.apps[appName] || AppIcons.apps.Default;

const classes = Utils.classNames("process__window", {
"process__window--focused": !displayOnlyCurrent && isFocused,
"process__window--only-current": displayOnlyCurrent,
"process__window--only-icon": displayOnlyIcon,
});
const onClick = (e) => {
!displayOnlyCurrent && Utils.clickEffect(e);
Yabai.focusWindow(id);
};
const onMouseEnter = () =>

const onMouseEnter = () => {
Utils.startSliding(ref.current, ".process__inner", ".process__name");
const onMouseLeave = () => Utils.stopSliding(ref.current, ".process__name");
};

const onMouseLeave = () => {
Utils.stopSliding(ref.current, ".process__name");
};

const classes = Utils.classNames("process__window", {
"process__window--focused": !displayOnlyCurrent && isFocused,
"process__window--only-current": displayOnlyCurrent,
"process__window--only-icon": displayOnlyIcon,
});

const cleanedUpName =
appName !== title && title.length ? `${appName} / ${title}` : appName;
Expand Down Expand Up @@ -75,6 +85,4 @@ const Window = ({ window }) => {
)}
</button>
);
};

export default Window;
}

0 comments on commit a904651

Please sign in to comment.