osd: add window-switcher field content types (#1623)

...`workspace`, `state`, `type_short` and `output`.

Example usage:

    <windowSwitcher allWorkspaces="yes">
      <fields>
        <field content="workspace" width="5%" />
        <field content="state" width="3%" />
        <field content="type_short" width="3%" />
        <field content="output" width="9%" />
        <field content="identifier" width="30%" />
        <field content="title" width="50%" />
      </fields>
    </windowSwitcher>
This commit is contained in:
droc12345 2024-03-16 10:28:37 -05:00 committed by GitHub
parent 901240b321
commit b0c2ac1a6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 77 additions and 0 deletions

View file

@ -216,6 +216,14 @@ this is for compatibility with Openbox.
- *title* Show window title if different to app_id
- *workspace* Show workspace name
- *state* Show window state, M/m/F (max/min/full)
- *type_short* Show view type ("W" or "X")
- *output* Show output id, if more than one output detected
*width* defines the width of the field expressed as a percentage of
the overall window switcher width. The "%" character is required.

View file

@ -63,6 +63,24 @@
</fields>
</windowSwitcher>
<!--
When using all workspaces option of window switcher, there are extra fields
that can be used, workspace (variable length), state (single space),
type_short (3 spaces), output (variable length), and can be set up
like this. Note: output only shows if more than one output available.
<windowSwitcher show="yes" preview="no" outlines="no" allWorkspaces="yes">
<fields>
<field content="workspace" width="5%" />
<field content="state" width="3%" />
<field content="type_short" width="3%" />
<field content="output" width="9%" />
<field content="identifier" width="30%" />
<field content="title" width="50%" />
</fields>
</windowSwitcher>
-->
<!-- edge strength is in pixels -->
<resistance>
<screenEdgeStrength>20</screenEdgeStrength>

View file

@ -21,6 +21,10 @@ enum window_switcher_field_content {
LAB_FIELD_IDENTIFIER,
LAB_FIELD_TRIMMED_IDENTIFIER,
LAB_FIELD_TITLE,
LAB_FIELD_WORKSPACE,
LAB_FIELD_WIN_STATE,
LAB_FIELD_TYPE_SHORT,
LAB_FIELD_OUTPUT,
};
enum view_placement_policy {

View file

@ -207,6 +207,14 @@ fill_window_switcher_field(char *nodename, char *content)
current_field->content = LAB_FIELD_TRIMMED_IDENTIFIER;
} else if (!strcmp(content, "title")) {
current_field->content = LAB_FIELD_TITLE;
} else if (!strcmp(content, "workspace")) {
current_field->content = LAB_FIELD_WORKSPACE;
} else if (!strcmp(content, "state")) {
current_field->content = LAB_FIELD_WIN_STATE;
} else if (!strcmp(content, "type_short")) {
current_field->content = LAB_FIELD_TYPE_SHORT;
} else if (!strcmp(content, "output")) {
current_field->content = LAB_FIELD_OUTPUT;
} else {
wlr_log(WLR_ERROR, "bad windowSwitcher field '%s'", content);
}

View file

@ -239,6 +239,20 @@ get_type(struct view *view)
return "";
}
static const char *
get_type_short(struct view *view)
{
switch (view->type) {
case LAB_XDG_SHELL_VIEW:
return "[W]";
#if HAVE_XWAYLAND
case LAB_XWAYLAND_VIEW:
return "[X]";
#endif
}
return "";
}
static const char *
get_app_id(struct view *view)
{
@ -364,6 +378,31 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
case LAB_FIELD_TYPE:
buf_add(&buf, get_type(*view));
break;
case LAB_FIELD_TYPE_SHORT:
buf_add(&buf, get_type_short(*view));
break;
case LAB_FIELD_WORKSPACE:
buf_add(&buf, (*view)->workspace->name);
break;
case LAB_FIELD_WIN_STATE:
if ((*view)->maximized) {
buf_add(&buf, "M");
} else if ((*view)->minimized) {
buf_add(&buf, "m");
} else if ((*view)->fullscreen) {
buf_add(&buf, "F");
} else {
buf_add(&buf, " ");
}
break;
case LAB_FIELD_OUTPUT:
if (wl_list_length(&server->outputs) > 1 &&
output_is_usable((*view)->output)) {
buf_add(&buf, (*view)->output->wlr_output->name);
} else {
buf_add(&buf, " ");
}
break;
case LAB_FIELD_IDENTIFIER:
buf_add(&buf, get_app_id(*view));
break;