wscreensaver: Use a widget and a redraw handler

dev
Kristian Høgsberg 13 years ago
parent 441338cb75
commit 5e41f09752
  1. 35
      clients/wscreensaver.c
  2. 1
      clients/wscreensaver.h

@ -64,11 +64,28 @@ struct wscreensaver {
}; };
static void static void
draw_instance(struct ModeInfo *mi) frame_callback(void *data, struct wl_callback *callback, uint32_t time)
{
struct ModeInfo *mi = data;
window_schedule_redraw(mi->window);
if (callback)
wl_callback_destroy(callback);
}
static const struct wl_callback_listener listener = {
frame_callback
};
static void
redraw_handler(struct widget *widget, void *data)
{ {
struct ModeInfo *mi = data;
struct wscreensaver *wscr = mi->priv; struct wscreensaver *wscr = mi->priv;
struct rectangle drawarea; struct rectangle drawarea;
struct rectangle winarea; struct rectangle winarea;
struct wl_callback *callback;
int bottom; int bottom;
mi->swap_buffers = 0; mi->swap_buffers = 0;
@ -101,20 +118,6 @@ draw_instance(struct ModeInfo *mi)
fprintf(stderr, "%s: swapBuffers not called\n", progname); fprintf(stderr, "%s: swapBuffers not called\n", progname);
display_release_window_surface(wscr->display, mi->window); display_release_window_surface(wscr->display, mi->window);
}
static void
frame_callback(void *data, struct wl_callback *callback, uint32_t time)
{
struct ModeInfo *mi = data;
static const struct wl_callback_listener listener = {
frame_callback
};
draw_instance(mi);
if (callback)
wl_callback_destroy(callback);
callback = wl_surface_frame(window_get_wl_surface(mi->window)); callback = wl_surface_frame(window_get_wl_surface(mi->window));
wl_callback_add_listener(callback, &listener, mi); wl_callback_add_listener(callback, &listener, mi);
@ -185,6 +188,8 @@ create_modeinfo(struct wscreensaver *wscr, struct window *window)
mi->eglctx = EGL_NO_CONTEXT; mi->eglctx = EGL_NO_CONTEXT;
mi->window = window; mi->window = window;
mi->widget = window_add_widget(window, mi);
widget_set_redraw_handler(mi->widget, redraw_handler);
mi->instance_number = instance++; /* XXX */ mi->instance_number = instance++; /* XXX */
mi->width = drawarea.width; mi->width = drawarea.width;

@ -36,6 +36,7 @@ struct ModeInfo {
int swap_buffers; int swap_buffers;
struct window *window; struct window *window;
struct widget *widget;
int instance_number; int instance_number;
unsigned width; unsigned width;

Loading…
Cancel
Save