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