Comparing version 1.3.1 to 1.4.0
import { MessageEvent, Event, CloseEvent, ErrorEvent } from 'ws'; | ||
interface KeybindingConfig { | ||
bindings: string[]; | ||
command: unknown; | ||
} | ||
interface BindingModeConfig { | ||
name: string; | ||
displayName: string; | ||
keybindings: KeybindingConfig; | ||
} | ||
declare enum ContainerType { | ||
ROOT = "root", | ||
MONITOR = "monitor", | ||
WORKSPACE = "workspace", | ||
SPLIT = "split", | ||
WINDOW = "window" | ||
} | ||
interface AppMetadata { | ||
version: string; | ||
} | ||
declare enum DisplayState { | ||
@@ -78,6 +55,25 @@ SHOWN = "shown", | ||
interface KeybindingConfig { | ||
bindings: string[]; | ||
command: unknown; | ||
} | ||
interface BindingModeConfig { | ||
name: string; | ||
displayName: string; | ||
keybindings: KeybindingConfig; | ||
} | ||
declare enum ContainerType { | ||
ROOT = "root", | ||
MONITOR = "monitor", | ||
WORKSPACE = "workspace", | ||
SPLIT = "split", | ||
WINDOW = "window" | ||
} | ||
interface Window { | ||
id: string; | ||
type: ContainerType.WINDOW; | ||
parent: string; | ||
parentId: string; | ||
hasFocus: boolean; | ||
@@ -103,3 +99,3 @@ floatingPlacement: Rect; | ||
type: ContainerType.SPLIT; | ||
parent: string; | ||
parentId: string; | ||
childFocusOrder: string[]; | ||
@@ -119,3 +115,3 @@ children: (SplitContainer | Window)[]; | ||
type: ContainerType.WORKSPACE; | ||
parent: string; | ||
parentId: string; | ||
childFocusOrder: string[]; | ||
@@ -126,2 +122,3 @@ children: (SplitContainer | Window)[]; | ||
name: string; | ||
displayName: string; | ||
tilingDirection: TilingDirection; | ||
@@ -137,3 +134,3 @@ width: number; | ||
type: ContainerType.MONITOR; | ||
parent: string; | ||
parentId: string; | ||
childFocusOrder: string[]; | ||
@@ -157,3 +154,3 @@ children: Workspace[]; | ||
type: ContainerType.ROOT; | ||
parent: null; | ||
parentId: null; | ||
childFocusOrder: string[]; | ||
@@ -221,3 +218,3 @@ children: Monitor[]; | ||
type: WmEventType.BINDING_MODES_CHANGED; | ||
activeBindingModes: BindingModeConfig[]; | ||
newBindingModes: BindingModeConfig[]; | ||
} | ||
@@ -227,3 +224,3 @@ | ||
type: WmEventType.FOCUS_CHANGED; | ||
focusedContainer: Container; | ||
focusedContainer: Window | Workspace; | ||
} | ||
@@ -233,3 +230,3 @@ | ||
type: WmEventType.FOCUSED_CONTAINER_MOVED; | ||
focusedContainer: Container; | ||
focusedContainer: Window | Workspace; | ||
} | ||
@@ -256,2 +253,3 @@ | ||
newTilingDirection: TilingDirection; | ||
directionContainer: SplitContainer | Workspace; | ||
} | ||
@@ -293,2 +291,39 @@ | ||
interface AppMetadataResponse { | ||
version: string; | ||
} | ||
interface BindingModesResponse { | ||
bindingModes: BindingModeConfig[]; | ||
} | ||
interface FocusedResponse { | ||
focused: Window | Workspace; | ||
} | ||
interface MonitorsResponse { | ||
monitors: Monitor[]; | ||
} | ||
interface RunCommandResponse { | ||
subjectContainerId: string; | ||
} | ||
interface SubscribeResponse { | ||
subscriptionId: string; | ||
} | ||
interface TilingDirectionResponse { | ||
tilingDirection: TilingDirection; | ||
directionContainer: Workspace | SplitContainer; | ||
} | ||
interface WindowsResponse { | ||
windows: Window[]; | ||
} | ||
interface WorkspacesResponse { | ||
workspaces: Workspace[]; | ||
} | ||
declare enum ServerMessageType { | ||
@@ -366,17 +401,11 @@ CLIENT_RESPONSE = "client_response", | ||
*/ | ||
queryMonitors(): Promise<{ | ||
monitors: Monitor[]; | ||
}>; | ||
queryMonitors(): Promise<MonitorsResponse>; | ||
/** | ||
* Gets all active workspaces. {@link Workspace} | ||
*/ | ||
queryWorkspaces(): Promise<{ | ||
workspaces: Workspace[]; | ||
}>; | ||
queryWorkspaces(): Promise<WorkspacesResponse>; | ||
/** | ||
* Gets all managed windows. {@link Window} | ||
*/ | ||
queryWindows(): Promise<{ | ||
windows: Window[]; | ||
}>; | ||
queryWindows(): Promise<WindowsResponse>; | ||
/** | ||
@@ -386,17 +415,16 @@ * Gets the currently focused container. This can either be a | ||
*/ | ||
queryFocused(): Promise<{ | ||
focused: Window | Workspace; | ||
}>; | ||
queryFocused(): Promise<FocusedResponse>; | ||
/** | ||
* Gets the active binding modes. {@link BindingModeConfig} | ||
* Gets the active binding modes. | ||
*/ | ||
queryBindingModes(): Promise<{ | ||
bindingModes: BindingModeConfig[]; | ||
}>; | ||
queryBindingModes(): Promise<BindingModesResponse>; | ||
/** | ||
* Gets metadata about the running GlazeWM application. | ||
* {@link AppMetadata} | ||
*/ | ||
queryAppMetadata(): Promise<AppMetadata>; | ||
queryAppMetadata(): Promise<AppMetadataResponse>; | ||
/** | ||
* Gets the tiling direction of the focused container. | ||
*/ | ||
queryTilingDirection(): Promise<TilingDirectionResponse>; | ||
/** | ||
* Invokes a WM command (e.g. `"focus --workspace 1"`). | ||
@@ -409,3 +437,3 @@ * | ||
*/ | ||
runCommand(command: string, subjectContainerId?: string): Promise<void>; | ||
runCommand(command: string, subjectContainerId?: string): Promise<RunCommandResponse>; | ||
/** | ||
@@ -510,2 +538,2 @@ * Establishes websocket connection. | ||
export { AppMetadata, ApplicationExitingEvent, BindingModeConfig, BindingModesChangedEvent, ClientResponseMessage, ConnectCallback, Container, ContainerType, DisconnectCallback, DisplayState, ErrorCallback, EventSubscriptionMessage, FocusChangedEvent, FocusedContainerMovedEvent, KeybindingConfig, LengthUnit, MessageCallback, Monitor, MonitorAddedEvent, MonitorRemovedEvent, MonitorUpdatedEvent, Rect, RectDelta, RootContainer, ServerMessage, ServerMessageType, SplitContainer, SubscribeCallback, TilingDirection, TilingDirectionChangedEvent, UnlistenFn, UserConfigChangedEvent, Window, WindowManagedEvent, WindowState, WindowType, WindowUnmanagedEvent, WmClient, WmClientOptions, WmEvent, WmEventData, WmEventType, Workspace, WorkspaceActivatedEvent, WorkspaceDeactivatedEvent, WorkspaceUpdatedEvent }; | ||
export { AppMetadataResponse, ApplicationExitingEvent, BindingModeConfig, BindingModesChangedEvent, BindingModesResponse, ClientResponseMessage, ConnectCallback, Container, ContainerType, DisconnectCallback, DisplayState, ErrorCallback, EventSubscriptionMessage, FocusChangedEvent, FocusedContainerMovedEvent, FocusedResponse, KeybindingConfig, LengthUnit, MessageCallback, Monitor, MonitorAddedEvent, MonitorRemovedEvent, MonitorUpdatedEvent, MonitorsResponse, Rect, RectDelta, RootContainer, RunCommandResponse, ServerMessage, ServerMessageType, SplitContainer, SubscribeCallback, SubscribeResponse, TilingDirection, TilingDirectionChangedEvent, TilingDirectionResponse, UnlistenFn, UserConfigChangedEvent, Window, WindowManagedEvent, WindowState, WindowType, WindowUnmanagedEvent, WindowsResponse, WmClient, WmClientOptions, WmEvent, WmEventData, WmEventType, Workspace, WorkspaceActivatedEvent, WorkspaceDeactivatedEvent, WorkspaceUpdatedEvent, WorkspacesResponse }; |
@@ -67,5 +67,3 @@ "use strict"; | ||
async queryMonitors() { | ||
return this._sendAndWaitReply( | ||
"query monitors" | ||
); | ||
return this._sendAndWaitReply("query monitors"); | ||
} | ||
@@ -76,5 +74,3 @@ /** | ||
async queryWorkspaces() { | ||
return this._sendAndWaitReply( | ||
"query workspaces" | ||
); | ||
return this._sendAndWaitReply("query workspaces"); | ||
} | ||
@@ -92,8 +88,6 @@ /** | ||
async queryFocused() { | ||
return this._sendAndWaitReply( | ||
"query focused" | ||
); | ||
return this._sendAndWaitReply("query focused"); | ||
} | ||
/** | ||
* Gets the active binding modes. {@link BindingModeConfig} | ||
* Gets the active binding modes. | ||
*/ | ||
@@ -107,8 +101,17 @@ async queryBindingModes() { | ||
* Gets metadata about the running GlazeWM application. | ||
* {@link AppMetadata} | ||
*/ | ||
async queryAppMetadata() { | ||
return this._sendAndWaitReply("query app-metadata"); | ||
return this._sendAndWaitReply( | ||
"query app-metadata" | ||
); | ||
} | ||
/** | ||
* Gets the tiling direction of the focused container. | ||
*/ | ||
async queryTilingDirection() { | ||
return this._sendAndWaitReply( | ||
"query tiling-direction" | ||
); | ||
} | ||
/** | ||
* Invokes a WM command (e.g. `"focus --workspace 1"`). | ||
@@ -122,3 +125,3 @@ * | ||
async runCommand(command, subjectContainerId) { | ||
await this._sendAndWaitReply( | ||
return this._sendAndWaitReply( | ||
subjectContainerId ? `command --id ${subjectContainerId} ${command}` : `command ${command}` | ||
@@ -171,3 +174,5 @@ ); | ||
async subscribeMany(events, callback) { | ||
const response = await this._sendAndWaitReply(`sub --events ${events.join(" ")}`); | ||
const { subscriptionId } = await this._sendAndWaitReply( | ||
`sub --events ${events.join(" ")}` | ||
); | ||
const unlisten = this.onMessage((e) => { | ||
@@ -177,3 +182,3 @@ const serverMessage = JSON.parse( | ||
); | ||
const isSubscribedEvent = serverMessage.messageType === "event_subscription" && events.includes(serverMessage.data?.type); | ||
const isSubscribedEvent = serverMessage.messageType === "event_subscription" && serverMessage.subscriptionId === subscriptionId; | ||
if (isSubscribedEvent) { | ||
@@ -185,5 +190,3 @@ callback(serverMessage.data); | ||
unlisten(); | ||
await this._sendAndWaitReply( | ||
`unsub --id ${response.subscriptionId}` | ||
); | ||
await this._sendAndWaitReply(`unsub --id ${subscriptionId}`); | ||
}; | ||
@@ -315,19 +318,2 @@ } | ||
// src/types/containers/container-type.ts | ||
var ContainerType = /* @__PURE__ */ ((ContainerType2) => { | ||
ContainerType2["ROOT"] = "root"; | ||
ContainerType2["MONITOR"] = "monitor"; | ||
ContainerType2["WORKSPACE"] = "workspace"; | ||
ContainerType2["SPLIT"] = "split"; | ||
ContainerType2["WINDOW"] = "window"; | ||
return ContainerType2; | ||
})(ContainerType || {}); | ||
// src/types/server-message.ts | ||
var ServerMessageType = /* @__PURE__ */ ((ServerMessageType2) => { | ||
ServerMessageType2["CLIENT_RESPONSE"] = "client_response"; | ||
ServerMessageType2["EVENT_SUBSCRIPTION"] = "event_subscription"; | ||
return ServerMessageType2; | ||
})(ServerMessageType || {}); | ||
// src/types/common/display-state.ts | ||
@@ -358,2 +344,19 @@ var DisplayState = /* @__PURE__ */ ((DisplayState2) => { | ||
// src/types/containers/container-type.ts | ||
var ContainerType = /* @__PURE__ */ ((ContainerType2) => { | ||
ContainerType2["ROOT"] = "root"; | ||
ContainerType2["MONITOR"] = "monitor"; | ||
ContainerType2["WORKSPACE"] = "workspace"; | ||
ContainerType2["SPLIT"] = "split"; | ||
ContainerType2["WINDOW"] = "window"; | ||
return ContainerType2; | ||
})(ContainerType || {}); | ||
// src/types/server-message.ts | ||
var ServerMessageType = /* @__PURE__ */ ((ServerMessageType2) => { | ||
ServerMessageType2["CLIENT_RESPONSE"] = "client_response"; | ||
ServerMessageType2["EVENT_SUBSCRIPTION"] = "event_subscription"; | ||
return ServerMessageType2; | ||
})(ServerMessageType || {}); | ||
// src/types/wm-events.ts | ||
@@ -360,0 +363,0 @@ var WmEventType = /* @__PURE__ */ ((WmEventType2) => { |
{ | ||
"name": "glazewm", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "Library for inter-process communication (IPC) with GlazeWM.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
import { WmClient } from './client'; | ||
import { TilingDirection } from './types'; | ||
@@ -25,4 +26,4 @@ describe.sequential('[CLIENT]', async () => { | ||
it.concurrent('focused container', async () => { | ||
const focused = await client.queryFocused(); | ||
it.concurrent('focused', async () => { | ||
const { focused } = await client.queryFocused(); | ||
expect(focused).toBeDefined(); | ||
@@ -40,2 +41,13 @@ }); | ||
}); | ||
it.concurrent('tiling direction', async () => { | ||
const { directionContainer, tilingDirection } = | ||
await client.queryTilingDirection(); | ||
expect(directionContainer).toBeDefined(); | ||
expect( | ||
tilingDirection === TilingDirection.HORIZONTAL || | ||
tilingDirection === TilingDirection.VERTICAL, | ||
).toBeTruthy(); | ||
}); | ||
}); | ||
@@ -42,0 +54,0 @@ |
@@ -10,3 +10,2 @@ import { | ||
import { | ||
type BindingModeConfig, | ||
WmEventType, | ||
@@ -18,3 +17,11 @@ type WmEventData, | ||
type Window, | ||
type AppMetadata, | ||
type AppMetadataResponse, | ||
type TilingDirectionResponse, | ||
type BindingModesResponse, | ||
type FocusedResponse, | ||
type WindowsResponse, | ||
type MonitorsResponse, | ||
type WorkspacesResponse, | ||
type RunCommandResponse, | ||
type SubscribeResponse, | ||
} from './types'; | ||
@@ -63,6 +70,4 @@ | ||
*/ | ||
async queryMonitors(): Promise<{ monitors: Monitor[] }> { | ||
return this._sendAndWaitReply<{ monitors: Monitor[] }>( | ||
'query monitors', | ||
); | ||
async queryMonitors(): Promise<MonitorsResponse> { | ||
return this._sendAndWaitReply<MonitorsResponse>('query monitors'); | ||
} | ||
@@ -73,6 +78,4 @@ | ||
*/ | ||
async queryWorkspaces(): Promise<{ workspaces: Workspace[] }> { | ||
return this._sendAndWaitReply<{ workspaces: Workspace[] }>( | ||
'query workspaces', | ||
); | ||
async queryWorkspaces(): Promise<WorkspacesResponse> { | ||
return this._sendAndWaitReply<WorkspacesResponse>('query workspaces'); | ||
} | ||
@@ -83,4 +86,4 @@ | ||
*/ | ||
async queryWindows(): Promise<{ windows: Window[] }> { | ||
return this._sendAndWaitReply<{ windows: Window[] }>('query windows'); | ||
async queryWindows(): Promise<WindowsResponse> { | ||
return this._sendAndWaitReply<WindowsResponse>('query windows'); | ||
} | ||
@@ -92,15 +95,11 @@ | ||
*/ | ||
async queryFocused(): Promise<{ focused: Window | Workspace }> { | ||
return this._sendAndWaitReply<{ focused: Window | Workspace }>( | ||
'query focused', | ||
); | ||
async queryFocused(): Promise<FocusedResponse> { | ||
return this._sendAndWaitReply<FocusedResponse>('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<BindingModesResponse> { | ||
return this._sendAndWaitReply<BindingModesResponse>( | ||
'query binding-modes', | ||
@@ -112,9 +111,19 @@ ); | ||
* Gets metadata about the running GlazeWM application. | ||
* {@link AppMetadata} | ||
*/ | ||
async queryAppMetadata(): Promise<AppMetadata> { | ||
return this._sendAndWaitReply<AppMetadata>('query app-metadata'); | ||
async queryAppMetadata(): Promise<AppMetadataResponse> { | ||
return this._sendAndWaitReply<AppMetadataResponse>( | ||
'query app-metadata', | ||
); | ||
} | ||
/** | ||
* Gets the tiling direction of the focused container. | ||
*/ | ||
async queryTilingDirection(): Promise<TilingDirectionResponse> { | ||
return this._sendAndWaitReply<TilingDirectionResponse>( | ||
'query tiling-direction', | ||
); | ||
} | ||
/** | ||
* Invokes a WM command (e.g. `"focus --workspace 1"`). | ||
@@ -130,4 +139,4 @@ * | ||
subjectContainerId?: string, | ||
): Promise<void> { | ||
await this._sendAndWaitReply<{ subjectContainerId: string }>( | ||
): Promise<RunCommandResponse> { | ||
return this._sendAndWaitReply<RunCommandResponse>( | ||
subjectContainerId | ||
@@ -196,5 +205,6 @@ ? `command --id ${subjectContainerId} ${command}` | ||
): Promise<UnlistenFn> { | ||
const response = await this._sendAndWaitReply<{ | ||
subscriptionId: string; | ||
}>(`sub --events ${events.join(' ')}`); | ||
const { subscriptionId } = | ||
await this._sendAndWaitReply<SubscribeResponse>( | ||
`sub --events ${events.join(' ')}`, | ||
); | ||
@@ -208,3 +218,3 @@ const unlisten = this.onMessage(e => { | ||
serverMessage.messageType === 'event_subscription' && | ||
events.includes(serverMessage.data?.type!); | ||
serverMessage.subscriptionId === subscriptionId; | ||
@@ -219,5 +229,3 @@ if (isSubscribedEvent) { | ||
await this._sendAndWaitReply<{ subscriptionId: string }>( | ||
`unsub --id ${response.subscriptionId}`, | ||
); | ||
await this._sendAndWaitReply<void>(`unsub --id ${subscriptionId}`); | ||
}; | ||
@@ -224,0 +232,0 @@ } |
@@ -1,2 +0,1 @@ | ||
export * from './app-metadata'; | ||
export * from './display-state'; | ||
@@ -3,0 +2,0 @@ export * from './length-unit'; |
@@ -8,3 +8,3 @@ import type { Rect } from '../common'; | ||
type: ContainerType.MONITOR; | ||
parent: string; | ||
parentId: string; | ||
childFocusOrder: string[]; | ||
@@ -11,0 +11,0 @@ children: Workspace[]; |
@@ -7,5 +7,5 @@ import { ContainerType } from './container-type'; | ||
type: ContainerType.ROOT; | ||
parent: null; | ||
parentId: null; | ||
childFocusOrder: string[]; | ||
children: Monitor[]; | ||
} |
@@ -8,3 +8,3 @@ import { TilingDirection } from '../common'; | ||
type: ContainerType.SPLIT; | ||
parent: string; | ||
parentId: string; | ||
childFocusOrder: string[]; | ||
@@ -11,0 +11,0 @@ children: (SplitContainer | Window)[]; |
@@ -12,3 +12,3 @@ import type { | ||
type: ContainerType.WINDOW; | ||
parent: string; | ||
parentId: string; | ||
hasFocus: boolean; | ||
@@ -15,0 +15,0 @@ floatingPlacement: Rect; |
@@ -9,3 +9,3 @@ import { TilingDirection } from '../common'; | ||
type: ContainerType.WORKSPACE; | ||
parent: string; | ||
parentId: string; | ||
childFocusOrder: string[]; | ||
@@ -16,2 +16,3 @@ children: (SplitContainer | Window)[]; | ||
name: string; | ||
displayName: string; | ||
tilingDirection: TilingDirection; | ||
@@ -18,0 +19,0 @@ width: number; |
@@ -6,3 +6,3 @@ import type { BindingModeConfig } from '../config'; | ||
type: WmEventType.BINDING_MODES_CHANGED; | ||
activeBindingModes: BindingModeConfig[]; | ||
newBindingModes: BindingModeConfig[]; | ||
} |
import { WmEventType } from '../wm-events'; | ||
import type { Container } from '../containers'; | ||
import type { Window, Workspace } from '../containers'; | ||
export interface FocusChangedEvent { | ||
type: WmEventType.FOCUS_CHANGED; | ||
focusedContainer: Container; | ||
focusedContainer: Window | Workspace; | ||
} |
import { WmEventType } from '../wm-events'; | ||
import type { Container } from '../containers'; | ||
import type { Window, Workspace } from '../containers'; | ||
export interface FocusedContainerMovedEvent { | ||
type: WmEventType.FOCUSED_CONTAINER_MOVED; | ||
focusedContainer: Container; | ||
focusedContainer: Window | Workspace; | ||
} |
@@ -0,3 +1,4 @@ | ||
import { TilingDirection } from '../common'; | ||
import type { SplitContainer, Workspace } from '../containers'; | ||
import { WmEventType } from '../wm-events'; | ||
import { TilingDirection } from '../common'; | ||
@@ -7,2 +8,3 @@ export interface TilingDirectionChangedEvent { | ||
newTilingDirection: TilingDirection; | ||
directionContainer: SplitContainer | Workspace; | ||
} |
@@ -0,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'; |
Sorry, the diff of this file is not supported yet
68752
62
2057