1 /*****************************************************************************
2 * x11_api.cpp: Various x11-specific functions
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: x11_api.cpp,v 1.10 2003/12/22 14:32:56 sam Exp $
7 * Author: Cyril Deguet <asmax@videolan.org>
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.
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.
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,
23 *****************************************************************************/
27 //--- X11 -------------------------------------------------------------------
30 //--- SKIN ------------------------------------------------------------------
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
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
46 extern intf_thread_t *g_pIntf; // ugly, but it's not my fault ;)
48 //---------------------------------------------------------------------------
50 //---------------------------------------------------------------------------
51 void OSAPI_SendMessage( SkinWindow *win, unsigned int message,
52 unsigned int param1, long param2 )
55 //---------------------------------------------------------------------------
56 void OSAPI_PostMessage( SkinWindow *win, unsigned int message,
57 unsigned int param1, long param2 )
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;
73 event.xclient.window = g_pIntf->p_sys->mainWin;
77 event.xclient.window = (( X11Window *)win)->GetHandle();
80 XSendEvent( g_pIntf->p_sys->display, event.xclient.window, False, 0,
84 //---------------------------------------------------------------------------
89 //---------------------------------------------------------------------------
91 //---------------------------------------------------------------------------
92 int OSAPI_GetNonTransparentColor( int c )
94 return ( c < 10 ? 10 : c );
96 //---------------------------------------------------------------------------
101 //---------------------------------------------------------------------------
103 //---------------------------------------------------------------------------
107 gettimeofday( &time, NULL );
108 return( (time.tv_sec&0xffffff) * 1000 + time.tv_usec / 1000 );
110 //---------------------------------------------------------------------------
111 void OSAPI_GetScreenSize( int &w, int &h )
113 Display *display = g_pIntf->p_sys->display;
114 int screen = DefaultScreen( display );
115 w = DisplayWidth( display, screen );
116 h = DisplayHeight( display, screen );
118 //---------------------------------------------------------------------------
119 void OSAPI_GetMousePos( int &x, int &y )
121 Window rootReturn, childReturn;
126 Window root = DefaultRootWindow( g_pIntf->p_sys->display );
128 XQueryPointer( g_pIntf->p_sys->display, root, &rootReturn, &childReturn,
129 &rootx, &rooty, &winx, &winy, &xmask );
134 //---------------------------------------------------------------------------
135 string OSAPI_GetWindowTitle( SkinWindow *win )
137 return ( (X11Window *)win )->GetName();
139 //---------------------------------------------------------------------------
140 bool OSAPI_RmDir( string path )
145 dir = opendir( path.c_str() );
146 if( !dir ) return false;
148 /* Parse the directory and remove everything it contains. */
149 while( (file = readdir( dir )) )
154 /* Skip "." and ".." */
155 if( !*file->d_name || *file->d_name == '.' ||
156 (!*(file->d_name+1) && *file->d_name == '.' &&
157 *(file->d_name+1) == '.') )
162 filename += path + "/";
163 filename += file->d_name;
165 if( !stat( filename.c_str(), &statbuf ) && statbuf.st_mode & S_IFDIR )
167 OSAPI_RmDir( filename );
171 unlink( filename.c_str() );
175 /* Close the directory */
178 rmdir( path.c_str() );
182 //---------------------------------------------------------------------------