]> git.sesse.net Git - vlc/blob - modules/gui/skins2/x11/x11_factory.cpp
FSF address change.
[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
42 X11Factory::X11Factory( intf_thread_t *pIntf ): OSFactory( pIntf ),
43     m_pDisplay( NULL ), m_pTimerLoop( NULL ), m_dirSep( "/" )
44 {
45     // see init()
46 }
47
48
49 X11Factory::~X11Factory()
50 {
51     delete m_pTimerLoop;
52     delete m_pDisplay;
53 }
54
55
56 bool X11Factory::init()
57 {
58     // Create the X11 display
59     m_pDisplay = new X11Display( getIntf() );
60
61     // Get the display
62     Display *pDisplay = m_pDisplay->getDisplay();
63     if( pDisplay == NULL )
64     {
65         // Initialization failed
66         return false;
67     }
68
69     // Create the timer loop
70     m_pTimerLoop = new X11TimerLoop( getIntf(),
71                                      ConnectionNumber( pDisplay ) );
72
73     // Initialize the resource path
74     m_resourcePath.push_back( (string)getIntf()->p_vlc->psz_homedir +
75         m_dirSep + CONFIG_DIR + "/skins2" );
76     m_resourcePath.push_back( (string)"share/skins2" );
77     m_resourcePath.push_back( (string)DATA_PATH + "/skins2" );
78
79     return true;
80 }
81
82
83 OSGraphics *X11Factory::createOSGraphics( int width, int height )
84 {
85     return new X11Graphics( getIntf(), *m_pDisplay, width, height );
86 }
87
88
89 OSLoop *X11Factory::getOSLoop()
90 {
91     return X11Loop::instance( getIntf(), *m_pDisplay );
92 }
93
94
95 void X11Factory::destroyOSLoop()
96 {
97     X11Loop::destroy( getIntf() );
98 }
99
100 void X11Factory::minimize()
101 {
102     XIconifyWindow( m_pDisplay->getDisplay(), m_pDisplay->getMainWindow(),
103                     DefaultScreen( m_pDisplay->getDisplay() ) );
104 }
105
106 OSTimer *X11Factory::createOSTimer( CmdGeneric &rCmd )
107 {
108     return new X11Timer( getIntf(), rCmd );
109 }
110
111
112 OSWindow *X11Factory::createOSWindow( GenericWindow &rWindow, bool dragDrop,
113                                       bool playOnDrop, OSWindow *pParent )
114 {
115     return new X11Window( getIntf(), rWindow, *m_pDisplay, dragDrop,
116                           playOnDrop, (X11Window*)pParent );
117 }
118
119
120 OSTooltip *X11Factory::createOSTooltip()
121 {
122     return new X11Tooltip( getIntf(), *m_pDisplay );
123 }
124
125
126 OSPopup *X11Factory::createOSPopup()
127 {
128     return new X11Popup( getIntf(), *m_pDisplay );
129 }
130
131
132 int X11Factory::getScreenWidth() const
133 {
134     Display *pDisplay = m_pDisplay->getDisplay();
135     int screen = DefaultScreen( pDisplay );
136     return DisplayWidth( pDisplay, screen );
137 }
138
139
140 int X11Factory::getScreenHeight() const
141 {
142     Display *pDisplay = m_pDisplay->getDisplay();
143     int screen = DefaultScreen( pDisplay );
144     return DisplayHeight( pDisplay, screen );
145 }
146
147
148 Rect X11Factory::getWorkArea() const
149 {
150     // XXX
151     return Rect( 0, 0, getScreenWidth(), getScreenHeight() );
152 }
153
154
155 void X11Factory::getMousePos( int &rXPos, int &rYPos ) const
156 {
157     Window rootReturn, childReturn;
158     int winx, winy;
159     unsigned int xmask;
160
161     Display *pDisplay = m_pDisplay->getDisplay();
162     Window root = DefaultRootWindow( pDisplay );
163     XQueryPointer( pDisplay, root, &rootReturn, &childReturn,
164                    &rXPos, &rYPos, &winx, &winy, &xmask );
165 }
166
167
168 void X11Factory::rmDir( const string &rPath )
169 {
170     struct dirent *file;
171     DIR *dir;
172
173     dir = opendir( rPath.c_str() );
174     if( !dir ) return;
175
176     // Parse the directory and remove everything it contains
177     while( (file = readdir( dir )) )
178     {
179         struct stat statbuf;
180         string filename = file->d_name;
181
182         // Skip "." and ".."
183         if( filename == "." || filename == ".." )
184         {
185             continue;
186         }
187
188         filename = rPath + "/" + filename;
189
190         if( !stat( filename.c_str(), &statbuf ) && statbuf.st_mode & S_IFDIR )
191         {
192             rmDir( filename );
193         }
194         else
195         {
196             unlink( filename.c_str() );
197         }
198     }
199
200     // Close the directory
201     closedir( dir );
202
203     // And delete it
204     rmdir( rPath.c_str() );
205 }
206
207
208 #endif