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