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