Browse Source

Cache the wallpaper

Instead of querying the wallpaper every time that root.wallpaper() is called, we
just remember it in globalconf.

Signed-off-by: Uli Schlachter <psychon@znc.in>
Uli Schlachter 3 years ago
parent
commit
3117b439a2
4 changed files with 63 additions and 41 deletions
  1. 3
    0
      awesome.c
  2. 5
    0
      globalconf.h
  3. 1
    0
      property.c
  4. 54
    41
      root.c

+ 3
- 0
awesome.c View File

@@ -694,6 +694,9 @@ main(int argc, char **argv)
694 694
     xcb_ungrab_server(globalconf.connection);
695 695
     xcb_flush(globalconf.connection);
696 696
 
697
+    /* get the current wallpaper, from now on we are informed when it changes */
698
+    root_update_wallpaper();
699
+
697 700
     /* Parse and run configuration file */
698 701
     if (!luaA_parserc(&xdg, confpath, true))
699 702
         fatal("couldn't find any rc file");

+ 5
- 0
globalconf.h View File

@@ -171,6 +171,8 @@ typedef struct
171 171
     struct xkb_state *xkb_state;
172 172
     /** The preferred size of client icons for this screen */
173 173
     uint32_t preferred_icon_size;
174
+    /** Cached wallpaper information */
175
+    cairo_surface_t *wallpaper;
174 176
 } awesome_t;
175 177
 
176 178
 extern awesome_t globalconf;
@@ -182,5 +184,8 @@ static inline lua_State *globalconf_get_lua_State(void) {
182 184
     return globalconf.L.real_L_dont_use_directly;
183 185
 }
184 186
 
187
+/* Defined in root.c */
188
+void root_update_wallpaper(void);
189
+
185 190
 #endif
186 191
 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

+ 1
- 0
property.c View File

@@ -381,6 +381,7 @@ property_handle_xrootpmap_id(uint8_t state,
381 381
                              xcb_window_t window)
382 382
 {
383 383
     lua_State *L = globalconf_get_lua_State();
384
+    root_update_wallpaper();
384 385
     signal_object_emit(L, &global_signals, "wallpaper_changed", 0);
385 386
     return 0;
386 387
 }

+ 54
- 41
root.c View File

@@ -123,6 +123,58 @@ disconnect:
123 123
     return result;
124 124
 }
125 125
 
126
+void
127
+root_update_wallpaper(void)
128
+{
129
+    xcb_get_property_cookie_t prop_c;
130
+    xcb_get_property_reply_t *prop_r;
131
+    xcb_get_geometry_cookie_t geom_c;
132
+    xcb_get_geometry_reply_t *geom_r;
133
+    xcb_pixmap_t *rootpix;
134
+
135
+    cairo_surface_destroy(globalconf.wallpaper);
136
+    globalconf.wallpaper = NULL;
137
+
138
+    prop_c = xcb_get_property_unchecked(globalconf.connection, false,
139
+            globalconf.screen->root, _XROOTPMAP_ID, XCB_ATOM_PIXMAP, 0, 1);
140
+    prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL);
141
+
142
+    if (!prop_r || !prop_r->value_len)
143
+    {
144
+        p_delete(&prop_r);
145
+        return;
146
+    }
147
+
148
+    rootpix = xcb_get_property_value(prop_r);
149
+    if (!rootpix)
150
+    {
151
+        p_delete(&prop_r);
152
+        return;
153
+    }
154
+
155
+    geom_c = xcb_get_geometry_unchecked(globalconf.connection, *rootpix);
156
+    geom_r = xcb_get_geometry_reply(globalconf.connection, geom_c, NULL);
157
+    if (!geom_r)
158
+    {
159
+        p_delete(&prop_r);
160
+        return;
161
+    }
162
+
163
+    /* Only the default visual makes sense, so just the default depth */
164
+    if (geom_r->depth != draw_visual_depth(globalconf.screen, globalconf.default_visual->visual_id))
165
+        warn("Got a pixmap with depth %d, but the default depth is %d, continuing anyway",
166
+                geom_r->depth, draw_visual_depth(globalconf.screen, globalconf.default_visual->visual_id));
167
+
168
+    globalconf.wallpaper = cairo_xcb_surface_create(globalconf.connection,
169
+                                                    *rootpix,
170
+                                                    globalconf.default_visual,
171
+                                                    geom_r->width,
172
+                                                    geom_r->height);
173
+
174
+    p_delete(&prop_r);
175
+    p_delete(&geom_r);
176
+}
177
+
126 178
 static xcb_keycode_t
127 179
 _string_to_key_code(const char *s)
128 180
 {
@@ -344,13 +396,6 @@ luaA_root_drawins(lua_State *L)
344 396
 static int
345 397
 luaA_root_wallpaper(lua_State *L)
346 398
 {
347
-    xcb_get_property_cookie_t prop_c;
348
-    xcb_get_property_reply_t *prop_r;
349
-    xcb_get_geometry_cookie_t geom_c;
350
-    xcb_get_geometry_reply_t *geom_r;
351
-    xcb_pixmap_t *rootpix;
352
-    cairo_surface_t *surface;
353
-
354 399
     if(lua_gettop(L) == 1)
355 400
     {
356 401
         cairo_pattern_t *pattern = (cairo_pattern_t *)lua_touserdata(L, -1);
@@ -359,43 +404,11 @@ luaA_root_wallpaper(lua_State *L)
359 404
         return 1;
360 405
     }
361 406
 
362
-    prop_c = xcb_get_property_unchecked(globalconf.connection, false,
363
-            globalconf.screen->root, _XROOTPMAP_ID, XCB_ATOM_PIXMAP, 0, 1);
364
-    prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL);
365
-
366
-    if (!prop_r || !prop_r->value_len)
367
-    {
368
-        p_delete(&prop_r);
407
+    if(globalconf.wallpaper == NULL)
369 408
         return 0;
370
-    }
371
-
372
-    rootpix = xcb_get_property_value(prop_r);
373
-    if (!rootpix)
374
-    {
375
-        p_delete(&prop_r);
376
-        return 0;
377
-    }
378
-
379
-    geom_c = xcb_get_geometry_unchecked(globalconf.connection, *rootpix);
380
-    geom_r = xcb_get_geometry_reply(globalconf.connection, geom_c, NULL);
381
-    if (!geom_r)
382
-    {
383
-        p_delete(&prop_r);
384
-        return 0;
385
-    }
386
-
387
-    /* Only the default visual makes sense, so just the default depth */
388
-    if (geom_r->depth != draw_visual_depth(globalconf.screen, globalconf.default_visual->visual_id))
389
-        warn("Got a pixmap with depth %d, but the default depth is %d, continuing anyway",
390
-                geom_r->depth, draw_visual_depth(globalconf.screen, globalconf.default_visual->visual_id));
391
-
392
-    surface = cairo_xcb_surface_create(globalconf.connection, *rootpix, globalconf.default_visual,
393
-                                       geom_r->width, geom_r->height);
394 409
 
395 410
     /* lua has to make sure this surface gets destroyed */
396
-    lua_pushlightuserdata(L, surface);
397
-    p_delete(&prop_r);
398
-    p_delete(&geom_r);
411
+    lua_pushlightuserdata(L, cairo_surface_reference(globalconf.wallpaper));
399 412
     return 1;
400 413
 }
401 414
 

Loading…
Cancel
Save