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