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