Fix previews and setting icon theme if index name does not match folder
COSMIC uses the file name of the folder containing the theme, GTK uses the name of the theme as specified in its index file. This fixes the use of breeze icons, for example, where the folder name is breeze but the index file is Breeze.
This commit is contained in:
parent
a7d8d73c9f
commit
4e7eb392e4
1 changed files with 19 additions and 7 deletions
|
|
@ -40,7 +40,7 @@ const ICON_PREV_ROW: usize = 3;
|
||||||
const ICON_TRY_SIZES: [u16; 3] = [32, 48, 64];
|
const ICON_TRY_SIZES: [u16; 3] = [32, 48, 64];
|
||||||
const ICON_THUMB_SIZE: u16 = 32;
|
const ICON_THUMB_SIZE: u16 = 32;
|
||||||
const ICON_NAME_TRUNC: usize = 20;
|
const ICON_NAME_TRUNC: usize = 20;
|
||||||
type IconThemes = Vec<String>;
|
type IconThemes = Vec<IconTheme>;
|
||||||
type IconHandles = Vec<[icon::Handle; ICON_PREV_N]>;
|
type IconHandles = Vec<[icon::Handle; ICON_PREV_N]>;
|
||||||
|
|
||||||
crate::cache_dynamic_lazy! {
|
crate::cache_dynamic_lazy! {
|
||||||
|
|
@ -62,6 +62,14 @@ enum ContextView {
|
||||||
InterfaceText,
|
InterfaceText,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||||
|
struct IconTheme {
|
||||||
|
// GTK uses the name of the theme as specified in its index file
|
||||||
|
name: String,
|
||||||
|
// COSMIC uses the file name of the folder containing the theme
|
||||||
|
id: String,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Page {
|
pub struct Page {
|
||||||
can_reset: bool,
|
can_reset: bool,
|
||||||
no_custom_window_hint: bool,
|
no_custom_window_hint: bool,
|
||||||
|
|
@ -473,7 +481,7 @@ impl Page {
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, (theme, handles))| {
|
.map(|(i, (theme, handles))| {
|
||||||
let selected = active.map(|j| i == j).unwrap_or_default();
|
let selected = active.map(|j| i == j).unwrap_or_default();
|
||||||
icon_theme_button(theme, handles, i, selected)
|
icon_theme_button(&theme.name, handles, i, selected)
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
|
|
@ -532,13 +540,13 @@ impl Page {
|
||||||
Message::IconTheme(id) => {
|
Message::IconTheme(id) => {
|
||||||
if let Some(theme) = self.icon_themes.get(id).cloned() {
|
if let Some(theme) = self.icon_themes.get(id).cloned() {
|
||||||
self.icon_theme_active = Some(id);
|
self.icon_theme_active = Some(id);
|
||||||
self.tk.icon_theme = theme.clone();
|
self.tk.icon_theme = theme.id.clone();
|
||||||
|
|
||||||
if let Some(ref config) = self.tk_config {
|
if let Some(ref config) = self.tk_config {
|
||||||
let _ = self.tk.write_entry(config);
|
let _ = self.tk.write_entry(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
tokio::spawn(set_gnome_icon_theme(theme));
|
tokio::spawn(set_gnome_icon_theme(theme.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::none()
|
Command::none()
|
||||||
|
|
@ -634,7 +642,7 @@ impl Page {
|
||||||
self.icon_theme_active = self
|
self.icon_theme_active = self
|
||||||
.icon_themes
|
.icon_themes
|
||||||
.iter()
|
.iter()
|
||||||
.position(|theme| theme == &self.tk.icon_theme);
|
.position(|theme| &theme.id == &self.tk.icon_theme);
|
||||||
self.icon_handles = icon_handles;
|
self.icon_handles = icon_handles;
|
||||||
Command::none()
|
Command::none()
|
||||||
}
|
}
|
||||||
|
|
@ -1628,6 +1636,10 @@ async fn fetch_icon_themes() -> Message {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let Some(id) = entry.file_name().to_str().map(|x| x.to_string()) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
let manifest = path.join("index.theme");
|
let manifest = path.join("index.theme");
|
||||||
|
|
||||||
if !manifest.exists() {
|
if !manifest.exists() {
|
||||||
|
|
@ -1686,12 +1698,12 @@ async fn fetch_icon_themes() -> Message {
|
||||||
);
|
);
|
||||||
theme_paths.entry(name.clone()).or_insert(path);
|
theme_paths.entry(name.clone()).or_insert(path);
|
||||||
|
|
||||||
let theme = name.clone();
|
let theme = id.clone();
|
||||||
// `icon::from_name` may perform blocking I/O
|
// `icon::from_name` may perform blocking I/O
|
||||||
if let Ok(handles) =
|
if let Ok(handles) =
|
||||||
tokio::task::spawn_blocking(|| preview_handles(theme, valid_dirs)).await
|
tokio::task::spawn_blocking(|| preview_handles(theme, valid_dirs)).await
|
||||||
{
|
{
|
||||||
icon_themes.insert(name, handles);
|
icon_themes.insert(IconTheme { id, name }, handles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue