mirror of
https://github.com/labwc/labwc.git
synced 2026-02-22 01:40:25 -05:00
osd: generalize osd_{classic,thumbnail}_item
This allows us to share common codes for dealing with osd items. For example: - Get the clicked osd item to focus its associated window - Scroll the items when their total height is taller than output height
This commit is contained in:
parent
747163fa3e
commit
00f0a46ef7
6 changed files with 43 additions and 31 deletions
|
|
@ -8,7 +8,9 @@
|
|||
#include "common/array.h"
|
||||
#include "common/box.h"
|
||||
#include "common/lab-scene-rect.h"
|
||||
#include "common/list.h"
|
||||
#include "labwc.h"
|
||||
#include "node.h"
|
||||
#include "osd.h"
|
||||
#include "output.h"
|
||||
#include "scaled-buffer/scaled-font-buffer.h"
|
||||
|
|
@ -17,8 +19,7 @@
|
|||
#include "view.h"
|
||||
|
||||
struct osd_thumbnail_item {
|
||||
struct view *view;
|
||||
struct wlr_scene_tree *tree;
|
||||
struct osd_item base;
|
||||
struct scaled_font_buffer *normal_title;
|
||||
struct scaled_font_buffer *active_title;
|
||||
struct lab_scene_rect *active_bg;
|
||||
|
|
@ -124,10 +125,11 @@ create_item_scene(struct wlr_scene_tree *parent, struct view *view,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct osd_thumbnail_item *item =
|
||||
wl_array_add(&output->osd_scene.items, sizeof(*item));
|
||||
item->tree = wlr_scene_tree_create(parent);
|
||||
item->view = view;
|
||||
struct osd_thumbnail_item *item = znew(*item);
|
||||
wl_list_append(&output->osd_scene.items, &item->base.link);
|
||||
struct wlr_scene_tree *tree = wlr_scene_tree_create(parent);
|
||||
item->base.tree = tree;
|
||||
item->base.view = view;
|
||||
|
||||
/* background for selected item */
|
||||
struct lab_scene_rect_options opts = {
|
||||
|
|
@ -138,13 +140,13 @@ create_item_scene(struct wlr_scene_tree *parent, struct view *view,
|
|||
.width = switcher_theme->item_width,
|
||||
.height = switcher_theme->item_height,
|
||||
};
|
||||
item->active_bg = lab_scene_rect_create(item->tree, &opts);
|
||||
item->active_bg = lab_scene_rect_create(tree, &opts);
|
||||
|
||||
/* thumbnail */
|
||||
struct wlr_buffer *thumb_buffer = render_thumb(output, view);
|
||||
if (thumb_buffer) {
|
||||
struct wlr_scene_buffer *thumb_scene_buffer =
|
||||
wlr_scene_buffer_create(item->tree, thumb_buffer);
|
||||
wlr_scene_buffer_create(tree, thumb_buffer);
|
||||
wlr_buffer_drop(thumb_buffer);
|
||||
struct wlr_box thumb_box = box_fit_within(
|
||||
thumb_buffer->width, thumb_buffer->height,
|
||||
|
|
@ -156,17 +158,17 @@ create_item_scene(struct wlr_scene_tree *parent, struct view *view,
|
|||
}
|
||||
|
||||
/* title */
|
||||
item->normal_title = create_title(item->tree, switcher_theme,
|
||||
item->normal_title = create_title(tree, switcher_theme,
|
||||
view->title, theme->osd_label_text_color,
|
||||
theme->osd_bg_color, title_y);
|
||||
item->active_title = create_title(item->tree, switcher_theme,
|
||||
item->active_title = create_title(tree, switcher_theme,
|
||||
view->title, theme->osd_label_text_color,
|
||||
switcher_theme->item_active_bg_color, title_y);
|
||||
|
||||
/* icon */
|
||||
int icon_size = switcher_theme->item_icon_size;
|
||||
struct scaled_icon_buffer *icon_buffer = scaled_icon_buffer_create(
|
||||
item->tree, server, icon_size, icon_size);
|
||||
struct scaled_icon_buffer *icon_buffer =
|
||||
scaled_icon_buffer_create(tree, server, icon_size, icon_size);
|
||||
scaled_icon_buffer_set_view(icon_buffer, view);
|
||||
int x = (switcher_theme->item_width - icon_size) / 2;
|
||||
int y = title_y - padding - icon_size + 10; /* slide by 10px */
|
||||
|
|
@ -210,7 +212,7 @@ get_items_geometry(struct output *output, struct theme *theme,
|
|||
static void
|
||||
osd_thumbnail_create(struct output *output, struct wl_array *views)
|
||||
{
|
||||
assert(!output->osd_scene.tree);
|
||||
assert(!output->osd_scene.tree && wl_list_empty(&output->osd_scene.items));
|
||||
|
||||
struct server *server = output->server;
|
||||
struct theme *theme = server->theme;
|
||||
|
|
@ -236,7 +238,7 @@ osd_thumbnail_create(struct output *output, struct wl_array *views)
|
|||
}
|
||||
int x = (index % nr_cols) * switcher_theme->item_width + padding;
|
||||
int y = (index / nr_cols) * switcher_theme->item_height + padding;
|
||||
wlr_scene_node_set_position(&item->tree->node, x, y);
|
||||
wlr_scene_node_set_position(&item->base.tree->node, x, y);
|
||||
index++;
|
||||
}
|
||||
|
||||
|
|
@ -266,8 +268,8 @@ static void
|
|||
osd_thumbnail_update(struct output *output)
|
||||
{
|
||||
struct osd_thumbnail_item *item;
|
||||
wl_array_for_each(item, &output->osd_scene.items) {
|
||||
bool active = (item->view == output->server->osd_state.cycle_view);
|
||||
wl_list_for_each(item, &output->osd_scene.items, base.link) {
|
||||
bool active = (item->base.view == output->server->osd_state.cycle_view);
|
||||
wlr_scene_node_set_enabled(&item->active_bg->tree->node, active);
|
||||
wlr_scene_node_set_enabled(
|
||||
&item->active_title->scene_buffer->node, active);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue