]> git.sesse.net Git - vlc/blob - plugins/x11/vout_x11.c
* Fixed the BeOS compile typo.
[vlc] / plugins / x11 / vout_x11.c
1 /*****************************************************************************
2  * vout_x11.c: X11 video output display method
3  *****************************************************************************
4  * Copyright (C) 1998, 1999, 2000 VideoLAN
5  * $Id: vout_x11.c,v 1.26 2001/05/30 17:03:12 sam Exp $
6  *
7  * Authors: Vincent Seguin <seguin@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          David Kennedy <dkennedy@tinytoad.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 #define MODULE_NAME x11
27 #include "modules_inner.h"
28
29 /*****************************************************************************
30  * Preamble
31  *****************************************************************************/
32 #include "defs.h"
33
34 #include <errno.h>                                                 /* ENOMEM */
35 #include <stdlib.h>                                                /* free() */
36 #include <string.h>                                            /* strerror() */
37
38 #ifdef HAVE_MACHINE_PARAM_H
39 /* BSD */
40 #include <machine/param.h>
41 #include <sys/types.h>                                     /* typedef ushort */
42 #include <sys/ipc.h>
43 #endif
44
45 #ifndef WIN32
46 #include <netinet/in.h>                               /* BSD: struct in_addr */
47 #endif
48
49 #include <sys/shm.h>                                   /* shmget(), shmctl() */
50 #include <X11/Xlib.h>
51 #include <X11/Xutil.h>
52 #include <X11/keysym.h>
53 #include <X11/extensions/XShm.h>
54
55 #include "config.h"
56 #include "common.h"
57 #include "threads.h"
58 #include "mtime.h"
59 #include "tests.h"
60
61 #include "video.h"
62 #include "video_output.h"
63
64 #include "interface.h"
65 #include "intf_msg.h"
66
67 #include "netutils.h"                                 /* network_ChannelJoin */
68
69 #include "main.h"
70
71 #include "modules.h"
72 #include "modules_export.h"
73
74 /*****************************************************************************
75  * vout_sys_t: video output X11 method descriptor
76  *****************************************************************************
77  * This structure is part of the video output thread descriptor.
78  * It describes the X11 specific properties of an output thread. X11 video
79  * output is performed through regular resizable windows. Windows can be
80  * dynamically resized to adapt to the size of the streams.
81  *****************************************************************************/
82 typedef struct vout_sys_s
83 {
84     /* User settings */
85     boolean_t           b_shm;               /* shared memory extension flag */
86
87     /* Internal settings and properties */
88     Display *           p_display;                        /* display pointer */
89     Visual *            p_visual;                          /* visual pointer */
90     int                 i_screen;                           /* screen number */
91     Window              window;                               /* root window */
92     GC                  gc;              /* graphic context instance handler */
93     Colormap            colormap;               /* colormap used (8bpp only) */
94
95     /* Display buffers and shared memory information */
96     XImage *            p_ximage[2];                       /* XImage pointer */
97     XShmSegmentInfo     shm_info[2];       /* shared memory zone information */
98
99     /* X11 generic properties */
100     Atom                wm_protocols;
101     Atom                wm_delete_window;
102
103     int                 i_width;                     /* width of main window */
104     int                 i_height;                   /* height of main window */
105
106     /* Screen saver properties */
107     int                 i_ss_timeout;                             /* timeout */
108     int                 i_ss_interval;           /* interval between changes */
109     int                 i_ss_blanking;                      /* blanking mode */
110     int                 i_ss_exposure;                      /* exposure mode */
111
112     /* Auto-hide cursor */
113     mtime_t     i_lastmoved;
114     
115     /* Mouse pointer properties */
116     boolean_t           b_mouse;         /* is the mouse pointer displayed ? */
117
118 } vout_sys_t;
119
120 /* Fullscreen needs to be able to hide the wm decorations */
121 #define MWM_HINTS_DECORATIONS   (1L << 1)
122 #define PROP_MWM_HINTS_ELEMENTS 5
123 typedef struct mwmhints_s
124 {
125     u32 flags;
126     u32 functions;
127     u32 decorations;
128     s32 input_mode;
129     u32 status;
130 } mwmhints_t;
131
132 /*****************************************************************************
133  * Local prototypes
134  *****************************************************************************/
135 static int  vout_Probe     ( probedata_t *p_data );
136 static int  vout_Create    ( struct vout_thread_s * );
137 static int  vout_Init      ( struct vout_thread_s * );
138 static void vout_End       ( struct vout_thread_s * );
139 static void vout_Destroy   ( struct vout_thread_s * );
140 static int  vout_Manage    ( struct vout_thread_s * );
141 static void vout_Display   ( struct vout_thread_s * );
142 static void vout_SetPalette( struct vout_thread_s *, u16*, u16*, u16*, u16* );
143
144 static int  X11CreateWindow     ( vout_thread_t *p_vout );
145 static int  X11InitDisplay      ( vout_thread_t *p_vout, char *psz_display );
146
147 static int  X11CreateImage      ( vout_thread_t *p_vout, XImage **pp_ximage );
148 static void X11DestroyImage     ( XImage *p_ximage );
149 static int  X11CreateShmImage   ( vout_thread_t *p_vout, XImage **pp_ximage,
150                                   XShmSegmentInfo *p_shm_info );
151 static void X11DestroyShmImage  ( vout_thread_t *p_vout, XImage *p_ximage,
152                                   XShmSegmentInfo *p_shm_info );
153
154 static void X11TogglePointer            ( vout_thread_t *p_vout );
155 static void X11EnableScreenSaver        ( vout_thread_t *p_vout );
156 static void X11DisableScreenSaver       ( vout_thread_t *p_vout );
157
158 /*****************************************************************************
159  * Functions exported as capabilities. They are declared as static so that
160  * we don't pollute the namespace too much.
161  *****************************************************************************/
162 void _M( vout_getfunctions )( function_list_t * p_function_list )
163 {
164     p_function_list->pf_probe = vout_Probe;
165     p_function_list->functions.vout.pf_create     = vout_Create;
166     p_function_list->functions.vout.pf_init       = vout_Init;
167     p_function_list->functions.vout.pf_end        = vout_End;
168     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
169     p_function_list->functions.vout.pf_manage     = vout_Manage;
170     p_function_list->functions.vout.pf_display    = vout_Display;
171     p_function_list->functions.vout.pf_setpalette = vout_SetPalette;
172 }
173
174 /*****************************************************************************
175  * vout_Probe: probe the video driver and return a score
176  *****************************************************************************
177  * This function tries to initialize SDL and returns a score to the
178  * plugin manager so that it can select the best plugin.
179  *****************************************************************************/
180 static int vout_Probe( probedata_t *p_data )
181 {
182     if( TestMethod( VOUT_METHOD_VAR, "x11" ) )
183     {
184         return( 999 );
185     }
186
187     return( 50 );
188 }
189
190 /*****************************************************************************
191  * vout_Create: allocate X11 video thread output method
192  *****************************************************************************
193  * This function allocate and initialize a X11 vout method. It uses some of the
194  * vout properties to choose the window size, and change them according to the
195  * actual properties of the display.
196  *****************************************************************************/
197 static int vout_Create( vout_thread_t *p_vout )
198 {
199     char *psz_display;
200
201     /* Allocate structure */
202     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
203     if( p_vout->p_sys == NULL )
204     {
205         intf_ErrMsg( "vout error: %s", strerror(ENOMEM) );
206         return( 1 );
207     }
208
209     /* Open display, unsing 'vlc_display' or DISPLAY environment variable */
210     psz_display = XDisplayName( main_GetPszVariable( VOUT_DISPLAY_VAR, NULL ) );
211     p_vout->p_sys->p_display = XOpenDisplay( psz_display );
212
213     if( p_vout->p_sys->p_display == NULL )                          /* error */
214     {
215         intf_ErrMsg( "vout error: cannot open display %s", psz_display );
216         free( p_vout->p_sys );
217         return( 1 );
218     }
219     p_vout->p_sys->i_screen = DefaultScreen( p_vout->p_sys->p_display );
220
221     p_vout->b_fullscreen
222         = main_GetIntVariable( VOUT_FULLSCREEN_VAR, VOUT_FULLSCREEN_DEFAULT );
223
224     /* Spawn base window - this window will include the video output window,
225      * but also command buttons, subtitles and other indicators */
226
227     if( X11CreateWindow( p_vout ) )
228     {
229         intf_ErrMsg( "vout error: cannot create X11 window" );
230         XCloseDisplay( p_vout->p_sys->p_display );
231         free( p_vout->p_sys );
232         return( 1 );
233     }
234
235     /* Open and initialize device. This function issues its own error messages.
236      * Since XLib is usually not thread-safe, we can't use the same display
237      * pointer than the interface or another thread. However, the root window
238      * id is still valid. */
239     if( X11InitDisplay( p_vout, psz_display ) )
240     {
241         intf_ErrMsg( "vout error: cannot initialize X11 display" );
242         XCloseDisplay( p_vout->p_sys->p_display );
243         free( p_vout->p_sys );
244         return( 1 );
245     }
246
247     p_vout->p_sys->b_mouse = 1;
248
249     /* Disable screen saver and return */
250     X11DisableScreenSaver( p_vout );
251
252     return( 0 );
253 }
254
255 /*****************************************************************************
256  * vout_Init: initialize X11 video thread output method
257  *****************************************************************************
258  * This function create the XImages needed by the output thread. It is called
259  * at the beginning of the thread, but also each time the window is resized.
260  *****************************************************************************/
261 static int vout_Init( vout_thread_t *p_vout )
262 {
263     int i_err;
264
265 #ifdef SYS_DARWIN1_3
266     /* FIXME : As of 2001-03-16, XFree4 for MacOS X does not support Xshm. */
267     p_vout->p_sys->b_shm = 0;
268 #endif
269
270     /* Create XImages using XShm extension - on failure, fall back to regular
271      * way (and destroy the first image if it was created successfully) */
272     if( p_vout->p_sys->b_shm )
273     {
274         /* Create first image */
275         i_err = X11CreateShmImage( p_vout, &p_vout->p_sys->p_ximage[0],
276                                    &p_vout->p_sys->shm_info[0] );
277         if( !i_err )                         /* first image has been created */
278         {
279             /* Create second image */
280             if( X11CreateShmImage( p_vout, &p_vout->p_sys->p_ximage[1],
281                                    &p_vout->p_sys->shm_info[1] ) )
282             {                             /* error creating the second image */
283                 X11DestroyShmImage( p_vout, p_vout->p_sys->p_ximage[0],
284                                     &p_vout->p_sys->shm_info[0] );
285                 i_err = 1;
286             }
287         }
288         if( i_err )                                      /* an error occured */
289         {
290             intf_Msg( "vout: XShm video extension unavailable" );
291             p_vout->p_sys->b_shm = 0;
292         }
293     }
294
295     /* Create XImages without XShm extension */
296     if( !p_vout->p_sys->b_shm )
297     {
298         if( X11CreateImage( p_vout, &p_vout->p_sys->p_ximage[0] ) )
299         {
300             intf_ErrMsg( "vout error: cannot create images" );
301             p_vout->p_sys->p_ximage[0] = NULL;
302             p_vout->p_sys->p_ximage[1] = NULL;
303             return( 1 );
304         }
305         if( X11CreateImage( p_vout, &p_vout->p_sys->p_ximage[1] ) )
306         {
307             intf_ErrMsg( "vout error: cannot create images" );
308             X11DestroyImage( p_vout->p_sys->p_ximage[0] );
309             p_vout->p_sys->p_ximage[0] = NULL;
310             p_vout->p_sys->p_ximage[1] = NULL;
311             return( 1 );
312         }
313     }
314
315     /* Set bytes per line and initialize buffers */
316     p_vout->i_bytes_per_line = p_vout->p_sys->p_ximage[0]->bytes_per_line;
317     p_vout->pf_setbuffers( p_vout, p_vout->p_sys->p_ximage[ 0 ]->data,
318                                    p_vout->p_sys->p_ximage[ 1 ]->data );
319
320     /* Set date for autohiding cursor */
321     p_vout->p_sys->i_lastmoved = mdate();
322     
323     return( 0 );
324 }
325
326 /*****************************************************************************
327  * vout_End: terminate X11 video thread output method
328  *****************************************************************************
329  * Destroy the X11 XImages created by vout_Init. It is called at the end of
330  * the thread, but also each time the window is resized.
331  *****************************************************************************/
332 static void vout_End( vout_thread_t *p_vout )
333 {
334     if( p_vout->p_sys->b_shm )                             /* Shm XImages... */
335     {
336         X11DestroyShmImage( p_vout, p_vout->p_sys->p_ximage[0],
337                             &p_vout->p_sys->shm_info[0] );
338         X11DestroyShmImage( p_vout, p_vout->p_sys->p_ximage[1],
339                             &p_vout->p_sys->shm_info[1] );
340     }
341     else                                          /* ...or regular XImages */
342     {
343         X11DestroyImage( p_vout->p_sys->p_ximage[0] );
344         X11DestroyImage( p_vout->p_sys->p_ximage[1] );
345     }
346 }
347
348 /*****************************************************************************
349  * vout_Destroy: destroy X11 video thread output method
350  *****************************************************************************
351  * Terminate an output method created by vout_CreateOutputMethod
352  *****************************************************************************/
353 static void vout_Destroy( vout_thread_t *p_vout )
354 {
355     /* Enable screen saver */
356     X11EnableScreenSaver( p_vout );
357
358     /* Destroy colormap */
359     if( p_vout->i_screen_depth == 8 )
360     {
361         XFreeColormap( p_vout->p_sys->p_display, p_vout->p_sys->colormap );
362     }
363
364     /* Destroy window */
365     XUnmapWindow( p_vout->p_sys->p_display, p_vout->p_sys->window );
366     XFreeGC( p_vout->p_sys->p_display, p_vout->p_sys->gc );
367     XDestroyWindow( p_vout->p_sys->p_display, p_vout->p_sys->window );
368
369     XCloseDisplay( p_vout->p_sys->p_display );
370
371     /* Destroy structure */
372     free( p_vout->p_sys );
373 }
374
375 /*****************************************************************************
376  * vout_Manage: handle X11 events
377  *****************************************************************************
378  * This function should be called regularly by video output thread. It manages
379  * X11 events and allows window resizing. It returns a non null value on
380  * error.
381  *****************************************************************************/
382 static int vout_Manage( vout_thread_t *p_vout )
383 {
384     XEvent      xevent;                                         /* X11 event */
385     boolean_t   b_resized;                        /* window has been resized */
386     char        i_key;                                    /* ISO Latin-1 key */
387     KeySym      x_key_symbol;
388
389     /* Handle X11 events: ConfigureNotify events are parsed to know if the
390      * output window's size changed, MapNotify and UnmapNotify to know if the
391      * window is mapped (and if the display is useful), and ClientMessages
392      * to intercept window destruction requests */
393
394     b_resized = 0;
395     while( XCheckWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
396                               StructureNotifyMask | KeyPressMask |
397                               ButtonPressMask | ButtonReleaseMask | 
398                               PointerMotionMask | Button1MotionMask , &xevent )
399            == True )
400     {
401         /* ConfigureNotify event: prepare  */
402         if( (xevent.type == ConfigureNotify)
403             && ((xevent.xconfigure.width != p_vout->p_sys->i_width)
404                 || (xevent.xconfigure.height != p_vout->p_sys->i_height)) )
405         {
406             /* Update dimensions */
407             b_resized = 1;
408             p_vout->p_sys->i_width = xevent.xconfigure.width;
409             p_vout->p_sys->i_height = xevent.xconfigure.height;
410         }
411         /* MapNotify event: change window status and disable screen saver */
412         else if( xevent.type == MapNotify)
413         {
414             if( (p_vout != NULL) && !p_vout->b_active )
415             {
416                 X11DisableScreenSaver( p_vout );
417                 p_vout->b_active = 1;
418             }
419         }
420         /* UnmapNotify event: change window status and enable screen saver */
421         else if( xevent.type == UnmapNotify )
422         {
423             if( (p_vout != NULL) && p_vout->b_active )
424             {
425                 X11EnableScreenSaver( p_vout );
426                 p_vout->b_active = 0;
427             }
428         }
429         /* Keyboard event */
430         else if( xevent.type == KeyPress )
431         {
432             /* We may have keys like F1 trough F12, ESC ... */
433             x_key_symbol = XKeycodeToKeysym( p_vout->p_sys->p_display,
434                                              xevent.xkey.keycode, 0 );
435             switch( x_key_symbol )
436             {
437                  case XK_Escape:
438                      p_main->p_intf->b_die = 1;
439                      break;
440                  case XK_Menu:
441                      p_main->p_intf->b_menu_change = 1;
442                      break;
443                  default:
444                      /* "Normal Keys"
445                       * The reason why I use this instead of XK_0 is that 
446                       * with XLookupString, we don't have to care about
447                       * keymaps. */
448
449                     if( XLookupString( &xevent.xkey, &i_key, 1, NULL, NULL ) )
450                     {
451                         /* FIXME: handle stuff here */
452                         switch( i_key )
453                         {
454                         case 'q':
455                         case 'Q':
456                             p_main->p_intf->b_die = 1;
457                             break;
458                         case 'f':
459                         case 'F':
460                             p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
461                             break;
462                         case '0':
463                             network_ChannelJoin( 0 );
464                             break;
465                         case '1':
466                             network_ChannelJoin( 1 );
467                             break;
468                         case '2':
469                             network_ChannelJoin( 2 );
470                             break;
471                         case '3':
472                             network_ChannelJoin( 3 );
473                             break;
474                         case '4':
475                             network_ChannelJoin( 4 );
476                             break;
477                         case '5':
478                             network_ChannelJoin( 5 );
479                             break;
480                         case '6':
481                             network_ChannelJoin( 6 );
482                             break;
483                         case '7':
484                             network_ChannelJoin( 7 );
485                             break;
486                         case '8':
487                             network_ChannelJoin( 8 );
488                             break;
489                         case '9':
490                             network_ChannelJoin( 9 );
491                             break;
492                         default:
493                             if( intf_ProcessKey( p_main->p_intf, 
494                                                  (char )i_key ) )
495                             {
496                                intf_DbgMsg( "vout: unhandled key '%c' (%i)", 
497                                             (char)i_key, i_key );
498                             }
499                             break;
500                         }
501                     }
502                 break;
503             }
504         }
505         /* Mouse click */
506         else if( xevent.type == ButtonPress )
507         {
508             switch( ((XButtonEvent *)&xevent)->button )
509             {
510                 case Button1:
511                     /* in this part we will eventually manage
512                      * clicks for DVD navigation for instance */
513                     break;
514             }
515         }
516         /* Mouse release */
517         else if( xevent.type == ButtonRelease )
518         {
519             switch( ((XButtonEvent *)&xevent)->button )
520             {
521                 case Button3:
522                     /* FIXME: need locking ! */
523                     p_main->p_intf->b_menu_change = 1;
524                     break;
525             }
526         }
527         /* Mouse move */
528         else if( xevent.type == MotionNotify )
529         {
530             p_vout->p_sys->i_lastmoved = mdate();
531             if( ! p_vout->p_sys->b_mouse )
532             {
533                 X11TogglePointer( p_vout ); 
534             }
535         }
536         /* Other event */
537         else
538         {
539             intf_WarnMsg( 3, "vout: unhandled event %d received", xevent.type );
540         }
541     }
542
543     /* ClientMessage event - only WM_PROTOCOLS with WM_DELETE_WINDOW data
544      * are handled - according to the man pages, the format is always 32
545      * in this case */
546     while( XCheckTypedEvent( p_vout->p_sys->p_display,
547                              ClientMessage, &xevent ) )
548     {
549         if( (xevent.xclient.message_type == p_vout->p_sys->wm_protocols)
550             && (xevent.xclient.data.l[0] == p_vout->p_sys->wm_delete_window ) )
551         {
552             p_main->p_intf->b_die = 1;
553         }
554         else
555         {
556             intf_DbgMsg( "vout: unhandled ClientMessage received" );
557         }
558     }
559
560     if ( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
561     {
562         char *psz_display;
563         /* Open display, unsing 'vlc_display' or the DISPLAY
564          * environment variable */
565         psz_display = XDisplayName( main_GetPszVariable( VOUT_DISPLAY_VAR, NULL ) );
566
567         intf_DbgMsg( "vout: changing full-screen status" );
568
569         p_vout->b_fullscreen = !p_vout->b_fullscreen;
570         p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
571
572         /* Get rid of the old window */
573         XUnmapWindow( p_vout->p_sys->p_display, p_vout->p_sys->window );
574         XFreeGC( p_vout->p_sys->p_display, p_vout->p_sys->gc );
575
576         /* And create a new one */
577         if( X11CreateWindow( p_vout ) )
578         {
579             intf_ErrMsg( "vout error: cannot create X11 window" );
580             XCloseDisplay( p_vout->p_sys->p_display );
581
582             free( p_vout->p_sys );
583             return( 1 );
584         }
585
586         if( X11InitDisplay( p_vout, psz_display ) )
587         {
588             intf_ErrMsg( "vout error: cannot initialize X11 display" );
589             XCloseDisplay( p_vout->p_sys->p_display );
590             free( p_vout->p_sys );
591             return( 1 );
592         }
593         /* We've changed the size, update it */
594         p_vout->i_changes |= VOUT_SIZE_CHANGE;
595     }
596
597     /*
598      * Handle vout window resizing
599      */
600     if( b_resized )
601     {
602         /* If interface window has been resized, change vout size */
603         intf_DbgMsg( "vout: resizing output window" );
604         p_vout->i_width =  p_vout->p_sys->i_width;
605         p_vout->i_height = p_vout->p_sys->i_height;
606         p_vout->i_changes |= VOUT_SIZE_CHANGE;
607     }
608     else if( (p_vout->i_width  != p_vout->p_sys->i_width) ||
609              (p_vout->i_height != p_vout->p_sys->i_height) )
610     {
611         /* If video output size has changed, change interface window size */
612         intf_DbgMsg( "vout: resizing output window" );
613         p_vout->p_sys->i_width =    p_vout->i_width;
614         p_vout->p_sys->i_height =   p_vout->i_height;
615         XResizeWindow( p_vout->p_sys->p_display, p_vout->p_sys->window,
616                        p_vout->p_sys->i_width, p_vout->p_sys->i_height );
617     }
618     /*
619      * Color/Grayscale or gamma change: in 8bpp, just change the colormap
620      */
621     if( (p_vout->i_changes & VOUT_GRAYSCALE_CHANGE)
622         && (p_vout->i_screen_depth == 8) )
623     {
624         /* FIXME: clear flags ?? */
625     }
626
627     /*
628      * Size change
629      */
630     if( p_vout->i_changes & VOUT_SIZE_CHANGE )
631     {
632         intf_DbgMsg( "vout info: resizing window" );
633         p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
634
635         /* Resize window */
636         XResizeWindow( p_vout->p_sys->p_display, p_vout->p_sys->window,
637                        p_vout->i_width, p_vout->i_height );
638
639         /* Destroy XImages to change their size */
640         vout_End( p_vout );
641
642         /* Recreate XImages. If SysInit failed, the thread can't go on. */
643         if( vout_Init( p_vout ) )
644         {
645             intf_ErrMsg( "vout error: cannot resize display" );
646             return( 1 );
647        }
648
649         /* Tell the video output thread that it will need to rebuild YUV
650          * tables. This is needed since conversion buffer size may have
651          * changed */
652         p_vout->i_changes |= VOUT_YUV_CHANGE;
653         intf_Msg( "vout: video display resized (%dx%d)",
654                   p_vout->i_width, p_vout->i_height);
655     }
656
657     /* Autohide Cursour */
658     if( mdate() - p_vout->p_sys->i_lastmoved > 2000000 )
659     {
660         /* Hide the mouse automatically */
661         if( p_vout->p_sys->b_mouse )
662         {
663             X11TogglePointer( p_vout ); 
664         }
665     }
666
667     
668     return 0;
669 }
670
671 /*****************************************************************************
672  * vout_Display: displays previously rendered output
673  *****************************************************************************
674  * This function send the currently rendered image to X11 server, wait until
675  * it is displayed and switch the two rendering buffer, preparing next frame.
676  *****************************************************************************/
677 static void vout_Display( vout_thread_t *p_vout )
678 {
679     if( p_vout->p_sys->b_shm)                                /* XShm is used */
680     {
681         /* Display rendered image using shared memory extension */
682         XShmPutImage(p_vout->p_sys->p_display, p_vout->p_sys->window, p_vout->p_sys->gc,
683                      p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ],
684                      0, 0, 0, 0,
685                      p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ]->width,
686                      p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ]->height, True);
687
688         /* Send the order to the X server */
689         XSync(p_vout->p_sys->p_display, False);
690     }
691     else                                /* regular X11 capabilities are used */
692     {
693         XPutImage(p_vout->p_sys->p_display, p_vout->p_sys->window, p_vout->p_sys->gc,
694                   p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ],
695                   0, 0, 0, 0,
696                   p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ]->width,
697                   p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ]->height);
698
699         /* Send the order to the X server */
700         XSync(p_vout->p_sys->p_display, False);
701     }
702 }
703
704 /*****************************************************************************
705  * vout_SetPalette: sets an 8 bpp palette
706  *****************************************************************************
707  * This function sets the palette given as an argument. It does not return
708  * anything, but could later send information on which colors it was unable
709  * to set.
710  *****************************************************************************/
711 static void vout_SetPalette( p_vout_thread_t p_vout,
712                              u16 *red, u16 *green, u16 *blue, u16 *transp )
713 {
714     int i, j;
715     XColor p_colors[255];
716
717     intf_DbgMsg( "vout: Palette change called" );
718
719     /* allocate palette */
720     for( i = 0, j = 255; i < 255; i++, j-- )
721     {
722         /* kludge: colors are indexed reversely because color 255 seems
723          * to be reserved for black even if we try to set it to white */
724         p_colors[ i ].pixel = j;
725         p_colors[ i ].pad   = 0;
726         p_colors[ i ].flags = DoRed | DoGreen | DoBlue;
727         p_colors[ i ].red   = red[ j ];
728         p_colors[ i ].blue  = blue[ j ];
729         p_colors[ i ].green = green[ j ];
730     }
731
732     XStoreColors( p_vout->p_sys->p_display,
733                   p_vout->p_sys->colormap, p_colors, 256 );
734 }
735
736 /* following functions are local */
737
738 /*****************************************************************************
739  * X11CreateWindow: open and set-up X11 main window
740  *****************************************************************************/
741 static int X11CreateWindow( vout_thread_t *p_vout )
742 {
743     XSizeHints              xsize_hints;
744     XSetWindowAttributes    xwindow_attributes;
745     XGCValues               xgcvalues;
746     XEvent                  xevent;
747     Atom                    prop;
748     mwmhints_t              mwmhints;
749
750     boolean_t               b_expose;
751     boolean_t               b_configure_notify;
752     boolean_t               b_map_notify;
753
754     /* If we're full screen, we're full screen! */
755     if( p_vout->b_fullscreen ) 
756     {
757         p_vout->p_sys->i_width = DisplayWidth( p_vout->p_sys->p_display, 
758                                                p_vout->p_sys->i_screen );
759         p_vout->p_sys->i_height =  DisplayHeight( p_vout->p_sys->p_display, 
760                                                   p_vout->p_sys->i_screen ); 
761         p_vout->i_width =  p_vout->p_sys->i_width;
762         p_vout->i_height = p_vout->p_sys->i_height;
763     }
764     else
765     {
766         /* Set main window's size */
767         p_vout->p_sys->i_width =  main_GetIntVariable( VOUT_WIDTH_VAR,
768                                                        VOUT_WIDTH_DEFAULT );
769         p_vout->p_sys->i_height = main_GetIntVariable( VOUT_HEIGHT_VAR,
770                                                        VOUT_HEIGHT_DEFAULT );
771         p_vout->i_width =  p_vout->p_sys->i_width;
772         p_vout->i_height = p_vout->p_sys->i_height;
773     }
774
775     /* Prepare window manager hints and properties */
776     xsize_hints.base_width          = p_vout->p_sys->i_width;
777     xsize_hints.base_height         = p_vout->p_sys->i_height;
778     xsize_hints.flags               = PSize;
779     p_vout->p_sys->wm_protocols     = XInternAtom( p_vout->p_sys->p_display,
780                                                    "WM_PROTOCOLS", True );
781     p_vout->p_sys->wm_delete_window = XInternAtom( p_vout->p_sys->p_display,
782                                                    "WM_DELETE_WINDOW", True );
783
784     /* Prepare window attributes */
785     xwindow_attributes.backing_store = Always;       /* save the hidden part */
786     xwindow_attributes.background_pixel = BlackPixel( p_vout->p_sys->p_display,
787                                                       p_vout->p_sys->i_screen );
788     xwindow_attributes.event_mask = ExposureMask | StructureNotifyMask;
789     
790
791     /* Create the window and set hints - the window must receive ConfigureNotify
792      * events, and, until it is displayed, Expose and MapNotify events. */
793
794     p_vout->p_sys->window =
795         XCreateWindow( p_vout->p_sys->p_display,
796                        DefaultRootWindow( p_vout->p_sys->p_display ),
797                        0, 0,
798                        p_vout->p_sys->i_width, p_vout->p_sys->i_height, 0,
799                        0, InputOutput, 0,
800                        CWBackingStore | CWBackPixel | CWEventMask,
801                        &xwindow_attributes );
802
803     if ( p_vout->b_fullscreen )
804     {
805         prop = XInternAtom(p_vout->p_sys->p_display, "_MOTIF_WM_HINTS", False);
806         mwmhints.flags = MWM_HINTS_DECORATIONS;
807         mwmhints.decorations = 0;
808         XChangeProperty( p_vout->p_sys->p_display, p_vout->p_sys->window,
809                          prop, prop, 32, PropModeReplace,
810                          (unsigned char *)&mwmhints, PROP_MWM_HINTS_ELEMENTS );
811
812         XSetTransientForHint( p_vout->p_sys->p_display,
813                               p_vout->p_sys->window, None );
814         XRaiseWindow( p_vout->p_sys->p_display, p_vout->p_sys->window );
815     }
816
817     /* Set window manager hints and properties: size hints, command,
818      * window's name, and accepted protocols */
819     XSetWMNormalHints( p_vout->p_sys->p_display, p_vout->p_sys->window,
820                        &xsize_hints );
821     XSetCommand( p_vout->p_sys->p_display, p_vout->p_sys->window,
822                  p_main->ppsz_argv, p_main->i_argc );
823     XStoreName( p_vout->p_sys->p_display, p_vout->p_sys->window,
824                 VOUT_TITLE " (X11 output)" );
825
826     if( (p_vout->p_sys->wm_protocols == None)        /* use WM_DELETE_WINDOW */
827         || (p_vout->p_sys->wm_delete_window == None)
828         || !XSetWMProtocols( p_vout->p_sys->p_display, p_vout->p_sys->window,
829                              &p_vout->p_sys->wm_delete_window, 1 ) )
830     {
831         /* WM_DELETE_WINDOW is not supported by window manager */
832         intf_Msg( "vout error: missing or bad window manager" );
833     }
834
835     /* Creation of a graphic context that doesn't generate a GraphicsExpose
836      * event when using functions like XCopyArea */
837     xgcvalues.graphics_exposures = False;
838     p_vout->p_sys->gc = XCreateGC( p_vout->p_sys->p_display,
839                                    p_vout->p_sys->window,
840                                    GCGraphicsExposures, &xgcvalues);
841
842     /* Send orders to server, and wait until window is displayed - three
843      * events must be received: a MapNotify event, an Expose event allowing
844      * drawing in the window, and a ConfigureNotify to get the window
845      * dimensions. Once those events have been received, only ConfigureNotify
846      * events need to be received. */
847     b_expose = 0;
848     b_configure_notify = 0;
849     b_map_notify = 0;
850     XMapWindow( p_vout->p_sys->p_display, p_vout->p_sys->window);
851     do
852     {
853         XNextEvent( p_vout->p_sys->p_display, &xevent);
854         if( (xevent.type == Expose)
855             && (xevent.xexpose.window == p_vout->p_sys->window) )
856         {
857             b_expose = 1;
858         }
859         else if( (xevent.type == MapNotify)
860                  && (xevent.xmap.window == p_vout->p_sys->window) )
861         {
862             b_map_notify = 1;
863         }
864         else if( (xevent.type == ConfigureNotify)
865                  && (xevent.xconfigure.window == p_vout->p_sys->window) )
866         {
867             b_configure_notify = 1;
868             p_vout->p_sys->i_width = xevent.xconfigure.width;
869             p_vout->p_sys->i_height = xevent.xconfigure.height;
870         }
871     } while( !( b_expose && b_configure_notify && b_map_notify ) );
872
873     XSelectInput( p_vout->p_sys->p_display, p_vout->p_sys->window,
874                   StructureNotifyMask | KeyPressMask |
875                   ButtonPressMask | ButtonReleaseMask | 
876                   PointerMotionMask );
877
878     if( XDefaultDepth(p_vout->p_sys->p_display, p_vout->p_sys->i_screen) == 8 )
879     {
880         /* Allocate a new palette */
881         p_vout->p_sys->colormap =
882             XCreateColormap( p_vout->p_sys->p_display,
883                              DefaultRootWindow( p_vout->p_sys->p_display ),
884                              DefaultVisual( p_vout->p_sys->p_display,
885                                             p_vout->p_sys->i_screen ),
886                              AllocAll );
887
888         xwindow_attributes.colormap = p_vout->p_sys->colormap;
889         XChangeWindowAttributes( p_vout->p_sys->p_display,
890                                  p_vout->p_sys->window,
891                                  CWColormap, &xwindow_attributes );
892     }
893
894     if( p_vout->b_fullscreen )
895     {
896         XSetInputFocus( p_vout->p_sys->p_display, p_vout->p_sys->window,
897                         RevertToNone, CurrentTime );
898         XMoveWindow( p_vout->p_sys->p_display, p_vout->p_sys->window, 0, 0 );
899     }
900
901     /* At this stage, the window is open, displayed, and ready to
902      * receive data */
903
904     return( 0 );
905 }
906
907 /*****************************************************************************
908  * X11InitDisplay: open and initialize X11 device
909  *****************************************************************************
910  * Create a window according to video output given size, and set other
911  * properties according to the display properties.
912  *****************************************************************************/
913 static int X11InitDisplay( vout_thread_t *p_vout, char *psz_display )
914 {
915     XPixmapFormatValues *       p_formats;                 /* pixmap formats */
916     XVisualInfo *               p_xvisual;           /* visuals informations */
917     XVisualInfo                 xvisual_template;         /* visual template */
918     int                         i_count;                       /* array size */
919
920
921
922     /* Initialize structure */
923     p_vout->p_sys->i_screen = DefaultScreen( p_vout->p_sys->p_display );
924     p_vout->p_sys->b_shm    = ( XShmQueryExtension( p_vout->p_sys->p_display )
925                                  == True );
926     if( !p_vout->p_sys->b_shm )
927     {
928         intf_Msg( "vout: XShm video extension is not available" );
929     }
930
931     /* Get screen depth */
932     p_vout->i_screen_depth = XDefaultDepth( p_vout->p_sys->p_display,
933                                             p_vout->p_sys->i_screen );
934     switch( p_vout->i_screen_depth )
935     {
936     case 8:
937         /*
938          * Screen depth is 8bpp. Use PseudoColor visual with private colormap.
939          */
940         xvisual_template.screen =   p_vout->p_sys->i_screen;
941         xvisual_template.class =    DirectColor;
942         p_xvisual = XGetVisualInfo( p_vout->p_sys->p_display,
943                                     VisualScreenMask | VisualClassMask,
944                                     &xvisual_template, &i_count );
945         if( p_xvisual == NULL )
946         {
947             intf_ErrMsg( "vout error: no PseudoColor visual available" );
948             return( 1 );
949         }
950         p_vout->i_bytes_per_pixel = 1;
951         break;
952     case 15:
953     case 16:
954     case 24:
955     default:
956         /*
957          * Screen depth is higher than 8bpp. TrueColor visual is used.
958          */
959         xvisual_template.screen =   p_vout->p_sys->i_screen;
960         xvisual_template.class =    TrueColor;
961         p_xvisual = XGetVisualInfo( p_vout->p_sys->p_display,
962                                     VisualScreenMask | VisualClassMask,
963                                     &xvisual_template, &i_count );
964         if( p_xvisual == NULL )
965         {
966             intf_ErrMsg( "vout error: no TrueColor visual available" );
967             return( 1 );
968         }
969         p_vout->i_red_mask =        p_xvisual->red_mask;
970         p_vout->i_green_mask =      p_xvisual->green_mask;
971         p_vout->i_blue_mask =       p_xvisual->blue_mask;
972
973         /* There is no difference yet between 3 and 4 Bpp. The only way
974          * to find the actual number of bytes per pixel is to list supported
975          * pixmap formats. */
976         p_formats = XListPixmapFormats( p_vout->p_sys->p_display, &i_count );
977         p_vout->i_bytes_per_pixel = 0;
978
979         for( ; i_count-- ; p_formats++ )
980         {
981             /* Under XFree4.0, the list contains pixmap formats available
982              * through all video depths ; so we have to check against current
983              * depth. */
984             if( p_formats->depth == p_vout->i_screen_depth )
985             {
986                 if( p_formats->bits_per_pixel / 8
987                         > p_vout->i_bytes_per_pixel )
988                 {
989                     p_vout->i_bytes_per_pixel = p_formats->bits_per_pixel / 8;
990                 }
991             }
992         }
993         break;
994     }
995     p_vout->p_sys->p_visual = p_xvisual->visual;
996     XFree( p_xvisual );
997
998     return( 0 );
999 }
1000
1001 /*****************************************************************************
1002  * X11CreateImage: create an XImage
1003  *****************************************************************************
1004  * Create a simple XImage used as a buffer.
1005  *****************************************************************************/
1006 static int X11CreateImage( vout_thread_t *p_vout, XImage **pp_ximage )
1007 {
1008     byte_t *    pb_data;                          /* image data storage zone */
1009     int         i_quantum;                     /* XImage quantum (see below) */
1010
1011     /* Allocate memory for image */
1012     p_vout->i_bytes_per_line = p_vout->i_width * p_vout->i_bytes_per_pixel;
1013     pb_data = (byte_t *) malloc( p_vout->i_bytes_per_line * p_vout->i_height );
1014     if( !pb_data )                                                  /* error */
1015     {
1016         intf_ErrMsg( "vout error: %s", strerror(ENOMEM));
1017         return( 1 );
1018     }
1019
1020     /* Optimize the quantum of a scanline regarding its size - the quantum is
1021        a diviser of the number of bits between the start of two scanlines. */
1022     if( !(( p_vout->i_bytes_per_line ) % 32) )
1023     {
1024         i_quantum = 32;
1025     }
1026     else
1027     {
1028         if( !(( p_vout->i_bytes_per_line ) % 16) )
1029         {
1030             i_quantum = 16;
1031         }
1032         else
1033         {
1034             i_quantum = 8;
1035         }
1036     }
1037
1038     /* Create XImage */
1039     *pp_ximage = XCreateImage( p_vout->p_sys->p_display,
1040                                p_vout->p_sys->p_visual, p_vout->i_screen_depth,
1041                                ZPixmap, 0, pb_data,
1042                                p_vout->i_width, p_vout->i_height, i_quantum, 0);
1043     if(! *pp_ximage )                                               /* error */
1044     {
1045         intf_ErrMsg( "vout error: XCreateImage() failed" );
1046         free( pb_data );
1047         return( 1 );
1048     }
1049
1050     return 0;
1051 }
1052
1053 /*****************************************************************************
1054  * X11CreateShmImage: create an XImage using shared memory extension
1055  *****************************************************************************
1056  * Prepare an XImage for DisplayX11ShmImage function.
1057  * The order of the operations respects the recommandations of the mit-shm
1058  * document by J.Corbet and K.Packard. Most of the parameters were copied from
1059  * there.
1060  *****************************************************************************/
1061 static int X11CreateShmImage( vout_thread_t *p_vout, XImage **pp_ximage,
1062                               XShmSegmentInfo *p_shm_info)
1063 {
1064     /* Create XImage */
1065     *pp_ximage =
1066         XShmCreateImage( p_vout->p_sys->p_display, p_vout->p_sys->p_visual,
1067                          p_vout->i_screen_depth, ZPixmap, 0,
1068                          p_shm_info, p_vout->i_width, p_vout->i_height );
1069     if(! *pp_ximage )                                               /* error */
1070     {
1071         intf_ErrMsg( "vout error: XShmCreateImage() failed" );
1072         return( 1 );
1073     }
1074
1075     /* Allocate shared memory segment - 0777 set the access permission
1076      * rights (like umask), they are not yet supported by X servers */
1077     p_shm_info->shmid =
1078         shmget( IPC_PRIVATE, (*pp_ximage)->bytes_per_line
1079                                  * (*pp_ximage)->height, IPC_CREAT | 0777);
1080     if( p_shm_info->shmid < 0)                                      /* error */
1081     {
1082         intf_ErrMsg( "vout error: cannot allocate shared image data (%s)",
1083                     strerror(errno));
1084         XDestroyImage( *pp_ximage );
1085         return( 1 );
1086     }
1087
1088     /* Attach shared memory segment to process (read/write) */
1089     p_shm_info->shmaddr = (*pp_ximage)->data = shmat(p_shm_info->shmid, 0, 0);
1090     if(! p_shm_info->shmaddr )
1091     {                                                               /* error */
1092         intf_ErrMsg( "vout error: cannot attach shared memory (%s)",
1093                     strerror(errno));
1094         shmctl( p_shm_info->shmid, IPC_RMID, 0 );      /* free shared memory */
1095         XDestroyImage( *pp_ximage );
1096         return( 1 );
1097     }
1098
1099     /* Mark the shm segment to be removed when there will be no more
1100      * attachements, so it is automatic on process exit or after shmdt */
1101     shmctl( p_shm_info->shmid, IPC_RMID, 0 );
1102
1103     /* Attach shared memory segment to X server (read only) */
1104     p_shm_info->readOnly = True;
1105     if( XShmAttach( p_vout->p_sys->p_display, p_shm_info )
1106          == False )                                                 /* error */
1107     {
1108         intf_ErrMsg( "vout error: cannot attach shared memory to X11 server" );
1109         shmdt( p_shm_info->shmaddr );   /* detach shared memory from process
1110                                          * and automatic free */
1111         XDestroyImage( *pp_ximage );
1112         return( 1 );
1113     }
1114
1115     /* Send image to X server. This instruction is required, since having
1116      * built a Shm XImage and not using it causes an error on XCloseDisplay */
1117     XFlush( p_vout->p_sys->p_display );
1118     return( 0 );
1119 }
1120
1121 /*****************************************************************************
1122  * X11DestroyImage: destroy an XImage
1123  *****************************************************************************
1124  * Destroy XImage AND associated data. If pointer is NULL, the image won't be
1125  * destroyed (see vout_ManageOutputMethod())
1126  *****************************************************************************/
1127 static void X11DestroyImage( XImage *p_ximage )
1128 {
1129     if( p_ximage != NULL )
1130     {
1131         XDestroyImage( p_ximage );                     /* no free() required */
1132     }
1133 }
1134
1135 /*****************************************************************************
1136  * X11DestroyShmImage
1137  *****************************************************************************
1138  * Destroy XImage AND associated data. Detach shared memory segment from
1139  * server and process, then free it. If pointer is NULL, the image won't be
1140  * destroyed (see vout_ManageOutputMethod())
1141  *****************************************************************************/
1142 static void X11DestroyShmImage( vout_thread_t *p_vout, XImage *p_ximage,
1143                                 XShmSegmentInfo *p_shm_info )
1144 {
1145     /* If pointer is NULL, do nothing */
1146     if( p_ximage == NULL )
1147     {
1148         return;
1149     }
1150
1151     XShmDetach( p_vout->p_sys->p_display, p_shm_info );/* detach from server */
1152     XDestroyImage( p_ximage );
1153
1154     if( shmdt( p_shm_info->shmaddr ) )  /* detach shared memory from process */
1155     {                                   /* also automatic freeing...         */
1156         intf_ErrMsg( "vout error: cannot detach shared memory (%s)",
1157                      strerror(errno) );
1158     }
1159 }
1160
1161
1162 /* WAZAAAAAAAAAAA */
1163
1164 /*****************************************************************************
1165  * X11EnableScreenSaver: enable screen saver
1166  *****************************************************************************
1167  * This function enable the screen saver on a display after it had been
1168  * disabled by XDisableScreenSaver. Both functions use a counter mechanism to
1169  * know wether the screen saver can be activated or not: if n successive calls
1170  * are made to XDisableScreenSaver, n successive calls to XEnableScreenSaver
1171  * will be required before the screen saver could effectively be activated.
1172  *****************************************************************************/
1173 void X11EnableScreenSaver( vout_thread_t *p_vout )
1174 {
1175     intf_DbgMsg( "vout: enabling screen saver" );
1176     XSetScreenSaver( p_vout->p_sys->p_display, p_vout->p_sys->i_ss_timeout,
1177                      p_vout->p_sys->i_ss_interval,
1178                      p_vout->p_sys->i_ss_blanking,
1179                      p_vout->p_sys->i_ss_exposure );
1180 }
1181
1182 /*****************************************************************************
1183  * X11DisableScreenSaver: disable screen saver
1184  *****************************************************************************
1185  * See XEnableScreenSaver
1186  *****************************************************************************/
1187 void X11DisableScreenSaver( vout_thread_t *p_vout )
1188 {
1189     /* Save screen saver informations */
1190     XGetScreenSaver( p_vout->p_sys->p_display, &p_vout->p_sys->i_ss_timeout,
1191                      &p_vout->p_sys->i_ss_interval,
1192                      &p_vout->p_sys->i_ss_blanking,
1193                      &p_vout->p_sys->i_ss_exposure );
1194
1195     /* Disable screen saver */
1196     intf_DbgMsg( "vout: disabling screen saver" );
1197     XSetScreenSaver( p_vout->p_sys->p_display, 0,
1198                      p_vout->p_sys->i_ss_interval,
1199                      p_vout->p_sys->i_ss_blanking,
1200                      p_vout->p_sys->i_ss_exposure );
1201 }
1202
1203 /*****************************************************************************
1204  * X11TogglePointer: hide or show the mouse pointer
1205  *****************************************************************************
1206  * This function hides the X pointer if it is visible by putting it at
1207  * coordinates (32,32) and setting the pointer sprite to a blank one. To
1208  * show it again, we disable the sprite and restore the original coordinates.
1209  *****************************************************************************/
1210 void X11TogglePointer( vout_thread_t *p_vout )
1211 {
1212     static Cursor cursor;
1213     static boolean_t b_cursor = 0;
1214
1215     if( p_vout->p_sys->b_mouse )
1216     {
1217         p_vout->p_sys->b_mouse = 0;
1218
1219         if( !b_cursor )
1220         {
1221             XColor color;
1222             Pixmap blank = XCreatePixmap( p_vout->p_sys->p_display,
1223                                DefaultRootWindow(p_vout->p_sys->p_display),
1224                                1, 1, 1 );
1225
1226             XParseColor( p_vout->p_sys->p_display,
1227                          XCreateColormap( p_vout->p_sys->p_display,
1228                                           DefaultRootWindow(
1229                                                   p_vout->p_sys->p_display ),
1230                                           DefaultVisual(
1231                                                   p_vout->p_sys->p_display,
1232                                                   p_vout->p_sys->i_screen ),
1233                                           AllocNone ),
1234                          "black", &color );
1235
1236             cursor = XCreatePixmapCursor( p_vout->p_sys->p_display,
1237                            blank, blank, &color, &color, 1, 1 );
1238
1239             b_cursor = 1;
1240         }
1241         XDefineCursor( p_vout->p_sys->p_display,
1242                        p_vout->p_sys->window, cursor );
1243     }
1244     else
1245     {
1246         p_vout->p_sys->b_mouse = 1;
1247
1248         XUndefineCursor( p_vout->p_sys->p_display, p_vout->p_sys->window );
1249     }
1250 }
1251