Browse Source

XKB update: Use an idle source

Instead of updating the keyboard state at the end of the current main
loop iteration, this now uses a GLib idle source with a very low
priority. This increases the chance of batching multiple refreshes
together. Also, this means that awesome_refresh() does less work.

Signed-off-by: Uli Schlachter <psychon@znc.in>
Uli Schlachter 9 months ago
parent
commit
fb147cf856
4 changed files with 24 additions and 9 deletions
  1. 0
    4
      event.h
  2. 2
    0
      globalconf.h
  3. 22
    4
      xkb.c
  4. 0
    1
      xkb.h

+ 0
- 4
event.h View File

@@ -39,13 +39,9 @@ void client_refresh(void);
39 39
 void client_focus_refresh(void);
40 40
 void client_destroy_later(void);
41 41
 
42
-/* xkb.c */
43
-void xkb_refresh(void);
44
-
45 42
 static inline int
46 43
 awesome_refresh(void)
47 44
 {
48
-    xkb_refresh();
49 45
     luaA_emit_refresh();
50 46
     drawin_refresh();
51 47
     client_refresh();

+ 2
- 0
globalconf.h View File

@@ -189,6 +189,8 @@ typedef struct
189 189
     struct xkb_context *xkb_ctx;
190 190
     /* xkb state of dead keys on keyboard */
191 191
     struct xkb_state *xkb_state;
192
+    /* Do we have a pending xkb update call? */
193
+    bool xkb_update_pending;
192 194
     /* Do we have a pending reload? */
193 195
     bool xkb_reload_keymap;
194 196
     /* Do we have a pending map change? */

+ 22
- 4
xkb.c View File

@@ -297,21 +297,33 @@ xkb_reload_keymap(void)
297 297
     }
298 298
 }
299 299
 
300
-void
301
-xkb_refresh(void)
300
+static gboolean
301
+xkb_refresh(gpointer unused)
302 302
 {
303 303
     lua_State *L = globalconf_get_lua_State();
304 304
 
305
+    globalconf.xkb_update_pending = false;
305 306
     if (globalconf.xkb_reload_keymap)
306 307
         xkb_reload_keymap();
307 308
     if (globalconf.xkb_map_changed)
308
-          signal_object_emit(L, &global_signals, "xkb::map_changed", 0);
309
+        signal_object_emit(L, &global_signals, "xkb::map_changed", 0);
309 310
     if (globalconf.xkb_group_changed)
310
-          signal_object_emit(L, &global_signals, "xkb::group_changed", 0);
311
+        signal_object_emit(L, &global_signals, "xkb::group_changed", 0);
311 312
 
312 313
     globalconf.xkb_reload_keymap = false;
313 314
     globalconf.xkb_map_changed = false;
314 315
     globalconf.xkb_group_changed = false;
316
+
317
+    return G_SOURCE_REMOVE;
318
+}
319
+
320
+static void
321
+xkb_schedule_refresh(void)
322
+{
323
+    if (globalconf.xkb_update_pending)
324
+        return;
325
+    globalconf.xkb_update_pending = true;
326
+    g_idle_add_full(G_PRIORITY_LOW, xkb_refresh, NULL, NULL);
315 327
 }
316 328
 
317 329
 /** The xkb notify event handler.
@@ -335,12 +347,14 @@ event_handle_xkb_notify(xcb_generic_event_t* event)
335 347
 
336 348
           if (new_keyboard_event->changed & XCB_XKB_NKN_DETAIL_KEYCODES)
337 349
               globalconf.xkb_map_changed = true;
350
+          xkb_schedule_refresh();
338 351
           break;
339 352
         }
340 353
       case XCB_XKB_MAP_NOTIFY:
341 354
         {
342 355
           globalconf.xkb_reload_keymap = true;
343 356
           globalconf.xkb_map_changed = true;
357
+          xkb_schedule_refresh();
344 358
           break;
345 359
         }
346 360
       case XCB_XKB_STATE_NOTIFY:
@@ -356,7 +370,10 @@ event_handle_xkb_notify(xcb_generic_event_t* event)
356 370
                                 state_notify_event->lockedGroup);
357 371
 
358 372
           if (state_notify_event->changed & XCB_XKB_STATE_PART_GROUP_STATE)
373
+          {
359 374
               globalconf.xkb_group_changed = true;
375
+              xkb_schedule_refresh();
376
+          }
360 377
 
361 378
           break;
362 379
         }
@@ -369,6 +386,7 @@ event_handle_xkb_notify(xcb_generic_event_t* event)
369 386
 void
370 387
 xkb_init(void)
371 388
 {
389
+    globalconf.xkb_update_pending = false;
372 390
     globalconf.xkb_reload_keymap = false;
373 391
     globalconf.xkb_map_changed = false;
374 392
     globalconf.xkb_group_changed = false;

+ 0
- 1
xkb.h View File

@@ -26,7 +26,6 @@
26 26
 #include <lua.h>
27 27
 
28 28
 void event_handle_xkb_notify(xcb_generic_event_t* event);
29
-void xkb_refresh(void);
30 29
 void xkb_init(void);
31 30
 void xkb_free(void);
32 31
 

Loading…
Cancel
Save