mirror of
https://github.com/labwc/labwc.git
synced 2025-11-30 06:59:52 -05:00
osd: add thumbnailLabelFormat to windowSwitcher (#3187)
Some checks failed
labwc.github.io / notify (push) Has been cancelled
Some checks failed
labwc.github.io / notify (push) Has been cancelled
This commit adds `<windowSwitcher thumbnailLabelFormat="%T">` to configure the label text in each item in the thumbnail-style window switcher. Its format follows `<fields><field content="custom" format="">`.
This commit is contained in:
parent
8b950350ed
commit
c8167c8ee0
6 changed files with 34 additions and 21 deletions
|
|
@ -339,7 +339,7 @@ this is for compatibility with Openbox.
|
||||||
## WINDOW SWITCHER
|
## WINDOW SWITCHER
|
||||||
|
|
||||||
```
|
```
|
||||||
<windowSwitcher show="yes" style="classic" preview="yes" outlines="yes" allWorkspaces="no">
|
<windowSwitcher show="yes" style="classic" preview="yes" outlines="yes" allWorkspaces="no" thumbnailLabelFormat="%T">
|
||||||
<fields>
|
<fields>
|
||||||
<field content="icon" width="5%" />
|
<field content="icon" width="5%" />
|
||||||
<field content="desktop_entry_name" width="30%" />
|
<field content="desktop_entry_name" width="30%" />
|
||||||
|
|
@ -348,7 +348,7 @@ this is for compatibility with Openbox.
|
||||||
</windowSwitcher>
|
</windowSwitcher>
|
||||||
```
|
```
|
||||||
|
|
||||||
*<windowSwitcher show="" style="" preview="" outlines="" allWorkspaces="" unshade="">*
|
*<windowSwitcher show="" style="" preview="" outlines="" allWorkspaces="" unshade="" thumbnailLabelFormat="">*
|
||||||
*show* [yes|no] Draw the OnScreenDisplay when switching between
|
*show* [yes|no] Draw the OnScreenDisplay when switching between
|
||||||
windows. Default is yes.
|
windows. Default is yes.
|
||||||
|
|
||||||
|
|
@ -369,6 +369,10 @@ this is for compatibility with Openbox.
|
||||||
*unshade* [yes|no] Temporarily unshade windows when switching between
|
*unshade* [yes|no] Temporarily unshade windows when switching between
|
||||||
them and permanently unshade on the final selection. Default is yes.
|
them and permanently unshade on the final selection. Default is yes.
|
||||||
|
|
||||||
|
*thumbnailLabelFormat* Format to be used for the thumbnail label according to *custom*
|
||||||
|
field below, only applied when using *<windowSwitcher style="thumbnail" />*.
|
||||||
|
Default is "%T".
|
||||||
|
|
||||||
*<windowSwitcher><fields><field content="" width="%">*
|
*<windowSwitcher><fields><field content="" width="%">*
|
||||||
Define window switcher fields when using *<windowSwitcher style="classic" />*.
|
Define window switcher fields when using *<windowSwitcher style="classic" />*.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -183,6 +183,7 @@ struct rcxml {
|
||||||
enum lab_view_criteria criteria;
|
enum lab_view_criteria criteria;
|
||||||
struct wl_list fields; /* struct window_switcher_field.link */
|
struct wl_list fields; /* struct window_switcher_field.link */
|
||||||
enum window_switcher_style style;
|
enum window_switcher_style style;
|
||||||
|
char *thumbnail_label_format;
|
||||||
} window_switcher;
|
} window_switcher;
|
||||||
|
|
||||||
struct wl_list window_rules; /* struct window_rule.link */
|
struct wl_list window_rules; /* struct window_rule.link */
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,9 @@ void osd_on_cursor_release(struct server *server, struct wlr_scene_node *node);
|
||||||
/* Used by osd.c internally to render window switcher fields */
|
/* Used by osd.c internally to render window switcher fields */
|
||||||
void osd_field_get_content(struct window_switcher_field *field,
|
void osd_field_get_content(struct window_switcher_field *field,
|
||||||
struct buf *buf, struct view *view);
|
struct buf *buf, struct view *view);
|
||||||
|
/* Sets view info to buf according to format */
|
||||||
|
void osd_field_set_custom(struct buf *buf, struct view *view,
|
||||||
|
const char *format);
|
||||||
|
|
||||||
/* Used by rcxml.c when parsing the config */
|
/* Used by rcxml.c when parsing the config */
|
||||||
void osd_field_arg_from_xml_node(struct window_switcher_field *field,
|
void osd_field_arg_from_xml_node(struct window_switcher_field *field,
|
||||||
|
|
|
||||||
|
|
@ -1208,6 +1208,8 @@ entry(xmlNode *node, char *nodename, char *content)
|
||||||
} else if (!strcasecmp(content, "thumbnail")) {
|
} else if (!strcasecmp(content, "thumbnail")) {
|
||||||
rc.window_switcher.style = WINDOW_SWITCHER_THUMBNAIL;
|
rc.window_switcher.style = WINDOW_SWITCHER_THUMBNAIL;
|
||||||
}
|
}
|
||||||
|
} else if (!strcasecmp(nodename, "thumbnailLabelFormat.windowSwitcher")) {
|
||||||
|
xstrdup_replace(rc.window_switcher.thumbnail_label_format, content);
|
||||||
} else if (!strcasecmp(nodename, "preview.windowSwitcher")) {
|
} else if (!strcasecmp(nodename, "preview.windowSwitcher")) {
|
||||||
set_bool(content, &rc.window_switcher.preview);
|
set_bool(content, &rc.window_switcher.preview);
|
||||||
} else if (!strcasecmp(nodename, "outlines.windowSwitcher")) {
|
} else if (!strcasecmp(nodename, "outlines.windowSwitcher")) {
|
||||||
|
|
@ -1429,6 +1431,7 @@ rcxml_init(void)
|
||||||
|
|
||||||
rc.window_switcher.show = true;
|
rc.window_switcher.show = true;
|
||||||
rc.window_switcher.style = WINDOW_SWITCHER_CLASSIC;
|
rc.window_switcher.style = WINDOW_SWITCHER_CLASSIC;
|
||||||
|
rc.window_switcher.thumbnail_label_format = xstrdup("%T");
|
||||||
rc.window_switcher.preview = true;
|
rc.window_switcher.preview = true;
|
||||||
rc.window_switcher.outlines = true;
|
rc.window_switcher.outlines = true;
|
||||||
rc.window_switcher.unshade = true;
|
rc.window_switcher.unshade = true;
|
||||||
|
|
@ -1905,6 +1908,7 @@ rcxml_finish(void)
|
||||||
zfree(rc.fallback_app_icon_name);
|
zfree(rc.fallback_app_icon_name);
|
||||||
zfree(rc.workspace_config.prefix);
|
zfree(rc.workspace_config.prefix);
|
||||||
zfree(rc.tablet.output_name);
|
zfree(rc.tablet.output_name);
|
||||||
|
zfree(rc.window_switcher.thumbnail_label_format);
|
||||||
|
|
||||||
clear_title_layout();
|
clear_title_layout();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -189,9 +189,6 @@ field_set_title_short(struct buf *buf, struct view *view, const char *format)
|
||||||
buf_add(buf, get_title_if_different(view));
|
buf_add(buf, get_title_if_different(view));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void field_set_custom(struct buf *buf, struct view *view,
|
|
||||||
const char *format);
|
|
||||||
|
|
||||||
static const struct field_converter field_converter[LAB_FIELD_COUNT] = {
|
static const struct field_converter field_converter[LAB_FIELD_COUNT] = {
|
||||||
[LAB_FIELD_TYPE] = { 'B', field_set_type },
|
[LAB_FIELD_TYPE] = { 'B', field_set_type },
|
||||||
[LAB_FIELD_TYPE_SHORT] = { 'b', field_set_type_short },
|
[LAB_FIELD_TYPE_SHORT] = { 'b', field_set_type_short },
|
||||||
|
|
@ -207,11 +204,11 @@ static const struct field_converter field_converter[LAB_FIELD_COUNT] = {
|
||||||
[LAB_FIELD_TITLE] = { 'T', field_set_title },
|
[LAB_FIELD_TITLE] = { 'T', field_set_title },
|
||||||
[LAB_FIELD_TITLE_SHORT] = { 't', field_set_title_short },
|
[LAB_FIELD_TITLE_SHORT] = { 't', field_set_title_short },
|
||||||
/* fmt_char can never be matched so prevents LAB_FIELD_CUSTOM recursion */
|
/* fmt_char can never be matched so prevents LAB_FIELD_CUSTOM recursion */
|
||||||
[LAB_FIELD_CUSTOM] = { '\0', field_set_custom },
|
[LAB_FIELD_CUSTOM] = { '\0', osd_field_set_custom },
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
void
|
||||||
field_set_custom(struct buf *buf, struct view *view, const char *format)
|
osd_field_set_custom(struct buf *buf, struct view *view, const char *format)
|
||||||
{
|
{
|
||||||
if (!format) {
|
if (!format) {
|
||||||
wlr_log(WLR_ERROR, "Missing format for custom window switcher field");
|
wlr_log(WLR_ERROR, "Missing format for custom window switcher field");
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include "config/rcxml.h"
|
#include "config/rcxml.h"
|
||||||
#include "common/array.h"
|
#include "common/array.h"
|
||||||
#include "common/box.h"
|
#include "common/box.h"
|
||||||
|
#include "common/buf.h"
|
||||||
#include "common/lab-scene-rect.h"
|
#include "common/lab-scene-rect.h"
|
||||||
#include "common/list.h"
|
#include "common/list.h"
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
|
|
@ -20,8 +21,8 @@
|
||||||
|
|
||||||
struct osd_thumbnail_item {
|
struct osd_thumbnail_item {
|
||||||
struct osd_item base;
|
struct osd_item base;
|
||||||
struct scaled_font_buffer *normal_title;
|
struct scaled_font_buffer *normal_label;
|
||||||
struct scaled_font_buffer *active_title;
|
struct scaled_font_buffer *active_label;
|
||||||
struct lab_scene_rect *active_bg;
|
struct lab_scene_rect *active_bg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -89,16 +90,19 @@ render_thumb(struct output *output, struct view *view)
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct scaled_font_buffer *
|
static struct scaled_font_buffer *
|
||||||
create_title(struct wlr_scene_tree *parent,
|
create_label(struct wlr_scene_tree *parent, struct view *view,
|
||||||
struct window_switcher_thumbnail_theme *switcher_theme,
|
struct window_switcher_thumbnail_theme *switcher_theme,
|
||||||
const char *title, const float *title_color,
|
const float *text_color, const float *bg_color, int y)
|
||||||
const float *bg_color, int y)
|
|
||||||
{
|
{
|
||||||
|
struct buf buf = BUF_INIT;
|
||||||
|
osd_field_set_custom(&buf, view,
|
||||||
|
rc.window_switcher.thumbnail_label_format);
|
||||||
struct scaled_font_buffer *buffer =
|
struct scaled_font_buffer *buffer =
|
||||||
scaled_font_buffer_create(parent);
|
scaled_font_buffer_create(parent);
|
||||||
scaled_font_buffer_update(buffer, title,
|
scaled_font_buffer_update(buffer, buf.data,
|
||||||
switcher_theme->item_width - 2 * switcher_theme->item_padding,
|
switcher_theme->item_width - 2 * switcher_theme->item_padding,
|
||||||
&rc.font_osd, title_color, bg_color);
|
&rc.font_osd, text_color, bg_color);
|
||||||
|
buf_reset(&buf);
|
||||||
wlr_scene_node_set_position(&buffer->scene_buffer->node,
|
wlr_scene_node_set_position(&buffer->scene_buffer->node,
|
||||||
(switcher_theme->item_width - buffer->width) / 2, y);
|
(switcher_theme->item_width - buffer->width) / 2, y);
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|
@ -163,11 +167,11 @@ create_item_scene(struct wlr_scene_tree *parent, struct view *view,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* title */
|
/* title */
|
||||||
item->normal_title = create_title(tree, switcher_theme,
|
item->normal_label = create_label(tree, view,
|
||||||
view->title, theme->osd_label_text_color,
|
switcher_theme, theme->osd_label_text_color,
|
||||||
theme->osd_bg_color, title_y);
|
theme->osd_bg_color, title_y);
|
||||||
item->active_title = create_title(tree, switcher_theme,
|
item->active_label = create_label(tree, view,
|
||||||
view->title, theme->osd_label_text_color,
|
switcher_theme, theme->osd_label_text_color,
|
||||||
switcher_theme->item_active_bg_color, title_y);
|
switcher_theme->item_active_bg_color, title_y);
|
||||||
|
|
||||||
/* icon */
|
/* icon */
|
||||||
|
|
@ -277,9 +281,9 @@ osd_thumbnail_update(struct output *output)
|
||||||
bool active = (item->base.view == output->server->osd_state.cycle_view);
|
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_bg->tree->node, active);
|
||||||
wlr_scene_node_set_enabled(
|
wlr_scene_node_set_enabled(
|
||||||
&item->active_title->scene_buffer->node, active);
|
&item->active_label->scene_buffer->node, active);
|
||||||
wlr_scene_node_set_enabled(
|
wlr_scene_node_set_enabled(
|
||||||
&item->normal_title->scene_buffer->node, !active);
|
&item->normal_label->scene_buffer->node, !active);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue