]> git.sesse.net Git - vlc/blobdiff - modules/video_output/xcb/window.c
Revert "vout_window_t: simplify via anynomous union"
[vlc] / modules / video_output / xcb / window.c
index 3bcb6f88332c43d0d156fec46c1729071b29be10..4bf2dce6b2841e8f115f0274682e6231f5d89e6f 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,11 @@ 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")
+    add_obsolete_bool ("xvmc-altfullscreen")
+    add_obsolete_bool ("glx-altfullscreen")
 
     add_submodule ()
     set_shortname (N_("Drawable"))
@@ -85,6 +83,8 @@ 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;
@@ -94,7 +94,11 @@ 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
 };
 
 /** Set an X window property from a nul-terminated string */
@@ -111,7 +115,20 @@ 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
+void set_wm_hints (xcb_connection_t *conn, xcb_window_t window)
+{
+    static const uint32_t wm_hints[8] = {
+        3, /* flags: Input, Initial state */
+        1, /* input: True */
+        1, /* initial state: Normal */
+        0, 0, 0, 0, 0, /* Icon */
+    };
+    xcb_change_property (conn, XCB_PROP_MODE_REPLACE, window, XA_WM_HINTS,
+                         XA_WM_HINTS, 32, 8, wm_hints);
 }
 
 /** Set the Window ICCCM client machine property */
@@ -162,15 +179,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
 }
 
 /**
@@ -191,7 +220,6 @@ static int Open (vlc_object_t *obj)
     int snum;
 
     xcb_connection_t *conn = xcb_connect (display, &snum);
-    free (display);
     if (xcb_connection_has_error (conn) /*== NULL*/)
         goto error;
 
@@ -232,15 +260,20 @@ static int Open (vlc_object_t *obj)
     if (err)
     {
         msg_Err (wnd, "creating window: X11 error %d", err->error_code);
+        free (err);
         goto error;
     }
 
     wnd->handle.xid = window;
+    wnd->x11_display = display;
     wnd->control = Control;
     wnd->sys = p_sys;
 
     p_sys->conn = conn;
-    p_sys->keys = CreateKeyHandler (obj, conn);
+    if (var_CreateGetBool (obj, "keyboard-events"))
+        p_sys->keys = CreateKeyHandler (obj, conn);
+    else
+        p_sys->keys = NULL;
     p_sys->root = scr->root;
 
     /* ICCCM
@@ -250,6 +283,7 @@ static int Open (vlc_object_t *obj)
                   vlc_pgettext ("ASCII", "VLC media player"));
     set_ascii_prop (conn, window, XA_WM_ICON_NAME,
                     vlc_pgettext ("ASCII", "VLC"));
+    set_wm_hints (conn, window);
     xcb_change_property (conn, XCB_PROP_MODE_REPLACE, window, XA_WM_CLASS,
                          XA_STRING, 8, 8, "vlc\0Vlc");
     set_hostname_prop (conn, window);
@@ -261,6 +295,8 @@ static int Open (vlc_object_t *obj)
         = intern_string (conn, "_NET_WM_NAME");
     xcb_intern_atom_cookie_t net_wm_icon_name_ck
         = intern_string (conn, "_NET_WM_ICON_NAME");
+    xcb_intern_atom_cookie_t wm_window_role_ck
+        = intern_string (conn, "WM_WINDOW_ROLE");
 
     xcb_atom_t utf8 = get_atom (conn, utf8_string_ck);
 
@@ -277,11 +313,28 @@ static int Open (vlc_object_t *obj)
     xcb_atom_t net_wm_icon_name = get_atom (conn, net_wm_icon_name_ck);
     set_string (conn, window, utf8, net_wm_icon_name, _("VLC"));
 
-    /* Make the window visible */
-    xcb_map_window (conn, window);
+    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);
+
+    if (var_CreateGetBool (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. */
@@ -289,12 +342,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;
 }
@@ -316,6 +374,7 @@ static void Close (vlc_object_t *obj)
         DestroyKeyHandler (p_sys->keys);
     }
     xcb_disconnect (conn);
+    free (wnd->x11_display);
     free (p_sys);
 }
 
@@ -343,7 +402,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);
@@ -401,13 +488,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);
@@ -424,9 +523,8 @@ 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;
+    size_t n = 0;
 
     if (var_Create (obj->p_libvlc, "xid-in-use", VLC_VAR_ADDRESS))
         return VLC_ENOMEM;
@@ -434,8 +532,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])
@@ -451,8 +548,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
     {
@@ -468,13 +564,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)
     {
@@ -531,7 +625,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_CreateGetBool (obj, "keyboard-events"))
     {
         p_sys->keys = CreateKeyHandler (obj, conn);
         if (p_sys->keys != NULL)