mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-01 10:41:03 +02:00
feat: IPC for get_visible, set_visible, new bar name
config option
This commit is contained in:
parent
2f8443f349
commit
2ccb2633c6
6 changed files with 93 additions and 15 deletions
|
@ -268,7 +268,8 @@ Check [here](config) for an example config file for a fully configured bar in ea
|
||||||
The following table lists each of the top-level bar config options:
|
The following table lists each of the top-level bar config options:
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|--------------------|----------------------------------------|-----------|-----------------------------------------------------------------------------------------|
|
|--------------------|----------------------------------------|-----------|-----------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `name` | `string` | `bar-<n>` | A unique identifier for the bar, used for controlling it over IPC. If not set, uses a generated integer suffix. |
|
||||||
| `position` | `top` or `bottom` or `left` or `right` | `bottom` | The bar's position on screen. |
|
| `position` | `top` or `bottom` or `left` or `right` | `bottom` | The bar's position on screen. |
|
||||||
| `anchor_to_edges` | `boolean` | `false` | Whether to anchor the bar to the edges of the screen. Setting to false centres the bar. |
|
| `anchor_to_edges` | `boolean` | `false` | Whether to anchor the bar to the edges of the screen. Setting to false centres the bar. |
|
||||||
| `height` | `integer` | `42` | The bar's height in pixels. |
|
| `height` | `integer` | `42` | The bar's height in pixels. |
|
||||||
|
|
|
@ -111,6 +111,33 @@ Responds with `ok` if the stylesheet exists, otherwise `error`.
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `set_visible`
|
||||||
|
|
||||||
|
Sets a bar's visibility.
|
||||||
|
|
||||||
|
Responds with `ok` if the bar exists, otherwise `error`.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "set_visible",
|
||||||
|
"bar_name": "bar-123",
|
||||||
|
"visible": true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### `get_visible`
|
||||||
|
|
||||||
|
Gets a bar's visibility.
|
||||||
|
|
||||||
|
Responds with `ok_value` and the visibility (`true`/`false`) if the bar exists, otherwise `error`.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "get_visible",
|
||||||
|
"bar_name": "bar-123"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Responses
|
## Responses
|
||||||
|
|
||||||
### `ok`
|
### `ok`
|
||||||
|
|
|
@ -21,6 +21,13 @@ pub fn create_bar(
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let win = ApplicationWindow::builder().application(app).build();
|
let win = ApplicationWindow::builder().application(app).build();
|
||||||
|
let bar_name = config
|
||||||
|
.name
|
||||||
|
.clone()
|
||||||
|
.unwrap_or_else(|| format!("bar-{}", get_unique_usize()));
|
||||||
|
|
||||||
|
win.set_widget_name(&bar_name);
|
||||||
|
info!("Creating bar {}", bar_name);
|
||||||
|
|
||||||
setup_layer_shell(
|
setup_layer_shell(
|
||||||
&win,
|
&win,
|
||||||
|
|
|
@ -97,6 +97,7 @@ pub struct Config {
|
||||||
pub margin: MarginConfig,
|
pub margin: MarginConfig,
|
||||||
#[serde(default = "default_popup_gap")]
|
#[serde(default = "default_popup_gap")]
|
||||||
pub popup_gap: i32,
|
pub popup_gap: i32,
|
||||||
|
pub name: Option<String>,
|
||||||
|
|
||||||
/// GTK icon theme to use.
|
/// GTK icon theme to use.
|
||||||
pub icon_theme: Option<String>,
|
pub icon_theme: Option<String>,
|
||||||
|
@ -125,6 +126,7 @@ impl Default for Config {
|
||||||
position: Default::default(),
|
position: Default::default(),
|
||||||
height: default_bar_height(),
|
height: default_bar_height(),
|
||||||
margin: Default::default(),
|
margin: Default::default(),
|
||||||
|
name: None,
|
||||||
popup_gap: default_popup_gap(),
|
popup_gap: default_popup_gap(),
|
||||||
icon_theme: None,
|
icon_theme: None,
|
||||||
ironvar_defaults: None,
|
ironvar_defaults: None,
|
||||||
|
|
|
@ -37,4 +37,18 @@ pub enum Command {
|
||||||
/// The path to the sheet.
|
/// The path to the sheet.
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// Set the visibility of the bar with the given name.
|
||||||
|
SetVisible {
|
||||||
|
///Bar name to target.
|
||||||
|
bar_name: String,
|
||||||
|
/// The visibility status.
|
||||||
|
visible: bool,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// Get the visibility of the bar with the given name.
|
||||||
|
GetVisible {
|
||||||
|
/// Bar name to target.
|
||||||
|
bar_name: String,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,6 +146,33 @@ impl Ipc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command::Ping => Response::Ok,
|
Command::Ping => Response::Ok,
|
||||||
|
Command::SetVisible { bar_name, visible } => {
|
||||||
|
let windows = application.windows();
|
||||||
|
let found = windows
|
||||||
|
.iter()
|
||||||
|
.find(|window| window.widget_name() == bar_name);
|
||||||
|
|
||||||
|
if let Some(window) = found {
|
||||||
|
window.set_visible(visible);
|
||||||
|
Response::Ok
|
||||||
|
} else {
|
||||||
|
Response::error("Bar not found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Command::GetVisible { bar_name } => {
|
||||||
|
let windows = application.windows();
|
||||||
|
let found = windows
|
||||||
|
.iter()
|
||||||
|
.find(|window| window.widget_name() == bar_name);
|
||||||
|
|
||||||
|
if let Some(window) = found {
|
||||||
|
Response::OkValue {
|
||||||
|
value: window.is_visible().to_string(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Response::error("Bar not found")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue