1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-08-17 23:01:04 +02:00

feat: libinput keys module

Adds a new module which shows the status of toggle mod keys (capslock, num lock, scroll lock).

Resolves #700
This commit is contained in:
Jake Stanger 2024-11-17 23:46:02 +00:00
parent 353ee92d48
commit ccfe73f6a7
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
20 changed files with 799 additions and 107 deletions

View file

@ -1,7 +1,8 @@
use super::ImageProvider;
use crate::gtk_helpers::IronbarGtkExt;
use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt};
use gtk::prelude::*;
use gtk::{Button, IconTheme, Image, Label, Orientation};
use std::ops::Deref;
#[cfg(any(feature = "music", feature = "workspaces", feature = "clipboard"))]
pub fn new_icon_button(input: &str, icon_theme: &IconTheme, size: i32) -> Button {
@ -30,26 +31,79 @@ pub fn new_icon_button(input: &str, icon_theme: &IconTheme, size: i32) -> Button
button
}
#[cfg(feature = "music")]
pub fn new_icon_label(input: &str, icon_theme: &IconTheme, size: i32) -> gtk::Box {
let container = gtk::Box::new(Orientation::Horizontal, 0);
#[cfg(any(feature = "music", feature = "keys"))]
pub struct IconLabel {
container: gtk::Box,
label: Label,
image: Image,
icon_theme: IconTheme,
size: i32,
}
#[cfg(any(feature = "music", feature = "keys"))]
impl IconLabel {
pub fn new(input: &str, icon_theme: &IconTheme, size: i32) -> Self {
let container = gtk::Box::new(Orientation::Horizontal, 0);
let label = Label::builder().use_markup(true).build();
label.add_class("icon");
label.add_class("text-icon");
if ImageProvider::is_definitely_image_input(input) {
let image = Image::new();
image.add_class("icon");
image.add_class("image");
container.add(&image);
ImageProvider::parse(input, icon_theme, false, size)
.map(|provider| provider.load_into_image(&image));
} else {
let label = Label::builder().use_markup(true).label(input).build();
label.add_class("icon");
label.add_class("text-icon");
container.add(&label);
if ImageProvider::is_definitely_image_input(input) {
ImageProvider::parse(input, icon_theme, false, size)
.map(|provider| provider.load_into_image(&image));
image.show();
} else {
label.set_text(input);
label.show();
}
Self {
container,
label,
image,
icon_theme: icon_theme.clone(),
size,
}
}
container
pub fn set_label(&self, input: Option<&str>) {
let label = &self.label;
let image = &self.image;
if let Some(input) = input {
if ImageProvider::is_definitely_image_input(input) {
ImageProvider::parse(input, &self.icon_theme, false, self.size)
.map(|provider| provider.load_into_image(image));
label.hide();
image.show();
} else {
label.set_label_escaped(input);
image.hide();
label.show();
}
} else {
label.hide();
image.hide();
}
}
}
impl Deref for IconLabel {
type Target = gtk::Box;
fn deref(&self) -> &Self::Target {
&self.container
}
}