]> git.sesse.net Git - vlc/blob - modules/gui/skins2/x11/x11_window.cpp
* all: support of 8 bpp mode for X11 skins. Like in the vout it uses
[vlc] / modules / gui / skins2 / x11 / x11_window.cpp
1 /*****************************************************************************
2  * x11_window.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: x11_window.cpp,v 1.3 2004/01/25 18:41:08 asmax Exp $
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #ifdef X11_SKINS
26
27 #include <X11/Xatom.h>
28
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"
35
36
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 )
40 {
41     Window root = DefaultRootWindow( XDISPLAY );
42     XSetWindowAttributes attr;
43
44     // Create the window
45     m_wnd = XCreateWindow( XDISPLAY, root, 0, 0, 1, 1, 0, 0,
46                            InputOutput, CopyFromParent, 0, &attr );
47
48     // Set the colormap for 8bpp mode
49     if( XPIXELSIZE == 1 )
50     {
51         XSetWindowColormap( XDISPLAY, m_wnd, m_rDisplay.getColormap() );
52     }
53
54     // Select events received by the window
55     XSelectInput( XDISPLAY, m_wnd, ExposureMask|KeyPressMask|PointerMotionMask|
56                   ButtonPressMask|ButtonReleaseMask|LeaveWindowMask|
57                   FocusChangeMask );
58
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;
62
63     // Changing decorations
64     struct {
65         unsigned long flags;
66         unsigned long functions;
67         unsigned long decorations;
68         long input_mode;
69         unsigned long status;
70     } motifWmHints;
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 ) );
77
78     // Drag & drop
79     if( m_dragDrop )
80     {
81         // Create a Dnd object for this window
82         m_pDropTarget = new X11DragDrop( getIntf(), m_rDisplay, m_wnd,
83                                          playOnDrop );
84
85         // Register the window as a drop target
86         Atom xdndAtom = XInternAtom( XDISPLAY, "XdndAware", False );
87         char xdndVersion = 4;
88         XChangeProperty( XDISPLAY, m_wnd, xdndAtom, XA_ATOM, 32,
89                          PropModeReplace, (unsigned char *)&xdndVersion, 1 );
90
91         // Store a pointer to be used in X11Loop
92         pFactory->m_dndMap[m_wnd] = m_pDropTarget;
93     }
94
95     // Change the window title XXX
96     XStoreName( XDISPLAY, m_wnd, "VLC" );
97 }
98
99
100 X11Window::~X11Window()
101 {
102     X11Factory *pFactory = (X11Factory*)X11Factory::instance( getIntf() );
103     pFactory->m_windowMap[m_wnd] = NULL;
104     pFactory->m_dndMap[m_wnd] = NULL;
105
106     if( m_dragDrop )
107     {
108         delete m_pDropTarget;
109     }
110     XDestroyWindow( XDISPLAY, m_wnd );
111     XSync( XDISPLAY, False );
112 }
113
114
115 void X11Window::show( int left, int top )
116 {
117     // Map the window
118     XMapRaised( XDISPLAY, m_wnd );
119     XMoveWindow( XDISPLAY, m_wnd, left, top );
120 }
121
122
123 void X11Window::hide()
124 {
125     // Unmap the window
126     XUnmapWindow( XDISPLAY, m_wnd );
127 }
128
129
130 void X11Window::moveResize( int left, int top, int width, int height )
131 {
132     XMoveResizeWindow( XDISPLAY, m_wnd, left, top, width, height );
133 }
134
135
136 void X11Window::raise()
137 {
138     XRaiseWindow( XDISPLAY, m_wnd );
139 }
140
141
142 void X11Window::setOpacity( uint8_t value )
143 {
144     // Sorry, the opacity cannot be changed :)
145 }
146
147
148 void X11Window::toggleOnTop( bool onTop )
149 {
150     // XXX TODO
151 }
152
153 #endif