2021-09-24 21:45:48 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2022-04-19 23:01:23 +01:00
|
|
|
#include <assert.h>
|
2021-02-27 17:10:53 -05:00
|
|
|
#include <stdio.h>
|
2021-07-20 19:54:57 +01:00
|
|
|
#include <strings.h>
|
2023-10-20 20:24:29 -04:00
|
|
|
#include "common/macros.h"
|
2023-08-28 18:55:29 +03:00
|
|
|
#include "common/match.h"
|
2022-07-07 19:05:54 +02:00
|
|
|
#include "common/mem.h"
|
2022-04-26 23:56:27 +02:00
|
|
|
#include "common/scene-helpers.h"
|
2023-09-07 16:41:47 +02:00
|
|
|
#include "input/keyboard.h"
|
2021-03-20 14:36:40 +00:00
|
|
|
#include "labwc.h"
|
2022-06-09 17:10:36 +02:00
|
|
|
#include "menu/menu.h"
|
2022-07-06 17:04:21 +02:00
|
|
|
#include "regions.h"
|
2023-08-17 18:59:29 +02:00
|
|
|
#include "resize_indicator.h"
|
2023-08-05 23:58:40 +02:00
|
|
|
#include "snap.h"
|
2023-01-01 19:35:07 +01:00
|
|
|
#include "ssd.h"
|
2022-11-21 10:10:39 -05:00
|
|
|
#include "view.h"
|
2023-04-28 21:41:41 +01:00
|
|
|
#include "window-rules.h"
|
2022-06-15 02:02:50 +02:00
|
|
|
#include "workspaces.h"
|
2023-01-07 17:50:33 -05:00
|
|
|
#include "xwayland.h"
|
2021-03-02 20:37:23 +00:00
|
|
|
|
2023-09-29 02:29:30 +02:00
|
|
|
#if HAVE_XWAYLAND
|
|
|
|
|
#include <wlr/xwayland.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-01-04 04:18:00 +01:00
|
|
|
#define LAB_FALLBACK_WIDTH 640
|
2022-07-02 20:23:14 +02:00
|
|
|
#define LAB_FALLBACK_HEIGHT 480
|
2023-01-04 04:18:00 +01:00
|
|
|
|
2023-09-27 18:24:35 -04:00
|
|
|
struct view *
|
|
|
|
|
view_from_wlr_surface(struct wlr_surface *surface)
|
|
|
|
|
{
|
|
|
|
|
assert(surface);
|
|
|
|
|
/*
|
|
|
|
|
* TODO:
|
|
|
|
|
* - find a way to get rid of xdg/xwayland-specific stuff
|
|
|
|
|
* - look up root/toplevel surface if passed a subsurface?
|
|
|
|
|
*/
|
|
|
|
|
if (wlr_surface_is_xdg_surface(surface)) {
|
|
|
|
|
struct wlr_xdg_surface *xdg_surface =
|
|
|
|
|
wlr_xdg_surface_from_wlr_surface(surface);
|
|
|
|
|
if (xdg_surface) {
|
|
|
|
|
return xdg_surface->data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#if HAVE_XWAYLAND
|
|
|
|
|
if (wlr_surface_is_xwayland_surface(surface)) {
|
|
|
|
|
struct wlr_xwayland_surface *xsurface =
|
|
|
|
|
wlr_xwayland_surface_from_wlr_surface(surface);
|
|
|
|
|
if (xsurface) {
|
|
|
|
|
return xsurface->data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-28 18:55:29 +03:00
|
|
|
void
|
|
|
|
|
view_query_free(struct view_query *query)
|
|
|
|
|
{
|
|
|
|
|
wl_list_remove(&query->link);
|
|
|
|
|
free(query->identifier);
|
|
|
|
|
free(query->title);
|
|
|
|
|
free(query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
view_matches_query(struct view *view, struct view_query *query)
|
|
|
|
|
{
|
|
|
|
|
bool match = true;
|
|
|
|
|
bool empty = true;
|
|
|
|
|
|
|
|
|
|
const char *identifier = view_get_string_prop(view, "app_id");
|
|
|
|
|
if (match && query->identifier) {
|
|
|
|
|
empty = false;
|
|
|
|
|
match &= match_glob(query->identifier, identifier);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *title = view_get_string_prop(view, "title");
|
|
|
|
|
if (match && query->title) {
|
|
|
|
|
empty = false;
|
|
|
|
|
match &= match_glob(query->title, title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return !empty && match;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-18 22:18:59 +01:00
|
|
|
static bool
|
|
|
|
|
matches_criteria(struct view *view, enum lab_view_criteria criteria)
|
2023-08-10 15:46:00 +01:00
|
|
|
{
|
2023-09-25 22:42:06 -04:00
|
|
|
if (!view_is_focusable(view)) {
|
2023-08-18 22:18:59 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (criteria & LAB_VIEW_CRITERIA_CURRENT_WORKSPACE) {
|
|
|
|
|
/*
|
|
|
|
|
* Always-on-top views are always on the current desktop and are
|
|
|
|
|
* special in that they live in a different tree.
|
|
|
|
|
*/
|
|
|
|
|
struct server *server = view->server;
|
|
|
|
|
if (view->scene_tree->node.parent != server->workspace_current->tree
|
|
|
|
|
&& !view_is_always_on_top(view)) {
|
|
|
|
|
return false;
|
2023-08-10 15:46:00 +01:00
|
|
|
}
|
2023-08-18 22:18:59 +01:00
|
|
|
}
|
2023-11-10 23:58:25 +01:00
|
|
|
if (criteria & LAB_VIEW_CRITERIA_FULLSCREEN) {
|
|
|
|
|
if (!view->fullscreen) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-21 03:08:04 +01:00
|
|
|
if (criteria & LAB_VIEW_CRITERIA_ALWAYS_ON_TOP) {
|
|
|
|
|
if (!view_is_always_on_top(view)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-18 22:18:59 +01:00
|
|
|
if (criteria & LAB_VIEW_CRITERIA_NO_ALWAYS_ON_TOP) {
|
|
|
|
|
if (view_is_always_on_top(view)) {
|
|
|
|
|
return false;
|
2023-08-10 15:46:00 +01:00
|
|
|
}
|
2023-08-18 22:18:59 +01:00
|
|
|
}
|
|
|
|
|
if (criteria & LAB_VIEW_CRITERIA_NO_SKIP_WINDOW_SWITCHER) {
|
|
|
|
|
if (window_rules_get_property(view, "skipWindowSwitcher") == LAB_PROP_TRUE) {
|
|
|
|
|
return false;
|
2023-08-10 15:46:00 +01:00
|
|
|
}
|
2023-08-18 22:18:59 +01:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct view *
|
|
|
|
|
view_next(struct wl_list *head, struct view *view, enum lab_view_criteria criteria)
|
|
|
|
|
{
|
|
|
|
|
assert(head);
|
|
|
|
|
|
|
|
|
|
struct wl_list *elm = view ? &view->link : head;
|
|
|
|
|
|
|
|
|
|
for (elm = elm->next; elm != head; elm = elm->next) {
|
|
|
|
|
view = wl_container_of(elm, view, link);
|
|
|
|
|
if (matches_criteria(view, criteria)) {
|
|
|
|
|
return view;
|
2023-08-10 15:46:00 +01:00
|
|
|
}
|
2023-08-18 22:18:59 +01:00
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2023-08-10 15:46:00 +01:00
|
|
|
|
2023-08-18 22:18:59 +01:00
|
|
|
void
|
|
|
|
|
view_array_append(struct server *server, struct wl_array *views,
|
|
|
|
|
enum lab_view_criteria criteria)
|
|
|
|
|
{
|
|
|
|
|
struct view *view;
|
|
|
|
|
for_each_view(view, &server->views, criteria) {
|
2023-08-10 15:46:00 +01:00
|
|
|
struct view **entry = wl_array_add(views, sizeof(*entry));
|
2023-08-18 22:18:59 +01:00
|
|
|
if (!entry) {
|
|
|
|
|
wlr_log(WLR_ERROR, "wl_array_add(): out of memory");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2023-08-10 15:46:00 +01:00
|
|
|
*entry = view;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-15 01:11:12 -04:00
|
|
|
enum view_wants_focus
|
|
|
|
|
view_wants_focus(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
|
|
|
|
if (view->impl->wants_focus) {
|
|
|
|
|
return view->impl->wants_focus(view);
|
|
|
|
|
}
|
|
|
|
|
return VIEW_WANTS_FOCUS_ALWAYS;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-20 16:43:29 +01:00
|
|
|
bool
|
2023-10-14 16:29:13 -04:00
|
|
|
view_is_focusable_from(struct view *view, struct wlr_surface *prev)
|
2023-08-20 16:43:29 +01:00
|
|
|
{
|
2023-09-25 22:42:06 -04:00
|
|
|
assert(view);
|
2023-08-20 16:43:29 +01:00
|
|
|
if (!view->surface) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-10-14 16:29:13 -04:00
|
|
|
if (!view->mapped && !view->minimized) {
|
2023-09-23 11:51:47 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
2023-10-14 16:29:13 -04:00
|
|
|
enum view_wants_focus wants_focus = view_wants_focus(view);
|
|
|
|
|
/*
|
|
|
|
|
* Consider "offer focus" (Globally Active) views as focusable
|
|
|
|
|
* only if another surface from the same application already had
|
|
|
|
|
* focus. The goal is to allow focusing a parent window when a
|
|
|
|
|
* dialog/popup is closed, but still avoid focusing standalone
|
|
|
|
|
* panels/toolbars/notifications. Note that we are basically
|
|
|
|
|
* guessing whether Globally Active views want focus, and will
|
|
|
|
|
* probably be wrong some of the time.
|
|
|
|
|
*/
|
|
|
|
|
return (wants_focus == VIEW_WANTS_FOCUS_ALWAYS
|
|
|
|
|
|| (wants_focus == VIEW_WANTS_FOCUS_OFFER
|
|
|
|
|
&& prev && view_is_related(view, prev)));
|
2023-08-20 16:43:29 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-01 02:07:40 +02:00
|
|
|
/**
|
|
|
|
|
* All view_apply_xxx_geometry() functions must *not* modify
|
|
|
|
|
* any state besides repositioning or resizing the view.
|
|
|
|
|
*
|
|
|
|
|
* They may be called repeatably during output layout changes.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static enum view_edge
|
|
|
|
|
view_edge_invert(enum view_edge edge)
|
|
|
|
|
{
|
|
|
|
|
switch (edge) {
|
|
|
|
|
case VIEW_EDGE_LEFT:
|
|
|
|
|
return VIEW_EDGE_RIGHT;
|
|
|
|
|
case VIEW_EDGE_RIGHT:
|
|
|
|
|
return VIEW_EDGE_LEFT;
|
|
|
|
|
case VIEW_EDGE_UP:
|
|
|
|
|
return VIEW_EDGE_DOWN;
|
|
|
|
|
case VIEW_EDGE_DOWN:
|
|
|
|
|
return VIEW_EDGE_UP;
|
|
|
|
|
case VIEW_EDGE_CENTER:
|
|
|
|
|
case VIEW_EDGE_INVALID:
|
|
|
|
|
default:
|
|
|
|
|
return VIEW_EDGE_INVALID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct wlr_box
|
|
|
|
|
view_get_edge_snap_box(struct view *view, struct output *output,
|
|
|
|
|
enum view_edge edge)
|
|
|
|
|
{
|
2023-08-05 23:53:01 +02:00
|
|
|
struct wlr_box usable = output_usable_area_scaled(output);
|
2022-07-01 02:07:40 +02:00
|
|
|
int x_offset = edge == VIEW_EDGE_RIGHT
|
|
|
|
|
? (usable.width + rc.gap) / 2 : rc.gap;
|
|
|
|
|
int y_offset = edge == VIEW_EDGE_DOWN
|
|
|
|
|
? (usable.height + rc.gap) / 2 : rc.gap;
|
|
|
|
|
|
|
|
|
|
int base_width, base_height;
|
|
|
|
|
switch (edge) {
|
|
|
|
|
case VIEW_EDGE_LEFT:
|
|
|
|
|
case VIEW_EDGE_RIGHT:
|
|
|
|
|
base_width = (usable.width - 3 * rc.gap) / 2;
|
|
|
|
|
base_height = usable.height - 2 * rc.gap;
|
|
|
|
|
break;
|
|
|
|
|
case VIEW_EDGE_UP:
|
|
|
|
|
case VIEW_EDGE_DOWN:
|
|
|
|
|
base_width = usable.width - 2 * rc.gap;
|
|
|
|
|
base_height = (usable.height - 3 * rc.gap) / 2;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
case VIEW_EDGE_CENTER:
|
|
|
|
|
base_width = usable.width - 2 * rc.gap;
|
|
|
|
|
base_height = usable.height - 2 * rc.gap;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-11-26 16:06:22 -05:00
|
|
|
|
2022-11-26 16:46:28 -05:00
|
|
|
struct border margin = ssd_get_margin(view->ssd);
|
2022-07-01 02:07:40 +02:00
|
|
|
struct wlr_box dst = {
|
2022-11-26 16:06:22 -05:00
|
|
|
.x = x_offset + usable.x + margin.left,
|
|
|
|
|
.y = y_offset + usable.y + margin.top,
|
|
|
|
|
.width = base_width - margin.left - margin.right,
|
|
|
|
|
.height = base_height - margin.top - margin.bottom,
|
2022-07-01 02:07:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 16:22:01 -05:00
|
|
|
static void
|
|
|
|
|
view_discover_output(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
2023-02-28 11:46:48 -05:00
|
|
|
assert(!view->fullscreen);
|
2023-02-20 16:22:01 -05:00
|
|
|
view->output = output_nearest_to(view->server,
|
|
|
|
|
view->current.x + view->current.width / 2,
|
|
|
|
|
view->current.y + view->current.height / 2);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-27 18:24:35 -04:00
|
|
|
void
|
|
|
|
|
view_set_activated(struct view *view, bool activated)
|
2021-10-16 19:24:26 +01:00
|
|
|
{
|
2023-09-27 18:24:35 -04:00
|
|
|
assert(view);
|
2022-11-26 16:46:28 -05:00
|
|
|
ssd_set_active(view->ssd, activated);
|
2021-10-16 19:24:26 +01:00
|
|
|
if (view->impl->set_activated) {
|
|
|
|
|
view->impl->set_activated(view, activated);
|
|
|
|
|
}
|
2023-02-01 09:27:25 +01:00
|
|
|
if (view->toplevel.handle) {
|
2021-10-16 19:24:26 +01:00
|
|
|
wlr_foreign_toplevel_handle_v1_set_activated(
|
2023-02-01 09:27:25 +01:00
|
|
|
view->toplevel.handle, activated);
|
2021-10-16 19:24:26 +01:00
|
|
|
}
|
2023-09-07 16:41:47 +02:00
|
|
|
|
|
|
|
|
if (rc.kb_layout_per_window) {
|
|
|
|
|
if (!activated) {
|
|
|
|
|
/* Store configured keyboard layout per view */
|
|
|
|
|
view->keyboard_layout =
|
|
|
|
|
view->server->seat.keyboard_group->keyboard.modifiers.group;
|
|
|
|
|
} else {
|
|
|
|
|
/* Switch to previously stored keyboard layout */
|
|
|
|
|
keyboard_update_layout(&view->server->seat, view->keyboard_layout);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-16 19:24:26 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-28 11:46:48 -05:00
|
|
|
void
|
|
|
|
|
view_set_output(struct view *view, struct output *output)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
|
|
|
|
assert(!view->fullscreen);
|
|
|
|
|
if (!output_is_usable(output)) {
|
|
|
|
|
wlr_log(WLR_ERROR, "invalid output set for view");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
view->output = output;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-23 12:24:24 +01:00
|
|
|
void
|
|
|
|
|
view_close(struct view *view)
|
|
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2021-12-23 12:24:24 +01:00
|
|
|
if (view->impl->close) {
|
|
|
|
|
view->impl->close(view);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
void
|
2022-08-17 21:41:49 +01:00
|
|
|
view_move(struct view *view, int x, int y)
|
2020-05-26 12:56:33 +01:00
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2023-02-09 01:07:07 -05:00
|
|
|
view_move_resize(view, (struct wlr_box){
|
|
|
|
|
.x = x, .y = y,
|
|
|
|
|
.width = view->pending.width,
|
|
|
|
|
.height = view->pending.height
|
|
|
|
|
});
|
2022-07-17 23:42:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
view_moved(struct view *view)
|
|
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2023-02-08 23:19:14 -05:00
|
|
|
wlr_scene_node_set_position(&view->scene_tree->node,
|
|
|
|
|
view->current.x, view->current.y);
|
2023-02-20 16:22:01 -05:00
|
|
|
/*
|
|
|
|
|
* Only floating views change output when moved. Non-floating
|
|
|
|
|
* views (maximized/tiled/fullscreen) are tied to a particular
|
|
|
|
|
* output when they enter that state.
|
|
|
|
|
*/
|
|
|
|
|
if (view_is_floating(view)) {
|
|
|
|
|
view_discover_output(view);
|
|
|
|
|
}
|
2022-11-26 16:46:28 -05:00
|
|
|
ssd_update_geometry(view->ssd);
|
2022-09-12 13:14:18 -04:00
|
|
|
cursor_update_focus(view->server);
|
2023-02-02 07:16:57 +01:00
|
|
|
if (view->toplevel.handle) {
|
|
|
|
|
foreign_toplevel_update_outputs(view);
|
|
|
|
|
}
|
2023-08-17 18:59:29 +02:00
|
|
|
if (rc.resize_indicator && view->server->grabbed_view == view) {
|
|
|
|
|
resize_indicator_update(view);
|
|
|
|
|
}
|
2020-05-26 12:56:33 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-23 18:52:46 +00:00
|
|
|
void
|
2022-01-07 20:53:48 +00:00
|
|
|
view_move_resize(struct view *view, struct wlr_box geo)
|
2020-12-23 18:52:46 +00:00
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2022-01-07 20:53:48 +00:00
|
|
|
if (view->impl->configure) {
|
|
|
|
|
view->impl->configure(view, geo);
|
2021-10-18 19:35:41 +01:00
|
|
|
}
|
2020-12-23 18:52:46 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-27 21:20:04 +03:00
|
|
|
void
|
|
|
|
|
view_resize_relative(struct view *view, int left, int right, int top, int bottom)
|
|
|
|
|
{
|
2023-09-25 22:42:06 -04:00
|
|
|
assert(view);
|
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
2023-10-26 00:38:29 -04:00
|
|
|
if (view->fullscreen || view->maximized != VIEW_AXIS_NONE) {
|
2023-07-02 23:25:24 +03:00
|
|
|
return;
|
2023-07-23 12:04:36 +03:00
|
|
|
}
|
2023-06-27 21:20:04 +03:00
|
|
|
struct wlr_box newgeo = view->pending;
|
|
|
|
|
newgeo.x -= left;
|
|
|
|
|
newgeo.width += left + right;
|
|
|
|
|
newgeo.y -= top;
|
|
|
|
|
newgeo.height += top + bottom;
|
|
|
|
|
view_move_resize(view, newgeo);
|
2023-07-02 23:25:24 +03:00
|
|
|
view_set_untiled(view);
|
2023-06-27 21:20:04 +03:00
|
|
|
}
|
|
|
|
|
|
2023-07-23 12:04:36 +03:00
|
|
|
void
|
|
|
|
|
view_move_relative(struct view *view, int x, int y)
|
|
|
|
|
{
|
2023-09-25 22:42:06 -04:00
|
|
|
assert(view);
|
2023-07-23 12:04:36 +03:00
|
|
|
if (view->fullscreen) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
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
2023-10-26 00:38:29 -04:00
|
|
|
view_maximize(view, VIEW_AXIS_NONE, /*store_natural_geometry*/ false);
|
2023-07-23 12:04:36 +03:00
|
|
|
if (view_is_tiled(view)) {
|
|
|
|
|
view_set_untiled(view);
|
|
|
|
|
view_restore_to(view, view->natural_geometry);
|
|
|
|
|
}
|
|
|
|
|
view_move(view, view->pending.x + x, view->pending.y + y);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-14 14:57:44 +02:00
|
|
|
void
|
|
|
|
|
view_move_to_cursor(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
|
|
|
|
|
|
|
|
|
struct output *pending_output = output_nearest_to_cursor(view->server);
|
|
|
|
|
if (!output_is_usable(pending_output)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
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
2023-10-26 00:38:29 -04:00
|
|
|
view_set_fullscreen(view, false);
|
|
|
|
|
view_maximize(view, VIEW_AXIS_NONE, /*store_natural_geometry*/ false);
|
2023-10-14 14:57:44 +02:00
|
|
|
if (view_is_tiled(view)) {
|
|
|
|
|
view_set_untiled(view);
|
|
|
|
|
view_restore_to(view, view->natural_geometry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct border margin = ssd_thickness(view);
|
|
|
|
|
struct wlr_box geo = view->pending;
|
|
|
|
|
geo.width += margin.left + margin.right;
|
|
|
|
|
geo.height += margin.top + margin.bottom;
|
|
|
|
|
|
|
|
|
|
int x = view->server->seat.cursor->x - (geo.width / 2);
|
|
|
|
|
int y = view->server->seat.cursor->y - (geo.height / 2);
|
|
|
|
|
|
|
|
|
|
struct wlr_box usable = output_usable_area_in_layout_coords(pending_output);
|
|
|
|
|
if (x + geo.width > usable.x + usable.width) {
|
|
|
|
|
x = usable.x + usable.width - geo.width;
|
|
|
|
|
}
|
|
|
|
|
x = MAX(x, usable.x);
|
|
|
|
|
|
|
|
|
|
if (y + geo.height > usable.y + usable.height) {
|
|
|
|
|
y = usable.y + usable.height - geo.height;
|
|
|
|
|
}
|
|
|
|
|
y = MAX(y, usable.y);
|
|
|
|
|
|
|
|
|
|
x += margin.left;
|
|
|
|
|
y += margin.top;
|
|
|
|
|
view_move(view, x, y);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 01:22:19 -04:00
|
|
|
struct view_size_hints
|
|
|
|
|
view_get_size_hints(struct view *view)
|
|
|
|
|
{
|
2023-09-25 22:42:06 -04:00
|
|
|
assert(view);
|
2023-09-22 01:22:19 -04:00
|
|
|
if (view->impl->get_size_hints) {
|
|
|
|
|
return view->impl->get_size_hints(view);
|
|
|
|
|
}
|
|
|
|
|
return (struct view_size_hints){0};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
substitute_nonzero(int *a, int *b)
|
|
|
|
|
{
|
|
|
|
|
if (!(*a)) {
|
|
|
|
|
*a = *b;
|
|
|
|
|
} else if (!(*b)) {
|
|
|
|
|
*b = *a;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
round_to_increment(int val, int base, int inc)
|
|
|
|
|
{
|
|
|
|
|
if (base < 0 || inc <= 0) {
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
return base + (val - base + inc / 2) / inc * inc;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-17 18:31:53 +00:00
|
|
|
void
|
2022-04-02 21:34:51 -04:00
|
|
|
view_adjust_size(struct view *view, int *w, int *h)
|
2021-10-17 18:31:53 +00:00
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2023-09-22 01:22:19 -04:00
|
|
|
struct view_size_hints hints = view_get_size_hints(view);
|
2023-01-04 04:18:00 +01:00
|
|
|
|
2023-09-22 01:22:19 -04:00
|
|
|
/*
|
|
|
|
|
* "If a base size is not provided, the minimum size is to be
|
|
|
|
|
* used in its place and vice versa." (ICCCM 4.1.2.3)
|
|
|
|
|
*/
|
|
|
|
|
substitute_nonzero(&hints.min_width, &hints.base_width);
|
|
|
|
|
substitute_nonzero(&hints.min_height, &hints.base_height);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Snap width/height to requested size increments (if any).
|
|
|
|
|
* Typically, terminal emulators use these to make sure that the
|
|
|
|
|
* terminal is resized to a width/height evenly divisible by the
|
|
|
|
|
* cell (character) size.
|
|
|
|
|
*/
|
|
|
|
|
*w = round_to_increment(*w, hints.base_width, hints.width_inc);
|
|
|
|
|
*h = round_to_increment(*h, hints.base_height, hints.height_inc);
|
2023-01-04 04:18:00 +01:00
|
|
|
|
2023-09-22 01:22:19 -04:00
|
|
|
/*
|
|
|
|
|
* If a minimum width/height was not set, then use default.
|
|
|
|
|
* This is currently always the case for xdg-shell views.
|
|
|
|
|
*/
|
|
|
|
|
if (hints.min_width < 1) {
|
|
|
|
|
hints.min_width = LAB_MIN_VIEW_WIDTH;
|
|
|
|
|
}
|
|
|
|
|
if (hints.min_height < 1) {
|
|
|
|
|
hints.min_height = LAB_MIN_VIEW_HEIGHT;
|
|
|
|
|
}
|
|
|
|
|
*w = MAX(*w, hints.min_width);
|
|
|
|
|
*h = MAX(*h, hints.min_height);
|
2021-10-17 18:31:53 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-02 20:57:39 +01:00
|
|
|
static void
|
|
|
|
|
_minimize(struct view *view, bool minimized)
|
2020-09-08 20:51:33 +01:00
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2021-08-05 13:00:34 +01:00
|
|
|
if (view->minimized == minimized) {
|
2020-09-08 20:51:33 +01:00
|
|
|
return;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2023-02-01 09:27:25 +01:00
|
|
|
if (view->toplevel.handle) {
|
2021-11-26 18:49:44 +00:00
|
|
|
wlr_foreign_toplevel_handle_v1_set_minimized(
|
2023-02-01 09:27:25 +01:00
|
|
|
view->toplevel.handle, minimized);
|
2021-08-05 13:00:34 +01:00
|
|
|
}
|
2023-06-25 11:37:56 +01:00
|
|
|
if (view->impl->minimize) {
|
|
|
|
|
view->impl->minimize(view, minimized);
|
|
|
|
|
}
|
2021-08-05 13:00:34 +01:00
|
|
|
view->minimized = minimized;
|
|
|
|
|
if (minimized) {
|
2023-07-01 12:37:47 -04:00
|
|
|
view->impl->unmap(view, /* client_request */ false);
|
2021-08-05 13:00:34 +01:00
|
|
|
} else {
|
|
|
|
|
view->impl->map(view);
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-09-08 20:51:33 +01:00
|
|
|
}
|
2020-09-29 20:48:50 +01:00
|
|
|
|
2023-08-02 20:57:39 +01:00
|
|
|
static void
|
|
|
|
|
minimize_sub_views(struct view *view, bool minimized)
|
|
|
|
|
{
|
|
|
|
|
struct view **child;
|
|
|
|
|
struct wl_array children;
|
|
|
|
|
|
|
|
|
|
wl_array_init(&children);
|
|
|
|
|
view_append_children(view, &children);
|
|
|
|
|
wl_array_for_each(child, &children) {
|
|
|
|
|
_minimize(*child, minimized);
|
|
|
|
|
minimize_sub_views(*child, minimized);
|
|
|
|
|
}
|
|
|
|
|
wl_array_release(&children);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Minimize the whole view-hierarchy from top to bottom regardless of which one
|
|
|
|
|
* in the hierarchy requested the minimize. For example, if an 'About' or
|
|
|
|
|
* 'Open File' dialog is minimized, its toplevel is minimized also. And vice
|
|
|
|
|
* versa.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
view_minimize(struct view *view, bool minimized)
|
|
|
|
|
{
|
2023-09-25 22:42:06 -04:00
|
|
|
assert(view);
|
2023-08-02 20:57:39 +01:00
|
|
|
/*
|
|
|
|
|
* Minimize the root window first because some xwayland clients send a
|
|
|
|
|
* request-unmap to sub-windows at this point (for example gimp and its
|
|
|
|
|
* 'open file' dialog), so it saves trying to unmap them twice
|
|
|
|
|
*/
|
|
|
|
|
struct view *root = view_get_root(view);
|
|
|
|
|
_minimize(root, minimized);
|
|
|
|
|
minimize_sub_views(root, minimized);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-17 23:06:12 -04:00
|
|
|
bool
|
2023-02-20 16:23:53 -05:00
|
|
|
view_compute_centered_position(struct view *view, const struct wlr_box *ref,
|
|
|
|
|
int w, int h, int *x, int *y)
|
2021-07-09 21:39:20 +01:00
|
|
|
{
|
2023-11-03 12:38:07 -04:00
|
|
|
assert(view);
|
2023-02-15 12:52:57 -05:00
|
|
|
if (w <= 0 || h <= 0) {
|
|
|
|
|
wlr_log(WLR_ERROR, "view has empty geometry, not centering");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-02-20 16:35:23 -05:00
|
|
|
if (!output_is_usable(view->output)) {
|
|
|
|
|
wlr_log(WLR_ERROR, "view has no output, not centering");
|
2023-02-20 16:23:53 -05:00
|
|
|
return false;
|
2021-07-09 21:39:20 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-26 16:46:28 -05:00
|
|
|
struct border margin = ssd_get_margin(view->ssd);
|
2023-02-20 16:35:23 -05:00
|
|
|
struct wlr_box usable = output_usable_area_in_layout_coords(view->output);
|
2022-11-26 16:06:22 -05:00
|
|
|
int width = w + margin.left + margin.right;
|
|
|
|
|
int height = h + margin.top + margin.bottom;
|
2023-02-19 12:42:21 -05:00
|
|
|
|
|
|
|
|
/* If reference box is NULL then center to usable area */
|
|
|
|
|
if (!ref) {
|
|
|
|
|
ref = &usable;
|
|
|
|
|
}
|
|
|
|
|
*x = ref->x + (ref->width - width) / 2;
|
|
|
|
|
*y = ref->y + (ref->height - height) / 2;
|
2022-06-06 18:33:40 +01:00
|
|
|
|
2022-06-06 18:38:04 +01:00
|
|
|
/* If view is bigger than usable area, just top/left align it */
|
2023-02-19 09:56:58 -05:00
|
|
|
if (*x < usable.x) {
|
|
|
|
|
*x = usable.x;
|
2022-06-06 18:38:04 +01:00
|
|
|
}
|
2023-02-19 09:56:58 -05:00
|
|
|
if (*y < usable.y) {
|
|
|
|
|
*y = usable.y;
|
2022-06-06 18:38:04 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-19 12:42:21 -05:00
|
|
|
*x += margin.left;
|
|
|
|
|
*y += margin.top;
|
2022-06-06 18:33:40 +01:00
|
|
|
|
2021-12-31 17:30:55 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-03 12:38:07 -04:00
|
|
|
bool
|
|
|
|
|
view_adjust_floating_geometry(struct view *view, struct wlr_box *geometry)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
|
|
|
|
if (!output_is_usable(view->output)) {
|
|
|
|
|
wlr_log(WLR_ERROR, "view has no output, not positioning");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-09 21:44:51 +00:00
|
|
|
if (window_rules_get_property(view, "fixedPosition") == LAB_PROP_TRUE) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-03 12:38:07 -04:00
|
|
|
bool adjusted = false;
|
|
|
|
|
/*
|
|
|
|
|
* First check whether the view is onscreen. For now, "onscreen"
|
|
|
|
|
* is defined as even one pixel of the client area being visible.
|
|
|
|
|
*/
|
|
|
|
|
if (wlr_output_layout_intersects(view->server->output_layout,
|
|
|
|
|
NULL, geometry)) {
|
|
|
|
|
/*
|
|
|
|
|
* If onscreen, then make sure the titlebar is also
|
|
|
|
|
* visible (and not overlapping any panels/docks)
|
|
|
|
|
*/
|
|
|
|
|
struct border margin = ssd_get_margin(view->ssd);
|
|
|
|
|
struct wlr_box usable =
|
|
|
|
|
output_usable_area_in_layout_coords(view->output);
|
|
|
|
|
|
|
|
|
|
if (geometry->x < usable.x + margin.left) {
|
|
|
|
|
geometry->x = usable.x + margin.left;
|
|
|
|
|
adjusted = true;
|
|
|
|
|
}
|
|
|
|
|
if (geometry->y < usable.y + margin.top) {
|
|
|
|
|
geometry->y = usable.y + margin.top;
|
|
|
|
|
adjusted = true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* If offscreen, then just center the view */
|
|
|
|
|
adjusted = view_compute_centered_position(view, NULL,
|
|
|
|
|
geometry->width, geometry->height,
|
|
|
|
|
&geometry->x, &geometry->y);
|
|
|
|
|
}
|
|
|
|
|
return adjusted;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-02 20:23:14 +02:00
|
|
|
static void
|
|
|
|
|
set_fallback_geometry(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
view->natural_geometry.width = LAB_FALLBACK_WIDTH;
|
|
|
|
|
view->natural_geometry.height = LAB_FALLBACK_HEIGHT;
|
2023-02-20 16:23:53 -05:00
|
|
|
view_compute_centered_position(view, NULL,
|
2022-07-02 20:23:14 +02:00
|
|
|
view->natural_geometry.width,
|
|
|
|
|
view->natural_geometry.height,
|
|
|
|
|
&view->natural_geometry.x,
|
|
|
|
|
&view->natural_geometry.y);
|
|
|
|
|
}
|
2022-09-17 12:31:07 +01:00
|
|
|
|
2022-07-02 20:23:14 +02:00
|
|
|
#undef LAB_FALLBACK_WIDTH
|
|
|
|
|
#undef LAB_FALLBACK_HEIGHT
|
|
|
|
|
|
2022-11-19 12:58:52 -05:00
|
|
|
void
|
2022-07-02 20:23:14 +02:00
|
|
|
view_store_natural_geometry(struct view *view)
|
|
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2023-02-20 16:35:23 -05:00
|
|
|
if (!view_is_floating(view)) {
|
2022-12-31 22:23:00 +01:00
|
|
|
/* Do not overwrite the stored geometry with special cases */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-02 20:23:14 +02:00
|
|
|
/**
|
|
|
|
|
* If an application was started maximized or fullscreened, its
|
|
|
|
|
* natural_geometry width/height may still be zero in which case we set
|
|
|
|
|
* some fallback values. This is the case with foot and Qt applications.
|
|
|
|
|
*/
|
2023-02-09 01:27:30 -05:00
|
|
|
if (wlr_box_empty(&view->pending)) {
|
2022-07-02 20:23:14 +02:00
|
|
|
set_fallback_geometry(view);
|
|
|
|
|
} else {
|
2023-02-09 01:27:30 -05:00
|
|
|
view->natural_geometry = view->pending;
|
2022-07-02 20:23:14 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 17:30:55 -05:00
|
|
|
void
|
2023-02-20 16:23:53 -05:00
|
|
|
view_center(struct view *view, const struct wlr_box *ref)
|
2021-12-31 17:30:55 -05:00
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2021-12-31 17:30:55 -05:00
|
|
|
int x, y;
|
2023-02-20 16:23:53 -05:00
|
|
|
if (view_compute_centered_position(view, ref, view->pending.width,
|
|
|
|
|
view->pending.height, &x, &y)) {
|
2021-12-31 17:30:55 -05:00
|
|
|
view_move(view, x, y);
|
2021-12-24 15:53:49 -05:00
|
|
|
}
|
2021-12-31 17:30:55 -05:00
|
|
|
}
|
|
|
|
|
|
2023-01-02 16:25:34 +01:00
|
|
|
static void
|
|
|
|
|
view_apply_natural_geometry(struct view *view)
|
|
|
|
|
{
|
2023-02-20 16:35:23 -05:00
|
|
|
assert(view);
|
|
|
|
|
assert(view_is_floating(view));
|
|
|
|
|
|
2023-11-03 12:38:07 -04:00
|
|
|
struct wlr_box geometry = view->natural_geometry;
|
|
|
|
|
view_adjust_floating_geometry(view, &geometry);
|
|
|
|
|
view_move_resize(view, geometry);
|
2023-01-02 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-06 17:04:21 +02:00
|
|
|
static void
|
|
|
|
|
view_apply_region_geometry(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
2023-01-01 18:12:20 +01:00
|
|
|
assert(view->tiled_region || view->tiled_region_evacuate);
|
2023-02-20 16:35:23 -05:00
|
|
|
struct output *output = view->output;
|
|
|
|
|
assert(output_is_usable(output));
|
2022-07-06 17:04:21 +02:00
|
|
|
|
2022-07-07 19:05:54 +02:00
|
|
|
if (view->tiled_region_evacuate) {
|
|
|
|
|
/* View was evacuated from a destroying output */
|
2023-01-01 18:12:20 +01:00
|
|
|
/* Get new output local region, may be NULL */
|
2022-07-07 19:05:54 +02:00
|
|
|
view->tiled_region = regions_from_name(
|
|
|
|
|
view->tiled_region_evacuate, output);
|
|
|
|
|
|
|
|
|
|
/* Get rid of the evacuate instruction */
|
|
|
|
|
zfree(view->tiled_region_evacuate);
|
|
|
|
|
|
|
|
|
|
if (!view->tiled_region) {
|
|
|
|
|
/* Existing region name doesn't exist in rc.xml anymore */
|
|
|
|
|
view_set_untiled(view);
|
|
|
|
|
view_apply_natural_geometry(view);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 17:04:21 +02:00
|
|
|
/* Create a copy of the original region geometry */
|
|
|
|
|
struct wlr_box geo = view->tiled_region->geo;
|
|
|
|
|
|
2022-09-16 06:08:28 +02:00
|
|
|
/* Adjust for rc.gap */
|
2023-02-20 16:35:23 -05:00
|
|
|
if (rc.gap) {
|
2022-09-16 06:08:28 +02:00
|
|
|
double half_gap = rc.gap / 2.0;
|
|
|
|
|
struct wlr_fbox offset = {
|
|
|
|
|
.x = half_gap,
|
|
|
|
|
.y = half_gap,
|
|
|
|
|
.width = -rc.gap,
|
|
|
|
|
.height = -rc.gap
|
|
|
|
|
};
|
|
|
|
|
struct wlr_box usable =
|
|
|
|
|
output_usable_area_in_layout_coords(output);
|
|
|
|
|
if (geo.x == usable.x) {
|
|
|
|
|
offset.x += half_gap;
|
|
|
|
|
offset.width -= half_gap;
|
|
|
|
|
}
|
|
|
|
|
if (geo.y == usable.y) {
|
|
|
|
|
offset.y += half_gap;
|
|
|
|
|
offset.height -= half_gap;
|
|
|
|
|
}
|
|
|
|
|
if (geo.x + geo.width == usable.x + usable.width) {
|
|
|
|
|
offset.width -= half_gap;
|
|
|
|
|
}
|
|
|
|
|
if (geo.y + geo.height == usable.y + usable.height) {
|
|
|
|
|
offset.height -= half_gap;
|
|
|
|
|
}
|
|
|
|
|
geo.x += offset.x;
|
|
|
|
|
geo.y += offset.y;
|
|
|
|
|
geo.width += offset.width;
|
|
|
|
|
geo.height += offset.height;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 17:04:21 +02:00
|
|
|
/* And adjust for current view */
|
|
|
|
|
struct border margin = ssd_get_margin(view->ssd);
|
|
|
|
|
geo.x += margin.left;
|
|
|
|
|
geo.y += margin.top;
|
|
|
|
|
geo.width -= margin.left + margin.right;
|
|
|
|
|
geo.height -= margin.top + margin.bottom;
|
|
|
|
|
|
2023-02-12 07:38:48 +01:00
|
|
|
view_move_resize(view, geo);
|
2022-07-06 17:04:21 +02:00
|
|
|
}
|
|
|
|
|
|
2022-07-01 02:07:40 +02:00
|
|
|
static void
|
2023-02-20 16:14:27 -05:00
|
|
|
view_apply_tiled_geometry(struct view *view)
|
2022-07-01 02:07:40 +02:00
|
|
|
{
|
2023-02-20 16:35:23 -05:00
|
|
|
assert(view);
|
2022-07-01 02:07:40 +02:00
|
|
|
assert(view->tiled);
|
2023-02-20 16:35:23 -05:00
|
|
|
assert(output_is_usable(view->output));
|
2022-07-01 02:07:40 +02:00
|
|
|
|
2023-02-20 16:35:23 -05:00
|
|
|
view_move_resize(view, view_get_edge_snap_box(view,
|
|
|
|
|
view->output, view->tiled));
|
2022-07-01 02:07:40 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-31 17:30:55 -05:00
|
|
|
static void
|
2023-02-15 02:12:22 -05:00
|
|
|
view_apply_fullscreen_geometry(struct view *view)
|
2021-12-31 17:30:55 -05:00
|
|
|
{
|
2023-02-20 16:35:23 -05:00
|
|
|
assert(view);
|
2023-02-15 02:12:22 -05:00
|
|
|
assert(view->fullscreen);
|
|
|
|
|
assert(output_is_usable(view->output));
|
|
|
|
|
|
2021-12-31 17:30:55 -05:00
|
|
|
struct wlr_box box = { 0 };
|
2023-02-15 02:12:22 -05:00
|
|
|
wlr_output_effective_resolution(view->output->wlr_output,
|
|
|
|
|
&box.width, &box.height);
|
2021-12-31 17:30:55 -05:00
|
|
|
double ox = 0, oy = 0;
|
2023-02-15 02:12:22 -05:00
|
|
|
wlr_output_layout_output_coords(view->server->output_layout,
|
|
|
|
|
view->output->wlr_output, &ox, &oy);
|
2021-12-31 17:30:55 -05:00
|
|
|
box.x -= ox;
|
|
|
|
|
box.y -= oy;
|
|
|
|
|
view_move_resize(view, box);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
view_apply_maximized_geometry(struct view *view)
|
|
|
|
|
{
|
2023-02-20 16:35:23 -05:00
|
|
|
assert(view);
|
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
2023-10-26 00:38:29 -04:00
|
|
|
assert(view->maximized != VIEW_AXIS_NONE);
|
2023-02-20 16:35:23 -05:00
|
|
|
struct output *output = view->output;
|
|
|
|
|
assert(output_is_usable(output));
|
|
|
|
|
|
2021-12-31 17:30:55 -05:00
|
|
|
struct wlr_box box = output_usable_area_in_layout_coords(output);
|
2022-04-04 20:53:36 +01:00
|
|
|
if (box.height == output->wlr_output->height
|
|
|
|
|
&& output->wlr_output->scale != 1) {
|
2021-12-31 17:30:55 -05:00
|
|
|
box.height /= output->wlr_output->scale;
|
|
|
|
|
}
|
2022-04-04 20:53:36 +01:00
|
|
|
if (box.width == output->wlr_output->width
|
|
|
|
|
&& output->wlr_output->scale != 1) {
|
2021-12-31 17:30:55 -05:00
|
|
|
box.width /= output->wlr_output->scale;
|
|
|
|
|
}
|
|
|
|
|
|
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
2023-10-26 00:38:29 -04:00
|
|
|
/*
|
|
|
|
|
* If one axis (horizontal or vertical) is unmaximized, it
|
|
|
|
|
* should use the natural geometry. But if that geometry is not
|
|
|
|
|
* on-screen on the output where the view is maximized, then
|
|
|
|
|
* center the unmaximized axis.
|
|
|
|
|
*/
|
|
|
|
|
struct wlr_box natural = view->natural_geometry;
|
|
|
|
|
if (view->maximized != VIEW_AXIS_BOTH) {
|
|
|
|
|
struct wlr_box intersect;
|
|
|
|
|
wlr_box_intersection(&intersect, &box, &natural);
|
|
|
|
|
if (wlr_box_empty(&intersect)) {
|
|
|
|
|
view_compute_centered_position(view, NULL,
|
|
|
|
|
natural.width, natural.height,
|
|
|
|
|
&natural.x, &natural.y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 15:38:20 -05:00
|
|
|
if (view->ssd_enabled) {
|
2021-12-31 17:30:55 -05:00
|
|
|
struct border border = ssd_thickness(view);
|
|
|
|
|
box.x += border.left;
|
|
|
|
|
box.y += border.top;
|
|
|
|
|
box.width -= border.right + border.left;
|
|
|
|
|
box.height -= border.top + border.bottom;
|
|
|
|
|
}
|
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
2023-10-26 00:38:29 -04:00
|
|
|
|
|
|
|
|
if (view->maximized == VIEW_AXIS_VERTICAL) {
|
|
|
|
|
box.x = natural.x;
|
|
|
|
|
box.width = natural.width;
|
|
|
|
|
} else if (view->maximized == VIEW_AXIS_HORIZONTAL) {
|
|
|
|
|
box.y = natural.y;
|
|
|
|
|
box.height = natural.height;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 17:30:55 -05:00
|
|
|
view_move_resize(view, box);
|
|
|
|
|
}
|
2021-12-24 15:53:49 -05:00
|
|
|
|
2023-02-20 16:29:41 -05:00
|
|
|
static void
|
2022-12-31 22:01:51 +01:00
|
|
|
view_apply_special_geometry(struct view *view)
|
|
|
|
|
{
|
2023-02-20 16:29:41 -05:00
|
|
|
assert(view);
|
|
|
|
|
assert(!view_is_floating(view));
|
2023-02-20 16:35:23 -05:00
|
|
|
if (!output_is_usable(view->output)) {
|
|
|
|
|
wlr_log(WLR_ERROR, "view has no output, not updating geometry");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-02-20 16:29:41 -05:00
|
|
|
|
2023-02-15 13:46:29 -05:00
|
|
|
if (view->fullscreen) {
|
|
|
|
|
view_apply_fullscreen_geometry(view);
|
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
2023-10-26 00:38:29 -04:00
|
|
|
} else if (view->maximized != VIEW_AXIS_NONE) {
|
2022-12-31 22:01:51 +01:00
|
|
|
view_apply_maximized_geometry(view);
|
|
|
|
|
} else if (view->tiled) {
|
2023-02-20 16:14:27 -05:00
|
|
|
view_apply_tiled_geometry(view);
|
2023-01-01 18:12:20 +01:00
|
|
|
} else if (view->tiled_region || view->tiled_region_evacuate) {
|
2022-07-06 17:04:21 +02:00
|
|
|
view_apply_region_geometry(view);
|
2022-12-31 22:01:51 +01:00
|
|
|
} else {
|
2023-02-20 16:29:41 -05:00
|
|
|
assert(false); // not reached
|
2022-12-31 22:01:51 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-16 16:30:38 -05:00
|
|
|
/* For internal use only. Does not update geometry. */
|
2022-11-19 12:58:52 -05:00
|
|
|
static void
|
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
2023-10-26 00:38:29 -04:00
|
|
|
set_maximized(struct view *view, enum view_axis maximized)
|
2022-11-19 12:58:52 -05:00
|
|
|
{
|
|
|
|
|
if (view->impl->maximize) {
|
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
2023-10-26 00:38:29 -04:00
|
|
|
view->impl->maximize(view, (maximized == VIEW_AXIS_BOTH));
|
2022-11-19 12:58:52 -05:00
|
|
|
}
|
2023-02-01 09:27:25 +01:00
|
|
|
if (view->toplevel.handle) {
|
2022-11-19 12:58:52 -05:00
|
|
|
wlr_foreign_toplevel_handle_v1_set_maximized(
|
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
2023-10-26 00:38:29 -04:00
|
|
|
view->toplevel.handle, (maximized == VIEW_AXIS_BOTH));
|
2022-11-19 12:58:52 -05:00
|
|
|
}
|
|
|
|
|
view->maximized = maximized;
|
2023-08-25 13:22:23 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Ensure that follow-up actions like SnapToEdge / SnapToRegion
|
|
|
|
|
* use up-to-date SSD margin information. Otherwise we will end
|
|
|
|
|
* up using an outdated ssd->margin to calculate offsets.
|
|
|
|
|
*/
|
|
|
|
|
ssd_update_margin(view->ssd);
|
2022-11-19 12:58:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Un-maximize view and move it to specific geometry. Does not reset
|
2022-11-21 13:17:14 -05:00
|
|
|
* tiled state (use view_set_untiled() if you want that).
|
2022-11-19 12:58:52 -05:00
|
|
|
*/
|
2021-02-27 17:10:53 -05:00
|
|
|
void
|
2022-11-19 12:58:52 -05:00
|
|
|
view_restore_to(struct view *view, struct wlr_box geometry)
|
|
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2022-11-19 12:58:52 -05:00
|
|
|
if (view->fullscreen) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
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
2023-10-26 00:38:29 -04:00
|
|
|
if (view->maximized != VIEW_AXIS_NONE) {
|
|
|
|
|
set_maximized(view, VIEW_AXIS_NONE);
|
2022-11-19 12:58:52 -05:00
|
|
|
}
|
|
|
|
|
view_move_resize(view, geometry);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-01 18:12:20 +01:00
|
|
|
bool
|
|
|
|
|
view_is_tiled(struct view *view)
|
|
|
|
|
{
|
2023-09-25 22:42:06 -04:00
|
|
|
assert(view);
|
|
|
|
|
return (view->tiled || view->tiled_region
|
2023-02-11 09:36:42 +01:00
|
|
|
|| view->tiled_region_evacuate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
view_is_floating(struct view *view)
|
|
|
|
|
{
|
2023-09-25 22:42:06 -04:00
|
|
|
assert(view);
|
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
2023-10-26 00:38:29 -04:00
|
|
|
return !(view->fullscreen || (view->maximized != VIEW_AXIS_NONE)
|
|
|
|
|
|| view_is_tiled(view));
|
2023-01-01 18:12:20 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-21 13:17:14 -05:00
|
|
|
/* Reset tiled state of view without changing geometry */
|
|
|
|
|
void
|
|
|
|
|
view_set_untiled(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
|
|
|
|
view->tiled = VIEW_EDGE_INVALID;
|
2022-07-06 17:04:21 +02:00
|
|
|
view->tiled_region = NULL;
|
2023-01-01 18:12:20 +01:00
|
|
|
zfree(view->tiled_region_evacuate);
|
2022-11-21 13:17:14 -05:00
|
|
|
}
|
|
|
|
|
|
2022-11-19 12:58:52 -05:00
|
|
|
void
|
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
2023-10-26 00:38:29 -04:00
|
|
|
view_maximize(struct view *view, enum view_axis axis,
|
|
|
|
|
bool store_natural_geometry)
|
2021-02-27 17:10:53 -05:00
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
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
2023-10-26 00:38:29 -04:00
|
|
|
if (view->maximized == axis) {
|
2021-03-12 21:27:17 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2022-01-02 10:19:48 -05:00
|
|
|
if (view->fullscreen) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
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
2023-10-26 00:38:29 -04:00
|
|
|
if (axis != VIEW_AXIS_NONE) {
|
2022-11-19 12:58:52 -05:00
|
|
|
/*
|
|
|
|
|
* Maximize via keybind or client request cancels
|
|
|
|
|
* interactive move/resize since we can't move/resize
|
|
|
|
|
* a maximized view.
|
|
|
|
|
*/
|
|
|
|
|
interactive_cancel(view);
|
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
2023-10-26 00:38:29 -04:00
|
|
|
if (store_natural_geometry && view_is_floating(view)) {
|
2022-07-01 20:42:41 +02:00
|
|
|
view_store_natural_geometry(view);
|
|
|
|
|
}
|
2022-12-31 22:01:51 +01:00
|
|
|
}
|
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
2023-10-26 00:38:29 -04:00
|
|
|
set_maximized(view, axis);
|
2023-02-20 16:29:41 -05:00
|
|
|
if (view_is_floating(view)) {
|
2023-01-01 03:57:19 +01:00
|
|
|
view_apply_natural_geometry(view);
|
2023-02-20 16:29:41 -05:00
|
|
|
} else {
|
|
|
|
|
view_apply_special_geometry(view);
|
2021-02-27 17:10:53 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-02 16:49:41 +01:00
|
|
|
void
|
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
2023-10-26 00:38:29 -04:00
|
|
|
view_toggle_maximize(struct view *view, enum view_axis axis)
|
2021-08-02 16:49:41 +01:00
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
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
2023-10-26 00:38:29 -04:00
|
|
|
switch (axis) {
|
|
|
|
|
case VIEW_AXIS_HORIZONTAL:
|
|
|
|
|
case VIEW_AXIS_VERTICAL:
|
|
|
|
|
/* Toggle one axis (XOR) */
|
|
|
|
|
view_maximize(view, view->maximized ^ axis,
|
|
|
|
|
/*store_natural_geometry*/ true);
|
|
|
|
|
break;
|
|
|
|
|
case VIEW_AXIS_BOTH:
|
|
|
|
|
/*
|
|
|
|
|
* Maximize in both directions if unmaximized or partially
|
|
|
|
|
* maximized, otherwise unmaximize.
|
|
|
|
|
*/
|
|
|
|
|
view_maximize(view, (view->maximized == VIEW_AXIS_BOTH) ?
|
|
|
|
|
VIEW_AXIS_NONE : VIEW_AXIS_BOTH,
|
|
|
|
|
/*store_natural_geometry*/ true);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-08-02 16:49:41 +01:00
|
|
|
}
|
|
|
|
|
|
2021-09-19 22:16:56 +00:00
|
|
|
void
|
|
|
|
|
view_toggle_decorations(struct view *view)
|
|
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2023-04-14 09:01:13 +02:00
|
|
|
if (rc.ssd_keep_border && view->ssd_enabled && view->ssd
|
2023-09-17 22:41:46 +02:00
|
|
|
&& !view->ssd_titlebar_hidden) {
|
|
|
|
|
/*
|
|
|
|
|
* ssd_titlebar_hidden has to be set before calling
|
|
|
|
|
* ssd_titlebar_hide() to make ssd_thickness() happy.
|
|
|
|
|
*/
|
2023-04-14 09:01:13 +02:00
|
|
|
view->ssd_titlebar_hidden = true;
|
2023-09-17 22:41:46 +02:00
|
|
|
ssd_titlebar_hide(view->ssd);
|
2023-04-14 09:01:13 +02:00
|
|
|
if (!view_is_floating(view)) {
|
|
|
|
|
view_apply_special_geometry(view);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-21 15:38:20 -05:00
|
|
|
view_set_decorations(view, !view->ssd_enabled);
|
2021-09-19 22:16:56 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-29 04:50:21 +01:00
|
|
|
bool
|
|
|
|
|
view_is_always_on_top(struct view *view)
|
2022-04-09 01:16:09 +02:00
|
|
|
{
|
2022-12-29 04:50:21 +01:00
|
|
|
assert(view);
|
2022-04-09 01:16:09 +02:00
|
|
|
return view->scene_tree->node.parent ==
|
2022-06-05 15:17:35 +02:00
|
|
|
view->server->view_tree_always_on_top;
|
2022-04-09 01:16:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
view_toggle_always_on_top(struct view *view)
|
|
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2022-12-29 04:50:21 +01:00
|
|
|
if (view_is_always_on_top(view)) {
|
2022-06-15 02:02:50 +02:00
|
|
|
view->workspace = view->server->workspace_current;
|
2022-11-21 13:03:49 -05:00
|
|
|
wlr_scene_node_reparent(&view->scene_tree->node,
|
|
|
|
|
view->workspace->tree);
|
2022-04-09 01:16:09 +02:00
|
|
|
} else {
|
|
|
|
|
wlr_scene_node_reparent(&view->scene_tree->node,
|
2022-06-05 15:17:35 +02:00
|
|
|
view->server->view_tree_always_on_top);
|
2022-04-09 01:16:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-14 23:42:56 +02:00
|
|
|
bool
|
2023-05-11 22:26:41 +01:00
|
|
|
view_is_always_on_bottom(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
|
|
|
|
return view->scene_tree->node.parent ==
|
|
|
|
|
view->server->view_tree_always_on_bottom;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
view_toggle_always_on_bottom(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
|
|
|
|
if (view_is_always_on_bottom(view)) {
|
|
|
|
|
view->workspace = view->server->workspace_current;
|
|
|
|
|
wlr_scene_node_reparent(&view->scene_tree->node,
|
|
|
|
|
view->workspace->tree);
|
|
|
|
|
} else {
|
|
|
|
|
wlr_scene_node_reparent(&view->scene_tree->node,
|
|
|
|
|
view->server->view_tree_always_on_bottom);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 13:03:49 -05:00
|
|
|
void
|
|
|
|
|
view_move_to_workspace(struct view *view, struct workspace *workspace)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
|
|
|
|
assert(workspace);
|
|
|
|
|
if (view->workspace != workspace) {
|
|
|
|
|
view->workspace = workspace;
|
|
|
|
|
wlr_scene_node_reparent(&view->scene_tree->node,
|
|
|
|
|
workspace->tree);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-26 16:46:28 -05:00
|
|
|
static void
|
|
|
|
|
decorate(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
if (!view->ssd) {
|
|
|
|
|
view->ssd = ssd_create(view,
|
|
|
|
|
view == view->server->focused_view);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
undecorate(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
ssd_destroy(view->ssd);
|
|
|
|
|
view->ssd = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-20 16:03:27 +00:00
|
|
|
void
|
|
|
|
|
view_set_decorations(struct view *view, bool decorations)
|
|
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2023-04-28 21:41:41 +01:00
|
|
|
|
2022-11-21 15:38:20 -05:00
|
|
|
if (view->ssd_enabled != decorations && !view->fullscreen) {
|
2022-11-26 22:49:10 -05:00
|
|
|
/*
|
|
|
|
|
* Set view->ssd_enabled first since it is referenced
|
|
|
|
|
* within the call tree of ssd_create()
|
|
|
|
|
*/
|
|
|
|
|
view->ssd_enabled = decorations;
|
2022-11-26 02:00:38 -05:00
|
|
|
if (decorations) {
|
2022-11-26 16:46:28 -05:00
|
|
|
decorate(view);
|
2022-11-26 02:00:38 -05:00
|
|
|
} else {
|
2022-11-26 16:46:28 -05:00
|
|
|
undecorate(view);
|
2023-04-14 09:01:13 +02:00
|
|
|
view->ssd_titlebar_hidden = false;
|
2022-11-26 02:00:38 -05:00
|
|
|
}
|
2023-02-20 16:29:41 -05:00
|
|
|
if (!view_is_floating(view)) {
|
|
|
|
|
view_apply_special_geometry(view);
|
|
|
|
|
}
|
2021-10-20 16:03:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-19 22:16:56 +00:00
|
|
|
void
|
|
|
|
|
view_toggle_fullscreen(struct view *view)
|
|
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2023-02-20 13:36:15 -05:00
|
|
|
view_set_fullscreen(view, !view->fullscreen);
|
2021-09-19 22:16:56 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-16 16:30:38 -05:00
|
|
|
/* For internal use only. Does not update geometry. */
|
|
|
|
|
static void
|
|
|
|
|
set_fullscreen(struct view *view, bool fullscreen)
|
2021-08-23 22:05:30 +01:00
|
|
|
{
|
2023-02-16 16:30:38 -05:00
|
|
|
/* Hide decorations when going fullscreen */
|
|
|
|
|
if (fullscreen && view->ssd_enabled) {
|
|
|
|
|
undecorate(view);
|
2022-12-26 23:10:11 +01:00
|
|
|
}
|
2023-02-16 16:30:38 -05:00
|
|
|
|
2021-08-23 22:05:30 +01:00
|
|
|
if (view->impl->set_fullscreen) {
|
2021-08-24 21:53:20 +01:00
|
|
|
view->impl->set_fullscreen(view, fullscreen);
|
2021-08-23 22:05:30 +01:00
|
|
|
}
|
2023-02-01 09:27:25 +01:00
|
|
|
if (view->toplevel.handle) {
|
2021-08-23 22:05:30 +01:00
|
|
|
wlr_foreign_toplevel_handle_v1_set_fullscreen(
|
2023-02-01 09:27:25 +01:00
|
|
|
view->toplevel.handle, fullscreen);
|
2021-08-23 22:05:30 +01:00
|
|
|
}
|
2023-02-16 16:30:38 -05:00
|
|
|
view->fullscreen = fullscreen;
|
|
|
|
|
|
|
|
|
|
/* Re-show decorations when no longer fullscreen */
|
|
|
|
|
if (!fullscreen && view->ssd_enabled) {
|
|
|
|
|
decorate(view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Show fullscreen views above top-layer */
|
|
|
|
|
if (view->output) {
|
2023-11-10 23:58:25 +01:00
|
|
|
desktop_update_top_layer_visiblity(view->server);
|
2023-02-16 16:30:38 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2023-02-20 13:36:15 -05:00
|
|
|
view_set_fullscreen(struct view *view, bool fullscreen)
|
2023-02-16 16:30:38 -05:00
|
|
|
{
|
|
|
|
|
assert(view);
|
|
|
|
|
if (fullscreen == view->fullscreen) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-08-23 22:05:30 +01:00
|
|
|
if (fullscreen) {
|
2023-02-20 16:35:23 -05:00
|
|
|
if (!output_is_usable(view->output)) {
|
2023-02-20 13:36:15 -05:00
|
|
|
/* Prevent fullscreen with no available outputs */
|
|
|
|
|
return;
|
2023-02-16 16:30:38 -05:00
|
|
|
}
|
2022-11-19 12:58:52 -05:00
|
|
|
/*
|
|
|
|
|
* Fullscreen via keybind or client request cancels
|
|
|
|
|
* interactive move/resize since we can't move/resize
|
|
|
|
|
* a fullscreen view.
|
|
|
|
|
*/
|
|
|
|
|
interactive_cancel(view);
|
2022-12-31 22:23:00 +01:00
|
|
|
view_store_natural_geometry(view);
|
2023-02-16 16:30:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_fullscreen(view, fullscreen);
|
2023-02-20 16:29:41 -05:00
|
|
|
if (view_is_floating(view)) {
|
2023-02-15 13:46:29 -05:00
|
|
|
view_apply_natural_geometry(view);
|
2023-02-20 16:29:41 -05:00
|
|
|
} else {
|
|
|
|
|
view_apply_special_geometry(view);
|
2021-08-23 22:05:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 17:30:55 -05:00
|
|
|
void
|
|
|
|
|
view_adjust_for_layout_change(struct view *view)
|
|
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2023-02-20 12:53:00 -05:00
|
|
|
|
|
|
|
|
/* Exit fullscreen if output is lost */
|
|
|
|
|
bool was_fullscreen = view->fullscreen;
|
|
|
|
|
if (was_fullscreen && !output_is_usable(view->output)) {
|
|
|
|
|
set_fullscreen(view, false);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 16:22:01 -05:00
|
|
|
/*
|
|
|
|
|
* Floating views are always assigned to the nearest output.
|
|
|
|
|
* Maximized/tiled views remain on the same output if possible.
|
|
|
|
|
*/
|
2023-02-20 16:29:41 -05:00
|
|
|
bool is_floating = view_is_floating(view);
|
|
|
|
|
if (is_floating || !output_is_usable(view->output)) {
|
2023-02-20 16:22:01 -05:00
|
|
|
view_discover_output(view);
|
|
|
|
|
}
|
2023-02-20 12:53:00 -05:00
|
|
|
|
2023-02-20 16:29:41 -05:00
|
|
|
if (!is_floating) {
|
|
|
|
|
view_apply_special_geometry(view);
|
|
|
|
|
} else if (was_fullscreen) {
|
|
|
|
|
view_apply_natural_geometry(view);
|
|
|
|
|
} else {
|
|
|
|
|
/* reposition view if it's offscreen */
|
2023-11-03 12:38:07 -04:00
|
|
|
struct wlr_box geometry = view->pending;
|
|
|
|
|
if (view_adjust_floating_geometry(view, &geometry)) {
|
|
|
|
|
view_move_resize(view, geometry);
|
2022-01-08 11:46:46 -05:00
|
|
|
}
|
2021-12-31 17:30:55 -05:00
|
|
|
}
|
2023-02-01 09:27:25 +01:00
|
|
|
if (view->toplevel.handle) {
|
2023-02-02 07:16:57 +01:00
|
|
|
foreign_toplevel_update_outputs(view);
|
2021-11-13 12:32:01 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-16 11:54:18 -05:00
|
|
|
void
|
|
|
|
|
view_evacuate_region(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
|
|
|
|
assert(view->tiled_region);
|
|
|
|
|
if (!view->tiled_region_evacuate) {
|
|
|
|
|
view->tiled_region_evacuate = xstrdup(view->tiled_region->name);
|
|
|
|
|
}
|
|
|
|
|
view->tiled_region = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-24 21:12:24 +02:00
|
|
|
void
|
|
|
|
|
view_on_output_destroy(struct view *view)
|
|
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2023-02-28 11:46:48 -05:00
|
|
|
/*
|
|
|
|
|
* This is the only time we modify view->output for a fullscreen
|
|
|
|
|
* view. We expect view_adjust_for_layout_change() to be called
|
|
|
|
|
* shortly afterward, which will exit fullscreen.
|
|
|
|
|
*/
|
2022-08-24 21:12:24 +02:00
|
|
|
view->output = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-20 19:54:57 +01:00
|
|
|
void
|
2023-08-05 23:58:40 +02:00
|
|
|
view_move_to_edge(struct view *view, enum view_edge direction, bool snap_to_windows)
|
2021-07-20 19:54:57 +01:00
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2023-08-05 23:58:40 +02:00
|
|
|
if (!output_is_usable(view->output)) {
|
2023-02-20 16:35:23 -05:00
|
|
|
wlr_log(WLR_ERROR, "view has no output, not moving to edge");
|
2021-10-18 19:35:41 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2022-11-26 16:06:22 -05:00
|
|
|
|
2023-08-05 23:58:40 +02:00
|
|
|
int dx = 0, dy = 0;
|
|
|
|
|
if (snap_to_windows) {
|
|
|
|
|
snap_vector_to_next_edge(view, direction, &dx, &dy);
|
|
|
|
|
} else {
|
|
|
|
|
struct border distance = snap_get_max_distance(view);
|
|
|
|
|
switch (direction) {
|
|
|
|
|
case VIEW_EDGE_LEFT:
|
|
|
|
|
dx = distance.left;
|
|
|
|
|
break;
|
|
|
|
|
case VIEW_EDGE_UP:
|
|
|
|
|
dy = distance.top;
|
|
|
|
|
break;
|
|
|
|
|
case VIEW_EDGE_RIGHT:
|
|
|
|
|
dx = distance.right;
|
|
|
|
|
break;
|
|
|
|
|
case VIEW_EDGE_DOWN:
|
|
|
|
|
dy = distance.bottom;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-11-24 17:15:37 -05:00
|
|
|
}
|
2021-07-20 19:54:57 +01:00
|
|
|
|
2023-08-05 23:58:40 +02:00
|
|
|
view_move(view, view->pending.x + dx, view->pending.y + dy);
|
2021-07-20 19:54:57 +01:00
|
|
|
}
|
2021-08-05 12:18:10 +01:00
|
|
|
|
2023-08-05 23:58:40 +02:00
|
|
|
void
|
|
|
|
|
view_grow_to_edge(struct view *view, enum view_edge direction)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
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
2023-10-26 00:38:29 -04:00
|
|
|
/* TODO: allow grow to edge if maximized along the other axis */
|
|
|
|
|
if (view->fullscreen || view->maximized != VIEW_AXIS_NONE) {
|
2023-08-05 23:58:40 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!output_is_usable(view->output)) {
|
|
|
|
|
wlr_log(WLR_ERROR, "view has no output, not growing view");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wlr_box geo = view->pending;
|
|
|
|
|
snap_grow_to_next_edge(view, direction, &geo);
|
|
|
|
|
view_move_resize(view, geo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
view_shrink_to_edge(struct view *view, enum view_edge direction)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
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
2023-10-26 00:38:29 -04:00
|
|
|
/* TODO: allow shrink to edge if maximized along the other axis */
|
|
|
|
|
if (view->fullscreen || view->maximized != VIEW_AXIS_NONE) {
|
2023-08-05 23:58:40 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!output_is_usable(view->output)) {
|
|
|
|
|
wlr_log(WLR_ERROR, "view has no output, not shrinking view");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wlr_box geo = view->pending;
|
|
|
|
|
snap_shrink_to_next_edge(view, direction, &geo);
|
|
|
|
|
view_move_resize(view, geo);
|
|
|
|
|
}
|
|
|
|
|
|
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
2023-10-26 00:38:29 -04:00
|
|
|
enum view_axis
|
|
|
|
|
view_axis_parse(const char *direction)
|
|
|
|
|
{
|
|
|
|
|
if (!direction) {
|
|
|
|
|
return VIEW_AXIS_NONE;
|
|
|
|
|
}
|
|
|
|
|
if (!strcasecmp(direction, "horizontal")) {
|
|
|
|
|
return VIEW_AXIS_HORIZONTAL;
|
|
|
|
|
} else if (!strcasecmp(direction, "vertical")) {
|
|
|
|
|
return VIEW_AXIS_VERTICAL;
|
|
|
|
|
} else if (!strcasecmp(direction, "both")) {
|
|
|
|
|
return VIEW_AXIS_BOTH;
|
|
|
|
|
} else {
|
|
|
|
|
return VIEW_AXIS_NONE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 04:30:50 +02:00
|
|
|
enum view_edge
|
2021-10-17 00:44:24 +00:00
|
|
|
view_edge_parse(const char *direction)
|
|
|
|
|
{
|
2022-06-03 02:19:31 +02:00
|
|
|
if (!direction) {
|
|
|
|
|
return VIEW_EDGE_INVALID;
|
|
|
|
|
}
|
2021-10-17 00:44:24 +00:00
|
|
|
if (!strcasecmp(direction, "left")) {
|
|
|
|
|
return VIEW_EDGE_LEFT;
|
|
|
|
|
} else if (!strcasecmp(direction, "up")) {
|
|
|
|
|
return VIEW_EDGE_UP;
|
|
|
|
|
} else if (!strcasecmp(direction, "right")) {
|
|
|
|
|
return VIEW_EDGE_RIGHT;
|
|
|
|
|
} else if (!strcasecmp(direction, "down")) {
|
|
|
|
|
return VIEW_EDGE_DOWN;
|
2021-11-26 18:49:44 +00:00
|
|
|
} else if (!strcasecmp(direction, "center")) {
|
2021-10-17 22:09:34 +00:00
|
|
|
return VIEW_EDGE_CENTER;
|
2021-10-17 00:44:24 +00:00
|
|
|
} else {
|
|
|
|
|
return VIEW_EDGE_INVALID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2023-11-07 14:43:53 +09:00
|
|
|
view_snap_to_edge(struct view *view, enum view_edge edge,
|
|
|
|
|
bool across_outputs, bool store_natural_geometry)
|
2021-10-17 00:44:24 +00:00
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2022-07-01 20:42:09 +02:00
|
|
|
if (view->fullscreen) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-02-20 16:35:23 -05:00
|
|
|
struct output *output = view->output;
|
|
|
|
|
if (!output_is_usable(output)) {
|
|
|
|
|
wlr_log(WLR_ERROR, "view has no output, not snapping to edge");
|
2021-10-17 00:44:24 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-07 14:43:53 +09:00
|
|
|
if (across_outputs && view->tiled == edge && view->maximized == VIEW_AXIS_NONE) {
|
2022-07-01 02:07:40 +02:00
|
|
|
/* We are already tiled for this edge and thus should switch outputs */
|
|
|
|
|
struct wlr_output *new_output = NULL;
|
|
|
|
|
struct wlr_output *current_output = output->wlr_output;
|
|
|
|
|
struct wlr_output_layout *layout = view->server->output_layout;
|
2021-10-17 00:44:24 +00:00
|
|
|
switch (edge) {
|
2021-11-26 18:49:44 +00:00
|
|
|
case VIEW_EDGE_LEFT:
|
2022-07-01 02:07:40 +02:00
|
|
|
new_output = wlr_output_layout_adjacent_output(
|
|
|
|
|
layout, WLR_DIRECTION_LEFT, current_output, 1, 0);
|
2021-11-26 18:49:44 +00:00
|
|
|
break;
|
|
|
|
|
case VIEW_EDGE_RIGHT:
|
2022-07-01 02:07:40 +02:00
|
|
|
new_output = wlr_output_layout_adjacent_output(
|
|
|
|
|
layout, WLR_DIRECTION_RIGHT, current_output, 1, 0);
|
2021-11-26 18:49:44 +00:00
|
|
|
break;
|
|
|
|
|
case VIEW_EDGE_UP:
|
2022-07-01 02:07:40 +02:00
|
|
|
new_output = wlr_output_layout_adjacent_output(
|
|
|
|
|
layout, WLR_DIRECTION_UP, current_output, 0, 1);
|
2021-11-26 18:49:44 +00:00
|
|
|
break;
|
|
|
|
|
case VIEW_EDGE_DOWN:
|
2022-07-01 02:07:40 +02:00
|
|
|
new_output = wlr_output_layout_adjacent_output(
|
|
|
|
|
layout, WLR_DIRECTION_DOWN, current_output, 0, 1);
|
2021-11-26 18:49:44 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2021-10-17 00:44:24 +00:00
|
|
|
}
|
2022-07-01 02:07:40 +02:00
|
|
|
if (new_output && new_output != current_output) {
|
|
|
|
|
/* Move to next output */
|
|
|
|
|
edge = view_edge_invert(edge);
|
|
|
|
|
output = output_from_wlr_output(view->server, new_output);
|
2023-02-20 16:14:27 -05:00
|
|
|
if (!output_is_usable(output)) {
|
|
|
|
|
wlr_log(WLR_ERROR, "invalid output in layout");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-07-01 02:07:40 +02:00
|
|
|
} else {
|
2022-12-22 03:22:34 +01:00
|
|
|
/*
|
|
|
|
|
* No more output to move to
|
|
|
|
|
*
|
|
|
|
|
* We re-apply the tiled geometry without changing any
|
|
|
|
|
* state because the window might have been moved away
|
|
|
|
|
* (and thus got untiled) and then snapped back to the
|
|
|
|
|
* original edge.
|
|
|
|
|
*/
|
2023-02-20 16:14:27 -05:00
|
|
|
view_apply_tiled_geometry(view);
|
2021-10-17 00:44:24 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
2023-10-26 00:38:29 -04:00
|
|
|
if (view->maximized != VIEW_AXIS_NONE) {
|
2022-07-01 20:42:41 +02:00
|
|
|
/* Unmaximize + keep using existing natural_geometry */
|
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
2023-10-26 00:38:29 -04:00
|
|
|
view_maximize(view, VIEW_AXIS_NONE,
|
|
|
|
|
/*store_natural_geometry*/ false);
|
2022-12-31 22:23:00 +01:00
|
|
|
} else if (store_natural_geometry) {
|
2022-07-01 20:42:41 +02:00
|
|
|
/* store current geometry as new natural_geometry */
|
|
|
|
|
view_store_natural_geometry(view);
|
2022-07-01 20:44:40 +02:00
|
|
|
}
|
2022-12-31 21:46:05 +01:00
|
|
|
view_set_untiled(view);
|
2023-02-28 11:46:48 -05:00
|
|
|
view_set_output(view, output);
|
2022-07-01 02:07:40 +02:00
|
|
|
view->tiled = edge;
|
2023-02-20 16:14:27 -05:00
|
|
|
view_apply_tiled_geometry(view);
|
2021-10-17 00:44:24 +00:00
|
|
|
}
|
|
|
|
|
|
2022-07-06 17:04:21 +02:00
|
|
|
void
|
|
|
|
|
view_snap_to_region(struct view *view, struct region *region,
|
|
|
|
|
bool store_natural_geometry)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
|
|
|
|
assert(region);
|
|
|
|
|
if (view->fullscreen) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-02-20 16:35:23 -05:00
|
|
|
/* view_apply_region_geometry() needs a usable output */
|
|
|
|
|
if (!output_is_usable(view->output)) {
|
|
|
|
|
wlr_log(WLR_ERROR, "view has no output, not snapping to region");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
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
2023-10-26 00:38:29 -04:00
|
|
|
if (view->maximized != VIEW_AXIS_NONE) {
|
2022-07-06 17:04:21 +02:00
|
|
|
/* Unmaximize + keep using existing natural_geometry */
|
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
2023-10-26 00:38:29 -04:00
|
|
|
view_maximize(view, VIEW_AXIS_NONE,
|
|
|
|
|
/*store_natural_geometry*/ false);
|
2022-07-06 17:04:21 +02:00
|
|
|
} else if (store_natural_geometry) {
|
|
|
|
|
/* store current geometry as new natural_geometry */
|
|
|
|
|
view_store_natural_geometry(view);
|
|
|
|
|
}
|
|
|
|
|
view_set_untiled(view);
|
|
|
|
|
view->tiled_region = region;
|
|
|
|
|
view_apply_region_geometry(view);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-20 21:34:29 -04:00
|
|
|
static void
|
|
|
|
|
for_each_subview(struct view *view, void (*action)(struct view *))
|
|
|
|
|
{
|
|
|
|
|
struct wl_array subviews;
|
|
|
|
|
struct view **subview;
|
|
|
|
|
|
|
|
|
|
wl_array_init(&subviews);
|
|
|
|
|
view_append_children(view, &subviews);
|
|
|
|
|
wl_array_for_each(subview, &subviews) {
|
|
|
|
|
action(*subview);
|
|
|
|
|
}
|
|
|
|
|
wl_array_release(&subviews);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
move_to_front(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
if (view->impl->move_to_front) {
|
|
|
|
|
view->impl->move_to_front(view);
|
|
|
|
|
}
|
2023-10-21 11:28:00 -04:00
|
|
|
view->server->last_raised_view = view;
|
2023-10-20 21:34:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
move_to_back(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
if (view->impl->move_to_back) {
|
|
|
|
|
view->impl->move_to_back(view);
|
|
|
|
|
}
|
2023-10-21 11:28:00 -04:00
|
|
|
if (view == view->server->last_raised_view) {
|
|
|
|
|
view->server->last_raised_view = NULL;
|
|
|
|
|
}
|
2023-10-20 21:34:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* In the view_move_to_{front,back} functions, a modal dialog is always
|
|
|
|
|
* shown above its parent window, and the two always move together, so
|
|
|
|
|
* other windows cannot come between them.
|
|
|
|
|
* This is consistent with GTK3/Qt5 applications on mutter and openbox.
|
|
|
|
|
*/
|
2023-04-01 14:06:52 -04:00
|
|
|
void
|
|
|
|
|
view_move_to_front(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
2023-10-21 11:28:00 -04:00
|
|
|
/*
|
|
|
|
|
* This function is called often, generally on every mouse
|
|
|
|
|
* button press (more often for focus-follows-mouse). Avoid
|
|
|
|
|
* unnecessarily raising the same view over and over, or
|
|
|
|
|
* attempting to raise a root view above its own sub-view.
|
|
|
|
|
*/
|
|
|
|
|
struct view *last = view->server->last_raised_view;
|
|
|
|
|
if (view == last || (last && view == view_get_root(last))) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-20 21:34:29 -04:00
|
|
|
struct view *root = view_get_root(view);
|
|
|
|
|
assert(root);
|
|
|
|
|
|
|
|
|
|
move_to_front(root);
|
|
|
|
|
for_each_subview(root, move_to_front);
|
|
|
|
|
/* make sure view is in front of other sub-views */
|
|
|
|
|
if (view != root) {
|
|
|
|
|
move_to_front(view);
|
2023-04-01 14:06:52 -04:00
|
|
|
}
|
2023-10-20 21:34:29 -04:00
|
|
|
|
|
|
|
|
cursor_update_focus(view->server);
|
2023-04-01 14:06:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
view_move_to_back(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
2023-10-20 21:34:29 -04:00
|
|
|
struct view *root = view_get_root(view);
|
|
|
|
|
assert(root);
|
|
|
|
|
|
|
|
|
|
for_each_subview(root, move_to_back);
|
|
|
|
|
move_to_back(root);
|
|
|
|
|
|
|
|
|
|
cursor_update_focus(view->server);
|
2023-04-01 14:06:52 -04:00
|
|
|
}
|
|
|
|
|
|
2023-08-02 20:57:39 +01:00
|
|
|
struct view *
|
|
|
|
|
view_get_root(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
|
|
|
|
if (view->impl->get_root) {
|
|
|
|
|
return view->impl->get_root(view);
|
|
|
|
|
}
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
view_append_children(struct view *view, struct wl_array *children)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
|
|
|
|
if (view->impl->append_children) {
|
|
|
|
|
view->impl->append_children(view, children);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-15 00:15:16 -04:00
|
|
|
bool
|
|
|
|
|
view_is_related(struct view *view, struct wlr_surface *surface)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
|
|
|
|
assert(surface);
|
|
|
|
|
if (view->impl->is_related) {
|
|
|
|
|
return view->impl->is_related(view, surface);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 20:01:10 +01:00
|
|
|
const char *
|
|
|
|
|
view_get_string_prop(struct view *view, const char *prop)
|
|
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
|
|
|
|
assert(prop);
|
2021-10-18 20:01:10 +01:00
|
|
|
if (view->impl->get_string_prop) {
|
2021-12-06 20:16:30 +00:00
|
|
|
return view->impl->get_string_prop(view, prop);
|
2021-10-18 20:01:10 +01:00
|
|
|
}
|
2021-10-18 20:06:47 +01:00
|
|
|
return "";
|
2021-10-18 20:01:10 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-05 12:18:10 +01:00
|
|
|
void
|
|
|
|
|
view_update_title(struct view *view)
|
|
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2021-10-18 20:01:10 +01:00
|
|
|
const char *title = view_get_string_prop(view, "title");
|
2023-02-01 09:27:25 +01:00
|
|
|
if (!view->toplevel.handle || !title) {
|
2021-08-05 12:18:10 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2022-11-26 16:46:28 -05:00
|
|
|
ssd_update_title(view->ssd);
|
2023-02-01 09:27:25 +01:00
|
|
|
wlr_foreign_toplevel_handle_v1_set_title(view->toplevel.handle, title);
|
2021-08-05 12:18:10 +01:00
|
|
|
}
|
2021-10-16 21:50:56 +01:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
view_update_app_id(struct view *view)
|
|
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2021-10-18 20:01:10 +01:00
|
|
|
const char *app_id = view_get_string_prop(view, "app_id");
|
2023-02-01 09:27:25 +01:00
|
|
|
if (!view->toplevel.handle || !app_id) {
|
2021-10-16 21:50:56 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
wlr_foreign_toplevel_handle_v1_set_app_id(
|
2023-02-01 09:27:25 +01:00
|
|
|
view->toplevel.handle, app_id);
|
2021-10-16 21:50:56 +01:00
|
|
|
}
|
2022-04-21 23:33:44 +00:00
|
|
|
|
2022-11-26 02:13:42 -05:00
|
|
|
void
|
|
|
|
|
view_reload_ssd(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
assert(view);
|
2022-11-26 02:25:02 -05:00
|
|
|
if (view->ssd_enabled && !view->fullscreen) {
|
2022-11-26 16:46:28 -05:00
|
|
|
undecorate(view);
|
|
|
|
|
decorate(view);
|
2022-11-26 02:13:42 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-25 22:42:06 -04:00
|
|
|
void
|
|
|
|
|
view_toggle_keybinds(struct view *view)
|
2023-03-05 10:35:56 +01:00
|
|
|
{
|
2023-09-25 22:42:06 -04:00
|
|
|
assert(view);
|
|
|
|
|
view->inhibits_keybinds = !view->inhibits_keybinds;
|
|
|
|
|
if (view->inhibits_keybinds) {
|
2023-03-05 10:35:56 +01:00
|
|
|
view->server->seat.nr_inhibited_keybind_views++;
|
|
|
|
|
} else {
|
|
|
|
|
view->server->seat.nr_inhibited_keybind_views--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (view->ssd_enabled) {
|
2023-09-25 22:42:06 -04:00
|
|
|
ssd_enable_keybind_inhibit_indicator(view->ssd,
|
|
|
|
|
view->inhibits_keybinds);
|
2023-03-05 10:35:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-21 23:33:44 +00:00
|
|
|
void
|
2022-04-23 03:44:41 +02:00
|
|
|
view_destroy(struct view *view)
|
2022-04-21 23:33:44 +00:00
|
|
|
{
|
2022-11-22 02:09:42 -05:00
|
|
|
assert(view);
|
2022-07-10 23:24:32 +02:00
|
|
|
struct server *server = view->server;
|
2022-09-12 13:14:18 -04:00
|
|
|
bool need_cursor_update = false;
|
2022-07-10 23:24:32 +02:00
|
|
|
|
2023-02-24 21:45:03 +00:00
|
|
|
wl_list_remove(&view->map.link);
|
|
|
|
|
wl_list_remove(&view->unmap.link);
|
|
|
|
|
wl_list_remove(&view->request_move.link);
|
|
|
|
|
wl_list_remove(&view->request_resize.link);
|
|
|
|
|
wl_list_remove(&view->request_minimize.link);
|
|
|
|
|
wl_list_remove(&view->request_maximize.link);
|
|
|
|
|
wl_list_remove(&view->request_fullscreen.link);
|
|
|
|
|
wl_list_remove(&view->set_title.link);
|
|
|
|
|
wl_list_remove(&view->destroy.link);
|
|
|
|
|
|
2023-02-01 09:27:25 +01:00
|
|
|
if (view->toplevel.handle) {
|
|
|
|
|
wlr_foreign_toplevel_handle_v1_destroy(view->toplevel.handle);
|
2022-04-21 23:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
2022-07-10 23:24:32 +02:00
|
|
|
if (server->grabbed_view == view) {
|
|
|
|
|
/* Application got killed while moving around */
|
|
|
|
|
server->input_mode = LAB_INPUT_STATE_PASSTHROUGH;
|
|
|
|
|
server->grabbed_view = NULL;
|
2022-09-12 13:14:18 -04:00
|
|
|
need_cursor_update = true;
|
2022-09-13 08:15:33 +02:00
|
|
|
regions_hide_overlay(&server->seat);
|
2022-07-10 23:24:32 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-26 02:02:19 -04:00
|
|
|
if (server->focused_view == view) {
|
|
|
|
|
server->focused_view = NULL;
|
2022-09-12 13:14:18 -04:00
|
|
|
need_cursor_update = true;
|
2022-08-26 02:02:19 -04:00
|
|
|
}
|
|
|
|
|
|
2023-10-21 11:28:00 -04:00
|
|
|
if (server->last_raised_view == view) {
|
|
|
|
|
server->last_raised_view = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-14 23:09:36 -04:00
|
|
|
if (server->seat.pressed.view == view) {
|
|
|
|
|
seat_reset_pressed(&server->seat);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-07 19:05:54 +02:00
|
|
|
if (view->tiled_region_evacuate) {
|
|
|
|
|
zfree(view->tiled_region_evacuate);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-05 10:35:56 +01:00
|
|
|
if (view->inhibits_keybinds) {
|
|
|
|
|
view->inhibits_keybinds = false;
|
|
|
|
|
server->seat.nr_inhibited_keybind_views--;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-22 02:54:40 +02:00
|
|
|
osd_on_view_destroy(view);
|
2022-11-26 16:46:28 -05:00
|
|
|
undecorate(view);
|
2022-04-21 23:33:44 +00:00
|
|
|
|
|
|
|
|
if (view->scene_tree) {
|
2022-08-22 02:54:40 +02:00
|
|
|
wlr_scene_node_destroy(&view->scene_tree->node);
|
2022-04-21 23:33:44 +00:00
|
|
|
view->scene_tree = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-07 22:28:25 +01:00
|
|
|
/*
|
|
|
|
|
* The layer-shell top-layer is disabled when an application is running
|
2023-11-10 23:58:25 +01:00
|
|
|
* in fullscreen mode, so if that's the case, we may have to re-enable
|
|
|
|
|
* it here.
|
2022-06-07 22:28:25 +01:00
|
|
|
*/
|
2023-02-15 02:12:22 -05:00
|
|
|
if (view->fullscreen && view->output) {
|
2023-11-10 23:58:25 +01:00
|
|
|
view->fullscreen = false;
|
|
|
|
|
desktop_update_top_layer_visiblity(server);
|
2022-06-07 22:28:25 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-09 17:10:36 +02:00
|
|
|
/* If we spawned a window menu, close it */
|
|
|
|
|
if (server->menu_current
|
|
|
|
|
&& server->menu_current->triggered_by_view == view) {
|
|
|
|
|
menu_close_root(server);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-23 03:44:41 +02:00
|
|
|
/* Remove view from server->views */
|
|
|
|
|
wl_list_remove(&view->link);
|
2022-04-21 23:33:44 +00:00
|
|
|
free(view);
|
2022-09-12 13:14:18 -04:00
|
|
|
|
|
|
|
|
if (need_cursor_update) {
|
|
|
|
|
cursor_update_focus(server);
|
|
|
|
|
}
|
2022-04-21 23:33:44 +00:00
|
|
|
}
|