1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA 02111, 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_timer.hpp"
37 #include "x11_window.hpp"
38 #include "x11_tooltip.hpp"
41 X11Factory::X11Factory( intf_thread_t *pIntf ): OSFactory( pIntf ),
42 m_pDisplay( NULL ), m_pTimerLoop( NULL ), m_dirSep( "/" )
48 X11Factory::~X11Factory()
55 bool X11Factory::init()
57 // Create the X11 display
58 m_pDisplay = new X11Display( getIntf() );
61 Display *pDisplay = m_pDisplay->getDisplay();
62 if( pDisplay == NULL )
64 // Initialization failed
68 // Create the timer loop
69 m_pTimerLoop = new X11TimerLoop( getIntf(),
70 ConnectionNumber( pDisplay ) );
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" );
82 OSGraphics *X11Factory::createOSGraphics( int width, int height )
84 return new X11Graphics( getIntf(), *m_pDisplay, width, height );
88 OSLoop *X11Factory::getOSLoop()
90 return X11Loop::instance( getIntf(), *m_pDisplay );
94 void X11Factory::destroyOSLoop()
96 X11Loop::destroy( getIntf() );
100 OSTimer *X11Factory::createOSTimer( const Callback &rCallback )
102 return new X11Timer( getIntf(), rCallback );
106 OSWindow *X11Factory::createOSWindow( GenericWindow &rWindow, bool dragDrop,
107 bool playOnDrop, OSWindow *pParent )
109 return new X11Window( getIntf(), rWindow, *m_pDisplay, dragDrop,
110 playOnDrop, (X11Window*)pParent );
114 OSTooltip *X11Factory::createOSTooltip()
116 return new X11Tooltip( getIntf(), *m_pDisplay );
120 int X11Factory::getScreenWidth() const
122 Display *pDisplay = m_pDisplay->getDisplay();
123 int screen = DefaultScreen( pDisplay );
124 return DisplayWidth( pDisplay, screen );
128 int X11Factory::getScreenHeight() const
130 Display *pDisplay = m_pDisplay->getDisplay();
131 int screen = DefaultScreen( pDisplay );
132 return DisplayHeight( pDisplay, screen );
136 Rect X11Factory::getWorkArea() const
139 return Rect( 0, 0, getScreenWidth(), getScreenHeight() );
143 void X11Factory::getMousePos( int &rXPos, int &rYPos ) const
145 Window rootReturn, childReturn;
149 Display *pDisplay = m_pDisplay->getDisplay();
150 Window root = DefaultRootWindow( pDisplay );
151 XQueryPointer( pDisplay, root, &rootReturn, &childReturn,
152 &rXPos, &rYPos, &winx, &winy, &xmask );
156 void X11Factory::rmDir( const string &rPath )
161 dir = opendir( rPath.c_str() );
164 // Parse the directory and remove everything it contains
165 while( (file = readdir( dir )) )
168 string filename = file->d_name;
171 if( filename == "." || filename == ".." )
176 filename = rPath + "/" + filename;
178 if( !stat( filename.c_str(), &statbuf ) && statbuf.st_mode & S_IFDIR )
184 unlink( filename.c_str() );
188 // Close the directory
192 rmdir( rPath.c_str() );