mirror of
https://github.com/swaywm/sway.git
synced 2026-04-26 06:46:26 -04:00
Load icon only from disk if window changes
Signed-off-by: Felix Weilbach <felix.weilbach@t-online.de>
This commit is contained in:
parent
402706ff9d
commit
7a20f8ed92
2 changed files with 41 additions and 29 deletions
|
|
@ -101,6 +101,7 @@ struct swaybar_window {
|
||||||
char *name;
|
char *name;
|
||||||
char *icon_name;
|
char *icon_name;
|
||||||
cairo_surface_t *icon;
|
cairo_surface_t *icon;
|
||||||
|
bool icon_name_icon_sync;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool bar_setup(struct swaybar *bar, const char *socket_path);
|
bool bar_setup(struct swaybar *bar, const char *socket_path);
|
||||||
|
|
|
||||||
|
|
@ -754,34 +754,44 @@ uint32_t render_focused_window_icon(cairo_t *cairo,
|
||||||
int padding = 4;
|
int padding = 4;
|
||||||
int target_size = height - 2 * padding;
|
int target_size = height - 2 * padding;
|
||||||
|
|
||||||
|
cairo_surface_t **icon = &output->bar->focused_window->icon;
|
||||||
char *icon_name = output->bar->focused_window->icon_name;
|
char *icon_name = output->bar->focused_window->icon_name;
|
||||||
cairo_surface_t *icon = NULL;
|
bool icon_name_icon_sync = output->bar->focused_window->icon_name_icon_sync;
|
||||||
if (icon_name) {
|
if (!icon_name_icon_sync && icon_name) {
|
||||||
|
assert(output->bar->config);
|
||||||
char *icon_theme = output->bar->config->icon_theme;
|
char *icon_theme = output->bar->config->icon_theme;
|
||||||
|
list_t *basedirs = output->bar->basedirs;
|
||||||
|
list_t *themes = output->bar->themes;
|
||||||
int min_size = 0;
|
int min_size = 0;
|
||||||
int max_size = 0;
|
int max_size = 0;
|
||||||
|
char *icon_path = find_icon(themes,
|
||||||
assert(output->bar);
|
basedirs,
|
||||||
assert(output->bar->themes);
|
|
||||||
char *icon_path = find_icon(output->bar->themes,
|
|
||||||
output->bar->basedirs,
|
|
||||||
icon_name,
|
icon_name,
|
||||||
target_size,
|
target_size,
|
||||||
icon_theme,
|
icon_theme,
|
||||||
&min_size,
|
&min_size,
|
||||||
&max_size);
|
&max_size);
|
||||||
icon = load_background_image(icon_path);
|
if (*icon) {
|
||||||
|
cairo_surface_destroy(*icon);
|
||||||
|
icon = NULL;
|
||||||
|
}
|
||||||
|
*icon = load_background_image(icon_path);
|
||||||
|
output->bar->focused_window->icon_name_icon_sync = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!icon) {
|
if (!*icon) {
|
||||||
return output->height;
|
return output->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
int icon_size;
|
int icon_size;
|
||||||
int actual_size = cairo_image_surface_get_height(icon);
|
int actual_size = cairo_image_surface_get_height(
|
||||||
icon_size = actual_size < target_size ?
|
output->bar->focused_window->icon);
|
||||||
actual_size*(target_size/actual_size) : target_size;
|
icon_size = actual_size < target_size
|
||||||
icon = cairo_image_surface_scale(icon, icon_size, icon_size);
|
? actual_size * (target_size / actual_size)
|
||||||
|
: target_size;
|
||||||
|
cairo_surface_t *icon = cairo_image_surface_scale(
|
||||||
|
output->bar->focused_window->icon, icon_size, icon_size);
|
||||||
|
|
||||||
int padded_size = icon_size + padding;
|
int padded_size = icon_size + padding;
|
||||||
if (*x + padded_size >= max_width) {
|
if (*x + padded_size >= max_width) {
|
||||||
|
|
@ -799,6 +809,7 @@ uint32_t render_focused_window_icon(cairo_t *cairo,
|
||||||
*x += padded_size;
|
*x += padded_size;
|
||||||
|
|
||||||
cairo_surface_destroy(icon);
|
cairo_surface_destroy(icon);
|
||||||
|
}
|
||||||
|
|
||||||
return output->height;
|
return output->height;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue