]> git.sesse.net Git - vlc/blob - modules/gui/skins2/x11/x11_factory.cpp
* all: brand new skins interface ( still _experimental_) for x11 and
[vlc] / modules / gui / skins2 / x11 / x11_factory.cpp
1 /*****************************************************************************
2  * x11_factory.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: x11_factory.cpp,v 1.1 2004/01/03 23:31:34 asmax Exp $
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., 59 Temple Place - Suite 330, Boston, MA  02111, 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_timer.hpp"
37 #include "x11_window.hpp"
38 #include "x11_tooltip.hpp"
39
40
41 X11Factory::X11Factory( intf_thread_t *pIntf ): OSFactory( pIntf )
42 {
43     // see init()
44 }
45
46
47 X11Factory::~X11Factory()
48 {
49     delete m_pTimerLoop;
50     delete m_pDisplay;
51 }
52
53
54 bool X11Factory::init()
55 {
56     // Create the X11 display
57     m_pDisplay = new X11Display( getIntf() );
58
59     // Get the display
60     Display *pDisplay = m_pDisplay->getDisplay();
61     if( pDisplay == NULL )
62     {
63         // Initialization failed
64         return false;
65     }
66
67     // Create the timer loop
68     m_pTimerLoop = new X11TimerLoop( getIntf(),
69                                      ConnectionNumber( pDisplay ) );
70
71     return true;
72 }
73
74
75 OSGraphics *X11Factory::createOSGraphics( int width, int height )
76 {
77     return new X11Graphics( getIntf(), *m_pDisplay, width, height );
78 }
79
80
81 OSLoop *X11Factory::getOSLoop()
82 {
83     return X11Loop::instance( getIntf(), *m_pDisplay );
84 }
85
86
87 void X11Factory::destroyOSLoop()
88 {
89     X11Loop::destroy( getIntf() );
90 }
91
92
93 OSTimer *X11Factory::createOSTimer( const Callback &rCallback )
94 {
95     return new X11Timer( getIntf(), rCallback );
96 }
97
98
99 OSWindow *X11Factory::createOSWindow( GenericWindow &rWindow, bool dragDrop,
100                                       bool playOnDrop )
101 {
102     return new X11Window( getIntf(), rWindow, *m_pDisplay, dragDrop,
103                           playOnDrop );
104 }
105
106
107 OSTooltip *X11Factory::createOSTooltip()
108 {
109     return new X11Tooltip( getIntf(), *m_pDisplay );
110 }
111
112
113 const string X11Factory::getDirSeparator() const
114 {
115     return "/";
116 }
117
118
119 int X11Factory::getScreenWidth() const
120 {
121     Display *pDisplay = m_pDisplay->getDisplay();
122     int screen = DefaultScreen( pDisplay );
123     return DisplayWidth( pDisplay, screen );
124 }
125
126
127 int X11Factory::getScreenHeight() const
128 {
129     Display *pDisplay = m_pDisplay->getDisplay();
130     int screen = DefaultScreen( pDisplay );
131     return DisplayHeight( pDisplay, screen );
132 }
133
134
135 Rect X11Factory::getWorkArea() const
136 {
137     // XXX
138     return Rect( 0, 0, getScreenWidth(), getScreenHeight() );
139 }
140
141
142 void X11Factory::getMousePos( int &rXPos, int &rYPos ) const
143 {
144     Window rootReturn, childReturn;
145     int winx, winy;
146     unsigned int xmask;
147
148     Display *pDisplay = m_pDisplay->getDisplay();
149     Window root = DefaultRootWindow( pDisplay );
150     XQueryPointer( pDisplay, root, &rootReturn, &childReturn,
151                    &rXPos, &rYPos, &winx, &winy, &xmask );
152 }
153
154
155 void X11Factory::rmDir( const string &rPath )
156 {
157     struct dirent *file;
158     DIR *dir;
159
160     dir = opendir( rPath.c_str() );
161     if( !dir ) return;
162
163     // Parse the directory and remove everything it contains
164     while( (file = readdir( dir )) )
165     {
166         struct stat statbuf;
167         string filename = file->d_name;
168
169         // Skip "." and ".."
170         if( filename == "." || filename == ".." )
171         {
172             continue;
173         }
174
175         filename = rPath + "/" + filename;
176
177         if( !stat( filename.c_str(), &statbuf ) && statbuf.st_mode & S_IFDIR )
178         {
179             rmDir( filename );
180         }
181         else
182         {
183             unlink( filename.c_str() );
184         }
185     }
186
187     // Close the directory
188     closedir( dir );
189
190     // And delete it
191     rmdir( rPath.c_str() );
192 }
193
194
195 #endif