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