Mercurial > mplayer.hg
annotate Gui/wm/ws.c @ 1782:dce42eebfda4
win->state fix
author | pontscho |
---|---|
date | Thu, 30 Aug 2001 19:44:39 +0000 |
parents | 5e905bf5d715 |
children | d44b0ce32791 |
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, | |
437 // GCForeground | GCBackground, | |
438 0, | |
439 &win->wGCV ); | |
440 | |
441 win->Visible=0; | |
442 win->Focused=0; | |
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; | |
485 win->Mapped=0; | |
486 win->Rolled=0; | |
487 } | |
488 | |
489 // ---------------------------------------------------------------------------------------------- | |
490 // Handle events. | |
491 // ---------------------------------------------------------------------------------------------- | |
492 | |
493 inline int wsSearch( Window win ) | |
494 { | |
495 int i; | |
496 for ( i=0;i<wsWLCount;i++ ) if ( wsWindowList[i]->WindowID == win ) return i; | |
497 return -1; | |
498 } | |
499 | |
500 Bool wsEvents( Display * display,XEvent * Event,XPointer arg ) | |
501 { | |
502 KeySym keySym; | |
503 unsigned long i = 0; | |
504 int l; | |
505 int x,y; | |
506 Window child_window = 0; | |
507 | |
508 l=wsSearch( Event->xany.window ); | |
509 if ( l == -1 ) return !wsTrue; | |
1782 | 510 wsWindowList[l]->State=0; |
1693 | 511 switch( Event->type ) |
512 { | |
513 case ClientMessage: | |
514 if ( Event->xclient.message_type == wsWindowList[l]->AtomProtocols ) | |
515 { | |
516 if ( Event->xclient.data.l[0] == wsWindowList[l]->AtomDeleteWindow ) | |
517 { wsTrue=False; break; } | |
518 if ( Event->xclient.data.l[0] == wsWindowList[l]->AtomTakeFocus ) | |
519 { i=wsWindowFocusIn; wsWindowList[l]->Focused=wsFocused; goto expose; } | |
520 if ( Event->xclient.data.l[0] == wsWindowList[l]->AtomRolle ) | |
521 { fprintf( stderr,"[ws] rolled.\n" ); } | |
522 } | |
523 break; | |
524 | |
525 // case CirculateRequest:fprintf( stderr,"[ws,r] win: 0x%x\n",(int)Event->xcirculaterequest.window ); break; | |
526 // case CirculateNotify: fprintf( stderr,"[ws,c] win: 0x%x\n",(int)Event->xcirculate.window ); break; | |
527 | |
528 case MapNotify: i=wsWindowMapped; wsWindowList[l]->Mapped=wsMapped; goto expose; | |
529 case UnmapNotify: i=wsWindowUnmapped; wsWindowList[l]->Mapped=wsNone; goto expose; | |
530 case FocusIn: | |
531 if ( wsWindowList[l]->Focused == wsFocused ) break; | |
532 i=wsWindowFocusIn; wsWindowList[l]->Focused=wsFocused; goto expose; | |
533 case FocusOut: | |
534 if ( wsWindowList[l]->Focused == wsNone ) break; | |
535 i=wsWindowFocusOut; wsWindowList[l]->Focused=wsNone; goto expose; | |
536 case VisibilityNotify: | |
537 switch( Event->xvisibility.state ) | |
538 { | |
539 case VisibilityUnobscured: i=wsWindowVisible; wsWindowList[l]->Visible=wsVisible; goto expose; | |
540 case VisibilityFullyObscured: i=wsWindowNotVisible; wsWindowList[l]->Visible=wsNotVisible; goto expose; | |
541 case VisibilityPartiallyObscured: i=wsWindowPartialVisible; wsWindowList[l]->Visible=wsPVisible; goto expose; | |
542 } | |
543 expose: | |
544 wsWindowList[l]->State=i; | |
545 if ( wsWindowList[l]->ReDraw ) wsWindowList[l]->ReDraw( wsDisplay,Event->xany.window ); | |
546 break; | |
547 | |
548 case Expose: | |
549 wsWindowList[l]->State=wsWindowExpose; | |
550 if ( ( wsWindowList[l]->ReDraw )&&( !Event->xexpose.count ) ) wsWindowList[l]->ReDraw( wsDisplay,Event->xany.window ); | |
551 break; | |
552 | |
553 case ConfigureNotify: | |
554 XTranslateCoordinates( wsDisplay,wsWindowList[l]->WindowID,wsRootWin,0,0,&x,&y,&child_window ); | |
555 if ( ( wsWindowList[l]->X != x )||( wsWindowList[l]->Y != y )||( wsWindowList[l]->Width != Event->xconfigure.width )||( wsWindowList[l]->Height != Event->xconfigure.height ) ) | |
556 { | |
557 wsWindowList[l]->X=x; wsWindowList[l]->Y=y; | |
558 wsWindowList[l]->Width=Event->xconfigure.width; wsWindowList[l]->Height=Event->xconfigure.height; | |
559 // fprintf( stderr,"[ws] resize: %d,%d %dx%d\n",wsWindowList[l]->X,wsWindowList[l]->Y,Event->xconfigure.width,Event->xconfigure.height ); | |
560 if ( wsWindowList[l]->ReSize ) wsWindowList[l]->ReSize( wsWindowList[l]->X,wsWindowList[l]->Y,wsWindowList[l]->Width,wsWindowList[l]->Height ); | |
561 } | |
562 | |
563 wsWindowList[l]->Rolled=wsNone; | |
564 if ( Event->xconfigure.y < 0 ) | |
565 { i=wsWindowRolled; wsWindowList[l]->Rolled=wsRolled; goto expose; } | |
566 | |
567 break; | |
568 | |
569 case KeyPress: i=wsKeyPressed; goto keypressed; | |
570 case KeyRelease: i=wsKeyReleased; | |
571 keypressed: | |
572 wsWindowList[l]->Alt=0; | |
573 wsWindowList[l]->Shift=0; | |
574 wsWindowList[l]->NumLock=0; | |
575 wsWindowList[l]->Control=0; | |
576 wsWindowList[l]->CapsLock=0; | |
577 if ( Event->xkey.state & Mod1Mask ) wsWindowList[l]->Alt=1; | |
578 if ( Event->xkey.state & Mod2Mask ) wsWindowList[l]->NumLock=1; | |
579 if ( Event->xkey.state & ControlMask ) wsWindowList[l]->Control=1; | |
580 if ( Event->xkey.state & ShiftMask ) wsWindowList[l]->Shift=1; | |
581 if ( Event->xkey.state & LockMask ) wsWindowList[l]->CapsLock=1; | |
582 keySym=XKeycodeToKeysym( wsDisplay,Event->xkey.keycode,0 ); | |
583 if ( keySym != NoSymbol ) | |
584 { | |
585 keySym=( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ); | |
586 wsKeyTable[ keySym ]=i; | |
587 if ( wsWindowList[l]->KeyHandler ) | |
588 wsWindowList[l]->KeyHandler( Event->xkey.state,i,keySym ); | |
589 } | |
590 break; | |
591 | |
592 case MotionNotify: i=wsMoveMouse; goto buttonreleased; | |
593 case ButtonRelease: i=Event->xbutton.button + 128; goto buttonreleased; | |
594 case ButtonPress: i=Event->xbutton.button; goto buttonreleased; | |
595 case EnterNotify: i=wsEnterWindow; goto buttonreleased; | |
596 case LeaveNotify: i=wsLeaveWindow; | |
597 buttonreleased: | |
598 if ( wsWindowList[l]->MouseHandler ) | |
599 wsWindowList[l]->MouseHandler( i,Event->xbutton.x,Event->xbutton.y,Event->xmotion.x_root,Event->xmotion.y_root ); | |
600 break; | |
601 | |
602 case PropertyNotify: | |
1779 | 603 break; |
1693 | 604 // fprintf(stderr,"[ws] PropertyNotify %s\n",XGetAtomName( wsDisplay,Event->xproperty.atom ) ); |
605 if ( Event->xproperty.atom == wsWindowList[l]->AtomRemote ) | |
606 { | |
607 Atom type; | |
608 int format; | |
609 unsigned long nitems, bytesafter; | |
610 unsigned char * args = NULL; | |
611 | |
612 // fprintf( stderr,"[ws] remote property notify.\n" ); | |
613 XGetWindowProperty( wsDisplay, | |
614 Event->xproperty.window, | |
615 Event->xproperty.atom, | |
616 0,( 65536 / sizeof( long ) ), | |
617 False,XA_STRING, | |
618 &type,&format,&nitems,&bytesafter, | |
619 &args ); | |
620 if ( ( nitems )&&( wsWindowList[l]->RemoteHandler ) ) | |
621 { | |
622 args[strlen( args ) - 1]=0; | |
623 wsWindowList[l]->RemoteHandler( args ); | |
624 args[strlen( args ) - 1]=1; | |
625 XFree( args ); | |
626 } | |
627 } | |
628 break; | |
629 | |
630 } | |
631 XFlush( wsDisplay ); | |
632 XSync( wsDisplay,False ); | |
633 return !wsTrue; | |
634 // return True; | |
635 } | |
636 | |
637 Bool wsDummyEvents( Display * display,XEvent * Event,XPointer arg ) | |
638 { return True; } | |
639 | |
1709 | 640 // mplTimerHandler(0); // handle timer event |
641 void wsHandleEvents(){ | |
642 // handle pending events | |
643 while ( XPending(wsDisplay) ){ | |
644 XNextEvent( wsDisplay,&wsEvent ); | |
645 // printf("### X event: %d [%d]\n",wsEvent.type,delay); | |
646 wsEvents( wsDisplay,&wsEvent,NULL ); | |
647 } | |
648 } | |
649 | |
1693 | 650 void wsMainLoop( void ) |
651 { | |
1699 | 652 int delay=20; |
1693 | 653 fprintf( stderr,"[ws] init threads: %d\n",XInitThreads() ); |
654 XSynchronize( wsDisplay,False ); | |
655 XLockDisplay( wsDisplay ); | |
656 // XIfEvent( wsDisplay,&wsEvent,wsEvents,NULL ); | |
1699 | 657 |
658 #if 1 | |
659 | |
660 while(wsTrue){ | |
661 // handle pending events | |
662 while ( XPending(wsDisplay) ){ | |
663 XNextEvent( wsDisplay,&wsEvent ); | |
1701 | 664 // printf("### X event: %d [%d]\n",wsEvent.type,delay); |
1699 | 665 wsEvents( wsDisplay,&wsEvent,NULL ); |
1701 | 666 delay=0; |
1699 | 667 } |
668 mplTimerHandler(0); // handle timer event | |
669 usleep(delay*1000); // FIXME! | |
1701 | 670 if(delay<10*20) delay+=20; // pump up delay up to 0.2 sec (low activity) |
1699 | 671 } |
672 | |
673 #else | |
674 | |
1693 | 675 while( wsTrue ) |
676 { | |
677 XIfEvent( wsDisplay,&wsEvent,wsDummyEvents,NULL ); | |
678 wsEvents( wsDisplay,&wsEvent,NULL ); | |
679 } | |
1699 | 680 #endif |
681 | |
1693 | 682 XUnlockDisplay( wsDisplay ); |
683 } | |
684 | |
685 // ---------------------------------------------------------------------------------------------- | |
686 // Switch to fullscreen. | |
687 // ---------------------------------------------------------------------------------------------- | |
688 void wsFullScreen( wsTWindow * win ) | |
689 { | |
690 int decoration = 0; | |
691 XUnmapWindow( wsDisplay,win->WindowID ); | |
692 win->SizeHint.flags=0; | |
693 if ( win->isFullScreen ) | |
694 { | |
695 win->X=win->OldX; | |
696 win->Y=win->OldY; | |
697 win->Width=win->OldWidth; | |
698 win->Height=win->OldHeight; | |
699 win->isFullScreen=False; | |
700 if ( win->Property & wsMaxSize ) | |
701 { | |
702 win->SizeHint.flags|=PMaxSize; | |
703 win->SizeHint.max_width=win->Width; | |
704 win->SizeHint.max_height=win->Height; | |
705 } | |
706 if ( win->Property & wsMinSize ) | |
707 { | |
708 win->SizeHint.flags|=PMinSize; | |
709 win->SizeHint.min_width=win->Width; | |
710 win->SizeHint.min_height=win->Height; | |
711 } | |
712 decoration=win->Decorations; | |
713 wsScreenSaverOn( wsDisplay ); | |
714 } | |
715 else | |
716 { | |
717 win->OldX=win->X; win->OldY=win->Y; | |
718 win->OldWidth=win->Width; win->OldHeight=win->Height; | |
719 win->X=0; win->Y=0; | |
720 win->Width=wsMaxX; win->Height=wsMaxY; | |
721 win->isFullScreen=True; | |
722 // if ( win->Property & wsMaxSize ) | |
723 // { | |
724 // win->SizeHint.flags|=PMaxSize; | |
725 // win->SizeHint.min_width=0; | |
726 // win->SizeHint.min_height=0; | |
727 // } | |
728 // if ( win->Property & wsMinSize ) | |
729 // { | |
730 // win->SizeHint.flags|=PMinSize; | |
731 // win->SizeHint.max_width=4096; | |
732 // win->SizeHint.max_height=4096; | |
733 // } | |
734 wsScreenSaverOff( wsDisplay ); | |
735 } | |
736 | |
737 win->SizeHint.flags|=PPosition | PSize; | |
738 win->SizeHint.x=win->X; | |
739 win->SizeHint.y=win->Y; | |
740 win->SizeHint.width=win->Width; | |
741 win->SizeHint.height=win->Height; | |
742 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); | |
743 | |
744 XMoveResizeWindow( wsDisplay,win->WindowID,win->X,win->Y,win->Width,win->Height ); | |
745 wsWindowDecoration( win,decoration ); | |
746 XRaiseWindow( wsDisplay,win->WindowID ); | |
747 XMapWindow( wsDisplay,win->WindowID ); | |
748 } | |
749 | |
750 // ---------------------------------------------------------------------------------------------- | |
751 // Redraw screen. | |
752 // ---------------------------------------------------------------------------------------------- | |
753 void wsPostRedisplay( wsTWindow * win ) | |
754 { | |
755 if ( win->ReDraw ) | |
756 { | |
757 win->ReDraw( wsDisplay,win->WindowID ); | |
758 XFlush( wsDisplay ); | |
759 } | |
760 } | |
761 | |
762 // ---------------------------------------------------------------------------------------------- | |
763 // Do Exit. | |
764 // ---------------------------------------------------------------------------------------------- | |
765 void wsDoExit( void ) | |
766 { wsTrue=False; wsResizeWindow( wsWindowList[0],32,32 ); } | |
767 | |
768 // ---------------------------------------------------------------------------------------------- | |
769 // Put 'Image' to window. | |
770 // ---------------------------------------------------------------------------------------------- | |
771 void wsConvert( wsTWindow * win,unsigned char * Image,unsigned int Size ) | |
772 { if ( wsConvFunc ) wsConvFunc( Image,win->ImageData,win->xImage->width * win->xImage->height ); } | |
773 | |
774 void wsPutImage( wsTWindow * win ) | |
775 { | |
776 if ( wsUseXShm ) | |
777 { | |
778 XShmPutImage( wsDisplay,win->WindowID,win->wGC,win->xImage, | |
779 0,0, | |
780 ( win->Width - win->xImage->width ) / 2,( win->Height - win->xImage->height ) / 2, | |
781 win->xImage->width,win->xImage->height,0 ); | |
782 // win->Width,win->Height,0 ); | |
783 } | |
784 else | |
785 { | |
786 XPutImage( wsDisplay,win->WindowID,win->wGC,win->xImage, | |
787 0,0, | |
788 ( win->Width - win->xImage->width ) / 2,( win->Height - win->xImage->height ) / 2, | |
789 win->xImage->width,win->xImage->height ); | |
790 } | |
791 } | |
792 | |
793 // ---------------------------------------------------------------------------------------------- | |
794 // Move window to x, y. | |
795 // ---------------------------------------------------------------------------------------------- | |
796 void wsMoveWindow( wsTWindow * win,int x, int y ) | |
797 { | |
798 switch ( x ) | |
799 { | |
800 case -1: win->X=( wsMaxX / 2 ) - ( win->Width / 2 ); break; | |
801 case -2: win->X=wsMaxX - win->Width; break; | |
802 default: win->X=x; break; | |
803 } | |
804 switch ( y ) | |
805 { | |
806 case -1: win->Y=( wsMaxY / 2 ) - ( win->Height / 2 ); break; | |
807 case -2: win->Y=wsMaxY - win->Height; break; | |
808 default: win->Y=y; break; | |
809 } | |
810 | |
811 win->SizeHint.flags=PPosition; | |
812 win->SizeHint.x=win->X; | |
813 win->SizeHint.y=win->Y; | |
814 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); | |
815 | |
816 XMoveWindow( wsDisplay,win->WindowID,win->X,win->Y ); | |
817 } | |
818 | |
819 // ---------------------------------------------------------------------------------------------- | |
820 // Resize window to sx, sy. | |
821 // ---------------------------------------------------------------------------------------------- | |
822 void wsResizeWindow( wsTWindow * win,int sx, int sy ) | |
823 { | |
824 win->Width=sx; | |
825 win->Height=sy; | |
826 | |
827 win->SizeHint.flags=PSize; | |
828 win->SizeHint.width=win->Width; | |
829 win->SizeHint.height=win->Height; | |
830 if ( win->Property & wsMinSize ) | |
831 { | |
832 win->SizeHint.flags|=PMinSize; | |
833 win->SizeHint.min_width=win->Width; | |
834 win->SizeHint.min_height=win->Height; | |
835 } | |
836 if ( win->Property & wsMaxSize ) | |
837 { | |
838 win->SizeHint.flags|=PMaxSize; | |
839 win->SizeHint.max_width=win->Width; | |
840 win->SizeHint.max_height=win->Height; | |
841 } | |
842 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); | |
843 XResizeWindow( wsDisplay,win->WindowID,sx,sy ); | |
844 } | |
845 | |
846 // ---------------------------------------------------------------------------------------------- | |
847 // Iconify window. | |
848 // ---------------------------------------------------------------------------------------------- | |
849 void wsIconify( wsTWindow win ) | |
850 { XIconifyWindow( wsDisplay,win.WindowID,0 ); } | |
851 | |
852 // ---------------------------------------------------------------------------------------------- | |
853 // Move top the window. | |
854 // ---------------------------------------------------------------------------------------------- | |
855 void wsMoveTopWindow( wsTWindow * win ) | |
1779 | 856 //{ XRaiseWindow( wsDisplay,win->WindowID ); } |
857 { XUnmapWindow( wsDisplay,win->WindowID ); XMapWindow( wsDisplay,win->WindowID ); } | |
1693 | 858 |
859 // ---------------------------------------------------------------------------------------------- | |
860 // Set window background to 'color'. | |
861 // ---------------------------------------------------------------------------------------------- | |
862 void wsSetBackground( wsTWindow * win,int color ) | |
863 { XSetWindowBackground( wsDisplay,win->WindowID,color ); } | |
864 | |
865 void wsSetBackgroundRGB( wsTWindow * win,int r,int g,int b ) | |
866 { | |
867 int color = 0; | |
868 switch ( wsOutMask ) | |
869 { | |
870 case wsRGB32: | |
871 case wsRGB24: color=( r << 16 ) + ( g << 8 ) + b; break; | |
872 case wsBGR32: | |
873 case wsBGR24: color=( b << 16 ) + ( g << 8 ) + r; break; | |
874 case wsRGB16: PACK_RGB16( r,g,b,color ); break; | |
875 case wsBGR16: PACK_RGB16( b,g,r,color ); break; | |
876 case wsRGB15: PACK_RGB15( r,g,b,color ); break; | |
877 case wsBGR15: PACK_RGB15( b,g,r,color ); break; | |
878 } | |
879 XSetWindowBackground( wsDisplay,win->WindowID,color ); | |
880 } | |
881 | |
882 | |
883 // ---------------------------------------------------------------------------------------------- | |
884 // Draw string at x,y with fc ( foreground color ) and bc ( background color ). | |
885 // ---------------------------------------------------------------------------------------------- | |
886 void wsDrawString( wsTWindow win,int x,int y,char * str,int fc,int bc ) | |
887 { | |
888 XSetForeground( wsDisplay,win.wGC,bc ); | |
889 XFillRectangle( wsDisplay,win.WindowID,win.wGC,x,y, | |
890 XTextWidth( win.Font,str,strlen( str ) ) + 20, | |
891 win.FontHeight + 2 ); | |
892 XSetForeground( wsDisplay,win.wGC,fc ); | |
893 XDrawString( wsDisplay,win.WindowID,win.wGC,x + 10,y + 13,str,strlen( str ) ); | |
894 } | |
895 | |
896 // ---------------------------------------------------------------------------------------------- | |
897 // Calculation string width. | |
898 // ---------------------------------------------------------------------------------------------- | |
899 int wsTextWidth( wsTWindow win,char * str ) | |
900 { return XTextWidth( win.Font,str,strlen( str ) ) + 20; } | |
901 | |
902 // ---------------------------------------------------------------------------------------------- | |
903 // Show / hide mouse cursor. | |
904 // ---------------------------------------------------------------------------------------------- | |
905 void wsVisibleMouse( wsTWindow * win,int m ) | |
906 { | |
907 switch ( m ) | |
908 { | |
909 case wsShowMouseCursor: | |
910 if ( win->wsCursor != None ) | |
911 { | |
912 XFreeCursor( wsDisplay,win->wsCursor ); | |
913 win->wsCursor=None; | |
914 } | |
915 XDefineCursor( wsDisplay,win->WindowID,0 ); | |
916 break; | |
917 case wsHideMouseCursor: | |
918 win->wsCursor=XCreatePixmapCursor( wsDisplay,win->wsCursorPixmap,win->wsCursorPixmap,&win->wsColor,&win->wsColor,0,0 ); | |
919 XDefineCursor( wsDisplay,win->WindowID,win->wsCursor ); | |
920 break; | |
921 } | |
922 XFlush( wsDisplay ); | |
923 } | |
924 | |
925 int wsGetDepthOnScreen( void ) | |
926 { | |
927 int bpp,ibpp; | |
928 XImage * mXImage; | |
929 XWindowAttributes attribs; | |
930 | |
931 mXImage=XGetImage( wsDisplay,wsRootWin,0,0,1,1,AllPlanes,ZPixmap ); | |
932 bpp=mXImage->bits_per_pixel; | |
933 | |
934 XGetWindowAttributes( wsDisplay,wsRootWin,&attribs ); | |
935 ibpp=attribs.depth; | |
936 mXImage=XGetImage( wsDisplay,wsRootWin,0,0,1,1,AllPlanes,ZPixmap ); | |
937 bpp=mXImage->bits_per_pixel; | |
938 if ( ( ibpp + 7 ) / 8 != ( bpp + 7 ) / 8 ) ibpp=bpp; | |
939 wsDepthOnScreen=ibpp; | |
940 wsRedMask=mXImage->red_mask; | |
941 wsGreenMask=mXImage->green_mask; | |
942 wsBlueMask=mXImage->blue_mask; | |
943 XDestroyImage( mXImage ); | |
944 return ibpp; | |
945 } | |
946 | |
947 void wsXDone( void ) | |
948 { | |
949 // if ( wsSwitchedAnotherVideoMode ) wsChangeVideoMode( wsOldXResolution,wsOldYResolution ); | |
950 // if ( wsUseDGA ) XF86DGADirectVideo( wsDisplay,wsScreen,0 ); | |
951 XCloseDisplay( wsDisplay ); | |
952 } | |
953 | |
954 void wsVisibleWindow( wsTWindow * win,int show ) | |
955 { | |
956 switch( show ) | |
957 { | |
958 case wsShowWindow: XMapWindow( wsDisplay,win->WindowID ); break; | |
959 case wsHideWindow: XUnmapWindow( wsDisplay,win->WindowID ); break; | |
960 } | |
961 XFlush( wsDisplay ); | |
962 } | |
963 | |
964 void wsDestroyImage( wsTWindow * win ) | |
965 { | |
966 if ( win->xImage ) | |
967 { | |
968 XDestroyImage( win->xImage ); | |
969 if ( wsUseXShm ) | |
970 { | |
971 XShmDetach( wsDisplay,&win->Shminfo ); | |
972 shmdt( win->Shminfo.shmaddr ); | |
973 } | |
974 } | |
975 win->xImage=NULL; | |
976 } | |
977 | |
978 void wsCreateImage( wsTWindow * win ) | |
979 { | |
980 int CompletionType = -1; | |
981 if ( wsUseXShm ) | |
982 { | |
983 CompletionType=XShmGetEventBase( wsDisplay ) + ShmCompletion; | |
984 win->xImage=XShmCreateImage( wsDisplay,win->VisualInfo.visual, | |
985 win->Attribs.depth,ZPixmap,NULL,&win->Shminfo,win->Width,win->Height ); | |
986 if ( win->xImage == NULL ) | |
987 { | |
988 fprintf( stderr,"[ws] shared memory extension error.\n" ); | |
989 exit( 0 ); | |
990 } | |
991 // #ifdef DEBUG | |
992 // fprintf( stderr,"[ws] Screen depth: %d\n",win->xImage->bits_per_pixel ); | |
993 // #endif | |
994 win->Shminfo.shmid=shmget( IPC_PRIVATE,win->xImage->bytes_per_line * win->xImage->height,IPC_CREAT|0777 ); | |
995 if ( win->Shminfo.shmid < 0 ) | |
996 { | |
997 XDestroyImage( win->xImage ); | |
998 fprintf( stderr,"[ws] shared memory extension error.\n" ); | |
999 exit( 0 ); | |
1000 } | |
1001 win->Shminfo.shmaddr=(char *)shmat( win->Shminfo.shmid,0,0 ); | |
1002 | |
1003 if ( win->Shminfo.shmaddr == ((char *) -1) ) | |
1004 { | |
1005 XDestroyImage( win->xImage ); | |
1006 if ( win->Shminfo.shmaddr != ((char *) -1) ) shmdt( win->Shminfo.shmaddr ); | |
1007 fprintf( stderr,"[ws] shared memory extension error.\n" ); | |
1008 exit( 0 ); | |
1009 } | |
1010 win->xImage->data=win->Shminfo.shmaddr; | |
1011 win->Shminfo.readOnly=0; | |
1012 XShmAttach( wsDisplay,&win->Shminfo ); | |
1013 shmctl( win->Shminfo.shmid,IPC_RMID,0 ); | |
1014 } | |
1015 else | |
1016 { | |
1017 win->xImage=XCreateImage( wsDisplay,win->VisualInfo.visual,win->Attribs.depth, | |
1018 ZPixmap,0,0,win->Width,win->Height, | |
1019 (wsDepthOnScreen == 3) ? 32 : wsDepthOnScreen, | |
1020 0 ); | |
1021 if ( ( win->xImage->data=malloc( win->xImage->bytes_per_line * win->xImage->height ) ) == NULL ) | |
1022 { | |
1023 fprintf( stderr,"[ws] sorry, not enough memory for draw buffer.\n" ); | |
1024 exit( 0 ); | |
1025 } | |
1026 } | |
1027 win->ImageData=(unsigned char *)win->xImage->data; | |
1028 win->ImageDataw=(unsigned short int *)win->xImage->data; | |
1029 win->ImageDatadw=(unsigned int *)win->xImage->data; | |
1030 } | |
1031 | |
1032 void wsResizeImage( wsTWindow * win ) | |
1033 { wsDestroyImage( win ); wsCreateImage( win ); } | |
1034 | |
1035 int wsGetOutMask( void ) | |
1036 { | |
1037 if ( ( wsDepthOnScreen == 32 )&&( wsRedMask == 0xff0000 )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0x0000ff ) ) return wsRGB32; | |
1038 if ( ( wsDepthOnScreen == 32 )&&( wsRedMask == 0x0000ff )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0xff0000 ) ) return wsBGR32; | |
1039 if ( ( wsDepthOnScreen == 24 )&&( wsRedMask == 0xff0000 )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0x0000ff ) ) return wsRGB24; | |
1040 if ( ( wsDepthOnScreen == 24 )&&( wsRedMask == 0x0000ff )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0xff0000 ) ) return wsBGR24; | |
1041 if ( ( wsDepthOnScreen == 16 )&&( wsRedMask == 0xf800 )&&( wsGreenMask == 0x7e0 )&&( wsBlueMask == 0x1f ) ) return wsRGB16; | |
1042 if ( ( wsDepthOnScreen == 16 )&&( wsRedMask == 0x1f )&&( wsGreenMask == 0x7e0 )&&( wsBlueMask == 0xf800 ) ) return wsBGR16; | |
1043 if ( ( wsDepthOnScreen == 15 )&&( wsRedMask == 0x7c00 )&&( wsGreenMask == 0x3e0 )&&( wsBlueMask == 0x1f ) ) return wsRGB15; | |
1044 if ( ( wsDepthOnScreen == 15 )&&( wsRedMask == 0x1f )&&( wsGreenMask == 0x3e0 )&&( wsBlueMask == 0x7c00 ) ) return wsBGR15; | |
1045 return 0; | |
1046 } | |
1047 | |
1048 void wsSetTitle( wsTWindow * win,char * name ) | |
1049 { XStoreName( wsDisplay,win->WindowID,name ); } | |
1050 | |
1051 void wsSetMousePosition( wsTWindow * win,int x, int y ) | |
1052 { XWarpPointer( wsDisplay,wsRootWin,win->WindowID,0,0,0,0,x,y ); } | |
1053 | |
1054 static int dpms_disabled=0; | |
1055 static int timeout_save=0; | |
1056 | |
1057 void wsScreenSaverOn( Display *mDisplay ) | |
1058 { | |
1059 int nothing; | |
1060 if ( dpms_disabled ) | |
1061 { | |
1062 if ( DPMSQueryExtension( mDisplay,¬hing,¬hing ) ) | |
1063 { | |
1064 if ( !DPMSEnable( mDisplay ) ) fprintf( stderr,"DPMS not available ?\n" ); // restoring power saving settings | |
1065 else | |
1066 { | |
1067 // DPMS does not seem to be enabled unless we call DPMSInfo | |
1068 BOOL onoff; | |
1069 CARD16 state; | |
1070 DPMSInfo( mDisplay,&state,&onoff ); | |
1071 if ( onoff ) fprintf( stderr,"Successfully enabled DPMS.\n" ); | |
1072 else fprintf( stderr,"Could not enable DPMS.\n" ); | |
1073 } | |
1074 } | |
1075 } | |
1076 | |
1077 if ( timeout_save ) | |
1078 { | |
1079 int dummy, interval, prefer_blank, allow_exp; | |
1080 XGetScreenSaver( mDisplay,&dummy,&interval,&prefer_blank,&allow_exp ); | |
1081 XSetScreenSaver( mDisplay,timeout_save,interval,prefer_blank,allow_exp ); | |
1082 XGetScreenSaver( mDisplay,&timeout_save,&interval,&prefer_blank,&allow_exp ); | |
1083 } | |
1084 } | |
1085 | |
1086 void wsScreenSaverOff( Display * mDisplay ) | |
1087 { | |
1088 int interval,prefer_blank,allow_exp,nothing; | |
1089 | |
1090 if ( DPMSQueryExtension( mDisplay,¬hing,¬hing ) ) | |
1091 { | |
1092 BOOL onoff; | |
1093 CARD16 state; | |
1094 DPMSInfo( mDisplay,&state,&onoff ); | |
1095 if ( onoff ) | |
1096 { | |
1097 Status stat; | |
1098 fprintf( stderr,"Disabling DPMS.\n" ); | |
1099 dpms_disabled=1; | |
1100 stat=DPMSDisable( mDisplay ); // monitor powersave off | |
1101 fprintf( stderr,"stat: %d.\n",stat ); | |
1102 } | |
1103 } | |
1104 XGetScreenSaver( mDisplay,&timeout_save,&interval,&prefer_blank,&allow_exp ); | |
1105 if ( timeout_save ) XSetScreenSaver( mDisplay,0,interval,prefer_blank,allow_exp ); // turning off screensaver | |
1106 } | |
1107 | |
1108 void wsSetShape( wsTWindow * win,char * data ) | |
1109 { | |
1110 #ifdef HAVE_XSHAPE | |
1111 if ( ( !wsUseXShape )||( !data ) ) return; | |
1112 win->Mask=XCreateBitmapFromData( wsDisplay,win->WindowID,data,win->Width,win->Height ); | |
1113 XShapeCombineMask( wsDisplay,win->WindowID,ShapeBounding,0,0,win->Mask,ShapeSet ); | |
1114 XFreePixmap( wsDisplay,win->Mask ); | |
1115 #endif | |
1116 } | |
1117 | |
1118 #include "wsmkeys.h" |