Consolidate redraw scheduling in window.c

dev
Kristian Høgsberg 14 years ago
parent 0953162db8
commit 80d746f6e3
  1. 32
      clients/image.c
  2. 35
      clients/terminal.c
  3. 38
      clients/view.c
  4. 34
      clients/window.c
  5. 7
      clients/window.h

@ -46,9 +46,6 @@ struct image {
struct window *window;
struct display *display;
uint32_t key;
gboolean redraw_scheduled;
gchar *filename;
};
@ -149,8 +146,6 @@ image_draw(struct image *image)
cairo_t *cr;
cairo_surface_t *wsurface, *surface;
image->redraw_scheduled = 0;
window_draw(image->window);
window_get_child_rectangle(image->window, &rectangle);
@ -186,31 +181,12 @@ image_draw(struct image *image)
cairo_surface_destroy(surface);
}
static gboolean
image_idle_redraw(void *data)
{
struct image *image = data;
image_draw(image);
return FALSE;
}
static void
image_schedule_redraw(struct image *image)
{
if (!image->redraw_scheduled) {
image->redraw_scheduled = 1;
g_idle_add(image_idle_redraw, image);
}
}
static void
resize_handler(struct window *window, void *data)
redraw_handler(struct window *window, void *data)
{
struct image *image = data;
image_schedule_redraw(image);
image_draw(image);
}
static void
@ -219,7 +195,7 @@ keyboard_focus_handler(struct window *window,
{
struct image *image = data;
image_schedule_redraw(image);
window_schedule_redraw(image->window);
}
static struct image *
@ -247,7 +223,7 @@ image_create(struct display *display, uint32_t key, const char *filename)
* allocation scheme here. Or maybe just a real toolkit. */
image->key = key + 100;
window_set_resize_handler(image->window, resize_handler, image);
window_set_redraw_handler(image->window, redraw_handler, image);
window_set_keyboard_focus_handler(image->window, keyboard_focus_handler, image);
image_draw(image);

@ -50,7 +50,6 @@ static int option_fullscreen;
struct terminal {
struct window *window;
struct display *display;
int redraw_scheduled;
char *data;
int width, height, start, row, column;
int fd, master;
@ -219,15 +218,12 @@ terminal_draw(struct terminal *terminal)
window_commit(terminal->window, 0);
}
static gboolean
idle_redraw(void *data)
static void
redraw_handler(struct window *window, void *data)
{
struct terminal *terminal = data;
terminal_draw(terminal);
terminal->redraw_scheduled = 0;
return FALSE;
}
#define STATE_NORMAL 0
@ -236,15 +232,6 @@ idle_redraw(void *data)
static void
terminal_data(struct terminal *terminal, const char *data, size_t length);
static void
terminal_schedule_redraw(struct terminal *terminal)
{
if (!terminal->redraw_scheduled) {
g_idle_add(idle_redraw, terminal);
terminal->redraw_scheduled = 1;
}
}
static void
handle_escape(struct terminal *terminal)
{
@ -396,15 +383,7 @@ terminal_data(struct terminal *terminal, const char *data, size_t length)
}
}
terminal_schedule_redraw(terminal);
}
static void
resize_handler(struct window *window, void *data)
{
struct terminal *terminal = data;
terminal_schedule_redraw(terminal);
window_schedule_redraw(terminal->window);
}
static void
@ -420,7 +399,7 @@ key_handler(struct window *window, uint32_t key, uint32_t unicode,
break;
terminal->fullscreen ^= 1;
window_set_fullscreen(window, terminal->fullscreen);
terminal_schedule_redraw(terminal);
window_schedule_redraw(terminal->window);
break;
default:
if (state && unicode)
@ -436,7 +415,7 @@ keyboard_focus_handler(struct window *window,
struct terminal *terminal = data;
terminal->focused = (device != NULL);
terminal_schedule_redraw(terminal);
window_schedule_redraw(terminal->window);
}
static struct terminal *
@ -459,7 +438,8 @@ terminal_create(struct display *display, int fullscreen)
terminal->margin = 5;
window_set_fullscreen(terminal->window, terminal->fullscreen);
window_set_resize_handler(terminal->window, resize_handler, terminal);
window_set_redraw_handler(terminal->window,
redraw_handler, terminal);
window_set_key_handler(terminal->window, key_handler, terminal);
window_set_keyboard_focus_handler(terminal->window,
@ -475,7 +455,6 @@ terminal_create(struct display *display, int fullscreen)
cairo_destroy(cr);
cairo_surface_destroy(surface);
terminal_draw(terminal);
return terminal;

@ -51,8 +51,6 @@ struct view {
struct display *display;
uint32_t key;
gboolean redraw_scheduled;
gchar *filename;
PopplerDocument *document;
int page;
@ -69,8 +67,6 @@ view_draw(struct view *view)
PopplerPage *page;
double width, height, doc_aspect, window_aspect, scale;
view->redraw_scheduled = 0;
window_draw(view->window);
window_get_child_rectangle(view->window, &rectangle);
@ -110,23 +106,12 @@ view_draw(struct view *view)
window_commit(view->window, 0);
}
static gboolean
view_idle_redraw(void *data)
static void
redraw_handler(struct window *window, void *data)
{
struct view *view = data;
view_draw(view);
return FALSE;
}
static void
view_schedule_redraw(struct view *view)
{
if (!view->redraw_scheduled) {
view->redraw_scheduled = 1;
g_idle_add(view_idle_redraw, view);
}
}
static void
@ -141,35 +126,27 @@ key_handler(struct window *window, uint32_t key, uint32_t unicode,
break;
view->fullscreen ^= 1;
window_set_fullscreen(window, view->fullscreen);
view_schedule_redraw(view);
window_schedule_redraw(view->window);
break;
case KEY_SPACE:
case KEY_PAGEDOWN:
if (!state)
break;
view->page++;
view_schedule_redraw(view);
window_schedule_redraw(view->window);
break;
case KEY_BACKSPACE:
case KEY_PAGEUP:
if (!state)
break;
view->page--;
view_schedule_redraw(view);
window_schedule_redraw(view->window);
break;
default:
break;
}
}
static void
resize_handler(struct window *window, void *data)
{
struct view *view = data;
view_schedule_redraw(view);
}
static void
keyboard_focus_handler(struct window *window,
struct wl_input_device *device, void *data)
@ -177,7 +154,7 @@ keyboard_focus_handler(struct window *window,
struct view *view = data;
view->focused = (device != NULL);
view_schedule_redraw(view);
window_schedule_redraw(view->window);
}
static struct view *
@ -206,9 +183,8 @@ view_create(struct display *display, uint32_t key, const char *filename)
/* FIXME: Window uses key 1 for moves, need some kind of
* allocation scheme here. Or maybe just a real toolkit. */
view->key = key + 100;
view->redraw_scheduled = 1;
window_set_resize_handler(view->window, resize_handler, view);
window_set_redraw_handler(view->window, redraw_handler, view);
window_set_key_handler(view->window, key_handler, view);
window_set_keyboard_focus_handler(view->window,
keyboard_focus_handler, view);

@ -68,6 +68,7 @@ struct window {
struct wl_surface *surface;
const char *title;
struct rectangle allocation, saved_allocation, surface_allocation;
int redraw_scheduled;
int minimum_width, minimum_height;
int margin;
int drag_x, drag_y;
@ -83,6 +84,7 @@ struct window {
cairo_surface_t *cairo_surface, *pending_surface;
window_resize_handler_t resize_handler;
window_redraw_handler_t redraw_handler;
window_key_handler_t key_handler;
window_keyboard_focus_handler_t keyboard_focus_handler;
window_acknowledge_handler_t acknowledge_handler;
@ -396,7 +398,8 @@ window_handle_motion(void *data, struct wl_input_device *input_device,
if (window->resize_handler)
(*window->resize_handler)(window,
window->user_data);
else if (window->redraw_handler)
window_schedule_redraw(window);
break;
}
}
@ -685,6 +688,26 @@ window_copy_surface(struct window *window,
cairo_destroy (cr);
}
static gboolean
idle_redraw(void *data)
{
struct window *window = data;
window->redraw_handler(window, window->user_data);
window->redraw_scheduled = 0;
return FALSE;
}
void
window_schedule_redraw(struct window *window)
{
if (!window->redraw_scheduled) {
g_idle_add(idle_redraw, window);
window->redraw_scheduled = 1;
}
}
void
window_set_fullscreen(struct window *window, int fullscreen)
{
@ -711,6 +734,14 @@ window_set_resize_handler(struct window *window,
window->user_data = data;
}
void
window_set_redraw_handler(struct window *window,
window_redraw_handler_t handler, void *data)
{
window->redraw_handler = handler;
window->user_data = data;
}
void
window_set_key_handler(struct window *window,
window_key_handler_t handler, void *data)
@ -804,7 +835,6 @@ display_handle_acknowledge(void *data,
{
struct display *d = data;
struct window *window;
cairo_surface_t *pending;
/* The acknowledge event means that the server processed our
* last commit request and we can now safely free the old

@ -55,6 +55,7 @@ enum {
};
typedef void (*window_resize_handler_t)(struct window *window, void *data);
typedef void (*window_redraw_handler_t)(struct window *window, void *data);
typedef void (*window_frame_handler_t)(struct window *window, uint32_t frame, uint32_t timestamp, void *data);
typedef void (*window_acknowledge_handler_t)(struct window *window, uint32_t key, uint32_t frame, void *data);
typedef void (*window_key_handler_t)(struct window *window, uint32_t key, uint32_t unicode,
@ -80,6 +81,8 @@ void
window_copy_image(struct window *window,
struct rectangle *rectangle,
void *image);
void
window_schedule_redraw(struct window *window);
void
window_move(struct window *window, int32_t x, int32_t y);
@ -99,6 +102,10 @@ window_copy_surface(struct window *window,
void
window_set_fullscreen(struct window *window, int fullscreen);
void
window_set_redraw_handler(struct window *window,
window_redraw_handler_t handler, void *data);
void
window_set_decoration(struct window *window, int decoration);

Loading…
Cancel
Save