]> git.sesse.net Git - vlc/blobdiff - modules/video_output/xcb/window.c
Name another anonynous union
[vlc] / modules / video_output / xcb / window.c
index e6f93f9e49ba9bd7b388279cb73465e996b73989..57f13dfb7dc1e2fbaf4f6a254b05eb6445ee1a26 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")
@@ -101,6 +94,7 @@ 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;
@@ -185,18 +179,23 @@ 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 = intern_string (conn, "_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);
@@ -221,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;
 
@@ -267,11 +265,15 @@ 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_CreateGetBool (obj, "keyboard-events"))
+        p_sys->keys = CreateKeyHandler (obj, conn);
+    else
+        p_sys->keys = NULL;
     p_sys->root = scr->root;
 
     /* ICCCM
@@ -314,17 +316,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
-    uint32_t value = XCB_EVENT_MASK_PROPERTY_CHANGE;
-    xcb_change_window_attributes (conn, scr->root,
-                                  XCB_CW_EVENT_MASK, &value);
+    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_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. */
@@ -333,14 +343,16 @@ static int Open (vlc_object_t *obj)
         DestroyKeyHandler (p_sys->keys);
 
 #ifdef MATCHBOX_HACK
-    xcb_set_input_focus (p_sys->conn, XCB_INPUT_FOCUS_POINTER_ROOT,
-                         wnd->handle.xid, XCB_CURRENT_TIME);
+    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;
 }
@@ -362,6 +374,7 @@ static void Close (vlc_object_t *obj)
         DestroyKeyHandler (p_sys->keys);
     }
     xcb_disconnect (conn);
+    free (wnd->display.x11);
     free (p_sys);
 }
 
@@ -390,7 +403,8 @@ static void *Thread (void *data)
             if (ProcessKeyEvent (p_sys->keys, ev) == 0)
                 continue;
 #ifdef MATCHBOX_HACK
-            if ((ev->response_type & 0x7f) == XCB_PROPERTY_NOTIFY)
+            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;
@@ -474,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);
@@ -497,7 +523,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;
 
@@ -507,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])
@@ -524,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
     {
@@ -541,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)
     {
@@ -604,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)