]> git.sesse.net Git - vlc/blob - modules/gui/skins/x11/x11_api.cpp
* tooltips are now updated during scrolling
[vlc] / modules / gui / skins / x11 / x11_api.cpp
1 /*****************************************************************************
2  * x11_api.cpp: Various x11-specific functions
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: x11_api.cpp,v 1.9 2003/06/09 22:02:13 asmax Exp $
6  *
7  * Authors: Cyril Deguet  <asmax@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111,
22  * USA.
23  *****************************************************************************/
24
25 #ifdef X11_SKINS
26
27 //--- X11 -------------------------------------------------------------------
28 #include <X11/Xlib.h>
29
30 //--- SKIN ------------------------------------------------------------------
31 #include <vlc/intf.h>
32 #include "../src/skin_common.h"
33 #include "../src/theme.h"
34 #include "../src/window.h"
35 #include "../os_theme.h"
36 #include "../os_window.h"
37 #include "../os_api.h"
38 #include "../src/event.h"       // for MAX_PARAM_SIZE
39
40 #include <unistd.h>                                       // unkink and rmdir
41 #include <sys/types.h>
42 #include <sys/stat.h>                                               // stat()
43 #include <sys/time.h>                                       // gettimeofday()
44 #include <dirent.h>                                  // opendir() and friends
45
46 extern intf_thread_t *g_pIntf;  // ugly, but it's not my fault ;)
47
48 //---------------------------------------------------------------------------
49 // Event API
50 //---------------------------------------------------------------------------
51 void OSAPI_SendMessage( SkinWindow *win, unsigned int message,
52                         unsigned int param1, long param2 )
53 {
54 }
55 //---------------------------------------------------------------------------
56 void OSAPI_PostMessage( SkinWindow *win, unsigned int message,
57                         unsigned int param1, long param2 )
58 {
59     XEvent event;
60
61     event.type = ClientMessage;
62     event.xclient.display = g_pIntf->p_sys->display;
63     event.xclient.send_event = 0;
64     event.xclient.message_type = 0;
65     event.xclient.format = 32;
66     event.xclient.data.l[0] = message;
67     event.xclient.data.l[1] = param1;
68     event.xclient.data.l[2] = param2;
69     
70     if( win == NULL )
71     {
72         // broadcast message
73         event.xclient.window = g_pIntf->p_sys->mainWin;
74     }
75     else
76     {
77         event.xclient.window = (( X11Window *)win)->GetHandle();
78     }
79     XLOCK;
80     XSendEvent( g_pIntf->p_sys->display, event.xclient.window, False, 0, 
81                 &event );
82     XUNLOCK;
83 }
84 //---------------------------------------------------------------------------
85
86
87
88
89 //---------------------------------------------------------------------------
90 // Graphic API
91 //---------------------------------------------------------------------------
92 int OSAPI_GetNonTransparentColor( int c )
93 {
94     return ( c < 10 ? 10 : c );
95 }
96 //---------------------------------------------------------------------------
97
98
99
100
101 //---------------------------------------------------------------------------
102 // General
103 //---------------------------------------------------------------------------
104 int OSAPI_GetTime()
105 {
106     struct timeval time;
107     gettimeofday( &time, NULL );
108     return( (time.tv_sec&0xffffff) * 1000 + time.tv_usec / 1000 );
109 }
110 //---------------------------------------------------------------------------
111 void OSAPI_GetScreenSize( int &w, int &h )
112 {
113     Display *display = g_pIntf->p_sys->display;
114     int screen = DefaultScreen( display );
115     w = DisplayWidth( display, screen );
116     h = DisplayHeight( display, screen );
117 }
118 //---------------------------------------------------------------------------
119 void OSAPI_GetMousePos( int &x, int &y )
120 {
121     Window rootReturn, childReturn;
122     int rootx, rooty;
123     int winx, winy;
124     unsigned int xmask;
125     
126     Window root = DefaultRootWindow( g_pIntf->p_sys->display );
127     XLOCK;
128     XQueryPointer( g_pIntf->p_sys->display, root, &rootReturn, &childReturn, 
129                    &rootx, &rooty, &winx, &winy, &xmask );
130     XUNLOCK;
131     x = rootx;
132     y = rooty;
133 }
134 //---------------------------------------------------------------------------
135 string OSAPI_GetWindowTitle( SkinWindow *win )
136 {
137     return ( (X11Window *)win )->GetName();
138 }
139 //---------------------------------------------------------------------------
140 bool OSAPI_RmDir( string path )
141 {
142     struct dirent *file;
143     DIR *dir;
144
145     dir = opendir( path.c_str() );
146     if( !dir ) return false;
147
148     /* Parse the directory and remove everything it contains. */
149     while( (file = readdir( dir )) )
150     {
151         struct stat statbuf;
152         string filename;
153
154         /* Skip "." and ".." */
155         if( !*file->d_name || *file->d_name == '.' ||
156             (!*(file->d_name+1) && *file->d_name == '.' &&
157              *(file->d_name+1) == '.') )
158         {
159             continue;
160         }
161
162         filename += path + "/";
163         filename += file->d_name;
164
165         if( !stat( filename.c_str(), &statbuf ) && statbuf.st_mode & S_IFDIR )
166         {
167             OSAPI_RmDir( filename );
168         }
169         else
170         {
171             unlink( filename.c_str() );
172         }
173     }
174
175     /* Close the directory */
176     closedir( dir );
177
178     rmdir( path.c_str() );
179
180     return true;
181 }
182 //---------------------------------------------------------------------------
183
184 #endif