diff --git a/src/client.test.ts b/src/client.test.ts index d96b1b5..e196e6d 100644 --- a/src/client.test.ts +++ b/src/client.test.ts @@ -1,4 +1,5 @@ import { WmClient } from './client'; +import { TilingDirection } from './types'; describe.sequential('[CLIENT]', async () => { const client = new WmClient(); @@ -22,8 +23,8 @@ describe.sequential('[CLIENT]', async () => { expect(workspaces.length).toBeGreaterThan(0); }); - it.concurrent('focused container', async () => { - const focused = await client.queryFocused(); + it.concurrent('focused', async () => { + const { focused } = await client.queryFocused(); expect(focused).toBeDefined(); }); @@ -36,6 +37,17 @@ describe.sequential('[CLIENT]', async () => { const { version } = await client.queryAppMetadata(); expect(typeof version).toBe('string'); }); + + it.concurrent('tiling direction', async () => { + const { directionContainer, tilingDirection } = + await client.queryTilingDirection(); + + expect(directionContainer).toBeDefined(); + expect( + tilingDirection === TilingDirection.HORIZONTAL || + tilingDirection === TilingDirection.VERTICAL, + ).toBeTruthy(); + }); }); describe('(command)', () => { diff --git a/src/client.ts b/src/client.ts index 1412d17..bce5289 100644 --- a/src/client.ts +++ b/src/client.ts @@ -7,14 +7,21 @@ import { } from 'ws'; import { - type BindingModeConfig, WmEventType, type WmEventData, type Monitor, type ServerMessage, type Workspace, type Window, - type AppMetadata, + type AppMetadataResponse, + type TilingDirectionResponse, + type BindingModesResponse, + type FocusedResponse, + type WindowsResponse, + type MonitorsResponse, + type WorkspacesResponse, + type RunCommandResponse, + type SubscribeResponse, } from './types'; export interface WmClientOptions { @@ -58,55 +65,57 @@ export class WmClient { /** * Gets all monitors. {@link Monitor} */ - async queryMonitors(): Promise<{ monitors: Monitor[] }> { - return this._sendAndWaitReply<{ monitors: Monitor[] }>( - 'query monitors', - ); + async queryMonitors(): Promise { + return this._sendAndWaitReply('query monitors'); } /** * Gets all active workspaces. {@link Workspace} */ - async queryWorkspaces(): Promise<{ workspaces: Workspace[] }> { - return this._sendAndWaitReply<{ workspaces: Workspace[] }>( - 'query workspaces', - ); + async queryWorkspaces(): Promise { + return this._sendAndWaitReply('query workspaces'); } /** * Gets all managed windows. {@link Window} */ - async queryWindows(): Promise<{ windows: Window[] }> { - return this._sendAndWaitReply<{ windows: Window[] }>('query windows'); + async queryWindows(): Promise { + return this._sendAndWaitReply('query windows'); } /** * Gets the currently focused container. This can either be a * {@link Window} or a {@link Workspace} without any descendant windows. */ - async queryFocused(): Promise<{ focused: Window | Workspace }> { - return this._sendAndWaitReply<{ focused: Window | Workspace }>( - 'query focused', - ); + async queryFocused(): Promise { + return this._sendAndWaitReply('query focused'); } /** - * Gets the active binding modes. {@link BindingModeConfig} + * Gets the active binding modes. */ - async queryBindingModes(): Promise<{ - bindingModes: BindingModeConfig[]; - }> { - return this._sendAndWaitReply<{ bindingModes: BindingModeConfig[] }>( + async queryBindingModes(): Promise { + return this._sendAndWaitReply( 'query binding-modes', ); } /** * Gets metadata about the running GlazeWM application. - * {@link AppMetadata} */ - async queryAppMetadata(): Promise { - return this._sendAndWaitReply('query app-metadata'); + async queryAppMetadata(): Promise { + return this._sendAndWaitReply( + 'query app-metadata', + ); + } + + /** + * Gets the tiling direction of the focused container. + */ + async queryTilingDirection(): Promise { + return this._sendAndWaitReply( + 'query tiling-direction', + ); } /** @@ -120,8 +129,8 @@ export class WmClient { async runCommand( command: string, subjectContainerId?: string, - ): Promise { - await this._sendAndWaitReply<{ subjectContainerId: string }>( + ): Promise { + return this._sendAndWaitReply( subjectContainerId ? `command --id ${subjectContainerId} ${command}` : `command ${command}`, @@ -185,9 +194,10 @@ export class WmClient { events: T, callback: SubscribeCallback, ): Promise { - const { subscriptionId } = await this._sendAndWaitReply<{ - subscriptionId: string; - }>(`sub --events ${events.join(' ')}`); + const { subscriptionId } = + await this._sendAndWaitReply( + `sub --events ${events.join(' ')}`, + ); const unlisten = this.onMessage(e => { const serverMessage: ServerMessage = JSON.parse( @@ -206,9 +216,7 @@ export class WmClient { return async () => { unlisten(); - await this._sendAndWaitReply<{ subscriptionId: string }>( - `unsub --id ${subscriptionId}`, - ); + await this._sendAndWaitReply(`unsub --id ${subscriptionId}`); }; } diff --git a/src/types/common/app-metadata.ts b/src/types/common/app-metadata.ts deleted file mode 100644 index c66a6ac..0000000 --- a/src/types/common/app-metadata.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface AppMetadata { - version: string; -} diff --git a/src/types/common/index.ts b/src/types/common/index.ts index b602b58..b2b0003 100644 --- a/src/types/common/index.ts +++ b/src/types/common/index.ts @@ -1,4 +1,3 @@ -export * from './app-metadata'; export * from './display-state'; export * from './length-unit'; export * from './rect-delta'; diff --git a/src/types/index.ts b/src/types/index.ts index 4354786..39037ed 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,6 +1,7 @@ +export * from './common'; export * from './config'; export * from './containers'; export * from './events'; +export * from './responses'; export * from './server-message'; -export * from './common'; export * from './wm-events'; diff --git a/src/types/responses/app-metadata-response.ts b/src/types/responses/app-metadata-response.ts new file mode 100644 index 0000000..911c0f1 --- /dev/null +++ b/src/types/responses/app-metadata-response.ts @@ -0,0 +1,3 @@ +export interface AppMetadataResponse { + version: string; +} diff --git a/src/types/responses/binding-modes-response.ts b/src/types/responses/binding-modes-response.ts new file mode 100644 index 0000000..43ed121 --- /dev/null +++ b/src/types/responses/binding-modes-response.ts @@ -0,0 +1,5 @@ +import type { BindingModeConfig } from '../config'; + +export interface BindingModesResponse { + bindingModes: BindingModeConfig[]; +} diff --git a/src/types/responses/focused-response.ts b/src/types/responses/focused-response.ts new file mode 100644 index 0000000..dc961c7 --- /dev/null +++ b/src/types/responses/focused-response.ts @@ -0,0 +1,5 @@ +import type { Window, Workspace } from '../containers'; + +export interface FocusedResponse { + focused: Window | Workspace; +} diff --git a/src/types/responses/index.ts b/src/types/responses/index.ts new file mode 100644 index 0000000..45c1ef7 --- /dev/null +++ b/src/types/responses/index.ts @@ -0,0 +1,9 @@ +export * from './app-metadata-response'; +export * from './binding-modes-response'; +export * from './focused-response'; +export * from './monitors-response'; +export * from './run-command-response'; +export * from './subscribe-response'; +export * from './tiling-direction-response'; +export * from './windows-response'; +export * from './workspaces-response'; diff --git a/src/types/responses/monitors-response.ts b/src/types/responses/monitors-response.ts new file mode 100644 index 0000000..7a770bc --- /dev/null +++ b/src/types/responses/monitors-response.ts @@ -0,0 +1,5 @@ +import type { Monitor } from '../containers'; + +export interface MonitorsResponse { + monitors: Monitor[]; +} diff --git a/src/types/responses/run-command-response.ts b/src/types/responses/run-command-response.ts new file mode 100644 index 0000000..265016f --- /dev/null +++ b/src/types/responses/run-command-response.ts @@ -0,0 +1,3 @@ +export interface RunCommandResponse { + subjectContainerId: string; +} diff --git a/src/types/responses/subscribe-response.ts b/src/types/responses/subscribe-response.ts new file mode 100644 index 0000000..9a0b811 --- /dev/null +++ b/src/types/responses/subscribe-response.ts @@ -0,0 +1,3 @@ +export interface SubscribeResponse { + subscriptionId: string; +} diff --git a/src/types/responses/tiling-direction-response.ts b/src/types/responses/tiling-direction-response.ts new file mode 100644 index 0000000..607adec --- /dev/null +++ b/src/types/responses/tiling-direction-response.ts @@ -0,0 +1,7 @@ +import { TilingDirection } from '../common'; +import type { SplitContainer, Workspace } from '../containers'; + +export interface TilingDirectionResponse { + tilingDirection: TilingDirection; + directionContainer: Workspace | SplitContainer; +} diff --git a/src/types/responses/windows-response.ts b/src/types/responses/windows-response.ts new file mode 100644 index 0000000..23223ef --- /dev/null +++ b/src/types/responses/windows-response.ts @@ -0,0 +1,5 @@ +import type { Window } from '../containers'; + +export interface WindowsResponse { + windows: Window[]; +} diff --git a/src/types/responses/workspaces-response.ts b/src/types/responses/workspaces-response.ts new file mode 100644 index 0000000..8977e53 --- /dev/null +++ b/src/types/responses/workspaces-response.ts @@ -0,0 +1,5 @@ +import type { Workspace } from '../containers'; + +export interface WorkspacesResponse { + workspaces: Workspace[]; +}