]> git.sesse.net Git - vlc/blob - modules/gui/skins/x11/x11_api.cpp
* modules/gui/skins/x11/x11_api.cpp: fixed OSAPI_GetScreenSize
[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.5 2003/06/01 22:11:24 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 extern intf_thread_t *g_pIntf;  // ugly, but it's not my fault ;)
41
42 //---------------------------------------------------------------------------
43 // Event API
44 //---------------------------------------------------------------------------
45 void OSAPI_SendMessage( SkinWindow *win, unsigned int message, unsigned int param1,
46                         long param2 )
47 {
48 /*    if( win == NULL )
49         SendMessage( NULL, message, param1, param2 );
50     else
51         SendMessage( ( (Win32Window *)win )->GetHandle(), message, param1,
52                      param2 );*/
53 }
54 //---------------------------------------------------------------------------
55 void OSAPI_PostMessage( SkinWindow *win, unsigned int message, unsigned int param1,
56                         long param2 )
57 {
58     XEvent event;
59
60     event.type = ClientMessage;
61     event.xclient.display = g_pIntf->p_sys->display;
62     event.xclient.send_event = 0;
63     event.xclient.message_type = NULL;
64     event.xclient.format = 32;
65     event.xclient.data.l[0] = message;
66     event.xclient.data.l[1] = param1;
67     event.xclient.data.l[2] = param2;
68     
69     if( win == NULL )
70     {
71         // broadcast message
72         event.xclient.window = g_pIntf->p_sys->mainWin;
73     }
74     else
75     {
76         event.xclient.window = (( X11Window *)win)->GetHandle();
77     }
78     XLOCK;
79     XSendEvent( g_pIntf->p_sys->display, event.xclient.window, False, 0, 
80                 &event );
81     XUNLOCK;
82 }
83 //---------------------------------------------------------------------------
84
85
86
87
88 //---------------------------------------------------------------------------
89 // Graphic API
90 //---------------------------------------------------------------------------
91 int OSAPI_GetNonTransparentColor( int c )
92 {
93 /*    // Get desktop device context
94     HDC DeskDC = GetWindowDC( GetDesktopWindow() );
95
96     // If color is black or color is same as black wether pixel color depth
97     if( c == 0 || SetPixel( DeskDC, 0, 0, c ) == 0 )
98     {
99         if( GetDeviceCaps( DeskDC, BITSPIXEL ) < 24 )
100             c = RGB(8, 0, 0);
101         else
102             c = RGB(1, 0, 0);
103     }
104     ReleaseDC( GetDesktopWindow(), DeskDC );
105     return c;*/
106 }
107 //---------------------------------------------------------------------------
108
109
110
111
112 //---------------------------------------------------------------------------
113 // General
114 //---------------------------------------------------------------------------
115 int OSAPI_GetTime()
116 {
117 /*    GTimeVal time;
118     g_get_current_time( &time );
119     return ( time.tv_sec * 1000 + time.tv_usec / 1000 );*/
120 }
121 //---------------------------------------------------------------------------
122 void OSAPI_GetScreenSize( int &w, int &h )
123 {
124     Display *display = g_pIntf->p_sys->display;
125     int screen = DefaultScreen( display );
126     w = DisplayWidth( display, screen );
127     h = DisplayHeight( display, screen );
128 }
129 //---------------------------------------------------------------------------
130 void OSAPI_GetMousePos( int &x, int &y )
131 {
132     Window rootReturn, childReturn;
133     int rootx, rooty;
134     int winx, winy;
135     unsigned int xmask;
136     
137     Window root = DefaultRootWindow( g_pIntf->p_sys->display );
138     XLOCK;
139     XQueryPointer( g_pIntf->p_sys->display, root, &rootReturn, &childReturn, 
140                    &rootx, &rooty, &winx, &winy, &xmask );
141     XUNLOCK;
142     x = rootx;
143     y = rooty;
144 }
145 //---------------------------------------------------------------------------
146 string OSAPI_GetWindowTitle( SkinWindow *win )
147 {
148     return ( (X11Window *)win )->GetName();
149 }
150 //---------------------------------------------------------------------------
151 bool OSAPI_RmDir( string path )
152 {
153 /*    WIN32_FIND_DATA find;
154     string File;
155     string FindFiles = path + "\\*.*";
156     HANDLE handle    = FindFirstFile( (char *)FindFiles.c_str(), &find );
157
158     while( handle != INVALID_HANDLE_VALUE )
159     {
160         // If file is neither "." nor ".."
161         if( strcmp( find.cFileName, "." ) && strcmp( find.cFileName, ".." ) )
162         {
163             // Set file name
164             File = path + "\\" + (string)find.cFileName;
165
166             // If file is a directory, delete it recursively
167             if( find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
168             {
169                 OSAPI_RmDir( File );
170             }
171             // Else, it is a file so simply delete it
172             else
173             {
174                 DeleteFile( (char *)File.c_str() );
175             }
176         }
177
178         // If no more file in directory, exit while
179         if( !FindNextFile( handle, &find ) )
180             break;
181     }
182
183     // Now directory is empty so can be removed
184     FindClose( handle );
185     RemoveDirectory( (char *)path.c_str() );
186
187     return true;*/
188 }
189 //---------------------------------------------------------------------------
190
191 #endif