Mercurial > mplayer.hg
annotate Gui/wm/ws.c @ 5919:60cf2bca993f
some bug fix
author | pontscho |
---|---|
date | Wed, 01 May 2002 09:29:06 +0000 |
parents | 20c335d98ab3 |
children | d34622ebaf45 |
rev | line source |
---|---|
1693 | 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> | |
2081 | 12 |
13 #include <stdio.h> | |
1693 | 14 #include <stdlib.h> |
2081 | 15 #include <string.h> |
16 #include <unistd.h> | |
17 #include <errno.h> | |
1693 | 18 |
2733 | 19 #include <inttypes.h> |
20 | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
4566
diff
changeset
|
21 #include "../../config.h" |
1693 | 22 #include "ws.h" |
23 #include "wsconv.h" | |
2733 | 24 #include "../../postproc/rgb2rgb.h" |
5919 | 25 #include "../../mp_msg.h" |
1693 | 26 |
27 #include <X11/extensions/XShm.h> | |
2476 | 28 #ifdef HAVE_XSHAPE |
1693 | 29 #include <X11/extensions/shape.h> |
2476 | 30 #endif |
31 | |
1693 | 32 #include <sys/ipc.h> |
33 #include <sys/shm.h> | |
34 | |
35 typedef struct | |
36 { | |
3054 | 37 unsigned long flags; |
38 unsigned long functions; | |
39 unsigned long decorations; | |
1693 | 40 long input_mode; |
3054 | 41 unsigned long status; |
1693 | 42 } MotifWmHints; |
43 | |
44 Atom wsMotifHints; | |
45 | |
4465 | 46 int wsMaxX = 0; // Screen width. |
47 int wsMaxY = 0; // Screen height. | |
1693 | 48 |
49 Display * wsDisplay; | |
50 int wsScreen; | |
51 Window wsRootWin; | |
52 XEvent wsEvent; | |
53 int wsWindowDepth; | |
5910
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
54 int wsWMType = 1; |
5919 | 55 int wsIsKDE = 0; |
1693 | 56 GC wsHGC; |
57 MotifWmHints wsMotifWmHints; | |
58 Atom wsTextProperlyAtom = None; | |
59 | |
60 int wsDepthOnScreen = 0; | |
61 int wsRedMask = 0; | |
62 int wsGreenMask = 0; | |
63 int wsBlueMask = 0; | |
64 int wsOutMask = 0; | |
65 | |
66 int wsTrue = True; | |
67 | |
68 wsTWindow * wsWindowList[5] = { NULL,NULL,NULL,NULL,NULL }; | |
69 int wsWLCount = 0; | |
70 | |
71 unsigned long wsKeyTable[512]; | |
72 | |
73 int wsUseXShm = 1; | |
74 int wsUseXShape = 1; | |
75 | |
76 int XShmGetEventBase( Display* ); | |
77 inline int wsSearch( Window win ); | |
78 | |
79 #define MWM_HINTS_FUNCTIONS (1L << 0) | |
80 #define MWM_HINTS_DECORATIONS (1L << 1) | |
81 #define MWM_HINTS_INPUT_MODE (1L << 2) | |
82 #define MWM_HINTS_STATUS (1L << 3) | |
83 | |
84 #define MWM_FUNC_ALL (1L << 0) | |
85 #define MWM_FUNC_RESIZE (1L << 1) | |
86 #define MWM_FUNC_MOVE (1L << 2) | |
87 #define MWM_FUNC_MINIMIZE (1L << 3) | |
88 #define MWM_FUNC_MAXIMIZE (1L << 4) | |
89 #define MWM_FUNC_CLOSE (1L << 5) | |
90 | |
91 #define MWM_DECOR_ALL (1L << 0) | |
92 #define MWM_DECOR_BORDER (1L << 1) | |
93 #define MWM_DECOR_RESIZEH (1L << 2) | |
94 #define MWM_DECOR_TITLE (1L << 3) | |
95 #define MWM_DECOR_MENU (1L << 4) | |
96 #define MWM_DECOR_MINIMIZE (1L << 5) | |
97 #define MWM_DECOR_MAXIMIZE (1L << 6) | |
98 | |
99 #define MWM_INPUT_MODELESS 0 | |
100 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 | |
101 #define MWM_INPUT_SYSTEM_MODAL 2 | |
102 #define MWM_INPUT_FULL_APPLICATION_MODAL 3 | |
103 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL | |
104 | |
105 #define MWM_TEAROFF_WINDOW (1L<<0) | |
106 | |
107 void wsWindowDecoration( wsTWindow * win,long d ) | |
108 { | |
109 wsMotifHints=XInternAtom( wsDisplay,"_MOTIF_WM_HINTS",0 ); | |
3054 | 110 if ( wsMotifHints == None ) return; |
111 | |
112 memset( &wsMotifWmHints,0,sizeof( MotifWmHints ) ); | |
5031 | 113 wsMotifWmHints.flags=MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; |
114 if ( d ) | |
115 { | |
116 wsMotifWmHints.functions=MWM_FUNC_MOVE | MWM_FUNC_CLOSE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE; | |
117 wsMotifWmHints.decorations=MWM_DECOR_ALL; | |
118 } | |
3054 | 119 XChangeProperty( wsDisplay,win->WindowID,wsMotifHints,wsMotifHints,32, |
120 PropModeReplace,(unsigned char *)&wsMotifWmHints,5 ); | |
1693 | 121 } |
122 | |
123 // ---------------------------------------------------------------------------------------------- | |
124 // Init X Window System. | |
125 // ---------------------------------------------------------------------------------------------- | |
126 | |
127 int wsIOErrorHandler( Display * dpy ) | |
128 { | |
129 fprintf( stderr,"[ws] io error in display.\n" ); | |
130 exit( 0 ); | |
131 } | |
132 | |
133 int wsErrorHandler( Display * dpy,XErrorEvent * Event ) | |
134 { | |
135 char type[128]; | |
136 XGetErrorText( wsDisplay,Event->error_code,type,128 ); | |
137 fprintf(stderr,"[ws] Error in display.\n"); | |
138 fprintf(stderr,"[ws] Error code: %d ( %s )\n",Event->error_code,type ); | |
139 fprintf(stderr,"[ws] Request code: %d\n",Event->request_code ); | |
140 fprintf(stderr,"[ws] Minor code: %d\n",Event->minor_code ); | |
141 exit( 0 ); | |
142 } | |
143 | |
1723
5e4214a7540e
GUI stuff. now seeking works, and xmga renders to video window
arpi
parents:
1709
diff
changeset
|
144 void wsXInit( void* mDisplay ) |
1693 | 145 { |
146 int eventbase; | |
147 int errorbase; | |
148 | |
1723
5e4214a7540e
GUI stuff. now seeking works, and xmga renders to video window
arpi
parents:
1709
diff
changeset
|
149 if(mDisplay){ |
5e4214a7540e
GUI stuff. now seeking works, and xmga renders to video window
arpi
parents:
1709
diff
changeset
|
150 wsDisplay=mDisplay; |
5e4214a7540e
GUI stuff. now seeking works, and xmga renders to video window
arpi
parents:
1709
diff
changeset
|
151 } else { |
5e4214a7540e
GUI stuff. now seeking works, and xmga renders to video window
arpi
parents:
1709
diff
changeset
|
152 char * DisplayName = ":0.0"; |
1693 | 153 if ( getenv( "DISPLAY" ) ) DisplayName=getenv( "DISPLAY" ); |
154 wsDisplay=XOpenDisplay( DisplayName ); | |
155 if ( !wsDisplay ) | |
156 { | |
5919 | 157 mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] couldn't open the display !\n" ); |
1693 | 158 exit( 0 ); |
159 } | |
1723
5e4214a7540e
GUI stuff. now seeking works, and xmga renders to video window
arpi
parents:
1709
diff
changeset
|
160 } |
1693 | 161 |
1838 | 162 { /* on remote display XShm will be disabled - LGB */ |
163 char *dispname=DisplayString(wsDisplay); | |
164 int localdisp=1; | |
165 if (dispname&&*dispname!=':') { | |
166 localdisp=0; | |
167 wsUseXShm=0; | |
168 } | |
5919 | 169 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[ws] Display name: %s => %s display.\n",dispname,localdisp?"local":"REMOTE"); |
170 if (!localdisp) mp_msg( MSGT_GPLAYER,MSGL_STATUS,"[ws] Remote display, disabling XMITSHM\n"); | |
1838 | 171 } |
172 | |
1693 | 173 if ( !XShmQueryExtension( wsDisplay ) ) |
174 { | |
5919 | 175 mp_msg( MSGT_GPLAYER,MSGL_ERR,"[ws] sorry, your system is not supported X shared memory extension.\n" ); |
1693 | 176 wsUseXShm=0; |
177 } | |
1699 | 178 #ifdef HAVE_XSHAPE |
1693 | 179 if ( !XShapeQueryExtension( wsDisplay,&eventbase,&errorbase ) ) |
180 { | |
5919 | 181 mp_msg( MSGT_GPLAYER,MSGL_ERR,"[ws] sorry, your system is not supported XShape extension.\n" ); |
1693 | 182 wsUseXShape=0; |
183 } | |
1699 | 184 #else |
1693 | 185 wsUseXShape=0; |
1699 | 186 #endif |
1693 | 187 |
188 XSynchronize( wsDisplay,True ); | |
189 | |
190 wsScreen=DefaultScreen( wsDisplay ); | |
191 wsRootWin=RootWindow( wsDisplay,wsScreen ); | |
192 wsMaxX=DisplayWidth( wsDisplay,wsScreen ); | |
193 wsMaxY=DisplayHeight( wsDisplay,wsScreen ); | |
194 | |
195 wsGetDepthOnScreen(); | |
1699 | 196 #ifdef DEBUG |
1693 | 197 { |
198 int minor,major,shp; | |
5919 | 199 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] Screen depth: %d\n",wsDepthOnScreen ); |
200 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] size: %dx%d\n",wsMaxX,wsMaxY ); | |
201 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] red mask: 0x%x\n",wsRedMask ); | |
202 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] green mask: 0x%x\n",wsGreenMask ); | |
203 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] blue mask: 0x%x\n",wsBlueMask ); | |
1693 | 204 if ( wsUseXShm ) |
205 { | |
206 XShmQueryVersion( wsDisplay,&major,&minor,&shp ); | |
5919 | 207 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] XShm version is %d.%d\n",major,minor ); |
1693 | 208 } |
209 #ifdef HAVE_XSHAPE | |
210 if ( wsUseXShape ) | |
211 { | |
212 XShapeQueryVersion( wsDisplay,&major,&minor ); | |
5919 | 213 mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] XShape version is %d.%d\n",major,minor ); |
1693 | 214 } |
215 #endif | |
216 } | |
1699 | 217 #endif |
1693 | 218 initConverter(); |
219 wsOutMask=wsGetOutMask(); | |
5919 | 220 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[ws] Initialized converter: " ); |
1693 | 221 switch ( wsOutMask ) |
222 { | |
223 case wsRGB32: | |
5919 | 224 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to rgb32\n" ); |
1693 | 225 wsConvFunc=BGR8880_to_RGB8880_c; |
226 break; | |
227 case wsBGR32: | |
5919 | 228 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to bgr32\n" ); |
2782 | 229 wsConvFunc=rgb32tobgr32; |
1693 | 230 break; |
231 case wsRGB24: | |
5919 | 232 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to rgb24\n" ); |
2733 | 233 wsConvFunc=rgb32to24; |
1693 | 234 break; |
235 case wsBGR24: | |
5919 | 236 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to bgr24\n" ); |
1693 | 237 wsConvFunc=BGR8880_to_BGR888_c; |
238 break; | |
239 case wsRGB16: | |
5919 | 240 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to rgb16\n" ); |
2733 | 241 wsConvFunc=rgb32to16; |
1693 | 242 break; |
243 case wsBGR16: | |
5919 | 244 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to bgr16\n" ); |
1693 | 245 wsConvFunc=BGR8880_to_BGR565_c; |
246 break; | |
247 case wsRGB15: | |
5919 | 248 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to rgb15\n" ); |
2733 | 249 wsConvFunc=rgb32to15; |
1693 | 250 break; |
251 case wsBGR15: | |
5919 | 252 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"rgb32 to bgr15\n" ); |
1693 | 253 wsConvFunc=BGR8880_to_BGR555_c; |
254 break; | |
255 } | |
256 } | |
257 | |
258 // ---------------------------------------------------------------------------------------------- | |
259 // Create window. | |
260 // X,Y : window position | |
261 // wX,wY : size of window | |
262 // bW : border width | |
263 // cV : visible mouse cursor on window | |
264 // D : visible frame, title, etc. | |
265 // sR : screen ratio | |
266 // ---------------------------------------------------------------------------------------------- | |
267 | |
268 XClassHint wsClassHint; | |
269 XTextProperty wsTextProperty; | |
270 Window LeaderWindow; | |
271 | |
272 void wsCreateWindow( wsTWindow * win,int X,int Y,int wX,int hY,int bW,int cV,unsigned char D,char * label ) | |
273 { | |
274 win->Property=D; | |
275 if ( D & wsShowFrame ) win->Decorations=1; | |
276 wsHGC=DefaultGC( wsDisplay,wsScreen ); | |
277 // The window position and size. | |
278 switch ( X ) | |
279 { | |
280 case -1: win->X=( wsMaxX / 2 ) - ( wX / 2 ); break; | |
281 case -2: win->X=wsMaxX - wX - 1; break; | |
282 default: win->X=X; break; | |
283 } | |
284 switch ( Y ) | |
285 { | |
286 case -1: win->Y=( wsMaxY / 2 ) - ( hY / 2 ); break; | |
287 case -2: win->Y=wsMaxY - hY - 1; break; | |
288 default: win->Y=Y; break; | |
289 } | |
290 win->Width=wX; | |
291 win->Height=hY; | |
292 win->OldX=win->X; | |
293 win->OldY=win->Y; | |
294 win->OldWidth=win->Width; | |
295 win->OldHeight=win->Height; | |
296 | |
297 // Border size for window. | |
298 win->BorderWidth=bW; | |
299 // Hide Mouse Cursor | |
300 win->wsCursor=None; | |
301 win->wsMouseEventType=cV; | |
302 win->wsCursorData[0]=0; | |
303 win->wsCursorPixmap=XCreateBitmapFromData( wsDisplay,wsRootWin,win->wsCursorData,1,1 ); | |
304 if ( !(cV & wsShowMouseCursor) ) win->wsCursor=XCreatePixmapCursor( wsDisplay,win->wsCursorPixmap,win->wsCursorPixmap,&win->wsColor,&win->wsColor,0,0 ); | |
305 | |
306 XGetWindowAttributes( wsDisplay,wsRootWin,&win->Attribs ); | |
307 if ( win->Attribs.depth < 15 ) | |
308 { | |
5919 | 309 mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] sorry, this color depth is not enough.\n" ); |
1693 | 310 exit( 0 ); |
311 } | |
312 XMatchVisualInfo( wsDisplay,wsScreen,win->Attribs.depth,TrueColor,&win->VisualInfo ); | |
313 | |
314 // --- | |
315 win->AtomLeaderClient=XInternAtom( wsDisplay,"WM_CLIENT_LEADER",False ); | |
316 win->AtomDeleteWindow=XInternAtom( wsDisplay,"WM_DELETE_WINDOW",False ); | |
317 win->AtomTakeFocus=XInternAtom( wsDisplay,"WM_TAKE_FOCUS",False ); | |
318 win->AtomRolle=XInternAtom( wsDisplay,"WM_WINDOW_ROLE",False ); | |
2851
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
319 win->AtomWMSizeHint=XInternAtom( wsDisplay,"WM_SIZE_HINT",False ); |
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
320 win->AtomWMNormalHint=XInternAtom( wsDisplay,"WM_NORMAL_HINT",False ); |
1693 | 321 win->AtomProtocols=XInternAtom( wsDisplay,"WM_PROTOCOLS",False ); |
322 win->AtomsProtocols[0]=win->AtomDeleteWindow; | |
323 win->AtomsProtocols[1]=win->AtomTakeFocus; | |
324 win->AtomsProtocols[2]=win->AtomRolle; | |
325 // --- | |
326 | |
327 win->WindowAttrib.background_pixel=BlackPixel( wsDisplay,wsScreen ); | |
328 win->WindowAttrib.border_pixel=WhitePixel( wsDisplay,wsScreen ); | |
329 win->WindowAttrib.colormap=XCreateColormap( wsDisplay,wsRootWin,win->VisualInfo.visual,AllocNone ); | |
330 win->WindowAttrib.event_mask=StructureNotifyMask | FocusChangeMask | | |
331 ExposureMask | PropertyChangeMask | | |
332 EnterWindowMask | LeaveWindowMask | | |
333 VisibilityChangeMask | | |
334 KeyPressMask | KeyReleaseMask; | |
335 if ( ( cV & wsHandleMouseButton ) ) win->WindowAttrib.event_mask|=ButtonPressMask | ButtonReleaseMask; | |
336 if ( ( cV & wsHandleMouseMove ) ) win->WindowAttrib.event_mask|=PointerMotionMask; | |
337 win->WindowAttrib.cursor=win->wsCursor; | |
338 win->WindowAttrib.override_redirect=False; | |
339 if ( D & wsOverredirect ) win->WindowAttrib.override_redirect=True; | |
340 | |
341 win->WindowMask=CWBackPixel | CWBorderPixel | | |
342 CWColormap | CWEventMask | CWCursor | | |
343 CWX | CWY | CWWidth | CWHeight | | |
344 CWOverrideRedirect; | |
345 | |
346 win->WindowID=XCreateWindow( wsDisplay, | |
347 (win->Parent != 0?win->Parent:wsRootWin), | |
348 win->X,win->Y,win->Width,win->Height,win->BorderWidth, | |
349 win->VisualInfo.depth, | |
350 InputOutput, | |
351 win->VisualInfo.visual, | |
352 win->WindowMask,&win->WindowAttrib ); | |
353 | |
4411 | 354 wsClassHint.res_name="MPlayer"; |
355 | |
2029 | 356 wsClassHint.res_class="MPlayer"; |
1693 | 357 XSetClassHint( wsDisplay,win->WindowID,&wsClassHint ); |
358 | |
5919 | 359 win->SizeHint.flags=PPosition | PSize | PResizeInc | PWinGravity | PBaseSize; |
1693 | 360 win->SizeHint.x=win->X; |
361 win->SizeHint.y=win->Y; | |
362 win->SizeHint.width=win->Width; | |
363 win->SizeHint.height=win->Height; | |
1860 | 364 if ( D & wsMinSize ) |
365 { | |
366 win->SizeHint.flags|=PMinSize; | |
367 win->SizeHint.min_width=win->Width; | |
368 win->SizeHint.min_height=win->Height; | |
369 } | |
1693 | 370 if ( D & wsMaxSize ) |
371 { | |
372 win->SizeHint.flags|=PMaxSize; | |
373 win->SizeHint.max_width=win->Width; | |
374 win->SizeHint.max_height=win->Height; | |
375 } | |
376 win->SizeHint.height_inc=1; | |
377 win->SizeHint.width_inc=1; | |
5919 | 378 win->SizeHint.base_width=win->Width; |
379 win->SizeHint.base_height=win->Height; | |
2851
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
380 win->SizeHint.win_gravity=StaticGravity; |
1693 | 381 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); |
382 | |
383 win->WMHints.flags=InputHint | StateHint; | |
384 win->WMHints.input=True; | |
385 win->WMHints.initial_state=NormalState; | |
386 XSetWMHints( wsDisplay,win->WindowID,&win->WMHints ); | |
387 | |
388 wsWindowDecoration( win,win->Decorations ); | |
389 XStoreName( wsDisplay,win->WindowID,label ); | |
390 XmbSetWMProperties( wsDisplay,win->WindowID,label,label,NULL,0,NULL,NULL,NULL ); | |
391 | |
392 XSetWMProtocols( wsDisplay,win->WindowID,win->AtomsProtocols,3 ); | |
393 XChangeProperty( wsDisplay,win->WindowID, | |
394 win->AtomLeaderClient, | |
395 XA_WINDOW,32,PropModeReplace, | |
396 (unsigned char *)&LeaderWindow,1 ); | |
397 | |
398 wsTextProperty.value=label; | |
399 wsTextProperty.encoding=XA_STRING; | |
400 wsTextProperty.format=8; | |
401 wsTextProperty.nitems=strlen( label ); | |
402 XSetWMIconName( wsDisplay,win->WindowID,&wsTextProperty ); | |
403 | |
404 win->wGC=XCreateGC( wsDisplay,win->WindowID, | |
1814 | 405 GCForeground | GCBackground, |
1693 | 406 &win->wGCV ); |
407 | |
408 win->Visible=0; | |
409 win->Focused=0; | |
410 win->Mapped=0; | |
411 win->Rolled=0; | |
412 if ( D & wsShowWindow ) XMapWindow( wsDisplay,win->WindowID ); | |
413 | |
1858
88a88d0a3f94
fix skin changing, xv fullscreen redraw bug, etc.
pontscho
parents:
1853
diff
changeset
|
414 wsCreateImage( win,win->Width,win->Height ); |
1693 | 415 // --- End of creating -------------------------------------------------------------------------- |
416 | |
417 wsWindowList[wsWLCount++]=win; | |
418 | |
419 XFlush( wsDisplay ); | |
420 XSync( wsDisplay,False ); | |
421 | |
422 win->ReDraw=NULL; | |
423 win->ReSize=NULL; | |
424 win->Idle=NULL; | |
425 win->MouseHandler=NULL; | |
426 win->KeyHandler=NULL; | |
5919 | 427 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[ws] window is created. ( %s ).\n",label ); |
1693 | 428 } |
429 | |
430 void wsDestroyWindow( wsTWindow * win ) | |
431 { | |
432 int l; | |
433 l=wsSearch( win->WindowID ); | |
434 wsWindowList[l]=NULL; | |
435 if ( win->wsCursor != None ) | |
436 { | |
437 XFreeCursor( wsDisplay,win->wsCursor ); | |
438 win->wsCursor=None; | |
439 } | |
440 XUnmapWindow( wsDisplay,win->WindowID ); | |
441 wsDestroyImage( win ); | |
442 XDestroyWindow( wsDisplay,win->WindowID ); | |
443 win->ReDraw=NULL; | |
444 win->ReSize=NULL; | |
445 win->Idle=NULL; | |
446 win->MouseHandler=NULL; | |
447 win->KeyHandler=NULL; | |
448 win->Visible=0; | |
449 win->Focused=0; | |
450 win->Mapped=0; | |
451 win->Rolled=0; | |
452 } | |
453 | |
454 // ---------------------------------------------------------------------------------------------- | |
455 // Handle events. | |
456 // ---------------------------------------------------------------------------------------------- | |
457 | |
458 inline int wsSearch( Window win ) | |
459 { | |
460 int i; | |
461 for ( i=0;i<wsWLCount;i++ ) if ( wsWindowList[i]->WindowID == win ) return i; | |
462 return -1; | |
463 } | |
464 | |
465 Bool wsEvents( Display * display,XEvent * Event,XPointer arg ) | |
466 { | |
467 KeySym keySym; | |
468 unsigned long i = 0; | |
469 int l; | |
470 int x,y; | |
471 Window child_window = 0; | |
472 | |
473 l=wsSearch( Event->xany.window ); | |
474 if ( l == -1 ) return !wsTrue; | |
1782 | 475 wsWindowList[l]->State=0; |
1693 | 476 switch( Event->type ) |
477 { | |
478 case ClientMessage: | |
479 if ( Event->xclient.message_type == wsWindowList[l]->AtomProtocols ) | |
480 { | |
481 if ( Event->xclient.data.l[0] == wsWindowList[l]->AtomDeleteWindow ) | |
5919 | 482 { i=wsWindowClosed; goto expose; } |
1693 | 483 if ( Event->xclient.data.l[0] == wsWindowList[l]->AtomTakeFocus ) |
484 { i=wsWindowFocusIn; wsWindowList[l]->Focused=wsFocused; goto expose; } | |
485 if ( Event->xclient.data.l[0] == wsWindowList[l]->AtomRolle ) | |
5919 | 486 { mp_msg( MSGT_GPLAYER,MSGL_STATUS,"[ws] rolled.\n" ); } |
1693 | 487 } |
488 break; | |
489 | |
490 case MapNotify: i=wsWindowMapped; wsWindowList[l]->Mapped=wsMapped; goto expose; | |
491 case UnmapNotify: i=wsWindowUnmapped; wsWindowList[l]->Mapped=wsNone; goto expose; | |
492 case FocusIn: | |
493 if ( wsWindowList[l]->Focused == wsFocused ) break; | |
2851
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
494 i=wsWindowFocusIn; |
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
495 wsWindowList[l]->Focused=wsFocused; |
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
496 goto expose; |
1693 | 497 case FocusOut: |
498 if ( wsWindowList[l]->Focused == wsNone ) break; | |
2851
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
499 i=wsWindowFocusOut; |
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
500 wsWindowList[l]->Focused=wsNone; |
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
501 goto expose; |
1693 | 502 case VisibilityNotify: |
503 switch( Event->xvisibility.state ) | |
504 { | |
505 case VisibilityUnobscured: i=wsWindowVisible; wsWindowList[l]->Visible=wsVisible; goto expose; | |
506 case VisibilityFullyObscured: i=wsWindowNotVisible; wsWindowList[l]->Visible=wsNotVisible; goto expose; | |
507 case VisibilityPartiallyObscured: i=wsWindowPartialVisible; wsWindowList[l]->Visible=wsPVisible; goto expose; | |
508 } | |
509 expose: | |
510 wsWindowList[l]->State=i; | |
511 if ( wsWindowList[l]->ReDraw ) wsWindowList[l]->ReDraw( wsDisplay,Event->xany.window ); | |
512 break; | |
513 | |
514 case Expose: | |
515 wsWindowList[l]->State=wsWindowExpose; | |
516 if ( ( wsWindowList[l]->ReDraw )&&( !Event->xexpose.count ) ) wsWindowList[l]->ReDraw( wsDisplay,Event->xany.window ); | |
517 break; | |
518 | |
519 case ConfigureNotify: | |
520 XTranslateCoordinates( wsDisplay,wsWindowList[l]->WindowID,wsRootWin,0,0,&x,&y,&child_window ); | |
521 if ( ( wsWindowList[l]->X != x )||( wsWindowList[l]->Y != y )||( wsWindowList[l]->Width != Event->xconfigure.width )||( wsWindowList[l]->Height != Event->xconfigure.height ) ) | |
522 { | |
523 wsWindowList[l]->X=x; wsWindowList[l]->Y=y; | |
524 wsWindowList[l]->Width=Event->xconfigure.width; wsWindowList[l]->Height=Event->xconfigure.height; | |
525 if ( wsWindowList[l]->ReSize ) wsWindowList[l]->ReSize( wsWindowList[l]->X,wsWindowList[l]->Y,wsWindowList[l]->Width,wsWindowList[l]->Height ); | |
526 } | |
527 | |
528 wsWindowList[l]->Rolled=wsNone; | |
529 if ( Event->xconfigure.y < 0 ) | |
530 { i=wsWindowRolled; wsWindowList[l]->Rolled=wsRolled; goto expose; } | |
531 | |
532 break; | |
533 | |
534 case KeyPress: i=wsKeyPressed; goto keypressed; | |
535 case KeyRelease: i=wsKeyReleased; | |
536 keypressed: | |
537 wsWindowList[l]->Alt=0; | |
538 wsWindowList[l]->Shift=0; | |
539 wsWindowList[l]->NumLock=0; | |
540 wsWindowList[l]->Control=0; | |
541 wsWindowList[l]->CapsLock=0; | |
542 if ( Event->xkey.state & Mod1Mask ) wsWindowList[l]->Alt=1; | |
543 if ( Event->xkey.state & Mod2Mask ) wsWindowList[l]->NumLock=1; | |
544 if ( Event->xkey.state & ControlMask ) wsWindowList[l]->Control=1; | |
545 if ( Event->xkey.state & ShiftMask ) wsWindowList[l]->Shift=1; | |
546 if ( Event->xkey.state & LockMask ) wsWindowList[l]->CapsLock=1; | |
547 keySym=XKeycodeToKeysym( wsDisplay,Event->xkey.keycode,0 ); | |
548 if ( keySym != NoSymbol ) | |
549 { | |
550 keySym=( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ); | |
551 wsKeyTable[ keySym ]=i; | |
552 if ( wsWindowList[l]->KeyHandler ) | |
553 wsWindowList[l]->KeyHandler( Event->xkey.state,i,keySym ); | |
554 } | |
555 break; | |
556 | |
557 case MotionNotify: i=wsMoveMouse; goto buttonreleased; | |
558 case ButtonRelease: i=Event->xbutton.button + 128; goto buttonreleased; | |
559 case ButtonPress: i=Event->xbutton.button; goto buttonreleased; | |
560 case EnterNotify: i=wsEnterWindow; goto buttonreleased; | |
561 case LeaveNotify: i=wsLeaveWindow; | |
562 buttonreleased: | |
563 if ( wsWindowList[l]->MouseHandler ) | |
564 wsWindowList[l]->MouseHandler( i,Event->xbutton.x,Event->xbutton.y,Event->xmotion.x_root,Event->xmotion.y_root ); | |
565 break; | |
566 | |
567 case PropertyNotify: | |
5910
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
568 { |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
569 char * name = XGetAtomName( wsDisplay,Event->xproperty.atom ); |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
570 |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
571 if ( !name ) break; |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
572 if ( !strncmp( name,"_ICEWM_TRAY",11 ) || |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
573 !strncmp( name,"_KDE_",5 ) || |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
574 !strncmp( name,"KWM_WIN_DESKTOP",15 ) ) wsWMType=0; |
5919 | 575 |
576 if ( !strncmp( name,"_KDE_",5 ) ) wsIsKDE=1; | |
5910
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
577 |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
578 // fprintf(stderr,"[ws] PropertyNotify %s ( 0x%x )\n",name,Event->xproperty.atom ); |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
579 |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
580 XFree( name ); |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
581 break; |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
582 } |
1693 | 583 break; |
584 | |
585 } | |
586 XFlush( wsDisplay ); | |
587 XSync( wsDisplay,False ); | |
588 return !wsTrue; | |
589 } | |
590 | |
591 Bool wsDummyEvents( Display * display,XEvent * Event,XPointer arg ) | |
592 { return True; } | |
593 | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
4566
diff
changeset
|
594 void wsHandleEvents( void ){ |
1709 | 595 // handle pending events |
596 while ( XPending(wsDisplay) ){ | |
597 XNextEvent( wsDisplay,&wsEvent ); | |
598 // printf("### X event: %d [%d]\n",wsEvent.type,delay); | |
599 wsEvents( wsDisplay,&wsEvent,NULL ); | |
600 } | |
601 } | |
602 | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
4566
diff
changeset
|
603 extern void mplTimerHandler( void ); |
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
4566
diff
changeset
|
604 |
1693 | 605 void wsMainLoop( void ) |
606 { | |
1699 | 607 int delay=20; |
5919 | 608 mp_msg( MSGT_GPLAYER,MSGL_STATUS,"[ws] init threads: %d\n",XInitThreads() ); |
1693 | 609 XSynchronize( wsDisplay,False ); |
610 XLockDisplay( wsDisplay ); | |
611 // XIfEvent( wsDisplay,&wsEvent,wsEvents,NULL ); | |
1699 | 612 |
613 #if 1 | |
614 | |
615 while(wsTrue){ | |
616 // handle pending events | |
617 while ( XPending(wsDisplay) ){ | |
618 XNextEvent( wsDisplay,&wsEvent ); | |
619 wsEvents( wsDisplay,&wsEvent,NULL ); | |
1701 | 620 delay=0; |
1699 | 621 } |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
4566
diff
changeset
|
622 mplTimerHandler(); // handle timer event |
1699 | 623 usleep(delay*1000); // FIXME! |
1701 | 624 if(delay<10*20) delay+=20; // pump up delay up to 0.2 sec (low activity) |
1699 | 625 } |
626 | |
627 #else | |
628 | |
1693 | 629 while( wsTrue ) |
630 { | |
631 XIfEvent( wsDisplay,&wsEvent,wsDummyEvents,NULL ); | |
632 wsEvents( wsDisplay,&wsEvent,NULL ); | |
633 } | |
1699 | 634 #endif |
635 | |
1693 | 636 XUnlockDisplay( wsDisplay ); |
637 } | |
638 | |
639 // ---------------------------------------------------------------------------------------------- | |
640 // Switch to fullscreen. | |
641 // ---------------------------------------------------------------------------------------------- | |
642 void wsFullScreen( wsTWindow * win ) | |
643 { | |
644 int decoration = 0; | |
5910
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
645 if ( wsWMType ) XUnmapWindow( wsDisplay,win->WindowID ); |
1693 | 646 if ( win->isFullScreen ) |
647 { | |
648 win->X=win->OldX; | |
649 win->Y=win->OldY; | |
650 win->Width=win->OldWidth; | |
651 win->Height=win->OldHeight; | |
652 win->isFullScreen=False; | |
653 decoration=win->Decorations; | |
654 wsScreenSaverOn( wsDisplay ); | |
655 } | |
656 else | |
657 { | |
658 win->OldX=win->X; win->OldY=win->Y; | |
659 win->OldWidth=win->Width; win->OldHeight=win->Height; | |
660 win->X=0; win->Y=0; | |
661 win->Width=wsMaxX; win->Height=wsMaxY; | |
662 win->isFullScreen=True; | |
663 wsScreenSaverOff( wsDisplay ); | |
664 } | |
665 | |
5910
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
666 win->SizeHint.flags=PPosition | PSize | PWinGravity | PBaseSize; |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
667 win->SizeHint.x=win->X; win->SizeHint.y=win->Y; |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
668 win->SizeHint.width=win->Width; win->SizeHint.height=win->Height; |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
669 win->SizeHint.base_width=win->Width; win->SizeHint.base_height=win->Height; |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
670 win->SizeHint.win_gravity=StaticGravity; |
1860 | 671 if ( win->Property & wsMaxSize ) |
672 { | |
673 win->SizeHint.flags|=PMaxSize; | |
674 win->SizeHint.max_width=win->Width; | |
675 win->SizeHint.max_height=win->Height; | |
676 } | |
677 if ( win->Property & wsMinSize ) | |
678 { | |
679 win->SizeHint.flags|=PMinSize; | |
680 win->SizeHint.min_width=win->Width; | |
681 win->SizeHint.min_height=win->Height; | |
682 } | |
1693 | 683 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); |
684 | |
685 XMoveResizeWindow( wsDisplay,win->WindowID,win->X,win->Y,win->Width,win->Height ); | |
686 wsWindowDecoration( win,decoration ); | |
5910
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
687 XMapRaised( wsDisplay,win->WindowID ); |
1693 | 688 XRaiseWindow( wsDisplay,win->WindowID ); |
689 } | |
690 | |
691 // ---------------------------------------------------------------------------------------------- | |
692 // Redraw screen. | |
693 // ---------------------------------------------------------------------------------------------- | |
694 void wsPostRedisplay( wsTWindow * win ) | |
695 { | |
696 if ( win->ReDraw ) | |
697 { | |
698 win->ReDraw( wsDisplay,win->WindowID ); | |
699 XFlush( wsDisplay ); | |
700 } | |
701 } | |
702 | |
703 // ---------------------------------------------------------------------------------------------- | |
704 // Do Exit. | |
705 // ---------------------------------------------------------------------------------------------- | |
706 void wsDoExit( void ) | |
707 { wsTrue=False; wsResizeWindow( wsWindowList[0],32,32 ); } | |
708 | |
709 // ---------------------------------------------------------------------------------------------- | |
710 // Put 'Image' to window. | |
711 // ---------------------------------------------------------------------------------------------- | |
712 void wsConvert( wsTWindow * win,unsigned char * Image,unsigned int Size ) | |
2733 | 713 { if ( wsConvFunc ) wsConvFunc( Image,win->ImageData,win->xImage->width * win->xImage->height * 4 ); } |
1693 | 714 |
715 void wsPutImage( wsTWindow * win ) | |
716 { | |
717 if ( wsUseXShm ) | |
718 { | |
719 XShmPutImage( wsDisplay,win->WindowID,win->wGC,win->xImage, | |
720 0,0, | |
721 ( win->Width - win->xImage->width ) / 2,( win->Height - win->xImage->height ) / 2, | |
722 win->xImage->width,win->xImage->height,0 ); | |
723 } | |
724 else | |
725 { | |
726 XPutImage( wsDisplay,win->WindowID,win->wGC,win->xImage, | |
727 0,0, | |
728 ( win->Width - win->xImage->width ) / 2,( win->Height - win->xImage->height ) / 2, | |
729 win->xImage->width,win->xImage->height ); | |
730 } | |
731 } | |
732 | |
733 // ---------------------------------------------------------------------------------------------- | |
734 // Move window to x, y. | |
735 // ---------------------------------------------------------------------------------------------- | |
2854 | 736 void wsMoveWindow( wsTWindow * win,int b,int x, int y ) |
1693 | 737 { |
2854 | 738 if ( b ) |
1693 | 739 { |
2854 | 740 switch ( x ) |
741 { | |
742 case -1: win->X=( wsMaxX / 2 ) - ( win->Width / 2 ); break; | |
743 case -2: win->X=wsMaxX - win->Width; break; | |
744 default: win->X=x; break; | |
745 } | |
746 switch ( y ) | |
747 { | |
748 case -1: win->Y=( wsMaxY / 2 ) - ( win->Height / 2 ); break; | |
749 case -2: win->Y=wsMaxY - win->Height; break; | |
750 default: win->Y=y; break; | |
751 } | |
1693 | 752 } |
2854 | 753 else { win->X=x; win->Y=y; } |
1693 | 754 |
2851
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
755 win->SizeHint.flags=PPosition | PWinGravity; |
1693 | 756 win->SizeHint.x=win->X; |
757 win->SizeHint.y=win->Y; | |
2851
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
758 win->SizeHint.win_gravity=StaticGravity; |
1693 | 759 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); |
760 | |
761 XMoveWindow( wsDisplay,win->WindowID,win->X,win->Y ); | |
1810 | 762 if ( win->ReSize ) win->ReSize( win->X,win->Y,win->Width,win->Height ); |
1693 | 763 } |
764 | |
765 // ---------------------------------------------------------------------------------------------- | |
766 // Resize window to sx, sy. | |
767 // ---------------------------------------------------------------------------------------------- | |
768 void wsResizeWindow( wsTWindow * win,int sx, int sy ) | |
769 { | |
770 win->Width=sx; | |
771 win->Height=sy; | |
772 | |
2851
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
773 win->SizeHint.flags=PSize | PWinGravity; |
1693 | 774 win->SizeHint.width=win->Width; |
775 win->SizeHint.height=win->Height; | |
776 if ( win->Property & wsMinSize ) | |
777 { | |
778 win->SizeHint.flags|=PMinSize; | |
779 win->SizeHint.min_width=win->Width; | |
780 win->SizeHint.min_height=win->Height; | |
781 } | |
782 if ( win->Property & wsMaxSize ) | |
783 { | |
784 win->SizeHint.flags|=PMaxSize; | |
785 win->SizeHint.max_width=win->Width; | |
786 win->SizeHint.max_height=win->Height; | |
787 } | |
2851
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
788 win->SizeHint.win_gravity=StaticGravity; |
1693 | 789 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); |
790 XResizeWindow( wsDisplay,win->WindowID,sx,sy ); | |
1810 | 791 if ( win->ReSize ) win->ReSize( win->X,win->Y,win->Width,win->Height ); |
1693 | 792 } |
793 | |
794 // ---------------------------------------------------------------------------------------------- | |
795 // Iconify window. | |
796 // ---------------------------------------------------------------------------------------------- | |
797 void wsIconify( wsTWindow win ) | |
798 { XIconifyWindow( wsDisplay,win.WindowID,0 ); } | |
799 | |
800 // ---------------------------------------------------------------------------------------------- | |
801 // Move top the window. | |
802 // ---------------------------------------------------------------------------------------------- | |
803 void wsMoveTopWindow( wsTWindow * win ) | |
2851
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
804 { |
5919 | 805 if ( wsIsKDE ) return; |
806 XMapRaised( wsDisplay,win->WindowID ); | |
2851
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
807 XRaiseWindow( wsDisplay,win->WindowID ); |
2045 | 808 } |
1693 | 809 |
810 // ---------------------------------------------------------------------------------------------- | |
811 // Set window background to 'color'. | |
812 // ---------------------------------------------------------------------------------------------- | |
813 void wsSetBackground( wsTWindow * win,int color ) | |
814 { XSetWindowBackground( wsDisplay,win->WindowID,color ); } | |
815 | |
816 void wsSetBackgroundRGB( wsTWindow * win,int r,int g,int b ) | |
817 { | |
818 int color = 0; | |
819 switch ( wsOutMask ) | |
820 { | |
821 case wsRGB32: | |
822 case wsRGB24: color=( r << 16 ) + ( g << 8 ) + b; break; | |
823 case wsBGR32: | |
824 case wsBGR24: color=( b << 16 ) + ( g << 8 ) + r; break; | |
2733 | 825 case wsRGB16: PACK_RGB16( b,g,r,color ); break; |
826 case wsBGR16: PACK_RGB16( r,g,b,color ); break; | |
827 case wsRGB15: PACK_RGB15( b,g,r,color ); break; | |
828 case wsBGR15: PACK_RGB15( r,g,b,color ); break; | |
1693 | 829 } |
830 XSetWindowBackground( wsDisplay,win->WindowID,color ); | |
831 } | |
832 | |
1814 | 833 void wsSetForegroundRGB( wsTWindow * win,int r,int g,int b ) |
834 { | |
835 int color = 0; | |
836 switch ( wsOutMask ) | |
837 { | |
838 case wsRGB32: | |
839 case wsRGB24: color=( r << 16 ) + ( g << 8 ) + b; break; | |
840 case wsBGR32: | |
841 case wsBGR24: color=( b << 16 ) + ( g << 8 ) + r; break; | |
2733 | 842 case wsRGB16: PACK_RGB16( b,g,r,color ); break; |
843 case wsBGR16: PACK_RGB16( r,g,b,color ); break; | |
844 case wsRGB15: PACK_RGB15( b,g,r,color ); break; | |
845 case wsBGR15: PACK_RGB15( r,g,b,color ); break; | |
1814 | 846 } |
847 XSetForeground( wsDisplay,win->wGC,color ); | |
848 } | |
1693 | 849 |
850 // ---------------------------------------------------------------------------------------------- | |
851 // Draw string at x,y with fc ( foreground color ) and bc ( background color ). | |
852 // ---------------------------------------------------------------------------------------------- | |
853 void wsDrawString( wsTWindow win,int x,int y,char * str,int fc,int bc ) | |
854 { | |
855 XSetForeground( wsDisplay,win.wGC,bc ); | |
856 XFillRectangle( wsDisplay,win.WindowID,win.wGC,x,y, | |
857 XTextWidth( win.Font,str,strlen( str ) ) + 20, | |
858 win.FontHeight + 2 ); | |
859 XSetForeground( wsDisplay,win.wGC,fc ); | |
860 XDrawString( wsDisplay,win.WindowID,win.wGC,x + 10,y + 13,str,strlen( str ) ); | |
861 } | |
862 | |
863 // ---------------------------------------------------------------------------------------------- | |
864 // Calculation string width. | |
865 // ---------------------------------------------------------------------------------------------- | |
866 int wsTextWidth( wsTWindow win,char * str ) | |
867 { return XTextWidth( win.Font,str,strlen( str ) ) + 20; } | |
868 | |
869 // ---------------------------------------------------------------------------------------------- | |
870 // Show / hide mouse cursor. | |
871 // ---------------------------------------------------------------------------------------------- | |
872 void wsVisibleMouse( wsTWindow * win,int m ) | |
873 { | |
874 switch ( m ) | |
875 { | |
876 case wsShowMouseCursor: | |
877 if ( win->wsCursor != None ) | |
878 { | |
879 XFreeCursor( wsDisplay,win->wsCursor ); | |
880 win->wsCursor=None; | |
881 } | |
882 XDefineCursor( wsDisplay,win->WindowID,0 ); | |
883 break; | |
884 case wsHideMouseCursor: | |
885 win->wsCursor=XCreatePixmapCursor( wsDisplay,win->wsCursorPixmap,win->wsCursorPixmap,&win->wsColor,&win->wsColor,0,0 ); | |
886 XDefineCursor( wsDisplay,win->WindowID,win->wsCursor ); | |
887 break; | |
888 } | |
889 XFlush( wsDisplay ); | |
890 } | |
891 | |
892 int wsGetDepthOnScreen( void ) | |
893 { | |
894 int bpp,ibpp; | |
895 XImage * mXImage; | |
896 XWindowAttributes attribs; | |
897 | |
898 mXImage=XGetImage( wsDisplay,wsRootWin,0,0,1,1,AllPlanes,ZPixmap ); | |
899 bpp=mXImage->bits_per_pixel; | |
900 | |
901 XGetWindowAttributes( wsDisplay,wsRootWin,&attribs ); | |
902 ibpp=attribs.depth; | |
903 mXImage=XGetImage( wsDisplay,wsRootWin,0,0,1,1,AllPlanes,ZPixmap ); | |
904 bpp=mXImage->bits_per_pixel; | |
905 if ( ( ibpp + 7 ) / 8 != ( bpp + 7 ) / 8 ) ibpp=bpp; | |
906 wsDepthOnScreen=ibpp; | |
907 wsRedMask=mXImage->red_mask; | |
908 wsGreenMask=mXImage->green_mask; | |
909 wsBlueMask=mXImage->blue_mask; | |
910 XDestroyImage( mXImage ); | |
911 return ibpp; | |
912 } | |
913 | |
914 void wsXDone( void ) | |
915 { | |
916 XCloseDisplay( wsDisplay ); | |
917 } | |
918 | |
919 void wsVisibleWindow( wsTWindow * win,int show ) | |
920 { | |
921 switch( show ) | |
922 { | |
923 case wsShowWindow: XMapWindow( wsDisplay,win->WindowID ); break; | |
924 case wsHideWindow: XUnmapWindow( wsDisplay,win->WindowID ); break; | |
925 } | |
926 XFlush( wsDisplay ); | |
927 } | |
928 | |
929 void wsDestroyImage( wsTWindow * win ) | |
930 { | |
931 if ( win->xImage ) | |
932 { | |
933 XDestroyImage( win->xImage ); | |
934 if ( wsUseXShm ) | |
935 { | |
936 XShmDetach( wsDisplay,&win->Shminfo ); | |
937 shmdt( win->Shminfo.shmaddr ); | |
938 } | |
939 } | |
940 win->xImage=NULL; | |
941 } | |
942 | |
1858
88a88d0a3f94
fix skin changing, xv fullscreen redraw bug, etc.
pontscho
parents:
1853
diff
changeset
|
943 void wsCreateImage( wsTWindow * win,int Width,int Height ) |
1693 | 944 { |
945 int CompletionType = -1; | |
946 if ( wsUseXShm ) | |
947 { | |
948 CompletionType=XShmGetEventBase( wsDisplay ) + ShmCompletion; | |
949 win->xImage=XShmCreateImage( wsDisplay,win->VisualInfo.visual, | |
1858
88a88d0a3f94
fix skin changing, xv fullscreen redraw bug, etc.
pontscho
parents:
1853
diff
changeset
|
950 win->Attribs.depth,ZPixmap,NULL,&win->Shminfo,Width,Height ); |
1693 | 951 if ( win->xImage == NULL ) |
952 { | |
5919 | 953 mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] shared memory extension error.\n" ); |
1693 | 954 exit( 0 ); |
955 } | |
956 win->Shminfo.shmid=shmget( IPC_PRIVATE,win->xImage->bytes_per_line * win->xImage->height,IPC_CREAT|0777 ); | |
957 if ( win->Shminfo.shmid < 0 ) | |
958 { | |
959 XDestroyImage( win->xImage ); | |
5919 | 960 mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] shared memory extension error.\n" ); |
1693 | 961 exit( 0 ); |
962 } | |
963 win->Shminfo.shmaddr=(char *)shmat( win->Shminfo.shmid,0,0 ); | |
964 | |
965 if ( win->Shminfo.shmaddr == ((char *) -1) ) | |
966 { | |
967 XDestroyImage( win->xImage ); | |
968 if ( win->Shminfo.shmaddr != ((char *) -1) ) shmdt( win->Shminfo.shmaddr ); | |
5919 | 969 mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] shared memory extension error.\n" ); |
1693 | 970 exit( 0 ); |
971 } | |
972 win->xImage->data=win->Shminfo.shmaddr; | |
973 win->Shminfo.readOnly=0; | |
974 XShmAttach( wsDisplay,&win->Shminfo ); | |
975 shmctl( win->Shminfo.shmid,IPC_RMID,0 ); | |
976 } | |
977 else | |
978 { | |
979 win->xImage=XCreateImage( wsDisplay,win->VisualInfo.visual,win->Attribs.depth, | |
1858
88a88d0a3f94
fix skin changing, xv fullscreen redraw bug, etc.
pontscho
parents:
1853
diff
changeset
|
980 ZPixmap,0,0,Width,Height, |
1693 | 981 (wsDepthOnScreen == 3) ? 32 : wsDepthOnScreen, |
982 0 ); | |
983 if ( ( win->xImage->data=malloc( win->xImage->bytes_per_line * win->xImage->height ) ) == NULL ) | |
984 { | |
5919 | 985 mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] sorry, not enough memory for draw buffer.\n" ); |
1693 | 986 exit( 0 ); |
987 } | |
988 } | |
989 win->ImageData=(unsigned char *)win->xImage->data; | |
990 win->ImageDataw=(unsigned short int *)win->xImage->data; | |
991 win->ImageDatadw=(unsigned int *)win->xImage->data; | |
992 } | |
993 | |
1858
88a88d0a3f94
fix skin changing, xv fullscreen redraw bug, etc.
pontscho
parents:
1853
diff
changeset
|
994 void wsResizeImage( wsTWindow * win,int Width,int Height ) |
88a88d0a3f94
fix skin changing, xv fullscreen redraw bug, etc.
pontscho
parents:
1853
diff
changeset
|
995 { wsDestroyImage( win ); wsCreateImage( win,Width,Height ); } |
1693 | 996 |
997 int wsGetOutMask( void ) | |
998 { | |
999 if ( ( wsDepthOnScreen == 32 )&&( wsRedMask == 0xff0000 )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0x0000ff ) ) return wsRGB32; | |
1000 if ( ( wsDepthOnScreen == 32 )&&( wsRedMask == 0x0000ff )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0xff0000 ) ) return wsBGR32; | |
1001 if ( ( wsDepthOnScreen == 24 )&&( wsRedMask == 0xff0000 )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0x0000ff ) ) return wsRGB24; | |
1002 if ( ( wsDepthOnScreen == 24 )&&( wsRedMask == 0x0000ff )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0xff0000 ) ) return wsBGR24; | |
1003 if ( ( wsDepthOnScreen == 16 )&&( wsRedMask == 0xf800 )&&( wsGreenMask == 0x7e0 )&&( wsBlueMask == 0x1f ) ) return wsRGB16; | |
1004 if ( ( wsDepthOnScreen == 16 )&&( wsRedMask == 0x1f )&&( wsGreenMask == 0x7e0 )&&( wsBlueMask == 0xf800 ) ) return wsBGR16; | |
1005 if ( ( wsDepthOnScreen == 15 )&&( wsRedMask == 0x7c00 )&&( wsGreenMask == 0x3e0 )&&( wsBlueMask == 0x1f ) ) return wsRGB15; | |
1006 if ( ( wsDepthOnScreen == 15 )&&( wsRedMask == 0x1f )&&( wsGreenMask == 0x3e0 )&&( wsBlueMask == 0x7c00 ) ) return wsBGR15; | |
1007 return 0; | |
1008 } | |
1009 | |
1010 void wsSetTitle( wsTWindow * win,char * name ) | |
1011 { XStoreName( wsDisplay,win->WindowID,name ); } | |
1012 | |
1013 void wsSetMousePosition( wsTWindow * win,int x, int y ) | |
1014 { XWarpPointer( wsDisplay,wsRootWin,win->WindowID,0,0,0,0,x,y ); } | |
1015 | |
1016 static int dpms_disabled=0; | |
1017 static int timeout_save=0; | |
1018 | |
1019 void wsScreenSaverOn( Display *mDisplay ) | |
1020 { | |
1021 int nothing; | |
4566 | 1022 #ifdef HAVE_XDPMS |
1693 | 1023 if ( dpms_disabled ) |
1024 { | |
1025 if ( DPMSQueryExtension( mDisplay,¬hing,¬hing ) ) | |
1026 { | |
5919 | 1027 if ( !DPMSEnable( mDisplay ) ) mp_msg( MSGT_GPLAYER,MSGL_ERR,"DPMS not available ?\n" ); // restoring power saving settings |
1693 | 1028 else |
1029 { | |
1030 // DPMS does not seem to be enabled unless we call DPMSInfo | |
1031 BOOL onoff; | |
1032 CARD16 state; | |
1033 DPMSInfo( mDisplay,&state,&onoff ); | |
5919 | 1034 if ( onoff ) mp_msg( MSGT_GPLAYER,MSGL_STATUS,"Successfully enabled DPMS.\n" ); |
1035 else mp_msg( MSGT_GPLAYER,MSGL_STATUS,"Could not enable DPMS.\n" ); | |
1693 | 1036 } |
1037 } | |
1038 } | |
4566 | 1039 #endif |
1693 | 1040 if ( timeout_save ) |
1041 { | |
1042 int dummy, interval, prefer_blank, allow_exp; | |
1043 XGetScreenSaver( mDisplay,&dummy,&interval,&prefer_blank,&allow_exp ); | |
1044 XSetScreenSaver( mDisplay,timeout_save,interval,prefer_blank,allow_exp ); | |
1045 XGetScreenSaver( mDisplay,&timeout_save,&interval,&prefer_blank,&allow_exp ); | |
1046 } | |
1047 } | |
1048 | |
1049 void wsScreenSaverOff( Display * mDisplay ) | |
1050 { | |
1051 int interval,prefer_blank,allow_exp,nothing; | |
4566 | 1052 #ifdef HAVE_XDPMS |
1693 | 1053 if ( DPMSQueryExtension( mDisplay,¬hing,¬hing ) ) |
1054 { | |
1055 BOOL onoff; | |
1056 CARD16 state; | |
1057 DPMSInfo( mDisplay,&state,&onoff ); | |
1058 if ( onoff ) | |
1059 { | |
1060 Status stat; | |
5919 | 1061 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"Disabling DPMS.\n" ); |
1693 | 1062 dpms_disabled=1; |
1063 stat=DPMSDisable( mDisplay ); // monitor powersave off | |
5919 | 1064 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"stat: %d.\n",stat ); |
1693 | 1065 } |
1066 } | |
4566 | 1067 #endif |
1693 | 1068 XGetScreenSaver( mDisplay,&timeout_save,&interval,&prefer_blank,&allow_exp ); |
1069 if ( timeout_save ) XSetScreenSaver( mDisplay,0,interval,prefer_blank,allow_exp ); // turning off screensaver | |
1070 } | |
1071 | |
1072 void wsSetShape( wsTWindow * win,char * data ) | |
1073 { | |
1074 #ifdef HAVE_XSHAPE | |
1852 | 1075 if ( !wsUseXShape ) return; |
1076 if ( data ) | |
1077 { | |
1078 win->Mask=XCreateBitmapFromData( wsDisplay,win->WindowID,data,win->Width,win->Height ); | |
1079 XShapeCombineMask( wsDisplay,win->WindowID,ShapeBounding,0,0,win->Mask,ShapeSet ); | |
1080 XFreePixmap( wsDisplay,win->Mask ); | |
1081 } | |
1082 else XShapeCombineMask( wsDisplay,win->WindowID,ShapeBounding,0,0,None,ShapeSet ); | |
1693 | 1083 #endif |
1084 } | |
1085 | |
1086 #include "wsmkeys.h" |