-
-
Save djpohly/28ba17f484e874ffda5a4184e2bc48ed to your computer and use it in GitHub Desktop.
MWE for another scene/output/damage bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Move the (invisible) mouse cursor to generate redraws. | |
* Click to exit. | |
* | |
* BROKEN defined: | |
* 1. wlr_output_commit | |
* 2. wlr_scene_output_create | |
* BROKEN undef'd: | |
* 1. wlr_scene_output_create | |
* 2. wlr_output_commit | |
*/ | |
#define BROKEN | |
#define _POSIX_C_SOURCE 200809L | |
#include <stdlib.h> | |
#include <wayland-server-core.h> | |
#include <wlr/backend.h> | |
#include <wlr/types/wlr_cursor.h> | |
#include <wlr/types/wlr_input_device.h> | |
#include <wlr/types/wlr_output.h> | |
#include <wlr/types/wlr_output_layout.h> | |
#include <wlr/types/wlr_pointer.h> | |
#include <wlr/types/wlr_scene.h> | |
struct monitor { | |
struct wlr_output *wlr_output; | |
struct wlr_scene_output *scene_output; | |
struct wl_listener frame; | |
}; | |
/* variables */ | |
static struct wl_display *dpy; | |
static struct wlr_scene *scene; | |
static struct wlr_output_layout *output_layout; | |
static struct wlr_cursor *cursor; | |
/* function implementations */ | |
static void handle_frame(struct wl_listener *listener, void *data) | |
{ | |
struct monitor *m = wl_container_of(listener, m, frame); | |
wlr_scene_output_commit(m->scene_output); | |
} | |
static void handle_new_output(struct wl_listener *listener, void *data) | |
{ | |
struct monitor *m = calloc(1, sizeof(*m)); | |
m->wlr_output = data; | |
m->frame.notify = handle_frame; | |
wl_signal_add(&m->wlr_output->events.frame, &m->frame); | |
/* Place all outputs at (0, 0) with default mode */ | |
wlr_output_set_mode(m->wlr_output, wlr_output_preferred_mode(m->wlr_output)); | |
wlr_output_layout_add(output_layout, m->wlr_output, 0, 0); | |
wlr_output_enable(m->wlr_output, 1); | |
#ifdef BROKEN | |
wlr_output_commit(m->wlr_output); | |
m->scene_output = wlr_scene_output_create(scene, m->wlr_output); | |
#else | |
m->scene_output = wlr_scene_output_create(scene, m->wlr_output); | |
wlr_output_commit(m->wlr_output); | |
#endif | |
} | |
static void handle_new_input(struct wl_listener *listener, void *data) | |
{ | |
struct wlr_input_device *device = data; | |
if (device->type == WLR_INPUT_DEVICE_POINTER) | |
wlr_cursor_attach_input_device(cursor, device); | |
} | |
static void handle_cursor_button(struct wl_listener *listener, void *data) | |
{ | |
struct wlr_event_pointer_button *event = data; | |
if (event->state == WLR_BUTTON_RELEASED) | |
wl_display_terminate(dpy); | |
} | |
static void handle_cursor_motion_absolute(struct wl_listener *listener, void *data) | |
{ | |
struct wlr_event_pointer_motion_absolute *event = data; | |
wlr_cursor_warp_absolute(cursor, event->device, event->x, event->y); | |
} | |
static void handle_cursor_motion(struct wl_listener *listener, void *data) | |
{ | |
struct wlr_event_pointer_motion *event = data; | |
wlr_cursor_move(cursor, event->device, event->delta_x, event->delta_y); | |
} | |
/* Global listeners */ | |
static struct wl_listener new_output = {.notify = handle_new_output}; | |
static struct wl_listener new_input = {.notify = handle_new_input}; | |
static struct wl_listener cursor_button = {.notify = handle_cursor_button}; | |
static struct wl_listener cursor_motion = {.notify = handle_cursor_motion}; | |
static struct wl_listener cursor_motion_absolute = {.notify = handle_cursor_motion_absolute}; | |
int | |
main(int argc, char *argv[]) | |
{ | |
struct wlr_backend *backend; | |
dpy = wl_display_create(); | |
backend = wlr_backend_autocreate(dpy); | |
output_layout = wlr_output_layout_create(); | |
cursor = wlr_cursor_create(); | |
scene = wlr_scene_create(); | |
/* Scene: one rectangle */ | |
wlr_scene_rect_create(&scene->node, 10, 30, (float[]) {.8, .8, 1, 1}); | |
/* Cursor (easy way to generate some redraws) */ | |
wlr_cursor_attach_output_layout(cursor, output_layout); | |
/* Events */ | |
wl_signal_add(&backend->events.new_output, &new_output); | |
wl_signal_add(&backend->events.new_input, &new_input); | |
wl_signal_add(&cursor->events.motion, &cursor_motion); | |
wl_signal_add(&cursor->events.motion_absolute, &cursor_motion_absolute); | |
wl_signal_add(&cursor->events.button, &cursor_button); | |
wlr_backend_start(backend); | |
wl_display_run(dpy); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment