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