]> git.sesse.net Git - vlc/blob - modules/gui/skins2/x11/x11_factory.cpp
skins2 vout manager
[vlc] / modules / gui / skins2 / x11 / x11_factory.cpp
1 /*****************************************************************************
2  * x11_factory.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifdef X11_SKINS
26
27 #include <unistd.h>
28 #include <dirent.h>
29 #include <sys/stat.h>
30 #include <X11/Xlib.h>
31
32 #include "x11_factory.hpp"
33 #include "x11_display.hpp"
34 #include "x11_graphics.hpp"
35 #include "x11_loop.hpp"
36 #include "x11_popup.hpp"
37 #include "x11_timer.hpp"
38 #include "x11_window.hpp"
39 #include "x11_tooltip.hpp"
40
41
42 X11Factory::X11Factory( intf_thread_t *pIntf ): OSFactory( pIntf ),
43     m_pDisplay( NULL ), m_pTimerLoop( NULL ), m_dirSep( "/" )
44 {
45     // see init()
46 }
47
48
49 X11Factory::~X11Factory()
50 {
51     delete m_pTimerLoop;
52     delete m_pDisplay;
53 }
54
55
56 bool X11Factory::init()
57 {
58     // make sure xlib is safe-thread
59     if( !XInitThreads() )
60         msg_Err( getIntf(), "initializing xlib for multi-threading failed" );
61
62     // Create the X11 display
63     m_pDisplay = new X11Display( getIntf() );
64
65     // Get the display
66     Display *pDisplay = m_pDisplay->getDisplay();
67     if( pDisplay == NULL )
68     {
69         // Initialization failed
70         return false;
71     }
72
73     // Create the timer loop
74     m_pTimerLoop = new X11TimerLoop( getIntf(),
75                                      ConnectionNumber( pDisplay ) );
76
77     // Initialize the resource path
78     char *datadir = config_GetUserDataDir();
79     m_resourcePath.push_back( (string)datadir + "/skins2" );
80     free( datadir );
81     m_resourcePath.push_back( (string)"share/skins2" );
82     m_resourcePath.push_back( (string)config_GetDataDir () + "/skins2" );
83
84     return true;
85 }
86
87
88 OSGraphics *X11Factory::createOSGraphics( int width, int height )
89 {
90     return new X11Graphics( getIntf(), *m_pDisplay, width, height );
91 }
92
93
94 OSLoop *X11Factory::getOSLoop()
95 {
96     return X11Loop::instance( getIntf(), *m_pDisplay );
97 }
98
99
100 void X11Factory::destroyOSLoop()
101 {
102     X11Loop::destroy( getIntf() );
103 }
104
105 void X11Factory::minimize()
106 {
107     XIconifyWindow( m_pDisplay->getDisplay(), m_pDisplay->getMainWindow(),
108                     DefaultScreen( m_pDisplay->getDisplay() ) );
109 }
110
111 void X11Factory::restore()
112 {
113     // TODO
114 }
115
116 void X11Factory::addInTray()
117 {
118     // TODO
119 }
120
121 void X11Factory::removeFromTray()
122 {
123     // TODO
124 }
125
126 void X11Factory::addInTaskBar()
127 {
128     // TODO
129 }
130
131 void X11Factory::removeFromTaskBar()
132 {
133     // TODO
134 }
135
136 OSTimer *X11Factory::createOSTimer( CmdGeneric &rCmd )
137 {
138     return new X11Timer( getIntf(), rCmd );
139 }
140
141
142 OSWindow *X11Factory::createOSWindow( GenericWindow &rWindow, bool dragDrop,
143                                       bool playOnDrop, OSWindow *pParent )
144 {
145     return new X11Window( getIntf(), rWindow, *m_pDisplay, dragDrop,
146                           playOnDrop, (X11Window*)pParent );
147 }
148
149
150 OSTooltip *X11Factory::createOSTooltip()
151 {
152     return new X11Tooltip( getIntf(), *m_pDisplay );
153 }
154
155
156 OSPopup *X11Factory::createOSPopup()
157 {
158     return new X11Popup( getIntf(), *m_pDisplay );
159 }
160
161
162 int X11Factory::getScreenWidth() const
163 {
164     Display *pDisplay = m_pDisplay->getDisplay();
165     int screen = DefaultScreen( pDisplay );
166     return DisplayWidth( pDisplay, screen );
167 }
168
169
170 int X11Factory::getScreenHeight() const
171 {
172     Display *pDisplay = m_pDisplay->getDisplay();
173     int screen = DefaultScreen( pDisplay );
174     return DisplayHeight( pDisplay, screen );
175 }
176
177
178 SkinsRect X11Factory::getWorkArea() const
179 {
180     // XXX
181     return SkinsRect( 0, 0, getScreenWidth(), getScreenHeight() );
182 }
183
184
185 void X11Factory::getMousePos( int &rXPos, int &rYPos ) const
186 {
187     Window rootReturn, childReturn;
188     int winx, winy;
189     unsigned int xmask;
190
191     Display *pDisplay = m_pDisplay->getDisplay();
192     Window root = DefaultRootWindow( pDisplay );
193     XQueryPointer( pDisplay, root, &rootReturn, &childReturn,
194                    &rXPos, &rYPos, &winx, &winy, &xmask );
195 }
196
197
198 void X11Factory::rmDir( const string &rPath )
199 {
200     struct dirent *file;
201     DIR *dir;
202
203     dir = opendir( rPath.c_str() );
204     if( !dir ) return;
205
206     // Parse the directory and remove everything it contains
207     while( (file = readdir( dir )) )
208     {
209         struct stat statbuf;
210         string filename = file->d_name;
211
212         // Skip "." and ".."
213         if( filename == "." || filename == ".." )
214         {
215             continue;
216         }
217
218         filename = rPath + "/" + filename;
219
220         if( !stat( filename.c_str(), &statbuf ) && statbuf.st_mode & S_IFDIR )
221         {
222             rmDir( filename );
223         }
224         else
225         {
226             unlink( filename.c_str() );
227         }
228     }
229
230     // Close the directory
231     closedir( dir );
232
233     // And delete it
234     rmdir( rPath.c_str() );
235 }
236
237
238 #endif