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"
41 #include "../src/generic_window.hpp"
43 X11Factory::X11Factory( intf_thread_t *pIntf ): OSFactory( pIntf ),
44 m_pDisplay( NULL ), m_pTimerLoop( NULL ), m_dirSep( "/" )
50 X11Factory::~X11Factory()
57 bool X11Factory::init()
59 // make sure xlib is safe-thread
61 msg_Err( getIntf(), "initializing xlib for multi-threading failed" );
63 // Create the X11 display
64 m_pDisplay = new X11Display( getIntf() );
67 Display *pDisplay = m_pDisplay->getDisplay();
68 if( pDisplay == NULL )
70 // Initialization failed
74 // Create the timer loop
75 m_pTimerLoop = new X11TimerLoop( getIntf(),
76 ConnectionNumber( pDisplay ) );
78 // Initialize the resource path
79 char *datadir = config_GetUserDir( VLC_DATA_DIR );
80 m_resourcePath.push_back( (string)datadir + "/skins2" );
82 m_resourcePath.push_back( (string)"share/skins2" );
83 m_resourcePath.push_back( (string)config_GetDataDir () + "/skins2" );
89 OSGraphics *X11Factory::createOSGraphics( int width, int height )
91 return new X11Graphics( getIntf(), *m_pDisplay, width, height );
95 OSLoop *X11Factory::getOSLoop()
97 return X11Loop::instance( getIntf(), *m_pDisplay );
101 void X11Factory::destroyOSLoop()
103 X11Loop::destroy( getIntf() );
106 void X11Factory::minimize()
108 XIconifyWindow( m_pDisplay->getDisplay(), m_pDisplay->getMainWindow(),
109 DefaultScreen( m_pDisplay->getDisplay() ) );
112 void X11Factory::restore()
117 void X11Factory::addInTray()
122 void X11Factory::removeFromTray()
127 void X11Factory::addInTaskBar()
132 void X11Factory::removeFromTaskBar()
137 OSTimer *X11Factory::createOSTimer( CmdGeneric &rCmd )
139 return new X11Timer( getIntf(), rCmd );
143 OSWindow *X11Factory::createOSWindow( GenericWindow &rWindow, bool dragDrop,
144 bool playOnDrop, OSWindow *pParent,
145 GenericWindow::WindowType_t type )
147 return new X11Window( getIntf(), rWindow, *m_pDisplay, dragDrop,
148 playOnDrop, (X11Window*)pParent, type );
152 OSTooltip *X11Factory::createOSTooltip()
154 return new X11Tooltip( getIntf(), *m_pDisplay );
158 OSPopup *X11Factory::createOSPopup()
160 return new X11Popup( getIntf(), *m_pDisplay );
164 int X11Factory::getScreenWidth() const
166 Display *pDisplay = m_pDisplay->getDisplay();
167 int screen = DefaultScreen( pDisplay );
168 return DisplayWidth( pDisplay, screen );
172 int X11Factory::getScreenHeight() const
174 Display *pDisplay = m_pDisplay->getDisplay();
175 int screen = DefaultScreen( pDisplay );
176 return DisplayHeight( pDisplay, screen );
180 SkinsRect X11Factory::getWorkArea() const
183 return SkinsRect( 0, 0, getScreenWidth(), getScreenHeight() );
187 void X11Factory::getMousePos( int &rXPos, int &rYPos ) const
189 Window rootReturn, childReturn;
193 Display *pDisplay = m_pDisplay->getDisplay();
194 Window root = DefaultRootWindow( pDisplay );
195 XQueryPointer( pDisplay, root, &rootReturn, &childReturn,
196 &rXPos, &rYPos, &winx, &winy, &xmask );
200 void X11Factory::rmDir( const string &rPath )
205 dir = opendir( rPath.c_str() );
208 // Parse the directory and remove everything it contains
209 while( (file = readdir( dir )) )
212 string filename = file->d_name;
215 if( filename == "." || filename == ".." )
220 filename = rPath + "/" + filename;
222 if( !stat( filename.c_str(), &statbuf ) && statbuf.st_mode & S_IFDIR )
228 unlink( filename.c_str() );
232 // Close the directory
236 rmdir( rPath.c_str() );