]> git.tdb.fi Git - geometrycompositor.git/commitdiff
Improve event handling
authorMikko Rasa <tdb@tdb.fi>
Sun, 13 Dec 2015 16:18:20 +0000 (18:18 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 13 Dec 2015 16:18:20 +0000 (18:18 +0200)
source/main.c

index a8a17fdedaa3ad7f6003778379270d1c8b438c06..64f5ed98c26288237e9e9b956579fcfaf65613de 100644 (file)
@@ -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);
        }