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