summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/output.c25
-rw-r--r--src/surface.c52
-rw-r--r--src/wlclock.c8
3 files changed, 42 insertions, 43 deletions
diff --git a/src/output.c b/src/output.c
index b2b4d0e..74088a9 100644
--- a/src/output.c
+++ b/src/output.c
@@ -43,13 +43,19 @@ static void output_handle_done (void *data, struct wl_output *wl_output)
return;
if ( output->surface == NULL )
{
+ /* We create the surface here, because we (sometimes) need to
+ * know the output name to decide whether an output gets a clock
+ * or not. This works both for outputs advertised during the
+ * initial registry dump and outputs added later.
+ */
if ( context.output == NULL || ! strcmp(context.output, output->name) )
create_surface(output);
}
- else
+ else if (output->surface->configured)
{
- if (! output->surface->configured)
- return;
+ /* If we already have a clock on an output, it might need a new
+ * frame, for example if the outputs scale changed.
+ */
render_background_frame(output->surface);
render_hands_frame(output->surface);
wl_surface_commit(output->surface->hands_surface);
@@ -74,6 +80,8 @@ static void xdg_output_handle_name (void *data, struct zxdg_output_v1 *xdg_outpu
}
static const struct zxdg_output_v1_listener xdg_output_listener = {
+ // TODO Remove XDG-Output dependency. The next Wayland version includes
+ // the name event in regular wl_output.
.name = xdg_output_handle_name,
.logical_size = noop,
.logical_position = noop,
@@ -86,15 +94,8 @@ static const struct zxdg_output_v1_listener xdg_output_listener = {
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;
- }
-
+ output->xdg_output = zxdg_output_manager_v1_get_xdg_output(
+ context.xdg_output_manager, output->wl_output);
zxdg_output_v1_add_listener(output->xdg_output, &xdg_output_listener, output);
output->configured = true;
return true;
diff --git a/src/surface.c b/src/surface.c
index e3b16cb..5a491ca 100644
--- a/src/surface.c
+++ b/src/surface.c
@@ -35,6 +35,9 @@ static void layer_surface_handle_configure (void *data,
bool dimensions_changed = false;
if ( w != (uint32_t)surface->dimensions.w )
{
+ /* A size of 0 means we are free to use whatever size we want.
+ * So let's just use the one the user configured.
+ */
surface->dimensions.w = w == 0 ? context.dimensions.w : (int32_t)w;
dimensions_changed = true;
}
@@ -56,12 +59,21 @@ static void layer_surface_handle_configure (void *data,
if ( surface->dimensions.center_size < 10 )
surface->dimensions.center_size = 10;
+ /* The size of the layer surface and the positioning of the
+ * subsurface may need to be updated.
+ */
zwlr_layer_surface_v1_set_size(surface->layer_surface,
surface->dimensions.w, surface->dimensions.h);
wl_subsurface_set_position(surface->subsurface,
- surface->dimensions.center_x, surface->dimensions.center_y);
+ surface->dimensions.center_x,
+ surface->dimensions.center_y);
}
+ /* We can only attach buffers to a surface after it has received a
+ * configure event. A new layer surface will get a configure event
+ * immediately. As a clean way to do the first render, we therefore
+ * always render on the first configure event.
+ */
if ( dimensions_changed || !surface->configured )
{
surface->configured = true;
@@ -75,6 +87,11 @@ static void layer_surface_handle_configure (void *data,
static void layer_surface_handle_closed (void *data, struct zwlr_layer_surface_v1 *layer_surface)
{
+ /* This event is received when the compositor closed our surface, for
+ * example because the output is was on disappeared. We now need to
+ * cleanup the surfaces remains. Should the output re-appear, then it
+ * will receive a new one.
+ */
struct Wlclock_surface *surface = (struct Wlclock_surface *)data;
clocklog(1, "[surface] Layer surface has been closed: global_name=%d\n",
surface->output->global_name);
@@ -124,34 +141,17 @@ bool create_surface (struct Wlclock_output *output)
surface->layer_surface = NULL;
surface->configured = false;
- if ( NULL == (surface->background_surface = wl_compositor_create_surface(context.compositor)) )
- {
- clocklog(0, "ERROR: Compositor did not create wl_surface (background).\n");
- return false;
- }
- if ( NULL == (surface->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
- context.layer_shell, surface->background_surface,
- output->wl_output, context.layer,
- context.namespace)) )
- {
- clocklog(0, "ERROR: Compositor did not create layer_surface.\n");
- return false;
- }
+ surface->background_surface = wl_compositor_create_surface(context.compositor);
+ surface->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
+ context.layer_shell, surface->background_surface,
+ output->wl_output, context.layer, context.namespace);
zwlr_layer_surface_v1_add_listener(surface->layer_surface,
&layer_surface_listener, surface);
- if ( NULL == (surface->hands_surface = wl_compositor_create_surface(context.compositor)) )
- {
- clocklog(0, "ERROR: Compositor did not create wl_surface (hands).\n");
- return false;
- }
- if ( NULL == (surface->subsurface = wl_subcompositor_get_subsurface(
- context.subcompositor, surface->hands_surface,
- surface->background_surface)) )
- {
- clocklog(0, "ERROR: Compositor did not create wl_subsurface.\n");
- return false;
- }
+ surface->hands_surface = wl_compositor_create_surface(context.compositor);
+ surface->subsurface = wl_subcompositor_get_subsurface(
+ context.subcompositor, surface->hands_surface,
+ surface->background_surface);
/* Set up layer surface. */
zwlr_layer_surface_v1_set_size(surface->layer_surface,
diff --git a/src/wlclock.c b/src/wlclock.c
index fefc480..bc88ca4 100644
--- a/src/wlclock.c
+++ b/src/wlclock.c
@@ -188,14 +188,12 @@ static bool init_wayland (void)
/* Get registry and add listeners. */
clocklog(2, "[main] Get wl_registry.\n");
- if ( NULL == (context.registry = wl_display_get_registry(context.display)) )
- {
- clocklog(0, "ERROR: Can not get registry.\n");
- return false;
- }
+ context.registry = wl_display_get_registry(context.display);
+
wl_registry_add_listener(context.registry, &registry_listener, NULL);
/* Allow registry listeners to catch up. */
+ // TODO use sync instead
if ( wl_display_roundtrip(context.display) == -1 )
{
clocklog(0, "ERROR: Roundtrip failed.\n");