|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <wayland-server-core.h>
|
|
|
|
#include <wlr/types/wlr_fractional_scale_v1.h>
|
|
|
|
#include <wlr/types/wlr_layer_shell_v1.h>
|
|
|
|
#include <wlr/types/wlr_output.h>
|
|
|
|
#include <wlr/types/wlr_scene.h>
|
|
|
|
#include <wlr/types/wlr_subcompositor.h>
|
|
|
|
#include <wlr/types/wlr_xdg_shell.h>
|
|
|
|
#include "log.h"
|
|
|
|
#include "sway/scene_descriptor.h"
|
|
|
|
#include "sway/desktop/transaction.h"
|
|
|
|
#include "sway/input/cursor.h"
|
|
|
|
#include "sway/input/input-manager.h"
|
|
|
|
#include "sway/input/seat.h"
|
|
|
|
#include "sway/layers.h"
|
|
|
|
#include "sway/output.h"
|
|
|
|
#include "sway/server.h"
|
|
|
|
#include "sway/tree/arrange.h"
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
6 years ago
|
|
|
#include "sway/tree/workspace.h"
|
|
|
|
|
|
|
|
struct wlr_layer_surface_v1 *toplevel_layer_surface_from_surface(
|
|
|
|
struct wlr_surface *surface) {
|
|
|
|
struct wlr_layer_surface_v1 *layer;
|
|
|
|
do {
|
|
|
|
if (!surface) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// Topmost layer surface
|
|
|
|
if ((layer = wlr_layer_surface_v1_try_from_wlr_surface(surface))) {
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
// Layer subsurface
|
|
|
|
if (wlr_subsurface_try_from_wlr_surface(surface)) {
|
|
|
|
surface = wlr_surface_get_root_surface(surface);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Layer surface popup
|
|
|
|
struct wlr_xdg_surface *xdg_surface = NULL;
|
|
|
|
if ((xdg_surface = wlr_xdg_surface_try_from_wlr_surface(surface)) &&
|
|
|
|
xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP && xdg_surface->popup != NULL) {
|
|
|
|
if (!xdg_surface->popup->parent) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
surface = wlr_surface_get_root_surface(xdg_surface->popup->parent);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return early if the surface is not a layer/xdg_popup/sub surface
|
|
|
|
return NULL;
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void arrange_surface(struct sway_output *output, const struct wlr_box *full_area,
|
|
|
|
struct wlr_box *usable_area, struct wlr_scene_tree *tree) {
|
|
|
|
struct wlr_scene_node *node;
|
|
|
|
wl_list_for_each(node, &tree->children, link) {
|
|
|
|
struct sway_layer_surface *surface = scene_descriptor_try_get(node,
|
|
|
|
SWAY_SCENE_DESC_LAYER_SHELL);
|
|
|
|
// surface could be null during destruction
|
|
|
|
if (!surface) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!surface->scene->layer_surface->initialized) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_scene_layer_surface_v1_configure(surface->scene, full_area, usable_area);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void arrange_layers(struct sway_output *output) {
|
|
|
|
struct wlr_box usable_area = { 0 };
|
|
|
|
wlr_output_effective_resolution(output->wlr_output,
|
|
|
|
&usable_area.width, &usable_area.height);
|
|
|
|
const struct wlr_box full_area = usable_area;
|
|
|
|
|
|
|
|
arrange_surface(output, &full_area, &usable_area, output->layers.shell_background);
|
|
|
|
arrange_surface(output, &full_area, &usable_area, output->layers.shell_bottom);
|
|
|
|
arrange_surface(output, &full_area, &usable_area, output->layers.shell_top);
|
|
|
|
arrange_surface(output, &full_area, &usable_area, output->layers.shell_overlay);
|
|
|
|
|
|
|
|
if (!wlr_box_equal(&usable_area, &output->usable_area)) {
|
|
|
|
sway_log(SWAY_DEBUG, "Usable area changed, rearranging output");
|
|
|
|
output->usable_area = usable_area;
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
6 years ago
|
|
|
arrange_output(output);
|
|
|
|
} else {
|
|
|
|
arrange_popups(root->layers.popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find topmost keyboard interactive layer, if such a layer exists
|
|
|
|
struct wlr_scene_tree *layers_above_shell[] = {
|
|
|
|
output->layers.shell_overlay,
|
|
|
|
output->layers.shell_top,
|
|
|
|
};
|
|
|
|
size_t nlayers = sizeof(layers_above_shell) / sizeof(layers_above_shell[0]);
|
|
|
|
struct wlr_scene_node *node;
|
|
|
|
struct sway_layer_surface *topmost = NULL;
|
|
|
|
for (size_t i = 0; i < nlayers; ++i) {
|
|
|
|
wl_list_for_each_reverse(node,
|
|
|
|
&layers_above_shell[i]->children, link) {
|
|
|
|
struct sway_layer_surface *surface = scene_descriptor_try_get(node,
|
|
|
|
SWAY_SCENE_DESC_LAYER_SHELL);
|
|
|
|
if (surface && surface->layer_surface->current.keyboard_interactive
|
|
|
|
== ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE &&
|
|
|
|
surface->layer_surface->surface->mapped) {
|
|
|
|
topmost = surface;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (topmost != NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sway_seat *seat;
|
|
|
|
wl_list_for_each(seat, &server.input->seats, link) {
|
|
|
|
seat->has_exclusive_layer = false;
|
|
|
|
if (topmost != NULL) {
|
|
|
|
seat_set_focus_layer(seat, topmost->layer_surface);
|
|
|
|
} else if (seat->focused_layer &&
|
|
|
|
seat->focused_layer->current.keyboard_interactive
|
|
|
|
!= ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE) {
|
|
|
|
seat_set_focus_layer(seat, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct wlr_scene_tree *sway_layer_get_scene(struct sway_output *output,
|
|
|
|
enum zwlr_layer_shell_v1_layer type) {
|
|
|
|
switch (type) {
|
|
|
|
case ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND:
|
|
|
|
return output->layers.shell_background;
|
|
|
|
case ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM:
|
|
|
|
return output->layers.shell_bottom;
|
|
|
|
case ZWLR_LAYER_SHELL_V1_LAYER_TOP:
|
|
|
|
return output->layers.shell_top;
|
|
|
|
case ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY:
|
|
|
|
return output->layers.shell_overlay;
|
|
|
|
}
|
|
|
|
|
|
|
|
sway_assert(false, "unreachable");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sway_layer_surface *sway_layer_surface_create(
|
|
|
|
struct wlr_scene_layer_surface_v1 *scene) {
|
|
|
|
struct sway_layer_surface *surface = calloc(1, sizeof(*surface));
|
|
|
|
if (!surface) {
|
|
|
|
sway_log(SWAY_ERROR, "Could not allocate a scene_layer surface");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_scene_tree *popups = wlr_scene_tree_create(root->layers.popup);
|
|
|
|
if (!popups) {
|
|
|
|
sway_log(SWAY_ERROR, "Could not allocate a scene_layer popup node");
|
|
|
|
free(surface);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface->desc.relative = &scene->tree->node;
|
|
|
|
|
|
|
|
if (!scene_descriptor_assign(&popups->node,
|
|
|
|
SWAY_SCENE_DESC_POPUP, &surface->desc)) {
|
|
|
|
sway_log(SWAY_ERROR, "Failed to allocate a popup scene descriptor");
|
|
|
|
wlr_scene_node_destroy(&popups->node);
|
|
|
|
free(surface);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface->tree = scene->tree;
|
|
|
|
surface->scene = scene;
|
|
|
|
surface->layer_surface = scene->layer_surface;
|
|
|
|
surface->popups = popups;
|
|
|
|
surface->layer_surface->data = surface;
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
Fix seat_set_focus_layer crash when disabling output
This fixes the following crash:
#0 0x00007f7daac3af25 in raise () at /usr/lib/libc.so.6
#1 0x00007f7daac24897 in abort () at /usr/lib/libc.so.6
#2 0x00007f7daac24767 in _nl_load_domain.cold () at /usr/lib/libc.so.6
#3 0x00007f7daac33526 in () at /usr/lib/libc.so.6
#4 0x0000555bfbc35029 in seat_set_focus_layer (seat=0x555bfd76d860, layer=0x555bfdda2ff0)
at ../sway/input/seat.c:1164
__PRETTY_FUNCTION__ = "seat_set_focus_layer"
__PRETTY_FUNCTION__ = "seat_set_focus_layer"
#5 0x0000555bfbc35029 in seat_set_focus_layer (seat=seat@entry=0x555bfd76d860, layer=0x555bfdda2ff0)
at ../sway/input/seat.c:1164
__PRETTY_FUNCTION__ = "seat_set_focus_layer"
#6 0x0000555bfbc25899 in handle_output_destroy (listener=0x555bfdb90688, data=<optimized out>)
at ../sway/desktop/layer_shell.c:263
layer = 0x555bfdd6b040
sway_layer = 0x555bfdb90610
seat = 0x555bfd76d860
client = 0x555bfdb76d70
set_focus = <optimized out>
#7 0x0000555bfbc5b669 in wl_signal_emit (data=0x555bfd795930, signal=0x555bfd795ae0)
at /usr/include/wayland-server-core.h:472
l = <optimized out>
next = 0x555bfdb6a3e8
__PRETTY_FUNCTION__ = "output_disable"
index = <optimized out>
#8 0x0000555bfbc5b669 in output_disable (output=output@entry=0x555bfd795930)
at ../sway/tree/output.c:263
__PRETTY_FUNCTION__ = "output_disable"
index = <optimized out>
#9 0x0000555bfbc3b890 in apply_output_config (oc=0x555bfd7d73d0, output=output@entry=0x555bfd795930)
at ../sway/config/output.c:321
wlr_output = 0x555bfd7afaf0
scale = <optimized out>
output_box = <optimized out>
#10 0x0000555bfbc28309 in handle_output_manager_apply
(listener=0x555bfbc7f148 <server+488>, data=0x555bfdca6eb0) at ../sway/desktop/output.c:936
wlr_output = <optimized out>
output = 0x555bfd795930
oc = <optimized out>
server = 0x555bfbc7ef60 <server>
config = 0x555bfdca6eb0
config_head = 0x555bfdb79350
ok = true
#11 0x00007f7dab4fbf7c in wlr_signal_emit_safe (signal=<optimized out>, data=0x555bfdca6eb0)
at ../subprojects/wlroots/util/signal.c:29
pos = 0x555bfbc7f148 <server+488>
l = 0x555bfbc7f148 <server+488>
cursor =
{link = {prev = 0x555bfbc7f148 <server+488>, next = 0x7fff238a8390}, notify = 0x7f7dab4fbef0 <handle_noop>}
end =
{link = {prev = 0x7fff238a8370, next = 0x555bfd7419f8}, notify = 0x7f7dab4fbef0 <handle_noop>}
#12 0x00007f7daa45469a in ffi_call_unix64 () at /usr/lib/libffi.so.6
#13 0x00007f7daa453fb6 in ffi_call () at /usr/lib/libffi.so.6
#14 0x00007f7daae6f82f in () at /usr/lib/libwayland-server.so.0
#15 0x00007f7daae6c193 in () at /usr/lib/libwayland-server.so.0
#16 0x00007f7daae6d7f2 in wl_event_loop_dispatch () at /usr/lib/libwayland-server.so.0
#17 0x00007f7daae6c39c in wl_display_run () at /usr/lib/libwayland-server.so.0
This crash happens because focus can only be set on mapped surfaces.
5 years ago
|
|
|
static struct sway_layer_surface *find_mapped_layer_by_client(
|
|
|
|
struct wl_client *client, struct sway_output *ignore_output) {
|
|
|
|
for (int i = 0; i < root->outputs->length; ++i) {
|
|
|
|
struct sway_output *output = root->outputs->items[i];
|
|
|
|
if (output == ignore_output) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// For now we'll only check the overlay layer
|
|
|
|
struct wlr_scene_node *node;
|
|
|
|
wl_list_for_each (node, &output->layers.shell_overlay->children, link) {
|
|
|
|
struct sway_layer_surface *surface = scene_descriptor_try_get(node,
|
|
|
|
SWAY_SCENE_DESC_LAYER_SHELL);
|
|
|
|
if (!surface) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_layer_surface_v1 *layer_surface = surface->layer_surface;
|
|
|
|
struct wl_resource *resource = layer_surface->resource;
|
Fix seat_set_focus_layer crash when disabling output
This fixes the following crash:
#0 0x00007f7daac3af25 in raise () at /usr/lib/libc.so.6
#1 0x00007f7daac24897 in abort () at /usr/lib/libc.so.6
#2 0x00007f7daac24767 in _nl_load_domain.cold () at /usr/lib/libc.so.6
#3 0x00007f7daac33526 in () at /usr/lib/libc.so.6
#4 0x0000555bfbc35029 in seat_set_focus_layer (seat=0x555bfd76d860, layer=0x555bfdda2ff0)
at ../sway/input/seat.c:1164
__PRETTY_FUNCTION__ = "seat_set_focus_layer"
__PRETTY_FUNCTION__ = "seat_set_focus_layer"
#5 0x0000555bfbc35029 in seat_set_focus_layer (seat=seat@entry=0x555bfd76d860, layer=0x555bfdda2ff0)
at ../sway/input/seat.c:1164
__PRETTY_FUNCTION__ = "seat_set_focus_layer"
#6 0x0000555bfbc25899 in handle_output_destroy (listener=0x555bfdb90688, data=<optimized out>)
at ../sway/desktop/layer_shell.c:263
layer = 0x555bfdd6b040
sway_layer = 0x555bfdb90610
seat = 0x555bfd76d860
client = 0x555bfdb76d70
set_focus = <optimized out>
#7 0x0000555bfbc5b669 in wl_signal_emit (data=0x555bfd795930, signal=0x555bfd795ae0)
at /usr/include/wayland-server-core.h:472
l = <optimized out>
next = 0x555bfdb6a3e8
__PRETTY_FUNCTION__ = "output_disable"
index = <optimized out>
#8 0x0000555bfbc5b669 in output_disable (output=output@entry=0x555bfd795930)
at ../sway/tree/output.c:263
__PRETTY_FUNCTION__ = "output_disable"
index = <optimized out>
#9 0x0000555bfbc3b890 in apply_output_config (oc=0x555bfd7d73d0, output=output@entry=0x555bfd795930)
at ../sway/config/output.c:321
wlr_output = 0x555bfd7afaf0
scale = <optimized out>
output_box = <optimized out>
#10 0x0000555bfbc28309 in handle_output_manager_apply
(listener=0x555bfbc7f148 <server+488>, data=0x555bfdca6eb0) at ../sway/desktop/output.c:936
wlr_output = <optimized out>
output = 0x555bfd795930
oc = <optimized out>
server = 0x555bfbc7ef60 <server>
config = 0x555bfdca6eb0
config_head = 0x555bfdb79350
ok = true
#11 0x00007f7dab4fbf7c in wlr_signal_emit_safe (signal=<optimized out>, data=0x555bfdca6eb0)
at ../subprojects/wlroots/util/signal.c:29
pos = 0x555bfbc7f148 <server+488>
l = 0x555bfbc7f148 <server+488>
cursor =
{link = {prev = 0x555bfbc7f148 <server+488>, next = 0x7fff238a8390}, notify = 0x7f7dab4fbef0 <handle_noop>}
end =
{link = {prev = 0x7fff238a8370, next = 0x555bfd7419f8}, notify = 0x7f7dab4fbef0 <handle_noop>}
#12 0x00007f7daa45469a in ffi_call_unix64 () at /usr/lib/libffi.so.6
#13 0x00007f7daa453fb6 in ffi_call () at /usr/lib/libffi.so.6
#14 0x00007f7daae6f82f in () at /usr/lib/libwayland-server.so.0
#15 0x00007f7daae6c193 in () at /usr/lib/libwayland-server.so.0
#16 0x00007f7daae6d7f2 in wl_event_loop_dispatch () at /usr/lib/libwayland-server.so.0
#17 0x00007f7daae6c39c in wl_display_run () at /usr/lib/libwayland-server.so.0
This crash happens because focus can only be set on mapped surfaces.
5 years ago
|
|
|
if (wl_resource_get_client(resource) == client
|
|
|
|
&& layer_surface->surface->mapped) {
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_output_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_layer_surface *layer =
|
|
|
|
wl_container_of(listener, layer, output_destroy);
|
|
|
|
|
|
|
|
layer->output = NULL;
|
|
|
|
wlr_scene_node_destroy(&layer->scene->tree->node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_node_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_layer_surface *layer =
|
|
|
|
wl_container_of(listener, layer, node_destroy);
|
|
|
|
|
|
|
|
// destroy the scene descriptor straight away if it exists, otherwise
|
|
|
|
// we will try to reflow still considering the destroyed node.
|
|
|
|
scene_descriptor_destroy(&layer->tree->node, SWAY_SCENE_DESC_LAYER_SHELL);
|
|
|
|
|
|
|
|
// Determine if this layer is being used by an exclusive client. If it is,
|
|
|
|
// try and find another layer owned by this client to pass focus to.
|
|
|
|
struct sway_seat *seat = input_manager_get_default_seat();
|
|
|
|
struct wl_client *client =
|
|
|
|
wl_resource_get_client(layer->layer_surface->resource);
|
|
|
|
if (!server.session_lock.lock) {
|
|
|
|
struct sway_layer_surface *consider_layer =
|
|
|
|
find_mapped_layer_by_client(client, layer->output);
|
|
|
|
if (consider_layer) {
|
|
|
|
seat_set_focus_layer(seat, consider_layer->layer_surface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layer->output) {
|
|
|
|
arrange_layers(layer->output);
|
|
|
|
transaction_commit_dirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_scene_node_destroy(&layer->popups->node);
|
|
|
|
|
|
|
|
wl_list_remove(&layer->map.link);
|
|
|
|
wl_list_remove(&layer->unmap.link);
|
|
|
|
wl_list_remove(&layer->surface_commit.link);
|
|
|
|
wl_list_remove(&layer->node_destroy.link);
|
|
|
|
wl_list_remove(&layer->output_destroy.link);
|
|
|
|
|
|
|
|
layer->layer_surface->data = NULL;
|
|
|
|
|
|
|
|
free(layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_surface_commit(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_layer_surface *surface =
|
|
|
|
wl_container_of(listener, surface, surface_commit);
|
|
|
|
|
|
|
|
struct wlr_layer_surface_v1 *layer_surface = surface->layer_surface;
|
|
|
|
if (!layer_surface->initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t committed = layer_surface->current.committed;
|
|
|
|
if (committed & WLR_LAYER_SURFACE_V1_STATE_LAYER) {
|
|
|
|
enum zwlr_layer_shell_v1_layer layer_type = layer_surface->current.layer;
|
|
|
|
struct wlr_scene_tree *output_layer = sway_layer_get_scene(
|
|
|
|
surface->output, layer_type);
|
|
|
|
wlr_scene_node_reparent(&surface->scene->tree->node, output_layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layer_surface->initial_commit || committed || layer_surface->surface->mapped != surface->mapped) {
|
|
|
|
surface->mapped = layer_surface->surface->mapped;
|
|
|
|
arrange_layers(surface->output);
|
|
|
|
transaction_commit_dirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_map(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_layer_surface *surface = wl_container_of(listener,
|
|
|
|
surface, map);
|
|
|
|
|
|
|
|
struct wlr_layer_surface_v1 *layer_surface =
|
|
|
|
surface->scene->layer_surface;
|
|
|
|
|
|
|
|
// focus on new surface
|
|
|
|
if (layer_surface->current.keyboard_interactive &&
|
|
|
|
(layer_surface->current.layer == ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY ||
|
|
|
|
layer_surface->current.layer == ZWLR_LAYER_SHELL_V1_LAYER_TOP)) {
|
|
|
|
struct sway_seat *seat;
|
|
|
|
wl_list_for_each(seat, &server.input->seats, link) {
|
|
|
|
// but only if the currently focused layer has a lower precedence
|
|
|
|
if (!seat->focused_layer ||
|
|
|
|
seat->focused_layer->current.layer >= layer_surface->current.layer) {
|
|
|
|
seat_set_focus_layer(seat, layer_surface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
arrange_layers(surface->output);
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor_rebase_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_unmap(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_layer_surface *surface = wl_container_of(
|
|
|
|
listener, surface, unmap);
|
|
|
|
struct sway_seat *seat;
|
|
|
|
wl_list_for_each(seat, &server.input->seats, link) {
|
|
|
|
if (seat->focused_layer == surface->layer_surface) {
|
|
|
|
seat_set_focus_layer(seat, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor_rebase_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void popup_handle_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_layer_popup *popup =
|
|
|
|
wl_container_of(listener, popup, destroy);
|
|
|
|
|
|
|
|
wl_list_remove(&popup->destroy.link);
|
|
|
|
wl_list_remove(&popup->new_popup.link);
|
|
|
|
wl_list_remove(&popup->commit.link);
|
|
|
|
free(popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void popup_unconstrain(struct sway_layer_popup *popup) {
|
|
|
|
struct wlr_xdg_popup *wlr_popup = popup->wlr_popup;
|
|
|
|
struct sway_output *output = popup->toplevel->output;
|
|
|
|
|
|
|
|
// if a client tries to create a popup while we are in the process of destroying
|
|
|
|
// its output, don't crash.
|
|
|
|
if (!output) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lx, ly;
|
|
|
|
wlr_scene_node_coords(&popup->toplevel->scene->tree->node, &lx, &ly);
|
|
|
|
|
|
|
|
// the output box expressed in the coordinate system of the toplevel parent
|
|
|
|
// of the popup
|
|
|
|
struct wlr_box output_toplevel_sx_box = {
|
|
|
|
.x = output->lx - lx,
|
|
|
|
.y = output->ly - ly,
|
|
|
|
.width = output->width,
|
|
|
|
.height = output->height,
|
|
|
|
};
|
|
|
|
|
|
|
|
wlr_xdg_popup_unconstrain_from_box(wlr_popup, &output_toplevel_sx_box);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void popup_handle_commit(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_layer_popup *popup = wl_container_of(listener, popup, commit);
|
|
|
|
if (popup->wlr_popup->base->initial_commit) {
|
|
|
|
popup_unconstrain(popup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void popup_handle_new_popup(struct wl_listener *listener, void *data);
|
|
|
|
|
|
|
|
static struct sway_layer_popup *create_popup(struct wlr_xdg_popup *wlr_popup,
|
|
|
|
struct sway_layer_surface *toplevel, struct wlr_scene_tree *parent) {
|
|
|
|
struct sway_layer_popup *popup = calloc(1, sizeof(*popup));
|
|
|
|
if (popup == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
popup->toplevel = toplevel;
|
|
|
|
popup->wlr_popup = wlr_popup;
|
|
|
|
popup->scene = wlr_scene_xdg_surface_create(parent,
|
|
|
|
wlr_popup->base);
|
|
|
|
|
|
|
|
if (!popup->scene) {
|
|
|
|
free(popup);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
popup->destroy.notify = popup_handle_destroy;
|
|
|
|
wl_signal_add(&wlr_popup->base->events.destroy, &popup->destroy);
|
|
|
|
popup->new_popup.notify = popup_handle_new_popup;
|
|
|
|
wl_signal_add(&wlr_popup->base->events.new_popup, &popup->new_popup);
|
|
|
|
popup->commit.notify = popup_handle_commit;
|
|
|
|
wl_signal_add(&wlr_popup->base->surface->events.commit, &popup->commit);
|
|
|
|
|
|
|
|
return popup;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void popup_handle_new_popup(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_layer_popup *sway_layer_popup =
|
|
|
|
wl_container_of(listener, sway_layer_popup, new_popup);
|
|
|
|
struct wlr_xdg_popup *wlr_popup = data;
|
|
|
|
create_popup(wlr_popup, sway_layer_popup->toplevel, sway_layer_popup->scene);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_new_popup(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_layer_surface *sway_layer_surface =
|
|
|
|
wl_container_of(listener, sway_layer_surface, new_popup);
|
|
|
|
struct wlr_xdg_popup *wlr_popup = data;
|
|
|
|
create_popup(wlr_popup, sway_layer_surface, sway_layer_surface->popups);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_layer_surface_v1 *layer_surface = data;
|
|
|
|
sway_log(SWAY_DEBUG, "new layer surface: namespace %s layer %d anchor %" PRIu32
|
|
|
|
" size %" PRIu32 "x%" PRIu32 " margin %" PRIu32 ",%" PRIu32 ",%" PRIu32 ",%" PRIu32 ",",
|
|
|
|
layer_surface->namespace,
|
|
|
|
layer_surface->pending.layer,
|
|
|
|
layer_surface->pending.anchor,
|
|
|
|
layer_surface->pending.desired_width,
|
|
|
|
layer_surface->pending.desired_height,
|
|
|
|
layer_surface->pending.margin.top,
|
|
|
|
layer_surface->pending.margin.right,
|
|
|
|
layer_surface->pending.margin.bottom,
|
|
|
|
layer_surface->pending.margin.left);
|
|
|
|
|
|
|
|
if (!layer_surface->output) {
|
|
|
|
// Assign last active output
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
6 years ago
|
|
|
struct sway_output *output = NULL;
|
|
|
|
struct sway_seat *seat = input_manager_get_default_seat();
|
|
|
|
if (seat) {
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
6 years ago
|
|
|
struct sway_workspace *ws = seat_get_focused_workspace(seat);
|
|
|
|
if (ws != NULL) {
|
|
|
|
output = ws->output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!output || output == root->fallback_output) {
|
|
|
|
if (!root->outputs->length) {
|
|
|
|
sway_log(SWAY_ERROR,
|
|
|
|
"no output to auto-assign layer surface '%s' to",
|
|
|
|
layer_surface->namespace);
|
|
|
|
wlr_layer_surface_v1_destroy(layer_surface);
|
|
|
|
return;
|
|
|
|
}
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
6 years ago
|
|
|
output = root->outputs->items[0];
|
|
|
|
}
|
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.
In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.
If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.
There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.
In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.
The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.
The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.
Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.
Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.
In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.
container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.
`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.
container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.
There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.
The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
6 years ago
|
|
|
layer_surface->output = output->wlr_output;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sway_output *output = layer_surface->output->data;
|
|
|
|
|
|
|
|
enum zwlr_layer_shell_v1_layer layer_type = layer_surface->pending.layer;
|
|
|
|
struct wlr_scene_tree *output_layer = sway_layer_get_scene(
|
|
|
|
output, layer_type);
|
|
|
|
struct wlr_scene_layer_surface_v1 *scene_surface =
|
|
|
|
wlr_scene_layer_surface_v1_create(output_layer, layer_surface);
|
|
|
|
if (!scene_surface) {
|
|
|
|
sway_log(SWAY_ERROR, "Could not allocate a layer_surface_v1");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sway_layer_surface *surface =
|
|
|
|
sway_layer_surface_create(scene_surface);
|
|
|
|
if (!surface) {
|
|
|
|
wlr_layer_surface_v1_destroy(layer_surface);
|
|
|
|
|
|
|
|
sway_log(SWAY_ERROR, "Could not allocate a sway_layer_surface");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!scene_descriptor_assign(&scene_surface->tree->node,
|
|
|
|
SWAY_SCENE_DESC_LAYER_SHELL, surface)) {
|
|
|
|
sway_log(SWAY_ERROR, "Failed to allocate a layer surface descriptor");
|
|
|
|
// destroying the layer_surface will also destroy its corresponding
|
|
|
|
// scene node
|
|
|
|
wlr_layer_surface_v1_destroy(layer_surface);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface->output = output;
|
|
|
|
|
|
|
|
// now that the surface's output is known, we can advertise its scale
|
|
|
|
wlr_fractional_scale_v1_notify_scale(surface->layer_surface->surface,
|
|
|
|
layer_surface->output->scale);
|
|
|
|
wlr_surface_set_preferred_buffer_scale(surface->layer_surface->surface,
|
|
|
|
ceil(layer_surface->output->scale));
|
|
|
|
|
|
|
|
surface->surface_commit.notify = handle_surface_commit;
|
|
|
|
wl_signal_add(&layer_surface->surface->events.commit,
|
|
|
|
&surface->surface_commit);
|
|
|
|
surface->map.notify = handle_map;
|
|
|
|
wl_signal_add(&layer_surface->surface->events.map, &surface->map);
|
|
|
|
surface->unmap.notify = handle_unmap;
|
|
|
|
wl_signal_add(&layer_surface->surface->events.unmap, &surface->unmap);
|
|
|
|
surface->new_popup.notify = handle_new_popup;
|
|
|
|
wl_signal_add(&layer_surface->events.new_popup, &surface->new_popup);
|
|
|
|
|
|
|
|
surface->output_destroy.notify = handle_output_destroy;
|
|
|
|
wl_signal_add(&output->events.disable, &surface->output_destroy);
|
|
|
|
|
|
|
|
surface->node_destroy.notify = handle_node_destroy;
|
|
|
|
wl_signal_add(&scene_surface->tree->node.events.destroy, &surface->node_destroy);
|
|
|
|
}
|