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 *****************************************************************************/
33 #include "x11_factory.hpp"
34 #include "x11_display.hpp"
35 #include "x11_graphics.hpp"
36 #include "x11_loop.hpp"
37 #include "x11_popup.hpp"
38 #include "x11_timer.hpp"
39 #include "x11_window.hpp"
40 #include "x11_tooltip.hpp"
42 #include "../src/generic_window.hpp"
44 X11Factory::X11Factory( intf_thread_t *pIntf ): OSFactory( pIntf ),
45 m_pDisplay( NULL ), m_pTimerLoop( NULL ), m_dirSep( "/" )
51 X11Factory::~X11Factory()
58 bool X11Factory::init()
60 // make sure xlib is safe-thread
61 if( !vlc_xlib_init( VLC_OBJECT( getIntf() ) ) )
63 msg_Err( getIntf(), "initializing xlib for multi-threading failed" );
67 // Create the X11 display
68 m_pDisplay = new X11Display( getIntf() );
71 Display *pDisplay = m_pDisplay->getDisplay();
72 if( pDisplay == NULL )
74 // Initialization failed
78 // Create the timer loop
79 m_pTimerLoop = new X11TimerLoop( getIntf(),
80 ConnectionNumber( pDisplay ) );
82 // Initialize the resource path
83 char *datadir = config_GetUserDir( VLC_DATA_DIR );
84 m_resourcePath.push_back( (string)datadir + "/skins2" );
86 m_resourcePath.push_back( (string)"share/skins2" );
87 datadir = config_GetDataDir( getIntf() );
88 m_resourcePath.push_back( (string)datadir + "/skins2" );
95 OSGraphics *X11Factory::createOSGraphics( int width, int height )
97 return new X11Graphics( getIntf(), *m_pDisplay, width, height );
101 OSLoop *X11Factory::getOSLoop()
103 return X11Loop::instance( getIntf(), *m_pDisplay );
107 void X11Factory::destroyOSLoop()
109 X11Loop::destroy( getIntf() );
112 void X11Factory::minimize()
114 XIconifyWindow( m_pDisplay->getDisplay(), m_pDisplay->getMainWindow(),
115 DefaultScreen( m_pDisplay->getDisplay() ) );
118 void X11Factory::restore()
123 void X11Factory::addInTray()
128 void X11Factory::removeFromTray()
133 void X11Factory::addInTaskBar()
138 void X11Factory::removeFromTaskBar()
143 OSTimer *X11Factory::createOSTimer( CmdGeneric &rCmd )
145 return new X11Timer( getIntf(), rCmd );
149 OSWindow *X11Factory::createOSWindow( GenericWindow &rWindow, bool dragDrop,
150 bool playOnDrop, OSWindow *pParent,
151 GenericWindow::WindowType_t type )
153 return new X11Window( getIntf(), rWindow, *m_pDisplay, dragDrop,
154 playOnDrop, (X11Window*)pParent, type );
158 OSTooltip *X11Factory::createOSTooltip()
160 return new X11Tooltip( getIntf(), *m_pDisplay );
164 OSPopup *X11Factory::createOSPopup()
166 return new X11Popup( getIntf(), *m_pDisplay );
170 int X11Factory::getScreenWidth() const
172 Display *pDisplay = m_pDisplay->getDisplay();
173 int screen = DefaultScreen( pDisplay );
174 return DisplayWidth( pDisplay, screen );
178 int X11Factory::getScreenHeight() const
180 Display *pDisplay = m_pDisplay->getDisplay();
181 int screen = DefaultScreen( pDisplay );
182 return DisplayHeight( pDisplay, screen );
186 SkinsRect X11Factory::getWorkArea() const
189 return SkinsRect( 0, 0, getScreenWidth(), getScreenHeight() );
193 void X11Factory::getMousePos( int &rXPos, int &rYPos ) const
195 Window rootReturn, childReturn;
199 Display *pDisplay = m_pDisplay->getDisplay();
200 Window root = DefaultRootWindow( pDisplay );
201 XQueryPointer( pDisplay, root, &rootReturn, &childReturn,
202 &rXPos, &rYPos, &winx, &winy, &xmask );
206 void X11Factory::rmDir( const string &rPath )
211 char buf[NAME_MAX + 1];
216 dir = opendir( rPath.c_str() );
219 // Parse the directory and remove everything it contains
220 while( readdir_r( dir, &buf.ent, &file ) == 0 && file != NULL )
223 string filename = file->d_name;
226 if( filename == "." || filename == ".." )
231 filename = rPath + "/" + filename;
233 if( !stat( filename.c_str(), &statbuf ) && S_ISDIR(statbuf.st_mode) )
239 unlink( filename.c_str() );
243 // Close the directory
247 rmdir( rPath.c_str() );