1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
27 #include <X11/Xatom.h>
29 #include "../src/generic_window.hpp"
30 #include "../src/vlcproc.hpp"
31 #include "x11_window.hpp"
32 #include "x11_display.hpp"
33 #include "x11_graphics.hpp"
34 #include "x11_dragdrop.hpp"
35 #include "x11_factory.hpp"
38 X11Window::X11Window( intf_thread_t *pIntf, GenericWindow &rWindow,
39 X11Display &rDisplay, bool dragDrop, bool playOnDrop,
40 X11Window *pParentWindow ):
41 OSWindow( pIntf ), m_rDisplay( rDisplay ), m_pParent( pParentWindow ),
42 m_dragDrop( dragDrop )
47 parent = pParentWindow->m_wnd;
51 parent = DefaultRootWindow( XDISPLAY );
53 XSetWindowAttributes attr;
56 m_wnd = XCreateWindow( XDISPLAY, parent, 0, 0, 1, 1, 0, 0,
57 InputOutput, CopyFromParent, 0, &attr );
59 // Set the colormap for 8bpp mode
62 XSetWindowColormap( XDISPLAY, m_wnd, m_rDisplay.getColormap() );
65 // Select events received by the window
66 XSelectInput( XDISPLAY, m_wnd, ExposureMask|KeyPressMask|
67 PointerMotionMask|ButtonPressMask|ButtonReleaseMask|
68 LeaveWindowMask|FocusChangeMask );
70 // Store a pointer on the generic window in a map
71 X11Factory *pFactory = (X11Factory*)X11Factory::instance( getIntf() );
72 pFactory->m_windowMap[m_wnd] = &rWindow;
74 // Changing decorations
77 unsigned long functions;
78 unsigned long decorations;
79 signed long input_mode;
82 Atom hints_atom = XInternAtom( XDISPLAY, "_MOTIF_WM_HINTS", False );
83 motifWmHints.flags = 2; // MWM_HINTS_DECORATIONS;
84 motifWmHints.decorations = 0;
85 XChangeProperty( XDISPLAY, m_wnd, hints_atom, hints_atom, 32,
86 PropModeReplace, (unsigned char *)&motifWmHints,
87 sizeof( motifWmHints ) / sizeof( uint32_t ) );
92 // Create a Dnd object for this window
93 m_pDropTarget = new X11DragDrop( getIntf(), m_rDisplay, m_wnd,
96 // Register the window as a drop target
97 Atom xdndAtom = XInternAtom( XDISPLAY, "XdndAware", False );
99 XChangeProperty( XDISPLAY, m_wnd, xdndAtom, XA_ATOM, 32,
100 PropModeReplace, (unsigned char *)&xdndVersion, 1 );
102 // Store a pointer to be used in X11Loop
103 pFactory->m_dndMap[m_wnd] = m_pDropTarget;
106 // Change the window title
107 XStoreName( XDISPLAY, m_wnd, "VLC" );
109 // Associate the window to the main "parent" window
110 XSetTransientForHint( XDISPLAY, m_wnd, m_rDisplay.getMainWindow() );
112 // Set this window as a vout
115 VlcProc::instance( getIntf() )->registerVoutWindow( (void*)m_wnd );
121 X11Window::~X11Window()
125 VlcProc::instance( getIntf() )->unregisterVoutWindow( (void*)m_wnd );
128 X11Factory *pFactory = (X11Factory*)X11Factory::instance( getIntf() );
129 pFactory->m_windowMap[m_wnd] = NULL;
130 pFactory->m_dndMap[m_wnd] = NULL;
134 delete m_pDropTarget;
136 XDestroyWindow( XDISPLAY, m_wnd );
137 XSync( XDISPLAY, False );
141 void X11Window::show( int left, int top ) const
144 XMapRaised( XDISPLAY, m_wnd );
145 XMoveWindow( XDISPLAY, m_wnd, left, top );
149 void X11Window::hide() const
152 XUnmapWindow( XDISPLAY, m_wnd );
156 void X11Window::moveResize( int left, int top, int width, int height ) const
158 XMoveResizeWindow( XDISPLAY, m_wnd, left, top, width, height );
162 void X11Window::raise() const
164 XRaiseWindow( XDISPLAY, m_wnd );
168 void X11Window::setOpacity( uint8_t value ) const
170 // Sorry, the opacity cannot be changed :)
174 void X11Window::toggleOnTop( bool onTop ) const
177 unsigned long i, i_items, i_bytesafter;
178 Atom net_wm_supported, net_wm_state, net_wm_state_on_top,net_wm_state_above;
179 union { Atom *p_atom; unsigned char *p_char; } p_args;
181 p_args.p_atom = NULL;
183 net_wm_supported = XInternAtom( XDISPLAY, "_NET_SUPPORTED", False );
185 i_ret = XGetWindowProperty( XDISPLAY, DefaultRootWindow( XDISPLAY ),
187 0, 16384, False, AnyPropertyType,
189 &i_format, &i_items, &i_bytesafter,
190 (unsigned char **)&p_args );
192 if( i_ret != Success || i_items == 0 ) return; /* Not supported */
194 net_wm_state = XInternAtom( XDISPLAY, "_NET_WM_STATE", False );
195 net_wm_state_on_top = XInternAtom( XDISPLAY, "_NET_WM_STATE_STAYS_ON_TOP",
198 for( i = 0; i < i_items; i++ )
200 if( p_args.p_atom[i] == net_wm_state_on_top ) break;
204 { /* use _NET_WM_STATE_ABOVE if window manager
205 * doesn't handle _NET_WM_STATE_STAYS_ON_TOP */
207 net_wm_state_above = XInternAtom( XDISPLAY, "_NET_WM_STATE_ABOVE",
209 for( i = 0; i < i_items; i++ )
211 if( p_args.p_atom[i] == net_wm_state_above ) break;
214 XFree( p_args.p_atom );
216 return; /* Not supported */
218 /* Switch "on top" status */
219 XClientMessageEvent event;
220 memset( &event, 0, sizeof( XClientMessageEvent ) );
222 event.type = ClientMessage;
223 event.message_type = net_wm_state;
224 event.display = XDISPLAY;
225 event.window = m_wnd;
227 event.data.l[ 0 ] = onTop; /* set property */
228 event.data.l[ 1 ] = net_wm_state_above;
230 XSendEvent( XDISPLAY, DefaultRootWindow( XDISPLAY ),
231 False, SubstructureRedirectMask, (XEvent*)&event );
235 XFree( p_args.p_atom );
237 /* Switch "on top" status */
238 XClientMessageEvent event;
239 memset( &event, 0, sizeof( XClientMessageEvent ) );
241 event.type = ClientMessage;
242 event.message_type = net_wm_state;
243 event.display = XDISPLAY;
244 event.window = m_wnd;
246 event.data.l[ 0 ] = onTop; /* set property */
247 event.data.l[ 1 ] = net_wm_state_on_top;
249 XSendEvent( XDISPLAY, DefaultRootWindow( XDISPLAY ),
250 False, SubstructureRedirectMask, (XEvent*)&event );