mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-17 14:51:04 +02:00
feat: rename sway_mode to bindmode and add Hyprland support
Signed-off-by: Rodrigodd <rodrigobatsmoraes@hotmail.com>
This commit is contained in:
parent
1e501d99d2
commit
5a5b110c7a
12 changed files with 206 additions and 76 deletions
91
src/modules/bindmode.rs
Normal file
91
src/modules/bindmode.rs
Normal file
|
@ -0,0 +1,91 @@
|
|||
use crate::clients::compositor::BindModeUpdate;
|
||||
use crate::config::{CommonConfig, LayoutConfig, TruncateMode};
|
||||
use crate::gtk_helpers::IronbarLabelExt;
|
||||
use crate::modules::{Module, ModuleInfo, ModuleParts, WidgetContext};
|
||||
use crate::{glib_recv, module_impl, module_update, send_async, spawn};
|
||||
use color_eyre::Result;
|
||||
use gtk::Label;
|
||||
use gtk::prelude::*;
|
||||
use serde::Deserialize;
|
||||
use tokio::sync::mpsc;
|
||||
use tracing::{info, trace};
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||
pub struct Bindmode {
|
||||
// -- Common --
|
||||
/// See [truncate options](module-level-options#truncate-mode).
|
||||
///
|
||||
/// **Default**: `null`
|
||||
pub truncate: Option<TruncateMode>,
|
||||
|
||||
/// See [layout options](module-level-options#layout)
|
||||
#[serde(default, flatten)]
|
||||
layout: LayoutConfig,
|
||||
|
||||
/// See [common options](module-level-options#common-options).
|
||||
#[serde(flatten)]
|
||||
pub common: Option<CommonConfig>,
|
||||
}
|
||||
|
||||
impl Module<Label> for Bindmode {
|
||||
type SendMessage = BindModeUpdate;
|
||||
type ReceiveMessage = ();
|
||||
|
||||
module_impl!("bindmode");
|
||||
|
||||
fn spawn_controller(
|
||||
&self,
|
||||
_info: &ModuleInfo,
|
||||
context: &WidgetContext<Self::SendMessage, Self::ReceiveMessage>,
|
||||
_rx: mpsc::Receiver<Self::ReceiveMessage>,
|
||||
) -> Result<()> {
|
||||
info!("Bindmode module started");
|
||||
|
||||
let client = context.try_client::<dyn crate::clients::compositor::BindModeClient>()?;
|
||||
|
||||
let tx = context.tx.clone();
|
||||
|
||||
let mut rx = client.subscribe()?;
|
||||
spawn(async move {
|
||||
while let Ok(ev) = rx.recv().await {
|
||||
module_update!(tx, ev);
|
||||
}
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn into_widget(
|
||||
self,
|
||||
context: WidgetContext<Self::SendMessage, Self::ReceiveMessage>,
|
||||
info: &ModuleInfo,
|
||||
) -> Result<ModuleParts<Label>> {
|
||||
let label = Label::builder()
|
||||
.use_markup(true)
|
||||
.angle(self.layout.angle(info))
|
||||
.justify(self.layout.justify.into())
|
||||
.build();
|
||||
|
||||
if let Some(truncate) = self.truncate {
|
||||
label.truncate(truncate);
|
||||
}
|
||||
|
||||
{
|
||||
let label = label.clone();
|
||||
|
||||
let on_mode = move |mode: BindModeUpdate| {
|
||||
trace!("mode: {:?}", mode);
|
||||
label.set_use_markup(mode.pango_markup);
|
||||
label.set_label_escaped(&mode.name);
|
||||
};
|
||||
|
||||
glib_recv!(context.subscribe(), on_mode);
|
||||
}
|
||||
|
||||
Ok(ModuleParts {
|
||||
widget: label,
|
||||
popup: None,
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue