From 027df8d34f414af1195dd7b3b8e955c632a5a302 Mon Sep 17 00:00:00 2001 From: Lars Berger Date: Sat, 27 Jul 2024 15:03:34 +0800 Subject: [PATCH 01/11] feat: update glazewm provider to v3; add new properties to glazewm provider --- packages/client-api/package.json | 2 +- .../src/providers/create-provider.ts | 4 +- .../glazewm/create-glazewm-provider.ts | 237 +++++++++++++++--- .../komorebi/create-komorebi-provider.ts | 2 +- .../window/provider-config.model.ts | 4 +- .../glazewm-provider-config.model.ts | 4 +- packages/desktop/resources/sample-config.yaml | 32 ++- pnpm-lock.yaml | 10 +- 8 files changed, 246 insertions(+), 49 deletions(-) diff --git a/packages/client-api/package.json b/packages/client-api/package.json index f329fbf6..8638e338 100644 --- a/packages/client-api/package.json +++ b/packages/client-api/package.json @@ -22,7 +22,7 @@ "@tauri-apps/api": "2.0.0-beta.15", "@tauri-apps/plugin-dialog": "2.0.0-beta.7", "@tauri-apps/plugin-shell": "2.0.0-beta.8", - "glazewm": "1.1.2", + "glazewm": "1.4.1", "luxon": "3.4.4", "solid-js": "1.8.14", "yaml": "2.3.4", diff --git a/packages/client-api/src/providers/create-provider.ts b/packages/client-api/src/providers/create-provider.ts index 69b71ff4..aa7c2da4 100644 --- a/packages/client-api/src/providers/create-provider.ts +++ b/packages/client-api/src/providers/create-provider.ts @@ -3,7 +3,7 @@ import type { Owner } from 'solid-js'; import { createBatteryProvider } from './battery/create-battery-provider'; import { createCpuProvider } from './cpu/create-cpu-provider'; import { createDateProvider } from './date/create-date-provider'; -import { createGlazewmProvider } from './glazewm/create-glazewm-provider'; +import { createGlazeWmProvider } from './glazewm/create-glazewm-provider'; import { createHostProvider } from './host/create-host-provider'; import { createIpProvider } from './ip/create-ip-provider'; import { createKomorebiProvider } from './komorebi/create-komorebi-provider'; @@ -32,7 +32,7 @@ export async function createProvider( case ProviderType.DATE: return createDateProvider(config, owner); case ProviderType.GLAZEWM: - return createGlazewmProvider(config, owner); + return createGlazeWmProvider(config, owner); case ProviderType.HOST: return createHostProvider(config, owner); case ProviderType.IP: diff --git a/packages/client-api/src/providers/glazewm/create-glazewm-provider.ts b/packages/client-api/src/providers/glazewm/create-glazewm-provider.ts index 2c4d62bc..e58b4f7e 100644 --- a/packages/client-api/src/providers/glazewm/create-glazewm-provider.ts +++ b/packages/client-api/src/providers/glazewm/create-glazewm-provider.ts @@ -1,69 +1,242 @@ +import { + TilingDirection, + WmClient, + WmEventType, + type BindingModesChangedEvent, + type Container, + type FocusChangedEvent, + type FocusedContainerMovedEvent, + type Monitor, + type TilingDirectionChangedEvent, + type Workspace, + type WorkspaceActivatedEvent, + type WorkspaceDeactivatedEvent, + type WorkspaceUpdatedEvent, +} from 'glazewm'; import { createEffect, on, runWithOwner, type Owner } from 'solid-js'; import { createStore } from 'solid-js/store'; -import { GwmClient, GwmEventType, type Workspace } from 'glazewm'; import { getMonitors } from '~/desktop'; import type { GlazewmProviderConfig } from '~/user-config'; import { getCoordinateDistance } from '~/utils'; -export async function createGlazewmProvider( +export interface GlazeWmProvider { + /** + * Workspace displayed on the current monitor. + */ + displayedWorkspace: Workspace; + + /** + * Workspace that currently has focus (on any monitor). + */ + focusedWorkspace: Workspace; + + /** + * Workspaces on the current monitor. + */ + currentWorkspaces: Workspace[]; + + /** + * Workspaces across all monitors. + */ + allWorkspaces: Workspace[]; + + /** + * All monitors. + */ + allMonitors: Monitor[]; + + /** + * Monitor that currently has focus. + */ + focusedMonitor: Monitor; + + /** + * Monitor that is nearest to this Zebar window. + */ + currentMonitor: Monitor; + + /** + * Container that currently has focus (on any monitor). + */ + focusedContainer: Container; + + /** + * Tiling direction of the focused container. + */ + tilingDirection: TilingDirection; + + /** + * Active binding modes; + */ + bindingModes: string[]; + + /** + * Focus a workspace by name. + */ + focusWorkspace(name: string): void; +} + +export async function createGlazeWmProvider( _: GlazewmProviderConfig, owner: Owner, -) { +): Promise { const monitors = await getMonitors(); - const client = new GwmClient(); + const client = new WmClient(); - const [glazewmVariables, setGlazewmVariables] = createStore({ - workspacesOnMonitor: [] as Workspace[], - // TODO - bindingMode: '', - }); - - client.onConnect(e => console.log('onOpen', e)); - client.onMessage(e => console.log('onMessage', e)); - client.onDisconnect(e => console.log('onClose', e)); - client.onError(e => console.log('onError', e)); - - // Get initial workspaces. - await refetch(); + const [glazeWmVariables, setGlazeWmVariables] = createStore( + await getInitialState(), + ); await client.subscribeMany( [ - GwmEventType.WORKSPACE_ACTIVATED, - GwmEventType.WORKSPACE_DEACTIVATED, - GwmEventType.FOCUS_CHANGED, + WmEventType.BINDING_MODES_CHANGED, + WmEventType.FOCUS_CHANGED, + WmEventType.FOCUSED_CONTAINER_MOVED, + WmEventType.TILING_DIRECTION_CHANGED, + WmEventType.WORKSPACE_ACTIVATED, + WmEventType.WORKSPACE_DEACTIVATED, + WmEventType.WORKSPACE_UPDATED, ], - refetch, + onEvent, ); runWithOwner(owner, () => { - createEffect(on(() => monitors.currentMonitor, refetch)); + createEffect( + on( + () => monitors.currentMonitor, + async () => setGlazeWmVariables({ ...(await getMonitorState()) }), + ), + ); }); - async function refetch() { + async function onEvent( + e: + | BindingModesChangedEvent + | FocusChangedEvent + | FocusedContainerMovedEvent + | TilingDirectionChangedEvent + | WorkspaceActivatedEvent + | WorkspaceDeactivatedEvent + | WorkspaceUpdatedEvent, + ) { + switch (e.eventType) { + case WmEventType.BINDING_MODES_CHANGED: { + setGlazeWmVariables({ + bindingModes: e.newBindingModes.map(mode => mode.name), + }); + break; + } + case WmEventType.FOCUS_CHANGED: + case WmEventType.FOCUSED_CONTAINER_MOVED: { + setGlazeWmVariables({ focusedContainer: e.focusedContainer }); + setGlazeWmVariables({ ...(await getMonitorState()) }); + break; + } + case WmEventType.TILING_DIRECTION_CHANGED: { + setGlazeWmVariables({ tilingDirection: e.newTilingDirection }); + break; + } + case WmEventType.WORKSPACE_ACTIVATED: + case WmEventType.WORKSPACE_DEACTIVATED: + case WmEventType.WORKSPACE_UPDATED: { + setGlazeWmVariables({ ...(await getMonitorState()) }); + break; + } + } + } + + async function getInitialState() { + const { focused } = await client.queryFocused(); + const { bindingModes } = await client.queryBindingModes(); + const { tilingDirection } = await client.queryTilingDirection(); + + return { + ...(await getMonitorState()), + focusedContainer: focused, + tilingDirection, + bindingModes: bindingModes.map(mode => mode.name), + }; + } + + async function getMonitorState() { const currentPosition = { x: monitors.currentMonitor!.x, y: monitors.currentMonitor!.y, }; - // Get GlazeWM monitor that corresponds to the bar's monitor. - const glazewmMonitor = (await client.getMonitors()).reduce((a, b) => + const { monitors: glazeWmMonitors } = await client.queryMonitors(); + + // Get GlazeWM monitor that corresponds to the Zebar window's monitor. + const currentGlazeWmMonitor = glazeWmMonitors.reduce((a, b) => getCoordinateDistance(currentPosition, a) < getCoordinateDistance(currentPosition, b) ? a : b, ); - setGlazewmVariables({ - workspacesOnMonitor: glazewmMonitor.children.sort( - (a, b) => Number(a.name) - Number(b.name), - ), - }); + const focusedGlazeWmMonitor = glazeWmMonitors.find( + monitor => monitor.hasFocus, + ); + + const allGlazeWmWorkspaces = glazeWmMonitors.flatMap( + monitor => monitor.children, + ); + + const focusedGlazeWmWorkspace = focusedGlazeWmMonitor?.children.find( + workspace => workspace.hasFocus, + ); + + const displayedGlazeWmWorkspace = currentGlazeWmMonitor.children.find( + workspace => workspace.isDisplayed, + ); + + return { + displayedWorkspace: displayedGlazeWmWorkspace!, + focusedWorkspace: focusedGlazeWmWorkspace!, + currentWorkspaces: currentGlazeWmMonitor.children, + allWorkspaces: allGlazeWmWorkspaces, + focusedMonitor: focusedGlazeWmMonitor!, + currentMonitor: currentGlazeWmMonitor, + allMonitors: glazeWmMonitors, + }; + } + + function focusWorkspace(name: string) { + client.runCommand(`focus --workspace ${name}`); } return { - get workspacesOnMonitor() { - return glazewmVariables.workspacesOnMonitor; + get displayedWorkspace() { + return glazeWmVariables.displayedWorkspace; + }, + get focusedWorkspace() { + return glazeWmVariables.focusedWorkspace; + }, + get currentWorkspaces() { + return glazeWmVariables.currentWorkspaces; + }, + get allWorkspaces() { + return glazeWmVariables.allWorkspaces; + }, + get allMonitors() { + return glazeWmVariables.allMonitors; + }, + get focusedMonitor() { + return glazeWmVariables.focusedMonitor; + }, + get currentMonitor() { + return glazeWmVariables.currentMonitor; + }, + get focusedContainer() { + return glazeWmVariables.focusedContainer; + }, + get tilingDirection() { + return glazeWmVariables.tilingDirection; + }, + get bindingModes() { + return glazeWmVariables.bindingModes; }, + focusWorkspace, }; } diff --git a/packages/client-api/src/providers/komorebi/create-komorebi-provider.ts b/packages/client-api/src/providers/komorebi/create-komorebi-provider.ts index b17b67ec..e498f64f 100644 --- a/packages/client-api/src/providers/komorebi/create-komorebi-provider.ts +++ b/packages/client-api/src/providers/komorebi/create-komorebi-provider.ts @@ -134,7 +134,7 @@ export async function createKomorebiProvider( y: monitors.currentMonitor!.y, }; - // Get Komorebi monitor that corresponds to the window's monitor. + // Get Komorebi monitor that corresponds to the Zebar window's monitor. const currentKomorebiMonitor = state.allMonitors.reduce((a, b) => getCoordinateDistance(currentPosition, { x: a.workAreaSize.left, diff --git a/packages/client-api/src/user-config/window/provider-config.model.ts b/packages/client-api/src/user-config/window/provider-config.model.ts index 3cb4dfff..456ea494 100644 --- a/packages/client-api/src/user-config/window/provider-config.model.ts +++ b/packages/client-api/src/user-config/window/provider-config.model.ts @@ -5,7 +5,7 @@ import { BatteryProviderConfigSchema, CpuProviderConfigSchema, DateProviderConfigSchema, - GlazewmProviderConfigSchema, + GlazeWmProviderConfigSchema, HostProviderConfigSchema, IpProviderConfigSchema, KomorebiProviderConfigSchema, @@ -20,7 +20,7 @@ export const ProviderConfigSchema = z.union([ BatteryProviderConfigSchema, CpuProviderConfigSchema, DateProviderConfigSchema, - GlazewmProviderConfigSchema, + GlazeWmProviderConfigSchema, HostProviderConfigSchema, IpProviderConfigSchema, KomorebiProviderConfigSchema, diff --git a/packages/client-api/src/user-config/window/providers/glazewm-provider-config.model.ts b/packages/client-api/src/user-config/window/providers/glazewm-provider-config.model.ts index d251da7b..1e972ba1 100644 --- a/packages/client-api/src/user-config/window/providers/glazewm-provider-config.model.ts +++ b/packages/client-api/src/user-config/window/providers/glazewm-provider-config.model.ts @@ -2,10 +2,10 @@ import { z } from 'zod'; import { ProviderType } from '../provider-type.model'; -export const GlazewmProviderConfigSchema = z.object({ +export const GlazeWmProviderConfigSchema = z.object({ type: z.literal(ProviderType.GLAZEWM), }); export type GlazewmProviderConfig = z.infer< - typeof GlazewmProviderConfigSchema + typeof GlazeWmProviderConfigSchema >; diff --git a/packages/desktop/resources/sample-config.yaml b/packages/desktop/resources/sample-config.yaml index 63b6cb7e..aea6963f 100644 --- a/packages/desktop/resources/sample-config.yaml +++ b/packages/desktop/resources/sample-config.yaml @@ -66,7 +66,7 @@ window/bar: template: | - template/glazewm: + template/glazewm_workspaces: styles: | display: flex; align-items: center; @@ -75,10 +75,18 @@ window/bar: background: rgba(255, 255, 255, 0.05); margin-right: 4px; width: 30px; - height: 30px; + height: 100%; color: #ffffffe6; border: none; border-radius: 2px; + + &.focused { + background: rgba(255, 255, 255, 0.1); + } + + &.displayed { + background: rgba(255, 255, 255, 0.2); + } } providers: ['glazewm'] events: @@ -86,8 +94,13 @@ window/bar: fn_path: 'script.js#invokeMe' selector: '.workspace' template: | - @for (workspace of glazewm.workspacesOnMonitor) { - + @for (workspace of glazewm.currentWorkspaces) { + } group/center: @@ -109,6 +122,17 @@ window/bar: margin-left: 20px; } + template/glazewm_other: + providers: ['glazewm'] + template: | + {{ glazewm.bindingModes.join(' ') }} + + @if (glazewm.tilingDirection === 'horizontal') { + + } @else { + + } + template/network: providers: ['network'] template: | diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ceaf7c27..11d04c4a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -55,8 +55,8 @@ importers: specifier: 2.0.0-beta.8 version: 2.0.0-beta.8 glazewm: - specifier: 1.1.2 - version: 1.1.2 + specifier: 1.4.1 + version: 1.4.1 luxon: specifier: 3.4.4 version: 3.4.4 @@ -1047,8 +1047,8 @@ packages: git-hooks-list@3.1.0: resolution: {integrity: sha512-LF8VeHeR7v+wAbXqfgRlTSX/1BJR9Q1vEMR8JAz1cEg6GX07+zyj3sAdDvYjj/xnlIfVuGgj4qBei1K3hKH+PA==} - glazewm@1.1.2: - resolution: {integrity: sha512-7T+petWe5FulIZt3A/e2GHQh9N2mkrGbqOgkr58abqHHg+G/QaTlTPIvcXk7h5Vc0wxKsQXYtXK+mcdO8e9/qg==} + glazewm@1.4.1: + resolution: {integrity: sha512-rltNAKzTY/g8XEGR+LkyDFIhw9AOq0GW0FqT1RAe54KN738YuPR+yJ72UIDfrXwSpH1Ztb6Ii72qBQPaOjlvNg==} engines: {node: '>=12'} peerDependencies: ws: '*' @@ -2618,7 +2618,7 @@ snapshots: git-hooks-list@3.1.0: {} - glazewm@1.1.2: + glazewm@1.4.1: dependencies: tslib: 2.6.1 From f2f5fd597d5995dc9c88c908476aa25d95226b75 Mon Sep 17 00:00:00 2001 From: Lars Berger Date: Sat, 27 Jul 2024 15:04:10 +0800 Subject: [PATCH 02/11] feat: focus workspace on glazewm button click in sample config --- packages/desktop/resources/sample-config.yaml | 2 +- packages/desktop/resources/script.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/desktop/resources/sample-config.yaml b/packages/desktop/resources/sample-config.yaml index aea6963f..e59f5dd2 100644 --- a/packages/desktop/resources/sample-config.yaml +++ b/packages/desktop/resources/sample-config.yaml @@ -91,7 +91,7 @@ window/bar: providers: ['glazewm'] events: - type: 'click' - fn_path: 'script.js#invokeMe' + fn_path: 'script.js#focusWorkspace' selector: '.workspace' template: | @for (workspace of glazewm.currentWorkspaces) { diff --git a/packages/desktop/resources/script.js b/packages/desktop/resources/script.js index 1a2e6ee7..a1801a61 100644 --- a/packages/desktop/resources/script.js +++ b/packages/desktop/resources/script.js @@ -1,3 +1,5 @@ -export function invokeMe(event, context) { - console.log('invokeMe', event, context); +export function focusWorkspace(event, context) { + console.log('Focus button clicked!', event, context); + const id = event.target.id; + context.providers.glazewm.focusWorkspace(id); } From 4ba70bfd397bc34dce03e6375f18603ecc2a70cf Mon Sep 17 00:00:00 2001 From: Lars Berger Date: Sat, 27 Jul 2024 15:04:51 +0800 Subject: [PATCH 03/11] feat: copy sample JS script resource on first run --- packages/desktop/src/user_config.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/desktop/src/user_config.rs b/packages/desktop/src/user_config.rs index 291f618b..652ac23b 100644 --- a/packages/desktop/src/user_config.rs +++ b/packages/desktop/src/user_config.rs @@ -36,6 +36,11 @@ fn create_from_sample( .resolve("resources/sample-config.yaml", BaseDirectory::Resource) .context("Unable to resolve sample config resource.")?; + let sample_script = app_handle + .path() + .resolve("resources/script.js", BaseDirectory::Resource) + .context("Unable to resolve sample script resource.")?; + let dest_dir = config_path.parent().context("Invalid config directory.")?; @@ -45,9 +50,15 @@ fn create_from_sample( })?; // Copy over sample config. - let dest_path = dest_dir.join("config.yaml"); - fs::copy(&sample_path, &dest_path).with_context(|| { - format!("Unable to write to {}.", dest_path.display()) + let config_path = dest_dir.join("config.yaml"); + fs::copy(&sample_path, &config_path).with_context(|| { + format!("Unable to write to {}.", config_path.display()) + })?; + + // Copy over sample script. + let script_path = dest_dir.join("script.js"); + fs::copy(&sample_script, &script_path).with_context(|| { + format!("Unable to write to {}.", script_path.display()) })?; Ok(()) From 9df713bf87aaa33a06f55422f74fa9d5adc62653 Mon Sep 17 00:00:00 2001 From: Lars Berger Date: Sat, 27 Jul 2024 16:40:50 +0800 Subject: [PATCH 04/11] feat: improve whitespace handling in template engine --- .../rendering/render-template-nodes.ts | 3 +- .../tokenizing/tokenize-template.ts | 30 +++++++++---------- packages/desktop/resources/sample-config.yaml | 10 +++---- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/packages/client-api/src/template-engine/rendering/render-template-nodes.ts b/packages/client-api/src/template-engine/rendering/render-template-nodes.ts index 9c736ae3..c96320d1 100644 --- a/packages/client-api/src/template-engine/rendering/render-template-nodes.ts +++ b/packages/client-api/src/template-engine/rendering/render-template-nodes.ts @@ -162,5 +162,6 @@ export function renderTemplateNodes( ); } - return visitAll(nodes); + // Render and trim any leading/trailing whitespace. + return visitAll(nodes).trim(); } diff --git a/packages/client-api/src/template-engine/tokenizing/tokenize-template.ts b/packages/client-api/src/template-engine/tokenizing/tokenize-template.ts index fbaad964..68c60b17 100644 --- a/packages/client-api/src/template-engine/tokenizing/tokenize-template.ts +++ b/packages/client-api/src/template-engine/tokenizing/tokenize-template.ts @@ -96,36 +96,36 @@ export function tokenizeTemplate(template: string): Token[] { } function tokenizeDefault() { - if (scanner.scan(/\s+/)) { - // Ignore whitespace between tokens. - } else if (scanner.scan(/@if/)) { + if (scanner.scan(/\s*@if/)) { pushToken(TokenType.IF_STATEMENT); pushState(TokenizeStateType.IN_STATEMENT_ARGS); - } else if (scanner.scan(/@else\s+if/)) { + } else if (scanner.scan(/\s*@else\s+if/)) { pushToken(TokenType.ELSE_IF_STATEMENT); pushState(TokenizeStateType.IN_STATEMENT_ARGS); - } else if (scanner.scan(/@else/)) { + } else if (scanner.scan(/\s*@else/)) { pushToken(TokenType.ELSE_STATEMENT); pushState(TokenizeStateType.IN_STATEMENT_ARGS); - } else if (scanner.scan(/@for/)) { + } else if (scanner.scan(/\s*@for/)) { pushToken(TokenType.FOR_STATEMENT); pushState(TokenizeStateType.IN_STATEMENT_ARGS); - } else if (scanner.scan(/@switch/)) { + } else if (scanner.scan(/\s*@switch/)) { pushToken(TokenType.SWITCH_STATEMENT); pushState(TokenizeStateType.IN_STATEMENT_ARGS); - } else if (scanner.scan(/@case/)) { + } else if (scanner.scan(/\s*@case/)) { pushToken(TokenType.SWITCH_CASE_STATEMENT); pushState(TokenizeStateType.IN_STATEMENT_ARGS); - } else if (scanner.scan(/@default/)) { + } else if (scanner.scan(/\s*@default/)) { pushToken(TokenType.SWITCH_DEFAULT_STATEMENT); pushState(TokenizeStateType.IN_STATEMENT_ARGS); - } else if (scanner.scan(/{{/)) { + } else if (scanner.scan(/(?:[\n\r\v\f\t]+\s*|){{/)) { + // Ignore newlines before interpolation tag. Spaces are not ignored + // for when the interpolation tag is mixed in with text tokens. pushToken(TokenType.OPEN_INTERPOLATION); pushState(TokenizeStateType.IN_INTERPOLATION); } else if (scanner.scanUntil(/[\S\s]+?(?={{|@|\})/)) { // Search until a close block, the start of a statement, or the start - // of an interpolation tag. In a JavaScript regex, the . character - // does not match new line characters, so we instead use [\S\s]. + // of an interpolation tag. In a JavaScript regex, the `.` character + // does not match newline characters, so we instead use [\S\s]. pushToken({ type: TokenType.TEXT, ...scanner.latestMatch!, @@ -144,7 +144,7 @@ export function tokenizeTemplate(template: string): Token[] { closeRegex: /[\S\s]+?(?=\))/, activeWrappingSymbol: null, }); - } else if (scanner.scan(/{/)) { + } else if (scanner.scan(/{\s*/)) { pushToken(TokenType.OPEN_BLOCK); stateStack.pop(); pushState(TokenizeStateType.IN_STATEMENT_BLOCK); @@ -157,7 +157,7 @@ export function tokenizeTemplate(template: string): Token[] { } function tokenizeStatementBlock() { - if (scanner.scan(/}/)) { + if (scanner.scan(/}\s*/)) { pushToken(TokenType.CLOSE_BLOCK); stateStack.pop(); } else { @@ -168,7 +168,7 @@ export function tokenizeTemplate(template: string): Token[] { function tokenizeInterpolation() { if (scanner.scan(/\s+/)) { // Ignore whitespace within interpolation tag. - } else if (scanner.scan(/}}/)) { + } else if (scanner.scan(/}}(?:[\n\r\v\f\t]+\s*|)/)) { pushToken(TokenType.CLOSE_INTERPOLATION); stateStack.pop(); } else if (scanner.scan(/[\S\s]*?/)) { diff --git a/packages/desktop/resources/sample-config.yaml b/packages/desktop/resources/sample-config.yaml index e59f5dd2..d7ab7586 100644 --- a/packages/desktop/resources/sample-config.yaml +++ b/packages/desktop/resources/sample-config.yaml @@ -140,11 +140,11 @@ window/bar: @if (network.defaultInterface?.type === 'ethernet') { } @else if (network.defaultInterface?.type === 'wifi') { - @if (network.defaultGateway?.signalStrength >= 80) { } - @else if (network.defaultGateway?.signalStrength >= 65) { } - @else if (network.defaultGateway?.signalStrength >= 40) { } - @else if (network.defaultGateway?.signalStrength >= 25) { } - @else { } + @if (network.defaultGateway?.signalStrength >= 80) {} + @else if (network.defaultGateway?.signalStrength >= 65) {} + @else if (network.defaultGateway?.signalStrength >= 40) {} + @else if (network.defaultGateway?.signalStrength >= 25) {} + @else {} {{ network.defaultGateway?.ssid }} } @else { From c97e46f46aa9fe6b99764b677179960d9e2ce34e Mon Sep 17 00:00:00 2001 From: Lars Berger Date: Sun, 28 Jul 2024 02:25:07 +0800 Subject: [PATCH 05/11] feat: add binding modes + tiling direction to sample config --- .../glazewm/create-glazewm-provider.ts | 9 ++- packages/desktop/resources/sample-config.yaml | 55 +++++++++++-------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/packages/client-api/src/providers/glazewm/create-glazewm-provider.ts b/packages/client-api/src/providers/glazewm/create-glazewm-provider.ts index e58b4f7e..56185fb3 100644 --- a/packages/client-api/src/providers/glazewm/create-glazewm-provider.ts +++ b/packages/client-api/src/providers/glazewm/create-glazewm-provider.ts @@ -2,6 +2,7 @@ import { TilingDirection, WmClient, WmEventType, + type BindingModeConfig, type BindingModesChangedEvent, type Container, type FocusChangedEvent, @@ -69,7 +70,7 @@ export interface GlazeWmProvider { /** * Active binding modes; */ - bindingModes: string[]; + bindingModes: BindingModeConfig[]; /** * Focus a workspace by name. @@ -122,9 +123,7 @@ export async function createGlazeWmProvider( ) { switch (e.eventType) { case WmEventType.BINDING_MODES_CHANGED: { - setGlazeWmVariables({ - bindingModes: e.newBindingModes.map(mode => mode.name), - }); + setGlazeWmVariables({ bindingModes: e.newBindingModes }); break; } case WmEventType.FOCUS_CHANGED: @@ -155,7 +154,7 @@ export async function createGlazeWmProvider( ...(await getMonitorState()), focusedContainer: focused, tilingDirection, - bindingModes: bindingModes.map(mode => mode.name), + bindingModes, }; } diff --git a/packages/desktop/resources/sample-config.yaml b/packages/desktop/resources/sample-config.yaml index d7ab7586..09d14da6 100644 --- a/packages/desktop/resources/sample-config.yaml +++ b/packages/desktop/resources/sample-config.yaml @@ -1,16 +1,8 @@ # Yaml is white-space sensitive (use 2 spaces to indent). -### -# Settings to apply to all windows. -# -# Docs regarding global: https://some-future-docs-link.com -global: - # Whether to enable the browser devtools. - enable_devtools: true - ### # Define a new window with an id of 'bar'. This window can then be opened -# via the Zebar cli by running 'zebar open bar'. +# via the Zebar cli by running 'zebar open bar --args '. # # Docs regarding window: https://some-future-docs-link.com window/bar: @@ -43,15 +35,15 @@ window/bar: grid-template-columns: 1fr 1fr 1fr; align-items: center; height: 100%; - color: #ffffffe6; + color: rgb(255 255 255 / 90%); font-family: ui-monospace, monospace; font-size: 12px; padding: 4px 24px; - border-bottom: 1px solid #ffffff08; - background: linear-gradient(rgba(0, 0, 0, 0.9), rgba(4, 1, 18, 0.85)); + border-bottom: 1px solid rgb(255 255 255 / 5%);; + background: linear-gradient(rgb(0 0 0 / 90%), rgb(5 2 20 / 85%)); i { - color: #7481b2e1; + color: rgb(115 130 175 / 95%); margin-right: 7px; } @@ -72,20 +64,21 @@ window/bar: align-items: center; .workspace { - background: rgba(255, 255, 255, 0.05); + background: rgb(255 255 255 / 5%); margin-right: 4px; - width: 30px; - height: 100%; - color: #ffffffe6; + padding: 4px 8px; + color: rgb(255 255 255 / 90%); border: none; border-radius: 2px; + cursor: pointer; - &.focused { - background: rgba(255, 255, 255, 0.1); + &.displayed { + background: rgb(255 255 255 / 15%); } - &.displayed { - background: rgba(255, 255, 255, 0.2); + &.focused, + &:hover { + background: rgb(75 115 255 / 50%); } } providers: ['glazewm'] @@ -124,13 +117,27 @@ window/bar: template/glazewm_other: providers: ['glazewm'] + styles: | + .binding-mode, + .tiling-direction { + background: rgb(255 255 255 / 15%); + color: rgb(255 255 255 / 90%); + border-radius: 2px; + padding: 4px 6px; + margin: 0; + } + template: | - {{ glazewm.bindingModes.join(' ') }} + @for (bindingMode of glazewm.bindingModes) { + + {{ bindingMode.displayName ?? bindingMode.name }} + + } @if (glazewm.tilingDirection === 'horizontal') { - + } @else { - + } template/network: From 2915d797ba2a97bdd7e4203e588d384fc26a582f Mon Sep 17 00:00:00 2001 From: Lars Berger Date: Sun, 28 Jul 2024 02:47:43 +0800 Subject: [PATCH 06/11] ci: update versions of 3d-party workflow actions --- .github/workflows/build.yaml | 6 +++--- .github/workflows/lint-check.yaml | 6 +++--- .github/workflows/release.yaml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 15bb7746..05050a2e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -35,7 +35,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: version: 9 @@ -44,12 +44,12 @@ jobs: node-version: 20 cache: pnpm - - uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248 + - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 with: toolchain: nightly targets: ${{ matrix.rust-targets }} - - uses: swatinem/rust-cache@988c164c3d0e93c4dbab36aaf5bbeb77425b2894 + - uses: swatinem/rust-cache@9bdad043e88c75890e36ad3bbc8d27f0090dd609 with: shared-key: ${{ matrix.tauri-target }}-${{ hashFiles('Cargo.lock') }} diff --git a/.github/workflows/lint-check.yaml b/.github/workflows/lint-check.yaml index 37fcb1fc..db8e2dfc 100644 --- a/.github/workflows/lint-check.yaml +++ b/.github/workflows/lint-check.yaml @@ -8,7 +8,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: version: 9 @@ -17,12 +17,12 @@ jobs: node-version: 20 cache: pnpm - - uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248 + - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 with: toolchain: nightly components: rustfmt - - uses: swatinem/rust-cache@988c164c3d0e93c4dbab36aaf5bbeb77425b2894 + - uses: swatinem/rust-cache@9bdad043e88c75890e36ad3bbc8d27f0090dd609 - run: pnpm i - run: pnpm run lint diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 1c06536b..49191a5c 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -42,7 +42,7 @@ jobs: pattern: bundle-** path: tmp - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: version: 8 From 55ccc67794b4374d4d958c09be3a2ad5f9ccd810 Mon Sep 17 00:00:00 2001 From: Lars Berger Date: Sun, 28 Jul 2024 02:50:46 +0800 Subject: [PATCH 07/11] ci: use pnpm version from `package.json` in setup workflow --- .github/workflows/build.yaml | 2 -- .github/workflows/lint-check.yaml | 2 -- .github/workflows/release.yaml | 2 -- 3 files changed, 6 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 05050a2e..8008f249 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -36,8 +36,6 @@ jobs: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 - with: - version: 9 - uses: actions/setup-node@v4 with: diff --git a/.github/workflows/lint-check.yaml b/.github/workflows/lint-check.yaml index db8e2dfc..08cbaf76 100644 --- a/.github/workflows/lint-check.yaml +++ b/.github/workflows/lint-check.yaml @@ -9,8 +9,6 @@ jobs: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 - with: - version: 9 - uses: actions/setup-node@v4 with: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 49191a5c..c17984b6 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -43,8 +43,6 @@ jobs: path: tmp - uses: pnpm/action-setup@v4 - with: - version: 8 - uses: actions/setup-node@v4 with: From 7cf21ba8b49fc0538fb2f19fdd18ac01d2fc9c06 Mon Sep 17 00:00:00 2001 From: Lars Berger Date: Sun, 28 Jul 2024 03:31:34 +0800 Subject: [PATCH 08/11] fix: CSP fix to allow local JS scripts to be loaded --- packages/desktop/tauri.conf.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/desktop/tauri.conf.json b/packages/desktop/tauri.conf.json index 9a4291ab..82aa17e8 100644 --- a/packages/desktop/tauri.conf.json +++ b/packages/desktop/tauri.conf.json @@ -39,10 +39,10 @@ "csp": { "default-src": "'self'", "style-src": "'self' 'unsafe-inline' *", - "script-src": "'self' 'unsafe-eval'", + "script-src": "'self' 'unsafe-eval' asset: http://asset.localhost", "connect-src": "'self' ipc: http://ipc.localhost ws://localhost:6123", "font-src": "'self' *", - "img-src": "'self' asset: blob: data: *" + "img-src": "'self' asset: http://asset.localhost blob: data: *" }, "assetProtocol": { "enable": true, From e7985dc7bc3ff081b36e8fdad10c55f663c97ff1 Mon Sep 17 00:00:00 2001 From: Lars Berger Date: Sun, 28 Jul 2024 16:28:25 +0800 Subject: [PATCH 09/11] feat: add MSI flag for optionally adding glazewm starter files --- packages/desktop/installer.wxs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/desktop/installer.wxs b/packages/desktop/installer.wxs index a61a00cd..f6284289 100644 --- a/packages/desktop/installer.wxs +++ b/packages/desktop/installer.wxs @@ -72,6 +72,9 @@ + + + @@ -121,6 +124,19 @@ + + + + + ADD_GLAZEWM_STARTER = 1 + + + + + + + + @@ -281,6 +297,8 @@ {{/if}} + + Date: Sun, 28 Jul 2024 16:28:40 +0800 Subject: [PATCH 10/11] ci: add verbose Tauri build logs --- packages/desktop/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop/package.json b/packages/desktop/package.json index aff8a5be..7ca6f3dd 100644 --- a/packages/desktop/package.json +++ b/packages/desktop/package.json @@ -2,7 +2,7 @@ "name": "@zebar/desktop", "version": "0.0.0", "scripts": { - "build": "npm run tauri build", + "build": "npm run tauri build -- --verbose", "dev": "npm run -s monitors -- --print0 | xargs -0 -P 99 -I % sh -c 'npm run tauri dev -- -- -- open bar --args %'", "format": "cargo fmt", "lint": "cargo fmt --check", From 77a6aa44681cab703cd9e2b6989149980ddf30f7 Mon Sep 17 00:00:00 2001 From: Lars Berger Date: Sun, 28 Jul 2024 16:35:12 +0800 Subject: [PATCH 11/11] feat: never overwrite starter config on install --- packages/desktop/installer.wxs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop/installer.wxs b/packages/desktop/installer.wxs index f6284289..6ba3cf3e 100644 --- a/packages/desktop/installer.wxs +++ b/packages/desktop/installer.wxs @@ -127,7 +127,7 @@ - + ADD_GLAZEWM_STARTER = 1