parent
e65ca967f9
commit
792d535225
@ -0,0 +1,93 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wayland-client.h>
|
||||
#include <wlr/types.h>
|
||||
#include "types.h"
|
||||
#include "backend/wayland.h"
|
||||
#include "common/log.h"
|
||||
|
||||
// TODO
|
||||
static void wlr_wl_output_enable(struct wlr_output_state *output, bool enable) {
|
||||
}
|
||||
|
||||
static bool wlr_wl_output_set_mode(struct wlr_output_state *output,
|
||||
struct wlr_output_mode *mode) {
|
||||
output->output->current_mode = mode;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void wlr_wl_output_transform(struct wlr_output_state *output,
|
||||
enum wl_output_transform transform) {
|
||||
}
|
||||
|
||||
static bool wlr_wl_output_set_cursor(struct wlr_output_state *output,
|
||||
const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool wlr_wl_output_move_cursor(struct wlr_output_state *output,
|
||||
int x, int y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static void wlr_wl_output_destroy(struct wlr_output_state *output) {
|
||||
// TODO: free egl surface
|
||||
wl_shell_surface_destroy(output->shell_surface);
|
||||
wl_surface_destroy(output->surface);
|
||||
free(output);
|
||||
}
|
||||
|
||||
static struct wlr_output_impl output_impl = {
|
||||
.enable = wlr_wl_output_enable,
|
||||
.set_mode = wlr_wl_output_set_mode,
|
||||
.transform = wlr_wl_output_transform,
|
||||
.set_cursor = wlr_wl_output_set_cursor,
|
||||
.move_cursor = wlr_wl_output_move_cursor,
|
||||
.destroy = wlr_wl_output_destroy,
|
||||
};
|
||||
|
||||
struct wlr_output *wlr_wl_output_create(struct wlr_backend_state* backend,
|
||||
size_t id) {
|
||||
// TODO: dont hardcode stuff like size
|
||||
static unsigned int width = 1100;
|
||||
static unsigned int height = 720;
|
||||
|
||||
struct wlr_output_state *ostate;
|
||||
if (!(ostate = calloc(sizeof(struct wlr_output_state), 1))) {
|
||||
wlr_log(L_ERROR, "Failed to allocate wlr_output_state");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_output *wlr_output = wlr_output_create(&output_impl, ostate);
|
||||
if (!wlr_output) {
|
||||
free(ostate);
|
||||
wlr_log_errno(L_ERROR, "Allocation failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wlr_output->width = width;
|
||||
wlr_output->height = height;
|
||||
wlr_output->scale = 1;
|
||||
strncpy(wlr_output->make, "wayland-output", sizeof(wlr_output->make));
|
||||
strncpy(wlr_output->model, "wayland-output", sizeof(wlr_output->model));
|
||||
strncpy(wlr_output->name, "wayland-output", sizeof(wlr_output->name));
|
||||
|
||||
struct wlr_output_mode mode = {
|
||||
.width = width,
|
||||
.height = height,
|
||||
.refresh = 60,
|
||||
.flags = 0,
|
||||
};
|
||||
list_add(wlr_output->modes, &mode);
|
||||
|
||||
ostate->id = id;
|
||||
ostate->output = wlr_output;
|
||||
ostate->surface = wl_compositor_create_surface(backend->compositor);
|
||||
ostate->shell_surface = wl_shell_get_shell_surface(backend->shell, ostate->surface);
|
||||
ostate->egl_window = wl_egl_window_create(ostate->surface, width, height);
|
||||
ostate->egl_surface = wlr_egl_create_surface(&backend->egl, ostate->egl_window);
|
||||
|
||||
wl_signal_emit(&backend->backend->events.output_add, wlr_output);
|
||||
return wlr_output;
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
#define _XOPEN_SOURCE 500
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <wayland-client.h>
|
||||
#include <wlr/types.h>
|
||||
#include "types.h"
|
||||
#include "backend/wayland.h"
|
||||
#include "common/log.h"
|
||||
|
||||
static void wl_output_handle_mode(void *data, struct wl_output *wl_output,
|
||||
uint32_t flags, int32_t width, int32_t height, int32_t refresh) {
|
||||
struct wlr_output *output = data;
|
||||
assert(output->state->output == wl_output);
|
||||
struct wlr_output_mode *mode;
|
||||
if (!(mode = calloc(sizeof(struct wlr_output_mode), 1))) {
|
||||
wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
mode->flags = flags;
|
||||
mode->width = width;
|
||||
mode->height = height;
|
||||
mode->refresh = refresh;
|
||||
list_add(output->modes, mode);
|
||||
|
||||
wlr_log(L_DEBUG, "Got mode for output %p: %dx%d @ %.2fHz%s%s",
|
||||
wl_output, width, height, refresh / 1000.0,
|
||||
(flags & WL_OUTPUT_MODE_PREFERRED) ? " (preferred)" : "",
|
||||
(flags & WL_OUTPUT_MODE_CURRENT) ? " (current)" : "");
|
||||
}
|
||||
|
||||
static void wl_output_handle_geometry(void *data, struct wl_output *wl_output,
|
||||
int32_t x, int32_t y, int32_t physical_width, int32_t physical_height,
|
||||
int32_t subpixel, const char *make, const char *model, int32_t transform) {
|
||||
struct wlr_output *output = data;
|
||||
assert(output->state->output == wl_output);
|
||||
|
||||
// TODO
|
||||
// output->x = x;
|
||||
// output->y = y;
|
||||
|
||||
output->phys_width = physical_width;
|
||||
output->phys_height = physical_height;
|
||||
output->subpixel = subpixel;
|
||||
strncpy(output->make, make, sizeof(output->make));
|
||||
strncpy(output->model, model, sizeof(output->model));
|
||||
output->transform = transform;
|
||||
wlr_log(L_DEBUG, "Got info for output %p %dx%d (%dmm x %dmm) %s %s",
|
||||
wl_output, (int)x, (int)y, (int)physical_width, (int)physical_height,
|
||||
make, model);
|
||||
}
|
||||
|
||||
static void wl_output_handle_scale(void *data, struct wl_output *wl_output, int32_t factor) {
|
||||
struct wlr_output *output = data;
|
||||
assert(output->state->output == wl_output);
|
||||
output->scale = factor;
|
||||
wlr_log(L_DEBUG, "Got scale factor for output %p: %d", wl_output, factor);
|
||||
}
|
||||
|
||||
static void wl_output_handle_done(void *data, struct wl_output *wl_output) {
|
||||
// TODO: notify of changes? Probably not necessary for this backend
|
||||
}
|
||||
|
||||
const struct wl_output_listener output_listener = {
|
||||
.mode = wl_output_handle_mode,
|
||||
.geometry = wl_output_handle_geometry,
|
||||
.scale = wl_output_handle_scale,
|
||||
.done = wl_output_handle_done
|
||||
};
|
Loading…
Reference in new issue