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