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