mirror of
https://github.com/labwc/labwc.git
synced 2025-11-02 09:01:47 -05:00
ssd: dynamically look up window icons in titlebar for output scales
by introducing scaled_icon_buffer.
This commit is contained in:
parent
5e29f79258
commit
dc474521ab
9 changed files with 225 additions and 102 deletions
|
|
@ -7,6 +7,7 @@
|
|||
#include "config.h"
|
||||
#include "common/mem.h"
|
||||
#include "common/scaled-font-buffer.h"
|
||||
#include "common/scaled-icon-buffer.h"
|
||||
#include "common/scaled-img-buffer.h"
|
||||
#include "common/scene-helpers.h"
|
||||
#include "common/string-helpers.h"
|
||||
|
|
@ -127,11 +128,12 @@ update_button_state(struct ssd_button *button, enum lab_button_state state,
|
|||
/* Switch the displayed icon buffer to the new one */
|
||||
for (uint8_t state_set = LAB_BS_DEFAULT;
|
||||
state_set <= LAB_BS_ALL; state_set++) {
|
||||
if (!button->nodes[state_set]) {
|
||||
struct scaled_img_buffer *buffer = button->img_buffers[state_set];
|
||||
if (!buffer) {
|
||||
continue;
|
||||
}
|
||||
wlr_scene_node_set_enabled(
|
||||
button->nodes[state_set], button->state_set == state_set);
|
||||
wlr_scene_node_set_enabled(&buffer->scene_buffer->node,
|
||||
state_set == button->state_set);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -584,37 +586,6 @@ ssd_update_window_icon(struct ssd *ssd)
|
|||
free(ssd->state.app_id);
|
||||
ssd->state.app_id = xstrdup(app_id);
|
||||
|
||||
struct theme *theme = ssd->view->server->theme;
|
||||
|
||||
/*
|
||||
* Ensure a small amount of horizontal padding within the button
|
||||
* area (2px on each side with the default 26px button width).
|
||||
* A new theme setting could be added to configure this. Using
|
||||
* an existing setting (padding.width or window.button.spacing)
|
||||
* was considered, but these settings have distinct purposes
|
||||
* already and are zero by default.
|
||||
*/
|
||||
int icon_padding = theme->window_button_width / 10;
|
||||
int icon_size = MIN(theme->window_button_width - 2 * icon_padding,
|
||||
theme->window_button_height);
|
||||
|
||||
/*
|
||||
* Load/render icons at the max scale of any usable output (at
|
||||
* this point in time). We don't want to be constantly reloading
|
||||
* icons as views are moved between outputs.
|
||||
*
|
||||
* TODO: currently there's no signal to reload/render icons if
|
||||
* outputs are reconfigured and the max scale changes.
|
||||
*/
|
||||
float icon_scale = output_max_scale(ssd->view->server);
|
||||
|
||||
struct lab_img *icon_img = desktop_entry_load_icon_from_app_id(
|
||||
ssd->view->server, app_id, icon_size, icon_scale);
|
||||
if (!icon_img) {
|
||||
wlr_log(WLR_DEBUG, "icon could not be loaded for %s", app_id);
|
||||
return;
|
||||
}
|
||||
|
||||
struct ssd_sub_tree *subtree;
|
||||
FOR_EACH_STATE(ssd, subtree) {
|
||||
struct ssd_part *part = ssd_get_part(
|
||||
|
|
@ -623,23 +594,10 @@ ssd_update_window_icon(struct ssd *ssd)
|
|||
break;
|
||||
}
|
||||
|
||||
/* Replace all the buffers in the button with the window icon */
|
||||
struct ssd_button *button = node_ssd_button_from_node(part->node);
|
||||
for (uint8_t state_set = LAB_BS_DEFAULT;
|
||||
state_set <= LAB_BS_ALL; state_set++) {
|
||||
struct wlr_scene_node *node = button->nodes[state_set];
|
||||
if (node) {
|
||||
struct scaled_img_buffer *img_buffer =
|
||||
scaled_img_buffer_from_node(node);
|
||||
scaled_img_buffer_update(img_buffer, icon_img,
|
||||
theme->window_button_width - 2 * icon_padding,
|
||||
theme->window_button_height);
|
||||
wlr_scene_node_set_position(node, icon_padding, 0);
|
||||
}
|
||||
}
|
||||
assert(button->window_icon);
|
||||
scaled_icon_buffer_set_app_id(button->window_icon, app_id);
|
||||
} FOR_EACH_END
|
||||
|
||||
lab_img_destroy(icon_img);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue