1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
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.
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.
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 *****************************************************************************/
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"
42 X11Factory::X11Factory( intf_thread_t *pIntf ): OSFactory( pIntf ),
43 m_pDisplay( NULL ), m_pTimerLoop( NULL ), m_dirSep( "/" )
49 X11Factory::~X11Factory()
56 bool X11Factory::init()
58 // Create the X11 display
59 m_pDisplay = new X11Display( getIntf() );
62 Display *pDisplay = m_pDisplay->getDisplay();
63 if( pDisplay == NULL )
65 // Initialization failed
69 // Create the timer loop
70 m_pTimerLoop = new X11TimerLoop( getIntf(),
71 ConnectionNumber( pDisplay ) );
73 // Initialize the resource path
74 m_resourcePath.push_back( (string)getIntf()->p_libvlc->psz_datadir +
76 m_resourcePath.push_back( (string)"share/skins2" );
77 m_resourcePath.push_back( (string)DATA_PATH + "/skins2" );
83 OSGraphics *X11Factory::createOSGraphics( int width, int height )
85 return new X11Graphics( getIntf(), *m_pDisplay, width, height );
89 OSLoop *X11Factory::getOSLoop()
91 return X11Loop::instance( getIntf(), *m_pDisplay );
95 void X11Factory::destroyOSLoop()
97 X11Loop::destroy( getIntf() );
100 void X11Factory::minimize()
102 XIconifyWindow( m_pDisplay->getDisplay(), m_pDisplay->getMainWindow(),
103 DefaultScreen( m_pDisplay->getDisplay() ) );
106 void X11Factory::restore()
111 void X11Factory::addInTray()
116 void X11Factory::removeFromTray()
121 void X11Factory::addInTaskBar()
126 void X11Factory::removeFromTaskBar()
131 OSTimer *X11Factory::createOSTimer( CmdGeneric &rCmd )
133 return new X11Timer( getIntf(), rCmd );
137 OSWindow *X11Factory::createOSWindow( GenericWindow &rWindow, bool dragDrop,
138 bool playOnDrop, OSWindow *pParent )
140 return new X11Window( getIntf(), rWindow, *m_pDisplay, dragDrop,
141 playOnDrop, (X11Window*)pParent );
145 OSTooltip *X11Factory::createOSTooltip()
147 return new X11Tooltip( getIntf(), *m_pDisplay );
151 OSPopup *X11Factory::createOSPopup()
153 return new X11Popup( getIntf(), *m_pDisplay );
157 int X11Factory::getScreenWidth() const
159 Display *pDisplay = m_pDisplay->getDisplay();
160 int screen = DefaultScreen( pDisplay );
161 return DisplayWidth( pDisplay, screen );
165 int X11Factory::getScreenHeight() const
167 Display *pDisplay = m_pDisplay->getDisplay();
168 int screen = DefaultScreen( pDisplay );
169 return DisplayHeight( pDisplay, screen );
173 SkinsRect X11Factory::getWorkArea() const
176 return SkinsRect( 0, 0, getScreenWidth(), getScreenHeight() );
180 void X11Factory::getMousePos( int &rXPos, int &rYPos ) const
182 Window rootReturn, childReturn;
186 Display *pDisplay = m_pDisplay->getDisplay();
187 Window root = DefaultRootWindow( pDisplay );
188 XQueryPointer( pDisplay, root, &rootReturn, &childReturn,
189 &rXPos, &rYPos, &winx, &winy, &xmask );
193 void X11Factory::rmDir( const string &rPath )
198 dir = opendir( rPath.c_str() );
201 // Parse the directory and remove everything it contains
202 while( (file = readdir( dir )) )
205 string filename = file->d_name;
208 if( filename == "." || filename == ".." )
213 filename = rPath + "/" + filename;
215 if( !stat( filename.c_str(), &statbuf ) && statbuf.st_mode & S_IFDIR )
221 unlink( filename.c_str() );
225 // Close the directory
229 rmdir( rPath.c_str() );