aboutsummaryrefslogtreecommitdiffstats
path: root/sway/desktop/layer_shell.c
blob: 3cf171bd1d85fa707b5f194ceb521865866bdfe5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <stdlib.h>
#include <wayland-server.h>
#include <wlr/util/log.h>
#include "sway/layers.h"
#include "sway/output.h"
#include "sway/server.h"

static void arrange_layers(struct sway_output *output) {
	// TODO
}

static void handle_output_destroy(struct wl_listener *listener, void *data) {
	// TODO
}

static void handle_output_mode(struct wl_listener *listener, void *data) {
	// TODO
}

static void handle_output_transform(struct wl_listener *listener, void *data) {
	// TODO
}

static void handle_surface_commit(struct wl_listener *listener, void *data) {
	// TODO
}

static void handle_destroy(struct wl_listener *listener, void *data) {
	// TODO
}

static void handle_map(struct wl_listener *listener, void *data) {
	// TODO
}

static void handle_unmap(struct wl_listener *listener, void *data) {
	// TODO
}

void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
	struct wlr_layer_surface *layer_surface = data;
	struct sway_server *server =
		wl_container_of(listener, server, layer_shell_surface);
	wlr_log(L_DEBUG, "new layer surface: namespace %s layer %d anchor %d "
			"size %dx%d margin %d,%d,%d,%d",
		layer_surface->namespace, layer_surface->layer, layer_surface->layer,
		layer_surface->client_pending.desired_width,
		layer_surface->client_pending.desired_height,
		layer_surface->client_pending.margin.top,
		layer_surface->client_pending.margin.right,
		layer_surface->client_pending.margin.bottom,
		layer_surface->client_pending.margin.left);

	struct sway_layer_surface *sway_layer =
		calloc(1, sizeof(struct sway_layer_surface));
	if (!sway_layer) {
		return;
	}

	sway_layer->surface_commit.notify = handle_surface_commit;
	wl_signal_add(&layer_surface->surface->events.commit,
		&sway_layer->surface_commit);

	sway_layer->output_destroy.notify = handle_output_destroy;
	wl_signal_add(&layer_surface->output->events.destroy,
		&sway_layer->output_destroy);

	sway_layer->output_mode.notify = handle_output_mode;
	wl_signal_add(&layer_surface->output->events.mode,
		&sway_layer->output_mode);

	sway_layer->output_transform.notify = handle_output_transform;
	wl_signal_add(&layer_surface->output->events.transform,
		&sway_layer->output_transform);

	sway_layer->destroy.notify = handle_destroy;
	wl_signal_add(&layer_surface->events.destroy, &sway_layer->destroy);
	sway_layer->map.notify = handle_map;
	wl_signal_add(&layer_surface->events.map, &sway_layer->map);
	sway_layer->unmap.notify = handle_unmap;
	wl_signal_add(&layer_surface->events.unmap, &sway_layer->unmap);
	// TODO: Listen for subsurfaces

	sway_layer->layer_surface = layer_surface;
	layer_surface->data = sway_layer;

	struct sway_output *output = layer_surface->output->data;
	wl_list_insert(&output->layers[layer_surface->layer], &sway_layer->link);

	// Temporarily set the layer's current state to client_pending
	// So that we can easily arrange it
	struct wlr_layer_surface_state old_state = layer_surface->current;
	layer_surface->current = layer_surface->client_pending;
	arrange_layers(output);
	layer_surface->current = old_state;
}