]> git.sesse.net Git - vlc/blob - modules/gui/skins2/x11/x11_factory.cpp
* skins2: support for custom popup menus, and win32 implementation.
[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( CmdGeneric &rCmd )
106 {
107     return new X11Timer( getIntf(), rCmd );
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 OSPopup *X11Factory::createOSPopup()
126 {
127     return new X11Popup( getIntf(), *m_pDisplay );
128 }
129
130
131 int X11Factory::getScreenWidth() const
132 {
133     Display *pDisplay = m_pDisplay->getDisplay();
134     int screen = DefaultScreen( pDisplay );
135     return DisplayWidth( pDisplay, screen );
136 }
137
138
139 int X11Factory::getScreenHeight() const
140 {
141     Display *pDisplay = m_pDisplay->getDisplay();
142     int screen = DefaultScreen( pDisplay );
143     return DisplayHeight( pDisplay, screen );
144 }
145
146
147 Rect X11Factory::getWorkArea() const
148 {
149     // XXX
150     return Rect( 0, 0, getScreenWidth(), getScreenHeight() );
151 }
152
153
154 void X11Factory::getMousePos( int &rXPos, int &rYPos ) const
155 {
156     Window rootReturn, childReturn;
157     int winx, winy;
158     unsigned int xmask;
159
160     Display *pDisplay = m_pDisplay->getDisplay();
161     Window root = DefaultRootWindow( pDisplay );
162     XQueryPointer( pDisplay, root, &rootReturn, &childReturn,
163                    &rXPos, &rYPos, &winx, &winy, &xmask );
164 }
165
166
167 void X11Factory::rmDir( const string &rPath )
168 {
169     struct dirent *file;
170     DIR *dir;
171
172     dir = opendir( rPath.c_str() );
173     if( !dir ) return;
174
175     // Parse the directory and remove everything it contains
176     while( (file = readdir( dir )) )
177     {
178         struct stat statbuf;
179         string filename = file->d_name;
180
181         // Skip "." and ".."
182         if( filename == "." || filename == ".." )
183         {
184             continue;
185         }
186
187         filename = rPath + "/" + filename;
188
189         if( !stat( filename.c_str(), &statbuf ) && statbuf.st_mode & S_IFDIR )
190         {
191             rmDir( filename );
192         }
193         else
194         {
195             unlink( filename.c_str() );
196         }
197     }
198
199     // Close the directory
200     closedir( dir );
201
202     // And delete it
203     rmdir( rPath.c_str() );
204 }
205
206
207 #endif