view: implement cascade placement policy

Adds following settings:
<placement>
  <policy>cascade</policy>
  <cascadeOffset x="40" y="30" />
</placement>

"Cascade" policy places a new window at the center of the screen like
"center" policy, but possibly shifts its position to bottom-right so the
new window doesn't cover existing windows.

The algorithm is copied from KWin's implementation:
df9f8f8346/src/placement.cpp (L589)

Also added some helper functions to manipulate `wlr_box`.
This commit is contained in:
tokyo4j 2024-05-04 06:26:27 +09:00 committed by Johan Malm
parent 3be8fe25f3
commit 46ec513630
10 changed files with 199 additions and 17 deletions

17
include/common/box.h Normal file
View file

@ -0,0 +1,17 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_BOX_H
#define LABWC_BOX_H
#include <wlr/util/box.h>
bool
box_contains(struct wlr_box *box_super, struct wlr_box *box_sub);
bool
box_intersects(struct wlr_box *box_a, struct wlr_box *box_b);
/* Returns the bounding box of 2 boxes */
void
box_union(struct wlr_box *box_dest, struct wlr_box *box_a, struct wlr_box *box_b);
#endif /* LABWC_BOX_H */

View file

@ -20,7 +20,8 @@ enum view_placement_policy {
LAB_PLACE_INVALID = 0,
LAB_PLACE_CENTER,
LAB_PLACE_CURSOR,
LAB_PLACE_AUTOMATIC
LAB_PLACE_AUTOMATIC,
LAB_PLACE_CASCADE,
};
enum adaptive_sync_mode {
@ -57,6 +58,8 @@ struct rcxml {
bool reuse_output_mode;
enum view_placement_policy placement_policy;
bool xwayland_persistence;
int placement_cascade_offset_x;
int placement_cascade_offset_y;
/* focus */
bool focus_follow_mouse;