view: implement separate horizontal/vertical maximize

This is a useful (if lesser-known) feature of at least a few popular X11
window managers, for example Openbox and XFWM4. Typically right-click on
the maximize button toggles horizontal maximize, while middle-click
toggles vertical maximize.

Support in labwc uses the same configuration syntax as Openbox, where the
Maximize/ToggleMaximize actions have an optional "direction" argument:
horizontal, vertical, or both (default). The default mouse bindings match
the XFWM4 defaults (not sure what Openbox has by default).

Most of the external protocols still assume "maximized" is a Boolean,
which is no longer true internally. For the sake of the outside world,
a view is only "maximized" if maximized in both directions.

Internally, I've taken the following approach:

- SSD code decorates the view as "maximized" (i.e. hiding borders) only
  if maximized in both directions.

- Layout code (interactive move/resize, tiling, etc.) generally treats
  the view as "maximized" (with the restrictions that entails) if
  maximized in either direction. For example, moving a vertically-
  maximized view first restores the natural geometry (this differs from
  Openbox, which instead allows the view to move only horizontally.)

v2: use enum view_axis for view->maximized
v3:
  - update docs
  - allow resizing if partly maximized
  - add TODOs & corrections noted by Consolatis
This commit is contained in:
John Lindgren 2023-10-26 00:38:29 -04:00 committed by Consolatis
parent 7b644b3b94
commit 0430f6f818
15 changed files with 193 additions and 78 deletions

View file

@ -45,7 +45,7 @@ interactive_begin(struct view *view, enum input_mode mode, uint32_t edges)
*/
return;
}
if (view->maximized || view_is_tiled(view)) {
if (!view_is_floating(view)) {
/*
* Un-maximize and restore natural width/height.
* Don't reset tiled state yet since we may want
@ -71,18 +71,20 @@ interactive_begin(struct view *view, enum input_mode mode, uint32_t edges)
cursor_set(seat, LAB_CURSOR_GRAB);
break;
case LAB_INPUT_STATE_RESIZE:
if (view->maximized || view->fullscreen) {
if (view->fullscreen || view->maximized == VIEW_AXIS_BOTH) {
/*
* We don't allow resizing while maximized or
* fullscreen.
* We don't allow resizing while fullscreen or
* maximized in both directions.
*/
return;
}
/*
* Reset tiled state but keep the same geometry as the
* starting point for the resize.
* If tiled or maximized in only one direction, reset
* tiled/maximized state but keep the same geometry as
* the starting point for the resize.
*/
view_set_untiled(view);
view_restore_to(view, view->pending);
cursor_set(seat, cursor_get_from_edge(edges));
break;
default:
@ -130,7 +132,7 @@ snap_to_edge(struct view *view)
/*store_natural_geometry*/ false);
} else if (cursor_y <= area->y + snap_range) {
if (rc.snap_top_maximize) {
view_maximize(view, true,
view_maximize(view, VIEW_AXIS_BOTH,
/*store_natural_geometry*/ false);
} else {
view_snap_to_edge(view, VIEW_EDGE_UP,