aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/pointer.c36
-rw-r--r--example/rotation.c4
-rw-r--r--example/simple.c4
-rw-r--r--example/tablet.c2
-rw-r--r--example/touch.c5
5 files changed, 28 insertions, 23 deletions
diff --git a/example/pointer.c b/example/pointer.c
index 8dba5454..c7518841 100644
--- a/example/pointer.c
+++ b/example/pointer.c
@@ -21,9 +21,7 @@
#include "cat.h"
struct sample_state {
- struct wlr_renderer *renderer;
- struct wlr_surface *cat_texture;
- int cur_x, cur_y;
+ double cur_x, cur_y;
float default_color[4];
float clear_color[4];
};
@@ -33,18 +31,13 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
struct sample_state *sample = state->data;
struct wlr_output *wlr_output = output->output;
- wlr_renderer_begin(sample->renderer, wlr_output);
+ wlr_output_make_current(wlr_output);
+
glClearColor(sample->clear_color[0], sample->clear_color[1],
sample->clear_color[2], sample->clear_color[3]);
glClear(GL_COLOR_BUFFER_BIT);
- float matrix[16];
- wlr_surface_get_matrix(sample->cat_texture, &matrix,
- &wlr_output->transform_matrix, sample->cur_x, sample->cur_y);
- wlr_render_with_matrix(sample->renderer,
- sample->cat_texture, &matrix);
-
- wlr_renderer_end(sample->renderer);
+ wlr_output_swap_buffers(wlr_output);
}
static void handle_pointer_motion(struct pointer_state *pstate,
@@ -52,6 +45,11 @@ static void handle_pointer_motion(struct pointer_state *pstate,
struct sample_state *state = pstate->compositor->data;
state->cur_x += d_x;
state->cur_y += d_y;
+
+ struct output_state *output;
+ wl_list_for_each(output, &pstate->compositor->outputs, link) {
+ wlr_output_move_cursor(output->output, state->cur_x, state->cur_y);
+ }
}
static void handle_pointer_motion_absolute(struct pointer_state *pstate,
@@ -59,6 +57,11 @@ static void handle_pointer_motion_absolute(struct pointer_state *pstate,
struct sample_state *state = pstate->compositor->data;
state->cur_x = x;
state->cur_y = y;
+
+ struct output_state *output;
+ wl_list_for_each(output, &pstate->compositor->outputs, link) {
+ wlr_output_move_cursor(output->output, state->cur_x, state->cur_y);
+ }
}
static void handle_pointer_button(struct pointer_state *pstate,
@@ -95,9 +98,8 @@ static void handle_pointer_axis(struct pointer_state *pstate,
static void handle_output_add(struct output_state *ostate) {
struct wlr_output *wlr_output = ostate->output;
- int width = 16, height = 16;
if (!wlr_output_set_cursor(wlr_output, cat_tex.pixel_data,
- width * 4, width, height)) {
+ cat_tex.width, cat_tex.width, cat_tex.height)) {
wlr_log(L_DEBUG, "Failed to set hardware cursor");
return;
}
@@ -121,13 +123,5 @@ int main(int argc, char *argv[]) {
compositor.pointer_axis_cb = handle_pointer_axis;
compositor_init(&compositor);
- state.renderer = wlr_gles2_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_run(&compositor);
-
- wlr_surface_destroy(state.cat_texture);
- wlr_renderer_destroy(state.renderer);
}
diff --git a/example/rotation.c b/example/rotation.c
index b8c43d4c..2dd148d0 100644
--- a/example/rotation.c
+++ b/example/rotation.c
@@ -46,6 +46,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
int32_t width, height;
wlr_output_effective_resolution(wlr_output, &width, &height);
+ wlr_output_make_current(wlr_output);
wlr_renderer_begin(sample->renderer, wlr_output);
float matrix[16];
@@ -59,6 +60,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
}
wlr_renderer_end(sample->renderer);
+ wlr_output_swap_buffers(wlr_output);
long ms = (ts->tv_sec - output->last_frame.tv_sec) * 1000 +
(ts->tv_nsec - output->last_frame.tv_nsec) / 1000000;
@@ -205,7 +207,7 @@ int main(int argc, char *argv[]) {
state.renderer = wlr_gles2_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);
+ cat_tex.width, cat_tex.width, cat_tex.height, cat_tex.pixel_data);
compositor_run(&compositor);
diff --git a/example/simple.c b/example/simple.c
index 4bbdf399..45cb2b93 100644
--- a/example/simple.c
+++ b/example/simple.c
@@ -34,8 +34,12 @@ void handle_output_frame(struct output_state *output, struct timespec *ts) {
sample->dec = inc;
}
+ wlr_output_make_current(output->output);
+
glClearColor(sample->color[0], sample->color[1], sample->color[2], 1.0);
glClear(GL_COLOR_BUFFER_BIT);
+
+ wlr_output_swap_buffers(output->output);
}
int main() {
diff --git a/example/tablet.c b/example/tablet.c
index 0343bd0a..d7f7d042 100644
--- a/example/tablet.c
+++ b/example/tablet.c
@@ -41,6 +41,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
int32_t width, height;
wlr_output_effective_resolution(wlr_output, &width, &height);
+ wlr_output_make_current(wlr_output);
wlr_renderer_begin(sample->renderer, wlr_output);
float matrix[16], view[16];
@@ -74,6 +75,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
}
wlr_renderer_end(sample->renderer);
+ wlr_output_swap_buffers(wlr_output);
}
static void handle_tool_axis(struct tablet_tool_state *tstate,
diff --git a/example/touch.c b/example/touch.c
index 29380ed4..aca86739 100644
--- a/example/touch.c
+++ b/example/touch.c
@@ -38,6 +38,8 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
int32_t width, height;
wlr_output_effective_resolution(wlr_output, &width, &height);
+
+ wlr_output_make_current(wlr_output);
wlr_renderer_begin(sample->renderer, wlr_output);
float matrix[16];
@@ -52,6 +54,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
}
wlr_renderer_end(sample->renderer);
+ wlr_output_swap_buffers(wlr_output);
}
static void handle_touch_down(struct touch_state *tstate, int32_t slot,
@@ -104,7 +107,7 @@ int main(int argc, char *argv[]) {
state.renderer = wlr_gles2_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);
+ cat_tex.width, cat_tex.width, cat_tex.height, cat_tex.pixel_data);
compositor_run(&compositor);