-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: icon overrides #837
base: master
Are you sure you want to change the base?
feat: icon overrides #837
Changes from 3 commits
87c6801
d1b4af4
40d449e
d5e4e08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,6 +290,13 @@ pub struct BarConfig { | |
/// **Default**: `null` | ||
pub icon_theme: Option<String>, | ||
|
||
/// Map of app IDs (or classes) to icon names, | ||
/// overriding the app's default icon. | ||
/// | ||
/// **Default**; `{}` | ||
#[serde(default)] | ||
pub icon_overrides: HashMap<String, String>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gives the ability to set overrides per-bar. I'm not sure I can see a use-case for that personally - it would probably be better to have this on the Happy to keep as-is if you think otherwise though? |
||
|
||
/// An array of modules to append to the start of the bar. | ||
/// Depending on the orientation, this is either the top of the left edge. | ||
/// | ||
|
@@ -338,6 +345,7 @@ impl Default for BarConfig { | |
start_hidden: None, | ||
autohide: None, | ||
icon_theme: None, | ||
icon_overrides: HashMap::default(), | ||
start: Some(vec![ModuleConfig::Label( | ||
LabelModule::new("ℹ️ Using default config".to_string()).into(), | ||
)]), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,7 @@ impl Module<gtk::Box> for FocusedModule { | |
info: &ModuleInfo, | ||
) -> Result<ModuleParts<gtk::Box>> { | ||
let icon_theme = info.icon_theme; | ||
let icon_overrides = info.icon_overrides; | ||
|
||
let container = gtk::Box::new(info.bar_position.orientation(), 5); | ||
|
||
|
@@ -153,9 +154,15 @@ impl Module<gtk::Box> for FocusedModule { | |
|
||
{ | ||
let icon_theme = icon_theme.clone(); | ||
let icon_overrides = icon_overrides.clone(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this were to move to If it's kept at bar-level config though, I think this is fine since in most cases you'll only have 1 copy of the launcher or focused module at a time anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how icon_overrides could be used in the closure without performing a clone (letalone in an Arc). Wouldn't there be lifetime issues with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'd still need to clone, but if it were in an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant put the |
||
glib_recv!(context.subscribe(), data => { | ||
if let Some((name, id)) = data { | ||
if let Some((name, mut id)) = data { | ||
if self.show_icon { | ||
|
||
if let Some(icon) = icon_overrides.get(&id) { | ||
id = icon.clone(); | ||
} | ||
|
||
match ImageProvider::parse(&id, &icon_theme, true, self.icon_size) | ||
.map(|image| image.load_into_image(&icon)) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,7 +138,7 @@ impl Module<gtk::Box> for LauncherModule { | |
|
||
fn spawn_controller( | ||
&self, | ||
_info: &ModuleInfo, | ||
info: &ModuleInfo, | ||
context: &WidgetContext<Self::SendMessage, Self::ReceiveMessage>, | ||
mut rx: mpsc::Receiver<Self::ReceiveMessage>, | ||
) -> crate::Result<()> { | ||
|
@@ -149,24 +149,32 @@ impl Module<gtk::Box> for LauncherModule { | |
favorites | ||
.iter() | ||
.map(|app_id| { | ||
let icon_override = info | ||
.icon_overrides | ||
.get(app_id) | ||
.map_or_else(String::new, |v| v.to_string()); | ||
|
||
( | ||
app_id.to_string(), | ||
Item::new(app_id.to_string(), OpenState::Closed, true), | ||
Item::new(app_id.to_string(), icon_override, OpenState::Closed, true), | ||
) | ||
}) | ||
.collect::<IndexMap<_, _>>() | ||
}); | ||
|
||
let items = arc_mut!(items); | ||
|
||
let items2 = Arc::clone(&items); | ||
|
||
let icon_overrides = arc_mut!(info.icon_overrides.clone()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not need to be mutable. Removing the mutex will also simplify some of the code below as it removes the need to lock. |
||
let icon_overrides2 = Arc::clone(&icon_overrides); | ||
|
||
let tx = context.tx.clone(); | ||
let tx2 = context.tx.clone(); | ||
|
||
let wl = context.client::<wayland::Client>(); | ||
spawn(async move { | ||
let items = items2; | ||
let icon_overrides = icon_overrides2; | ||
let tx = tx2; | ||
|
||
let mut wlrx = wl.subscribe_toplevels(); | ||
|
@@ -180,7 +188,14 @@ impl Module<gtk::Box> for LauncherModule { | |
item.merge_toplevel(info.clone()); | ||
} | ||
None => { | ||
items.insert(info.app_id.clone(), Item::from(info.clone())); | ||
let mut item = Item::from(info.clone()); | ||
let icon_overrides = lock!(icon_overrides); | ||
|
||
if let Some(icon) = icon_overrides.get(&info.app_id) { | ||
item.icon_override = icon.clone(); | ||
} | ||
|
||
items.insert(info.app_id.clone(), item); | ||
} | ||
} | ||
} | ||
|
@@ -210,7 +225,12 @@ impl Module<gtk::Box> for LauncherModule { | |
let item = items.get_mut(&info.app_id); | ||
match item { | ||
None => { | ||
let item: Item = info.into(); | ||
let mut item: Item = info.into(); | ||
let icon_overrides = lock!(icon_overrides); | ||
|
||
if let Some(icon) = icon_overrides.get(&app_id) { | ||
item.icon_override = icon.clone(); | ||
} | ||
|
||
items.insert(app_id.clone(), item.clone()); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.