]> git.sesse.net Git - vlc/blob - plugins/x11/vout_x11.c
Change --enable-debug into --enable-trace. Same with DEBUG_*.
[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.21 2001/04/27 19:29:11 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 #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 DISPLAY environment variable */
563         psz_display = XDisplayName( main_GetPszVariable( VOUT_DISPLAY_VAR, NULL ) );
564
565         intf_DbgMsg( "vout: changing full-screen status" );
566
567         p_vout->p_sys->b_fullscreen = !p_vout->p_sys->b_fullscreen;
568
569         /* Get rid of the old window */
570         XUnmapWindow( p_vout->p_sys->p_display, p_vout->p_sys->window );
571         XFreeGC( p_vout->p_sys->p_display, p_vout->p_sys->gc );
572
573         /* And create a new one */
574         if( X11CreateWindow( p_vout ) )
575         {
576             intf_ErrMsg( "vout error: cannot create X11 window" );
577             XCloseDisplay( p_vout->p_sys->p_display );
578
579             free( p_vout->p_sys );
580             return( 1 );
581         }
582
583         if( X11InitDisplay( p_vout, psz_display ) )
584         {
585             intf_ErrMsg( "vout error: cannot initialize X11 display" );
586             XCloseDisplay( p_vout->p_sys->p_display );
587             free( p_vout->p_sys );
588             return( 1 );
589         }
590         /* We've changed the size, update it */
591         p_vout->i_changes |= VOUT_SIZE_CHANGE;
592     }
593
594     /*
595      * Handle vout window resizing
596      */
597     if( b_resized )
598     {
599         /* If interface window has been resized, change vout size */
600         intf_DbgMsg( "vout: resizing output window" );
601         p_vout->i_width =  p_vout->p_sys->i_width;
602         p_vout->i_height = p_vout->p_sys->i_height;
603         p_vout->i_changes |= VOUT_SIZE_CHANGE;
604     }
605     else if( (p_vout->i_width  != p_vout->p_sys->i_width) ||
606              (p_vout->i_height != p_vout->p_sys->i_height) )
607     {
608         /* If video output size has changed, change interface window size */
609         intf_DbgMsg( "vout: resizing output window" );
610         p_vout->p_sys->i_width =    p_vout->i_width;
611         p_vout->p_sys->i_height =   p_vout->i_height;
612         XResizeWindow( p_vout->p_sys->p_display, p_vout->p_sys->window,
613                        p_vout->p_sys->i_width, p_vout->p_sys->i_height );
614     }
615     /*
616      * Color/Grayscale or gamma change: in 8bpp, just change the colormap
617      */
618     if( (p_vout->i_changes & VOUT_GRAYSCALE_CHANGE)
619         && (p_vout->i_screen_depth == 8) )
620     {
621         /* FIXME: clear flags ?? */
622     }
623
624     /*
625      * Size change
626      */
627     if( p_vout->i_changes & VOUT_SIZE_CHANGE )
628     {
629         intf_DbgMsg( "vout info: resizing window" );
630         p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
631
632         /* Resize window */
633         XResizeWindow( p_vout->p_sys->p_display, p_vout->p_sys->window,
634                        p_vout->i_width, p_vout->i_height );
635
636         /* Destroy XImages to change their size */
637         vout_End( p_vout );
638
639         /* Recreate XImages. If SysInit failed, the thread can't go on. */
640         if( vout_Init( p_vout ) )
641         {
642             intf_ErrMsg( "vout error: cannot resize display" );
643             return( 1 );
644        }
645
646         /* Tell the video output thread that it will need to rebuild YUV
647          * tables. This is needed since conversion buffer size may have
648          * changed */
649         p_vout->i_changes |= VOUT_YUV_CHANGE;
650         intf_Msg( "vout: video display resized (%dx%d)",
651                   p_vout->i_width, p_vout->i_height);
652     }
653
654     /* Autohide Cursour */
655     if( mdate() - p_vout->p_sys->i_lastmoved > 2000000 )
656     {
657         /* Hide the mouse automatically */
658         if( p_vout->p_sys->b_mouse )
659         {
660             X11TogglePointer( p_vout ); 
661         }
662     }
663
664     
665     return 0;
666 }
667
668 /*****************************************************************************
669  * vout_Display: displays previously rendered output
670  *****************************************************************************
671  * This function send the currently rendered image to X11 server, wait until
672  * it is displayed and switch the two rendering buffer, preparing next frame.
673  *****************************************************************************/
674 static void vout_Display( vout_thread_t *p_vout )
675 {
676     if( p_vout->p_sys->b_shm)                                /* XShm is used */
677     {
678         /* Display rendered image using shared memory extension */
679         XShmPutImage(p_vout->p_sys->p_display, p_vout->p_sys->window, p_vout->p_sys->gc,
680                      p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ],
681                      0, 0, 0, 0,
682                      p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ]->width,
683                      p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ]->height, True);
684
685         /* Send the order to the X server */
686         XSync(p_vout->p_sys->p_display, False);
687     }
688     else                                /* regular X11 capabilities are used */
689     {
690         XPutImage(p_vout->p_sys->p_display, p_vout->p_sys->window, p_vout->p_sys->gc,
691                   p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ],
692                   0, 0, 0, 0,
693                   p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ]->width,
694                   p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ]->height);
695
696         /* Send the order to the X server */
697         XSync(p_vout->p_sys->p_display, False);
698     }
699 }
700
701 /*****************************************************************************
702  * vout_SetPalette: sets an 8 bpp palette
703  *****************************************************************************
704  * This function sets the palette given as an argument. It does not return
705  * anything, but could later send information on which colors it was unable
706  * to set.
707  *****************************************************************************/
708 static void vout_SetPalette( p_vout_thread_t p_vout,
709                              u16 *red, u16 *green, u16 *blue, u16 *transp )
710 {
711     int i, j;
712     XColor p_colors[255];
713
714     intf_DbgMsg( "vout: Palette change called" );
715
716     /* allocate palette */
717     for( i = 0, j = 255; i < 255; i++, j-- )
718     {
719         /* kludge: colors are indexed reversely because color 255 seems
720          * to be reserved for black even if we try to set it to white */
721         p_colors[ i ].pixel = j;
722         p_colors[ i ].pad   = 0;
723         p_colors[ i ].flags = DoRed | DoGreen | DoBlue;
724         p_colors[ i ].red   = red[ j ];
725         p_colors[ i ].blue  = blue[ j ];
726         p_colors[ i ].green = green[ j ];
727     }
728
729     XStoreColors( p_vout->p_sys->p_display,
730                   p_vout->p_sys->colormap, p_colors, 256 );
731 }
732
733 /* following functions are local */
734
735 /*****************************************************************************
736  * X11CreateWindow: open and set-up X11 main window
737  *****************************************************************************/
738 static int X11CreateWindow( vout_thread_t *p_vout )
739 {
740     XSizeHints              xsize_hints;
741     XSetWindowAttributes    xwindow_attributes;
742     XGCValues               xgcvalues;
743     XEvent                  xevent;
744     Atom                    prop;
745     mwmhints_t              mwmhints;
746
747     boolean_t               b_expose;
748     boolean_t               b_configure_notify;
749     boolean_t               b_map_notify;
750
751     /* If we're full screen, we're full screen! */
752     if( p_vout->p_sys->b_fullscreen ) 
753     {
754         p_vout->p_sys->i_width = DisplayWidth( p_vout->p_sys->p_display, 
755                                                p_vout->p_sys->i_screen );
756         p_vout->p_sys->i_height =  DisplayHeight( p_vout->p_sys->p_display, 
757                                                   p_vout->p_sys->i_screen ); 
758         p_vout->i_width =  p_vout->p_sys->i_width;
759         p_vout->i_height = p_vout->p_sys->i_height;
760     }
761     else
762     {
763         /* Set main window's size */
764         p_vout->p_sys->i_width =  main_GetIntVariable( VOUT_WIDTH_VAR,
765                                                        VOUT_WIDTH_DEFAULT );
766         p_vout->p_sys->i_height = main_GetIntVariable( VOUT_HEIGHT_VAR,
767                                                        VOUT_HEIGHT_DEFAULT );
768         p_vout->i_width =  p_vout->p_sys->i_width;
769         p_vout->i_height = p_vout->p_sys->i_height;
770     }
771
772     /* Prepare window manager hints and properties */
773     xsize_hints.base_width          = p_vout->p_sys->i_width;
774     xsize_hints.base_height         = p_vout->p_sys->i_height;
775     xsize_hints.flags               = PSize;
776     p_vout->p_sys->wm_protocols     = XInternAtom( p_vout->p_sys->p_display,
777                                                    "WM_PROTOCOLS", True );
778     p_vout->p_sys->wm_delete_window = XInternAtom( p_vout->p_sys->p_display,
779                                                    "WM_DELETE_WINDOW", True );
780
781     /* Prepare window attributes */
782     xwindow_attributes.backing_store = Always;       /* save the hidden part */
783     xwindow_attributes.background_pixel = BlackPixel( p_vout->p_sys->p_display,
784                                                       p_vout->p_sys->i_screen );
785     xwindow_attributes.event_mask = ExposureMask | StructureNotifyMask;
786     
787
788     /* Create the window and set hints - the window must receive ConfigureNotify
789      * events, and, until it is displayed, Expose and MapNotify events. */
790
791     p_vout->p_sys->window =
792         XCreateWindow( p_vout->p_sys->p_display,
793                        DefaultRootWindow( p_vout->p_sys->p_display ),
794                        0, 0,
795                        p_vout->p_sys->i_width, p_vout->p_sys->i_height, 0,
796                        0, InputOutput, 0,
797                        CWBackingStore | CWBackPixel | CWEventMask,
798                        &xwindow_attributes );
799
800     if ( p_vout->p_sys->b_fullscreen )
801     {
802         prop = XInternAtom(p_vout->p_sys->p_display, "_MOTIF_WM_HINTS", False);
803         mwmhints.flags = MWM_HINTS_DECORATIONS;
804         mwmhints.decorations = 0;
805         XChangeProperty( p_vout->p_sys->p_display, p_vout->p_sys->window,
806                          prop, prop, 32, PropModeReplace,
807                          (unsigned char *)&mwmhints, PROP_MWM_HINTS_ELEMENTS );
808
809         XSetTransientForHint( p_vout->p_sys->p_display,
810                               p_vout->p_sys->window, None );
811         XRaiseWindow( p_vout->p_sys->p_display, p_vout->p_sys->window );
812     }
813
814     /* Set window manager hints and properties: size hints, command,
815      * window's name, and accepted protocols */
816     XSetWMNormalHints( p_vout->p_sys->p_display, p_vout->p_sys->window,
817                        &xsize_hints );
818     XSetCommand( p_vout->p_sys->p_display, p_vout->p_sys->window,
819                  p_main->ppsz_argv, p_main->i_argc );
820     XStoreName( p_vout->p_sys->p_display, p_vout->p_sys->window,
821                 VOUT_TITLE " (X11 output)" );
822
823     if( (p_vout->p_sys->wm_protocols == None)        /* use WM_DELETE_WINDOW */
824         || (p_vout->p_sys->wm_delete_window == None)
825         || !XSetWMProtocols( p_vout->p_sys->p_display, p_vout->p_sys->window,
826                              &p_vout->p_sys->wm_delete_window, 1 ) )
827     {
828         /* WM_DELETE_WINDOW is not supported by window manager */
829         intf_Msg( "vout error: missing or bad window manager" );
830     }
831
832     /* Creation of a graphic context that doesn't generate a GraphicsExpose
833      * event when using functions like XCopyArea */
834     xgcvalues.graphics_exposures = False;
835     p_vout->p_sys->gc = XCreateGC( p_vout->p_sys->p_display,
836                                    p_vout->p_sys->window,
837                                    GCGraphicsExposures, &xgcvalues);
838
839     /* Send orders to server, and wait until window is displayed - three
840      * events must be received: a MapNotify event, an Expose event allowing
841      * drawing in the window, and a ConfigureNotify to get the window
842      * dimensions. Once those events have been received, only ConfigureNotify
843      * events need to be received. */
844     b_expose = 0;
845     b_configure_notify = 0;
846     b_map_notify = 0;
847     XMapWindow( p_vout->p_sys->p_display, p_vout->p_sys->window);
848     do
849     {
850         XNextEvent( p_vout->p_sys->p_display, &xevent);
851         if( (xevent.type == Expose)
852             && (xevent.xexpose.window == p_vout->p_sys->window) )
853         {
854             b_expose = 1;
855         }
856         else if( (xevent.type == MapNotify)
857                  && (xevent.xmap.window == p_vout->p_sys->window) )
858         {
859             b_map_notify = 1;
860         }
861         else if( (xevent.type == ConfigureNotify)
862                  && (xevent.xconfigure.window == p_vout->p_sys->window) )
863         {
864             b_configure_notify = 1;
865             p_vout->p_sys->i_width = xevent.xconfigure.width;
866             p_vout->p_sys->i_height = xevent.xconfigure.height;
867         }
868     } while( !( b_expose && b_configure_notify && b_map_notify ) );
869
870     XSelectInput( p_vout->p_sys->p_display, p_vout->p_sys->window,
871                   StructureNotifyMask | KeyPressMask |
872                   ButtonPressMask | ButtonReleaseMask | 
873                   PointerMotionMask );
874
875     if( XDefaultDepth(p_vout->p_sys->p_display, p_vout->p_sys->i_screen) == 8 )
876     {
877         /* Allocate a new palette */
878         p_vout->p_sys->colormap =
879             XCreateColormap( p_vout->p_sys->p_display,
880                              DefaultRootWindow( p_vout->p_sys->p_display ),
881                              DefaultVisual( p_vout->p_sys->p_display,
882                                             p_vout->p_sys->i_screen ),
883                              AllocAll );
884
885         xwindow_attributes.colormap = p_vout->p_sys->colormap;
886         XChangeWindowAttributes( p_vout->p_sys->p_display,
887                                  p_vout->p_sys->window,
888                                  CWColormap, &xwindow_attributes );
889     }
890
891     if( p_vout->p_sys->b_fullscreen )
892     {
893         XSetInputFocus( p_vout->p_sys->p_display, p_vout->p_sys->window,
894                         RevertToNone, CurrentTime );
895         XMoveWindow( p_vout->p_sys->p_display, p_vout->p_sys->window, 0, 0 );
896     }
897
898     /* At this stage, the window is open, displayed, and ready to
899      * receive data */
900
901     return( 0 );
902 }
903
904 /*****************************************************************************
905  * X11InitDisplay: open and initialize X11 device
906  *****************************************************************************
907  * Create a window according to video output given size, and set other
908  * properties according to the display properties.
909  *****************************************************************************/
910 static int X11InitDisplay( vout_thread_t *p_vout, char *psz_display )
911 {
912     XPixmapFormatValues *       p_formats;                 /* pixmap formats */
913     XVisualInfo *               p_xvisual;           /* visuals informations */
914     XVisualInfo                 xvisual_template;         /* visual template */
915     int                         i_count;                       /* array size */
916
917
918
919     /* Initialize structure */
920     p_vout->p_sys->i_screen = DefaultScreen( p_vout->p_sys->p_display );
921     p_vout->p_sys->b_shm    = ( XShmQueryExtension( p_vout->p_sys->p_display )
922                                  == True );
923     if( !p_vout->p_sys->b_shm )
924     {
925         intf_Msg( "vout: XShm video extension is not available" );
926     }
927
928     /* Get screen depth */
929     p_vout->i_screen_depth = XDefaultDepth( p_vout->p_sys->p_display,
930                                             p_vout->p_sys->i_screen );
931     switch( p_vout->i_screen_depth )
932     {
933     case 8:
934         /*
935          * Screen depth is 8bpp. Use PseudoColor visual with private colormap.
936          */
937         xvisual_template.screen =   p_vout->p_sys->i_screen;
938         xvisual_template.class =    DirectColor;
939         p_xvisual = XGetVisualInfo( p_vout->p_sys->p_display,
940                                     VisualScreenMask | VisualClassMask,
941                                     &xvisual_template, &i_count );
942         if( p_xvisual == NULL )
943         {
944             intf_ErrMsg( "vout error: no PseudoColor visual available" );
945             return( 1 );
946         }
947         p_vout->i_bytes_per_pixel = 1;
948         break;
949     case 15:
950     case 16:
951     case 24:
952     default:
953         /*
954          * Screen depth is higher than 8bpp. TrueColor visual is used.
955          */
956         xvisual_template.screen =   p_vout->p_sys->i_screen;
957         xvisual_template.class =    TrueColor;
958         p_xvisual = XGetVisualInfo( p_vout->p_sys->p_display,
959                                     VisualScreenMask | VisualClassMask,
960                                     &xvisual_template, &i_count );
961         if( p_xvisual == NULL )
962         {
963             intf_ErrMsg( "vout error: no TrueColor visual available" );
964             return( 1 );
965         }
966         p_vout->i_red_mask =        p_xvisual->red_mask;
967         p_vout->i_green_mask =      p_xvisual->green_mask;
968         p_vout->i_blue_mask =       p_xvisual->blue_mask;
969
970         /* There is no difference yet between 3 and 4 Bpp. The only way
971          * to find the actual number of bytes per pixel is to list supported
972          * pixmap formats. */
973         p_formats = XListPixmapFormats( p_vout->p_sys->p_display, &i_count );
974         p_vout->i_bytes_per_pixel = 0;
975
976         for( ; i_count-- ; p_formats++ )
977         {
978             /* Under XFree4.0, the list contains pixmap formats available
979              * through all video depths ; so we have to check against current
980              * depth. */
981             if( p_formats->depth == p_vout->i_screen_depth )
982             {
983                 if( p_formats->bits_per_pixel / 8
984                         > p_vout->i_bytes_per_pixel )
985                 {
986                     p_vout->i_bytes_per_pixel = p_formats->bits_per_pixel / 8;
987                 }
988             }
989         }
990         break;
991     }
992     p_vout->p_sys->p_visual = p_xvisual->visual;
993     XFree( p_xvisual );
994
995     return( 0 );
996 }
997
998 /*****************************************************************************
999  * X11CreateImage: create an XImage
1000  *****************************************************************************
1001  * Create a simple XImage used as a buffer.
1002  *****************************************************************************/
1003 static int X11CreateImage( vout_thread_t *p_vout, XImage **pp_ximage )
1004 {
1005     byte_t *    pb_data;                          /* image data storage zone */
1006     int         i_quantum;                     /* XImage quantum (see below) */
1007
1008     /* Allocate memory for image */
1009     p_vout->i_bytes_per_line = p_vout->i_width * p_vout->i_bytes_per_pixel;
1010     pb_data = (byte_t *) malloc( p_vout->i_bytes_per_line * p_vout->i_height );
1011     if( !pb_data )                                                  /* error */
1012     {
1013         intf_ErrMsg( "vout error: %s", strerror(ENOMEM));
1014         return( 1 );
1015     }
1016
1017     /* Optimize the quantum of a scanline regarding its size - the quantum is
1018        a diviser of the number of bits between the start of two scanlines. */
1019     if( !(( p_vout->i_bytes_per_line ) % 32) )
1020     {
1021         i_quantum = 32;
1022     }
1023     else
1024     {
1025         if( !(( p_vout->i_bytes_per_line ) % 16) )
1026         {
1027             i_quantum = 16;
1028         }
1029         else
1030         {
1031             i_quantum = 8;
1032         }
1033     }
1034
1035     /* Create XImage */
1036     *pp_ximage = XCreateImage( p_vout->p_sys->p_display,
1037                                p_vout->p_sys->p_visual, p_vout->i_screen_depth,
1038                                ZPixmap, 0, pb_data,
1039                                p_vout->i_width, p_vout->i_height, i_quantum, 0);
1040     if(! *pp_ximage )                                               /* error */
1041     {
1042         intf_ErrMsg( "vout error: XCreateImage() failed" );
1043         free( pb_data );
1044         return( 1 );
1045     }
1046
1047     return 0;
1048 }
1049
1050 /*****************************************************************************
1051  * X11CreateShmImage: create an XImage using shared memory extension
1052  *****************************************************************************
1053  * Prepare an XImage for DisplayX11ShmImage function.
1054  * The order of the operations respects the recommandations of the mit-shm
1055  * document by J.Corbet and K.Packard. Most of the parameters were copied from
1056  * there.
1057  *****************************************************************************/
1058 static int X11CreateShmImage( vout_thread_t *p_vout, XImage **pp_ximage,
1059                               XShmSegmentInfo *p_shm_info)
1060 {
1061     /* Create XImage */
1062     *pp_ximage =
1063         XShmCreateImage( p_vout->p_sys->p_display, p_vout->p_sys->p_visual,
1064                          p_vout->i_screen_depth, ZPixmap, 0,
1065                          p_shm_info, p_vout->i_width, p_vout->i_height );
1066     if(! *pp_ximage )                                               /* error */
1067     {
1068         intf_ErrMsg( "vout error: XShmCreateImage() failed" );
1069         return( 1 );
1070     }
1071
1072     /* Allocate shared memory segment - 0777 set the access permission
1073      * rights (like umask), they are not yet supported by X servers */
1074     p_shm_info->shmid =
1075         shmget( IPC_PRIVATE, (*pp_ximage)->bytes_per_line
1076                                  * (*pp_ximage)->height, IPC_CREAT | 0777);
1077     if( p_shm_info->shmid < 0)                                      /* error */
1078     {
1079         intf_ErrMsg( "vout error: cannot allocate shared image data (%s)",
1080                     strerror(errno));
1081         XDestroyImage( *pp_ximage );
1082         return( 1 );
1083     }
1084
1085     /* Attach shared memory segment to process (read/write) */
1086     p_shm_info->shmaddr = (*pp_ximage)->data = shmat(p_shm_info->shmid, 0, 0);
1087     if(! p_shm_info->shmaddr )
1088     {                                                               /* error */
1089         intf_ErrMsg( "vout error: cannot attach shared memory (%s)",
1090                     strerror(errno));
1091         shmctl( p_shm_info->shmid, IPC_RMID, 0 );      /* free shared memory */
1092         XDestroyImage( *pp_ximage );
1093         return( 1 );
1094     }
1095
1096     /* Mark the shm segment to be removed when there will be no more
1097      * attachements, so it is automatic on process exit or after shmdt */
1098     shmctl( p_shm_info->shmid, IPC_RMID, 0 );
1099
1100     /* Attach shared memory segment to X server (read only) */
1101     p_shm_info->readOnly = True;
1102     if( XShmAttach( p_vout->p_sys->p_display, p_shm_info )
1103          == False )                                                 /* error */
1104     {
1105         intf_ErrMsg( "vout error: cannot attach shared memory to X11 server" );
1106         shmdt( p_shm_info->shmaddr );   /* detach shared memory from process
1107                                          * and automatic free */
1108         XDestroyImage( *pp_ximage );
1109         return( 1 );
1110     }
1111
1112     /* Send image to X server. This instruction is required, since having
1113      * built a Shm XImage and not using it causes an error on XCloseDisplay */
1114     XFlush( p_vout->p_sys->p_display );
1115     return( 0 );
1116 }
1117
1118 /*****************************************************************************
1119  * X11DestroyImage: destroy an XImage
1120  *****************************************************************************
1121  * Destroy XImage AND associated data. If pointer is NULL, the image won't be
1122  * destroyed (see vout_ManageOutputMethod())
1123  *****************************************************************************/
1124 static void X11DestroyImage( XImage *p_ximage )
1125 {
1126     if( p_ximage != NULL )
1127     {
1128         XDestroyImage( p_ximage );                     /* no free() required */
1129     }
1130 }
1131
1132 /*****************************************************************************
1133  * X11DestroyShmImage
1134  *****************************************************************************
1135  * Destroy XImage AND associated data. Detach shared memory segment from
1136  * server and process, then free it. If pointer is NULL, the image won't be
1137  * destroyed (see vout_ManageOutputMethod())
1138  *****************************************************************************/
1139 static void X11DestroyShmImage( vout_thread_t *p_vout, XImage *p_ximage,
1140                                 XShmSegmentInfo *p_shm_info )
1141 {
1142     /* If pointer is NULL, do nothing */
1143     if( p_ximage == NULL )
1144     {
1145         return;
1146     }
1147
1148     XShmDetach( p_vout->p_sys->p_display, p_shm_info );/* detach from server */
1149     XDestroyImage( p_ximage );
1150
1151     if( shmdt( p_shm_info->shmaddr ) )  /* detach shared memory from process */
1152     {                                   /* also automatic freeing...         */
1153         intf_ErrMsg( "vout error: cannot detach shared memory (%s)",
1154                      strerror(errno) );
1155     }
1156 }
1157
1158
1159 /* WAZAAAAAAAAAAA */
1160
1161 /*****************************************************************************
1162  * X11EnableScreenSaver: enable screen saver
1163  *****************************************************************************
1164  * This function enable the screen saver on a display after it had been
1165  * disabled by XDisableScreenSaver. Both functions use a counter mechanism to
1166  * know wether the screen saver can be activated or not: if n successive calls
1167  * are made to XDisableScreenSaver, n successive calls to XEnableScreenSaver
1168  * will be required before the screen saver could effectively be activated.
1169  *****************************************************************************/
1170 void X11EnableScreenSaver( vout_thread_t *p_vout )
1171 {
1172     intf_DbgMsg( "vout: enabling screen saver" );
1173     XSetScreenSaver( p_vout->p_sys->p_display, p_vout->p_sys->i_ss_timeout,
1174                      p_vout->p_sys->i_ss_interval,
1175                      p_vout->p_sys->i_ss_blanking,
1176                      p_vout->p_sys->i_ss_exposure );
1177 }
1178
1179 /*****************************************************************************
1180  * X11DisableScreenSaver: disable screen saver
1181  *****************************************************************************
1182  * See XEnableScreenSaver
1183  *****************************************************************************/
1184 void X11DisableScreenSaver( vout_thread_t *p_vout )
1185 {
1186     /* Save screen saver informations */
1187     XGetScreenSaver( p_vout->p_sys->p_display, &p_vout->p_sys->i_ss_timeout,
1188                      &p_vout->p_sys->i_ss_interval,
1189                      &p_vout->p_sys->i_ss_blanking,
1190                      &p_vout->p_sys->i_ss_exposure );
1191
1192     /* Disable screen saver */
1193     intf_DbgMsg( "vout: disabling screen saver" );
1194     XSetScreenSaver( p_vout->p_sys->p_display, 0,
1195                      p_vout->p_sys->i_ss_interval,
1196                      p_vout->p_sys->i_ss_blanking,
1197                      p_vout->p_sys->i_ss_exposure );
1198 }
1199
1200 /*****************************************************************************
1201  * X11TogglePointer: hide or show the mouse pointer
1202  *****************************************************************************
1203  * This function hides the X pointer if it is visible by putting it at
1204  * coordinates (32,32) and setting the pointer sprite to a blank one. To
1205  * show it again, we disable the sprite and restore the original coordinates.
1206  *****************************************************************************/
1207 void X11TogglePointer( vout_thread_t *p_vout )
1208 {
1209     static Cursor cursor;
1210     static boolean_t b_cursor = 0;
1211
1212     if( p_vout->p_sys->b_mouse )
1213     {
1214         p_vout->p_sys->b_mouse = 0;
1215
1216         if( !b_cursor )
1217         {
1218             XColor color;
1219             Pixmap blank = XCreatePixmap( p_vout->p_sys->p_display,
1220                                DefaultRootWindow(p_vout->p_sys->p_display),
1221                                1, 1, 1 );
1222
1223             XParseColor( p_vout->p_sys->p_display,
1224                          XCreateColormap( p_vout->p_sys->p_display,
1225                                           DefaultRootWindow(
1226                                                   p_vout->p_sys->p_display ),
1227                                           DefaultVisual(
1228                                                   p_vout->p_sys->p_display,
1229                                                   p_vout->p_sys->i_screen ),
1230                                           AllocNone ),
1231                          "black", &color );
1232
1233             cursor = XCreatePixmapCursor( p_vout->p_sys->p_display,
1234                            blank, blank, &color, &color, 1, 1 );
1235
1236             b_cursor = 1;
1237         }
1238         XDefineCursor( p_vout->p_sys->p_display,
1239                        p_vout->p_sys->window, cursor );
1240     }
1241     else
1242     {
1243         p_vout->p_sys->b_mouse = 1;
1244
1245         XUndefineCursor( p_vout->p_sys->p_display, p_vout->p_sys->window );
1246     }
1247 }
1248