From: Mikko Rasa Date: Fri, 11 Dec 2015 16:09:12 +0000 (+0200) Subject: Refresh the screen only when there's no events to process X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=ce67a9ea6b3bbce18ea80a238fa2104afaa3971c;p=geometrycompositor.git Refresh the screen only when there's no events to process --- diff --git a/source/main.c b/source/main.c index 3532854..3f78884 100644 --- a/source/main.c +++ b/source/main.c @@ -42,6 +42,7 @@ typedef struct CompositedScreen CompositedWindow *windows; unsigned nwindows; unsigned windows_capacity; + int dirty; } CompositedScreen; typedef struct Compositor @@ -53,6 +54,7 @@ typedef struct Compositor PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB; PFNGLXBINDTEXIMAGEEXTPROC glXBindTexImageEXT; PFNGLXRELEASETEXIMAGEEXTPROC glXReleaseTexImageEXT; + int dirty; } Compositor; static const char *vshader = @@ -303,6 +305,18 @@ CompositedScreen *find_screen_by_root(Compositor *compositor, Window root) return NULL; } +CompositedScreen *find_screen_by_window(Compositor *compositor, Window w) +{ + unsigned i, j; + + for(i=0; inscreens; ++i) + for(j=0; jscreens[i].nwindows; ++j) + if(compositor->screens[i].windows[j].window==w) + return &compositor->screens[i]; + + return NULL; +} + int initialize_screen(Compositor *compositor, unsigned number) { CompositedScreen *screen; @@ -456,10 +470,27 @@ void process_unmap_event(Compositor *compositor, XUnmapEvent *event) window->map_state = IsUnviewable; } -void process_event(Compositor *compositor) +void process_damage_event(Compositor *compositor, XDamageNotifyEvent *event) +{ + CompositedScreen *screen = find_screen_by_window(compositor, event->drawable); + if(!screen) + return; + + screen->dirty = 1; + compositor->dirty = 1; +} + +int process_event(Compositor *compositor) { XEvent event; - XNextEvent(compositor->display, &event); + if(compositor->dirty) + { + if(!XCheckMaskEvent(compositor->display, -1, &event)) + return 0; + } + else + XNextEvent(compositor->display, &event); + switch(event.type) { case CreateNotify: @@ -472,9 +503,13 @@ void process_event(Compositor *compositor) process_unmap_event(compositor, &event.xunmap); break; default: - if(event.type!=compositor->damage_event+XDamageNotify) + if(event.type==compositor->damage_event+XDamageNotify) + process_damage_event(compositor, (XDamageNotifyEvent *)&event); + else printf("Event %d\n", event.type); } + + return 1; } void refresh_screens(Compositor *compositor) @@ -508,7 +543,11 @@ void refresh_screens(Compositor *compositor) } XUngrabServer(compositor->display); glXSwapBuffers(compositor->display, screen->glx_window); + + screen->dirty = 0; } + + compositor->dirty = 0; } int main() @@ -520,8 +559,8 @@ int main() while(1) { - process_event(&compositor); - refresh_screens(&compositor); + if(!process_event(&compositor)) + refresh_screens(&compositor); } shutdown_compositor(&compositor);