Dunst
Lightweight notification daemon
Loading...
Searching...
No Matches
wl_output.c
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause */
7
8#define _POSIX_C_SOURCE 200112L
9#include "wl_output.h"
10
11#include "../dunst.h"
12#include "../log.h"
13#include "wl_ctx.h"
14
15static void output_handle_geometry(void *data, struct wl_output *wl_output,
16 int32_t x, int32_t y, int32_t phy_width, int32_t phy_height,
17 int32_t subpixel, const char *make, const char *model,
18 int32_t transform) {
19 //TODO do something with the subpixel data
20 struct dunst_output *output = data;
21 output->subpixel = subpixel;
22}
23static void output_handle_mode(void *data, struct wl_output *wl_output, uint32_t flags,
24 int32_t width, int32_t height, int32_t refresh) {
25 struct dunst_output *output = data;
26 output->width = width;
27 output->height = height;
28}
29
30static void output_handle_scale(void *data, struct wl_output *wl_output,
31 int32_t factor) {
32 struct dunst_output *output = data;
33 output->scale = factor;
34
35 wake_up();
36}
37
38#ifdef WL_OUTPUT_NAME_SINCE_VERSION
39static void output_handle_name(void *data, struct wl_output *wl_output,
40 const char *name) {
41 struct dunst_output *output = data;
42 output->name = g_strdup(name);
43 LOG_D("Output global %" PRIu32 " name %s", output->global_name, name);
44}
45
46static void output_handle_description(void *data, struct wl_output *output, const char* description) {
47 // do nothing
48}
49#endif
50
51static void output_listener_done_handler(void *data, struct wl_output *output) {
52 // do nothing
53}
54
55static const struct wl_output_listener output_listener = {
56 .geometry = output_handle_geometry,
57 .mode = output_handle_mode,
58 .done = output_listener_done_handler,
59 .scale = output_handle_scale,
60#ifdef WL_OUTPUT_NAME_SINCE_VERSION
61 .name = output_handle_name,
62 .description = output_handle_description,
63#endif
64};
65
66void create_output(struct wl_registry *registry, uint32_t global_name, uint32_t version) {
67 struct dunst_output *output = g_malloc0(sizeof(struct dunst_output));
68 if (output == NULL) {
69 LOG_E("allocation failed");
70 return;
71 }
72
73 uint32_t max_version = 3;
74#ifdef WL_OUTPUT_NAME_SINCE_VERSION
75 max_version = WL_OUTPUT_NAME_SINCE_VERSION;
76#endif
77 bool recreate_surface = false;
78 static int number = 0;
79 LOG_I("New output found - id %i", number);
80 output->global_name = global_name;
81 output->wl_output = wl_registry_bind(registry, global_name, &wl_output_interface,
82 CLAMP(version, 3, max_version));
83 output->scale = 1;
84 output->fullscreen = false;
85
86 recreate_surface = wl_list_empty(&ctx.outputs);
87
88 wl_list_insert(&ctx.outputs, &output->link);
89
90 wl_output_set_user_data(output->wl_output, output);
91 wl_output_add_listener(output->wl_output, &output_listener, output);
92 number++;
93
94 if (recreate_surface) {
95 // We had no outputs, force our surface to redraw
96 set_dirty();
97 }
98}
99
100void destroy_output(struct dunst_output *output) {
101 if (ctx.surface_output == output) {
102 ctx.surface_output = NULL;
103 }
104 if (ctx.layer_surface_output == output) {
105 ctx.layer_surface_output = NULL;
106 }
107 wl_list_remove(&output->link);
108 wl_output_destroy(output->wl_output);
109 g_free(output->name);
110 g_free(output);
111}
Main event loop logic.
Logging subsystem and helpers.
#define LOG_E
Prefix message with "[<source path>:<function name>:<line number>] ".
Definition log.h:42
Wayland context tracking.
Wayland output wrapper.