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