commit a22d49c

Michael Forney  ·  2014-01-15 22:13:26 +0000 UTC
parent 1dba360
Allow overriding of Wayland interface via WLD_WAYLAND_INTERFACE env var
1 files changed,  +26, -0
+26, -0
 1@@ -54,6 +54,18 @@ const static struct wld_wayland_interface * interfaces[] = {
 2 #endif
 3 };
 4 
 5+enum wld_wayland_interface_id interface_id(const char * string)
 6+{
 7+    if (strcmp(string, "drm") == 0)
 8+        return WLD_DRM;
 9+    if (strcmp(string, "shm") == 0)
10+        return WLD_SHM;
11+
12+    fprintf(stderr, "Unknown Wayland interface specified: '%s'\n", string);
13+
14+    return WLD_NONE;
15+}
16+
17 EXPORT
18 struct wld_context * wld_wayland_create_context
19     (struct wl_display * display, enum wld_wayland_interface_id id, ...)
20@@ -62,10 +74,24 @@ struct wld_context * wld_wayland_create_context
21     struct wl_event_queue * queue;
22     va_list requested_interfaces;
23     bool interfaces_tried[ARRAY_LENGTH(interfaces)] = {0};
24+    const char * interface_string;
25 
26     if (!(queue = wl_display_create_queue(display)))
27         return NULL;
28 
29+    if ((interface_string = getenv("WLD_WAYLAND_INTERFACE")))
30+    {
31+        id = interface_id(interface_string);
32+
33+        if ((context = interfaces[id]->create_context(display, queue)))
34+            return context;
35+
36+        fprintf(stderr, "Could not create context for Wayland interface '%s'\n",
37+                interface_string);
38+
39+        return NULL;
40+    }
41+
42     va_start(requested_interfaces, id);
43 
44     while (id >= 0)