Mercurial > mplayer.hg
annotate gui/wm/ws.c @ 31137:72638e3330a3
K&R coding style should be applied to new code.
author | diego |
---|---|
date | Sun, 23 May 2010 15:07:34 +0000 |
parents | 768242ad42e2 |
children | c69ecf7d80a4 |
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 | |
111 inline int wsSearch( Window win ); | |
112 | |
113 // --- | |
114 | |
115 #define PACK_RGB16(r,g,b,pixel) pixel=(b>>3);\ | |
116 pixel<<=6;\ | |
117 pixel|=(g>>2);\ | |
118 pixel<<=5;\ | |
119 pixel|=(r>>3) | |
120 | |
121 #define PACK_RGB15(r,g,b,pixel) pixel=(b>>3);\ | |
122 pixel<<=5;\ | |
123 pixel|=(g>>3);\ | |
124 pixel<<=5;\ | |
125 pixel|=(r>>3) | |
126 | |
127 typedef void(*wsTConvFunc)( const unsigned char * in_pixels, unsigned char * out_pixels, unsigned num_pixels ); | |
128 wsTConvFunc wsConvFunc = NULL; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
129 |
30535
016e5fc1dead
GUI: Mark functions that are not used outside their files as static.
diego
parents:
30218
diff
changeset
|
130 static void rgb32torgb32( const unsigned char * src, unsigned char * dst,unsigned int src_size ) |
23077 | 131 { memcpy( dst,src,src_size ); } |
132 | |
133 // --- | |
134 | |
135 #define MWM_HINTS_FUNCTIONS (1L << 0) | |
136 #define MWM_HINTS_DECORATIONS (1L << 1) | |
137 #define MWM_HINTS_INPUT_MODE (1L << 2) | |
138 #define MWM_HINTS_STATUS (1L << 3) | |
139 | |
140 #define MWM_FUNC_ALL (1L << 0) | |
141 #define MWM_FUNC_RESIZE (1L << 1) | |
142 #define MWM_FUNC_MOVE (1L << 2) | |
143 #define MWM_FUNC_MINIMIZE (1L << 3) | |
144 #define MWM_FUNC_MAXIMIZE (1L << 4) | |
145 #define MWM_FUNC_CLOSE (1L << 5) | |
146 | |
147 #define MWM_DECOR_ALL (1L << 0) | |
148 #define MWM_DECOR_BORDER (1L << 1) | |
149 #define MWM_DECOR_RESIZEH (1L << 2) | |
150 #define MWM_DECOR_TITLE (1L << 3) | |
151 #define MWM_DECOR_MENU (1L << 4) | |
152 #define MWM_DECOR_MINIMIZE (1L << 5) | |
153 #define MWM_DECOR_MAXIMIZE (1L << 6) | |
154 | |
155 #define MWM_INPUT_MODELESS 0 | |
156 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 | |
157 #define MWM_INPUT_SYSTEM_MODAL 2 | |
158 #define MWM_INPUT_FULL_APPLICATION_MODAL 3 | |
159 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL | |
160 | |
161 #define MWM_TEAROFF_WINDOW (1L<<0) | |
162 | |
163 void wsWindowDecoration( wsTWindow * win,long d ) | |
164 { | |
165 wsMotifHints=XInternAtom( wsDisplay,"_MOTIF_WM_HINTS",0 ); | |
166 if ( wsMotifHints == None ) return; | |
167 | |
168 memset( &wsMotifWmHints,0,sizeof( MotifWmHints ) ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
169 wsMotifWmHints.flags=MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; |
23077 | 170 if ( d ) |
171 { | |
172 wsMotifWmHints.functions=MWM_FUNC_MOVE | MWM_FUNC_CLOSE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE; | |
173 wsMotifWmHints.decorations=MWM_DECOR_ALL; | |
174 } | |
175 XChangeProperty( wsDisplay,win->WindowID,wsMotifHints,wsMotifHints,32, | |
176 PropModeReplace,(unsigned char *)&wsMotifWmHints,5 ); | |
177 } | |
178 | |
179 // ---------------------------------------------------------------------------------------------- | |
180 // Init X Window System. | |
181 // ---------------------------------------------------------------------------------------------- | |
182 | |
30535
016e5fc1dead
GUI: Mark functions that are not used outside their files as static.
diego
parents:
30218
diff
changeset
|
183 static int wsErrorHandler( Display * dpy, XErrorEvent * Event ) |
23077 | 184 { |
185 char type[128]; | |
186 XGetErrorText( wsDisplay,Event->error_code,type,128 ); | |
187 fprintf(stderr,"[ws] Error in display.\n"); | |
188 fprintf(stderr,"[ws] Error code: %d ( %s )\n",Event->error_code,type ); | |
189 fprintf(stderr,"[ws] Request code: %d\n",Event->request_code ); | |
190 fprintf(stderr,"[ws] Minor code: %d\n",Event->minor_code ); | |
191 fprintf(stderr,"[ws] Modules: %s\n",current_module?current_module:"(NULL)" ); | |
192 exit( 0 ); | |
193 } | |
194 | |
195 void wsXInit( void* mDisplay ) | |
196 { | |
197 int eventbase; | |
198 int errorbase; | |
199 | |
200 if(mDisplay){ | |
201 wsDisplay=mDisplay; | |
202 } else { | |
203 char * DisplayName = ":0.0"; | |
204 if ( getenv( "DISPLAY" ) ) DisplayName=getenv( "DISPLAY" ); | |
205 wsDisplay=XOpenDisplay( DisplayName ); | |
206 if ( !wsDisplay ) | |
207 { | |
208 mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_CouldNotOpenDisplay ); | |
209 exit( 0 ); | |
210 } | |
211 } | |
212 | |
213 /* enable DND atoms */ | |
214 wsXDNDInitialize(); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
215 |
23077 | 216 { /* on remote display XShm will be disabled - LGB */ |
217 char *dispname=DisplayString(wsDisplay); | |
218 int localdisp=1; | |
219 if (dispname&&*dispname!=':') { | |
220 localdisp=0; | |
221 wsUseXShm=0; | |
222 } | |
223 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[ws] display name: %s => %s display.\n",dispname,localdisp?"local":"REMOTE"); | |
224 if (!localdisp) mp_msg( MSGT_GPLAYER,MSGL_V,MSGTR_WS_RemoteDisplay ); | |
225 } | |
226 | |
227 if ( !XShmQueryExtension( wsDisplay ) ) | |
228 { | |
229 mp_msg( MSGT_GPLAYER,MSGL_ERR,MSGTR_WS_NoXshm ); | |
230 wsUseXShm=0; | |
231 } | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
232 #ifdef CONFIG_XSHAPE |
23077 | 233 if ( !XShapeQueryExtension( wsDisplay,&eventbase,&errorbase ) ) |
234 { | |
235 mp_msg( MSGT_GPLAYER,MSGL_ERR,MSGTR_WS_NoXshape ); | |
236 wsUseXShape=0; | |
237 } | |
238 #else | |
239 wsUseXShape=0; | |
240 #endif | |
241 | |
242 XSynchronize( wsDisplay,True ); | |
243 | |
244 wsScreen=DefaultScreen( wsDisplay ); | |
245 wsRootWin=RootWindow( wsDisplay,wsScreen ); | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
246 #ifdef CONFIG_XF86VM |
23077 | 247 { |
248 int clock; | |
249 XF86VidModeModeLine modeline; | |
250 | |
251 XF86VidModeGetModeLine( wsDisplay,wsScreen,&clock ,&modeline ); | |
252 wsMaxX=modeline.hdisplay; | |
253 wsMaxY=modeline.vdisplay; | |
254 } | |
255 #endif | |
256 { | |
257 wsOrgX = wsOrgY = 0; | |
258 if ( !wsMaxX ) | |
259 wsMaxX=DisplayWidth( wsDisplay,wsScreen ); | |
260 if ( !wsMaxY ) | |
261 wsMaxY=DisplayHeight( wsDisplay,wsScreen ); | |
262 } | |
263 vo_screenwidth = wsMaxX; vo_screenheight = wsMaxY; | |
264 xinerama_x = wsOrgX; xinerama_y = wsOrgY; | |
265 update_xinerama_info(); | |
266 wsMaxX = vo_screenwidth; wsMaxY = vo_screenheight; | |
267 wsOrgX = xinerama_x; wsOrgY = xinerama_y; | |
268 | |
269 wsGetDepthOnScreen(); | |
270 #ifdef DEBUG | |
271 { | |
272 int minor,major,shp; | |
273 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] Screen depth: %d\n",wsDepthOnScreen ); | |
274 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
|
275 #ifdef CONFIG_XINERAMA |
23077 | 276 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] origin: +%d+%d\n",wsOrgX,wsOrgY ); |
277 #endif | |
278 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] red mask: 0x%x\n",wsRedMask ); | |
279 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] green mask: 0x%x\n",wsGreenMask ); | |
280 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] blue mask: 0x%x\n",wsBlueMask ); | |
281 if ( wsUseXShm ) | |
282 { | |
283 XShmQueryVersion( wsDisplay,&major,&minor,&shp ); | |
284 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] XShm version is %d.%d\n",major,minor ); | |
285 } | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
286 #ifdef CONFIG_XSHAPE |
23077 | 287 if ( wsUseXShape ) |
288 { | |
289 XShapeQueryVersion( wsDisplay,&major,&minor ); | |
290 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] XShape version is %d.%d\n",major,minor ); | |
291 } | |
292 #endif | |
293 } | |
294 #endif | |
295 wsOutMask=wsGetOutMask(); | |
296 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[ws] Initialized converter: " ); | |
297 sws_rgb2rgb_init(get_sws_cpuflags()); | |
298 switch ( wsOutMask ) | |
299 { | |
300 case wsRGB32: | |
301 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to rgb32\n" ); | |
302 wsConvFunc=rgb32torgb32; | |
303 break; | |
304 case wsBGR32: | |
305 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to bgr32\n" ); | |
306 wsConvFunc=rgb32tobgr32; | |
307 break; | |
308 case wsRGB24: | |
309 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to rgb24\n" ); | |
310 wsConvFunc=rgb32to24; | |
311 break; | |
312 case wsBGR24: | |
313 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to bgr24\n" ); | |
314 wsConvFunc=rgb32tobgr24; | |
315 break; | |
316 case wsRGB16: | |
317 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to rgb16\n" ); | |
318 wsConvFunc=rgb32to16; | |
319 break; | |
320 case wsBGR16: | |
321 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to bgr16\n" ); | |
322 wsConvFunc=rgb32tobgr16; | |
323 break; | |
324 case wsRGB15: | |
325 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to rgb15\n" ); | |
326 wsConvFunc=rgb32to15; | |
327 break; | |
328 case wsBGR15: | |
329 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to bgr15\n" ); | |
330 wsConvFunc=rgb32tobgr15; | |
331 break; | |
332 } | |
333 XSetErrorHandler( wsErrorHandler ); | |
334 } | |
335 | |
336 // ---------------------------------------------------------------------------------------------- | |
337 // Create window. | |
338 // X,Y : window position | |
339 // wX,wY : size of window | |
340 // bW : border width | |
341 // cV : visible mouse cursor on window | |
342 // D : visible frame, title, etc. | |
343 // sR : screen ratio | |
344 // ---------------------------------------------------------------------------------------------- | |
345 | |
346 XClassHint wsClassHint; | |
347 XTextProperty wsTextProperty; | |
348 Window LeaderWindow; | |
349 | |
350 void wsCreateWindow( wsTWindow * win,int X,int Y,int wX,int hY,int bW,int cV,unsigned char D,char * label ) | |
351 { | |
352 int depth; | |
353 | |
354 win->Property=D; | |
355 if ( D & wsShowFrame ) win->Decorations=1; | |
356 wsHGC=DefaultGC( wsDisplay,wsScreen ); | |
357 // The window position and size. | |
358 switch ( X ) | |
359 { | |
360 case -1: win->X=( wsMaxX / 2 ) - ( wX / 2 ) + wsOrgX; break; | |
361 case -2: win->X=wsMaxX - wX - 1 + wsOrgX; break; | |
362 default: win->X=X; break; | |
363 } | |
364 switch ( Y ) | |
365 { | |
366 case -1: win->Y=( wsMaxY / 2 ) - ( hY / 2 ) + wsOrgY; break; | |
367 case -2: win->Y=wsMaxY - hY - 1 + wsOrgY; break; | |
368 default: win->Y=Y; break; | |
369 } | |
370 win->Width=wX; | |
371 win->Height=hY; | |
372 win->OldX=win->X; | |
373 win->OldY=win->Y; | |
374 win->OldWidth=win->Width; | |
375 win->OldHeight=win->Height; | |
376 | |
377 // Border size for window. | |
378 win->BorderWidth=bW; | |
379 // Hide Mouse Cursor | |
380 win->wsCursor=None; | |
381 win->wsMouseEventType=cV; | |
382 win->wsCursorData[0]=0; | |
383 win->wsCursorPixmap=XCreateBitmapFromData( wsDisplay,wsRootWin,win->wsCursorData,1,1 ); | |
384 if ( !(cV & wsShowMouseCursor) ) win->wsCursor=XCreatePixmapCursor( wsDisplay,win->wsCursorPixmap,win->wsCursorPixmap,&win->wsColor,&win->wsColor,0,0 ); | |
385 | |
386 depth = vo_find_depth_from_visuals( wsDisplay,wsScreen,NULL ); | |
387 if ( depth < 15 ) | |
388 { | |
389 mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_ColorDepthTooLow ); | |
390 exit( 0 ); | |
391 } | |
392 XMatchVisualInfo( wsDisplay,wsScreen,depth,TrueColor,&win->VisualInfo ); | |
393 | |
394 // --- | |
395 win->AtomLeaderClient=XInternAtom( wsDisplay,"WM_CLIENT_LEADER",False ); | |
396 win->AtomDeleteWindow=XInternAtom( wsDisplay,"WM_DELETE_WINDOW",False ); | |
397 win->AtomTakeFocus=XInternAtom( wsDisplay,"WM_TAKE_FOCUS",False ); | |
398 win->AtomRolle=XInternAtom( wsDisplay,"WM_WINDOW_ROLE",False ); | |
399 win->AtomWMSizeHint=XInternAtom( wsDisplay,"WM_SIZE_HINT",False ); | |
400 win->AtomWMNormalHint=XInternAtom( wsDisplay,"WM_NORMAL_HINT",False ); | |
401 win->AtomProtocols=XInternAtom( wsDisplay,"WM_PROTOCOLS",False ); | |
402 win->AtomsProtocols[0]=win->AtomDeleteWindow; | |
403 win->AtomsProtocols[1]=win->AtomTakeFocus; | |
404 win->AtomsProtocols[2]=win->AtomRolle; | |
405 // --- | |
406 | |
407 win->WindowAttrib.background_pixel=BlackPixel( wsDisplay,wsScreen ); | |
408 win->WindowAttrib.border_pixel=WhitePixel( wsDisplay,wsScreen ); | |
409 win->WindowAttrib.colormap=XCreateColormap( wsDisplay,wsRootWin,win->VisualInfo.visual,AllocNone ); | |
410 win->WindowAttrib.event_mask=StructureNotifyMask | FocusChangeMask | | |
411 ExposureMask | PropertyChangeMask | | |
412 EnterWindowMask | LeaveWindowMask | | |
413 VisibilityChangeMask | | |
414 KeyPressMask | KeyReleaseMask; | |
415 if ( ( cV & wsHandleMouseButton ) ) win->WindowAttrib.event_mask|=ButtonPressMask | ButtonReleaseMask; | |
416 if ( ( cV & wsHandleMouseMove ) ) win->WindowAttrib.event_mask|=PointerMotionMask; | |
417 win->WindowAttrib.cursor=win->wsCursor; | |
418 win->WindowAttrib.override_redirect=False; | |
419 if ( D & wsOverredirect ) win->WindowAttrib.override_redirect=True; | |
420 | |
421 win->WindowMask=CWBackPixel | CWBorderPixel | | |
422 CWColormap | CWEventMask | CWCursor | | |
423 CWOverrideRedirect; | |
424 | |
425 win->WindowID=XCreateWindow( wsDisplay, | |
426 (win->Parent != 0?win->Parent:wsRootWin), | |
427 win->X,win->Y,win->Width,win->Height,win->BorderWidth, | |
428 win->VisualInfo.depth, | |
429 InputOutput, | |
430 win->VisualInfo.visual, | |
431 win->WindowMask,&win->WindowAttrib ); | |
432 | |
433 wsClassHint.res_name="MPlayer"; | |
434 | |
435 wsClassHint.res_class="MPlayer"; | |
436 XSetClassHint( wsDisplay,win->WindowID,&wsClassHint ); | |
437 | |
438 win->SizeHint.flags=PPosition | PSize | PResizeInc | PWinGravity;// | PBaseSize; | |
439 win->SizeHint.x=win->X; | |
440 win->SizeHint.y=win->Y; | |
441 win->SizeHint.width=win->Width; | |
442 win->SizeHint.height=win->Height; | |
443 | |
444 if ( D & wsMinSize ) | |
445 { | |
446 win->SizeHint.flags|=PMinSize; | |
447 win->SizeHint.min_width=win->Width; | |
448 win->SizeHint.min_height=win->Height; | |
449 } | |
450 if ( D & wsMaxSize ) | |
451 { | |
452 win->SizeHint.flags|=PMaxSize; | |
453 win->SizeHint.max_width=win->Width; | |
454 win->SizeHint.max_height=win->Height; | |
455 } | |
456 | |
457 win->SizeHint.height_inc=1; | |
458 win->SizeHint.width_inc=1; | |
459 win->SizeHint.base_width=win->Width; | |
460 win->SizeHint.base_height=win->Height; | |
461 win->SizeHint.win_gravity=StaticGravity; | |
462 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); | |
463 | |
464 win->WMHints.flags=InputHint | StateHint; | |
465 win->WMHints.input=True; | |
466 win->WMHints.initial_state=NormalState; | |
467 XSetWMHints( wsDisplay,win->WindowID,&win->WMHints ); | |
468 | |
469 wsWindowDecoration( win,win->Decorations ); | |
470 XStoreName( wsDisplay,win->WindowID,label ); | |
471 XmbSetWMProperties( wsDisplay,win->WindowID,label,label,NULL,0,NULL,NULL,NULL ); | |
472 | |
473 XSetWMProtocols( wsDisplay,win->WindowID,win->AtomsProtocols,3 ); | |
474 XChangeProperty( wsDisplay,win->WindowID, | |
475 win->AtomLeaderClient, | |
476 XA_WINDOW,32,PropModeReplace, | |
477 (unsigned char *)&LeaderWindow,1 ); | |
478 | |
479 wsTextProperty.value=label; | |
480 wsTextProperty.encoding=XA_STRING; | |
481 wsTextProperty.format=8; | |
482 wsTextProperty.nitems=strlen( label ); | |
483 XSetWMIconName( wsDisplay,win->WindowID,&wsTextProperty ); | |
484 | |
485 win->wGC=XCreateGC( wsDisplay,win->WindowID, | |
486 GCForeground | GCBackground, | |
487 &win->wGCV ); | |
488 | |
489 win->Visible=0; | |
490 win->Focused=0; | |
491 win->Mapped=0; | |
492 win->Rolled=0; | |
493 if ( D & wsShowWindow ) XMapWindow( wsDisplay,win->WindowID ); | |
494 | |
495 wsCreateImage( win,win->Width,win->Height ); | |
496 // --- End of creating -------------------------------------------------------------------------- | |
497 | |
498 { | |
499 int i; | |
500 for ( i=0;i < wsWLCount;i++ ) | |
501 if ( wsWindowList[i] == NULL ) break; | |
502 if ( i == wsWLCount ) | |
503 { mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_TooManyOpenWindows ); exit( 0 ); } | |
504 wsWindowList[i]=win; | |
505 } | |
506 | |
507 XFlush( wsDisplay ); | |
508 XSync( wsDisplay,False ); | |
509 | |
510 win->ReDraw=NULL; | |
511 win->ReSize=NULL; | |
512 win->Idle=NULL; | |
513 win->MouseHandler=NULL; | |
514 win->KeyHandler=NULL; | |
515 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[ws] window is created. ( %s ).\n",label ); | |
516 } | |
517 | |
518 void wsDestroyWindow( wsTWindow * win ) | |
519 { | |
520 int l; | |
521 l=wsSearch( win->WindowID ); | |
522 wsWindowList[l]=NULL; | |
523 if ( win->wsCursor != None ) | |
524 { | |
525 XFreeCursor( wsDisplay,win->wsCursor ); | |
526 win->wsCursor=None; | |
527 } | |
528 XFreeGC( wsDisplay,win->wGC ); | |
529 XUnmapWindow( wsDisplay,win->WindowID ); | |
530 wsDestroyImage( win ); | |
531 XDestroyWindow( wsDisplay,win->WindowID ); | |
532 #if 0 | |
533 win->ReDraw=NULL; | |
534 win->ReSize=NULL; | |
535 win->Idle=NULL; | |
536 win->MouseHandler=NULL; | |
537 win->KeyHandler=NULL; | |
538 win->Visible=0; | |
539 win->Focused=0; | |
540 win->Mapped=0; | |
541 win->Rolled=0; | |
542 #endif | |
543 } | |
544 | |
545 // ---------------------------------------------------------------------------------------------- | |
546 // Handle events. | |
547 // ---------------------------------------------------------------------------------------------- | |
548 | |
549 inline int wsSearch( Window win ) | |
550 { | |
551 int i; | |
552 for ( i=0;i<wsWLCount;i++ ) if ( wsWindowList[i] && wsWindowList[i]->WindowID == win ) return i; | |
553 return -1; | |
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" |