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