]> git.sesse.net Git - vlc/blobdiff - modules/video_output/xcb/window.c
Qt: CaptureOpenPanel: check and prefill with usual devices
[vlc] / modules / video_output / xcb / window.c
index d4922551e7ce3262c2e6d6b661996f26ef1003f2..a7040a8930ce86439569d9dc983208dd3075d29d 100644 (file)
@@ -7,7 +7,7 @@
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2.0
+ * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
@@ -15,7 +15,7 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU Lesser General Public
+ * You should have received a copy of the GNU General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  ****************************************************************************/
@@ -40,11 +40,6 @@ typedef xcb_atom_t Atom;
 
 #include "xcb_vlc.h"
 
-#define DISPLAY_TEXT N_("X11 display")
-#define DISPLAY_LONGTEXT N_( \
-    "X11 hardware display to use. By default VLC will " \
-    "use the value of the DISPLAY environment variable.")
-
 #define XID_TEXT N_("ID of the video output X window")
 #define XID_LONGTEXT N_( \
     "VLC can embed its video output in an existing X11 window. " \
@@ -66,8 +61,6 @@ vlc_module_begin ()
     set_capability ("vout window xid", 10)
     set_callbacks (Open, Close)
 
-    add_string ("x11-display", NULL, NULL,
-                DISPLAY_TEXT, DISPLAY_LONGTEXT, true)
     /* Obsolete since 1.1.0: */
     add_obsolete_bool ("x11-altfullscreen")
     add_obsolete_bool ("xvideo-altfullscreen")
@@ -81,15 +74,18 @@ vlc_module_begin ()
     set_subcategory (SUBCAT_VIDEO_VOUT)
     set_capability ("vout window xid", 70)
     set_callbacks (EmOpen, EmClose)
+    add_shortcut ("embed-xid")
 
     add_integer ("drawable-xid", 0, NULL, XID_TEXT, XID_LONGTEXT, true)
-        change_unsaveable ()
+        change_volatile ()
 
 vlc_module_end ()
 
 static int Control (vout_window_t *, int, va_list ap);
 static void *Thread (void *);
 
+#define MATCHBOX_HACK 1 /* Matchbox focus hack */
+
 struct vout_window_sys_t
 {
     xcb_connection_t *conn;
@@ -99,7 +95,13 @@ struct vout_window_sys_t
     xcb_window_t root;
     xcb_atom_t wm_state;
     xcb_atom_t wm_state_above;
+    xcb_atom_t wm_state_below;
     xcb_atom_t wm_state_fullscreen;
+#ifdef MATCHBOX_HACK
+    xcb_atom_t mb_current_app_window;
+#endif
+
+    bool embedded;
 };
 
 /** Set an X window property from a nul-terminated string */
@@ -116,7 +118,7 @@ static inline
 void set_ascii_prop (xcb_connection_t *conn, xcb_window_t window,
                      xcb_atom_t atom, const char *value)
 {
-    set_string (conn, window, atom, XA_STRING, value);
+    set_string (conn, window, XA_STRING, atom, value);
 }
 
 static inline
@@ -180,15 +182,27 @@ xcb_atom_t get_atom (xcb_connection_t *conn, xcb_intern_atom_cookie_t ck)
 static void CacheAtoms (vout_window_sys_t *p_sys)
 {
     xcb_connection_t *conn = p_sys->conn;
-    xcb_intern_atom_cookie_t wm_state_ck, wm_state_above_ck, wm_state_fs_ck;
+    xcb_intern_atom_cookie_t wm_state_ck, wm_state_above_ck,
+                             wm_state_below_ck, wm_state_fs_ck;
 
     wm_state_ck = intern_string (conn, "_NET_WM_STATE");
     wm_state_above_ck = intern_string (conn, "_NET_WM_STATE_ABOVE");
+    wm_state_below_ck = intern_string (conn, "_NET_WM_STATE_BELOW");
     wm_state_fs_ck = intern_string (conn, "_NET_WM_STATE_FULLSCREEN");
+#ifdef MATCHBOX_HACK
+    xcb_intern_atom_cookie_t mb_current_app_window;
+    mb_current_app_window = xcb_intern_atom (conn, true,
+                                             strlen ("_MB_CURRENT_APP_WINDOW"),
+                                             "_MB_CURRENT_APP_WINDOW");
+#endif
 
     p_sys->wm_state = get_atom (conn, wm_state_ck);
     p_sys->wm_state_above = get_atom (conn, wm_state_above_ck);
+    p_sys->wm_state_below = get_atom (conn, wm_state_below_ck);
     p_sys->wm_state_fullscreen = get_atom (conn, wm_state_fs_ck);
+#ifdef MATCHBOX_HACK
+    p_sys->mb_current_app_window = get_atom (conn, mb_current_app_window);
+#endif
 }
 
 /**
@@ -203,13 +217,13 @@ static int Open (vlc_object_t *obj)
     vout_window_sys_t *p_sys = malloc (sizeof (*p_sys));
     if (p_sys == NULL)
         return VLC_ENOMEM;
+    p_sys->embedded = false;
 
     /* Connect to X */
-    char *display = var_CreateGetNonEmptyString (wnd, "x11-display");
+    char *display = var_InheritString (wnd, "x11-display");
     int snum;
 
     xcb_connection_t *conn = xcb_connect (display, &snum);
-    free (display);
     if (xcb_connection_has_error (conn) /*== NULL*/)
         goto error;
 
@@ -243,7 +257,8 @@ static int Open (vlc_object_t *obj)
 
     xcb_window_t window = xcb_generate_id (conn);
     ck = xcb_create_window_checked (conn, scr->root_depth, window, scr->root,
-                                    0, 0, wnd->cfg->width, wnd->cfg->height, 0,
+                                    wnd->cfg->x, wnd->cfg->y,
+                                    wnd->cfg->width, wnd->cfg->height, 0,
                                     XCB_WINDOW_CLASS_INPUT_OUTPUT,
                                     scr->root_visual, mask, values);
     err = xcb_request_check (conn, ck);
@@ -255,19 +270,30 @@ static int Open (vlc_object_t *obj)
     }
 
     wnd->handle.xid = window;
+    wnd->display.x11 = display;
     wnd->control = Control;
     wnd->sys = p_sys;
 
     p_sys->conn = conn;
-    p_sys->keys = CreateKeyHandler (obj, conn);
+    if (var_InheritBool (obj, "keyboard-events"))
+        p_sys->keys = CreateKeyHandler (obj, conn);
+    else
+        p_sys->keys = NULL;
     p_sys->root = scr->root;
 
     /* ICCCM
      * No cut&paste nor drag&drop, only Window Manager communication. */
-    /* Plain ASCII localization of VLC for ICCCM window name */
     set_ascii_prop (conn, window, XA_WM_NAME,
-                  vlc_pgettext ("ASCII", "VLC media player"));
+    /* xgettext: This is a plain ASCII spelling of "VLC media player"
+       for the ICCCM window name. This must be pure ASCII.
+       The limitation is partially with ICCCM and partially with VLC.
+       For Latin script languages, you may need to strip accents.
+       For other scripts, you will need to transliterate into Latin. */
+                    vlc_pgettext ("ASCII", "VLC media player"));
+
     set_ascii_prop (conn, window, XA_WM_ICON_NAME,
+    /* xgettext: This is a plain ASCII spelling of "VLC"
+       for the ICCCM window name. This must be pure ASCII. */
                     vlc_pgettext ("ASCII", "VLC"));
     set_wm_hints (conn, window);
     xcb_change_property (conn, XCB_PROP_MODE_REPLACE, window, XA_WM_CLASS,
@@ -287,7 +313,7 @@ static int Open (vlc_object_t *obj)
     xcb_atom_t utf8 = get_atom (conn, utf8_string_ck);
 
     xcb_atom_t net_wm_name = get_atom (conn, net_wm_name_ck);
-    char *title = var_CreateGetNonEmptyString (wnd, "video-title");
+    char *title = var_InheritString (wnd, "video-title");
     if (title)
     {
         set_string (conn, window, utf8, net_wm_name, title);
@@ -302,11 +328,25 @@ static int Open (vlc_object_t *obj)
     xcb_atom_t wm_window_role = get_atom (conn, wm_window_role_ck);
     set_ascii_prop (conn, window, wm_window_role, "vlc-video");
 
+    /* Cache any EWMH atom we may need later */
+    CacheAtoms (p_sys);
+#ifdef MATCHBOX_HACK
+    if (p_sys->mb_current_app_window)
+    {
+        uint32_t value = XCB_EVENT_MASK_PROPERTY_CHANGE;
+        xcb_change_window_attributes (conn, scr->root,
+                                      XCB_CW_EVENT_MASK, &value);
+    }
+#endif
+
     /* Make the window visible */
     xcb_map_window (conn, window);
 
-    /* Cache any EWMH atom we may need later */
-    CacheAtoms (p_sys);
+    if (var_InheritBool (obj, "video-wallpaper"))
+    {
+        vout_window_SetState (wnd, VOUT_WINDOW_STATE_BELOW);
+        vout_window_SetFullScreen (wnd, true);
+    }
 
     /* Create the event thread. It will dequeue all events, so any checked
      * request from this thread must be completed at this point. */
@@ -314,12 +354,17 @@ static int Open (vlc_object_t *obj)
      && vlc_clone (&p_sys->thread, Thread, wnd, VLC_THREAD_PRIORITY_LOW))
         DestroyKeyHandler (p_sys->keys);
 
+#ifdef MATCHBOX_HACK
+    if (p_sys->mb_current_app_window)
+        xcb_set_input_focus (p_sys->conn, XCB_INPUT_FOCUS_POINTER_ROOT,
+                             wnd->handle.xid, XCB_CURRENT_TIME);
+#endif
     xcb_flush (conn); /* Make sure map_window is sent (should be useless) */
-
     return VLC_SUCCESS;
 
 error:
     xcb_disconnect (conn);
+    free (display);
     free (p_sys);
     return VLC_EGENERIC;
 }
@@ -341,6 +386,7 @@ static void Close (vlc_object_t *obj)
         DestroyKeyHandler (p_sys->keys);
     }
     xcb_disconnect (conn);
+    free (wnd->display.x11);
     free (p_sys);
 }
 
@@ -368,7 +414,35 @@ static void *Thread (void *data)
         {
             if (ProcessKeyEvent (p_sys->keys, ev) == 0)
                 continue;
-            msg_Dbg (wnd, "unhandled event: %"PRIu8, ev->response_type);
+#ifdef MATCHBOX_HACK
+            if (p_sys->mb_current_app_window
+             && (ev->response_type & 0x7f) == XCB_PROPERTY_NOTIFY)
+            {
+                const xcb_property_notify_event_t *pne =
+                    (xcb_property_notify_event_t *)ev;
+                if (pne->atom == p_sys->mb_current_app_window
+                 && pne->state == XCB_PROPERTY_NEW_VALUE)
+                {
+                    xcb_get_property_reply_t *r =
+                        xcb_get_property_reply (conn,
+                            xcb_get_property (conn, 0, pne->window, pne->atom,
+                                              XA_WINDOW, 0, 4), NULL);
+                    if (r != NULL
+                     && !memcmp (xcb_get_property_value (r), &wnd->handle.xid,
+                                 4))
+                    {
+                        msg_Dbg (wnd, "asking Matchbox for input focus");
+                        xcb_set_input_focus (conn,
+                                             XCB_INPUT_FOCUS_POINTER_ROOT,
+                                             wnd->handle.xid, pne->time);
+                        xcb_flush (conn);
+                    }
+                    free (r);
+                }
+            }
+            else
+#endif
+                msg_Dbg (wnd, "unhandled event: %"PRIu8, ev->response_type);
             free (ev);
         }
         vlc_restorecancel (canc);
@@ -416,6 +490,9 @@ static int Control (vout_window_t *wnd, int cmd, va_list ap)
     {
         case VOUT_WINDOW_SET_SIZE:
         {
+            if (p_sys->embedded)
+                return VLC_EGENERIC;
+
             unsigned width = va_arg (ap, unsigned);
             unsigned height = va_arg (ap, unsigned);
             const uint32_t values[] = { width, height, };
@@ -426,13 +503,25 @@ static int Control (vout_window_t *wnd, int cmd, va_list ap)
             break;
         }
 
-        case VOUT_WINDOW_SET_ON_TOP:
-            set_wm_state (wnd, va_arg (ap, int), p_sys->wm_state_above);
+        case VOUT_WINDOW_SET_STATE:
+        {
+            unsigned state = va_arg (ap, unsigned);
+            bool above = (state & VOUT_WINDOW_STATE_ABOVE) != 0;
+            bool below = (state & VOUT_WINDOW_STATE_BELOW) != 0;
+
+            set_wm_state (wnd, above, p_sys->wm_state_above);
+            set_wm_state (wnd, below, p_sys->wm_state_below);
             break;
+        }
 
         case VOUT_WINDOW_SET_FULLSCREEN:
-            set_wm_state (wnd, va_arg (ap, int), p_sys->wm_state_fullscreen);
+        {
+            bool fs = va_arg (ap, int);
+            if (!fs && var_GetBool (wnd, "video-wallpaper"))
+                return VLC_EGENERIC;
+            set_wm_state (wnd, fs, p_sys->wm_state_fullscreen);
             break;
+        }
 
         default:
             msg_Err (wnd, "request %d not implemented", cmd);
@@ -449,7 +538,6 @@ static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
 /** Acquire a drawable */
 static int AcquireDrawable (vlc_object_t *obj, xcb_window_t window)
 {
-    vlc_value_t val;
     xcb_window_t *used;
     size_t n = 0;
 
@@ -459,8 +547,7 @@ static int AcquireDrawable (vlc_object_t *obj, xcb_window_t window)
     /* Keep a list of busy drawables, so we don't overlap videos if there are
      * more than one video track in the stream. */
     vlc_mutex_lock (&serializer);
-    var_Get (VLC_OBJECT (obj->p_libvlc), "xid-in-use", &val);
-    used = val.p_address;
+    used = var_GetAddress (obj->p_libvlc, "xid-in-use");
     if (used != NULL)
     {
         while (used[n])
@@ -476,8 +563,7 @@ static int AcquireDrawable (vlc_object_t *obj, xcb_window_t window)
     {
         used[n] = window;
         used[n + 1] = 0;
-        val.p_address = used;
-        var_Set (obj->p_libvlc, "xid-in-use", val);
+        var_SetAddress (obj->p_libvlc, "xid-in-use", used);
     }
     else
     {
@@ -493,13 +579,11 @@ skip:
 /** Remove this drawable from the list of busy ones */
 static void ReleaseDrawable (vlc_object_t *obj, xcb_window_t window)
 {
-    vlc_value_t val;
     xcb_window_t *used;
     size_t n = 0;
 
     vlc_mutex_lock (&serializer);
-    var_Get (VLC_OBJECT (obj->p_libvlc), "xid-in-use", &val);
-    used = val.p_address;
+    used = var_GetAddress (obj->p_libvlc, "xid-in-use");
     assert (used);
     while (used[n] != window)
     {
@@ -527,10 +611,9 @@ static int EmOpen (vlc_object_t *obj)
 {
     vout_window_t *wnd = (vout_window_t *)obj;
 
-    xcb_window_t window = var_CreateGetInteger (obj, "drawable-xid");
+    xcb_window_t window = var_InheritInteger (obj, "drawable-xid");
     if (window == 0)
         return VLC_EGENERIC;
-    var_Destroy (obj, "drawable-xid");
 
     if (AcquireDrawable (obj, window))
         return VLC_EGENERIC;
@@ -540,6 +623,8 @@ static int EmOpen (vlc_object_t *obj)
     if (p_sys == NULL || xcb_connection_has_error (conn))
         goto error;
 
+    p_sys->embedded = true;
+    p_sys->keys = NULL;
     wnd->handle.xid = window;
     wnd->control = Control;
     wnd->sys = p_sys;
@@ -556,7 +641,7 @@ static int EmOpen (vlc_object_t *obj)
     p_sys->root = geo->root;
     free (geo);
 
-    if (var_CreateGetInteger (obj, "vout-event") != 3) /* FIXME: <- cleanup */
+    if (var_InheritBool (obj, "keyboard-events"))
     {
         p_sys->keys = CreateKeyHandler (obj, conn);
         if (p_sys->keys != NULL)