-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Patrick Hund
committed
Feb 8, 2023
1 parent
39185c3
commit 6c0bbd1
Showing
7 changed files
with
105 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export const nickNames = { | ||
"DELL U3419W": "dell", | ||
"Color LCD": "hinkel", | ||
"Sidecar Display": "ipad", | ||
}; | ||
|
||
export const stageManagerMarginWidth = 70; | ||
|
||
export const menuBarHeight = { | ||
normal: 25, | ||
notch: 38, | ||
}; | ||
|
||
export const hinkelScreenDimensions = { | ||
width: 1728, | ||
height: 1117, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import getFocusedScreenInfo from "./getFocusedScreenInfo.mjs"; | ||
import getMenuBarHeight from "./getMenuBarHeight.mjs"; | ||
import { stageManagerMarginWidth } from "./config.mjs"; | ||
import getFocusedWindowInfo from "./getFocusedWindowInfo.mjs"; | ||
|
||
export default async function focusedWindowIsMaximised() { | ||
const { focusedScreenX, focusedScreenY, focusedScreenWidth, focusedScreenHeight } = | ||
await getFocusedScreenInfo(); | ||
const { focusedWindowX, focusedWindowY, focusedWindowWidth, focusedWindowHeight } = | ||
await getFocusedWindowInfo(); | ||
const menuBarHeight = getMenuBarHeight(focusedScreenWidth, focusedScreenHeight); | ||
|
||
const isInUpperLeftCorner = | ||
focusedWindowX === focusedScreenX + stageManagerMarginWidth && | ||
focusedWindowY === focusedScreenY + menuBarHeight; | ||
const isMaximumSize = | ||
focusedWindowWidth === focusedScreenWidth - stageManagerMarginWidth && | ||
focusedWindowHeight === focusedScreenHeight - menuBarHeight; | ||
const isMaximised = isInUpperLeftCorner && isMaximumSize; | ||
|
||
BTTLog(`focusedScreenX: ${focusedScreenX}`); | ||
BTTLog(`focusedScreenY: ${focusedScreenY}`); | ||
BTTLog(`focusedScreenWidth: ${focusedScreenWidth}`); | ||
BTTLog(`focusedScreenHeight: ${focusedScreenHeight}`); | ||
BTTLog(`focusedWindowX: ${focusedWindowX}`); | ||
BTTLog(`focusedWindowY: ${focusedWindowY}`); | ||
BTTLog(`focusedWindowWidth: ${focusedWindowWidth}`); | ||
BTTLog(`focusedWindowHeight: ${focusedWindowHeight}`); | ||
BTTLog(`menuBarHeight: ${menuBarHeight}`); | ||
BTTLog(`stageManagerWidth: ${stageManagerMarginWidth}`); | ||
BTTLog(`isInUpperLeftCorner: ${isInUpperLeftCorner}`); | ||
BTTLog(`isMaximumSize: ${isMaximumSize}`); | ||
BTTLog(`isMaximised: ${isMaximised}`); | ||
|
||
return isMaximised; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export default async function getFocusedWindowInfo() { | ||
const appleScript = ` | ||
tell application "System Events" | ||
set appOfInterest to name of application processes whose frontmost is true | ||
set currentApplication to item 1 of appOfInterest | ||
set firstWindow to the first window of application process currentApplication | ||
set windowDimensions to size of firstWindow | ||
set windowPosition to position of firstWindow | ||
end tell | ||
return "[" & (item 1 of windowPosition as text) & "," & (item 2 of windowPosition as text) & "," & (item 1 of windowDimensions as text) & "," & (item 2 of windowDimensions as text) & "]" | ||
`; | ||
|
||
const resultStr = await runAppleScript(appleScript); | ||
const result = JSON.parse(resultStr); | ||
const [focusedWindowX, focusedWindowY, focusedWindowWidth, focusedWindowHeight] = result.map((str) => | ||
parseInt(str, 10) | ||
); | ||
|
||
return { | ||
focusedWindowX, | ||
focusedWindowY, | ||
focusedWindowWidth, | ||
focusedWindowHeight, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { hinkelScreenDimensions, menuBarHeight } from "./config.mjs"; | ||
|
||
export default function getMenuBarHeight(screenWidth, screenHeight) { | ||
if (screenWidth === hinkelScreenDimensions.width && screenHeight === hinkelScreenDimensions.height) { | ||
return menuBarHeight.notch; | ||
} | ||
return menuBarHeight.normal; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import "./lib/setupMocks.mjs"; | ||
import focusedWindowIsMaximised from "./lib/focusedWindowIsMaximised.mjs"; | ||
|
||
(async () => { | ||
const isMaximised = await focusedWindowIsMaximised(); | ||
returnToBTT(isMaximised ? "focused window is maximised" : "focused window is not maximised"); | ||
})(); |