mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-17 23:01:04 +02:00
feat(workspaces): niri support
Co-authored-by: Jake Stanger <mail@jstanger.dev>
This commit is contained in:
parent
57bfab1dcc
commit
02a8ddabf0
12 changed files with 367 additions and 31 deletions
|
@ -22,9 +22,8 @@ impl Button {
|
|||
|
||||
let tx = context.tx.clone();
|
||||
|
||||
let name = name.to_string();
|
||||
button.connect_clicked(move |_item| {
|
||||
try_send!(tx, name.clone());
|
||||
try_send!(tx, id);
|
||||
});
|
||||
|
||||
let btn = Self {
|
||||
|
|
|
@ -12,6 +12,7 @@ pub enum Identifier {
|
|||
/// Wrapper around a hashmap of workspace buttons,
|
||||
/// which can be found using the workspace ID,
|
||||
/// or their name for favourites.
|
||||
#[derive(Debug)]
|
||||
pub struct ButtonMap {
|
||||
map: HashMap<Identifier, Button>,
|
||||
}
|
||||
|
|
|
@ -66,7 +66,8 @@ pub struct WorkspacesModule {
|
|||
///
|
||||
/// If a workspace is not present in the map,
|
||||
/// it will fall back to using its actual name.
|
||||
name_map: Option<HashMap<String, String>>,
|
||||
#[serde(default)]
|
||||
name_map: HashMap<String, String>,
|
||||
|
||||
/// Workspaces which should always be shown.
|
||||
/// This can either be an array of workspace names,
|
||||
|
@ -140,7 +141,7 @@ pub struct WorkspaceItemContext {
|
|||
name_map: HashMap<String, String>,
|
||||
icon_theme: IconTheme,
|
||||
icon_size: i32,
|
||||
tx: mpsc::Sender<String>,
|
||||
tx: mpsc::Sender<i64>,
|
||||
}
|
||||
|
||||
/// Re-orders the container children alphabetically,
|
||||
|
@ -182,7 +183,7 @@ fn reorder_workspaces(container: >k::Box, sort_order: SortOrder) {
|
|||
|
||||
impl Module<gtk::Box> for WorkspacesModule {
|
||||
type SendMessage = WorkspaceUpdate;
|
||||
type ReceiveMessage = String;
|
||||
type ReceiveMessage = i64;
|
||||
|
||||
module_impl!("workspaces");
|
||||
|
||||
|
@ -212,8 +213,8 @@ impl Module<gtk::Box> for WorkspacesModule {
|
|||
spawn(async move {
|
||||
trace!("Setting up UI event handler");
|
||||
|
||||
while let Some(name) = rx.recv().await {
|
||||
client.focus(name.clone());
|
||||
while let Some(id) = rx.recv().await {
|
||||
client.focus(id);
|
||||
}
|
||||
|
||||
Ok::<(), Report>(())
|
||||
|
@ -229,12 +230,10 @@ impl Module<gtk::Box> for WorkspacesModule {
|
|||
) -> Result<ModuleParts<gtk::Box>> {
|
||||
let container = gtk::Box::new(info.bar_position.orientation(), 0);
|
||||
|
||||
let name_map = self.name_map.clone().unwrap_or_default();
|
||||
|
||||
let mut button_map = ButtonMap::new();
|
||||
|
||||
let item_context = WorkspaceItemContext {
|
||||
name_map,
|
||||
name_map: self.name_map.clone(),
|
||||
icon_theme: info.icon_theme.clone(),
|
||||
icon_size: self.icon_size,
|
||||
tx: context.controller_tx.clone(),
|
||||
|
@ -312,6 +311,7 @@ impl Module<gtk::Box> for WorkspacesModule {
|
|||
};
|
||||
}
|
||||
|
||||
let name_map = self.name_map;
|
||||
let mut handle_event = move |event: WorkspaceUpdate| match event {
|
||||
WorkspaceUpdate::Init(workspaces) => {
|
||||
if has_initialized {
|
||||
|
@ -381,7 +381,9 @@ impl Module<gtk::Box> for WorkspacesModule {
|
|||
.or_else(|| button_map.get(&Identifier::Name(name.clone())))
|
||||
.map(Button::button)
|
||||
{
|
||||
button.set_label(&name);
|
||||
let display_name = name_map.get(&name).unwrap_or(&name);
|
||||
|
||||
button.set_label(display_name);
|
||||
button.set_widget_name(&name);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue