mirror of
https://github.com/labwc/labwc.git
synced 2025-10-31 22:25:34 -04:00
layer: support popups
This commit is contained in:
parent
2891ff245e
commit
49e8658a7b
2 changed files with 131 additions and 193 deletions
|
|
@ -8,13 +8,8 @@ struct server;
|
||||||
|
|
||||||
#define LAB_NR_LAYERS (4)
|
#define LAB_NR_LAYERS (4)
|
||||||
|
|
||||||
enum layer_parent {
|
|
||||||
LAYER_PARENT_LAYER,
|
|
||||||
LAYER_PARENT_POPUP,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct lab_layer_surface {
|
struct lab_layer_surface {
|
||||||
struct wl_list link; /* output::layers[] */
|
struct wl_list link; /* output::layers */
|
||||||
struct wlr_scene_layer_surface_v1 *scene_layer_surface;
|
struct wlr_scene_layer_surface_v1 *scene_layer_surface;
|
||||||
|
|
||||||
struct wl_listener destroy;
|
struct wl_listener destroy;
|
||||||
|
|
@ -23,39 +18,21 @@ struct lab_layer_surface {
|
||||||
struct wl_listener surface_commit;
|
struct wl_listener surface_commit;
|
||||||
struct wl_listener output_destroy;
|
struct wl_listener output_destroy;
|
||||||
struct wl_listener new_popup;
|
struct wl_listener new_popup;
|
||||||
struct wl_listener new_subsurface;
|
|
||||||
|
|
||||||
struct wlr_box geo;
|
struct wlr_box geo;
|
||||||
bool mapped;
|
bool mapped;
|
||||||
/* TODO: add extent and layer */
|
/* TODO: add extent? */
|
||||||
struct server *server;
|
struct server *server;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* FIXME: do we still need lab_layer_popup and lab_layer_subsurface? */
|
|
||||||
struct lab_layer_popup {
|
struct lab_layer_popup {
|
||||||
struct wlr_xdg_popup *wlr_popup;
|
struct wlr_xdg_popup *wlr_popup;
|
||||||
enum layer_parent parent_type;
|
struct wlr_scene_node *scene_node;
|
||||||
union {
|
|
||||||
struct lab_layer_surface *parent_layer;
|
|
||||||
struct lab_layer_popup *parent_popup;
|
|
||||||
};
|
|
||||||
struct wl_listener map;
|
|
||||||
struct wl_listener unmap;
|
|
||||||
struct wl_listener destroy;
|
struct wl_listener destroy;
|
||||||
struct wl_listener commit;
|
|
||||||
struct wl_listener new_popup;
|
struct wl_listener new_popup;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct lab_layer_subsurface {
|
|
||||||
struct wlr_subsurface *wlr_subsurface;
|
|
||||||
struct lab_layer_surface *layer_surface;
|
|
||||||
|
|
||||||
struct wl_listener map;
|
|
||||||
struct wl_listener unmap;
|
|
||||||
struct wl_listener destroy;
|
|
||||||
struct wl_listener commit;
|
|
||||||
};
|
|
||||||
|
|
||||||
void layers_init(struct server *server);
|
void layers_init(struct server *server);
|
||||||
|
|
||||||
#endif /* __LABWC_LAYERS_H */
|
#endif /* __LABWC_LAYERS_H */
|
||||||
|
|
|
||||||
293
src/layers.c
293
src/layers.c
|
|
@ -2,7 +2,7 @@
|
||||||
/*
|
/*
|
||||||
* layers.c - layer-shell implementation
|
* layers.c - layer-shell implementation
|
||||||
*
|
*
|
||||||
* Based on:
|
* Based on
|
||||||
* - https://git.sr.ht/~sircmpwm/wio
|
* - https://git.sr.ht/~sircmpwm/wio
|
||||||
* - https://github.com/swaywm/sway
|
* - https://github.com/swaywm/sway
|
||||||
* Copyright (C) 2019 Drew DeVault and Sway developers
|
* Copyright (C) 2019 Drew DeVault and Sway developers
|
||||||
|
|
@ -16,17 +16,14 @@
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "layers.h"
|
#include "layers.h"
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
|
#include "node-descriptor.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
arrange_layers(struct output *output)
|
arrange_layers(struct output *output)
|
||||||
{
|
{
|
||||||
struct server *server = output->server;
|
|
||||||
struct wlr_scene_output *scene_output =
|
|
||||||
wlr_scene_get_scene_output(server->scene, output->wlr_output);
|
|
||||||
|
|
||||||
struct wlr_box full_area = { 0 };
|
struct wlr_box full_area = { 0 };
|
||||||
wlr_output_effective_resolution(output->wlr_output,
|
wlr_output_effective_resolution(output->wlr_output,
|
||||||
&full_area.width, &full_area.height);
|
&full_area.width, &full_area.height);
|
||||||
struct wlr_box usable_area = full_area;
|
struct wlr_box usable_area = full_area;
|
||||||
|
|
||||||
for (int i = 0; i < LAB_NR_LAYERS; i++) {
|
for (int i = 0; i < LAB_NR_LAYERS; i++) {
|
||||||
|
|
@ -110,7 +107,6 @@ unmap(struct lab_layer_surface *layer)
|
||||||
if (seat->focused_layer == layer->scene_layer_surface->layer_surface) {
|
if (seat->focused_layer == layer->scene_layer_surface->layer_surface) {
|
||||||
seat_set_focus_layer(seat, NULL);
|
seat_set_focus_layer(seat, NULL);
|
||||||
}
|
}
|
||||||
damage_all_outputs(layer->server);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -122,15 +118,15 @@ destroy_notify(struct wl_listener *listener, void *data)
|
||||||
unmap(layer);
|
unmap(layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: sort this out properly */
|
|
||||||
wl_list_remove(&layer->link);
|
wl_list_remove(&layer->link);
|
||||||
wl_list_remove(&layer->destroy.link);
|
wl_list_remove(&layer->destroy.link);
|
||||||
wl_list_remove(&layer->map.link);
|
wl_list_remove(&layer->map.link);
|
||||||
|
wl_list_remove(&layer->unmap.link);
|
||||||
wl_list_remove(&layer->surface_commit.link);
|
wl_list_remove(&layer->surface_commit.link);
|
||||||
if (layer->scene_layer_surface->layer_surface->output) {
|
if (layer->scene_layer_surface->layer_surface->output) {
|
||||||
wl_list_remove(&layer->output_destroy.link);
|
wl_list_remove(&layer->output_destroy.link);
|
||||||
struct output *output = output_from_wlr_output(
|
struct output *output = output_from_wlr_output(layer->server,
|
||||||
layer->server, layer->scene_layer_surface->layer_surface->output);
|
layer->scene_layer_surface->layer_surface->output);
|
||||||
arrange_layers(output);
|
arrange_layers(output);
|
||||||
}
|
}
|
||||||
free(layer);
|
free(layer);
|
||||||
|
|
@ -139,160 +135,128 @@ destroy_notify(struct wl_listener *listener, void *data)
|
||||||
static void
|
static void
|
||||||
unmap_notify(struct wl_listener *listener, void *data)
|
unmap_notify(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
struct lab_layer_surface *l = wl_container_of(listener, l, unmap);
|
return;
|
||||||
unmap(l);
|
struct lab_layer_surface *lab_layer_surface =
|
||||||
|
wl_container_of(listener, lab_layer_surface, unmap);
|
||||||
|
unmap(lab_layer_surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
map_notify(struct wl_listener *listener, void *data)
|
map_notify(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
struct wlr_layer_surface_v1 *l = data;
|
return;
|
||||||
wlr_surface_send_enter(l->surface, l->output);
|
struct wlr_layer_surface_v1 *layer_surface = data;
|
||||||
|
wlr_surface_send_enter(layer_surface->surface, layer_surface->output);
|
||||||
}
|
}
|
||||||
|
|
||||||
//static struct
|
static struct
|
||||||
//lab_layer_surface *popup_get_layer(struct lab_layer_popup *popup)
|
lab_layer_surface *popup_get_layer(struct lab_layer_popup *popup)
|
||||||
//{
|
{
|
||||||
// while (popup->parent_type == LAYER_PARENT_POPUP) {
|
struct wlr_scene_node *node = popup->scene_node;
|
||||||
// popup = popup->parent_popup;
|
while (node) {
|
||||||
// }
|
if (node->data) {
|
||||||
// return popup->parent_layer;
|
struct node_descriptor *desc = node->data;
|
||||||
//}
|
if (desc->type == LAB_NODE_DESC_LAYER_SURFACE) {
|
||||||
//
|
return desc->data;
|
||||||
//static void
|
}
|
||||||
//popup_damage(struct lab_layer_popup *layer_popup, bool whole)
|
}
|
||||||
//{
|
node = node->parent;
|
||||||
// struct lab_layer_surface *layer;
|
}
|
||||||
// while (true) {
|
return NULL;
|
||||||
// if (layer_popup->parent_type == LAYER_PARENT_POPUP) {
|
}
|
||||||
// layer_popup = layer_popup->parent_popup;
|
|
||||||
// } else {
|
static void
|
||||||
// layer = layer_popup->parent_layer;
|
popup_handle_destroy(struct wl_listener *listener, void *data)
|
||||||
// break;
|
{
|
||||||
// }
|
struct lab_layer_popup *popup =
|
||||||
// }
|
wl_container_of(listener, popup, destroy);
|
||||||
// damage_all_outputs(layer->server);
|
wl_list_remove(&popup->destroy.link);
|
||||||
//}
|
wl_list_remove(&popup->new_popup.link);
|
||||||
//
|
free(popup);
|
||||||
//static void
|
}
|
||||||
//popup_handle_map(struct wl_listener *listener, void *data)
|
|
||||||
//{
|
static void
|
||||||
// struct lab_layer_popup *popup = wl_container_of(listener, popup, map);
|
popup_unconstrain(struct lab_layer_popup *popup)
|
||||||
// struct lab_layer_surface *layer = popup_get_layer(popup);
|
{
|
||||||
// struct wlr_output *wlr_output = layer->scene_layer_surface->layer_surface->output;
|
struct lab_layer_surface *layer = popup_get_layer(popup);
|
||||||
// wlr_surface_send_enter(popup->wlr_popup->base->surface, wlr_output);
|
if (!layer) {
|
||||||
// popup_damage(popup, true);
|
return;
|
||||||
//}
|
}
|
||||||
//
|
struct wlr_xdg_popup *wlr_popup = popup->wlr_popup;
|
||||||
//static void
|
struct output *output =
|
||||||
//popup_handle_unmap(struct wl_listener *listener, void *data)
|
layer->scene_layer_surface->layer_surface->output->data;
|
||||||
//{
|
|
||||||
// struct lab_layer_popup *popup = wl_container_of(listener, popup, unmap);
|
struct wlr_box output_box = { 0 };
|
||||||
// popup_damage(popup, true);
|
wlr_output_effective_resolution(output->wlr_output, &output_box.width,
|
||||||
//}
|
&output_box.height);
|
||||||
//
|
|
||||||
//static void
|
/*
|
||||||
//popup_handle_commit(struct wl_listener *listener, void *data)
|
* Output geometry expressed in the coordinate system of the toplevel
|
||||||
//{
|
* parent of popup
|
||||||
// struct lab_layer_popup *popup = wl_container_of(listener, popup, commit);
|
*/
|
||||||
// popup_damage(popup, false);
|
struct wlr_box output_toplevel_sx_box = {
|
||||||
//}
|
.x = -layer->geo.x,
|
||||||
//
|
.y = -layer->geo.y,
|
||||||
//static void
|
.width = output_box.width,
|
||||||
//popup_handle_destroy(struct wl_listener *listener, void *data)
|
.height = output_box.height,
|
||||||
//{
|
};
|
||||||
// struct lab_layer_popup *popup =
|
|
||||||
// wl_container_of(listener, popup, destroy);
|
wlr_xdg_popup_unconstrain_from_box(wlr_popup, &output_toplevel_sx_box);
|
||||||
// wl_list_remove(&popup->destroy.link);
|
}
|
||||||
// free(popup);
|
|
||||||
//}
|
static void popup_handle_new_popup(struct wl_listener *listener, void *data);
|
||||||
//
|
|
||||||
//static void
|
static struct lab_layer_popup *
|
||||||
//popup_unconstrain(struct lab_layer_popup *popup)
|
create_popup(struct wlr_xdg_popup *wlr_popup, struct wlr_scene_node *parent)
|
||||||
//{
|
{
|
||||||
// struct lab_layer_surface *layer = popup_get_layer(popup);
|
struct lab_layer_popup *popup =
|
||||||
// struct wlr_xdg_popup *wlr_popup = popup->wlr_popup;
|
calloc(1, sizeof(struct lab_layer_popup));
|
||||||
// struct output *output = layer->scene_layer_surface->layer_surface->output->data;
|
if (!popup) {
|
||||||
//
|
return NULL;
|
||||||
// struct wlr_box output_box = { 0 };
|
}
|
||||||
// wlr_output_effective_resolution(output->wlr_output, &output_box.width,
|
|
||||||
// &output_box.height);
|
popup->wlr_popup = wlr_popup;
|
||||||
//
|
popup->scene_node =
|
||||||
// struct wlr_box output_toplevel_sx_box = {
|
wlr_scene_xdg_surface_create(parent, wlr_popup->base);
|
||||||
// .x = -layer->geo.x,
|
if (!popup->scene_node) {
|
||||||
// .y = -layer->geo.y,
|
free(popup);
|
||||||
// .width = output_box.width,
|
return NULL;
|
||||||
// .height = output_box.height,
|
}
|
||||||
// };
|
node_descriptor_create(popup->scene_node,
|
||||||
//
|
LAB_NODE_DESC_LAYER_POPUP, popup);
|
||||||
// wlr_xdg_popup_unconstrain_from_box(wlr_popup, &output_toplevel_sx_box);
|
|
||||||
//}
|
popup->destroy.notify = popup_handle_destroy;
|
||||||
//
|
wl_signal_add(&wlr_popup->base->events.destroy, &popup->destroy);
|
||||||
//static void popup_handle_new_popup(struct wl_listener *listener, void *data);
|
popup->new_popup.notify = popup_handle_new_popup;
|
||||||
//
|
wl_signal_add(&wlr_popup->base->events.new_popup, &popup->new_popup);
|
||||||
//static struct lab_layer_popup *
|
|
||||||
//create_popup(struct wlr_xdg_popup *wlr_popup,
|
/*
|
||||||
// enum layer_parent parent_type, void *parent)
|
* FIXME: should we put popups in ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY
|
||||||
//{
|
* or a dedicated output->layer_popup_tree - so that for example
|
||||||
// struct lab_layer_popup *popup =
|
* a panel in the bottom layer displays any popup above views.
|
||||||
// calloc(1, sizeof(struct lab_layer_popup));
|
*/
|
||||||
// if (!popup) {
|
|
||||||
// return NULL;
|
popup_unconstrain(popup);
|
||||||
// }
|
return popup;
|
||||||
//
|
}
|
||||||
// struct lab_layer_surface *layer = parent_type == LAYER_PARENT_LAYER
|
|
||||||
// ? (struct lab_layer_surface *)parent
|
static void
|
||||||
// : (struct lab_layer_popup *)parent;
|
popup_handle_new_popup(struct wl_listener *listener, void *data)
|
||||||
// struct server *server = layer->server;
|
{
|
||||||
//
|
struct lab_layer_popup *lab_layer_popup =
|
||||||
// popup->wlr_popup = wlr_popup;
|
wl_container_of(listener, lab_layer_popup, new_popup);
|
||||||
// popup->parent_type = parent_type;
|
struct wlr_xdg_popup *wlr_popup = data;
|
||||||
// popup->parent_layer = parent;
|
create_popup(wlr_popup, lab_layer_popup->scene_node);
|
||||||
//
|
}
|
||||||
// popup->destroy.notify = popup_handle_destroy;
|
|
||||||
// wl_signal_add(&wlr_popup->base->events.destroy, &popup->destroy);
|
static void
|
||||||
// popup->new_popup.notify = popup_handle_new_popup;
|
new_popup_notify(struct wl_listener *listener, void *data)
|
||||||
// wl_signal_add(&wlr_popup->base->events.new_popup, &popup->new_popup);
|
{
|
||||||
//
|
struct lab_layer_surface *lab_layer_surface =
|
||||||
// if (!wlr_surface_is_layer_surface(wlr_popup->base->surface)) {
|
wl_container_of(listener, lab_layer_surface, new_popup);
|
||||||
// wlr_log(WLR_ERROR, "xdg_surface is not layer surface");
|
struct wlr_xdg_popup *wlr_popup = data;
|
||||||
// return;
|
create_popup(wlr_popup, lab_layer_surface->scene_layer_surface->node);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// struct wlr_output *wlr_output =
|
|
||||||
// layer->scene_layer_surface->layer_surface->data;
|
|
||||||
// struct output *output = output_from_wlr_output(server, wlr_output);
|
|
||||||
//
|
|
||||||
// struct wlr_scene_tree *selected_layer =
|
|
||||||
// output->layer_tree[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY];
|
|
||||||
// struct wlr_scene_node *node =
|
|
||||||
// wlr_scene_layer_surface_v1_create(&server->view_tree->node,
|
|
||||||
// wlr_popup->base->surface->data);
|
|
||||||
// wlr_popup->base->surface->data =
|
|
||||||
// wlr_scene_xdg_surface_create(&selected_layer->node, wlr_popup->base);
|
|
||||||
//
|
|
||||||
// popup_unconstrain(popup);
|
|
||||||
//
|
|
||||||
// return popup;
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//static void
|
|
||||||
//popup_handle_new_popup(struct wl_listener *listener, void *data)
|
|
||||||
//{
|
|
||||||
// struct lab_layer_popup *lab_layer_popup =
|
|
||||||
// wl_container_of(listener, lab_layer_popup, new_popup);
|
|
||||||
// struct wlr_xdg_popup *wlr_popup = data;
|
|
||||||
// create_popup(wlr_popup, LAYER_PARENT_POPUP, lab_layer_popup);
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//static void
|
|
||||||
//new_popup_notify(struct wl_listener *listener, void *data)
|
|
||||||
//{
|
|
||||||
// struct lab_layer_surface *lab_layer_surface =
|
|
||||||
// wl_container_of(listener, lab_layer_surface, new_popup);
|
|
||||||
// struct wlr_xdg_popup *wlr_popup = data;
|
|
||||||
// create_popup(wlr_popup, LAYER_PARENT_LAYER, lab_layer_surface);
|
|
||||||
//}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
new_layer_surface_notify(struct wl_listener *listener, void *data)
|
new_layer_surface_notify(struct wl_listener *listener, void *data)
|
||||||
|
|
@ -327,13 +291,8 @@ new_layer_surface_notify(struct wl_listener *listener, void *data)
|
||||||
surface->unmap.notify = unmap_notify;
|
surface->unmap.notify = unmap_notify;
|
||||||
wl_signal_add(&layer_surface->events.unmap, &surface->unmap);
|
wl_signal_add(&layer_surface->events.unmap, &surface->unmap);
|
||||||
|
|
||||||
/* TODO: support popups */
|
surface->new_popup.notify = new_popup_notify;
|
||||||
// surface->new_popup.notify = new_popup_notify;
|
wl_signal_add(&layer_surface->events.new_popup, &surface->new_popup);
|
||||||
// wl_signal_add(&layer_surface->events.new_popup, &surface->new_popup);
|
|
||||||
//
|
|
||||||
// surface->new_subsurface.notify = new_subsurface_notify;
|
|
||||||
// wl_signal_add(&layer_surface->surface->events.new_subsurface,
|
|
||||||
// &surface->new_subsurface);
|
|
||||||
|
|
||||||
struct output *output = layer_surface->output->data;
|
struct output *output = layer_surface->output->data;
|
||||||
|
|
||||||
|
|
@ -342,12 +301,14 @@ new_layer_surface_notify(struct wl_listener *listener, void *data)
|
||||||
|
|
||||||
surface->scene_layer_surface = wlr_scene_layer_surface_v1_create(
|
surface->scene_layer_surface = wlr_scene_layer_surface_v1_create(
|
||||||
&selected_layer->node, layer_surface);
|
&selected_layer->node, layer_surface);
|
||||||
|
node_descriptor_create(surface->scene_layer_surface->node,
|
||||||
|
LAB_NODE_DESC_LAYER_SURFACE, surface);
|
||||||
|
|
||||||
surface->server = server;
|
surface->server = server;
|
||||||
surface->scene_layer_surface->layer_surface = layer_surface;
|
surface->scene_layer_surface->layer_surface = layer_surface;
|
||||||
|
|
||||||
/* wlr_surface->data needed to find parent in xdg_surface_new() */
|
// /* wlr_surface->data needed to find parent in xdg_surface_new() */
|
||||||
layer_surface->surface->data = surface->scene_layer_surface->node;
|
// layer_surface->surface->data = surface->scene_layer_surface->node;
|
||||||
|
|
||||||
surface->output_destroy.notify = output_destroy_notify;
|
surface->output_destroy.notify = output_destroy_notify;
|
||||||
wl_signal_add(&layer_surface->output->events.destroy,
|
wl_signal_add(&layer_surface->output->events.destroy,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue