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