mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-04-19 19:34:24 +02:00
feat(tray): add direction
option
This commit is contained in:
parent
d2adecb935
commit
b037a55fb7
2 changed files with 43 additions and 5 deletions
|
@ -6,7 +6,10 @@ Displays a fully interactive icon tray using the KDE `libappindicator` protocol.
|
||||||
|
|
||||||
> Type: `tray`
|
> Type: `tray`
|
||||||
|
|
||||||
***This module provides no configuration options.***
|
|
||||||
|
| Name | Type | Default | Description |
|
||||||
|
|-------------|----------|-----------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `direction` | `string` | `left_to_right` if bar is horizontal, `top_to_bottom` otherwise | Direction to display the tray items. Possible values: `top_to_bottom`, `bottom_to_top`, `left_to_right`, `right_to_left` |
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>JSON</summary>
|
<summary>JSON</summary>
|
||||||
|
@ -15,7 +18,8 @@ Displays a fully interactive icon tray using the KDE `libappindicator` protocol.
|
||||||
{
|
{
|
||||||
"end": [
|
"end": [
|
||||||
{
|
{
|
||||||
"type": "tray"
|
"type": "tray",
|
||||||
|
"direction": "top_to_bottom"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -29,6 +33,7 @@ Displays a fully interactive icon tray using the KDE `libappindicator` protocol.
|
||||||
```toml
|
```toml
|
||||||
[[end]]
|
[[end]]
|
||||||
type = "tray"
|
type = "tray"
|
||||||
|
direction = "top_to_bottom"
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
@ -39,6 +44,7 @@ type = "tray"
|
||||||
```yaml
|
```yaml
|
||||||
end:
|
end:
|
||||||
- type: "tray"
|
- type: "tray"
|
||||||
|
direction: "top_to_bottom"
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
@ -49,7 +55,10 @@ end:
|
||||||
```corn
|
```corn
|
||||||
{
|
{
|
||||||
end = [
|
end = [
|
||||||
{ type = "tray" }
|
{
|
||||||
|
type = "tray"
|
||||||
|
direction = "top_to_bottom"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -63,4 +72,4 @@ end:
|
||||||
| `.tray` | Tray widget box |
|
| `.tray` | Tray widget box |
|
||||||
| `.tray .item` | Tray icon button |
|
| `.tray .item` | Tray icon button |
|
||||||
|
|
||||||
For more information on styling, please see the [styling guide](styling-guide).
|
For more information on styling, please see the [styling guide](styling-guide).
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::modules::tray::diff::get_diffs;
|
||||||
use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext};
|
use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext};
|
||||||
use crate::{glib_recv, spawn};
|
use crate::{glib_recv, spawn};
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use gtk::prelude::*;
|
use gtk::{prelude::*, PackDirection};
|
||||||
use gtk::{IconTheme, MenuBar};
|
use gtk::{IconTheme, MenuBar};
|
||||||
use interface::TrayMenu;
|
use interface::TrayMenu;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -18,10 +18,28 @@ use tokio::sync::mpsc;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
pub struct TrayModule {
|
pub struct TrayModule {
|
||||||
|
#[serde(default, deserialize_with = "deserialize_orientation")]
|
||||||
|
pub direction: Option<PackDirection>,
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub common: Option<CommonConfig>,
|
pub common: Option<CommonConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn deserialize_orientation<'de, D>(deserializer: D) -> Result<Option<PackDirection>, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let value = Option::<String>::deserialize(deserializer)?;
|
||||||
|
value
|
||||||
|
.map(|v| match v.as_str() {
|
||||||
|
"left_to_right" => Ok(PackDirection::Ltr),
|
||||||
|
"right_to_left" => Ok(PackDirection::Rtl),
|
||||||
|
"top_to_bottom" => Ok(PackDirection::Ttb),
|
||||||
|
"bottom_to_top" => Ok(PackDirection::Btt),
|
||||||
|
_ => Err(serde::de::Error::custom("invalid value for orientation")),
|
||||||
|
})
|
||||||
|
.transpose()
|
||||||
|
}
|
||||||
|
|
||||||
impl Module<MenuBar> for TrayModule {
|
impl Module<MenuBar> for TrayModule {
|
||||||
type SendMessage = NotifierItemMessage;
|
type SendMessage = NotifierItemMessage;
|
||||||
type ReceiveMessage = NotifierItemCommand;
|
type ReceiveMessage = NotifierItemCommand;
|
||||||
|
@ -70,6 +88,17 @@ impl Module<MenuBar> for TrayModule {
|
||||||
) -> Result<ModuleParts<MenuBar>> {
|
) -> Result<ModuleParts<MenuBar>> {
|
||||||
let container = MenuBar::new();
|
let container = MenuBar::new();
|
||||||
|
|
||||||
|
let direction = self.direction.unwrap_or(
|
||||||
|
if info.bar_position.get_orientation() == gtk::Orientation::Vertical {
|
||||||
|
PackDirection::Ttb
|
||||||
|
} else {
|
||||||
|
PackDirection::Ltr
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
container.set_pack_direction(direction);
|
||||||
|
container.set_child_pack_direction(direction);
|
||||||
|
|
||||||
{
|
{
|
||||||
let container = container.clone();
|
let container = container.clone();
|
||||||
let mut menus = HashMap::new();
|
let mut menus = HashMap::new();
|
||||||
|
|
Loading…
Add table
Reference in a new issue