1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: x11_window.cpp,v 1.3 2004/01/25 18:41:08 asmax Exp $
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
27 #include <X11/Xatom.h>
29 #include "../src/generic_window.hpp"
30 #include "x11_window.hpp"
31 #include "x11_display.hpp"
32 #include "x11_graphics.hpp"
33 #include "x11_dragdrop.hpp"
34 #include "x11_factory.hpp"
37 X11Window::X11Window( intf_thread_t *pIntf, GenericWindow &rWindow,
38 X11Display &rDisplay, bool dragDrop, bool playOnDrop ):
39 OSWindow( pIntf ), m_rDisplay( rDisplay ), m_dragDrop( dragDrop )
41 Window root = DefaultRootWindow( XDISPLAY );
42 XSetWindowAttributes attr;
45 m_wnd = XCreateWindow( XDISPLAY, root, 0, 0, 1, 1, 0, 0,
46 InputOutput, CopyFromParent, 0, &attr );
48 // Set the colormap for 8bpp mode
51 XSetWindowColormap( XDISPLAY, m_wnd, m_rDisplay.getColormap() );
54 // Select events received by the window
55 XSelectInput( XDISPLAY, m_wnd, ExposureMask|KeyPressMask|PointerMotionMask|
56 ButtonPressMask|ButtonReleaseMask|LeaveWindowMask|
59 // Store a pointer on the generic window in a map
60 X11Factory *pFactory = (X11Factory*)X11Factory::instance( getIntf() );
61 pFactory->m_windowMap[m_wnd] = &rWindow;
63 // Changing decorations
66 unsigned long functions;
67 unsigned long decorations;
71 Atom hints_atom = XInternAtom( XDISPLAY, "_MOTIF_WM_HINTS", False );
72 motifWmHints.flags = 2; // MWM_HINTS_DECORATIONS;
73 motifWmHints.decorations = 0;
74 XChangeProperty( XDISPLAY, m_wnd, hints_atom, hints_atom, 32,
75 PropModeReplace, (unsigned char *)&motifWmHints,
76 sizeof( motifWmHints ) / sizeof( long ) );
81 // Create a Dnd object for this window
82 m_pDropTarget = new X11DragDrop( getIntf(), m_rDisplay, m_wnd,
85 // Register the window as a drop target
86 Atom xdndAtom = XInternAtom( XDISPLAY, "XdndAware", False );
88 XChangeProperty( XDISPLAY, m_wnd, xdndAtom, XA_ATOM, 32,
89 PropModeReplace, (unsigned char *)&xdndVersion, 1 );
91 // Store a pointer to be used in X11Loop
92 pFactory->m_dndMap[m_wnd] = m_pDropTarget;
95 // Change the window title XXX
96 XStoreName( XDISPLAY, m_wnd, "VLC" );
100 X11Window::~X11Window()
102 X11Factory *pFactory = (X11Factory*)X11Factory::instance( getIntf() );
103 pFactory->m_windowMap[m_wnd] = NULL;
104 pFactory->m_dndMap[m_wnd] = NULL;
108 delete m_pDropTarget;
110 XDestroyWindow( XDISPLAY, m_wnd );
111 XSync( XDISPLAY, False );
115 void X11Window::show( int left, int top )
118 XMapRaised( XDISPLAY, m_wnd );
119 XMoveWindow( XDISPLAY, m_wnd, left, top );
123 void X11Window::hide()
126 XUnmapWindow( XDISPLAY, m_wnd );
130 void X11Window::moveResize( int left, int top, int width, int height )
132 XMoveResizeWindow( XDISPLAY, m_wnd, left, top, width, height );
136 void X11Window::raise()
138 XRaiseWindow( XDISPLAY, m_wnd );
142 void X11Window::setOpacity( uint8_t value )
144 // Sorry, the opacity cannot be changed :)
148 void X11Window::toggleOnTop( bool onTop )