aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/pointer.c7
-rw-r--r--example/rotation.c7
-rw-r--r--example/shared.c10
-rw-r--r--example/simple.c10
-rw-r--r--example/tablet.c18
-rw-r--r--example/touch.c16
6 files changed, 34 insertions, 34 deletions
diff --git a/example/pointer.c b/example/pointer.c
index ddb665a1..8735c61e 100644
--- a/example/pointer.c
+++ b/example/pointer.c
@@ -110,22 +110,21 @@ int main(int argc, char *argv[]) {
.default_color = { 0.25f, 0.25f, 0.25f, 1 },
.clear_color = { 0.25f, 0.25f, 0.25f, 1 }
};
- struct compositor_state compositor;
-
- compositor_init(&compositor);
+ struct compositor_state compositor = { 0 };
+ compositor.data = &state;
compositor.output_add_cb = handle_output_add;
compositor.output_frame_cb = handle_output_frame;
compositor.keyboard_key_cb = handle_keyboard_key;
compositor.pointer_motion_cb = handle_pointer_motion;
compositor.pointer_button_cb = handle_pointer_button;
compositor.pointer_axis_cb = handle_pointer_axis;
+ compositor_init(&compositor);
state.renderer = wlr_gles3_renderer_init();
state.cat_texture = wlr_render_surface_init(state.renderer);
wlr_surface_attach_pixels(state.cat_texture, GL_RGBA,
cat_tex.width, cat_tex.height, cat_tex.pixel_data);
- compositor.data = &state;
compositor_run(&compositor);
wlr_surface_destroy(state.cat_texture);
diff --git a/example/rotation.c b/example/rotation.c
index f4b7625e..d7b6b169 100644
--- a/example/rotation.c
+++ b/example/rotation.c
@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <time.h>
#include <string.h>
+#include <strings.h>
#include <unistd.h>
#include <wayland-server.h>
#include <wayland-server-protocol.h>
@@ -193,22 +194,22 @@ static void parse_args(int argc, char *argv[], struct wl_list *config) {
int main(int argc, char *argv[]) {
struct sample_state state = { 0 };
- struct compositor_state compositor;
wl_list_init(&state.config);
parse_args(argc, argv, &state.config);
- compositor_init(&compositor);
+ struct compositor_state compositor = { 0 };
+ compositor.data = &state;
compositor.output_add_cb = handle_output_add;
compositor.output_remove_cb = handle_output_remove;
compositor.output_frame_cb = handle_output_frame;
compositor.keyboard_key_cb = handle_keyboard_key;
+ compositor_init(&compositor);
state.renderer = wlr_gles3_renderer_init();
state.cat_texture = wlr_render_surface_init(state.renderer);
wlr_surface_attach_pixels(state.cat_texture, GL_RGBA,
cat_tex.width, cat_tex.height, cat_tex.pixel_data);
- compositor.data = &state;
compositor_run(&compositor);
wlr_surface_destroy(state.cat_texture);
diff --git a/example/shared.c b/example/shared.c
index be1bdee7..6af3042b 100644
--- a/example/shared.c
+++ b/example/shared.c
@@ -383,7 +383,9 @@ static void output_add_notify(struct wl_listener *listener, void *data) {
fprintf(stderr, "Output '%s' added\n", output->name);
fprintf(stderr, "%s %s %"PRId32"mm x %"PRId32"mm\n", output->make, output->model,
output->phys_width, output->phys_height);
- wlr_output_set_mode(output, output->modes->items[0]);
+ if (output->modes->length > 0) {
+ wlr_output_set_mode(output, output->modes->items[0]);
+ }
struct output_state *ostate = calloc(1, sizeof(struct output_state));
clock_gettime(CLOCK_MONOTONIC, &ostate->last_frame);
ostate->output = output;
@@ -418,8 +420,6 @@ static void output_remove_notify(struct wl_listener *listener, void *data) {
}
void compositor_init(struct compositor_state *state) {
- memset(state, 0, sizeof(struct compositor_state));
-
state->display = wl_display_create();
state->event_loop = wl_display_get_event_loop(state->display);
state->session = wlr_session_start(state->display);
@@ -457,14 +457,14 @@ void compositor_init(struct compositor_state *state) {
state->backend = wlr;
clock_gettime(CLOCK_MONOTONIC, &state->last_frame);
-}
-void compositor_run(struct compositor_state *state) {
if (!wlr_backend_init(state->backend)) {
fprintf(stderr, "Failed to initialize backend\n");
exit(1);
}
+}
+void compositor_run(struct compositor_state *state) {
while (!state->exit) {
wl_event_loop_dispatch(state->event_loop, 0);
}
diff --git a/example/simple.c b/example/simple.c
index 5a5a1300..f3a66db9 100644
--- a/example/simple.c
+++ b/example/simple.c
@@ -50,11 +50,11 @@ int main() {
.color = { 1.0, 0.0, 0.0 },
.dec = 0,
};
- struct compositor_state compositor;
-
+ struct compositor_state compositor = { 0,
+ .data = &state,
+ .output_frame_cb = handle_output_frame,
+ .keyboard_key_cb = handle_keyboard_key,
+ };
compositor_init(&compositor);
- compositor.output_frame_cb = handle_output_frame;
- compositor.keyboard_key_cb = handle_keyboard_key;
- compositor.data = &state;
compositor_run(&compositor);
}
diff --git a/example/tablet.c b/example/tablet.c
index 3c5b583e..6be006f0 100644
--- a/example/tablet.c
+++ b/example/tablet.c
@@ -145,19 +145,19 @@ int main(int argc, char *argv[]) {
.tool_color = { 1, 1, 1, 1 },
.pad_color = { 0.75, 0.75, 0.75, 1.0 }
};
- struct compositor_state compositor;
-
+ struct compositor_state compositor = { 0,
+ .data = &state,
+ .output_frame_cb = handle_output_frame,
+ .keyboard_key_cb = handle_keyboard_key,
+ .tool_axis_cb = handle_tool_axis,
+ .tool_proximity_cb = handle_tool_proximity,
+ .tool_button_cb = handle_tool_button,
+ .pad_button_cb = handle_pad_button,
+ };
compositor_init(&compositor);
- compositor.output_frame_cb = handle_output_frame;
- compositor.keyboard_key_cb = handle_keyboard_key;
- compositor.tool_axis_cb = handle_tool_axis;
- compositor.tool_proximity_cb = handle_tool_proximity;
- compositor.tool_button_cb = handle_tool_button;
- compositor.pad_button_cb = handle_pad_button;
state.renderer = wlr_gles3_renderer_init();
- compositor.data = &state;
compositor_run(&compositor);
wlr_renderer_destroy(state.renderer);
diff --git a/example/touch.c b/example/touch.c
index 46eddf62..1b4233bb 100644
--- a/example/touch.c
+++ b/example/touch.c
@@ -100,21 +100,21 @@ int main(int argc, char *argv[]) {
struct sample_state state = {
.touch_points = list_create()
};
- struct compositor_state compositor;
-
+ struct compositor_state compositor = { 0,
+ .data = &state,
+ .output_frame_cb = handle_output_frame,
+ .keyboard_key_cb = handle_keyboard_key,
+ .touch_down_cb = handle_touch_down,
+ .touch_up_cb = handle_touch_up,
+ .touch_motion_cb = handle_touch_motion,
+ };
compositor_init(&compositor);
- compositor.output_frame_cb = handle_output_frame;
- compositor.keyboard_key_cb = handle_keyboard_key;
- compositor.touch_down_cb = handle_touch_down;
- compositor.touch_up_cb = handle_touch_up;
- compositor.touch_motion_cb = handle_touch_motion;
state.renderer = wlr_gles3_renderer_init();
state.cat_texture = wlr_render_surface_init(state.renderer);
wlr_surface_attach_pixels(state.cat_texture, GL_RGBA,
cat_tex.width, cat_tex.height, cat_tex.pixel_data);
- compositor.data = &state;
compositor_run(&compositor);
wlr_surface_destroy(state.cat_texture);