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