x11_factory.cpp 5.26 KB
Newer Older
1
2
3
/*****************************************************************************
 * x11_factory.cpp
 *****************************************************************************
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
11
12
13
14
15
16
17
18
19
20
21
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
dionoea's avatar
dionoea committed
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23
24
25
26
27
28
29
30
31
32
33
34
35
 *****************************************************************************/

#ifdef X11_SKINS

#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>
#include <X11/Xlib.h>

#include "x11_factory.hpp"
#include "x11_display.hpp"
#include "x11_graphics.hpp"
#include "x11_loop.hpp"
zorglub's avatar
zorglub committed
36
#include "x11_popup.hpp"
37
38
39
40
41
#include "x11_timer.hpp"
#include "x11_window.hpp"
#include "x11_tooltip.hpp"


42
X11Factory::X11Factory( intf_thread_t *pIntf ): OSFactory( pIntf ),
43
    m_pDisplay( NULL ), m_pTimerLoop( NULL ), m_dirSep( "/" )
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{
    // see init()
}


X11Factory::~X11Factory()
{
    delete m_pTimerLoop;
    delete m_pDisplay;
}


bool X11Factory::init()
{
    // Create the X11 display
    m_pDisplay = new X11Display( getIntf() );

    // Get the display
    Display *pDisplay = m_pDisplay->getDisplay();
    if( pDisplay == NULL )
    {
        // Initialization failed
        return false;
    }

    // Create the timer loop
    m_pTimerLoop = new X11TimerLoop( getIntf(),
                                     ConnectionNumber( pDisplay ) );

73
    // Initialize the resource path
74
75
    m_resourcePath.push_back( (string)getIntf()->p_libvlc->psz_datadir +
                              + "/skins2" );
76
    m_resourcePath.push_back( (string)"share/skins2" );
77
    m_resourcePath.push_back( (string)config_GetDataDir () + "/skins2" );
78

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
    return true;
}


OSGraphics *X11Factory::createOSGraphics( int width, int height )
{
    return new X11Graphics( getIntf(), *m_pDisplay, width, height );
}


OSLoop *X11Factory::getOSLoop()
{
    return X11Loop::instance( getIntf(), *m_pDisplay );
}


void X11Factory::destroyOSLoop()
{
    X11Loop::destroy( getIntf() );
}

100
101
102
103
104
void X11Factory::minimize()
{
    XIconifyWindow( m_pDisplay->getDisplay(), m_pDisplay->getMainWindow(),
                    DefaultScreen( m_pDisplay->getDisplay() ) );
}
105

106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
void X11Factory::restore()
{
    // TODO
}

void X11Factory::addInTray()
{
    // TODO
}

void X11Factory::removeFromTray()
{
    // TODO
}

121
122
123
124
125
126
127
128
129
130
void X11Factory::addInTaskBar()
{
    // TODO
}

void X11Factory::removeFromTaskBar()
{
    // TODO
}

131
OSTimer *X11Factory::createOSTimer( CmdGeneric &rCmd )
132
{
133
    return new X11Timer( getIntf(), rCmd );
134
135
136
137
}


OSWindow *X11Factory::createOSWindow( GenericWindow &rWindow, bool dragDrop,
138
                                      bool playOnDrop, OSWindow *pParent )
139
140
{
    return new X11Window( getIntf(), rWindow, *m_pDisplay, dragDrop,
141
                          playOnDrop, (X11Window*)pParent );
142
143
144
145
146
147
148
149
150
}


OSTooltip *X11Factory::createOSTooltip()
{
    return new X11Tooltip( getIntf(), *m_pDisplay );
}


151
152
153
154
155
156
OSPopup *X11Factory::createOSPopup()
{
    return new X11Popup( getIntf(), *m_pDisplay );
}


157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
int X11Factory::getScreenWidth() const
{
    Display *pDisplay = m_pDisplay->getDisplay();
    int screen = DefaultScreen( pDisplay );
    return DisplayWidth( pDisplay, screen );
}


int X11Factory::getScreenHeight() const
{
    Display *pDisplay = m_pDisplay->getDisplay();
    int screen = DefaultScreen( pDisplay );
    return DisplayHeight( pDisplay, screen );
}


173
SkinsRect X11Factory::getWorkArea() const
174
175
{
    // XXX
176
    return SkinsRect( 0, 0, getScreenWidth(), getScreenHeight() );
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
}


void X11Factory::getMousePos( int &rXPos, int &rYPos ) const
{
    Window rootReturn, childReturn;
    int winx, winy;
    unsigned int xmask;

    Display *pDisplay = m_pDisplay->getDisplay();
    Window root = DefaultRootWindow( pDisplay );
    XQueryPointer( pDisplay, root, &rootReturn, &childReturn,
                   &rXPos, &rYPos, &winx, &winy, &xmask );
}


void X11Factory::rmDir( const string &rPath )
{
    struct dirent *file;
    DIR *dir;

    dir = opendir( rPath.c_str() );
    if( !dir ) return;

    // Parse the directory and remove everything it contains
    while( (file = readdir( dir )) )
    {
        struct stat statbuf;
        string filename = file->d_name;

        // Skip "." and ".."
        if( filename == "." || filename == ".." )
        {
            continue;
        }

        filename = rPath + "/" + filename;

        if( !stat( filename.c_str(), &statbuf ) && statbuf.st_mode & S_IFDIR )
        {
            rmDir( filename );
        }
        else
        {
            unlink( filename.c_str() );
        }
    }

    // Close the directory
    closedir( dir );

    // And delete it
    rmdir( rPath.c_str() );
}


#endif