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