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