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