2021-09-24 21:45:48 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2023-02-02 07:16:57 +01:00
|
|
|
#include <assert.h>
|
2021-08-05 12:18:10 +01:00
|
|
|
#include "labwc.h"
|
2022-11-21 10:10:39 -05:00
|
|
|
#include "view.h"
|
2022-06-15 22:49:36 +02:00
|
|
|
#include "workspaces.h"
|
2021-08-05 12:18:10 +01:00
|
|
|
|
2021-08-05 13:00:34 +01:00
|
|
|
static void
|
2023-02-01 09:27:25 +01:00
|
|
|
handle_request_minimize(struct wl_listener *listener, void *data)
|
2021-08-05 13:00:34 +01:00
|
|
|
{
|
2023-02-01 09:27:25 +01:00
|
|
|
struct view *view = wl_container_of(listener, view, toplevel.minimize);
|
2021-08-05 13:00:34 +01:00
|
|
|
struct wlr_foreign_toplevel_handle_v1_minimized_event *event = data;
|
2023-02-01 09:27:25 +01:00
|
|
|
view_minimize(view, event->minimized);
|
2021-08-05 13:00:34 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-05 12:52:42 +01:00
|
|
|
static void
|
2023-02-01 09:27:25 +01:00
|
|
|
handle_request_maximize(struct wl_listener *listener, void *data)
|
2021-08-05 12:52:42 +01:00
|
|
|
{
|
2023-02-01 09:27:25 +01:00
|
|
|
struct view *view = wl_container_of(listener, view, toplevel.maximize);
|
2021-08-05 12:52:42 +01:00
|
|
|
struct wlr_foreign_toplevel_handle_v1_maximized_event *event = data;
|
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, event->maximized ? VIEW_AXIS_BOTH : VIEW_AXIS_NONE,
|
|
|
|
|
/*store_natural_geometry*/ true);
|
2021-08-05 12:52:42 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-23 22:05:30 +01:00
|
|
|
static void
|
2023-02-01 09:27:25 +01:00
|
|
|
handle_request_fullscreen(struct wl_listener *listener, void *data)
|
2021-08-23 22:05:30 +01:00
|
|
|
{
|
2023-02-01 09:27:25 +01:00
|
|
|
struct view *view = wl_container_of(listener, view, toplevel.fullscreen);
|
2021-08-23 22:05:30 +01:00
|
|
|
struct wlr_foreign_toplevel_handle_v1_fullscreen_event *event = data;
|
2023-02-20 13:36:15 -05:00
|
|
|
view_set_fullscreen(view, event->fullscreen);
|
2021-08-23 22:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-02 14:12:32 +00:00
|
|
|
static void
|
2023-02-01 09:27:25 +01:00
|
|
|
handle_request_activate(struct wl_listener *listener, void *data)
|
2021-12-02 14:12:32 +00:00
|
|
|
{
|
2023-02-01 09:27:25 +01:00
|
|
|
struct view *view = wl_container_of(listener, view, toplevel.activate);
|
2021-12-02 14:12:32 +00:00
|
|
|
// struct wlr_foreign_toplevel_handle_v1_activated_event *event = data;
|
|
|
|
|
/* In a multi-seat world we would select seat based on event->seat here. */
|
2023-09-27 18:37:28 -04:00
|
|
|
desktop_focus_view(view, /*raise*/ true);
|
2021-12-02 14:12:32 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-23 12:24:24 +01:00
|
|
|
static void
|
2023-02-01 09:27:25 +01:00
|
|
|
handle_request_close(struct wl_listener *listener, void *data)
|
2021-12-23 12:24:24 +01:00
|
|
|
{
|
2023-02-01 09:27:25 +01:00
|
|
|
struct view *view = wl_container_of(listener, view, toplevel.close);
|
|
|
|
|
view_close(view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
handle_destroy(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct view *view = wl_container_of(listener, view, toplevel.destroy);
|
|
|
|
|
struct foreign_toplevel *toplevel = &view->toplevel;
|
|
|
|
|
wl_list_remove(&toplevel->maximize.link);
|
|
|
|
|
wl_list_remove(&toplevel->minimize.link);
|
|
|
|
|
wl_list_remove(&toplevel->fullscreen.link);
|
|
|
|
|
wl_list_remove(&toplevel->activate.link);
|
|
|
|
|
wl_list_remove(&toplevel->close.link);
|
|
|
|
|
wl_list_remove(&toplevel->destroy.link);
|
|
|
|
|
toplevel->handle = NULL;
|
2021-12-23 12:24:24 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-05 12:18:10 +01:00
|
|
|
void
|
|
|
|
|
foreign_toplevel_handle_create(struct view *view)
|
|
|
|
|
{
|
2023-02-01 09:27:25 +01:00
|
|
|
struct foreign_toplevel *toplevel = &view->toplevel;
|
|
|
|
|
|
|
|
|
|
toplevel->handle = wlr_foreign_toplevel_handle_v1_create(
|
2021-08-05 12:18:10 +01:00
|
|
|
view->server->foreign_toplevel_manager);
|
2023-02-01 09:27:25 +01:00
|
|
|
if (!toplevel->handle) {
|
2021-08-07 09:35:53 +01:00
|
|
|
wlr_log(WLR_ERROR, "cannot create foreign toplevel handle for (%s)",
|
2021-10-18 20:01:10 +01:00
|
|
|
view_get_string_prop(view, "title"));
|
2021-08-07 09:35:53 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-01 09:27:25 +01:00
|
|
|
toplevel->maximize.notify = handle_request_maximize;
|
|
|
|
|
wl_signal_add(&toplevel->handle->events.request_maximize,
|
|
|
|
|
&toplevel->maximize);
|
2021-10-18 19:40:04 +01:00
|
|
|
|
2023-02-01 09:27:25 +01:00
|
|
|
toplevel->minimize.notify = handle_request_minimize;
|
|
|
|
|
wl_signal_add(&toplevel->handle->events.request_minimize,
|
|
|
|
|
&toplevel->minimize);
|
2021-10-18 19:40:04 +01:00
|
|
|
|
2023-02-01 09:27:25 +01:00
|
|
|
toplevel->fullscreen.notify = handle_request_fullscreen;
|
|
|
|
|
wl_signal_add(&toplevel->handle->events.request_fullscreen,
|
|
|
|
|
&toplevel->fullscreen);
|
2021-12-02 14:12:32 +00:00
|
|
|
|
2023-02-01 09:27:25 +01:00
|
|
|
toplevel->activate.notify = handle_request_activate;
|
|
|
|
|
wl_signal_add(&toplevel->handle->events.request_activate,
|
|
|
|
|
&toplevel->activate);
|
2021-12-23 12:24:24 +01:00
|
|
|
|
2023-02-01 09:27:25 +01:00
|
|
|
toplevel->close.notify = handle_request_close;
|
|
|
|
|
wl_signal_add(&toplevel->handle->events.request_close,
|
|
|
|
|
&toplevel->close);
|
2021-12-23 12:24:24 +01:00
|
|
|
|
2023-02-01 09:27:25 +01:00
|
|
|
toplevel->destroy.notify = handle_destroy;
|
|
|
|
|
wl_signal_add(&toplevel->handle->events.destroy, &toplevel->destroy);
|
2021-08-05 12:18:10 +01:00
|
|
|
}
|
2023-02-02 07:16:57 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Loop over all outputs and notify foreign_toplevel clients about changes.
|
|
|
|
|
* wlr_foreign_toplevel_handle_v1_output_xxx() keeps track of the active
|
|
|
|
|
* outputs internally and merges the events. It also listens to output
|
|
|
|
|
* destroy events so its fine to just relay the current state and let
|
|
|
|
|
* wlr_foreign_toplevel handle the rest.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
foreign_toplevel_update_outputs(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
assert(view->toplevel.handle);
|
|
|
|
|
struct wlr_output_layout *layout = view->server->output_layout;
|
|
|
|
|
struct output *output;
|
|
|
|
|
wl_list_for_each(output, &view->server->outputs, link) {
|
2023-02-16 12:24:27 -05:00
|
|
|
if (output_is_usable(output) && wlr_output_layout_intersects(
|
|
|
|
|
layout, output->wlr_output, &view->current)) {
|
|
|
|
|
wlr_foreign_toplevel_handle_v1_output_enter(
|
|
|
|
|
view->toplevel.handle, output->wlr_output);
|
|
|
|
|
} else {
|
|
|
|
|
wlr_foreign_toplevel_handle_v1_output_leave(
|
|
|
|
|
view->toplevel.handle, output->wlr_output);
|
2023-02-02 07:16:57 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|