]> git.sesse.net Git - vlc/blobdiff - modules/video_output/xcb/window.c
adding posterize video filter
[vlc] / modules / video_output / xcb / window.c
index f22db1d353f81f65db403c8147fa1be1107dfc49..a7040a8930ce86439569d9dc983208dd3075d29d 100644 (file)
@@ -74,9 +74,10 @@ 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 ()
 
@@ -94,10 +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 */
@@ -178,10 +182,12 @@ 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;
@@ -192,6 +198,7 @@ static void CacheAtoms (vout_window_sys_t *p_sys)
 
     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);
@@ -210,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;
 
@@ -250,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);
@@ -261,12 +269,13 @@ static int Open (vlc_object_t *obj)
         goto error;
     }
 
-    wnd->xid = window;
+    wnd->handle.xid = window;
+    wnd->display.x11 = display;
     wnd->control = Control;
     wnd->sys = p_sys;
 
     p_sys->conn = conn;
-    if (var_CreateGetBool (obj, "keyboard-events"))
+    if (var_InheritBool (obj, "keyboard-events"))
         p_sys->keys = CreateKeyHandler (obj, conn);
     else
         p_sys->keys = NULL;
@@ -274,10 +283,17 @@ static int Open (vlc_object_t *obj)
 
     /* 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,
@@ -297,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);
@@ -326,6 +342,12 @@ static int Open (vlc_object_t *obj)
     /* Make the window visible */
     xcb_map_window (conn, window);
 
+    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. */
     if ((p_sys->keys != NULL)
@@ -335,13 +357,14 @@ static int Open (vlc_object_t *obj)
 #ifdef MATCHBOX_HACK
     if (p_sys->mb_current_app_window)
         xcb_set_input_focus (p_sys->conn, XCB_INPUT_FOCUS_POINTER_ROOT,
-                             wnd->xid, XCB_CURRENT_TIME);
+                             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;
 }
@@ -363,6 +386,7 @@ static void Close (vlc_object_t *obj)
         DestroyKeyHandler (p_sys->keys);
     }
     xcb_disconnect (conn);
+    free (wnd->display.x11);
     free (p_sys);
 }
 
@@ -404,13 +428,13 @@ static void *Thread (void *data)
                             xcb_get_property (conn, 0, pne->window, pne->atom,
                                               XA_WINDOW, 0, 4), NULL);
                     if (r != NULL
-                     && !memcmp (xcb_get_property_value (r), &wnd->xid,
+                     && !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->xid, pne->time);
+                                             wnd->handle.xid, pne->time);
                         xcb_flush (conn);
                     }
                     free (r);
@@ -440,7 +464,7 @@ static void set_wm_state (vout_window_t *wnd, bool on, xcb_atom_t state)
     xcb_client_message_event_t ev = {
          .response_type = XCB_CLIENT_MESSAGE,
          .format = 32,
-         .window = wnd->xid,
+         .window = wnd->handle.xid,
          .type = sys->wm_state,
     };
 
@@ -466,23 +490,38 @@ 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, };
 
-            xcb_configure_window (conn, wnd->xid,
+            xcb_configure_window (conn, wnd->handle.xid,
                                   XCB_CONFIG_WINDOW_WIDTH |
                                   XCB_CONFIG_WINDOW_HEIGHT, values);
             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);
@@ -572,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;
@@ -585,7 +623,9 @@ static int EmOpen (vlc_object_t *obj)
     if (p_sys == NULL || xcb_connection_has_error (conn))
         goto error;
 
-    wnd->xid = window;
+    p_sys->embedded = true;
+    p_sys->keys = NULL;
+    wnd->handle.xid = window;
     wnd->control = Control;
     wnd->sys = p_sys;
 
@@ -601,7 +641,7 @@ static int EmOpen (vlc_object_t *obj)
     p_sys->root = geo->root;
     free (geo);
 
-    if (var_CreateGetBool (obj, "keyboard-events"))
+    if (var_InheritBool (obj, "keyboard-events"))
     {
         p_sys->keys = CreateKeyHandler (obj, conn);
         if (p_sys->keys != NULL)
@@ -633,7 +673,7 @@ error:
 static void EmClose (vlc_object_t *obj)
 {
     vout_window_t *wnd = (vout_window_t *)obj;
-    xcb_window_t window = wnd->xid;
+    xcb_window_t window = wnd->handle.xid;
 
     Close (obj);
     ReleaseDrawable (obj, window);