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