]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/x11/x11_window.cpp
playlist.m: Fix the so problematic 21193.
[vlc] / modules / gui / skins2 / x11 / x11_window.cpp
index e2c10f1bb9722a4b56eb9d8284383e72382df3de..b97649776fe5f67748950e2178181f44830aa649 100644 (file)
@@ -1,11 +1,11 @@
 /*****************************************************************************
  * x11_window.cpp
  *****************************************************************************
- * Copyright (C) 2003 VideoLAN
+ * Copyright (C) 2003 the VideoLAN team
  * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
- *          Olivier Teulière <ipkiss@via.ecp.fr>
+ *          Olivier Teulière <ipkiss@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #ifdef X11_SKINS
@@ -27,6 +27,7 @@
 #include <X11/Xatom.h>
 
 #include "../src/generic_window.hpp"
+#include "../src/vlcproc.hpp"
 #include "x11_window.hpp"
 #include "x11_display.hpp"
 #include "x11_graphics.hpp"
@@ -37,7 +38,8 @@
 X11Window::X11Window( intf_thread_t *pIntf, GenericWindow &rWindow,
                       X11Display &rDisplay, bool dragDrop, bool playOnDrop,
                       X11Window *pParentWindow ):
-    OSWindow( pIntf ), m_rDisplay( rDisplay ), m_dragDrop( dragDrop )
+    OSWindow( pIntf ), m_rDisplay( rDisplay ), m_pParent( pParentWindow ),
+    m_dragDrop( dragDrop )
 {
     Window parent;
     if (pParentWindow)
@@ -74,7 +76,7 @@ X11Window::X11Window( intf_thread_t *pIntf, GenericWindow &rWindow,
         unsigned long flags;
         unsigned long functions;
         unsigned long decorations;
-        long input_mode;
+        signed   long input_mode;
         unsigned long status;
     } motifWmHints;
     Atom hints_atom = XInternAtom( XDISPLAY, "_MOTIF_WM_HINTS", False );
@@ -82,7 +84,7 @@ X11Window::X11Window( intf_thread_t *pIntf, GenericWindow &rWindow,
     motifWmHints.decorations = 0;
     XChangeProperty( XDISPLAY, m_wnd, hints_atom, hints_atom, 32,
                      PropModeReplace, (unsigned char *)&motifWmHints,
-                     sizeof( motifWmHints ) / sizeof( long ) );
+                     sizeof( motifWmHints ) / sizeof( uint32_t ) );
 
     // Drag & drop
     if( m_dragDrop )
@@ -101,21 +103,28 @@ X11Window::X11Window( intf_thread_t *pIntf, GenericWindow &rWindow,
         pFactory->m_dndMap[m_wnd] = m_pDropTarget;
     }
 
-    // Change the window title XXX
+    // Change the window title
     XStoreName( XDISPLAY, m_wnd, "VLC" );
 
-    // XXX Kludge to tell VLC that this window is the vout
-    if (pParentWindow)
+    // Associate the window to the main "parent" window
+    XSetTransientForHint( XDISPLAY, m_wnd, m_rDisplay.getMainWindow() );
+
+    // Set this window as a vout
+    if( m_pParent )
     {
-        vlc_value_t value;
-        value.i_int = (int) (ptrdiff_t) (void *) m_wnd;
-        var_Set( getIntf()->p_vlc, "drawable", value );
+        VlcProc::instance( getIntf() )->registerVoutWindow( (void*)m_wnd );
     }
+
 }
 
 
 X11Window::~X11Window()
 {
+    if( m_pParent )
+    {
+        VlcProc::instance( getIntf() )->unregisterVoutWindow( (void*)m_wnd );
+    }
+
     X11Factory *pFactory = (X11Factory*)X11Factory::instance( getIntf() );
     pFactory->m_windowMap[m_wnd] = NULL;
     pFactory->m_dndMap[m_wnd] = NULL;
@@ -156,7 +165,7 @@ void X11Window::raise() const
 }
 
 
-void X11Window::setOpacity( uint8_t value )
+void X11Window::setOpacity( uint8_t value ) const
 {
     // Sorry, the opacity cannot be changed :)
 }
@@ -164,7 +173,50 @@ void X11Window::setOpacity( uint8_t value )
 
 void X11Window::toggleOnTop( bool onTop ) const
 {
-    // TODO
+    int i_ret, i_format;
+    unsigned long i, i_items, i_bytesafter;
+    Atom net_wm_supported, net_wm_state, net_wm_state_on_top;
+    union { Atom *p_atom; unsigned char *p_char; } p_args;
+
+    p_args.p_atom = NULL;
+
+    net_wm_supported = XInternAtom( XDISPLAY, "_NET_SUPPORTED", False );
+
+    i_ret = XGetWindowProperty( XDISPLAY, DefaultRootWindow( XDISPLAY ),
+                                net_wm_supported,
+                                0, 16384, False, AnyPropertyType,
+                                &net_wm_supported,
+                                &i_format, &i_items, &i_bytesafter,
+                                (unsigned char **)&p_args );
+
+    if( i_ret != Success || i_items == 0 ) return; /* Not supported */
+
+    net_wm_state = XInternAtom( XDISPLAY, "_NET_WM_STATE", False );
+    net_wm_state_on_top = XInternAtom( XDISPLAY, "_NET_WM_STATE_STAYS_ON_TOP",
+                                       False );
+
+    for( i = 0; i < i_items; i++ )
+    {
+        if( p_args.p_atom[i] == net_wm_state_on_top ) break;
+    }
+
+    XFree( p_args.p_atom );
+    if( i == i_items ) return; /* Not supported */
+
+    /* Switch "on top" status */
+    XClientMessageEvent event;
+    memset( &event, 0, sizeof( XClientMessageEvent ) );
+
+    event.type = ClientMessage;
+    event.message_type = net_wm_state;
+    event.display = XDISPLAY;
+    event.window = m_wnd;
+    event.format = 32;
+    event.data.l[ 0 ] = onTop; /* set property */
+    event.data.l[ 1 ] = net_wm_state_on_top;
+
+    XSendEvent( XDISPLAY, DefaultRootWindow( XDISPLAY ),
+                False, SubstructureRedirectMask, (XEvent*)&event );
 }
 
 #endif