decorations: add titlebar actions

This commit is contained in:
Tobias Bengfort 2024-04-18 09:46:36 +02:00
parent bba57c0315
commit 496c933582
6 changed files with 69 additions and 6 deletions

View file

@ -126,6 +126,23 @@ Actions are used in menus and keyboard/mouse bindings.
*<action name="Undecorate" />*
Disable server side decorations of focused window.
*<action name="ToggleTitlebar" />*
Toggle titlebar of focused window.
If the 'keepBorder' configuration option is enabled (as in the default
configuraton), then a border will be left as the only decorations around the
window.
This has no effect on windows that do not have server side decorations.
*<action name="ShowTitlebar" />*
Hide titlebar of focused window.
See 'ToggleTitlebar' for details.
*<action name="HideTitlebar" />*
Show titlebar of focused window.
See 'ToggleTitlebar' for details.
*<action name="ToggleFullscreen" />*
Toggle fullscreen state of focused window.

View file

@ -65,7 +65,7 @@ void ssd_set_active(struct ssd *ssd, bool active);
void ssd_update_title(struct ssd *ssd);
void ssd_update_geometry(struct ssd *ssd);
void ssd_destroy(struct ssd *ssd);
void ssd_titlebar_hide(struct ssd *ssd);
void ssd_set_titlebar(struct ssd *ssd, bool enabled);
void ssd_enable_keybind_inhibit_indicator(struct ssd *ssd, bool enable);
void ssd_enable_shade(struct ssd *ssd, bool enable);

View file

@ -452,6 +452,7 @@ bool view_is_tiled(struct view *view);
bool view_is_floating(struct view *view);
void view_move_to_workspace(struct view *view, struct workspace *workspace);
void view_set_decorations(struct view *view, bool decorations);
void view_set_titlebar(struct view *view, bool enabled);
void view_toggle_fullscreen(struct view *view);
void view_invalidate_last_layout_geometry(struct view *view);
void view_adjust_for_layout_change(struct view *view);

View file

@ -81,6 +81,9 @@ enum action_type {
ACTION_TYPE_TOGGLE_DECORATIONS,
ACTION_TYPE_DECORATE,
ACTION_TYPE_UNDECORATE,
ACTION_TYPE_TOGGLE_TITLEBAR,
ACTION_TYPE_SHOW_TITLEBAR,
ACTION_TYPE_HIDE_TITLEBAR,
ACTION_TYPE_TOGGLE_ALWAYS_ON_TOP,
ACTION_TYPE_TOGGLE_ALWAYS_ON_BOTTOM,
ACTION_TYPE_TOGGLE_OMNIPRESENT,
@ -136,6 +139,9 @@ const char *action_names[] = {
"ToggleDecorations",
"Decorate",
"Undecorate",
"ToggleTitlebar",
"ShowTitlebar",
"HideTitlebar",
"ToggleAlwaysOnTop",
"ToggleAlwaysOnBottom",
"ToggleOmnipresent",
@ -804,6 +810,21 @@ actions_run(struct view *activator, struct server *server,
view_set_decorations(view, false);
}
break;
case ACTION_TYPE_TOGGLE_TITLEBAR:
if (view) {
view_set_titlebar(view, view->ssd_titlebar_hidden);
}
break;
case ACTION_TYPE_SHOW_TITLEBAR:
if (view) {
view_set_titlebar(view, true);
}
break;
case ACTION_TYPE_HIDE_TITLEBAR:
if (view) {
view_set_titlebar(view, false);
}
break;
case ACTION_TYPE_TOGGLE_ALWAYS_ON_TOP:
if (view) {
view_toggle_always_on_top(view);

View file

@ -190,7 +190,7 @@ ssd_create(struct view *view, bool active)
ssd_titlebar_create(ssd);
if (view->ssd_titlebar_hidden) {
/* Ensure we keep the old state on Reconfigure or when exiting fullscreen */
ssd_titlebar_hide(ssd);
ssd_set_titlebar(ssd, false);
}
ssd->margin = ssd_thickness(view);
ssd_set_active(ssd, active);
@ -254,13 +254,13 @@ ssd_update_geometry(struct ssd *ssd)
}
void
ssd_titlebar_hide(struct ssd *ssd)
ssd_set_titlebar(struct ssd *ssd, bool enabled)
{
if (!ssd || !ssd->titlebar.tree->node.enabled) {
if (!ssd || ssd->titlebar.tree->node.enabled == enabled) {
return;
}
wlr_scene_node_set_enabled(&ssd->titlebar.tree->node, false);
ssd->titlebar.height = 0;
wlr_scene_node_set_enabled(&ssd->titlebar.tree->node, enabled);
ssd->titlebar.height = enabled ? ssd->view->server->theme->title_height : 0;
ssd_border_update(ssd);
ssd_extents_update(ssd);
ssd->margin = ssd_thickness(ssd->view);

View file

@ -1294,6 +1294,30 @@ view_set_decorations(struct view *view, bool decorations)
}
}
void
view_set_titlebar(struct view *view, bool enabled)
{
/* Reject decoration toggles when shaded */
if (view->shaded) {
return;
}
if (enabled == !view->ssd_titlebar_hidden) {
return;
}
/*
* ssd_titlebar_hidden has to be set before calling
* ssd_titlebar_hide() to make ssd_thickness() happy.
*/
view->ssd_titlebar_hidden = !enabled;
ssd_set_titlebar(view->ssd, enabled);
if (!view_is_floating(view)) {
view_apply_special_geometry(view);
}
}
void
view_toggle_fullscreen(struct view *view)
{