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