22 #include "uwac-priv.h"
23 #include "uwac-utils.h"
30 #define TARGET_OUTPUT_INTERFACE 2U
32 static bool dupstr(
char** dst,
const char* src)
43 static void output_handle_geometry(
void* data,
struct wl_output* wl_output,
int x,
int y,
44 int physical_width,
int physical_height,
int subpixel,
45 const char* make,
const char* model,
int transform)
47 UwacOutput* output = data;
50 output->position.x = x;
51 output->position.y = y;
52 output->transform = transform;
54 if (!dupstr(&output->make, make))
56 assert(uwacErrorHandler(output->display, UWAC_ERROR_NOMEMORY,
"%s: unable to strdup make\n",
60 if (!dupstr(&output->model, model))
62 assert(uwacErrorHandler(output->display, UWAC_ERROR_NOMEMORY,
63 "%s: unable to strdup model\n", __func__));
66 UwacEvent*
event = UwacDisplayNewEvent(output->display, UWAC_EVENT_OUTPUT_GEOMETRY);
67 event->output_geometry.output = output;
68 event->output_geometry.x = x;
69 event->output_geometry.y = y;
70 event->output_geometry.physical_width = physical_width;
71 event->output_geometry.physical_height = physical_height;
72 event->output_geometry.subpixel = subpixel;
73 event->output_geometry.make = output->make;
74 event->output_geometry.model = output->model;
75 event->output_geometry.transform = transform;
78 static void output_handle_done(
void* data,
struct wl_output* wl_output)
80 UwacOutput* output = data;
83 output->doneReceived =
true;
86 static void output_handle_scale(
void* data,
struct wl_output* wl_output, int32_t scale)
88 UwacOutput* output = data;
91 output->scale = scale;
92 if (scale > output->display->actual_scale)
93 output->display->actual_scale = scale;
96 static void output_handle_name(
void* data,
struct wl_output* wl_output,
const char* name)
98 UwacOutput* output = data;
101 if (!dupstr(&output->name, name))
103 assert(uwacErrorHandler(output->display, UWAC_ERROR_NOMEMORY,
"%s: unable to strdup make\n",
108 static void output_handle_description(
void* data,
struct wl_output* wl_output,
109 const char* description)
111 UwacOutput* output = data;
114 if (!dupstr(&output->description, description))
116 assert(uwacErrorHandler(output->display, UWAC_ERROR_NOMEMORY,
"%s: unable to strdup make\n",
121 static void output_handle_mode(
void* data,
struct wl_output* wl_output, uint32_t flags,
int width,
122 int height,
int refresh)
124 UwacOutput* output = data;
128 if (output->doneNeeded && output->doneReceived)
133 if (flags & WL_OUTPUT_MODE_CURRENT)
135 output->resolution.width = width;
136 output->resolution.height = height;
145 static const struct wl_output_listener output_listener = {
146 output_handle_geometry, output_handle_mode, output_handle_done,
147 output_handle_scale, output_handle_name, output_handle_description
150 UwacOutput* UwacCreateOutput(UwacDisplay* d, uint32_t
id, uint32_t version)
152 UwacOutput* o = xzalloc(
sizeof *o);
157 o->server_output_id = id;
158 o->doneNeeded = (version > 1);
159 o->doneReceived =
false;
160 o->output = wl_registry_bind(d->registry,
id, &wl_output_interface,
161 min(TARGET_OUTPUT_INTERFACE, version));
162 wl_output_add_listener(o->output, &output_listener, o);
164 wl_list_insert(d->outputs.prev, &o->link);
168 int UwacDestroyOutput(UwacOutput* output)
176 free(output->description);
178 wl_output_destroy(output->output);
179 wl_list_remove(&output->link);