/*****************************************************************************
* 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
*
* 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
#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"
OSWindow( pIntf ), m_rDisplay( rDisplay ), m_pParent( pParentWindow ),
m_dragDrop( dragDrop )
{
- Window parent;
+ XSetWindowAttributes attr;
+ unsigned long valuemask;
+
if (pParentWindow)
{
- parent = pParentWindow->m_wnd;
+ m_wnd_parent = pParentWindow->m_wnd;
+
+ int i_screen = DefaultScreen( XDISPLAY );
+
+ attr.event_mask = ExposureMask | StructureNotifyMask;
+ attr.backing_store = Always;
+ attr.background_pixel = BlackPixel( XDISPLAY, i_screen );
+ valuemask = CWBackingStore | CWBackPixel | CWEventMask;
}
else
{
- parent = DefaultRootWindow( XDISPLAY );
+ m_wnd_parent = DefaultRootWindow( XDISPLAY );
+
+ attr.event_mask = ExposureMask | StructureNotifyMask;
+ valuemask = CWEventMask;
}
- XSetWindowAttributes attr;
// Create the window
- m_wnd = XCreateWindow( XDISPLAY, parent, 0, 0, 1, 1, 0, 0,
- InputOutput, CopyFromParent, 0, &attr );
+ m_wnd = XCreateWindow( XDISPLAY, m_wnd_parent, -10, 0, 1, 1, 0, 0,
+ InputOutput, CopyFromParent, valuemask, &attr );
+
+ // wait for X server to process the previous commands
+ XSync( XDISPLAY, false );
// Set the colormap for 8bpp mode
if( XPIXELSIZE == 1 )
// Select events received by the window
XSelectInput( XDISPLAY, m_wnd, ExposureMask|KeyPressMask|
PointerMotionMask|ButtonPressMask|ButtonReleaseMask|
- LeaveWindowMask|FocusChangeMask|StructureNotifyMask );
+ LeaveWindowMask|FocusChangeMask );
// Store a pointer on the generic window in a map
X11Factory *pFactory = (X11Factory*)X11Factory::instance( getIntf() );
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 );
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 )
// Associate the window to the main "parent" window
XSetTransientForHint( XDISPLAY, m_wnd, m_rDisplay.getMainWindow() );
- // XXX Kludge to tell VLC that this window is the vout
- if( m_pParent )
- {
- vlc_value_t value;
- value.i_int = (int) (ptrdiff_t) (void *) m_wnd;
- var_Set( getIntf()->p_vlc, "drawable", value );
- }
}
X11Window::~X11Window()
{
- // XXX Kludge to tell VLC that this window is no more the vout
- if( m_pParent )
- {
- vlc_value_t value;
- value.i_int = 0;
- var_Set( getIntf()->p_vlc, "drawable", value );
- }
-
X11Factory *pFactory = (X11Factory*)X11Factory::instance( getIntf() );
pFactory->m_windowMap[m_wnd] = NULL;
pFactory->m_dndMap[m_wnd] = NULL;
XSync( XDISPLAY, False );
}
+void X11Window::reparent( void* OSHandle, int x, int y, int w, int h )
+{
+ // Reparent the window
+ Window new_parent =
+ OSHandle ? (Window) OSHandle : DefaultRootWindow( XDISPLAY );
+
+ if( w && h )
+ XResizeWindow( XDISPLAY, m_wnd, w, h );
+
+ XReparentWindow( XDISPLAY, m_wnd, new_parent, x, y);
+ m_wnd_parent = new_parent;
+}
+
-void X11Window::show( int left, int top ) const
+void X11Window::show() const
{
// Map the window
XMapRaised( XDISPLAY, m_wnd );
- XMoveWindow( XDISPLAY, m_wnd, left, top );
}
void X11Window::moveResize( int left, int top, int width, int height ) const
{
- XMoveResizeWindow( XDISPLAY, m_wnd, left, top, width, height );
+ if( width && height )
+ XMoveResizeWindow( XDISPLAY, m_wnd, left, top, width, height );
+ else
+ XMoveWindow( XDISPLAY, m_wnd, left, top );
}
}
-void X11Window::setOpacity( uint8_t value )
+void X11Window::setOpacity( uint8_t value ) const
{
// Sorry, the opacity cannot be changed :)
}
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,net_wm_state_above;
+ 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;
+ }
+
+ if( i == i_items )
+ { /* use _NET_WM_STATE_ABOVE if window manager
+ * doesn't handle _NET_WM_STATE_STAYS_ON_TOP */
+
+ net_wm_state_above = XInternAtom( XDISPLAY, "_NET_WM_STATE_ABOVE",
+ False);
+ for( i = 0; i < i_items; i++ )
+ {
+ if( p_args.p_atom[i] == net_wm_state_above ) 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_above;
+
+ XSendEvent( XDISPLAY, DefaultRootWindow( XDISPLAY ),
+ False, SubstructureRedirectMask, (XEvent*)&event );
+ return;
+ }
+
+ XFree( p_args.p_atom );
+
+ /* 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