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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<unistd.h>
#include<string.h>
#include<assert.h>
#include<wayland-server.h>
#include<wayland-client.h>
#include<wayland-client-protocol.h>
#include"xdg-output-unstable-v1-protocol.h"
#include"xdg-shell-protocol.h"
#include"wlclock.h"
#include"misc.h"
#include"output.h"
#include"surface.h"
#include"render.h"
/* No-Op function. */
static void noop () {}
static void output_handle_scale (void *data, struct wl_output *wl_output,
int32_t factor)
{
struct Wlclock_output *output = (struct Wlclock_output *)data;
output->scale = (uint32_t)factor;
clocklog(1, "[output] Property update: global_name=%d scale=%d\n",
output->global_name, output->scale);
}
static void output_handle_done (void *data, struct wl_output *wl_output)
{
/* This event is sent after all output property changes (by wl_output
* and by xdg_output) have been advertised by preceding events.
*/
struct Wlclock_output *output = (struct Wlclock_output *)data;
clocklog(1, "[output] Atomic update complete: global_name=%d\n",
output->global_name);
if ( ! output->configured || output->name == NULL )
return;
if ( output->surface == NULL )
{
if ( context.output == NULL || ! strcmp(context.output, output->name) )
create_surface(output);
}
else
{
if (! output->surface->configured)
return;
render_background_frame(output->surface);
render_hands_frame(output->surface);
wl_surface_commit(output->surface->hands_surface);
wl_surface_commit(output->surface->background_surface);
}
}
static const struct wl_output_listener output_listener = {
.scale = output_handle_scale,
.geometry = noop,
.mode = noop,
.done = output_handle_done
};
static void xdg_output_handle_name (void *data, struct zxdg_output_v1 *xdg_output,
const char *name)
{
struct Wlclock_output *output = (struct Wlclock_output *)data;
set_string(&output->name, (char *)name);
clocklog(1, "[output] Property update: global_name=%d name=%s\n",
output->global_name, name);
}
static const struct zxdg_output_v1_listener xdg_output_listener = {
.name = xdg_output_handle_name,
.logical_size = noop,
.logical_position = noop,
.description = noop,
/* Deprecated since version 3, xdg_output property changes now send wl_output.done */
.done = noop
};
bool configure_output (struct Wlclock_output *output)
{
clocklog(1, "[output] Configuring: global_name=%d\n", output->global_name);
/* Create xdg_output and attach listeners. */
if ( NULL == (output->xdg_output = zxdg_output_manager_v1_get_xdg_output(
context.xdg_output_manager, output->wl_output)) )
{
clocklog(0, "ERROR: Could not get XDG output.\n");
return false;
}
zxdg_output_v1_add_listener(output->xdg_output, &xdg_output_listener, output);
output->configured = true;
return true;
}
bool create_output (struct wl_registry *registry, uint32_t name,
const char *interface, uint32_t version)
{
clocklog(1, "[output] Creating: global_name=%d\n", name);
struct wl_output *wl_output = wl_registry_bind(registry, name,
&wl_output_interface, 3);
assert(wl_output);
struct Wlclock_output *output = calloc(1, sizeof(struct Wlclock_output));
if ( output == NULL )
{
clocklog(0, "ERROR: Could not allocate.\n");
return false;
}
output->global_name = name;
output->scale = 1;
output->wl_output = wl_output;
output->configured = false;
output->name = NULL;
wl_list_insert(&context.outputs, &output->link);
wl_output_set_user_data(wl_output, output);
wl_output_add_listener(wl_output, &output_listener, output);
/* We can only use the output if we have both xdg_output_manager and
* the layer_shell. If either one is not available yet, we have to
* configure the output later (see init_wayland()).
*/
if ( context.xdg_output_manager != NULL && context.layer_shell != NULL )
{
if (! configure_output(output))
return false;
}
else
clocklog(2, "[output] Not yet configureable.\n");
return true;
}
struct Wlclock_output *get_output_from_global_name (uint32_t name)
{
struct Wlclock_output *op;
wl_list_for_each(op, &context.outputs, link)
if ( op->global_name == name )
return op;
return NULL;
}
void destroy_output (struct Wlclock_output *output)
{
if ( output == NULL )
return;
if ( output->surface != NULL )
destroy_surface(output->surface);
wl_list_remove(&output->link);
wl_output_destroy(output->wl_output);
free(output);
}
void destroy_all_outputs (void)
{
clocklog(1, "[output] Destroying all outputs.\n");
struct Wlclock_output *op, *tmp;
wl_list_for_each_safe(op, tmp, &context.outputs, link)
destroy_output(op);
}
|