Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

x11_window.cpp

00001 /*****************************************************************************
00002  * x11_window.cpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: x11_window.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Cyril Deguet     <[email protected]>
00008  *          Olivier Teulière <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 #ifdef X11_SKINS
00026 
00027 #include <X11/Xatom.h>
00028 
00029 #include "../src/generic_window.hpp"
00030 #include "../src/vlcproc.hpp"
00031 #include "x11_window.hpp"
00032 #include "x11_display.hpp"
00033 #include "x11_graphics.hpp"
00034 #include "x11_dragdrop.hpp"
00035 #include "x11_factory.hpp"
00036 
00037 
00038 X11Window::X11Window( intf_thread_t *pIntf, GenericWindow &rWindow,
00039                       X11Display &rDisplay, bool dragDrop, bool playOnDrop,
00040                       X11Window *pParentWindow ):
00041     OSWindow( pIntf ), m_rDisplay( rDisplay ), m_pParent( pParentWindow ),
00042     m_dragDrop( dragDrop )
00043 {
00044     Window parent;
00045     if (pParentWindow)
00046     {
00047         parent = pParentWindow->m_wnd;
00048     }
00049     else
00050     {
00051         parent = DefaultRootWindow( XDISPLAY );
00052     }
00053     XSetWindowAttributes attr;
00054 
00055     // Create the window
00056     m_wnd = XCreateWindow( XDISPLAY, parent, 0, 0, 1, 1, 0, 0,
00057                            InputOutput, CopyFromParent, 0, &attr );
00058 
00059     // Set the colormap for 8bpp mode
00060     if( XPIXELSIZE == 1 )
00061     {
00062         XSetWindowColormap( XDISPLAY, m_wnd, m_rDisplay.getColormap() );
00063     }
00064 
00065     // Select events received by the window
00066     XSelectInput( XDISPLAY, m_wnd, ExposureMask|KeyPressMask|
00067                   PointerMotionMask|ButtonPressMask|ButtonReleaseMask|
00068                   LeaveWindowMask|FocusChangeMask );
00069 
00070     // Store a pointer on the generic window in a map
00071     X11Factory *pFactory = (X11Factory*)X11Factory::instance( getIntf() );
00072     pFactory->m_windowMap[m_wnd] = &rWindow;
00073 
00074     // Changing decorations
00075     struct {
00076         unsigned long flags;
00077         unsigned long functions;
00078         unsigned long decorations;
00079         long input_mode;
00080         unsigned long status;
00081     } motifWmHints;
00082     Atom hints_atom = XInternAtom( XDISPLAY, "_MOTIF_WM_HINTS", False );
00083     motifWmHints.flags = 2;    // MWM_HINTS_DECORATIONS;
00084     motifWmHints.decorations = 0;
00085     XChangeProperty( XDISPLAY, m_wnd, hints_atom, hints_atom, 32,
00086                      PropModeReplace, (unsigned char *)&motifWmHints,
00087                      sizeof( motifWmHints ) / sizeof( long ) );
00088 
00089     // Drag & drop
00090     if( m_dragDrop )
00091     {
00092         // Create a Dnd object for this window
00093         m_pDropTarget = new X11DragDrop( getIntf(), m_rDisplay, m_wnd,
00094                                          playOnDrop );
00095 
00096         // Register the window as a drop target
00097         Atom xdndAtom = XInternAtom( XDISPLAY, "XdndAware", False );
00098         char xdndVersion = 4;
00099         XChangeProperty( XDISPLAY, m_wnd, xdndAtom, XA_ATOM, 32,
00100                          PropModeReplace, (unsigned char *)&xdndVersion, 1 );
00101 
00102         // Store a pointer to be used in X11Loop
00103         pFactory->m_dndMap[m_wnd] = m_pDropTarget;
00104     }
00105 
00106     // Change the window title
00107     XStoreName( XDISPLAY, m_wnd, "VLC" );
00108 
00109     // Associate the window to the main "parent" window
00110     XSetTransientForHint( XDISPLAY, m_wnd, m_rDisplay.getMainWindow() );
00111 
00112     // Set this window as a vout
00113     if( m_pParent )
00114     {
00115         VlcProc::instance( getIntf() )->registerVoutWindow( (void*)m_wnd );
00116     }
00117 
00118 }
00119 
00120 
00121 X11Window::~X11Window()
00122 {
00123     if( m_pParent )
00124     {
00125         VlcProc::instance( getIntf() )->unregisterVoutWindow( (void*)m_wnd );
00126     }
00127 
00128     X11Factory *pFactory = (X11Factory*)X11Factory::instance( getIntf() );
00129     pFactory->m_windowMap[m_wnd] = NULL;
00130     pFactory->m_dndMap[m_wnd] = NULL;
00131 
00132     if( m_dragDrop )
00133     {
00134         delete m_pDropTarget;
00135     }
00136     XDestroyWindow( XDISPLAY, m_wnd );
00137     XSync( XDISPLAY, False );
00138 }
00139 
00140 
00141 void X11Window::show( int left, int top ) const
00142 {
00143     // Map the window
00144     XMapRaised( XDISPLAY, m_wnd );
00145     XMoveWindow( XDISPLAY, m_wnd, left, top );
00146 }
00147 
00148 
00149 void X11Window::hide() const
00150 {
00151     // Unmap the window
00152     XUnmapWindow( XDISPLAY, m_wnd );
00153 }
00154 
00155 
00156 void X11Window::moveResize( int left, int top, int width, int height ) const
00157 {
00158     XMoveResizeWindow( XDISPLAY, m_wnd, left, top, width, height );
00159 }
00160 
00161 
00162 void X11Window::raise() const
00163 {
00164     XRaiseWindow( XDISPLAY, m_wnd );
00165 }
00166 
00167 
00168 void X11Window::setOpacity( uint8_t value ) const
00169 {
00170     // Sorry, the opacity cannot be changed :)
00171 }
00172 
00173 
00174 void X11Window::toggleOnTop( bool onTop ) const
00175 {
00176     int i_ret, i_format;
00177     unsigned long i, i_items, i_bytesafter;
00178     Atom net_wm_supported, net_wm_state, net_wm_state_on_top;
00179     union { Atom *p_atom; unsigned char *p_char; } p_args;
00180 
00181     p_args.p_atom = NULL;
00182 
00183     net_wm_supported = XInternAtom( XDISPLAY, "_NET_SUPPORTED", False );
00184 
00185     i_ret = XGetWindowProperty( XDISPLAY, DefaultRootWindow( XDISPLAY ),
00186                                 net_wm_supported,
00187                                 0, 16384, False, AnyPropertyType,
00188                                 &net_wm_supported,
00189                                 &i_format, &i_items, &i_bytesafter,
00190                                 (unsigned char **)&p_args );
00191 
00192     if( i_ret != Success || i_items == 0 ) return; /* Not supported */
00193 
00194     net_wm_state = XInternAtom( XDISPLAY, "_NET_WM_STATE", False );
00195     net_wm_state_on_top = XInternAtom( XDISPLAY, "_NET_WM_STATE_STAYS_ON_TOP",
00196                                        False );
00197 
00198     for( i = 0; i < i_items; i++ )
00199     {
00200         if( p_args.p_atom[i] == net_wm_state_on_top ) break;
00201     }
00202 
00203     XFree( p_args.p_atom );
00204     if( i == i_items ) return; /* Not supported */
00205 
00206     /* Switch "on top" status */
00207     XClientMessageEvent event;
00208     memset( &event, 0, sizeof( XClientMessageEvent ) );
00209 
00210     event.type = ClientMessage;
00211     event.message_type = net_wm_state;
00212     event.display = XDISPLAY;
00213     event.window = m_wnd;
00214     event.format = 32;
00215     event.data.l[ 0 ] = onTop; /* set property */
00216     event.data.l[ 1 ] = net_wm_state_on_top;
00217 
00218     XSendEvent( XDISPLAY, DefaultRootWindow( XDISPLAY ),
00219                 False, SubstructureRedirectMask, (XEvent*)&event );
00220 }
00221 
00222 #endif

Generated on Tue Dec 20 10:14:44 2005 for vlc-0.8.4a by  doxygen 1.4.2