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