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

@ -29,6 +29,18 @@ enum ssd_preference {
LAB_SSD_PREF_SERVER,
};
/**
* Directions in which a view can be maximized. "None" is used
* internally to mean "not maximized" but is not valid in rc.xml.
* Therefore when parsing rc.xml, "None" means "Invalid".
*/
enum view_axis {
VIEW_AXIS_NONE = 0,
VIEW_AXIS_HORIZONTAL = (1 << 0),
VIEW_AXIS_VERTICAL = (1 << 1),
VIEW_AXIS_BOTH = (VIEW_AXIS_HORIZONTAL | VIEW_AXIS_VERTICAL),
};
enum view_edge {
VIEW_EDGE_INVALID = 0,
@ -127,7 +139,7 @@ struct view {
bool ssd_titlebar_hidden;
enum ssd_preference ssd_preference;
bool minimized;
bool maximized;
enum view_axis maximized;
bool fullscreen;
uint32_t tiled; /* private, enum view_edge in src/view.c */
bool inhibits_keybinds;
@ -353,10 +365,10 @@ void view_store_natural_geometry(struct view *view);
void view_center(struct view *view, const struct wlr_box *ref);
void view_restore_to(struct view *view, struct wlr_box geometry);
void view_set_untiled(struct view *view);
void view_maximize(struct view *view, bool maximize,
void view_maximize(struct view *view, enum view_axis axis,
bool store_natural_geometry);
void view_set_fullscreen(struct view *view, bool fullscreen);
void view_toggle_maximize(struct view *view);
void view_toggle_maximize(struct view *view, enum view_axis axis);
void view_toggle_decorations(struct view *view);
bool view_is_always_on_top(struct view *view);
@ -400,6 +412,7 @@ void view_evacuate_region(struct view *view);
void view_on_output_destroy(struct view *view);
void view_destroy(struct view *view);
enum view_axis view_axis_parse(const char *direction);
enum view_edge view_edge_parse(const char *direction);
/* xdg.c */