Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/aerospace.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,17 @@ export async function getDisplays() {
export function getDisplayIndex(item) {
const settings = Settings.get();
const { customAeroSpaceDisplayIndexes } = settings.spacesDisplay;
const nativeId = item["monitor-appkit-nsscreen-screens-id"];
const nativeId = item["monitor-id"];
const customId = customAeroSpaceDisplayIndexes[nativeId];
return customId || nativeId;
}

/**
* Retrieves the `NSScreen.screens` index for the specified display.
* @param {Object} display - The display object.
* @returns {number} The custom display index.
*/
export function getScreenIndex(item) {
const nativeId = item["monitor-appkit-nsscreen-screens-id"];
return nativeId;
}
2 changes: 1 addition & 1 deletion lib/components/aerospace-context.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function AerospaceContextProvider({ children }) {
return Promise.all(
result.map(async (space) => {
const focused = space.workspace === focusedSpace.workspace;
const monitor = Aerospace.getDisplayIndex(space);
const monitor = Aerospace.getScreenIndex(space);
const windows = await Aerospace.getWindows(space.workspace);
const formatted = windows.map((window) => {
const focused =
Expand Down
43 changes: 17 additions & 26 deletions lib/components/simple-bar-context.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export default function SimpleBarContextProvider({
const { windowManager, enableServer, yabaiServerRefresh } = settings.global;
const serverEnabled = enableServer && yabaiServerRefresh;
const isYabai = windowManager === "yabai";
const isAeroSpace = windowManager === "aerospace";

const currentDisplays = serverEnabled && isYabai ? _displays : displays;

Expand All @@ -52,34 +51,26 @@ export default function SimpleBarContextProvider({
10
);

// Check if the built-in Retina Display is present in the current displays
const hasBuiltInRetina = currentDisplays?.some(
(d) => d["monitor-name"] === "Built-in Retina Display"
);

// Adjust displayId if the Retina screen is missing when using AeroSpace
// This prevents mismatch between Übersicht and AeroSpace display numbering
// as Übersicht still count closed built in screen in the display count
const adjustedUbersichtDisplayId =
isAeroSpace && !hasBuiltInRetina
? ubersichtDisplayId - 1
: ubersichtDisplayId;
// Find the current display by walking down from ubersichtDisplayId
// until we find a match. This handles phantom displays (closed lid,
// previously connected monitors) that Übersicht still counts but
// AeroSpace doesn't report.
let currentDisplay = {};
let displayIndex = 1;

// Find the current display based on the adjusted display ID
// Use Aerospace's display index if available (check for custom logic)
// Fallback to yabai id otherwise
const currentDisplay =
currentDisplays?.find((d) => {
for (let candidateId = ubersichtDisplayId; candidateId >= 1; candidateId--) {
const display = currentDisplays?.find((d) => {
const id = Aerospace.getDisplayIndex(d) ?? d.id;
return id === adjustedUbersichtDisplayId;
}) || {};
return id === candidateId;
});

// Determine the display index for context value
// currentDisplay.index is from yabai
// Aerospace.getDisplayIndex is from Aerospace with custom logic
// Fallback to Aerospace monitor-id or default to 1
const displayIndex =
(currentDisplay.index ?? Aerospace.getDisplayIndex(currentDisplay)) || 1;
if (display) {
currentDisplay = display;
displayIndex =
display.index ?? Aerospace.getScreenIndex(display) ?? 1;
break;
}
}

const pushMissive = (newMissive) => {
const now = Date.now();
Expand Down