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