]> git.sesse.net Git - vlc/blobdiff - modules/services_discovery/xcb_apps.c
Use var_InheritString for --decklink-video-connection.
[vlc] / modules / services_discovery / xcb_apps.c
index 1ea58bf16d5f0f6fe33e376473b0a41b9c008b95..88927c3fe9289958f287b84f757352a3aa74efde 100644 (file)
@@ -30,12 +30,14 @@ typedef xcb_atom_t Atom;
 #include <vlc_common.h>
 #include <vlc_services_discovery.h>
 #include <vlc_dialog.h>
+#include <vlc_charset.h>
 #include <vlc_plugin.h>
 #include <poll.h>
 #include <search.h>
 
 static int  Open (vlc_object_t *);
 static void Close (vlc_object_t *);
+static int vlc_sd_probe_Open (vlc_object_t *);
 
 /*
  * Module descriptor
@@ -49,6 +51,8 @@ vlc_module_begin ()
     set_callbacks (Open, Close)
 
     add_shortcut ("apps")
+
+    VLC_SD_PROBE_SUBMODULE
 vlc_module_end ()
 
 struct services_discovery_sys_t
@@ -56,6 +60,7 @@ struct services_discovery_sys_t
     xcb_connection_t *conn;
     vlc_thread_t      thread;
     xcb_atom_t        net_client_list;
+    xcb_atom_t        net_wm_name;
     xcb_window_t      root_window;
     void             *nodes;
 };
@@ -63,6 +68,21 @@ struct services_discovery_sys_t
 static void *Run (void *);
 static void Update (services_discovery_t *);
 static void DelItem (void *);
+static void AddDesktopItem(services_discovery_t *);
+
+static int vlc_sd_probe_Open (vlc_object_t *obj)
+{
+    vlc_probe_t *probe = (vlc_probe_t *)obj;
+
+    char *display = var_InheritString (obj, "x11-display");
+    xcb_connection_t *conn = xcb_connect (display, NULL);
+    free (display);
+    if (xcb_connection_has_error (conn))
+        return VLC_PROBE_CONTINUE;
+    xcb_disconnect (conn);
+    return vlc_sd_probe_Add (probe, "xcb_apps{longname=\"Screen capture\"}",
+                             N_("Screen capture"), SD_CAT_MYCOMPUTER);
+}
 
 /**
  * Probes and initializes.
@@ -77,7 +97,7 @@ static int Open (vlc_object_t *obj)
     sd->p_sys = p_sys;
 
     /* Connect to X server */
-    char *display = var_CreateGetNonEmptyString (obj, "x11-display");
+    char *display = var_InheritString (obj, "x11-display");
     int snum;
     xcb_connection_t *conn = xcb_connect (display, &snum);
     free (display);
@@ -107,26 +127,37 @@ static int Open (vlc_object_t *obj)
         goto error;
     }
 
+    /* Add a permanent item for the entire desktop */
+    AddDesktopItem (sd);
+
     p_sys->root_window = scr->root;
     xcb_change_window_attributes (conn, scr->root, XCB_CW_EVENT_MASK,
                                &(uint32_t) { XCB_EVENT_MASK_PROPERTY_CHANGE });
 
     /* TODO: check that _NET_CLIENT_LIST is in _NET_SUPPORTED
      * (and _NET_SUPPORTING_WM_CHECK) */
-    xcb_intern_atom_cookie_t ck;
-    ck = xcb_intern_atom (conn, 1, strlen ("_NET_CLIENT_LIST"),
+    xcb_intern_atom_reply_t *r;
+    xcb_intern_atom_cookie_t ncl, nwn;
+
+    ncl = xcb_intern_atom (conn, 1, strlen ("_NET_CLIENT_LIST"),
                           "_NET_CLIENT_LIST");
-    xcb_intern_atom_reply_t *r = xcb_intern_atom_reply (conn, ck, NULL);
+    nwn = xcb_intern_atom (conn, 0, strlen ("_NET_WM_NAME"), "_NET_WM_NAME");
+
+    r = xcb_intern_atom_reply (conn, ncl, NULL);
     if (r == NULL || r->atom == 0)
     {
-        dialog_Fatal (sd, _("Application list failure"),
-                  _("Your window manager does not support application list."));
-        msg_Err (sd, "application list not support (_NET_CLIENT_LIST absent)");
-        free (r);
-        goto error;
+        dialog_Fatal (sd, _("Screen capture"),
+            _("Your window manager does not provide a list of applications."));
+        msg_Err (sd, "client list not supported (_NET_CLIENT_LIST absent)");
     }
-    p_sys->net_client_list = r->atom;
+    p_sys->net_client_list = r ? r->atom : 0;
     free (r);
+    r = xcb_intern_atom_reply (conn, nwn, NULL);
+    if (r != NULL)
+    {
+        p_sys->net_wm_name = r->atom;
+        free (r);
+    }
 
     p_sys->nodes = NULL;
     Update (sd);
@@ -199,15 +230,34 @@ struct app
 
 static struct app *AddItem (services_discovery_t *sd, xcb_window_t xid)
 {
-    char *mrl;
+    services_discovery_sys_t *p_sys = sd->p_sys;
+    char *mrl, *name;
+
     if (asprintf (&mrl, "window://0x%"PRIx8, xid) == -1)
         return NULL;
 
+    xcb_get_property_reply_t *r =
+        xcb_get_property_reply (p_sys->conn,
+            xcb_get_property (p_sys->conn, 0, xid, p_sys->net_wm_name, 0,
+                              0, 1023 /* max size */), NULL);
+    if (r != NULL)
+    {
+        name = strndup (xcb_get_property_value (r),
+                        xcb_get_property_value_length (r));
+        if (name != NULL)
+            EnsureUTF8 (name); /* don't trust third party apps too much ;-) */
+        free (r);
+    }
+    /* TODO: use WM_NAME (Latin-1) for very old apps */
+    else
+        name = NULL;
+
     input_item_t *item = input_item_NewWithType (VLC_OBJECT (sd), mrl,
-                                                 mrl,
+                                                 name ? name : mrl,
                                                  0, NULL, 0, -1,
                                                  ITEM_TYPE_CARD /* FIXME */);
     free (mrl);
+    free (name);
     if (item == NULL)
         return NULL;
 
@@ -290,3 +340,15 @@ static void Update (services_discovery_t *sd)
     tdestroy (oldnodes, DelItem);
     p_sys->nodes = newnodes;
 }
+
+static void AddDesktopItem(services_discovery_t *sd)
+{
+    input_item_t *item;
+
+    item = input_item_NewWithType (VLC_OBJECT (sd), "screen://", _("Desktop"),
+                                   0, NULL, 0, -1, ITEM_TYPE_CARD);
+    if (item == NULL)
+        return;
+
+    services_discovery_AddItem (sd, item, NULL);
+}