]> git.sesse.net Git - vlc/blob - modules/gui/skins2/x11/x11_factory.cpp
Make Zorglub less unhappy
[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., 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 void X11Factory::minimize()
100 {
101     XIconifyWindow( m_pDisplay->getDisplay(), m_pDisplay->getMainWindow(),
102                     DefaultScreen( m_pDisplay->getDisplay() ) );
103 }
104
105 OSTimer *X11Factory::createOSTimer( const Callback &rCallback )
106 {
107     return new X11Timer( getIntf(), rCallback );
108 }
109
110
111 OSWindow *X11Factory::createOSWindow( GenericWindow &rWindow, bool dragDrop,
112                                       bool playOnDrop, OSWindow *pParent )
113 {
114     return new X11Window( getIntf(), rWindow, *m_pDisplay, dragDrop,
115                           playOnDrop, (X11Window*)pParent );
116 }
117
118
119 OSTooltip *X11Factory::createOSTooltip()
120 {
121     return new X11Tooltip( getIntf(), *m_pDisplay );
122 }
123
124
125 int X11Factory::getScreenWidth() const
126 {
127     Display *pDisplay = m_pDisplay->getDisplay();
128     int screen = DefaultScreen( pDisplay );
129     return DisplayWidth( pDisplay, screen );
130 }
131
132
133 int X11Factory::getScreenHeight() const
134 {
135     Display *pDisplay = m_pDisplay->getDisplay();
136     int screen = DefaultScreen( pDisplay );
137     return DisplayHeight( pDisplay, screen );
138 }
139
140
141 Rect X11Factory::getWorkArea() const
142 {
143     // XXX
144     return Rect( 0, 0, getScreenWidth(), getScreenHeight() );
145 }
146
147
148 void X11Factory::getMousePos( int &rXPos, int &rYPos ) const
149 {
150     Window rootReturn, childReturn;
151     int winx, winy;
152     unsigned int xmask;
153
154     Display *pDisplay = m_pDisplay->getDisplay();
155     Window root = DefaultRootWindow( pDisplay );
156     XQueryPointer( pDisplay, root, &rootReturn, &childReturn,
157                    &rXPos, &rYPos, &winx, &winy, &xmask );
158 }
159
160
161 void X11Factory::rmDir( const string &rPath )
162 {
163     struct dirent *file;
164     DIR *dir;
165
166     dir = opendir( rPath.c_str() );
167     if( !dir ) return;
168
169     // Parse the directory and remove everything it contains
170     while( (file = readdir( dir )) )
171     {
172         struct stat statbuf;
173         string filename = file->d_name;
174
175         // Skip "." and ".."
176         if( filename == "." || filename == ".." )
177         {
178             continue;
179         }
180
181         filename = rPath + "/" + filename;
182
183         if( !stat( filename.c_str(), &statbuf ) && statbuf.st_mode & S_IFDIR )
184         {
185             rmDir( filename );
186         }
187         else
188         {
189             unlink( filename.c_str() );
190         }
191     }
192
193     // Close the directory
194     closedir( dir );
195
196     // And delete it
197     rmdir( rPath.c_str() );
198 }
199
200
201 #endif