Skip to content

Commit

Permalink
feat: flatten launchOptions in config
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Sep 26, 2024
1 parent 0f2c376 commit f4bf1c7
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 125 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ When Zebar is first launched, a set of default widget configs are generated to `

To create a new widget, simply copy its config file into the `%userprofile%/.glzr/zebar` directory.

Widgets are powered by native webviews (_similar_ to Electron, but less resource heavy). Every widget has its own config file and a corresponding HTML file for the markup and styling of the window. This is an ordinary HTML file, so any frontend framework (React, Angular, Vue, etc.) can be used.
Widgets are powered by native webviews (_similar_ to Electron, but less resource heavy). Every widget has its own config file and a corresponding HTML file for the markup and styling of the widget. This is an ordinary HTML file, so any frontend framework (React, Angular, Vue, etc.) can be used.

Zebar exposes various system information (refered to as "providers") which can be used and displayed by your frontend. This includes stats like CPU usage, battery info, various window manager integrations, and lots more.

Expand Down Expand Up @@ -134,7 +134,7 @@ No config options.
| `allWorkspaces` | Workspaces across all monitors. | `Workspace[]` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `allMonitors` | All monitors. | `Monitor[]` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `focusedMonitor` | Monitor that currently has focus. | `Monitor` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `currentMonitor` | Monitor that is nearest to this Zebar window. | `Monitor` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `currentMonitor` | Monitor that is nearest to this Zebar widget. | `Monitor` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `focusedContainer` | Container that currently has focus (on any monitor). | `Container` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `tilingDirection` | Tiling direction of the focused container. | `TilingDirection` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `bindingModes` | Active binding modes; | `BindingModeConfig[]` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
Expand Down Expand Up @@ -268,7 +268,7 @@ No config options.
| `allWorkspaces` | Workspaces across all monitors. | `KomorebiWorkspace[]` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `allMonitors` | All monitors. | `KomorebiMonitor[]` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `focusedMonitor` | Monitor that currently has focus. | `KomorebiMonitor` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `currentMonitor` | Monitor that is nearest to this Zebar window. | `KomorebiMonitor` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |
| `currentMonitor` | Monitor that is nearest to this Zebar widget. | `KomorebiMonitor` | <img src="https://github.com/glzr-io/zebar/assets/34844898/568e90c8-cd32-49a5-a17f-ab233d41f1aa" alt="microsoft icon" width="24"> |


### Weather
Expand Down
36 changes: 17 additions & 19 deletions examples/boilerplates/react-buildless/my-window.zebar.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
{
"$schema": "TODO",
"$schema": "https://github.com/glzr-io/zebar/raw/v2.1.0/resources/widget-schema.json",
"htmlPath": "./index.html",
"launchOptions": {
"zOrder": "normal",
"shownInTaskbar": false,
"focused": false,
"resizable": false,
"transparent": false,
"placements": [
{
"anchor": "top_left",
"offsetX": "0px",
"offsetY": "0px",
"width": "100%",
"height": "40px",
"monitorSelection": {
"type": "all"
}
"zOrder": "normal",
"shownInTaskbar": false,
"focused": false,
"resizable": false,
"transparent": false,
"defaultPlacements": [
{
"anchor": "top_left",
"offsetX": "0px",
"offsetY": "0px",
"width": "100%",
"height": "40px",
"monitorSelection": {
"type": "all"
}
]
}
}
]
}
36 changes: 17 additions & 19 deletions examples/boilerplates/solid-ts/my-window.zebar.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
{
"$schema": "TODO",
"$schema": "https://github.com/glzr-io/zebar/raw/v2.1.0/resources/widget-schema.json",
"htmlPath": "./dist/index.html",
"launchOptions": {
"zOrder": "normal",
"shownInTaskbar": false,
"focused": false,
"resizable": false,
"transparent": false,
"placements": [
{
"anchor": "top_left",
"offsetX": "0px",
"offsetY": "0px",
"width": "100%",
"height": "40px",
"monitorSelection": {
"type": "all"
}
"zOrder": "normal",
"shownInTaskbar": false,
"focused": false,
"resizable": false,
"transparent": false,
"defaultPlacements": [
{
"anchor": "top_left",
"offsetX": "0px",
"offsetY": "0px",
"width": "100%",
"height": "40px",
"monitorSelection": {
"type": "all"
}
]
}
}
]
}
16 changes: 0 additions & 16 deletions examples/boilerplates/solid-ts/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@ import { render } from 'solid-js/web';
import { createStore } from 'solid-js/store';
import * as zebar from 'zebar';

// import { init } from 'zebar';
// const zebarCtx = await init();

// zebarCtx.widgets.start('./starter/vanilla');
// zebarCtx.startWidget('./starter/vanilla');
// zebarCtx.currentInstance.tauri.setZOrder('alwaysOnTop');

// zebarCtx.instanceId;
// zebarCtx.config;
// zebarCtx.currentWidget.tauriWindow.getPosition();
// zebarCtx.setZOrder('always_on_top');

const providers = await zebar.createProviderGroup({
cpu: { type: 'cpu' },
battery: { type: 'battery' },
Expand All @@ -24,10 +12,6 @@ const providers = await zebar.createProviderGroup({
keyboard: { type: 'keyboard' },
});

const monitor = zebar.currentMonitor();
const window = zebar.currentWindow();
const widget = zebar.currentWidget();

render(() => <App />, document.getElementById('root')!);

function App() {
Expand Down
36 changes: 17 additions & 19 deletions examples/starter/with-glazewm.zebar.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
{
"$schema": "TODO",
"$schema": "https://github.com/glzr-io/zebar/raw/v2.1.0/resources/widget-schema.json",
"htmlPath": "./with-glazewm.html",
"launchOptions": {
"zOrder": "normal",
"shownInTaskbar": false,
"focused": false,
"resizable": false,
"transparent": false,
"placements": [
{
"anchor": "top_left",
"offsetX": "0px",
"offsetY": "0px",
"width": "100%",
"height": "40px",
"monitorSelection": {
"type": "all"
}
"zOrder": "normal",
"shownInTaskbar": false,
"focused": false,
"resizable": false,
"transparent": false,
"defaultPlacements": [
{
"anchor": "top_left",
"offsetX": "0px",
"offsetY": "0px",
"width": "100%",
"height": "40px",
"monitorSelection": {
"type": "all"
}
]
}
}
]
}
36 changes: 17 additions & 19 deletions examples/starter/with-komorebi.zebar.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
{
"$schema": "TODO",
"$schema": "https://github.com/glzr-io/zebar/raw/v2.1.0/resources/widget-schema.json",
"htmlPath": "./with-komorebi.html",
"launchOptions": {
"zOrder": "normal",
"shownInTaskbar": false,
"focused": false,
"resizable": false,
"transparent": false,
"placements": [
{
"anchor": "top_left",
"offsetX": "0px",
"offsetY": "0px",
"width": "100%",
"height": "40px",
"monitorSelection": {
"type": "all"
}
"zOrder": "normal",
"shownInTaskbar": false,
"focused": false,
"resizable": false,
"transparent": false,
"defaultPlacements": [
{
"anchor": "top_left",
"offsetX": "0px",
"offsetY": "0px",
"width": "100%",
"height": "40px",
"monitorSelection": {
"type": "all"
}
]
}
}
]
}
2 changes: 1 addition & 1 deletion packages/client-api/src/desktop/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface Window {
readonly tauri: ReturnType<typeof getCurrentWindow>;

/**
* Sets the z-order of the window.
* Sets the z-order of the Tauri window.
*/
setZOrder(zOrder: ZOrder): Promise<void>;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/client-api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './providers';
export {
currentWindow,
currentWidget,
currentWindow,
startWidget,
type Widget,
type Window,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface GlazeWmOutput {
focusedMonitor: Monitor;

/**
* Monitor that is nearest to this Zebar window.
* Monitor that is nearest to this Zebar widget.
*/
currentMonitor: Monitor;

Expand Down Expand Up @@ -213,7 +213,7 @@ export async function createGlazeWmProvider(

const { monitors: glazeWmMonitors } = await client.queryMonitors();

// Get GlazeWM monitor that corresponds to the Zebar window's monitor.
// Get GlazeWM monitor that corresponds to the widget's monitor.
const currentGlazeWmMonitor = glazeWmMonitors.reduce((a, b) =>
getCoordinateDistance(currentPosition, a) <
getCoordinateDistance(currentPosition, b)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface KomorebiOutput {
focusedMonitor: KomorebiMonitor;

/**
* Monitor that is nearest to this Zebar window.
* Monitor that is nearest to this Zebar widget.
*/
currentMonitor: KomorebiMonitor;
}
Expand Down
31 changes: 12 additions & 19 deletions packages/desktop/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,37 @@ pub struct WidgetConfig {
/// Relative path to entry point HTML file.
pub html_path: PathBuf,

/// Default options for when the window is opened.
pub launch_options: WidgetLaunchOptions,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WidgetLaunchOptions {
/// Whether to show the window above/below all others.
/// Whether to show the Tauri window above/below all others.
pub z_order: ZOrder,

/// Whether the window should be shown in the taskbar.
/// Whether the Tauri window should be shown in the taskbar.
pub shown_in_taskbar: bool,

/// Whether the window should be focused when opened.
/// Whether the Tauri window should be focused when opened.
pub focused: bool,

/// Whether the window should have resize handles.
/// Whether the Tauri window should have resize handles.
pub resizable: bool,

/// Whether the window frame should be transparent.
/// Whether the Tauri window frame should be transparent.
pub transparent: bool,

/// Where to place the widget.
pub placements: Vec<WidgetPlacement>,
pub default_placements: Vec<WidgetPlacement>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum ZOrder {
AlwaysOnBottom,
AlwaysOnTop,
BottomMost,
Normal,
TopMost,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WidgetPlacement {
/// Anchor-point of the window.
/// Anchor-point of the widget.
pub anchor: AnchorPoint,

/// Offset from the anchor-point.
Expand All @@ -81,13 +74,13 @@ pub struct WidgetPlacement {
/// Offset from the anchor-point.
pub offset_y: LengthValue,

/// Width of the window in % or physical pixels.
/// Width of the widget in % or physical pixels.
pub width: LengthValue,

/// Height of the window in % or physical pixels.
/// Height of the widget in % or physical pixels.
pub height: LengthValue,

/// Monitor(s) to place the window on.
/// Monitor(s) to place the widget on.
pub monitor_selection: MonitorSelection,
}

Expand Down
12 changes: 6 additions & 6 deletions packages/desktop/src/widget_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ impl WidgetFactory {
.title("Zebar")
.inner_size(size.width, size.height)
.position(position.x, position.y)
.focused(config.launch_options.focused)
.skip_taskbar(!config.launch_options.shown_in_taskbar)
.focused(config.focused)
.skip_taskbar(!config.shown_in_taskbar)
.visible_on_all_workspaces(true)
.transparent(config.launch_options.transparent)
.transparent(config.transparent)
.shadow(false)
.decorations(false)
.resizable(config.launch_options.resizable)
.resizable(config.resizable)
.build()?;

let state = WidgetState {
Expand All @@ -168,7 +168,7 @@ impl WidgetFactory {
let _ = window
.as_ref()
.window()
.set_tool_window(!config.launch_options.shown_in_taskbar);
.set_tool_window(!config.shown_in_taskbar);

// On Windows, there's an issue where the window size is constrained
// when initially created. To work around this, apply the size and
Expand Down Expand Up @@ -236,7 +236,7 @@ impl WidgetFactory {
) -> Vec<(LogicalSize<f64>, LogicalPosition<f64>)> {
let mut placements = vec![];

for placement in config.launch_options.placements.iter() {
for placement in config.default_placements.iter() {
let monitors = self
.monitor_state
.monitors_by_selection(&placement.monitor_selection)
Expand Down

0 comments on commit f4bf1c7

Please sign in to comment.