00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00056 m_wnd = XCreateWindow( XDISPLAY, parent, 0, 0, 1, 1, 0, 0,
00057 InputOutput, CopyFromParent, 0, &attr );
00058
00059
00060 if( XPIXELSIZE == 1 )
00061 {
00062 XSetWindowColormap( XDISPLAY, m_wnd, m_rDisplay.getColormap() );
00063 }
00064
00065
00066 XSelectInput( XDISPLAY, m_wnd, ExposureMask|KeyPressMask|
00067 PointerMotionMask|ButtonPressMask|ButtonReleaseMask|
00068 LeaveWindowMask|FocusChangeMask );
00069
00070
00071 X11Factory *pFactory = (X11Factory*)X11Factory::instance( getIntf() );
00072 pFactory->m_windowMap[m_wnd] = &rWindow;
00073
00074
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;
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
00090 if( m_dragDrop )
00091 {
00092
00093 m_pDropTarget = new X11DragDrop( getIntf(), m_rDisplay, m_wnd,
00094 playOnDrop );
00095
00096
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
00103 pFactory->m_dndMap[m_wnd] = m_pDropTarget;
00104 }
00105
00106
00107 XStoreName( XDISPLAY, m_wnd, "VLC" );
00108
00109
00110 XSetTransientForHint( XDISPLAY, m_wnd, m_rDisplay.getMainWindow() );
00111
00112
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
00144 XMapRaised( XDISPLAY, m_wnd );
00145 XMoveWindow( XDISPLAY, m_wnd, left, top );
00146 }
00147
00148
00149 void X11Window::hide() const
00150 {
00151
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
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;
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;
00205
00206
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;
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