2016-01-18 17:55:33 +03:00
|
|
|
/*
|
|
|
|
* Copyright © 2014 David FORT <contact@hardening-consulting.com>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
* the above copyright notice appear in all copies and that both that copyright
|
|
|
|
* notice and this permission notice appear in supporting documentation, and
|
|
|
|
* that the name of the copyright holders not be used in advertising or
|
|
|
|
* publicity pertaining to distribution of the software without specific,
|
|
|
|
* written prior permission. The copyright holders make no representations
|
|
|
|
* about the suitability of this software for any purpose. It is provided "as
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
|
|
|
* OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include "uwac-priv.h"
|
|
|
|
#include "uwac-utils.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2019-02-07 16:21:04 +03:00
|
|
|
#define TARGET_OUTPUT_INTERFACE 2U
|
2016-01-18 17:55:33 +03:00
|
|
|
|
2023-08-25 11:30:16 +03:00
|
|
|
static bool dupstr(char** dst, const char* src)
|
|
|
|
{
|
|
|
|
assert(dst);
|
|
|
|
free(*dst);
|
|
|
|
*dst = NULL;
|
|
|
|
if (!src)
|
2023-08-31 09:13:52 +03:00
|
|
|
return true;
|
2023-11-22 11:44:37 +03:00
|
|
|
*dst = strdup(src);
|
2023-08-25 11:30:16 +03:00
|
|
|
return *dst != NULL;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static void output_handle_geometry(void* data, struct wl_output* wl_output, int x, int y,
|
|
|
|
int physical_width, int physical_height, int subpixel,
|
|
|
|
const char* make, const char* model, int transform)
|
2016-01-18 17:55:33 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
UwacOutput* output = data;
|
2023-08-25 11:30:16 +03:00
|
|
|
assert(output);
|
2016-01-18 17:55:33 +03:00
|
|
|
|
2020-04-18 00:29:29 +03:00
|
|
|
output->position.x = x;
|
|
|
|
output->position.y = y;
|
2016-01-18 17:55:33 +03:00
|
|
|
output->transform = transform;
|
|
|
|
|
2023-08-25 11:30:16 +03:00
|
|
|
if (!dupstr(&output->make, make))
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
assert(uwacErrorHandler(output->display, UWAC_ERROR_NOMEMORY, "%s: unable to strdup make\n",
|
2021-06-18 11:01:33 +03:00
|
|
|
__func__));
|
2016-01-18 17:55:33 +03:00
|
|
|
}
|
|
|
|
|
2023-08-25 11:30:16 +03:00
|
|
|
if (!dupstr(&output->model, model))
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
assert(uwacErrorHandler(output->display, UWAC_ERROR_NOMEMORY,
|
2021-06-18 11:01:33 +03:00
|
|
|
"%s: unable to strdup model\n", __func__));
|
2016-01-18 17:55:33 +03:00
|
|
|
}
|
2019-01-25 17:38:56 +03:00
|
|
|
|
|
|
|
UwacEvent* event = UwacDisplayNewEvent(output->display, UWAC_EVENT_OUTPUT_GEOMETRY);
|
|
|
|
event->output_geometry.output = output;
|
|
|
|
event->output_geometry.x = x;
|
|
|
|
event->output_geometry.y = y;
|
|
|
|
event->output_geometry.physical_width = physical_width;
|
|
|
|
event->output_geometry.physical_height = physical_height;
|
|
|
|
event->output_geometry.subpixel = subpixel;
|
|
|
|
event->output_geometry.make = output->make;
|
|
|
|
event->output_geometry.model = output->model;
|
|
|
|
event->output_geometry.transform = transform;
|
2016-01-18 17:55:33 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static void output_handle_done(void* data, struct wl_output* wl_output)
|
2016-01-18 17:55:33 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
UwacOutput* output = data;
|
2023-08-25 11:30:16 +03:00
|
|
|
assert(output);
|
2016-01-18 17:55:33 +03:00
|
|
|
|
|
|
|
output->doneReceived = true;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static void output_handle_scale(void* data, struct wl_output* wl_output, int32_t scale)
|
2016-01-18 17:55:33 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
UwacOutput* output = data;
|
2023-08-25 11:30:16 +03:00
|
|
|
assert(output);
|
2016-01-18 17:55:33 +03:00
|
|
|
|
2024-01-11 09:39:01 +03:00
|
|
|
output->scale = scale;
|
|
|
|
if (scale > output->display->actual_scale)
|
|
|
|
output->display->actual_scale = scale;
|
2016-01-18 17:55:33 +03:00
|
|
|
}
|
|
|
|
|
2023-08-25 11:30:16 +03:00
|
|
|
static void output_handle_name(void* data, struct wl_output* wl_output, const char* name)
|
|
|
|
{
|
|
|
|
UwacOutput* output = data;
|
|
|
|
assert(output);
|
|
|
|
|
|
|
|
if (!dupstr(&output->name, name))
|
|
|
|
{
|
|
|
|
assert(uwacErrorHandler(output->display, UWAC_ERROR_NOMEMORY, "%s: unable to strdup make\n",
|
|
|
|
__func__));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void output_handle_description(void* data, struct wl_output* wl_output,
|
|
|
|
const char* description)
|
|
|
|
{
|
|
|
|
UwacOutput* output = data;
|
|
|
|
assert(output);
|
|
|
|
|
|
|
|
if (!dupstr(&output->description, description))
|
|
|
|
{
|
|
|
|
assert(uwacErrorHandler(output->display, UWAC_ERROR_NOMEMORY, "%s: unable to strdup make\n",
|
|
|
|
__func__));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static void output_handle_mode(void* data, struct wl_output* wl_output, uint32_t flags, int width,
|
|
|
|
int height, int refresh)
|
2016-01-18 17:55:33 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
UwacOutput* output = data;
|
2023-08-25 11:30:16 +03:00
|
|
|
assert(output);
|
2019-11-06 17:24:51 +03:00
|
|
|
// UwacDisplay *display = output->display;
|
2016-01-18 17:55:33 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (output->doneNeeded && output->doneReceived)
|
|
|
|
{
|
2016-01-18 17:55:33 +03:00
|
|
|
/* TODO: we should clear the mode list */
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (flags & WL_OUTPUT_MODE_CURRENT)
|
|
|
|
{
|
2016-01-18 17:55:33 +03:00
|
|
|
output->resolution.width = width;
|
|
|
|
output->resolution.height = height;
|
2019-11-06 17:24:51 +03:00
|
|
|
/* output->allocation.width = width;
|
|
|
|
output->allocation.height = height;
|
|
|
|
if (display->output_configure_handler)
|
|
|
|
(*display->output_configure_handler)(
|
|
|
|
output, display->user_data);*/
|
2016-01-18 17:55:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-25 11:30:16 +03:00
|
|
|
static const struct wl_output_listener output_listener = {
|
|
|
|
output_handle_geometry, output_handle_mode, output_handle_done,
|
|
|
|
output_handle_scale, output_handle_name, output_handle_description
|
|
|
|
};
|
2016-01-18 17:55:33 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
UwacOutput* UwacCreateOutput(UwacDisplay* d, uint32_t id, uint32_t version)
|
|
|
|
{
|
2023-08-25 11:30:16 +03:00
|
|
|
UwacOutput* o = xzalloc(sizeof *o);
|
2016-01-18 17:55:33 +03:00
|
|
|
if (!o)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
o->display = d;
|
|
|
|
o->server_output_id = id;
|
|
|
|
o->doneNeeded = (version > 1);
|
|
|
|
o->doneReceived = false;
|
2019-11-06 17:24:51 +03:00
|
|
|
o->output = wl_registry_bind(d->registry, id, &wl_output_interface,
|
|
|
|
min(TARGET_OUTPUT_INTERFACE, version));
|
2016-01-18 17:55:33 +03:00
|
|
|
wl_output_add_listener(o->output, &output_listener, o);
|
|
|
|
|
|
|
|
wl_list_insert(d->outputs.prev, &o->link);
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
int UwacDestroyOutput(UwacOutput* output)
|
|
|
|
{
|
2023-08-25 11:30:16 +03:00
|
|
|
if (!output)
|
|
|
|
return UWAC_SUCCESS;
|
|
|
|
|
2016-01-18 17:55:33 +03:00
|
|
|
free(output->make);
|
|
|
|
free(output->model);
|
2023-08-25 11:30:16 +03:00
|
|
|
free(output->name);
|
|
|
|
free(output->description);
|
2016-01-18 17:55:33 +03:00
|
|
|
|
|
|
|
wl_output_destroy(output->output);
|
|
|
|
wl_list_remove(&output->link);
|
|
|
|
free(output);
|
|
|
|
|
|
|
|
return UWAC_SUCCESS;
|
|
|
|
}
|