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