]> git.sesse.net Git - vlc/blob - plugins/x11/vout_x11.c
* Coding style fixes here and there.
[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.22 2001/04/28 03:36:25 sam Exp $
6  *
7  * Authors: Vincent Seguin <seguin@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          David Kennedy <dkennedy@tinytoad.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 #define MODULE_NAME x11
27 #include "modules_inner.h"
28
29 /*****************************************************************************
30  * Preamble
31  *****************************************************************************/
32 #include "defs.h"
33
34 #include <errno.h>                                                 /* ENOMEM */
35 #include <stdlib.h>                                                /* free() */
36 #include <string.h>                                            /* strerror() */
37
38 #ifdef HAVE_MACHINE_PARAM_H
39 /* BSD */
40 #include <machine/param.h>
41 #include <sys/types.h>                                     /* typedef ushort */
42 #include <sys/ipc.h>
43 #endif
44
45 #include <sys/shm.h>                                   /* shmget(), shmctl() */
46 #include <X11/Xlib.h>
47 #include <X11/Xutil.h>
48 #include <X11/keysym.h>
49 #include <X11/extensions/XShm.h>
50
51 #include "config.h"
52 #include "common.h"
53 #include "threads.h"
54 #include "mtime.h"
55 #include "tests.h"
56 #include "modules.h"
57
58 #include "video.h"
59 #include "video_output.h"
60
61 #include "interface.h"
62 #include "intf_msg.h"
63
64 #include "netutils.h"                                 /* network_ChannelJoin */
65
66 #include "main.h"
67
68 /*****************************************************************************
69  * vout_sys_t: video output X11 method descriptor
70  *****************************************************************************
71  * This structure is part of the video output thread descriptor.
72  * It describes the X11 specific properties of an output thread. X11 video
73  * output is performed through regular resizable windows. Windows can be
74  * dynamically resized to adapt to the size of the streams.
75  *****************************************************************************/
76 typedef struct vout_sys_s
77 {
78     /* User settings */
79     boolean_t           b_shm;               /* shared memory extension flag */
80
81     /* Internal settings and properties */
82     Display *           p_display;                        /* display pointer */
83     Visual *            p_visual;                          /* visual pointer */
84     int                 i_screen;                           /* screen number */
85     Window              window;                               /* root window */
86     GC                  gc;              /* graphic context instance handler */
87     Colormap            colormap;               /* colormap used (8bpp only) */
88
89     /* Display buffers and shared memory information */
90     XImage *            p_ximage[2];                       /* XImage pointer */
91     XShmSegmentInfo     shm_info[2];       /* shared memory zone information */
92
93     /* X11 generic properties */
94     Atom                wm_protocols;
95     Atom                wm_delete_window;
96
97     int                 i_width;                     /* width of main window */
98     int                 i_height;                   /* height of main window */
99
100     /* Screen saver properties */
101     int                 i_ss_timeout;                             /* timeout */
102     int                 i_ss_interval;           /* interval between changes */
103     int                 i_ss_blanking;                      /* blanking mode */
104     int                 i_ss_exposure;                      /* exposure mode */
105
106     /* Auto-hide cursor */
107     mtime_t     i_lastmoved;
108     
109     /* Mouse pointer properties */
110     boolean_t           b_mouse;         /* is the mouse pointer displayed ? */
111
112     /* Displaying fullscreen */
113     boolean_t           b_fullscreen;
114
115 } vout_sys_t;
116
117 /* Fullscreen needs to be able to hide the wm decorations */
118 #define MWM_HINTS_DECORATIONS   (1L << 1)
119 #define PROP_MWM_HINTS_ELEMENTS 5
120 typedef struct mwmhints_s
121 {
122     u32 flags;
123     u32 functions;
124     u32 decorations;
125     s32 input_mode;
126     u32 status;
127 } mwmhints_t;
128
129 /*****************************************************************************
130  * Local prototypes
131  *****************************************************************************/
132 static int  vout_Probe     ( probedata_t *p_data );
133 static int  vout_Create    ( struct vout_thread_s * );
134 static int  vout_Init      ( struct vout_thread_s * );
135 static void vout_End       ( struct vout_thread_s * );
136 static void vout_Destroy   ( struct vout_thread_s * );
137 static int  vout_Manage    ( struct vout_thread_s * );
138 static void vout_Display   ( struct vout_thread_s * );
139 static void vout_SetPalette( struct vout_thread_s *, u16*, u16*, u16*, u16* );
140
141 static int  X11CreateWindow     ( vout_thread_t *p_vout );
142 static int  X11InitDisplay      ( vout_thread_t *p_vout, char *psz_display );
143
144 static int  X11CreateImage      ( vout_thread_t *p_vout, XImage **pp_ximage );
145 static void X11DestroyImage     ( XImage *p_ximage );
146 static int  X11CreateShmImage   ( vout_thread_t *p_vout, XImage **pp_ximage,
147                                   XShmSegmentInfo *p_shm_info );
148 static void X11DestroyShmImage  ( vout_thread_t *p_vout, XImage *p_ximage,
149                                   XShmSegmentInfo *p_shm_info );
150
151 static void X11TogglePointer            ( vout_thread_t *p_vout );
152 static void X11EnableScreenSaver        ( vout_thread_t *p_vout );
153 static void X11DisableScreenSaver       ( vout_thread_t *p_vout );
154
155 /*****************************************************************************
156  * Functions exported as capabilities. They are declared as static so that
157  * we don't pollute the namespace too much.
158  *****************************************************************************/
159 void _M( vout_getfunctions )( function_list_t * p_function_list )
160 {
161     p_function_list->pf_probe = vout_Probe;
162     p_function_list->functions.vout.pf_create     = vout_Create;
163     p_function_list->functions.vout.pf_init       = vout_Init;
164     p_function_list->functions.vout.pf_end        = vout_End;
165     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
166     p_function_list->functions.vout.pf_manage     = vout_Manage;
167     p_function_list->functions.vout.pf_display    = vout_Display;
168     p_function_list->functions.vout.pf_setpalette = vout_SetPalette;
169 }
170
171 /*****************************************************************************
172  * vout_Probe: probe the video driver and return a score
173  *****************************************************************************
174  * This function tries to initialize SDL and returns a score to the
175  * plugin manager so that it can select the best plugin.
176  *****************************************************************************/
177 static int vout_Probe( probedata_t *p_data )
178 {
179     if( TestMethod( VOUT_METHOD_VAR, "x11" ) )
180     {
181         return( 999 );
182     }
183
184     return( 50 );
185 }
186
187 /*****************************************************************************
188  * vout_Create: allocate X11 video thread output method
189  *****************************************************************************
190  * This function allocate and initialize a X11 vout method. It uses some of the
191  * vout properties to choose the window size, and change them according to the
192  * actual properties of the display.
193  *****************************************************************************/
194 static int vout_Create( vout_thread_t *p_vout )
195 {
196     char *psz_display;
197
198     /* Allocate structure */
199     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
200     if( p_vout->p_sys == NULL )
201     {
202         intf_ErrMsg( "vout error: %s", strerror(ENOMEM) );
203         return( 1 );
204     }
205
206     /* Open display, unsing 'vlc_display' or DISPLAY environment variable */
207     psz_display = XDisplayName( main_GetPszVariable( VOUT_DISPLAY_VAR, NULL ) );
208     p_vout->p_sys->p_display = XOpenDisplay( psz_display );
209
210     if( p_vout->p_sys->p_display == NULL )                          /* error */
211     {
212         intf_ErrMsg( "vout error: cannot open display %s", psz_display );
213         free( p_vout->p_sys );
214         return( 1 );
215     }
216     p_vout->p_sys->i_screen = DefaultScreen( p_vout->p_sys->p_display );
217
218     p_vout->p_sys->b_fullscreen
219         = main_GetIntVariable( VOUT_FULLSCREEN_VAR, VOUT_FULLSCREEN_DEFAULT );
220
221     /* Spawn base window - this window will include the video output window,
222      * but also command buttons, subtitles and other indicators */
223
224     if( X11CreateWindow( p_vout ) )
225     {
226         intf_ErrMsg( "vout error: cannot create X11 window" );
227         XCloseDisplay( p_vout->p_sys->p_display );
228         free( p_vout->p_sys );
229         return( 1 );
230     }
231
232     /* Open and initialize device. This function issues its own error messages.
233      * Since XLib is usually not thread-safe, we can't use the same display
234      * pointer than the interface or another thread. However, the root window
235      * id is still valid. */
236     if( X11InitDisplay( p_vout, psz_display ) )
237     {
238         intf_ErrMsg( "vout error: cannot initialize X11 display" );
239         XCloseDisplay( p_vout->p_sys->p_display );
240         free( p_vout->p_sys );
241         return( 1 );
242     }
243
244     p_vout->p_sys->b_mouse = 1;
245
246     /* Disable screen saver and return */
247     X11DisableScreenSaver( p_vout );
248
249     return( 0 );
250 }
251
252 /*****************************************************************************
253  * vout_Init: initialize X11 video thread output method
254  *****************************************************************************
255  * This function create the XImages needed by the output thread. It is called
256  * at the beginning of the thread, but also each time the window is resized.
257  *****************************************************************************/
258 static int vout_Init( vout_thread_t *p_vout )
259 {
260     int i_err;
261
262 #ifdef SYS_DARWIN1_3
263     /* FIXME : As of 2001-03-16, XFree4 for MacOS X does not support Xshm. */
264     p_vout->p_sys->b_shm = 0;
265 #endif
266
267     /* Create XImages using XShm extension - on failure, fall back to regular
268      * way (and destroy the first image if it was created successfully) */
269     if( p_vout->p_sys->b_shm )
270     {
271         /* Create first image */
272         i_err = X11CreateShmImage( p_vout, &p_vout->p_sys->p_ximage[0],
273                                    &p_vout->p_sys->shm_info[0] );
274         if( !i_err )                         /* first image has been created */
275         {
276             /* Create second image */
277             if( X11CreateShmImage( p_vout, &p_vout->p_sys->p_ximage[1],
278                                    &p_vout->p_sys->shm_info[1] ) )
279             {                             /* error creating the second image */
280                 X11DestroyShmImage( p_vout, p_vout->p_sys->p_ximage[0],
281                                     &p_vout->p_sys->shm_info[0] );
282                 i_err = 1;
283             }
284         }
285         if( i_err )                                      /* an error occured */
286         {
287             intf_Msg( "vout: XShm video extension unavailable" );
288             p_vout->p_sys->b_shm = 0;
289         }
290     }
291
292     /* Create XImages without XShm extension */
293     if( !p_vout->p_sys->b_shm )
294     {
295         if( X11CreateImage( p_vout, &p_vout->p_sys->p_ximage[0] ) )
296         {
297             intf_ErrMsg( "vout error: cannot create images" );
298             p_vout->p_sys->p_ximage[0] = NULL;
299             p_vout->p_sys->p_ximage[1] = NULL;
300             return( 1 );
301         }
302         if( X11CreateImage( p_vout, &p_vout->p_sys->p_ximage[1] ) )
303         {
304             intf_ErrMsg( "vout error: cannot create images" );
305             X11DestroyImage( p_vout->p_sys->p_ximage[0] );
306             p_vout->p_sys->p_ximage[0] = NULL;
307             p_vout->p_sys->p_ximage[1] = NULL;
308             return( 1 );
309         }
310     }
311
312     /* Set bytes per line and initialize buffers */
313     p_vout->i_bytes_per_line = p_vout->p_sys->p_ximage[0]->bytes_per_line;
314     vout_SetBuffers( p_vout, p_vout->p_sys->p_ximage[ 0 ]->data,
315                      p_vout->p_sys->p_ximage[ 1 ]->data );
316
317     /* Set date for autohiding cursor */
318     p_vout->p_sys->i_lastmoved = mdate();
319     
320     return( 0 );
321 }
322
323 /*****************************************************************************
324  * vout_End: terminate X11 video thread output method
325  *****************************************************************************
326  * Destroy the X11 XImages created by vout_Init. It is called at the end of
327  * the thread, but also each time the window is resized.
328  *****************************************************************************/
329 static void vout_End( vout_thread_t *p_vout )
330 {
331     if( p_vout->p_sys->b_shm )                             /* Shm XImages... */
332     {
333         X11DestroyShmImage( p_vout, p_vout->p_sys->p_ximage[0],
334                             &p_vout->p_sys->shm_info[0] );
335         X11DestroyShmImage( p_vout, p_vout->p_sys->p_ximage[1],
336                             &p_vout->p_sys->shm_info[1] );
337     }
338     else                                          /* ...or regular XImages */
339     {
340         X11DestroyImage( p_vout->p_sys->p_ximage[0] );
341         X11DestroyImage( p_vout->p_sys->p_ximage[1] );
342     }
343 }
344
345 /*****************************************************************************
346  * vout_Destroy: destroy X11 video thread output method
347  *****************************************************************************
348  * Terminate an output method created by vout_CreateOutputMethod
349  *****************************************************************************/
350 static void vout_Destroy( vout_thread_t *p_vout )
351 {
352     /* Enable screen saver */
353     X11EnableScreenSaver( p_vout );
354
355     /* Destroy colormap */
356     if( p_vout->i_screen_depth == 8 )
357     {
358         XFreeColormap( p_vout->p_sys->p_display, p_vout->p_sys->colormap );
359     }
360
361     /* Destroy window */
362     XUnmapWindow( p_vout->p_sys->p_display, p_vout->p_sys->window );
363     XFreeGC( p_vout->p_sys->p_display, p_vout->p_sys->gc );
364     XDestroyWindow( p_vout->p_sys->p_display, p_vout->p_sys->window );
365
366     XCloseDisplay( p_vout->p_sys->p_display );
367
368     /* Destroy structure */
369     free( p_vout->p_sys );
370 }
371
372 /*****************************************************************************
373  * vout_Manage: handle X11 events
374  *****************************************************************************
375  * This function should be called regularly by video output thread. It manages
376  * X11 events and allows window resizing. It returns a non null value on
377  * error.
378  *****************************************************************************/
379 static int vout_Manage( vout_thread_t *p_vout )
380 {
381     XEvent      xevent;                                         /* X11 event */
382     boolean_t   b_resized;                        /* window has been resized */
383     boolean_t   b_gofullscreen;                    /* user wants full-screen */
384     char        i_key;                                    /* ISO Latin-1 key */
385     KeySym      x_key_symbol;
386
387     /* Handle X11 events: ConfigureNotify events are parsed to know if the
388      * output window's size changed, MapNotify and UnmapNotify to know if the
389      * window is mapped (and if the display is useful), and ClientMessages
390      * to intercept window destruction requests */
391     b_resized = 0;
392     b_gofullscreen = 0;
393
394     while( XCheckWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
395                               StructureNotifyMask | KeyPressMask |
396                               ButtonPressMask | ButtonReleaseMask | 
397                               PointerMotionMask | Button1MotionMask , &xevent )
398            == True )
399     {
400         /* ConfigureNotify event: prepare  */
401         if( (xevent.type == ConfigureNotify)
402             && ((xevent.xconfigure.width != p_vout->p_sys->i_width)
403                 || (xevent.xconfigure.height != p_vout->p_sys->i_height)) )
404         {
405             /* Update dimensions */
406             b_resized = 1;
407             p_vout->p_sys->i_width = xevent.xconfigure.width;
408             p_vout->p_sys->i_height = xevent.xconfigure.height;
409         }
410         /* MapNotify event: change window status and disable screen saver */
411         else if( xevent.type == MapNotify)
412         {
413             if( (p_vout != NULL) && !p_vout->b_active )
414             {
415                 X11DisableScreenSaver( p_vout );
416                 p_vout->b_active = 1;
417             }
418         }
419         /* UnmapNotify event: change window status and enable screen saver */
420         else if( xevent.type == UnmapNotify )
421         {
422             if( (p_vout != NULL) && p_vout->b_active )
423             {
424                 X11EnableScreenSaver( p_vout );
425                 p_vout->b_active = 0;
426             }
427         }
428         /* Keyboard event */
429         else if( xevent.type == KeyPress )
430         {
431             /* We may have keys like F1 trough F12, ESC ... */
432             x_key_symbol = XKeycodeToKeysym( p_vout->p_sys->p_display,
433                                              xevent.xkey.keycode, 0 );
434             switch( x_key_symbol )
435             {
436                  case XK_Escape:
437                      p_main->p_intf->b_die = 1;
438                      break;
439                  case XK_Menu:
440                      p_main->p_intf->b_menu_change = 1;
441                      break;
442                  default:
443                      /* "Normal Keys"
444                       * The reason why I use this instead of XK_0 is that 
445                       * with XLookupString, we don't have to care about
446                       * keymaps. */
447
448                     if( XLookupString( &xevent.xkey, &i_key, 1, NULL, NULL ) )
449                     {
450                         /* FIXME: handle stuff here */
451                         switch( i_key )
452                         {
453                         case 'q':
454                         case 'Q':
455                             p_main->p_intf->b_die = 1;
456                             break;
457                         case 'f':
458                         case 'F':
459                             b_gofullscreen = 1;
460                             break;
461                         case '0':
462                             network_ChannelJoin( 0 );
463                             break;
464                         case '1':
465                             network_ChannelJoin( 1 );
466                             break;
467                         case '2':
468                             network_ChannelJoin( 2 );
469                             break;
470                         case '3':
471                             network_ChannelJoin( 3 );
472                             break;
473                         case '4':
474                             network_ChannelJoin( 4 );
475                             break;
476                         case '5':
477                             network_ChannelJoin( 5 );
478                             break;
479                         case '6':
480                             network_ChannelJoin( 6 );
481                             break;
482                         case '7':
483                             network_ChannelJoin( 7 );
484                             break;
485                         case '8':
486                             network_ChannelJoin( 8 );
487                             break;
488                         case '9':
489                             network_ChannelJoin( 9 );
490                             break;
491                         default:
492                             if( intf_ProcessKey( p_main->p_intf, 
493                                                  (char )i_key ) )
494                             {
495                                intf_DbgMsg( "vout: unhandled key '%c' (%i)", 
496                                             (char)i_key, i_key );
497                             }
498                             break;
499                         }
500                     }
501                 break;
502             }
503         }
504         /* Mouse click */
505         else if( xevent.type == ButtonPress )
506         {
507             switch( ((XButtonEvent *)&xevent)->button )
508             {
509                 case Button1:
510                     /* in this part we will eventually manage
511                      * clicks for DVD navigation for instance */
512                     break;
513             }
514         }
515         /* Mouse release */
516         else if( xevent.type == ButtonRelease )
517         {
518             switch( ((XButtonEvent *)&xevent)->button )
519             {
520                 case Button3:
521                     /* FIXME: need locking ! */
522                     p_main->p_intf->b_menu_change = 1;
523                     break;
524             }
525         }
526         /* Mouse move */
527         else if( xevent.type == MotionNotify )
528         {
529             p_vout->p_sys->i_lastmoved = mdate();
530             if( ! p_vout->p_sys->b_mouse )
531             {
532                 X11TogglePointer( p_vout ); 
533             }
534         }
535         /* Other event */
536         else
537         {
538             intf_WarnMsg( 1, "vout: unhandled event %d received", xevent.type );
539         }
540     }
541
542     /* ClientMessage event - only WM_PROTOCOLS with WM_DELETE_WINDOW data
543      * are handled - according to the man pages, the format is always 32
544      * in this case */
545     while( XCheckTypedEvent( p_vout->p_sys->p_display,
546                              ClientMessage, &xevent ) )
547     {
548         if( (xevent.xclient.message_type == p_vout->p_sys->wm_protocols)
549             && (xevent.xclient.data.l[0] == p_vout->p_sys->wm_delete_window ) )
550         {
551             p_main->p_intf->b_die = 1;
552         }
553         else
554         {
555             intf_DbgMsg( "vout: unhandled ClientMessage received" );
556         }
557     }
558
559     if ( b_gofullscreen )
560     {
561         char *psz_display;
562         /* Open display, unsing 'vlc_display' or the DISPLAY
563          * environment variable */
564         psz_display = XDisplayName( main_GetPszVariable( VOUT_DISPLAY_VAR, NULL ) );
565
566         intf_DbgMsg( "vout: changing full-screen status" );
567
568         p_vout->p_sys->b_fullscreen = !p_vout->p_sys->b_fullscreen;
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->p_sys->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->p_sys->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->p_sys->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