From 2b3489ad79e8996d72b3df69977b00cdb77df821 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 13 Dec 2015 18:18:20 +0200 Subject: [PATCH] Improve event handling --- source/main.c | 82 +++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/source/main.c b/source/main.c index a8a17fd..64f5ed9 100644 --- a/source/main.c +++ b/source/main.c @@ -1137,50 +1137,53 @@ void process_shape_event(Compositor *compositor, XShapeEvent *event) } } -int process_event(Compositor *compositor) +void process_events(Compositor *compositor) { + int pending; XEvent event; - if(compositor->dirty) + + pending = 0; + while((pending || !compositor->dirty) && !terminate_requested) { - if(!XCheckMaskEvent(compositor->display, -1, &event)) - return 0; - } - else + if(!pending) + pending = XPending(compositor->display); + XNextEvent(compositor->display, &event); + if(pending) + --pending; - switch(event.type) - { - case CreateNotify: - process_create_window_event(compositor, &event.xcreatewindow); - break; - case DestroyNotify: - process_destroy_window_event(compositor, &event.xdestroywindow); - break; - case MapNotify: - process_map_event(compositor, &event.xmap); - break; - case UnmapNotify: - process_unmap_event(compositor, &event.xunmap); - break; - case ReparentNotify: - process_reparent_event(compositor, &event.xreparent); - break; - case ConfigureNotify: - process_configure_event(compositor, &event.xconfigure); - break; - case PropertyNotify: - process_property_event(compositor, &event.xproperty); - break; - default: - if(event.type==compositor->damage_event+XDamageNotify) - process_damage_event(compositor, (XDamageNotifyEvent *)&event); - else if(event.type==compositor->shape_event+ShapeNotify) - process_shape_event(compositor, (XShapeEvent *)&event); - else - printf("Event %d\n", event.type); + switch(event.type) + { + case CreateNotify: + process_create_window_event(compositor, &event.xcreatewindow); + break; + case DestroyNotify: + process_destroy_window_event(compositor, &event.xdestroywindow); + break; + case MapNotify: + process_map_event(compositor, &event.xmap); + break; + case UnmapNotify: + process_unmap_event(compositor, &event.xunmap); + break; + case ReparentNotify: + process_reparent_event(compositor, &event.xreparent); + break; + case ConfigureNotify: + process_configure_event(compositor, &event.xconfigure); + break; + case PropertyNotify: + process_property_event(compositor, &event.xproperty); + break; + default: + if(event.type==compositor->damage_event+XDamageNotify) + process_damage_event(compositor, (XDamageNotifyEvent *)&event); + else if(event.type==compositor->shape_event+ShapeNotify) + process_shape_event(compositor, (XShapeEvent *)&event); + else + printf("Event %d\n", event.type); + } } - - return 1; } void refresh_screen(Compositor *compositor, CompositedScreen *screen) @@ -1291,7 +1294,8 @@ int main() while(!terminate_requested) { - if(!process_event(&compositor)) + process_events(&compositor); + if(compositor.dirty && !terminate_requested) refresh_all_screens(&compositor); } -- 2.45.2