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