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