-
Notifications
You must be signed in to change notification settings - Fork 56
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
1 parent
6742fa0
commit f712189
Showing
22 changed files
with
1,196 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pnpm-lock.yaml | ||
packages/desktop/installer.wxs | ||
README.md |
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
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
191 changes: 191 additions & 0 deletions
191
packages/client-api/src/providers/komorebi/create-komorebi-provider.ts
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,191 @@ | ||
import { createEffect, type Owner } from 'solid-js'; | ||
import { createStore } from 'solid-js/store'; | ||
|
||
import type { KomorebiProviderConfig } from '~/user-config'; | ||
import { createProviderListener } from '../create-provider-listener'; | ||
import { getMonitors } from '~/desktop'; | ||
import { getCoordinateDistance } from '~/utils'; | ||
|
||
interface KomorebiResponse { | ||
allMonitors: KomorebiMonitor[]; | ||
focusedMonitorIndex: number; | ||
} | ||
|
||
export interface KomorebiProvider { | ||
/** | ||
* Workspace displayed on the current monitor. | ||
*/ | ||
displayedWorkspace: KomorebiWorkspace; | ||
|
||
/** | ||
* Workspace that currently has focus (on any monitor). | ||
*/ | ||
focusedWorkspace: KomorebiWorkspace; | ||
|
||
/** | ||
* Workspaces on the current monitor. | ||
*/ | ||
currentWorkspaces: KomorebiWorkspace[]; | ||
|
||
/** | ||
* Workspaces across all monitors. | ||
*/ | ||
allWorkspaces: KomorebiWorkspace[]; | ||
|
||
/** | ||
* All monitors. | ||
*/ | ||
allMonitors: KomorebiMonitor[]; | ||
|
||
/** | ||
* Monitor that currently has focus. | ||
*/ | ||
focusedMonitor: KomorebiMonitor; | ||
|
||
/** | ||
* Monitor that is nearest to this Zebar window. | ||
*/ | ||
currentMonitor: KomorebiMonitor; | ||
} | ||
|
||
export interface KomorebiMonitor { | ||
id: number; | ||
deviceId: string; | ||
focusedWorkspaceIndex: number; | ||
name: string; | ||
size: KomorebiRect; | ||
workAreaOffset: number | null; | ||
workAreaSize: KomorebiRect; | ||
workspaces: KomorebiWorkspace[]; | ||
} | ||
|
||
export interface KomorebiWorkspace { | ||
containerPadding: number | null; | ||
floatingWindows: KomorebiWindow[]; | ||
focusedContainerIndex: number; | ||
latestLayout: KomorebiRect[]; | ||
layout: KomorebiLayout; | ||
layoutFlip: KomorebiLayoutFlip | null; | ||
maximizedWindow: KomorebiWindow | null; | ||
monocleContainer: KomorebiContainer | null; | ||
name: string | null; | ||
tilingContainers: KomorebiContainer[]; | ||
workspacePadding: number | null; | ||
} | ||
|
||
export interface KomorebiContainer { | ||
id: string; | ||
windows: KomorebiWindow[]; | ||
} | ||
|
||
export interface KomorebiWindow { | ||
class: string | null; | ||
exe: string | null; | ||
hwnd: number; | ||
title: string | null; | ||
} | ||
|
||
export interface KomorebiRect { | ||
left: number; | ||
top: number; | ||
right: number; | ||
bottom: number; | ||
} | ||
|
||
export type KomorebiLayout = | ||
| 'bsp' | ||
| 'vertical_stack' | ||
| 'horizontal_stack' | ||
| 'ultrawide_vertical_stack' | ||
| 'rows' | ||
| 'grid' | ||
| 'custom'; | ||
|
||
export type KomorebiLayoutFlip = | ||
| 'horizontal' | ||
| 'vertical' | ||
| 'horizontal_and_vertical'; | ||
|
||
export async function createKomorebiProvider( | ||
config: KomorebiProviderConfig, | ||
owner: Owner, | ||
): Promise<KomorebiProvider> { | ||
const { currentMonitor } = await getMonitors(); | ||
|
||
const providerListener = await createProviderListener< | ||
KomorebiProviderConfig, | ||
KomorebiResponse | ||
>(config, owner); | ||
|
||
const [komorebiVariables, setKomorebiVariables] = createStore( | ||
await getVariables(), | ||
); | ||
|
||
createEffect(async () => setKomorebiVariables(await getVariables())); | ||
|
||
async function getVariables() { | ||
const state = providerListener(); | ||
const currentPosition = { x: currentMonitor!.x, y: currentMonitor!.y }; | ||
|
||
// Get Komorebi monitor that corresponds to the window's monitor. | ||
const currentKomorebiMonitor = state.allMonitors.reduce((a, b) => | ||
getCoordinateDistance(currentPosition, { | ||
x: a.workAreaSize.left, | ||
y: a.workAreaSize.top, | ||
}) < | ||
getCoordinateDistance(currentPosition, { | ||
x: b.workAreaSize.left, | ||
y: b.workAreaSize.top, | ||
}) | ||
? a | ||
: b, | ||
); | ||
|
||
const displayedWorkspace = | ||
currentKomorebiMonitor.workspaces[ | ||
currentKomorebiMonitor.focusedWorkspaceIndex | ||
]!; | ||
|
||
const allWorkspaces = state.allMonitors.flatMap( | ||
monitor => monitor.workspaces, | ||
); | ||
|
||
const focusedMonitor = state.allMonitors[state.focusedMonitorIndex]!; | ||
const focusedWorkspace = | ||
focusedMonitor.workspaces[focusedMonitor.focusedWorkspaceIndex]!; | ||
|
||
return { | ||
displayedWorkspace, | ||
focusedWorkspace, | ||
currentWorkspaces: currentKomorebiMonitor.workspaces, | ||
allWorkspaces, | ||
focusedMonitor, | ||
currentMonitor: currentKomorebiMonitor, | ||
allMonitors: state.allMonitors, | ||
}; | ||
} | ||
|
||
return { | ||
get displayedWorkspace() { | ||
return komorebiVariables.displayedWorkspace; | ||
}, | ||
get focusedWorkspace() { | ||
return komorebiVariables.focusedWorkspace; | ||
}, | ||
get currentWorkspaces() { | ||
return komorebiVariables.currentWorkspaces; | ||
}, | ||
get allWorkspaces() { | ||
return komorebiVariables.allWorkspaces; | ||
}, | ||
get allMonitors() { | ||
return komorebiVariables.allMonitors; | ||
}, | ||
get focusedMonitor() { | ||
return komorebiVariables.focusedMonitor; | ||
}, | ||
get currentMonitor() { | ||
return komorebiVariables.currentMonitor; | ||
}, | ||
}; | ||
} |
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
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
11 changes: 11 additions & 0 deletions
11
packages/client-api/src/user-config/window/providers/komorebi-provider-config.model.ts
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,11 @@ | ||
import { z } from 'zod'; | ||
|
||
import { ProviderType } from '../provider-type.model'; | ||
|
||
export const KomorebiProviderConfigSchema = z.object({ | ||
type: z.literal(ProviderType.KOMOREBI), | ||
}); | ||
|
||
export type KomorebiProviderConfig = z.infer< | ||
typeof KomorebiProviderConfigSchema | ||
>; |
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,11 @@ | ||
/** | ||
* Get distance between two points. | ||
*/ | ||
export function getCoordinateDistance( | ||
pointA: { x: number; y: number }, | ||
pointB: { x: number; y: number }, | ||
) { | ||
return Math.sqrt( | ||
Math.pow(pointB.x - pointA.x, 2) + Math.pow(pointB.y - pointA.y, 2), | ||
); | ||
} |
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
Oops, something went wrong.