Mercurial > mplayer.hg
annotate Gui/wm/ws.c @ 2030:68dbb349566e
mwm fullscreen bug fixed (?)
author | pontscho |
---|---|
date | Mon, 01 Oct 2001 13:09:04 +0000 |
parents | 41ed89701ece |
children | deb4aff05c44 |
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: | |
1779 | 616 break; |
1860 | 617 fprintf(stderr,"[ws] PropertyNotify %s\n",XGetAtomName( wsDisplay,Event->xproperty.atom ) ); |
1693 | 618 if ( Event->xproperty.atom == wsWindowList[l]->AtomRemote ) |
619 { | |
620 Atom type; | |
621 int format; | |
622 unsigned long nitems, bytesafter; | |
623 unsigned char * args = NULL; | |
624 | |
625 // fprintf( stderr,"[ws] remote property notify.\n" ); | |
626 XGetWindowProperty( wsDisplay, | |
627 Event->xproperty.window, | |
628 Event->xproperty.atom, | |
629 0,( 65536 / sizeof( long ) ), | |
630 False,XA_STRING, | |
631 &type,&format,&nitems,&bytesafter, | |
632 &args ); | |
633 if ( ( nitems )&&( wsWindowList[l]->RemoteHandler ) ) | |
634 { | |
635 args[strlen( args ) - 1]=0; | |
636 wsWindowList[l]->RemoteHandler( args ); | |
637 args[strlen( args ) - 1]=1; | |
638 XFree( args ); | |
639 } | |
640 } | |
641 break; | |
642 | |
643 } | |
644 XFlush( wsDisplay ); | |
645 XSync( wsDisplay,False ); | |
646 return !wsTrue; | |
647 // return True; | |
648 } | |
649 | |
650 Bool wsDummyEvents( Display * display,XEvent * Event,XPointer arg ) | |
651 { return True; } | |
652 | |
1709 | 653 // mplTimerHandler(0); // handle timer event |
654 void wsHandleEvents(){ | |
655 // handle pending events | |
656 while ( XPending(wsDisplay) ){ | |
657 XNextEvent( wsDisplay,&wsEvent ); | |
658 // printf("### X event: %d [%d]\n",wsEvent.type,delay); | |
659 wsEvents( wsDisplay,&wsEvent,NULL ); | |
660 } | |
661 } | |
662 | |
1693 | 663 void wsMainLoop( void ) |
664 { | |
1699 | 665 int delay=20; |
1693 | 666 fprintf( stderr,"[ws] init threads: %d\n",XInitThreads() ); |
667 XSynchronize( wsDisplay,False ); | |
668 XLockDisplay( wsDisplay ); | |
669 // XIfEvent( wsDisplay,&wsEvent,wsEvents,NULL ); | |
1699 | 670 |
671 #if 1 | |
672 | |
673 while(wsTrue){ | |
674 // handle pending events | |
675 while ( XPending(wsDisplay) ){ | |
676 XNextEvent( wsDisplay,&wsEvent ); | |
1701 | 677 // printf("### X event: %d [%d]\n",wsEvent.type,delay); |
1699 | 678 wsEvents( wsDisplay,&wsEvent,NULL ); |
1701 | 679 delay=0; |
1699 | 680 } |
681 mplTimerHandler(0); // handle timer event | |
682 usleep(delay*1000); // FIXME! | |
1701 | 683 if(delay<10*20) delay+=20; // pump up delay up to 0.2 sec (low activity) |
1699 | 684 } |
685 | |
686 #else | |
687 | |
1693 | 688 while( wsTrue ) |
689 { | |
690 XIfEvent( wsDisplay,&wsEvent,wsDummyEvents,NULL ); | |
691 wsEvents( wsDisplay,&wsEvent,NULL ); | |
692 } | |
1699 | 693 #endif |
694 | |
1693 | 695 XUnlockDisplay( wsDisplay ); |
696 } | |
697 | |
698 // ---------------------------------------------------------------------------------------------- | |
699 // Switch to fullscreen. | |
700 // ---------------------------------------------------------------------------------------------- | |
701 void wsFullScreen( wsTWindow * win ) | |
702 { | |
703 int decoration = 0; | |
704 XUnmapWindow( wsDisplay,win->WindowID ); | |
705 win->SizeHint.flags=0; | |
706 if ( win->isFullScreen ) | |
707 { | |
708 win->X=win->OldX; | |
709 win->Y=win->OldY; | |
710 win->Width=win->OldWidth; | |
711 win->Height=win->OldHeight; | |
712 win->isFullScreen=False; | |
713 decoration=win->Decorations; | |
714 wsScreenSaverOn( wsDisplay ); | |
715 } | |
716 else | |
717 { | |
718 win->OldX=win->X; win->OldY=win->Y; | |
719 win->OldWidth=win->Width; win->OldHeight=win->Height; | |
720 win->X=0; win->Y=0; | |
721 win->Width=wsMaxX; win->Height=wsMaxY; | |
722 win->isFullScreen=True; | |
723 wsScreenSaverOff( wsDisplay ); | |
724 } | |
725 | |
726 win->SizeHint.flags|=PPosition | PSize; | |
727 win->SizeHint.x=win->X; | |
728 win->SizeHint.y=win->Y; | |
729 win->SizeHint.width=win->Width; | |
730 win->SizeHint.height=win->Height; | |
1860 | 731 if ( win->Property & wsMaxSize ) |
732 { | |
733 win->SizeHint.flags|=PMaxSize; | |
734 win->SizeHint.max_width=win->Width; | |
735 win->SizeHint.max_height=win->Height; | |
736 } | |
737 if ( win->Property & wsMinSize ) | |
738 { | |
739 win->SizeHint.flags|=PMinSize; | |
740 win->SizeHint.min_width=win->Width; | |
741 win->SizeHint.min_height=win->Height; | |
742 } | |
1693 | 743 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); |
744 | |
745 XMoveResizeWindow( wsDisplay,win->WindowID,win->X,win->Y,win->Width,win->Height ); | |
746 wsWindowDecoration( win,decoration ); | |
747 XRaiseWindow( wsDisplay,win->WindowID ); | |
748 XMapWindow( wsDisplay,win->WindowID ); | |
749 } | |
750 | |
751 // ---------------------------------------------------------------------------------------------- | |
752 // Redraw screen. | |
753 // ---------------------------------------------------------------------------------------------- | |
754 void wsPostRedisplay( wsTWindow * win ) | |
755 { | |
756 if ( win->ReDraw ) | |
757 { | |
758 win->ReDraw( wsDisplay,win->WindowID ); | |
759 XFlush( wsDisplay ); | |
760 } | |
761 } | |
762 | |
763 // ---------------------------------------------------------------------------------------------- | |
764 // Do Exit. | |
765 // ---------------------------------------------------------------------------------------------- | |
766 void wsDoExit( void ) | |
767 { wsTrue=False; wsResizeWindow( wsWindowList[0],32,32 ); } | |
768 | |
769 // ---------------------------------------------------------------------------------------------- | |
770 // Put 'Image' to window. | |
771 // ---------------------------------------------------------------------------------------------- | |
772 void wsConvert( wsTWindow * win,unsigned char * Image,unsigned int Size ) | |
773 { if ( wsConvFunc ) wsConvFunc( Image,win->ImageData,win->xImage->width * win->xImage->height ); } | |
774 | |
775 void wsPutImage( wsTWindow * win ) | |
776 { | |
777 if ( wsUseXShm ) | |
778 { | |
779 XShmPutImage( wsDisplay,win->WindowID,win->wGC,win->xImage, | |
780 0,0, | |
781 ( win->Width - win->xImage->width ) / 2,( win->Height - win->xImage->height ) / 2, | |
782 win->xImage->width,win->xImage->height,0 ); | |
783 // win->Width,win->Height,0 ); | |
784 } | |
785 else | |
786 { | |
787 XPutImage( 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 ); | |
791 } | |
792 } | |
793 | |
794 // ---------------------------------------------------------------------------------------------- | |
795 // Move window to x, y. | |
796 // ---------------------------------------------------------------------------------------------- | |
797 void wsMoveWindow( wsTWindow * win,int x, int y ) | |
798 { | |
799 switch ( x ) | |
800 { | |
801 case -1: win->X=( wsMaxX / 2 ) - ( win->Width / 2 ); break; | |
802 case -2: win->X=wsMaxX - win->Width; break; | |
803 default: win->X=x; break; | |
804 } | |
805 switch ( y ) | |
806 { | |
807 case -1: win->Y=( wsMaxY / 2 ) - ( win->Height / 2 ); break; | |
808 case -2: win->Y=wsMaxY - win->Height; break; | |
809 default: win->Y=y; break; | |
810 } | |
811 | |
812 win->SizeHint.flags=PPosition; | |
813 win->SizeHint.x=win->X; | |
814 win->SizeHint.y=win->Y; | |
815 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); | |
816 | |
817 XMoveWindow( wsDisplay,win->WindowID,win->X,win->Y ); | |
1810 | 818 if ( win->ReSize ) win->ReSize( win->X,win->Y,win->Width,win->Height ); |
1693 | 819 } |
820 | |
821 // ---------------------------------------------------------------------------------------------- | |
822 // Resize window to sx, sy. | |
823 // ---------------------------------------------------------------------------------------------- | |
824 void wsResizeWindow( wsTWindow * win,int sx, int sy ) | |
825 { | |
826 win->Width=sx; | |
827 win->Height=sy; | |
828 | |
829 win->SizeHint.flags=PSize; | |
830 win->SizeHint.width=win->Width; | |
831 win->SizeHint.height=win->Height; | |
832 if ( win->Property & wsMinSize ) | |
833 { | |
834 win->SizeHint.flags|=PMinSize; | |
835 win->SizeHint.min_width=win->Width; | |
836 win->SizeHint.min_height=win->Height; | |
837 } | |
838 if ( win->Property & wsMaxSize ) | |
839 { | |
840 win->SizeHint.flags|=PMaxSize; | |
841 win->SizeHint.max_width=win->Width; | |
842 win->SizeHint.max_height=win->Height; | |
843 } | |
844 XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); | |
845 XResizeWindow( wsDisplay,win->WindowID,sx,sy ); | |
1810 | 846 if ( win->ReSize ) win->ReSize( win->X,win->Y,win->Width,win->Height ); |
1693 | 847 } |
848 | |
849 // ---------------------------------------------------------------------------------------------- | |
850 // Iconify window. | |
851 // ---------------------------------------------------------------------------------------------- | |
852 void wsIconify( wsTWindow win ) | |
853 { XIconifyWindow( wsDisplay,win.WindowID,0 ); } | |
854 | |
855 // ---------------------------------------------------------------------------------------------- | |
856 // Move top the window. | |
857 // ---------------------------------------------------------------------------------------------- | |
858 void wsMoveTopWindow( wsTWindow * win ) | |
2030 | 859 { XRaiseWindow( wsDisplay,win->WindowID ); } |
860 //{ XUnmapWindow( wsDisplay,win->WindowID ); XMapWindow( wsDisplay,win->WindowID ); } | |
1693 | 861 |
862 // ---------------------------------------------------------------------------------------------- | |
863 // Set window background to 'color'. | |
864 // ---------------------------------------------------------------------------------------------- | |
865 void wsSetBackground( wsTWindow * win,int color ) | |
866 { XSetWindowBackground( wsDisplay,win->WindowID,color ); } | |
867 | |
868 void wsSetBackgroundRGB( wsTWindow * win,int r,int g,int b ) | |
869 { | |
870 int color = 0; | |
871 switch ( wsOutMask ) | |
872 { | |
873 case wsRGB32: | |
874 case wsRGB24: color=( r << 16 ) + ( g << 8 ) + b; break; | |
875 case wsBGR32: | |
876 case wsBGR24: color=( b << 16 ) + ( g << 8 ) + r; break; | |
877 case wsRGB16: PACK_RGB16( r,g,b,color ); break; | |
878 case wsBGR16: PACK_RGB16( b,g,r,color ); break; | |
879 case wsRGB15: PACK_RGB15( r,g,b,color ); break; | |
880 case wsBGR15: PACK_RGB15( b,g,r,color ); break; | |
881 } | |
882 XSetWindowBackground( wsDisplay,win->WindowID,color ); | |
883 } | |
884 | |
1814 | 885 void wsSetForegroundRGB( wsTWindow * win,int r,int g,int b ) |
886 { | |
887 int color = 0; | |
888 switch ( wsOutMask ) | |
889 { | |
890 case wsRGB32: | |
891 case wsRGB24: color=( r << 16 ) + ( g << 8 ) + b; break; | |
892 case wsBGR32: | |
893 case wsBGR24: color=( b << 16 ) + ( g << 8 ) + r; break; | |
894 case wsRGB16: PACK_RGB16( r,g,b,color ); break; | |
895 case wsBGR16: PACK_RGB16( b,g,r,color ); break; | |
896 case wsRGB15: PACK_RGB15( r,g,b,color ); break; | |
897 case wsBGR15: PACK_RGB15( b,g,r,color ); break; | |
898 } | |
899 XSetForeground( wsDisplay,win->wGC,color ); | |
900 // XSetWindowBackground( wsDisplay,win->WindowID,color ); | |
901 } | |
1693 | 902 |
903 // ---------------------------------------------------------------------------------------------- | |
904 // Draw string at x,y with fc ( foreground color ) and bc ( background color ). | |
905 // ---------------------------------------------------------------------------------------------- | |
906 void wsDrawString( wsTWindow win,int x,int y,char * str,int fc,int bc ) | |
907 { | |
908 XSetForeground( wsDisplay,win.wGC,bc ); | |
909 XFillRectangle( wsDisplay,win.WindowID,win.wGC,x,y, | |
910 XTextWidth( win.Font,str,strlen( str ) ) + 20, | |
911 win.FontHeight + 2 ); | |
912 XSetForeground( wsDisplay,win.wGC,fc ); | |
913 XDrawString( wsDisplay,win.WindowID,win.wGC,x + 10,y + 13,str,strlen( str ) ); | |
914 } | |
915 | |
916 // ---------------------------------------------------------------------------------------------- | |
917 // Calculation string width. | |
918 // ---------------------------------------------------------------------------------------------- | |
919 int wsTextWidth( wsTWindow win,char * str ) | |
920 { return XTextWidth( win.Font,str,strlen( str ) ) + 20; } | |
921 | |
922 // ---------------------------------------------------------------------------------------------- | |
923 // Show / hide mouse cursor. | |
924 // ---------------------------------------------------------------------------------------------- | |
925 void wsVisibleMouse( wsTWindow * win,int m ) | |
926 { | |
927 switch ( m ) | |
928 { | |
929 case wsShowMouseCursor: | |
930 if ( win->wsCursor != None ) | |
931 { | |
932 XFreeCursor( wsDisplay,win->wsCursor ); | |
933 win->wsCursor=None; | |
934 } | |
935 XDefineCursor( wsDisplay,win->WindowID,0 ); | |
936 break; | |
937 case wsHideMouseCursor: | |
938 win->wsCursor=XCreatePixmapCursor( wsDisplay,win->wsCursorPixmap,win->wsCursorPixmap,&win->wsColor,&win->wsColor,0,0 ); | |
939 XDefineCursor( wsDisplay,win->WindowID,win->wsCursor ); | |
940 break; | |
941 } | |
942 XFlush( wsDisplay ); | |
943 } | |
944 | |
945 int wsGetDepthOnScreen( void ) | |
946 { | |
947 int bpp,ibpp; | |
948 XImage * mXImage; | |
949 XWindowAttributes attribs; | |
950 | |
951 mXImage=XGetImage( wsDisplay,wsRootWin,0,0,1,1,AllPlanes,ZPixmap ); | |
952 bpp=mXImage->bits_per_pixel; | |
953 | |
954 XGetWindowAttributes( wsDisplay,wsRootWin,&attribs ); | |
955 ibpp=attribs.depth; | |
956 mXImage=XGetImage( wsDisplay,wsRootWin,0,0,1,1,AllPlanes,ZPixmap ); | |
957 bpp=mXImage->bits_per_pixel; | |
958 if ( ( ibpp + 7 ) / 8 != ( bpp + 7 ) / 8 ) ibpp=bpp; | |
959 wsDepthOnScreen=ibpp; | |
960 wsRedMask=mXImage->red_mask; | |
961 wsGreenMask=mXImage->green_mask; | |
962 wsBlueMask=mXImage->blue_mask; | |
963 XDestroyImage( mXImage ); | |
964 return ibpp; | |
965 } | |
966 | |
967 void wsXDone( void ) | |
968 { | |
969 // if ( wsSwitchedAnotherVideoMode ) wsChangeVideoMode( wsOldXResolution,wsOldYResolution ); | |
970 // if ( wsUseDGA ) XF86DGADirectVideo( wsDisplay,wsScreen,0 ); | |
971 XCloseDisplay( wsDisplay ); | |
972 } | |
973 | |
974 void wsVisibleWindow( wsTWindow * win,int show ) | |
975 { | |
976 switch( show ) | |
977 { | |
978 case wsShowWindow: XMapWindow( wsDisplay,win->WindowID ); break; | |
979 case wsHideWindow: XUnmapWindow( wsDisplay,win->WindowID ); break; | |
980 } | |
981 XFlush( wsDisplay ); | |
982 } | |
983 | |
984 void wsDestroyImage( wsTWindow * win ) | |
985 { | |
986 if ( win->xImage ) | |
987 { | |
988 XDestroyImage( win->xImage ); | |
989 if ( wsUseXShm ) | |
990 { | |
991 XShmDetach( wsDisplay,&win->Shminfo ); | |
992 shmdt( win->Shminfo.shmaddr ); | |
993 } | |
994 } | |
995 win->xImage=NULL; | |
996 } | |
997 | |
1858
88a88d0a3f94
fix skin changing, xv fullscreen redraw bug, etc.
pontscho
parents:
1853
diff
changeset
|
998 void wsCreateImage( wsTWindow * win,int Width,int Height ) |
1693 | 999 { |
1000 int CompletionType = -1; | |
1001 if ( wsUseXShm ) | |
1002 { | |
1003 CompletionType=XShmGetEventBase( wsDisplay ) + ShmCompletion; | |
1004 win->xImage=XShmCreateImage( wsDisplay,win->VisualInfo.visual, | |
1858
88a88d0a3f94
fix skin changing, xv fullscreen redraw bug, etc.
pontscho
parents:
1853
diff
changeset
|
1005 win->Attribs.depth,ZPixmap,NULL,&win->Shminfo,Width,Height ); |
1693 | 1006 if ( win->xImage == NULL ) |
1007 { | |
1008 fprintf( stderr,"[ws] shared memory extension error.\n" ); | |
1009 exit( 0 ); | |
1010 } | |
1011 // #ifdef DEBUG | |
1012 // fprintf( stderr,"[ws] Screen depth: %d\n",win->xImage->bits_per_pixel ); | |
1013 // #endif | |
1014 win->Shminfo.shmid=shmget( IPC_PRIVATE,win->xImage->bytes_per_line * win->xImage->height,IPC_CREAT|0777 ); | |
1015 if ( win->Shminfo.shmid < 0 ) | |
1016 { | |
1017 XDestroyImage( win->xImage ); | |
1018 fprintf( stderr,"[ws] shared memory extension error.\n" ); | |
1019 exit( 0 ); | |
1020 } | |
1021 win->Shminfo.shmaddr=(char *)shmat( win->Shminfo.shmid,0,0 ); | |
1022 | |
1023 if ( win->Shminfo.shmaddr == ((char *) -1) ) | |
1024 { | |
1025 XDestroyImage( win->xImage ); | |
1026 if ( win->Shminfo.shmaddr != ((char *) -1) ) shmdt( win->Shminfo.shmaddr ); | |
1027 fprintf( stderr,"[ws] shared memory extension error.\n" ); | |
1028 exit( 0 ); | |
1029 } | |
1030 win->xImage->data=win->Shminfo.shmaddr; | |
1031 win->Shminfo.readOnly=0; | |
1032 XShmAttach( wsDisplay,&win->Shminfo ); | |
1033 shmctl( win->Shminfo.shmid,IPC_RMID,0 ); | |
1034 } | |
1035 else | |
1036 { | |
1037 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
|
1038 ZPixmap,0,0,Width,Height, |
1693 | 1039 (wsDepthOnScreen == 3) ? 32 : wsDepthOnScreen, |
1040 0 ); | |
1041 if ( ( win->xImage->data=malloc( win->xImage->bytes_per_line * win->xImage->height ) ) == NULL ) | |
1042 { | |
1043 fprintf( stderr,"[ws] sorry, not enough memory for draw buffer.\n" ); | |
1044 exit( 0 ); | |
1045 } | |
1046 } | |
1047 win->ImageData=(unsigned char *)win->xImage->data; | |
1048 win->ImageDataw=(unsigned short int *)win->xImage->data; | |
1049 win->ImageDatadw=(unsigned int *)win->xImage->data; | |
1050 } | |
1051 | |
1858
88a88d0a3f94
fix skin changing, xv fullscreen redraw bug, etc.
pontscho
parents:
1853
diff
changeset
|
1052 void wsResizeImage( wsTWindow * win,int Width,int Height ) |
88a88d0a3f94
fix skin changing, xv fullscreen redraw bug, etc.
pontscho
parents:
1853
diff
changeset
|
1053 { wsDestroyImage( win ); wsCreateImage( win,Width,Height ); } |
1693 | 1054 |
1055 int wsGetOutMask( void ) | |
1056 { | |
1057 if ( ( wsDepthOnScreen == 32 )&&( wsRedMask == 0xff0000 )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0x0000ff ) ) return wsRGB32; | |
1058 if ( ( wsDepthOnScreen == 32 )&&( wsRedMask == 0x0000ff )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0xff0000 ) ) return wsBGR32; | |
1059 if ( ( wsDepthOnScreen == 24 )&&( wsRedMask == 0xff0000 )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0x0000ff ) ) return wsRGB24; | |
1060 if ( ( wsDepthOnScreen == 24 )&&( wsRedMask == 0x0000ff )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0xff0000 ) ) return wsBGR24; | |
1061 if ( ( wsDepthOnScreen == 16 )&&( wsRedMask == 0xf800 )&&( wsGreenMask == 0x7e0 )&&( wsBlueMask == 0x1f ) ) return wsRGB16; | |
1062 if ( ( wsDepthOnScreen == 16 )&&( wsRedMask == 0x1f )&&( wsGreenMask == 0x7e0 )&&( wsBlueMask == 0xf800 ) ) return wsBGR16; | |
1063 if ( ( wsDepthOnScreen == 15 )&&( wsRedMask == 0x7c00 )&&( wsGreenMask == 0x3e0 )&&( wsBlueMask == 0x1f ) ) return wsRGB15; | |
1064 if ( ( wsDepthOnScreen == 15 )&&( wsRedMask == 0x1f )&&( wsGreenMask == 0x3e0 )&&( wsBlueMask == 0x7c00 ) ) return wsBGR15; | |
1065 return 0; | |
1066 } | |
1067 | |
1068 void wsSetTitle( wsTWindow * win,char * name ) | |
1069 { XStoreName( wsDisplay,win->WindowID,name ); } | |
1070 | |
1071 void wsSetMousePosition( wsTWindow * win,int x, int y ) | |
1072 { XWarpPointer( wsDisplay,wsRootWin,win->WindowID,0,0,0,0,x,y ); } | |
1073 | |
1074 static int dpms_disabled=0; | |
1075 static int timeout_save=0; | |
1076 | |
1077 void wsScreenSaverOn( Display *mDisplay ) | |
1078 { | |
1079 int nothing; | |
1080 if ( dpms_disabled ) | |
1081 { | |
1082 if ( DPMSQueryExtension( mDisplay,¬hing,¬hing ) ) | |
1083 { | |
1084 if ( !DPMSEnable( mDisplay ) ) fprintf( stderr,"DPMS not available ?\n" ); // restoring power saving settings | |
1085 else | |
1086 { | |
1087 // DPMS does not seem to be enabled unless we call DPMSInfo | |
1088 BOOL onoff; | |
1089 CARD16 state; | |
1090 DPMSInfo( mDisplay,&state,&onoff ); | |
1091 if ( onoff ) fprintf( stderr,"Successfully enabled DPMS.\n" ); | |
1092 else fprintf( stderr,"Could not enable DPMS.\n" ); | |
1093 } | |
1094 } | |
1095 } | |
1096 | |
1097 if ( timeout_save ) | |
1098 { | |
1099 int dummy, interval, prefer_blank, allow_exp; | |
1100 XGetScreenSaver( mDisplay,&dummy,&interval,&prefer_blank,&allow_exp ); | |
1101 XSetScreenSaver( mDisplay,timeout_save,interval,prefer_blank,allow_exp ); | |
1102 XGetScreenSaver( mDisplay,&timeout_save,&interval,&prefer_blank,&allow_exp ); | |
1103 } | |
1104 } | |
1105 | |
1106 void wsScreenSaverOff( Display * mDisplay ) | |
1107 { | |
1108 int interval,prefer_blank,allow_exp,nothing; | |
1109 | |
1110 if ( DPMSQueryExtension( mDisplay,¬hing,¬hing ) ) | |
1111 { | |
1112 BOOL onoff; | |
1113 CARD16 state; | |
1114 DPMSInfo( mDisplay,&state,&onoff ); | |
1115 if ( onoff ) | |
1116 { | |
1117 Status stat; | |
1118 fprintf( stderr,"Disabling DPMS.\n" ); | |
1119 dpms_disabled=1; | |
1120 stat=DPMSDisable( mDisplay ); // monitor powersave off | |
1121 fprintf( stderr,"stat: %d.\n",stat ); | |
1122 } | |
1123 } | |
1124 XGetScreenSaver( mDisplay,&timeout_save,&interval,&prefer_blank,&allow_exp ); | |
1125 if ( timeout_save ) XSetScreenSaver( mDisplay,0,interval,prefer_blank,allow_exp ); // turning off screensaver | |
1126 } | |
1127 | |
1128 void wsSetShape( wsTWindow * win,char * data ) | |
1129 { | |
1130 #ifdef HAVE_XSHAPE | |
1852 | 1131 if ( !wsUseXShape ) return; |
1132 if ( data ) | |
1133 { | |
1134 win->Mask=XCreateBitmapFromData( wsDisplay,win->WindowID,data,win->Width,win->Height ); | |
1135 XShapeCombineMask( wsDisplay,win->WindowID,ShapeBounding,0,0,win->Mask,ShapeSet ); | |
1136 XFreePixmap( wsDisplay,win->Mask ); | |
1137 } | |
1138 else XShapeCombineMask( wsDisplay,win->WindowID,ShapeBounding,0,0,None,ShapeSet ); | |
1693 | 1139 #endif |
1140 } | |
1141 | |
1142 #include "wsmkeys.h" |