Mercurial > mplayer.hg
annotate Gui/wm/ws.c @ 5986:d34622ebaf45
window resize bug fixed
author | pontscho |
---|---|
date | Sun, 05 May 2002 18:46:42 +0000 |
parents | 60cf2bca993f |
children | b5fb9a927bf3 |
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; | |
5986 | 364 |
1860 | 365 if ( D & wsMinSize ) |
366 { | |
367 win->SizeHint.flags|=PMinSize; | |
368 win->SizeHint.min_width=win->Width; | |
369 win->SizeHint.min_height=win->Height; | |
370 } | |
1693 | 371 if ( D & wsMaxSize ) |
372 { | |
373 win->SizeHint.flags|=PMaxSize; | |
374 win->SizeHint.max_width=win->Width; | |
375 win->SizeHint.max_height=win->Height; | |
376 } | |
5986 | 377 |
1693 | 378 win->SizeHint.height_inc=1; |
379 win->SizeHint.width_inc=1; | |
5919 | 380 win->SizeHint.base_width=win->Width; |
381 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
|
382 win->SizeHint.win_gravity=StaticGravity; |
1693 | 383 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); |
384 | |
385 win->WMHints.flags=InputHint | StateHint; | |
386 win->WMHints.input=True; | |
387 win->WMHints.initial_state=NormalState; | |
388 XSetWMHints( wsDisplay,win->WindowID,&win->WMHints ); | |
389 | |
390 wsWindowDecoration( win,win->Decorations ); | |
391 XStoreName( wsDisplay,win->WindowID,label ); | |
392 XmbSetWMProperties( wsDisplay,win->WindowID,label,label,NULL,0,NULL,NULL,NULL ); | |
393 | |
394 XSetWMProtocols( wsDisplay,win->WindowID,win->AtomsProtocols,3 ); | |
395 XChangeProperty( wsDisplay,win->WindowID, | |
396 win->AtomLeaderClient, | |
397 XA_WINDOW,32,PropModeReplace, | |
398 (unsigned char *)&LeaderWindow,1 ); | |
399 | |
400 wsTextProperty.value=label; | |
401 wsTextProperty.encoding=XA_STRING; | |
402 wsTextProperty.format=8; | |
403 wsTextProperty.nitems=strlen( label ); | |
404 XSetWMIconName( wsDisplay,win->WindowID,&wsTextProperty ); | |
405 | |
406 win->wGC=XCreateGC( wsDisplay,win->WindowID, | |
1814 | 407 GCForeground | GCBackground, |
1693 | 408 &win->wGCV ); |
409 | |
410 win->Visible=0; | |
411 win->Focused=0; | |
412 win->Mapped=0; | |
413 win->Rolled=0; | |
414 if ( D & wsShowWindow ) XMapWindow( wsDisplay,win->WindowID ); | |
415 | |
1858
88a88d0a3f94
fix skin changing, xv fullscreen redraw bug, etc.
pontscho
parents:
1853
diff
changeset
|
416 wsCreateImage( win,win->Width,win->Height ); |
1693 | 417 // --- End of creating -------------------------------------------------------------------------- |
418 | |
419 wsWindowList[wsWLCount++]=win; | |
420 | |
421 XFlush( wsDisplay ); | |
422 XSync( wsDisplay,False ); | |
423 | |
424 win->ReDraw=NULL; | |
425 win->ReSize=NULL; | |
426 win->Idle=NULL; | |
427 win->MouseHandler=NULL; | |
428 win->KeyHandler=NULL; | |
5919 | 429 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[ws] window is created. ( %s ).\n",label ); |
1693 | 430 } |
431 | |
432 void wsDestroyWindow( wsTWindow * win ) | |
433 { | |
434 int l; | |
435 l=wsSearch( win->WindowID ); | |
436 wsWindowList[l]=NULL; | |
437 if ( win->wsCursor != None ) | |
438 { | |
439 XFreeCursor( wsDisplay,win->wsCursor ); | |
440 win->wsCursor=None; | |
441 } | |
442 XUnmapWindow( wsDisplay,win->WindowID ); | |
443 wsDestroyImage( win ); | |
444 XDestroyWindow( wsDisplay,win->WindowID ); | |
445 win->ReDraw=NULL; | |
446 win->ReSize=NULL; | |
447 win->Idle=NULL; | |
448 win->MouseHandler=NULL; | |
449 win->KeyHandler=NULL; | |
450 win->Visible=0; | |
451 win->Focused=0; | |
452 win->Mapped=0; | |
453 win->Rolled=0; | |
454 } | |
455 | |
456 // ---------------------------------------------------------------------------------------------- | |
457 // Handle events. | |
458 // ---------------------------------------------------------------------------------------------- | |
459 | |
460 inline int wsSearch( Window win ) | |
461 { | |
462 int i; | |
463 for ( i=0;i<wsWLCount;i++ ) if ( wsWindowList[i]->WindowID == win ) return i; | |
464 return -1; | |
465 } | |
466 | |
467 Bool wsEvents( Display * display,XEvent * Event,XPointer arg ) | |
468 { | |
469 KeySym keySym; | |
470 unsigned long i = 0; | |
471 int l; | |
472 int x,y; | |
473 Window child_window = 0; | |
474 | |
475 l=wsSearch( Event->xany.window ); | |
476 if ( l == -1 ) return !wsTrue; | |
1782 | 477 wsWindowList[l]->State=0; |
1693 | 478 switch( Event->type ) |
479 { | |
480 case ClientMessage: | |
481 if ( Event->xclient.message_type == wsWindowList[l]->AtomProtocols ) | |
482 { | |
483 if ( Event->xclient.data.l[0] == wsWindowList[l]->AtomDeleteWindow ) | |
5919 | 484 { i=wsWindowClosed; goto expose; } |
1693 | 485 if ( Event->xclient.data.l[0] == wsWindowList[l]->AtomTakeFocus ) |
486 { i=wsWindowFocusIn; wsWindowList[l]->Focused=wsFocused; goto expose; } | |
487 if ( Event->xclient.data.l[0] == wsWindowList[l]->AtomRolle ) | |
5919 | 488 { mp_msg( MSGT_GPLAYER,MSGL_STATUS,"[ws] rolled.\n" ); } |
1693 | 489 } |
490 break; | |
491 | |
492 case MapNotify: i=wsWindowMapped; wsWindowList[l]->Mapped=wsMapped; goto expose; | |
493 case UnmapNotify: i=wsWindowUnmapped; wsWindowList[l]->Mapped=wsNone; goto expose; | |
494 case FocusIn: | |
495 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
|
496 i=wsWindowFocusIn; |
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
497 wsWindowList[l]->Focused=wsFocused; |
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
498 goto expose; |
1693 | 499 case FocusOut: |
500 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
|
501 i=wsWindowFocusOut; |
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
502 wsWindowList[l]->Focused=wsNone; |
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
503 goto expose; |
1693 | 504 case VisibilityNotify: |
505 switch( Event->xvisibility.state ) | |
506 { | |
507 case VisibilityUnobscured: i=wsWindowVisible; wsWindowList[l]->Visible=wsVisible; goto expose; | |
508 case VisibilityFullyObscured: i=wsWindowNotVisible; wsWindowList[l]->Visible=wsNotVisible; goto expose; | |
509 case VisibilityPartiallyObscured: i=wsWindowPartialVisible; wsWindowList[l]->Visible=wsPVisible; goto expose; | |
510 } | |
511 expose: | |
512 wsWindowList[l]->State=i; | |
513 if ( wsWindowList[l]->ReDraw ) wsWindowList[l]->ReDraw( wsDisplay,Event->xany.window ); | |
514 break; | |
515 | |
516 case Expose: | |
517 wsWindowList[l]->State=wsWindowExpose; | |
518 if ( ( wsWindowList[l]->ReDraw )&&( !Event->xexpose.count ) ) wsWindowList[l]->ReDraw( wsDisplay,Event->xany.window ); | |
519 break; | |
520 | |
521 case ConfigureNotify: | |
522 XTranslateCoordinates( wsDisplay,wsWindowList[l]->WindowID,wsRootWin,0,0,&x,&y,&child_window ); | |
523 if ( ( wsWindowList[l]->X != x )||( wsWindowList[l]->Y != y )||( wsWindowList[l]->Width != Event->xconfigure.width )||( wsWindowList[l]->Height != Event->xconfigure.height ) ) | |
524 { | |
525 wsWindowList[l]->X=x; wsWindowList[l]->Y=y; | |
526 wsWindowList[l]->Width=Event->xconfigure.width; wsWindowList[l]->Height=Event->xconfigure.height; | |
527 if ( wsWindowList[l]->ReSize ) wsWindowList[l]->ReSize( wsWindowList[l]->X,wsWindowList[l]->Y,wsWindowList[l]->Width,wsWindowList[l]->Height ); | |
528 } | |
529 | |
530 wsWindowList[l]->Rolled=wsNone; | |
531 if ( Event->xconfigure.y < 0 ) | |
532 { i=wsWindowRolled; wsWindowList[l]->Rolled=wsRolled; goto expose; } | |
533 | |
534 break; | |
535 | |
536 case KeyPress: i=wsKeyPressed; goto keypressed; | |
537 case KeyRelease: i=wsKeyReleased; | |
538 keypressed: | |
539 wsWindowList[l]->Alt=0; | |
540 wsWindowList[l]->Shift=0; | |
541 wsWindowList[l]->NumLock=0; | |
542 wsWindowList[l]->Control=0; | |
543 wsWindowList[l]->CapsLock=0; | |
544 if ( Event->xkey.state & Mod1Mask ) wsWindowList[l]->Alt=1; | |
545 if ( Event->xkey.state & Mod2Mask ) wsWindowList[l]->NumLock=1; | |
546 if ( Event->xkey.state & ControlMask ) wsWindowList[l]->Control=1; | |
547 if ( Event->xkey.state & ShiftMask ) wsWindowList[l]->Shift=1; | |
548 if ( Event->xkey.state & LockMask ) wsWindowList[l]->CapsLock=1; | |
549 keySym=XKeycodeToKeysym( wsDisplay,Event->xkey.keycode,0 ); | |
550 if ( keySym != NoSymbol ) | |
551 { | |
552 keySym=( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ); | |
553 wsKeyTable[ keySym ]=i; | |
554 if ( wsWindowList[l]->KeyHandler ) | |
555 wsWindowList[l]->KeyHandler( Event->xkey.state,i,keySym ); | |
556 } | |
557 break; | |
558 | |
559 case MotionNotify: i=wsMoveMouse; goto buttonreleased; | |
560 case ButtonRelease: i=Event->xbutton.button + 128; goto buttonreleased; | |
561 case ButtonPress: i=Event->xbutton.button; goto buttonreleased; | |
562 case EnterNotify: i=wsEnterWindow; goto buttonreleased; | |
563 case LeaveNotify: i=wsLeaveWindow; | |
564 buttonreleased: | |
565 if ( wsWindowList[l]->MouseHandler ) | |
566 wsWindowList[l]->MouseHandler( i,Event->xbutton.x,Event->xbutton.y,Event->xmotion.x_root,Event->xmotion.y_root ); | |
567 break; | |
568 | |
569 case PropertyNotify: | |
5910
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 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
|
572 |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
573 if ( !name ) break; |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
574 if ( !strncmp( name,"_ICEWM_TRAY",11 ) || |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
575 !strncmp( name,"_KDE_",5 ) || |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
576 !strncmp( name,"KWM_WIN_DESKTOP",15 ) ) wsWMType=0; |
5919 | 577 |
578 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
|
579 |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
580 // 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
|
581 |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
582 XFree( name ); |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
583 break; |
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
584 } |
1693 | 585 break; |
586 | |
587 } | |
588 XFlush( wsDisplay ); | |
589 XSync( wsDisplay,False ); | |
590 return !wsTrue; | |
591 } | |
592 | |
593 Bool wsDummyEvents( Display * display,XEvent * Event,XPointer arg ) | |
594 { return True; } | |
595 | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
4566
diff
changeset
|
596 void wsHandleEvents( void ){ |
1709 | 597 // handle pending events |
598 while ( XPending(wsDisplay) ){ | |
599 XNextEvent( wsDisplay,&wsEvent ); | |
600 // printf("### X event: %d [%d]\n",wsEvent.type,delay); | |
601 wsEvents( wsDisplay,&wsEvent,NULL ); | |
602 } | |
603 } | |
604 | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
4566
diff
changeset
|
605 extern void mplTimerHandler( void ); |
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
4566
diff
changeset
|
606 |
1693 | 607 void wsMainLoop( void ) |
608 { | |
1699 | 609 int delay=20; |
5919 | 610 mp_msg( MSGT_GPLAYER,MSGL_STATUS,"[ws] init threads: %d\n",XInitThreads() ); |
1693 | 611 XSynchronize( wsDisplay,False ); |
612 XLockDisplay( wsDisplay ); | |
613 // XIfEvent( wsDisplay,&wsEvent,wsEvents,NULL ); | |
1699 | 614 |
615 #if 1 | |
616 | |
617 while(wsTrue){ | |
618 // handle pending events | |
619 while ( XPending(wsDisplay) ){ | |
620 XNextEvent( wsDisplay,&wsEvent ); | |
621 wsEvents( wsDisplay,&wsEvent,NULL ); | |
1701 | 622 delay=0; |
1699 | 623 } |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
4566
diff
changeset
|
624 mplTimerHandler(); // handle timer event |
1699 | 625 usleep(delay*1000); // FIXME! |
1701 | 626 if(delay<10*20) delay+=20; // pump up delay up to 0.2 sec (low activity) |
1699 | 627 } |
628 | |
629 #else | |
630 | |
1693 | 631 while( wsTrue ) |
632 { | |
633 XIfEvent( wsDisplay,&wsEvent,wsDummyEvents,NULL ); | |
634 wsEvents( wsDisplay,&wsEvent,NULL ); | |
635 } | |
1699 | 636 #endif |
637 | |
1693 | 638 XUnlockDisplay( wsDisplay ); |
639 } | |
640 | |
641 // ---------------------------------------------------------------------------------------------- | |
642 // Switch to fullscreen. | |
643 // ---------------------------------------------------------------------------------------------- | |
644 void wsFullScreen( wsTWindow * win ) | |
645 { | |
646 int decoration = 0; | |
5910
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
647 if ( wsWMType ) XUnmapWindow( wsDisplay,win->WindowID ); |
1693 | 648 if ( win->isFullScreen ) |
649 { | |
650 win->X=win->OldX; | |
651 win->Y=win->OldY; | |
652 win->Width=win->OldWidth; | |
653 win->Height=win->OldHeight; | |
654 win->isFullScreen=False; | |
655 decoration=win->Decorations; | |
656 wsScreenSaverOn( wsDisplay ); | |
657 } | |
658 else | |
659 { | |
660 win->OldX=win->X; win->OldY=win->Y; | |
661 win->OldWidth=win->Width; win->OldHeight=win->Height; | |
662 win->X=0; win->Y=0; | |
663 win->Width=wsMaxX; win->Height=wsMaxY; | |
664 win->isFullScreen=True; | |
665 wsScreenSaverOff( wsDisplay ); | |
666 } | |
667 | |
5910
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
668 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
|
669 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
|
670 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
|
671 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
|
672 win->SizeHint.win_gravity=StaticGravity; |
1860 | 673 if ( win->Property & wsMaxSize ) |
674 { | |
675 win->SizeHint.flags|=PMaxSize; | |
676 win->SizeHint.max_width=win->Width; | |
677 win->SizeHint.max_height=win->Height; | |
678 } | |
679 if ( win->Property & wsMinSize ) | |
680 { | |
681 win->SizeHint.flags|=PMinSize; | |
682 win->SizeHint.min_width=win->Width; | |
683 win->SizeHint.min_height=win->Height; | |
684 } | |
1693 | 685 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); |
686 | |
687 XMoveResizeWindow( wsDisplay,win->WindowID,win->X,win->Y,win->Width,win->Height ); | |
688 wsWindowDecoration( win,decoration ); | |
5910
20c335d98ab3
fix fullscreen bug es ilyen libvo not initialized bug with gui igy
pontscho
parents:
5031
diff
changeset
|
689 XMapRaised( wsDisplay,win->WindowID ); |
1693 | 690 XRaiseWindow( wsDisplay,win->WindowID ); |
691 } | |
692 | |
693 // ---------------------------------------------------------------------------------------------- | |
694 // Redraw screen. | |
695 // ---------------------------------------------------------------------------------------------- | |
696 void wsPostRedisplay( wsTWindow * win ) | |
697 { | |
698 if ( win->ReDraw ) | |
699 { | |
700 win->ReDraw( wsDisplay,win->WindowID ); | |
701 XFlush( wsDisplay ); | |
702 } | |
703 } | |
704 | |
705 // ---------------------------------------------------------------------------------------------- | |
706 // Do Exit. | |
707 // ---------------------------------------------------------------------------------------------- | |
708 void wsDoExit( void ) | |
709 { wsTrue=False; wsResizeWindow( wsWindowList[0],32,32 ); } | |
710 | |
711 // ---------------------------------------------------------------------------------------------- | |
712 // Put 'Image' to window. | |
713 // ---------------------------------------------------------------------------------------------- | |
714 void wsConvert( wsTWindow * win,unsigned char * Image,unsigned int Size ) | |
2733 | 715 { if ( wsConvFunc ) wsConvFunc( Image,win->ImageData,win->xImage->width * win->xImage->height * 4 ); } |
1693 | 716 |
717 void wsPutImage( wsTWindow * win ) | |
718 { | |
719 if ( wsUseXShm ) | |
720 { | |
721 XShmPutImage( wsDisplay,win->WindowID,win->wGC,win->xImage, | |
722 0,0, | |
723 ( win->Width - win->xImage->width ) / 2,( win->Height - win->xImage->height ) / 2, | |
724 win->xImage->width,win->xImage->height,0 ); | |
725 } | |
726 else | |
727 { | |
728 XPutImage( wsDisplay,win->WindowID,win->wGC,win->xImage, | |
729 0,0, | |
730 ( win->Width - win->xImage->width ) / 2,( win->Height - win->xImage->height ) / 2, | |
731 win->xImage->width,win->xImage->height ); | |
732 } | |
733 } | |
734 | |
735 // ---------------------------------------------------------------------------------------------- | |
736 // Move window to x, y. | |
737 // ---------------------------------------------------------------------------------------------- | |
2854 | 738 void wsMoveWindow( wsTWindow * win,int b,int x, int y ) |
1693 | 739 { |
2854 | 740 if ( b ) |
1693 | 741 { |
2854 | 742 switch ( x ) |
743 { | |
744 case -1: win->X=( wsMaxX / 2 ) - ( win->Width / 2 ); break; | |
745 case -2: win->X=wsMaxX - win->Width; break; | |
746 default: win->X=x; break; | |
747 } | |
748 switch ( y ) | |
749 { | |
750 case -1: win->Y=( wsMaxY / 2 ) - ( win->Height / 2 ); break; | |
751 case -2: win->Y=wsMaxY - win->Height; break; | |
752 default: win->Y=y; break; | |
753 } | |
1693 | 754 } |
2854 | 755 else { win->X=x; win->Y=y; } |
1693 | 756 |
2851
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
757 win->SizeHint.flags=PPosition | PWinGravity; |
1693 | 758 win->SizeHint.x=win->X; |
759 win->SizeHint.y=win->Y; | |
2851
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
760 win->SizeHint.win_gravity=StaticGravity; |
1693 | 761 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); |
762 | |
763 XMoveWindow( wsDisplay,win->WindowID,win->X,win->Y ); | |
1810 | 764 if ( win->ReSize ) win->ReSize( win->X,win->Y,win->Width,win->Height ); |
1693 | 765 } |
766 | |
767 // ---------------------------------------------------------------------------------------------- | |
768 // Resize window to sx, sy. | |
769 // ---------------------------------------------------------------------------------------------- | |
770 void wsResizeWindow( wsTWindow * win,int sx, int sy ) | |
771 { | |
772 win->Width=sx; | |
773 win->Height=sy; | |
774 | |
5986 | 775 win->SizeHint.flags=PPosition | PSize | PWinGravity | PBaseSize; |
776 win->SizeHint.x=win->X; | |
777 win->SizeHint.y=win->Y; | |
1693 | 778 win->SizeHint.width=win->Width; |
779 win->SizeHint.height=win->Height; | |
5986 | 780 /* |
1693 | 781 if ( win->Property & wsMinSize ) |
782 { | |
783 win->SizeHint.flags|=PMinSize; | |
784 win->SizeHint.min_width=win->Width; | |
785 win->SizeHint.min_height=win->Height; | |
786 } | |
787 if ( win->Property & wsMaxSize ) | |
788 { | |
789 win->SizeHint.flags|=PMaxSize; | |
790 win->SizeHint.max_width=win->Width; | |
791 win->SizeHint.max_height=win->Height; | |
792 } | |
5986 | 793 */ |
2851
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
794 win->SizeHint.win_gravity=StaticGravity; |
5986 | 795 win->SizeHint.base_width=sx; win->SizeHint.base_height=sy; |
796 if ( !wsIsKDE ) XUnmapWindow( wsDisplay,win->WindowID ); | |
1693 | 797 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); |
798 XResizeWindow( wsDisplay,win->WindowID,sx,sy ); | |
5986 | 799 XMapRaised( wsDisplay,win->WindowID ); |
1810 | 800 if ( win->ReSize ) win->ReSize( win->X,win->Y,win->Width,win->Height ); |
1693 | 801 } |
802 | |
803 // ---------------------------------------------------------------------------------------------- | |
804 // Iconify window. | |
805 // ---------------------------------------------------------------------------------------------- | |
806 void wsIconify( wsTWindow win ) | |
807 { XIconifyWindow( wsDisplay,win.WindowID,0 ); } | |
808 | |
809 // ---------------------------------------------------------------------------------------------- | |
810 // Move top the window. | |
811 // ---------------------------------------------------------------------------------------------- | |
812 void wsMoveTopWindow( wsTWindow * win ) | |
2851
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
813 { |
5919 | 814 if ( wsIsKDE ) return; |
815 XMapRaised( wsDisplay,win->WindowID ); | |
2851
b64fa5d25142
add roleld mouse support and some small bugfix. neked jol a testedbe.
pontscho
parents:
2782
diff
changeset
|
816 XRaiseWindow( wsDisplay,win->WindowID ); |
2045 | 817 } |
1693 | 818 |
819 // ---------------------------------------------------------------------------------------------- | |
820 // Set window background to 'color'. | |
821 // ---------------------------------------------------------------------------------------------- | |
822 void wsSetBackground( wsTWindow * win,int color ) | |
823 { XSetWindowBackground( wsDisplay,win->WindowID,color ); } | |
824 | |
825 void wsSetBackgroundRGB( wsTWindow * win,int r,int g,int b ) | |
826 { | |
827 int color = 0; | |
828 switch ( wsOutMask ) | |
829 { | |
830 case wsRGB32: | |
831 case wsRGB24: color=( r << 16 ) + ( g << 8 ) + b; break; | |
832 case wsBGR32: | |
833 case wsBGR24: color=( b << 16 ) + ( g << 8 ) + r; break; | |
2733 | 834 case wsRGB16: PACK_RGB16( b,g,r,color ); break; |
835 case wsBGR16: PACK_RGB16( r,g,b,color ); break; | |
836 case wsRGB15: PACK_RGB15( b,g,r,color ); break; | |
837 case wsBGR15: PACK_RGB15( r,g,b,color ); break; | |
1693 | 838 } |
839 XSetWindowBackground( wsDisplay,win->WindowID,color ); | |
840 } | |
841 | |
1814 | 842 void wsSetForegroundRGB( wsTWindow * win,int r,int g,int b ) |
843 { | |
844 int color = 0; | |
845 switch ( wsOutMask ) | |
846 { | |
847 case wsRGB32: | |
848 case wsRGB24: color=( r << 16 ) + ( g << 8 ) + b; break; | |
849 case wsBGR32: | |
850 case wsBGR24: color=( b << 16 ) + ( g << 8 ) + r; break; | |
2733 | 851 case wsRGB16: PACK_RGB16( b,g,r,color ); break; |
852 case wsBGR16: PACK_RGB16( r,g,b,color ); break; | |
853 case wsRGB15: PACK_RGB15( b,g,r,color ); break; | |
854 case wsBGR15: PACK_RGB15( r,g,b,color ); break; | |
1814 | 855 } |
856 XSetForeground( wsDisplay,win->wGC,color ); | |
857 } | |
1693 | 858 |
859 // ---------------------------------------------------------------------------------------------- | |
860 // Draw string at x,y with fc ( foreground color ) and bc ( background color ). | |
861 // ---------------------------------------------------------------------------------------------- | |
862 void wsDrawString( wsTWindow win,int x,int y,char * str,int fc,int bc ) | |
863 { | |
864 XSetForeground( wsDisplay,win.wGC,bc ); | |
865 XFillRectangle( wsDisplay,win.WindowID,win.wGC,x,y, | |
866 XTextWidth( win.Font,str,strlen( str ) ) + 20, | |
867 win.FontHeight + 2 ); | |
868 XSetForeground( wsDisplay,win.wGC,fc ); | |
869 XDrawString( wsDisplay,win.WindowID,win.wGC,x + 10,y + 13,str,strlen( str ) ); | |
870 } | |
871 | |
872 // ---------------------------------------------------------------------------------------------- | |
873 // Calculation string width. | |
874 // ---------------------------------------------------------------------------------------------- | |
875 int wsTextWidth( wsTWindow win,char * str ) | |
876 { return XTextWidth( win.Font,str,strlen( str ) ) + 20; } | |
877 | |
878 // ---------------------------------------------------------------------------------------------- | |
879 // Show / hide mouse cursor. | |
880 // ---------------------------------------------------------------------------------------------- | |
881 void wsVisibleMouse( wsTWindow * win,int m ) | |
882 { | |
883 switch ( m ) | |
884 { | |
885 case wsShowMouseCursor: | |
886 if ( win->wsCursor != None ) | |
887 { | |
888 XFreeCursor( wsDisplay,win->wsCursor ); | |
889 win->wsCursor=None; | |
890 } | |
891 XDefineCursor( wsDisplay,win->WindowID,0 ); | |
892 break; | |
893 case wsHideMouseCursor: | |
894 win->wsCursor=XCreatePixmapCursor( wsDisplay,win->wsCursorPixmap,win->wsCursorPixmap,&win->wsColor,&win->wsColor,0,0 ); | |
895 XDefineCursor( wsDisplay,win->WindowID,win->wsCursor ); | |
896 break; | |
897 } | |
898 XFlush( wsDisplay ); | |
899 } | |
900 | |
901 int wsGetDepthOnScreen( void ) | |
902 { | |
903 int bpp,ibpp; | |
904 XImage * mXImage; | |
905 XWindowAttributes attribs; | |
906 | |
907 mXImage=XGetImage( wsDisplay,wsRootWin,0,0,1,1,AllPlanes,ZPixmap ); | |
908 bpp=mXImage->bits_per_pixel; | |
909 | |
910 XGetWindowAttributes( wsDisplay,wsRootWin,&attribs ); | |
911 ibpp=attribs.depth; | |
912 mXImage=XGetImage( wsDisplay,wsRootWin,0,0,1,1,AllPlanes,ZPixmap ); | |
913 bpp=mXImage->bits_per_pixel; | |
914 if ( ( ibpp + 7 ) / 8 != ( bpp + 7 ) / 8 ) ibpp=bpp; | |
915 wsDepthOnScreen=ibpp; | |
916 wsRedMask=mXImage->red_mask; | |
917 wsGreenMask=mXImage->green_mask; | |
918 wsBlueMask=mXImage->blue_mask; | |
919 XDestroyImage( mXImage ); | |
920 return ibpp; | |
921 } | |
922 | |
923 void wsXDone( void ) | |
924 { | |
925 XCloseDisplay( wsDisplay ); | |
926 } | |
927 | |
928 void wsVisibleWindow( wsTWindow * win,int show ) | |
929 { | |
930 switch( show ) | |
931 { | |
932 case wsShowWindow: XMapWindow( wsDisplay,win->WindowID ); break; | |
933 case wsHideWindow: XUnmapWindow( wsDisplay,win->WindowID ); break; | |
934 } | |
935 XFlush( wsDisplay ); | |
936 } | |
937 | |
938 void wsDestroyImage( wsTWindow * win ) | |
939 { | |
940 if ( win->xImage ) | |
941 { | |
942 XDestroyImage( win->xImage ); | |
943 if ( wsUseXShm ) | |
944 { | |
945 XShmDetach( wsDisplay,&win->Shminfo ); | |
946 shmdt( win->Shminfo.shmaddr ); | |
947 } | |
948 } | |
949 win->xImage=NULL; | |
950 } | |
951 | |
1858
88a88d0a3f94
fix skin changing, xv fullscreen redraw bug, etc.
pontscho
parents:
1853
diff
changeset
|
952 void wsCreateImage( wsTWindow * win,int Width,int Height ) |
1693 | 953 { |
954 int CompletionType = -1; | |
955 if ( wsUseXShm ) | |
956 { | |
957 CompletionType=XShmGetEventBase( wsDisplay ) + ShmCompletion; | |
958 win->xImage=XShmCreateImage( wsDisplay,win->VisualInfo.visual, | |
1858
88a88d0a3f94
fix skin changing, xv fullscreen redraw bug, etc.
pontscho
parents:
1853
diff
changeset
|
959 win->Attribs.depth,ZPixmap,NULL,&win->Shminfo,Width,Height ); |
1693 | 960 if ( win->xImage == NULL ) |
961 { | |
5919 | 962 mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] shared memory extension error.\n" ); |
1693 | 963 exit( 0 ); |
964 } | |
965 win->Shminfo.shmid=shmget( IPC_PRIVATE,win->xImage->bytes_per_line * win->xImage->height,IPC_CREAT|0777 ); | |
966 if ( win->Shminfo.shmid < 0 ) | |
967 { | |
968 XDestroyImage( win->xImage ); | |
5919 | 969 mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] shared memory extension error.\n" ); |
1693 | 970 exit( 0 ); |
971 } | |
972 win->Shminfo.shmaddr=(char *)shmat( win->Shminfo.shmid,0,0 ); | |
973 | |
974 if ( win->Shminfo.shmaddr == ((char *) -1) ) | |
975 { | |
976 XDestroyImage( win->xImage ); | |
977 if ( win->Shminfo.shmaddr != ((char *) -1) ) shmdt( win->Shminfo.shmaddr ); | |
5919 | 978 mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] shared memory extension error.\n" ); |
1693 | 979 exit( 0 ); |
980 } | |
981 win->xImage->data=win->Shminfo.shmaddr; | |
982 win->Shminfo.readOnly=0; | |
983 XShmAttach( wsDisplay,&win->Shminfo ); | |
984 shmctl( win->Shminfo.shmid,IPC_RMID,0 ); | |
985 } | |
986 else | |
987 { | |
988 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
|
989 ZPixmap,0,0,Width,Height, |
1693 | 990 (wsDepthOnScreen == 3) ? 32 : wsDepthOnScreen, |
991 0 ); | |
992 if ( ( win->xImage->data=malloc( win->xImage->bytes_per_line * win->xImage->height ) ) == NULL ) | |
993 { | |
5919 | 994 mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] sorry, not enough memory for draw buffer.\n" ); |
1693 | 995 exit( 0 ); |
996 } | |
997 } | |
998 win->ImageData=(unsigned char *)win->xImage->data; | |
999 win->ImageDataw=(unsigned short int *)win->xImage->data; | |
1000 win->ImageDatadw=(unsigned int *)win->xImage->data; | |
1001 } | |
1002 | |
1858
88a88d0a3f94
fix skin changing, xv fullscreen redraw bug, etc.
pontscho
parents:
1853
diff
changeset
|
1003 void wsResizeImage( wsTWindow * win,int Width,int Height ) |
88a88d0a3f94
fix skin changing, xv fullscreen redraw bug, etc.
pontscho
parents:
1853
diff
changeset
|
1004 { wsDestroyImage( win ); wsCreateImage( win,Width,Height ); } |
1693 | 1005 |
1006 int wsGetOutMask( void ) | |
1007 { | |
1008 if ( ( wsDepthOnScreen == 32 )&&( wsRedMask == 0xff0000 )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0x0000ff ) ) return wsRGB32; | |
1009 if ( ( wsDepthOnScreen == 32 )&&( wsRedMask == 0x0000ff )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0xff0000 ) ) return wsBGR32; | |
1010 if ( ( wsDepthOnScreen == 24 )&&( wsRedMask == 0xff0000 )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0x0000ff ) ) return wsRGB24; | |
1011 if ( ( wsDepthOnScreen == 24 )&&( wsRedMask == 0x0000ff )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0xff0000 ) ) return wsBGR24; | |
1012 if ( ( wsDepthOnScreen == 16 )&&( wsRedMask == 0xf800 )&&( wsGreenMask == 0x7e0 )&&( wsBlueMask == 0x1f ) ) return wsRGB16; | |
1013 if ( ( wsDepthOnScreen == 16 )&&( wsRedMask == 0x1f )&&( wsGreenMask == 0x7e0 )&&( wsBlueMask == 0xf800 ) ) return wsBGR16; | |
1014 if ( ( wsDepthOnScreen == 15 )&&( wsRedMask == 0x7c00 )&&( wsGreenMask == 0x3e0 )&&( wsBlueMask == 0x1f ) ) return wsRGB15; | |
1015 if ( ( wsDepthOnScreen == 15 )&&( wsRedMask == 0x1f )&&( wsGreenMask == 0x3e0 )&&( wsBlueMask == 0x7c00 ) ) return wsBGR15; | |
1016 return 0; | |
1017 } | |
1018 | |
1019 void wsSetTitle( wsTWindow * win,char * name ) | |
1020 { XStoreName( wsDisplay,win->WindowID,name ); } | |
1021 | |
1022 void wsSetMousePosition( wsTWindow * win,int x, int y ) | |
1023 { XWarpPointer( wsDisplay,wsRootWin,win->WindowID,0,0,0,0,x,y ); } | |
1024 | |
1025 static int dpms_disabled=0; | |
1026 static int timeout_save=0; | |
1027 | |
1028 void wsScreenSaverOn( Display *mDisplay ) | |
1029 { | |
1030 int nothing; | |
4566 | 1031 #ifdef HAVE_XDPMS |
1693 | 1032 if ( dpms_disabled ) |
1033 { | |
1034 if ( DPMSQueryExtension( mDisplay,¬hing,¬hing ) ) | |
1035 { | |
5919 | 1036 if ( !DPMSEnable( mDisplay ) ) mp_msg( MSGT_GPLAYER,MSGL_ERR,"DPMS not available ?\n" ); // restoring power saving settings |
1693 | 1037 else |
1038 { | |
1039 // DPMS does not seem to be enabled unless we call DPMSInfo | |
1040 BOOL onoff; | |
1041 CARD16 state; | |
1042 DPMSInfo( mDisplay,&state,&onoff ); | |
5919 | 1043 if ( onoff ) mp_msg( MSGT_GPLAYER,MSGL_STATUS,"Successfully enabled DPMS.\n" ); |
1044 else mp_msg( MSGT_GPLAYER,MSGL_STATUS,"Could not enable DPMS.\n" ); | |
1693 | 1045 } |
1046 } | |
1047 } | |
4566 | 1048 #endif |
1693 | 1049 if ( timeout_save ) |
1050 { | |
1051 int dummy, interval, prefer_blank, allow_exp; | |
1052 XGetScreenSaver( mDisplay,&dummy,&interval,&prefer_blank,&allow_exp ); | |
1053 XSetScreenSaver( mDisplay,timeout_save,interval,prefer_blank,allow_exp ); | |
1054 XGetScreenSaver( mDisplay,&timeout_save,&interval,&prefer_blank,&allow_exp ); | |
1055 } | |
1056 } | |
1057 | |
1058 void wsScreenSaverOff( Display * mDisplay ) | |
1059 { | |
1060 int interval,prefer_blank,allow_exp,nothing; | |
4566 | 1061 #ifdef HAVE_XDPMS |
1693 | 1062 if ( DPMSQueryExtension( mDisplay,¬hing,¬hing ) ) |
1063 { | |
1064 BOOL onoff; | |
1065 CARD16 state; | |
1066 DPMSInfo( mDisplay,&state,&onoff ); | |
1067 if ( onoff ) | |
1068 { | |
1069 Status stat; | |
5919 | 1070 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"Disabling DPMS.\n" ); |
1693 | 1071 dpms_disabled=1; |
1072 stat=DPMSDisable( mDisplay ); // monitor powersave off | |
5919 | 1073 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"stat: %d.\n",stat ); |
1693 | 1074 } |
1075 } | |
4566 | 1076 #endif |
1693 | 1077 XGetScreenSaver( mDisplay,&timeout_save,&interval,&prefer_blank,&allow_exp ); |
1078 if ( timeout_save ) XSetScreenSaver( mDisplay,0,interval,prefer_blank,allow_exp ); // turning off screensaver | |
1079 } | |
1080 | |
1081 void wsSetShape( wsTWindow * win,char * data ) | |
1082 { | |
1083 #ifdef HAVE_XSHAPE | |
1852 | 1084 if ( !wsUseXShape ) return; |
1085 if ( data ) | |
1086 { | |
1087 win->Mask=XCreateBitmapFromData( wsDisplay,win->WindowID,data,win->Width,win->Height ); | |
1088 XShapeCombineMask( wsDisplay,win->WindowID,ShapeBounding,0,0,win->Mask,ShapeSet ); | |
1089 XFreePixmap( wsDisplay,win->Mask ); | |
1090 } | |
1091 else XShapeCombineMask( wsDisplay,win->WindowID,ShapeBounding,0,0,None,ShapeSet ); | |
1693 | 1092 #endif |
1093 } | |
1094 | |
1095 #include "wsmkeys.h" |