Mercurial > mplayer.hg
annotate gui/wm/ws.c @ 31386:2c34afe8f37f
Add #include for unrar_exec.h instead of declaring unrar_executable extern.
author | diego |
---|---|
date | Thu, 17 Jun 2010 09:49:41 +0000 |
parents | e45b8fb721fd |
children | 9e6fdede8ece |
rev | line source |
---|---|
26458 | 1 /* |
2 * AutoSpace Window System for Linux/Win32 v0.85 | |
3 * written by pontscho/fresh!mindworkz | |
4 * | |
5 * This file is part of MPlayer. | |
6 * | |
7 * MPlayer is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * MPlayer is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License along | |
18 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
20 */ | |
23077 | 21 |
22 #include <X11/Xlib.h> | |
23 #include <X11/Xproto.h> | |
24 #include <X11/Xutil.h> | |
25 #include <X11/keysym.h> | |
26 #include <X11/Xatom.h> | |
27 | |
28 #include <stdio.h> | |
29 #include <stdlib.h> | |
30 #include <string.h> | |
31 #include <unistd.h> | |
32 #include <errno.h> | |
33 | |
34 #include <inttypes.h> | |
35 | |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
23795
diff
changeset
|
36 #include "config.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
23795
diff
changeset
|
37 #include "libvo/x11_common.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
23795
diff
changeset
|
38 #include "libvo/video_out.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
23795
diff
changeset
|
39 #include "cpudetect.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
23795
diff
changeset
|
40 #include "libswscale/swscale.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
23795
diff
changeset
|
41 #include "libswscale/rgb2rgb.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
23795
diff
changeset
|
42 #include "libmpcodecs/vf_scale.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
23795
diff
changeset
|
43 #include "mp_msg.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
23795
diff
changeset
|
44 #include "help_mp.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
23795
diff
changeset
|
45 #include "mplayer.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
23795
diff
changeset
|
46 #include "mpbswap.h" |
23077 | 47 #include "ws.h" |
48 #include "wsxdnd.h" | |
49 | |
50 #include <X11/extensions/XShm.h> | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
51 #ifdef CONFIG_XSHAPE |
23077 | 52 #include <X11/extensions/shape.h> |
53 #endif | |
54 | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
55 #ifdef CONFIG_XINERAMA |
23077 | 56 #include <X11/extensions/Xinerama.h> |
57 #endif | |
58 | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
59 #ifdef CONFIG_XF86VM |
23077 | 60 #include <X11/extensions/xf86vmode.h> |
61 #endif | |
62 | |
63 #include <sys/ipc.h> | |
64 #include <sys/shm.h> | |
65 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
66 #undef ENABLE_DPMS |
23077 | 67 |
68 typedef struct | |
69 { | |
70 unsigned long flags; | |
71 unsigned long functions; | |
72 unsigned long decorations; | |
73 long input_mode; | |
74 unsigned long status; | |
75 } MotifWmHints; | |
76 | |
77 Atom wsMotifHints; | |
78 | |
79 int wsMaxX = 0; // Screen width. | |
80 int wsMaxY = 0; // Screen height. | |
81 int wsOrgX = 0; // Screen origin x. | |
82 int wsOrgY = 0; // Screen origin y. | |
83 | |
84 Display * wsDisplay; | |
85 int wsScreen; | |
86 Window wsRootWin; | |
87 XEvent wsEvent; | |
88 int wsWindowDepth; | |
89 GC wsHGC; | |
90 MotifWmHints wsMotifWmHints; | |
91 Atom wsTextProperlyAtom = None; | |
92 int wsLayer = 0; | |
93 | |
94 int wsDepthOnScreen = 0; | |
95 int wsRedMask = 0; | |
96 int wsGreenMask = 0; | |
97 int wsBlueMask = 0; | |
98 int wsOutMask = 0; | |
23453
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
99 int wsNonNativeOrder = 0; |
23077 | 100 |
101 int wsTrue = True; | |
102 | |
103 #define wsWLCount 5 | |
104 wsTWindow * wsWindowList[wsWLCount] = { NULL,NULL,NULL,NULL,NULL }; | |
105 | |
106 unsigned long wsKeyTable[512]; | |
107 | |
108 int wsUseXShm = 1; | |
109 int wsUseXShape = 1; | |
110 | |
31325 | 111 static int wsSearch( Window win ) |
112 { | |
113 int i; | |
114 for ( i=0;i<wsWLCount;i++ ) if ( wsWindowList[i] && wsWindowList[i]->WindowID == win ) return i; | |
115 return -1; | |
116 } | |
117 | |
23077 | 118 |
119 // --- | |
120 | |
121 #define PACK_RGB16(r,g,b,pixel) pixel=(b>>3);\ | |
122 pixel<<=6;\ | |
123 pixel|=(g>>2);\ | |
124 pixel<<=5;\ | |
125 pixel|=(r>>3) | |
126 | |
127 #define PACK_RGB15(r,g,b,pixel) pixel=(b>>3);\ | |
128 pixel<<=5;\ | |
129 pixel|=(g>>3);\ | |
130 pixel<<=5;\ | |
131 pixel|=(r>>3) | |
132 | |
133 typedef void(*wsTConvFunc)( const unsigned char * in_pixels, unsigned char * out_pixels, unsigned num_pixels ); | |
134 wsTConvFunc wsConvFunc = NULL; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
135 |
30535
016e5fc1dead
GUI: Mark functions that are not used outside their files as static.
diego
parents:
30218
diff
changeset
|
136 static void rgb32torgb32( const unsigned char * src, unsigned char * dst,unsigned int src_size ) |
23077 | 137 { memcpy( dst,src,src_size ); } |
138 | |
139 // --- | |
140 | |
141 #define MWM_HINTS_FUNCTIONS (1L << 0) | |
142 #define MWM_HINTS_DECORATIONS (1L << 1) | |
143 #define MWM_HINTS_INPUT_MODE (1L << 2) | |
144 #define MWM_HINTS_STATUS (1L << 3) | |
145 | |
146 #define MWM_FUNC_ALL (1L << 0) | |
147 #define MWM_FUNC_RESIZE (1L << 1) | |
148 #define MWM_FUNC_MOVE (1L << 2) | |
149 #define MWM_FUNC_MINIMIZE (1L << 3) | |
150 #define MWM_FUNC_MAXIMIZE (1L << 4) | |
151 #define MWM_FUNC_CLOSE (1L << 5) | |
152 | |
153 #define MWM_DECOR_ALL (1L << 0) | |
154 #define MWM_DECOR_BORDER (1L << 1) | |
155 #define MWM_DECOR_RESIZEH (1L << 2) | |
156 #define MWM_DECOR_TITLE (1L << 3) | |
157 #define MWM_DECOR_MENU (1L << 4) | |
158 #define MWM_DECOR_MINIMIZE (1L << 5) | |
159 #define MWM_DECOR_MAXIMIZE (1L << 6) | |
160 | |
161 #define MWM_INPUT_MODELESS 0 | |
162 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 | |
163 #define MWM_INPUT_SYSTEM_MODAL 2 | |
164 #define MWM_INPUT_FULL_APPLICATION_MODAL 3 | |
165 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL | |
166 | |
167 #define MWM_TEAROFF_WINDOW (1L<<0) | |
168 | |
169 void wsWindowDecoration( wsTWindow * win,long d ) | |
170 { | |
171 wsMotifHints=XInternAtom( wsDisplay,"_MOTIF_WM_HINTS",0 ); | |
172 if ( wsMotifHints == None ) return; | |
173 | |
174 memset( &wsMotifWmHints,0,sizeof( MotifWmHints ) ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
175 wsMotifWmHints.flags=MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; |
23077 | 176 if ( d ) |
177 { | |
178 wsMotifWmHints.functions=MWM_FUNC_MOVE | MWM_FUNC_CLOSE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE; | |
179 wsMotifWmHints.decorations=MWM_DECOR_ALL; | |
180 } | |
181 XChangeProperty( wsDisplay,win->WindowID,wsMotifHints,wsMotifHints,32, | |
182 PropModeReplace,(unsigned char *)&wsMotifWmHints,5 ); | |
183 } | |
184 | |
185 // ---------------------------------------------------------------------------------------------- | |
186 // Init X Window System. | |
187 // ---------------------------------------------------------------------------------------------- | |
188 | |
30535
016e5fc1dead
GUI: Mark functions that are not used outside their files as static.
diego
parents:
30218
diff
changeset
|
189 static int wsErrorHandler( Display * dpy, XErrorEvent * Event ) |
23077 | 190 { |
191 char type[128]; | |
192 XGetErrorText( wsDisplay,Event->error_code,type,128 ); | |
193 fprintf(stderr,"[ws] Error in display.\n"); | |
194 fprintf(stderr,"[ws] Error code: %d ( %s )\n",Event->error_code,type ); | |
195 fprintf(stderr,"[ws] Request code: %d\n",Event->request_code ); | |
196 fprintf(stderr,"[ws] Minor code: %d\n",Event->minor_code ); | |
197 fprintf(stderr,"[ws] Modules: %s\n",current_module?current_module:"(NULL)" ); | |
31314
c69ecf7d80a4
Gui: Do not just exit on X error, just ignoring problems is already
reimar
parents:
31006
diff
changeset
|
198 return 0; |
23077 | 199 } |
200 | |
201 void wsXInit( void* mDisplay ) | |
202 { | |
203 int eventbase; | |
204 int errorbase; | |
205 | |
206 if(mDisplay){ | |
207 wsDisplay=mDisplay; | |
208 } else { | |
209 char * DisplayName = ":0.0"; | |
210 if ( getenv( "DISPLAY" ) ) DisplayName=getenv( "DISPLAY" ); | |
211 wsDisplay=XOpenDisplay( DisplayName ); | |
212 if ( !wsDisplay ) | |
213 { | |
214 mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_CouldNotOpenDisplay ); | |
215 exit( 0 ); | |
216 } | |
217 } | |
218 | |
31323
c674bb16fa6d
Install error handler as early as possible to avoid crashing.
reimar
parents:
31314
diff
changeset
|
219 XSetErrorHandler( wsErrorHandler ); |
c674bb16fa6d
Install error handler as early as possible to avoid crashing.
reimar
parents:
31314
diff
changeset
|
220 |
23077 | 221 /* enable DND atoms */ |
222 wsXDNDInitialize(); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
223 |
23077 | 224 { /* on remote display XShm will be disabled - LGB */ |
225 char *dispname=DisplayString(wsDisplay); | |
226 int localdisp=1; | |
227 if (dispname&&*dispname!=':') { | |
228 localdisp=0; | |
229 wsUseXShm=0; | |
230 } | |
231 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[ws] display name: %s => %s display.\n",dispname,localdisp?"local":"REMOTE"); | |
232 if (!localdisp) mp_msg( MSGT_GPLAYER,MSGL_V,MSGTR_WS_RemoteDisplay ); | |
233 } | |
234 | |
235 if ( !XShmQueryExtension( wsDisplay ) ) | |
236 { | |
237 mp_msg( MSGT_GPLAYER,MSGL_ERR,MSGTR_WS_NoXshm ); | |
238 wsUseXShm=0; | |
239 } | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
240 #ifdef CONFIG_XSHAPE |
23077 | 241 if ( !XShapeQueryExtension( wsDisplay,&eventbase,&errorbase ) ) |
242 { | |
243 mp_msg( MSGT_GPLAYER,MSGL_ERR,MSGTR_WS_NoXshape ); | |
244 wsUseXShape=0; | |
245 } | |
246 #else | |
247 wsUseXShape=0; | |
248 #endif | |
249 | |
250 XSynchronize( wsDisplay,True ); | |
251 | |
252 wsScreen=DefaultScreen( wsDisplay ); | |
253 wsRootWin=RootWindow( wsDisplay,wsScreen ); | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
254 #ifdef CONFIG_XF86VM |
23077 | 255 { |
256 int clock; | |
257 XF86VidModeModeLine modeline; | |
258 | |
259 XF86VidModeGetModeLine( wsDisplay,wsScreen,&clock ,&modeline ); | |
260 wsMaxX=modeline.hdisplay; | |
261 wsMaxY=modeline.vdisplay; | |
262 } | |
263 #endif | |
264 { | |
265 wsOrgX = wsOrgY = 0; | |
266 if ( !wsMaxX ) | |
267 wsMaxX=DisplayWidth( wsDisplay,wsScreen ); | |
268 if ( !wsMaxY ) | |
269 wsMaxY=DisplayHeight( wsDisplay,wsScreen ); | |
270 } | |
271 vo_screenwidth = wsMaxX; vo_screenheight = wsMaxY; | |
272 xinerama_x = wsOrgX; xinerama_y = wsOrgY; | |
273 update_xinerama_info(); | |
274 wsMaxX = vo_screenwidth; wsMaxY = vo_screenheight; | |
275 wsOrgX = xinerama_x; wsOrgY = xinerama_y; | |
276 | |
277 wsGetDepthOnScreen(); | |
278 #ifdef DEBUG | |
279 { | |
280 int minor,major,shp; | |
281 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] Screen depth: %d\n",wsDepthOnScreen ); | |
282 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] size: %dx%d\n",wsMaxX,wsMaxY ); | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
283 #ifdef CONFIG_XINERAMA |
23077 | 284 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] origin: +%d+%d\n",wsOrgX,wsOrgY ); |
285 #endif | |
286 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] red mask: 0x%x\n",wsRedMask ); | |
287 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] green mask: 0x%x\n",wsGreenMask ); | |
288 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] blue mask: 0x%x\n",wsBlueMask ); | |
289 if ( wsUseXShm ) | |
290 { | |
291 XShmQueryVersion( wsDisplay,&major,&minor,&shp ); | |
292 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] XShm version is %d.%d\n",major,minor ); | |
293 } | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
294 #ifdef CONFIG_XSHAPE |
23077 | 295 if ( wsUseXShape ) |
296 { | |
297 XShapeQueryVersion( wsDisplay,&major,&minor ); | |
298 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] XShape version is %d.%d\n",major,minor ); | |
299 } | |
300 #endif | |
301 } | |
302 #endif | |
303 wsOutMask=wsGetOutMask(); | |
304 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[ws] Initialized converter: " ); | |
305 sws_rgb2rgb_init(get_sws_cpuflags()); | |
306 switch ( wsOutMask ) | |
307 { | |
308 case wsRGB32: | |
309 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to rgb32\n" ); | |
310 wsConvFunc=rgb32torgb32; | |
311 break; | |
312 case wsBGR32: | |
313 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to bgr32\n" ); | |
314 wsConvFunc=rgb32tobgr32; | |
315 break; | |
316 case wsRGB24: | |
317 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to rgb24\n" ); | |
318 wsConvFunc=rgb32to24; | |
319 break; | |
320 case wsBGR24: | |
321 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to bgr24\n" ); | |
322 wsConvFunc=rgb32tobgr24; | |
323 break; | |
324 case wsRGB16: | |
325 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to rgb16\n" ); | |
326 wsConvFunc=rgb32to16; | |
327 break; | |
328 case wsBGR16: | |
329 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to bgr16\n" ); | |
330 wsConvFunc=rgb32tobgr16; | |
331 break; | |
332 case wsRGB15: | |
333 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to rgb15\n" ); | |
334 wsConvFunc=rgb32to15; | |
335 break; | |
336 case wsBGR15: | |
337 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to bgr15\n" ); | |
338 wsConvFunc=rgb32tobgr15; | |
339 break; | |
340 } | |
341 } | |
342 | |
343 // ---------------------------------------------------------------------------------------------- | |
344 // Create window. | |
345 // X,Y : window position | |
346 // wX,wY : size of window | |
347 // bW : border width | |
348 // cV : visible mouse cursor on window | |
349 // D : visible frame, title, etc. | |
350 // sR : screen ratio | |
351 // ---------------------------------------------------------------------------------------------- | |
352 | |
353 XClassHint wsClassHint; | |
354 XTextProperty wsTextProperty; | |
355 Window LeaderWindow; | |
356 | |
357 void wsCreateWindow( wsTWindow * win,int X,int Y,int wX,int hY,int bW,int cV,unsigned char D,char * label ) | |
358 { | |
359 int depth; | |
360 | |
361 win->Property=D; | |
362 if ( D & wsShowFrame ) win->Decorations=1; | |
363 wsHGC=DefaultGC( wsDisplay,wsScreen ); | |
364 // The window position and size. | |
365 switch ( X ) | |
366 { | |
367 case -1: win->X=( wsMaxX / 2 ) - ( wX / 2 ) + wsOrgX; break; | |
368 case -2: win->X=wsMaxX - wX - 1 + wsOrgX; break; | |
369 default: win->X=X; break; | |
370 } | |
371 switch ( Y ) | |
372 { | |
373 case -1: win->Y=( wsMaxY / 2 ) - ( hY / 2 ) + wsOrgY; break; | |
374 case -2: win->Y=wsMaxY - hY - 1 + wsOrgY; break; | |
375 default: win->Y=Y; break; | |
376 } | |
377 win->Width=wX; | |
378 win->Height=hY; | |
379 win->OldX=win->X; | |
380 win->OldY=win->Y; | |
381 win->OldWidth=win->Width; | |
382 win->OldHeight=win->Height; | |
383 | |
384 // Border size for window. | |
385 win->BorderWidth=bW; | |
386 // Hide Mouse Cursor | |
387 win->wsCursor=None; | |
388 win->wsMouseEventType=cV; | |
389 win->wsCursorData[0]=0; | |
390 win->wsCursorPixmap=XCreateBitmapFromData( wsDisplay,wsRootWin,win->wsCursorData,1,1 ); | |
391 if ( !(cV & wsShowMouseCursor) ) win->wsCursor=XCreatePixmapCursor( wsDisplay,win->wsCursorPixmap,win->wsCursorPixmap,&win->wsColor,&win->wsColor,0,0 ); | |
392 | |
393 depth = vo_find_depth_from_visuals( wsDisplay,wsScreen,NULL ); | |
394 if ( depth < 15 ) | |
395 { | |
396 mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_ColorDepthTooLow ); | |
397 exit( 0 ); | |
398 } | |
399 XMatchVisualInfo( wsDisplay,wsScreen,depth,TrueColor,&win->VisualInfo ); | |
400 | |
401 // --- | |
402 win->AtomLeaderClient=XInternAtom( wsDisplay,"WM_CLIENT_LEADER",False ); | |
403 win->AtomDeleteWindow=XInternAtom( wsDisplay,"WM_DELETE_WINDOW",False ); | |
404 win->AtomTakeFocus=XInternAtom( wsDisplay,"WM_TAKE_FOCUS",False ); | |
405 win->AtomRolle=XInternAtom( wsDisplay,"WM_WINDOW_ROLE",False ); | |
406 win->AtomWMSizeHint=XInternAtom( wsDisplay,"WM_SIZE_HINT",False ); | |
407 win->AtomWMNormalHint=XInternAtom( wsDisplay,"WM_NORMAL_HINT",False ); | |
408 win->AtomProtocols=XInternAtom( wsDisplay,"WM_PROTOCOLS",False ); | |
409 win->AtomsProtocols[0]=win->AtomDeleteWindow; | |
410 win->AtomsProtocols[1]=win->AtomTakeFocus; | |
411 win->AtomsProtocols[2]=win->AtomRolle; | |
412 // --- | |
413 | |
414 win->WindowAttrib.background_pixel=BlackPixel( wsDisplay,wsScreen ); | |
415 win->WindowAttrib.border_pixel=WhitePixel( wsDisplay,wsScreen ); | |
416 win->WindowAttrib.colormap=XCreateColormap( wsDisplay,wsRootWin,win->VisualInfo.visual,AllocNone ); | |
417 win->WindowAttrib.event_mask=StructureNotifyMask | FocusChangeMask | | |
418 ExposureMask | PropertyChangeMask | | |
419 EnterWindowMask | LeaveWindowMask | | |
420 VisibilityChangeMask | | |
421 KeyPressMask | KeyReleaseMask; | |
422 if ( ( cV & wsHandleMouseButton ) ) win->WindowAttrib.event_mask|=ButtonPressMask | ButtonReleaseMask; | |
423 if ( ( cV & wsHandleMouseMove ) ) win->WindowAttrib.event_mask|=PointerMotionMask; | |
424 win->WindowAttrib.cursor=win->wsCursor; | |
425 win->WindowAttrib.override_redirect=False; | |
426 if ( D & wsOverredirect ) win->WindowAttrib.override_redirect=True; | |
427 | |
428 win->WindowMask=CWBackPixel | CWBorderPixel | | |
429 CWColormap | CWEventMask | CWCursor | | |
430 CWOverrideRedirect; | |
431 | |
432 win->WindowID=XCreateWindow( wsDisplay, | |
433 (win->Parent != 0?win->Parent:wsRootWin), | |
434 win->X,win->Y,win->Width,win->Height,win->BorderWidth, | |
435 win->VisualInfo.depth, | |
436 InputOutput, | |
437 win->VisualInfo.visual, | |
438 win->WindowMask,&win->WindowAttrib ); | |
439 | |
440 wsClassHint.res_name="MPlayer"; | |
441 | |
442 wsClassHint.res_class="MPlayer"; | |
443 XSetClassHint( wsDisplay,win->WindowID,&wsClassHint ); | |
444 | |
445 win->SizeHint.flags=PPosition | PSize | PResizeInc | PWinGravity;// | PBaseSize; | |
446 win->SizeHint.x=win->X; | |
447 win->SizeHint.y=win->Y; | |
448 win->SizeHint.width=win->Width; | |
449 win->SizeHint.height=win->Height; | |
450 | |
451 if ( D & wsMinSize ) | |
452 { | |
453 win->SizeHint.flags|=PMinSize; | |
454 win->SizeHint.min_width=win->Width; | |
455 win->SizeHint.min_height=win->Height; | |
456 } | |
457 if ( D & wsMaxSize ) | |
458 { | |
459 win->SizeHint.flags|=PMaxSize; | |
460 win->SizeHint.max_width=win->Width; | |
461 win->SizeHint.max_height=win->Height; | |
462 } | |
463 | |
464 win->SizeHint.height_inc=1; | |
465 win->SizeHint.width_inc=1; | |
466 win->SizeHint.base_width=win->Width; | |
467 win->SizeHint.base_height=win->Height; | |
468 win->SizeHint.win_gravity=StaticGravity; | |
469 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); | |
470 | |
471 win->WMHints.flags=InputHint | StateHint; | |
472 win->WMHints.input=True; | |
473 win->WMHints.initial_state=NormalState; | |
474 XSetWMHints( wsDisplay,win->WindowID,&win->WMHints ); | |
475 | |
476 wsWindowDecoration( win,win->Decorations ); | |
477 XStoreName( wsDisplay,win->WindowID,label ); | |
478 XmbSetWMProperties( wsDisplay,win->WindowID,label,label,NULL,0,NULL,NULL,NULL ); | |
479 | |
480 XSetWMProtocols( wsDisplay,win->WindowID,win->AtomsProtocols,3 ); | |
481 XChangeProperty( wsDisplay,win->WindowID, | |
482 win->AtomLeaderClient, | |
483 XA_WINDOW,32,PropModeReplace, | |
484 (unsigned char *)&LeaderWindow,1 ); | |
485 | |
486 wsTextProperty.value=label; | |
487 wsTextProperty.encoding=XA_STRING; | |
488 wsTextProperty.format=8; | |
489 wsTextProperty.nitems=strlen( label ); | |
490 XSetWMIconName( wsDisplay,win->WindowID,&wsTextProperty ); | |
491 | |
492 win->wGC=XCreateGC( wsDisplay,win->WindowID, | |
493 GCForeground | GCBackground, | |
494 &win->wGCV ); | |
495 | |
496 win->Visible=0; | |
497 win->Focused=0; | |
498 win->Mapped=0; | |
499 win->Rolled=0; | |
500 if ( D & wsShowWindow ) XMapWindow( wsDisplay,win->WindowID ); | |
501 | |
502 wsCreateImage( win,win->Width,win->Height ); | |
503 // --- End of creating -------------------------------------------------------------------------- | |
504 | |
505 { | |
506 int i; | |
507 for ( i=0;i < wsWLCount;i++ ) | |
508 if ( wsWindowList[i] == NULL ) break; | |
509 if ( i == wsWLCount ) | |
510 { mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_TooManyOpenWindows ); exit( 0 ); } | |
511 wsWindowList[i]=win; | |
512 } | |
513 | |
514 XFlush( wsDisplay ); | |
515 XSync( wsDisplay,False ); | |
516 | |
517 win->ReDraw=NULL; | |
518 win->ReSize=NULL; | |
519 win->Idle=NULL; | |
520 win->MouseHandler=NULL; | |
521 win->KeyHandler=NULL; | |
522 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[ws] window is created. ( %s ).\n",label ); | |
523 } | |
524 | |
525 void wsDestroyWindow( wsTWindow * win ) | |
526 { | |
527 int l; | |
528 l=wsSearch( win->WindowID ); | |
529 wsWindowList[l]=NULL; | |
530 if ( win->wsCursor != None ) | |
531 { | |
532 XFreeCursor( wsDisplay,win->wsCursor ); | |
533 win->wsCursor=None; | |
534 } | |
535 XFreeGC( wsDisplay,win->wGC ); | |
536 XUnmapWindow( wsDisplay,win->WindowID ); | |
537 wsDestroyImage( win ); | |
538 XDestroyWindow( wsDisplay,win->WindowID ); | |
539 #if 0 | |
540 win->ReDraw=NULL; | |
541 win->ReSize=NULL; | |
542 win->Idle=NULL; | |
543 win->MouseHandler=NULL; | |
544 win->KeyHandler=NULL; | |
545 win->Visible=0; | |
546 win->Focused=0; | |
547 win->Mapped=0; | |
548 win->Rolled=0; | |
549 #endif | |
550 } | |
551 | |
552 // ---------------------------------------------------------------------------------------------- | |
553 // Handle events. | |
554 // ---------------------------------------------------------------------------------------------- | |
555 | |
556 Bool wsEvents( Display * display,XEvent * Event,XPointer arg ) | |
557 { | |
558 unsigned long i = 0; | |
559 int l; | |
560 int x,y; | |
561 Window child_window = 0; | |
562 | |
563 l=wsSearch( Event->xany.window ); | |
564 if ( l == -1 ) return !wsTrue; | |
565 wsWindowList[l]->State=0; | |
566 switch( Event->type ) | |
567 { | |
568 case ClientMessage: | |
569 if ( Event->xclient.message_type == wsWindowList[l]->AtomProtocols ) | |
570 { | |
571 if ( (Atom)Event->xclient.data.l[0] == wsWindowList[l]->AtomDeleteWindow ) | |
572 { i=wsWindowClosed; goto expose; } | |
573 if ( (Atom)Event->xclient.data.l[0] == wsWindowList[l]->AtomTakeFocus ) | |
574 { i=wsWindowFocusIn; wsWindowList[l]->Focused=wsFocused; goto expose; } | |
575 if ( (Atom)Event->xclient.data.l[0] == wsWindowList[l]->AtomRolle ) | |
576 { mp_msg( MSGT_GPLAYER,MSGL_V,"[ws] role set.\n" ); } | |
577 } else { | |
578 /* try to process DND events */ | |
579 wsXDNDProcessClientMessage(wsWindowList[l],&Event->xclient); | |
580 } | |
581 break; | |
582 | |
583 case MapNotify: i=wsWindowMapped; wsWindowList[l]->Mapped=wsMapped; goto expose; | |
584 case UnmapNotify: i=wsWindowUnmapped; wsWindowList[l]->Mapped=wsNone; goto expose; | |
585 case FocusIn: | |
586 if ( wsWindowList[l]->Focused == wsFocused ) break; | |
587 i=wsWindowFocusIn; | |
588 wsWindowList[l]->Focused=wsFocused; | |
589 goto expose; | |
590 case FocusOut: | |
591 if ( wsWindowList[l]->Focused == wsNone ) break; | |
592 i=wsWindowFocusOut; | |
593 wsWindowList[l]->Focused=wsNone; | |
594 goto expose; | |
595 case VisibilityNotify: | |
596 switch( Event->xvisibility.state ) | |
597 { | |
598 case VisibilityUnobscured: i=wsWindowVisible; wsWindowList[l]->Visible=wsVisible; goto expose; | |
599 case VisibilityFullyObscured: i=wsWindowNotVisible; wsWindowList[l]->Visible=wsNotVisible; goto expose; | |
600 case VisibilityPartiallyObscured: i=wsWindowPartialVisible; wsWindowList[l]->Visible=wsPVisible; goto expose; | |
601 } | |
602 expose: | |
603 wsWindowList[l]->State=i; | |
604 if ( wsWindowList[l]->ReDraw ) wsWindowList[l]->ReDraw(); | |
605 break; | |
606 | |
607 case Expose: | |
608 wsWindowList[l]->State=wsWindowExpose; | |
609 if ( ( wsWindowList[l]->ReDraw )&&( !Event->xexpose.count ) ) wsWindowList[l]->ReDraw(); | |
610 break; | |
611 | |
612 case ConfigureNotify: | |
613 XTranslateCoordinates( wsDisplay,wsWindowList[l]->WindowID,wsRootWin,0,0,&x,&y,&child_window ); | |
614 if ( ( wsWindowList[l]->X != x )||( wsWindowList[l]->Y != y )||( wsWindowList[l]->Width != Event->xconfigure.width )||( wsWindowList[l]->Height != Event->xconfigure.height ) ) | |
615 { | |
616 wsWindowList[l]->X=x; wsWindowList[l]->Y=y; | |
617 wsWindowList[l]->Width=Event->xconfigure.width; wsWindowList[l]->Height=Event->xconfigure.height; | |
618 if ( wsWindowList[l]->ReSize ) wsWindowList[l]->ReSize( wsWindowList[l]->X,wsWindowList[l]->Y,wsWindowList[l]->Width,wsWindowList[l]->Height ); | |
619 } | |
620 | |
621 wsWindowList[l]->Rolled=wsNone; | |
622 if ( Event->xconfigure.y < 0 ) | |
623 { i=wsWindowRolled; wsWindowList[l]->Rolled=wsRolled; goto expose; } | |
624 | |
625 break; | |
626 | |
627 case KeyPress: i=wsKeyPressed; goto keypressed; | |
628 case KeyRelease: i=wsKeyReleased; | |
629 keypressed: | |
630 wsWindowList[l]->Alt=0; | |
631 wsWindowList[l]->Shift=0; | |
632 wsWindowList[l]->NumLock=0; | |
633 wsWindowList[l]->Control=0; | |
634 wsWindowList[l]->CapsLock=0; | |
635 if ( Event->xkey.state & Mod1Mask ) wsWindowList[l]->Alt=1; | |
636 if ( Event->xkey.state & Mod2Mask ) wsWindowList[l]->NumLock=1; | |
637 if ( Event->xkey.state & ControlMask ) wsWindowList[l]->Control=1; | |
638 if ( Event->xkey.state & ShiftMask ) wsWindowList[l]->Shift=1; | |
639 if ( Event->xkey.state & LockMask ) wsWindowList[l]->CapsLock=1; | |
640 #if 0 | |
641 { | |
642 KeySym keySym; | |
643 keySym=XKeycodeToKeysym( wsDisplay,Event->xkey.keycode,0 ); | |
644 if ( keySym != NoSymbol ) | |
645 { | |
646 keySym=( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ); | |
647 wsKeyTable[ keySym ]=i; | |
648 if ( wsWindowList[l]->KeyHandler ) | |
649 wsWindowList[l]->KeyHandler( Event->xkey.state,i,keySym ); | |
650 } | |
651 } | |
652 #else | |
653 { | |
654 int key; | |
655 char buf[100]; | |
656 KeySym keySym; | |
657 static XComposeStatus stat; | |
658 | |
659 XLookupString( &Event->xkey,buf,sizeof(buf),&keySym,&stat ); | |
660 key=( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ); | |
661 wsKeyTable[ key ]=i; | |
662 if ( wsWindowList[l]->KeyHandler ) wsWindowList[l]->KeyHandler( Event->xkey.keycode,i,key ); | |
663 } | |
664 #endif | |
665 break; | |
666 | |
667 case MotionNotify: | |
668 i=wsMoveMouse; | |
669 { | |
670 /* pump all motion events from the display queue: | |
671 this way it works faster when moving the window */ | |
672 static XEvent e; | |
673 if ( Event->xmotion.state ) | |
674 { | |
675 while(XCheckTypedWindowEvent(display,Event->xany.window,MotionNotify,&e)){ | |
676 /* FIXME: need to make sure we didn't release/press the button in between...*/ | |
677 /* FIXME: do we need some timeout here to make sure we don't spend too much time | |
678 removing events from the queue? */ | |
679 Event = &e; | |
680 } | |
681 } | |
682 } | |
683 goto buttonreleased; | |
684 case ButtonRelease: i=Event->xbutton.button + 128; goto buttonreleased; | |
685 case ButtonPress: i=Event->xbutton.button; goto buttonreleased; | |
686 case EnterNotify: i=wsEnterWindow; goto buttonreleased; | |
687 case LeaveNotify: i=wsLeaveWindow; | |
688 buttonreleased: | |
689 if ( wsWindowList[l]->MouseHandler ) | |
690 wsWindowList[l]->MouseHandler( i,Event->xbutton.x,Event->xbutton.y,Event->xmotion.x_root,Event->xmotion.y_root ); | |
691 break; | |
692 | |
693 case SelectionNotify: | |
694 /* Handle DandD */ | |
695 wsXDNDProcessSelection(wsWindowList[l],Event); | |
696 break; | |
697 } | |
698 XFlush( wsDisplay ); | |
699 XSync( wsDisplay,False ); | |
700 return !wsTrue; | |
701 } | |
702 | |
703 void wsHandleEvents( void ){ | |
704 // handle pending events | |
705 while ( XPending(wsDisplay) ){ | |
706 XNextEvent( wsDisplay,&wsEvent ); | |
707 // printf("### X event: %d [%d]\n",wsEvent.type,delay); | |
708 wsEvents( wsDisplay,&wsEvent,NULL ); | |
709 } | |
710 } | |
711 | |
712 void wsMainLoop( void ) | |
713 { | |
714 int delay=20; | |
715 mp_msg( MSGT_GPLAYER,MSGL_V,"[ws] init threads: %d\n",XInitThreads() ); | |
716 XSynchronize( wsDisplay,False ); | |
717 XLockDisplay( wsDisplay ); | |
718 // XIfEvent( wsDisplay,&wsEvent,wsEvents,NULL ); | |
719 | |
720 while(wsTrue){ | |
721 // handle pending events | |
722 while ( XPending(wsDisplay) ){ | |
723 XNextEvent( wsDisplay,&wsEvent ); | |
724 wsEvents( wsDisplay,&wsEvent,NULL ); | |
725 delay=0; | |
726 } | |
727 usleep(delay*1000); // FIXME! | |
728 if(delay<10*20) delay+=20; // pump up delay up to 0.2 sec (low activity) | |
729 } | |
730 | |
731 XUnlockDisplay( wsDisplay ); | |
732 } | |
733 | |
734 // ---------------------------------------------------------------------------------------------- | |
735 // Move window to selected layer | |
736 // ---------------------------------------------------------------------------------------------- | |
737 | |
738 #define WIN_LAYER_ONBOTTOM 2 | |
739 #define WIN_LAYER_NORMAL 4 | |
740 #define WIN_LAYER_ONTOP 10 | |
741 | |
742 void wsSetLayer( Display * wsDisplay, Window win, int layer ) | |
743 { vo_x11_setlayer( wsDisplay,win,layer ); } | |
744 | |
745 // ---------------------------------------------------------------------------------------------- | |
746 // Switch to fullscreen. | |
747 // ---------------------------------------------------------------------------------------------- | |
748 void wsFullScreen( wsTWindow * win ) | |
749 { | |
750 int decoration = 0; | |
751 | |
752 if ( win->isFullScreen ) | |
753 { | |
754 vo_x11_ewmh_fullscreen( _NET_WM_STATE_REMOVE ); // removes fullscreen state if wm supports EWMH | |
755 if ( ! (vo_fs_type & vo_wm_FULLSCREEN) ) // shouldn't be needed with EWMH fs | |
756 { | |
757 win->X=win->OldX; | |
758 win->Y=win->OldY; | |
759 win->Width=win->OldWidth; | |
760 win->Height=win->OldHeight; | |
761 decoration=win->Decorations; | |
762 } | |
763 | |
764 #ifdef ENABLE_DPMS | |
765 wsScreenSaverOn( wsDisplay ); | |
766 #endif | |
767 | |
768 win->isFullScreen=False; | |
769 } | |
770 else | |
771 { | |
772 if ( ! (vo_fs_type & vo_wm_FULLSCREEN) ) // shouldn't be needed with EWMH fs | |
773 { | |
774 win->OldX=win->X; win->OldY=win->Y; | |
775 win->OldWidth=win->Width; win->OldHeight=win->Height; | |
776 vo_dx = win->X; vo_dy = win->Y; | |
777 vo_dwidth = win->Width; vo_dheight = win->Height; | |
778 vo_screenwidth = wsMaxX; vo_screenheight = wsMaxY; | |
779 xinerama_x = wsOrgX; xinerama_y = wsOrgY; | |
780 update_xinerama_info(); | |
781 wsMaxX = vo_screenwidth; wsMaxY = vo_screenheight; | |
782 wsOrgX = xinerama_x; wsOrgY = xinerama_y; | |
783 win->X=wsOrgX; win->Y=wsOrgY; | |
784 win->Width=wsMaxX; win->Height=wsMaxY; | |
785 } | |
786 | |
787 win->isFullScreen=True; | |
788 #ifdef ENABLE_DPMS | |
789 wsScreenSaverOff( wsDisplay ); | |
790 #endif | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
791 |
23077 | 792 vo_x11_ewmh_fullscreen( _NET_WM_STATE_ADD ); // adds fullscreen state if wm supports EWMH |
793 } | |
794 | |
795 if ( ! (vo_fs_type & vo_wm_FULLSCREEN) ) // shouldn't be needed with EWMH fs | |
796 { | |
797 vo_x11_decoration( wsDisplay,win->WindowID,decoration ); | |
798 vo_x11_sizehint( win->X,win->Y,win->Width,win->Height,0 ); | |
799 vo_x11_setlayer( wsDisplay,win->WindowID,win->isFullScreen ); | |
800 | |
801 if ((!(win->isFullScreen)) & vo_ontop) vo_x11_setlayer(wsDisplay, win->WindowID,1); | |
802 | |
803 XMoveResizeWindow( wsDisplay,win->WindowID,win->X,win->Y,win->Width,win->Height ); | |
804 } | |
805 | |
806 if ( vo_wm_type == 0 && !(vo_fsmode&16) ) | |
807 { | |
808 XWithdrawWindow( wsDisplay,win->WindowID,wsScreen ); | |
809 } | |
810 | |
811 | |
812 XMapRaised( wsDisplay,win->WindowID ); | |
813 XRaiseWindow( wsDisplay,win->WindowID ); | |
814 XFlush( wsDisplay ); | |
815 } | |
816 | |
817 // ---------------------------------------------------------------------------------------------- | |
818 // Redraw screen. | |
819 // ---------------------------------------------------------------------------------------------- | |
820 void wsPostRedisplay( wsTWindow * win ) | |
821 { | |
822 if ( win->ReDraw ) | |
823 { | |
824 win->State=wsWindowExpose; | |
825 win->ReDraw(); | |
826 XFlush( wsDisplay ); | |
827 } | |
828 } | |
829 | |
830 // ---------------------------------------------------------------------------------------------- | |
831 // Do Exit. | |
832 // ---------------------------------------------------------------------------------------------- | |
833 void wsDoExit( void ) | |
834 { wsTrue=False; wsResizeWindow( wsWindowList[0],32,32 ); } | |
835 | |
836 // ---------------------------------------------------------------------------------------------- | |
837 // Put 'Image' to window. | |
838 // ---------------------------------------------------------------------------------------------- | |
839 void wsConvert( wsTWindow * win,unsigned char * Image,unsigned int Size ) | |
23453
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
840 { |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
841 int i; |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
842 if ( wsConvFunc ) |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
843 wsConvFunc( Image,win->ImageData,win->xImage->width * win->xImage->height * 4 ); |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
844 if (!wsNonNativeOrder) return; |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
845 switch (win->xImage->bits_per_pixel) { |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
846 case 32: |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
847 { |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
848 uint32_t *d = win->ImageData; |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
849 for (i = 0; i < win->xImage->width * win->xImage->height; i++) |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
850 d[i] = bswap_32(d[i]); |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
851 break; |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
852 } |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
853 case 16: |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
854 case 15: |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
855 { |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
856 uint16_t *d = win->ImageData; |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
857 for (i = 0; i < win->xImage->width * win->xImage->height; i++) |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
858 d[i] = bswap_16(d[i]); |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
859 break; |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
860 } |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
861 } |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
862 } |
23077 | 863 |
864 void wsPutImage( wsTWindow * win ) | |
865 { | |
866 if ( wsUseXShm ) | |
867 { | |
868 XShmPutImage( wsDisplay,win->WindowID,win->wGC,win->xImage, | |
869 0,0, | |
870 ( win->Width - win->xImage->width ) / 2,( win->Height - win->xImage->height ) / 2, | |
871 win->xImage->width,win->xImage->height,0 ); | |
872 } | |
873 else | |
874 { | |
875 XPutImage( wsDisplay,win->WindowID,win->wGC,win->xImage, | |
876 0,0, | |
877 ( win->Width - win->xImage->width ) / 2,( win->Height - win->xImage->height ) / 2, | |
878 win->xImage->width,win->xImage->height ); | |
879 } | |
880 } | |
881 | |
882 // ---------------------------------------------------------------------------------------------- | |
883 // Move window to x, y. | |
884 // ---------------------------------------------------------------------------------------------- | |
885 void wsMoveWindow( wsTWindow * win,int b,int x, int y ) | |
886 { | |
887 if ( b ) | |
888 { | |
889 switch ( x ) | |
890 { | |
891 case -1: win->X=( wsMaxX / 2 ) - ( win->Width / 2 ) + wsOrgX; break; | |
892 case -2: win->X=wsMaxX - win->Width + wsOrgX; break; | |
893 default: win->X=x; break; | |
894 } | |
895 switch ( y ) | |
896 { | |
897 case -1: win->Y=( wsMaxY / 2 ) - ( win->Height / 2 ) + wsOrgY; break; | |
898 case -2: win->Y=wsMaxY - win->Height + wsOrgY; break; | |
899 default: win->Y=y; break; | |
900 } | |
901 } | |
902 else { win->X=x; win->Y=y; } | |
903 | |
904 win->SizeHint.flags=PPosition | PWinGravity; | |
905 win->SizeHint.x=win->X; | |
906 win->SizeHint.y=win->Y; | |
907 win->SizeHint.win_gravity=StaticGravity; | |
908 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); | |
909 | |
910 XMoveWindow( wsDisplay,win->WindowID,win->X,win->Y ); | |
911 if ( win->ReSize ) win->ReSize( win->X,win->Y,win->Width,win->Height ); | |
912 } | |
913 | |
914 // ---------------------------------------------------------------------------------------------- | |
915 // Resize window to sx, sy. | |
916 // ---------------------------------------------------------------------------------------------- | |
917 void wsResizeWindow( wsTWindow * win,int sx, int sy ) | |
918 { | |
919 win->Width=sx; | |
920 win->Height=sy; | |
921 | |
922 win->SizeHint.flags=PPosition | PSize | PWinGravity;// | PBaseSize; | |
923 win->SizeHint.x=win->X; | |
924 win->SizeHint.y=win->Y; | |
925 win->SizeHint.width=win->Width; | |
926 win->SizeHint.height=win->Height; | |
927 | |
928 if ( win->Property & wsMinSize ) | |
929 { | |
930 win->SizeHint.flags|=PMinSize; | |
931 win->SizeHint.min_width=win->Width; | |
932 win->SizeHint.min_height=win->Height; | |
933 } | |
934 if ( win->Property & wsMaxSize ) | |
935 { | |
936 win->SizeHint.flags|=PMaxSize; | |
937 win->SizeHint.max_width=win->Width; | |
938 win->SizeHint.max_height=win->Height; | |
939 } | |
940 | |
941 win->SizeHint.win_gravity=StaticGravity; | |
942 win->SizeHint.base_width=sx; win->SizeHint.base_height=sy; | |
943 | |
944 if ( vo_wm_type == 0 ) XUnmapWindow( wsDisplay,win->WindowID ); | |
945 | |
946 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); | |
947 XResizeWindow( wsDisplay,win->WindowID,sx,sy ); | |
948 XMapRaised( wsDisplay,win->WindowID ); | |
949 if ( win->ReSize ) win->ReSize( win->X,win->Y,win->Width,win->Height ); | |
950 } | |
951 | |
952 // ---------------------------------------------------------------------------------------------- | |
953 // Iconify window. | |
954 // ---------------------------------------------------------------------------------------------- | |
955 void wsIconify( wsTWindow win ) | |
956 { XIconifyWindow( wsDisplay,win.WindowID,0 ); } | |
957 | |
958 // ---------------------------------------------------------------------------------------------- | |
959 // Move top the window. | |
960 // ---------------------------------------------------------------------------------------------- | |
961 void wsMoveTopWindow( Display * wsDisplay,Window win ) | |
962 { | |
963 // XUnmapWindow( wsDisplay,win ); | |
964 // XMapWindow( wsDisplay,win ); | |
965 XMapRaised( wsDisplay,win ); | |
966 XRaiseWindow( wsDisplay,win ); | |
967 } | |
968 | |
969 // ---------------------------------------------------------------------------------------------- | |
970 // Set window background to 'color'. | |
971 // ---------------------------------------------------------------------------------------------- | |
972 void wsSetBackground( wsTWindow * win,int color ) | |
973 { XSetWindowBackground( wsDisplay,win->WindowID,color ); } | |
974 | |
975 void wsSetBackgroundRGB( wsTWindow * win,int r,int g,int b ) | |
976 { | |
977 int color = 0; | |
978 switch ( wsOutMask ) | |
979 { | |
980 case wsRGB32: | |
981 case wsRGB24: color=( r << 16 ) + ( g << 8 ) + b; break; | |
982 case wsBGR32: | |
983 case wsBGR24: color=( b << 16 ) + ( g << 8 ) + r; break; | |
984 case wsRGB16: PACK_RGB16( b,g,r,color ); break; | |
985 case wsBGR16: PACK_RGB16( r,g,b,color ); break; | |
986 case wsRGB15: PACK_RGB15( b,g,r,color ); break; | |
987 case wsBGR15: PACK_RGB15( r,g,b,color ); break; | |
988 } | |
989 XSetWindowBackground( wsDisplay,win->WindowID,color ); | |
990 } | |
991 | |
992 void wsSetForegroundRGB( wsTWindow * win,int r,int g,int b ) | |
993 { | |
994 int color = 0; | |
995 switch ( wsOutMask ) | |
996 { | |
997 case wsRGB32: | |
998 case wsRGB24: color=( r << 16 ) + ( g << 8 ) + b; break; | |
999 case wsBGR32: | |
1000 case wsBGR24: color=( b << 16 ) + ( g << 8 ) + r; break; | |
1001 case wsRGB16: PACK_RGB16( b,g,r,color ); break; | |
1002 case wsBGR16: PACK_RGB16( r,g,b,color ); break; | |
1003 case wsRGB15: PACK_RGB15( b,g,r,color ); break; | |
1004 case wsBGR15: PACK_RGB15( r,g,b,color ); break; | |
1005 } | |
1006 XSetForeground( wsDisplay,win->wGC,color ); | |
1007 } | |
1008 | |
1009 // ---------------------------------------------------------------------------------------------- | |
1010 // Draw string at x,y with fc ( foreground color ) and bc ( background color ). | |
1011 // ---------------------------------------------------------------------------------------------- | |
1012 void wsDrawString( wsTWindow win,int x,int y,char * str,int fc,int bc ) | |
1013 { | |
1014 XSetForeground( wsDisplay,win.wGC,bc ); | |
1015 XFillRectangle( wsDisplay,win.WindowID,win.wGC,x,y, | |
1016 XTextWidth( win.Font,str,strlen( str ) ) + 20, | |
1017 win.FontHeight + 2 ); | |
1018 XSetForeground( wsDisplay,win.wGC,fc ); | |
1019 XDrawString( wsDisplay,win.WindowID,win.wGC,x + 10,y + 13,str,strlen( str ) ); | |
1020 } | |
1021 | |
1022 // ---------------------------------------------------------------------------------------------- | |
1023 // Calculation string width. | |
1024 // ---------------------------------------------------------------------------------------------- | |
1025 int wsTextWidth( wsTWindow win,char * str ) | |
1026 { return XTextWidth( win.Font,str,strlen( str ) ) + 20; } | |
1027 | |
1028 // ---------------------------------------------------------------------------------------------- | |
1029 // Show / hide mouse cursor. | |
1030 // ---------------------------------------------------------------------------------------------- | |
1031 void wsVisibleMouse( wsTWindow * win,int m ) | |
1032 { | |
1033 switch ( m ) | |
1034 { | |
1035 case wsShowMouseCursor: | |
1036 if ( win->wsCursor != None ) | |
1037 { | |
1038 XFreeCursor( wsDisplay,win->wsCursor ); | |
1039 win->wsCursor=None; | |
1040 } | |
1041 XDefineCursor( wsDisplay,win->WindowID,0 ); | |
1042 break; | |
1043 case wsHideMouseCursor: | |
1044 win->wsCursor=XCreatePixmapCursor( wsDisplay,win->wsCursorPixmap,win->wsCursorPixmap,&win->wsColor,&win->wsColor,0,0 ); | |
1045 XDefineCursor( wsDisplay,win->WindowID,win->wsCursor ); | |
1046 break; | |
1047 } | |
1048 XFlush( wsDisplay ); | |
1049 } | |
1050 | |
1051 int wsGetDepthOnScreen( void ) | |
1052 { | |
1053 int depth; | |
1054 XImage * mXImage; | |
1055 Visual * visual; | |
1056 | |
1057 if( (depth = vo_find_depth_from_visuals( wsDisplay,wsScreen,&visual )) > 0 ) | |
1058 { | |
1059 mXImage = XCreateImage( wsDisplay,visual,depth,ZPixmap,0,NULL, | |
1060 1,1,32,0 ); | |
1061 wsDepthOnScreen = mXImage->bits_per_pixel; | |
1062 wsRedMask=mXImage->red_mask; | |
1063 wsGreenMask=mXImage->green_mask; | |
1064 wsBlueMask=mXImage->blue_mask; | |
29401
f01023c524c3
Replace WORDS_BIGENDIAN by HAVE_BIGENDIAN in all internal code.
diego
parents:
29263
diff
changeset
|
1065 #if HAVE_BIGENDIAN |
23453
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
1066 wsNonNativeOrder = mXImage->byte_order == LSBFirst; |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
1067 #else |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
1068 wsNonNativeOrder = mXImage->byte_order == MSBFirst; |
3e18bed9618a
Make gmplayer show right colors if X server does not use native byteorder.
reimar
parents:
23077
diff
changeset
|
1069 #endif |
23077 | 1070 XDestroyImage( mXImage ); |
1071 } | |
1072 else | |
1073 { | |
1074 int bpp,ibpp; | |
1075 XWindowAttributes attribs; | |
1076 | |
1077 mXImage=XGetImage( wsDisplay,wsRootWin,0,0,1,1,AllPlanes,ZPixmap ); | |
1078 bpp=mXImage->bits_per_pixel; | |
1079 | |
1080 XGetWindowAttributes( wsDisplay,wsRootWin,&attribs ); | |
1081 ibpp=attribs.depth; | |
1082 mXImage=XGetImage( wsDisplay,wsRootWin,0,0,1,1,AllPlanes,ZPixmap ); | |
1083 bpp=mXImage->bits_per_pixel; | |
1084 if ( ( ibpp + 7 ) / 8 != ( bpp + 7 ) / 8 ) ibpp=bpp; | |
1085 wsDepthOnScreen=ibpp; | |
1086 wsRedMask=mXImage->red_mask; | |
1087 wsGreenMask=mXImage->green_mask; | |
1088 wsBlueMask=mXImage->blue_mask; | |
1089 XDestroyImage( mXImage ); | |
1090 } | |
1091 return wsDepthOnScreen; | |
1092 } | |
1093 | |
1094 void wsXDone( void ) | |
1095 { | |
1096 XCloseDisplay( wsDisplay ); | |
1097 } | |
1098 | |
1099 void wsVisibleWindow( wsTWindow * win,int show ) | |
1100 { | |
1101 switch( show ) | |
1102 { | |
1103 case wsShowWindow: XMapRaised( wsDisplay,win->WindowID ); break; | |
1104 case wsHideWindow: XUnmapWindow( wsDisplay,win->WindowID ); break; | |
1105 } | |
1106 XFlush( wsDisplay ); | |
1107 } | |
1108 | |
1109 void wsDestroyImage( wsTWindow * win ) | |
1110 { | |
1111 if ( win->xImage ) | |
1112 { | |
1113 XDestroyImage( win->xImage ); | |
1114 if ( wsUseXShm ) | |
1115 { | |
1116 XShmDetach( wsDisplay,&win->Shminfo ); | |
1117 shmdt( win->Shminfo.shmaddr ); | |
1118 } | |
1119 } | |
1120 win->xImage=NULL; | |
1121 } | |
1122 | |
1123 void wsCreateImage( wsTWindow * win,int Width,int Height ) | |
1124 { | |
1125 int CompletionType = -1; | |
1126 if ( wsUseXShm ) | |
1127 { | |
1128 CompletionType=XShmGetEventBase( wsDisplay ) + ShmCompletion; | |
1129 win->xImage=XShmCreateImage( wsDisplay,win->VisualInfo.visual, | |
1130 win->VisualInfo.depth,ZPixmap,NULL,&win->Shminfo,Width,Height ); | |
1131 if ( win->xImage == NULL ) | |
1132 { | |
1133 mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_ShmError ); | |
1134 exit( 0 ); | |
1135 } | |
1136 win->Shminfo.shmid=shmget( IPC_PRIVATE,win->xImage->bytes_per_line * win->xImage->height,IPC_CREAT|0777 ); | |
1137 if ( win->Shminfo.shmid < 0 ) | |
1138 { | |
1139 XDestroyImage( win->xImage ); | |
1140 mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_ShmError ); | |
1141 exit( 0 ); | |
1142 } | |
1143 win->Shminfo.shmaddr=(char *)shmat( win->Shminfo.shmid,0,0 ); | |
1144 | |
1145 if ( win->Shminfo.shmaddr == ((char *) -1) ) | |
1146 { | |
1147 XDestroyImage( win->xImage ); | |
1148 if ( win->Shminfo.shmaddr != ((char *) -1) ) shmdt( win->Shminfo.shmaddr ); | |
1149 mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_ShmError ); | |
1150 exit( 0 ); | |
1151 } | |
1152 win->xImage->data=win->Shminfo.shmaddr; | |
1153 win->Shminfo.readOnly=0; | |
1154 XShmAttach( wsDisplay,&win->Shminfo ); | |
30218
9247ff6e841c
Call XSync after XShmAttach to avoid a possible race-condition with shmctl.
reimar
parents:
29401
diff
changeset
|
1155 XSync(wsDisplay, False); |
23077 | 1156 shmctl( win->Shminfo.shmid,IPC_RMID,0 ); |
1157 } | |
1158 else | |
1159 { | |
1160 win->xImage=XCreateImage( wsDisplay,win->VisualInfo.visual,win->VisualInfo.depth, | |
1161 ZPixmap,0,0,Width,Height, | |
1162 (wsDepthOnScreen == 3) ? 32 : wsDepthOnScreen, | |
1163 0 ); | |
1164 if ( ( win->xImage->data=malloc( win->xImage->bytes_per_line * win->xImage->height ) ) == NULL ) | |
1165 { | |
1166 mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_NotEnoughMemoryDrawBuffer ); | |
1167 exit( 0 ); | |
1168 } | |
1169 } | |
1170 win->ImageData=(unsigned char *)win->xImage->data; | |
1171 win->ImageDataw=(unsigned short int *)win->xImage->data; | |
1172 win->ImageDatadw=(unsigned int *)win->xImage->data; | |
1173 } | |
1174 | |
1175 void wsResizeImage( wsTWindow * win,int Width,int Height ) | |
1176 { wsDestroyImage( win ); wsCreateImage( win,Width,Height ); } | |
1177 | |
1178 int wsGetOutMask( void ) | |
1179 { | |
1180 if ( ( wsDepthOnScreen == 32 )&&( wsRedMask == 0xff0000 )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0x0000ff ) ) return wsRGB32; | |
1181 if ( ( wsDepthOnScreen == 32 )&&( wsRedMask == 0x0000ff )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0xff0000 ) ) return wsBGR32; | |
1182 if ( ( wsDepthOnScreen == 24 )&&( wsRedMask == 0xff0000 )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0x0000ff ) ) return wsRGB24; | |
1183 if ( ( wsDepthOnScreen == 24 )&&( wsRedMask == 0x0000ff )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0xff0000 ) ) return wsBGR24; | |
1184 if ( ( wsDepthOnScreen == 16 )&&( wsRedMask == 0xf800 )&&( wsGreenMask == 0x7e0 )&&( wsBlueMask == 0x1f ) ) return wsRGB16; | |
1185 if ( ( wsDepthOnScreen == 16 )&&( wsRedMask == 0x1f )&&( wsGreenMask == 0x7e0 )&&( wsBlueMask == 0xf800 ) ) return wsBGR16; | |
1186 if ( ( wsDepthOnScreen == 15 )&&( wsRedMask == 0x7c00 )&&( wsGreenMask == 0x3e0 )&&( wsBlueMask == 0x1f ) ) return wsRGB15; | |
1187 if ( ( wsDepthOnScreen == 15 )&&( wsRedMask == 0x1f )&&( wsGreenMask == 0x3e0 )&&( wsBlueMask == 0x7c00 ) ) return wsBGR15; | |
1188 return 0; | |
1189 } | |
1190 | |
1191 void wsSetTitle( wsTWindow * win,char * name ) | |
1192 { XStoreName( wsDisplay,win->WindowID,name ); } | |
1193 | |
1194 void wsSetMousePosition( wsTWindow * win,int x, int y ) | |
1195 { XWarpPointer( wsDisplay,wsRootWin,win->WindowID,0,0,0,0,x,y ); } | |
1196 | |
1197 #ifdef ENABLE_DPMS | |
1198 static int dpms_disabled=0; | |
1199 static int timeout_save=0; | |
1200 | |
1201 void wsScreenSaverOn( Display *mDisplay ) | |
1202 { | |
1203 int nothing; | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
1204 #ifdef CONFIG_XDPMS |
23077 | 1205 if ( dpms_disabled ) |
1206 { | |
1207 if ( DPMSQueryExtension( mDisplay,¬hing,¬hing ) ) | |
1208 { | |
1209 if ( !DPMSEnable( mDisplay ) ) mp_msg( MSGT_GPLAYER,MSGL_ERR,MSGTR_WS_DpmsUnavailable ); // restoring power saving settings | |
1210 else | |
1211 { | |
1212 // DPMS does not seem to be enabled unless we call DPMSInfo | |
1213 BOOL onoff; | |
1214 CARD16 state; | |
1215 DPMSInfo( mDisplay,&state,&onoff ); | |
1216 if ( onoff ) mp_msg( MSGT_GPLAYER,MSGL_V,"Successfully enabled DPMS.\n" ); | |
1217 else mp_msg( MSGT_GPLAYER,MSGL_STATUS,MSGTR_WS_DpmsNotEnabled ); | |
1218 } | |
1219 } | |
1220 } | |
1221 #endif | |
1222 if ( timeout_save ) | |
1223 { | |
1224 int dummy, interval, prefer_blank, allow_exp; | |
1225 XGetScreenSaver( mDisplay,&dummy,&interval,&prefer_blank,&allow_exp ); | |
1226 XSetScreenSaver( mDisplay,timeout_save,interval,prefer_blank,allow_exp ); | |
1227 XGetScreenSaver( mDisplay,&timeout_save,&interval,&prefer_blank,&allow_exp ); | |
1228 } | |
1229 } | |
1230 | |
1231 void wsScreenSaverOff( Display * mDisplay ) | |
1232 { | |
1233 int interval,prefer_blank,allow_exp,nothing; | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
1234 #ifdef CONFIG_XDPMS |
23077 | 1235 if ( DPMSQueryExtension( mDisplay,¬hing,¬hing ) ) |
1236 { | |
1237 BOOL onoff; | |
1238 CARD16 state; | |
1239 DPMSInfo( mDisplay,&state,&onoff ); | |
1240 if ( onoff ) | |
1241 { | |
1242 Status stat; | |
1243 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"Disabling DPMS.\n" ); | |
1244 dpms_disabled=1; | |
1245 stat=DPMSDisable( mDisplay ); // monitor powersave off | |
1246 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"stat: %d.\n",stat ); | |
1247 } | |
1248 } | |
1249 #endif | |
1250 XGetScreenSaver( mDisplay,&timeout_save,&interval,&prefer_blank,&allow_exp ); | |
1251 if ( timeout_save ) XSetScreenSaver( mDisplay,0,interval,prefer_blank,allow_exp ); // turning off screensaver | |
1252 } | |
1253 #endif | |
1254 | |
1255 void wsSetShape( wsTWindow * win,char * data ) | |
1256 { | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
1257 #ifdef CONFIG_XSHAPE |
23077 | 1258 if ( !wsUseXShape ) return; |
1259 if ( data ) | |
1260 { | |
1261 win->Mask=XCreateBitmapFromData( wsDisplay,win->WindowID,data,win->Width,win->Height ); | |
1262 XShapeCombineMask( wsDisplay,win->WindowID,ShapeBounding,0,0,win->Mask,ShapeSet ); | |
1263 XFreePixmap( wsDisplay,win->Mask ); | |
1264 } | |
1265 else XShapeCombineMask( wsDisplay,win->WindowID,ShapeBounding,0,0,None,ShapeSet ); | |
1266 #endif | |
1267 } | |
1268 | |
1269 void wsSetIcon( Display * dsp,Window win,Pixmap icon,Pixmap mask ) | |
1270 { | |
1271 XWMHints * wm; | |
1272 long data[2]; | |
1273 Atom iconatom; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
1274 |
23077 | 1275 wm=XGetWMHints( dsp,win ); |
1276 if ( !wm ) wm=XAllocWMHints(); | |
1277 | |
1278 wm->icon_pixmap=icon; | |
1279 wm->icon_mask=mask; | |
1280 wm->flags|=IconPixmapHint | IconMaskHint; | |
1281 | |
1282 XSetWMHints( dsp,win,wm ); | |
1283 | |
1284 data[0]=icon; | |
1285 data[1]=mask; | |
1286 iconatom=XInternAtom( dsp,"KWM_WIN_ICON",0 ); | |
1287 XChangeProperty( dsp,win,iconatom,iconatom,32,PropModeReplace,(unsigned char *)data,2 ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
1288 |
23077 | 1289 XFree( wm ); |
1290 } | |
1291 | |
1292 #include "wsmkeys.h" |