1 /*****************************************************************************
2 * xcommon.c: Functions common to the X11 and XVideo plugins
3 *****************************************************************************
4 * Copyright (C) 1998-2001 VideoLAN
7 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8 * Sam Hocevar <sam@zoy.org>
9 * David Kennedy <dkennedy@tinytoad.com>
10 * Gildas Bazin <gbazin@netcourrier.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
30 #include <errno.h> /* ENOMEM */
31 #include <stdlib.h> /* free() */
32 #include <string.h> /* strerror() */
39 #ifdef HAVE_MACHINE_PARAM_H
41 # include <machine/param.h>
42 # include <sys/types.h> /* typedef ushort */
47 # include <netinet/in.h> /* BSD: struct in_addr */
51 # include <sys/shm.h> /* shmget(), shmctl() */
56 #include <X11/Xutil.h>
57 #include <X11/keysym.h>
59 # include <X11/extensions/XShm.h>
61 #ifdef DPMSINFO_IN_DPMS_H
62 # include <X11/extensions/dpms.h>
65 #ifdef MODULE_NAME_IS_xvideo
66 # include <X11/extensions/Xv.h>
67 # include <X11/extensions/Xvlib.h>
71 # include <X11/extensions/Xinerama.h>
76 /*****************************************************************************
78 *****************************************************************************/
79 int E_(Activate) ( vlc_object_t * );
80 void E_(Deactivate) ( vlc_object_t * );
82 static int InitVideo ( vout_thread_t * );
83 static void EndVideo ( vout_thread_t * );
84 static void DisplayVideo ( vout_thread_t *, picture_t * );
85 static int ManageVideo ( vout_thread_t * );
86 static int Control ( vout_thread_t *, int, va_list );
88 static int InitDisplay ( vout_thread_t * );
90 static int CreateWindow ( vout_thread_t *, x11_window_t * );
91 static void DestroyWindow ( vout_thread_t *, x11_window_t * );
93 static int NewPicture ( vout_thread_t *, picture_t * );
94 static void FreePicture ( vout_thread_t *, picture_t * );
96 static IMAGE_TYPE *CreateImage ( vout_thread_t *,
97 Display *, EXTRA_ARGS, int, int );
99 static IMAGE_TYPE *CreateShmImage ( vout_thread_t *,
100 Display *, EXTRA_ARGS_SHM, int, int );
103 static void ToggleFullScreen ( vout_thread_t * );
105 static void EnableXScreenSaver ( vout_thread_t * );
106 static void DisableXScreenSaver ( vout_thread_t * );
108 static void CreateCursor ( vout_thread_t * );
109 static void DestroyCursor ( vout_thread_t * );
110 static void ToggleCursor ( vout_thread_t * );
112 #ifdef MODULE_NAME_IS_xvideo
113 static int XVideoGetPort ( vout_thread_t *, vlc_fourcc_t, vlc_fourcc_t * );
114 static void XVideoReleasePort( vout_thread_t *, int );
117 #ifdef MODULE_NAME_IS_x11
118 static void SetPalette ( vout_thread_t *,
119 uint16_t *, uint16_t *, uint16_t * );
122 static void TestNetWMSupport( vout_thread_t * );
123 static int ConvertKey( int );
125 static int WindowOnTop( vout_thread_t *, vlc_bool_t );
127 /*****************************************************************************
128 * Activate: allocate X11 video thread output method
129 *****************************************************************************
130 * This function allocate and initialize a X11 vout method. It uses some of the
131 * vout properties to choose the window size, and change them according to the
132 * actual properties of the display.
133 *****************************************************************************/
134 int E_(Activate) ( vlc_object_t *p_this )
136 vout_thread_t *p_vout = (vout_thread_t *)p_this;
140 #ifdef MODULE_NAME_IS_xvideo
142 vlc_fourcc_t i_chroma = 0;
143 vlc_bool_t b_chroma = 0;
146 p_vout->pf_init = InitVideo;
147 p_vout->pf_end = EndVideo;
148 p_vout->pf_manage = ManageVideo;
149 p_vout->pf_render = NULL;
150 p_vout->pf_display = DisplayVideo;
151 p_vout->pf_control = Control;
153 /* Allocate structure */
154 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
155 if( p_vout->p_sys == NULL )
157 msg_Err( p_vout, "out of memory" );
161 vlc_mutex_init( p_vout, &p_vout->p_sys->lock );
163 /* Open display, using the "display" config variable or the DISPLAY
164 * environment variable */
165 psz_display = config_GetPsz( p_vout, MODULE_STRING "-display" );
167 p_vout->p_sys->p_display = XOpenDisplay( psz_display );
169 if( p_vout->p_sys->p_display == NULL ) /* error */
171 msg_Err( p_vout, "cannot open display %s",
172 XDisplayName( psz_display ) );
173 free( p_vout->p_sys );
174 if( psz_display ) free( psz_display );
177 if( psz_display ) free( psz_display );
179 /* Get a screen ID matching the XOpenDisplay return value */
180 p_vout->p_sys->i_screen = DefaultScreen( p_vout->p_sys->p_display );
182 #ifdef MODULE_NAME_IS_xvideo
183 psz_chroma = config_GetPsz( p_vout, "xvideo-chroma" );
186 if( strlen( psz_chroma ) >= 4 )
188 /* Do not use direct assignment because we are not sure of the
190 memcpy(&i_chroma, psz_chroma, 4);
199 msg_Dbg( p_vout, "forcing chroma 0x%.8x (%4.4s)",
200 i_chroma, (char*)&i_chroma );
204 i_chroma = p_vout->render.i_chroma;
207 /* Check that we have access to an XVideo port providing this chroma */
208 p_vout->p_sys->i_xvport = XVideoGetPort( p_vout, VLC2X11_FOURCC(i_chroma),
209 &p_vout->output.i_chroma );
210 if( p_vout->p_sys->i_xvport < 0 )
212 /* If a specific chroma format was requested, then we don't try to
213 * be cleverer than the user. He knew pretty well what he wanted. */
216 XCloseDisplay( p_vout->p_sys->p_display );
217 free( p_vout->p_sys );
221 /* It failed, but it's not completely lost ! We try to open an
222 * XVideo port for an YUY2 picture. We'll need to do an YUV
223 * conversion, but at least it has got scaling. */
224 p_vout->p_sys->i_xvport =
225 XVideoGetPort( p_vout, X11_FOURCC('Y','U','Y','2'),
226 &p_vout->output.i_chroma );
227 if( p_vout->p_sys->i_xvport < 0 )
229 /* It failed, but it's not completely lost ! We try to open an
230 * XVideo port for a simple 16bpp RGB picture. We'll need to do
231 * an YUV conversion, but at least it has got scaling. */
232 p_vout->p_sys->i_xvport =
233 XVideoGetPort( p_vout, X11_FOURCC('R','V','1','6'),
234 &p_vout->output.i_chroma );
235 if( p_vout->p_sys->i_xvport < 0 )
237 XCloseDisplay( p_vout->p_sys->p_display );
238 free( p_vout->p_sys );
243 p_vout->output.i_chroma = X112VLC_FOURCC(p_vout->output.i_chroma);
246 /* Create blank cursor (for mouse cursor autohiding) */
247 p_vout->p_sys->i_time_mouse_last_moved = mdate();
248 p_vout->p_sys->b_mouse_pointer_visible = 1;
249 CreateCursor( p_vout );
251 /* Set main window's size */
252 p_vout->p_sys->original_window.i_width = p_vout->i_window_width;
253 p_vout->p_sys->original_window.i_height = p_vout->i_window_height;
255 /* Spawn base window - this window will include the video output window,
256 * but also command buttons, subtitles and other indicators */
257 if( CreateWindow( p_vout, &p_vout->p_sys->original_window ) )
259 msg_Err( p_vout, "cannot create X11 window" );
260 DestroyCursor( p_vout );
261 XCloseDisplay( p_vout->p_sys->p_display );
262 free( p_vout->p_sys );
266 /* Open and initialize device. */
267 if( InitDisplay( p_vout ) )
269 msg_Err( p_vout, "cannot initialize X11 display" );
270 DestroyCursor( p_vout );
271 DestroyWindow( p_vout, &p_vout->p_sys->original_window );
272 XCloseDisplay( p_vout->p_sys->p_display );
273 free( p_vout->p_sys );
277 /* Disable screen saver */
278 DisableXScreenSaver( p_vout );
281 p_vout->p_sys->b_altfullscreen = 0;
282 p_vout->p_sys->i_time_button_last_pressed = 0;
284 TestNetWMSupport( p_vout );
286 /* Variable to indicate if the window should be on top of others */
287 /* Trigger a callback right now */
288 var_Get( p_vout, "video-on-top", &val );
289 var_Set( p_vout, "video-on-top", val );
294 /*****************************************************************************
295 * Deactivate: destroy X11 video thread output method
296 *****************************************************************************
297 * Terminate an output method created by Open
298 *****************************************************************************/
299 void E_(Deactivate) ( vlc_object_t *p_this )
301 vout_thread_t *p_vout = (vout_thread_t *)p_this;
303 /* If the fullscreen window is still open, close it */
304 if( p_vout->b_fullscreen )
306 ToggleFullScreen( p_vout );
309 /* Restore cursor if it was blanked */
310 if( !p_vout->p_sys->b_mouse_pointer_visible )
312 ToggleCursor( p_vout );
315 #ifdef MODULE_NAME_IS_x11
316 /* Destroy colormap */
317 if( XDefaultDepth(p_vout->p_sys->p_display, p_vout->p_sys->i_screen) == 8 )
319 XFreeColormap( p_vout->p_sys->p_display, p_vout->p_sys->colormap );
322 XVideoReleasePort( p_vout, p_vout->p_sys->i_xvport );
325 DestroyCursor( p_vout );
326 EnableXScreenSaver( p_vout );
327 DestroyWindow( p_vout, &p_vout->p_sys->original_window );
329 XCloseDisplay( p_vout->p_sys->p_display );
331 /* Destroy structure */
332 vlc_mutex_destroy( &p_vout->p_sys->lock );
333 free( p_vout->p_sys );
336 /*****************************************************************************
337 * InitVideo: initialize X11 video thread output method
338 *****************************************************************************
339 * This function create the XImages needed by the output thread. It is called
340 * at the beginning of the thread, but also each time the window is resized.
341 *****************************************************************************/
342 static int InitVideo( vout_thread_t *p_vout )
347 I_OUTPUTPICTURES = 0;
349 #ifdef MODULE_NAME_IS_xvideo
350 /* Initialize the output structure; we already found an XVideo port,
351 * and the corresponding chroma we will be using. Since we can
352 * arbitrary scale, stick to the coordinates and aspect. */
353 p_vout->output.i_width = p_vout->render.i_width;
354 p_vout->output.i_height = p_vout->render.i_height;
355 p_vout->output.i_aspect = p_vout->render.i_aspect;
357 switch( p_vout->output.i_chroma )
359 case VLC_FOURCC('R','V','1','5'):
360 p_vout->output.i_rmask = 0x001f;
361 p_vout->output.i_gmask = 0x07e0;
362 p_vout->output.i_bmask = 0xf800;
364 case VLC_FOURCC('R','V','1','6'):
365 p_vout->output.i_rmask = 0x001f;
366 p_vout->output.i_gmask = 0x03e0;
367 p_vout->output.i_bmask = 0x7c00;
372 /* Initialize the output structure: RGB with square pixels, whatever
373 * the input format is, since it's the only format we know */
374 switch( p_vout->p_sys->i_screen_depth )
376 case 8: /* FIXME: set the palette */
377 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2'); break;
379 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5'); break;
381 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); break;
383 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4'); break;
385 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); break;
387 msg_Err( p_vout, "unknown screen depth %i",
388 p_vout->p_sys->i_screen_depth );
392 vout_PlacePicture( p_vout, p_vout->p_sys->p_win->i_width,
393 p_vout->p_sys->p_win->i_height,
395 &p_vout->output.i_width, &p_vout->output.i_height );
397 /* Assume we have square pixels */
398 p_vout->output.i_aspect = p_vout->output.i_width
399 * VOUT_ASPECT_FACTOR / p_vout->output.i_height;
402 /* Try to initialize up to MAX_DIRECTBUFFERS direct buffers */
403 while( I_OUTPUTPICTURES < MAX_DIRECTBUFFERS )
407 /* Find an empty picture slot */
408 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
410 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
412 p_pic = p_vout->p_picture + i_index;
417 /* Allocate the picture */
418 if( p_pic == NULL || NewPicture( p_vout, p_pic ) )
423 p_pic->i_status = DESTROYED_PICTURE;
424 p_pic->i_type = DIRECT_PICTURE;
426 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
434 /*****************************************************************************
435 * DisplayVideo: displays previously rendered output
436 *****************************************************************************
437 * This function sends the currently rendered image to X11 server.
438 * (The Xv extension takes care of "double-buffering".)
439 *****************************************************************************/
440 static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
442 int i_width, i_height, i_x, i_y;
444 vout_PlacePicture( p_vout, p_vout->p_sys->p_win->i_width,
445 p_vout->p_sys->p_win->i_height,
446 &i_x, &i_y, &i_width, &i_height );
448 vlc_mutex_lock( &p_vout->p_sys->lock );
450 #ifdef HAVE_SYS_SHM_H
451 if( p_vout->p_sys->b_shm )
453 /* Display rendered image using shared memory extension */
454 # ifdef MODULE_NAME_IS_xvideo
455 XvShmPutImage( p_vout->p_sys->p_display, p_vout->p_sys->i_xvport,
456 p_vout->p_sys->p_win->video_window,
457 p_vout->p_sys->p_win->gc, p_pic->p_sys->p_image,
458 0 /*src_x*/, 0 /*src_y*/,
459 p_vout->output.i_width, p_vout->output.i_height,
460 0 /*dest_x*/, 0 /*dest_y*/, i_width, i_height,
461 False /* Don't put True here or you'll waste your CPU */ );
463 XShmPutImage( p_vout->p_sys->p_display,
464 p_vout->p_sys->p_win->video_window,
465 p_vout->p_sys->p_win->gc, p_pic->p_sys->p_image,
466 0 /*src_x*/, 0 /*src_y*/, 0 /*dest_x*/, 0 /*dest_y*/,
467 p_vout->output.i_width, p_vout->output.i_height,
468 False /* Don't put True here ! */ );
472 #endif /* HAVE_SYS_SHM_H */
474 /* Use standard XPutImage -- this is gonna be slow ! */
475 #ifdef MODULE_NAME_IS_xvideo
476 XvPutImage( p_vout->p_sys->p_display, p_vout->p_sys->i_xvport,
477 p_vout->p_sys->p_win->video_window,
478 p_vout->p_sys->p_win->gc, p_pic->p_sys->p_image,
479 0 /*src_x*/, 0 /*src_y*/,
480 p_vout->output.i_width, p_vout->output.i_height,
481 0 /*dest_x*/, 0 /*dest_y*/, i_width, i_height );
483 XPutImage( p_vout->p_sys->p_display,
484 p_vout->p_sys->p_win->video_window,
485 p_vout->p_sys->p_win->gc, p_pic->p_sys->p_image,
486 0 /*src_x*/, 0 /*src_y*/, 0 /*dest_x*/, 0 /*dest_y*/,
487 p_vout->output.i_width, p_vout->output.i_height );
491 /* Make sure the command is sent now - do NOT use XFlush !*/
492 XSync( p_vout->p_sys->p_display, False );
494 vlc_mutex_unlock( &p_vout->p_sys->lock );
497 /*****************************************************************************
498 * ManageVideo: handle X11 events
499 *****************************************************************************
500 * This function should be called regularly by video output thread. It manages
501 * X11 events and allows window resizing. It returns a non null value on
503 *****************************************************************************/
504 static int ManageVideo( vout_thread_t *p_vout )
506 XEvent xevent; /* X11 event */
509 vlc_mutex_lock( &p_vout->p_sys->lock );
511 /* Handle events from the owner window */
512 if( p_vout->p_sys->p_win->owner_window )
514 while( XCheckWindowEvent( p_vout->p_sys->p_display,
515 p_vout->p_sys->p_win->owner_window,
516 StructureNotifyMask, &xevent ) == True )
518 /* ConfigureNotify event: prepare */
519 if( xevent.type == ConfigureNotify )
521 /* Update dimensions */
522 XResizeWindow( p_vout->p_sys->p_display,
523 p_vout->p_sys->p_win->base_window,
524 xevent.xconfigure.width,
525 xevent.xconfigure.height );
530 /* Handle X11 events: ConfigureNotify events are parsed to know if the
531 * output window's size changed, MapNotify and UnmapNotify to know if the
532 * window is mapped (and if the display is useful), and ClientMessages
533 * to intercept window destruction requests */
535 while( XCheckWindowEvent( p_vout->p_sys->p_display,
536 p_vout->p_sys->p_win->base_window,
537 StructureNotifyMask | KeyPressMask |
538 ButtonPressMask | ButtonReleaseMask |
539 PointerMotionMask | Button1MotionMask , &xevent )
542 /* ConfigureNotify event: prepare */
543 if( xevent.type == ConfigureNotify )
545 if( (unsigned int)xevent.xconfigure.width
546 != p_vout->p_sys->p_win->i_width
547 || (unsigned int)xevent.xconfigure.height
548 != p_vout->p_sys->p_win->i_height )
550 /* Update dimensions */
551 p_vout->i_changes |= VOUT_SIZE_CHANGE;
552 p_vout->p_sys->p_win->i_width = xevent.xconfigure.width;
553 p_vout->p_sys->p_win->i_height = xevent.xconfigure.height;
557 else if( xevent.type == KeyPress )
559 unsigned int state = xevent.xkey.state;
561 char i_key; /* ISO Latin-1 key */
563 /* We may have keys like F1 trough F12, ESC ... */
564 x_key_symbol = XKeycodeToKeysym( p_vout->p_sys->p_display,
565 xevent.xkey.keycode, 0 );
566 val.i_int = ConvertKey( (int)x_key_symbol );
568 xevent.xkey.state &= ~ShiftMask;
569 xevent.xkey.state &= ~ControlMask;
570 xevent.xkey.state &= ~Mod1Mask;
573 XLookupString( &xevent.xkey, &i_key, 1, NULL, NULL ) )
576 * The reason why I use this instead of XK_0 is that
577 * with XLookupString, we don't have to care about
584 if( state & ShiftMask )
586 val.i_int |= KEY_MODIFIER_SHIFT;
588 if( state & ControlMask )
590 val.i_int |= KEY_MODIFIER_CTRL;
592 if( state & Mod1Mask )
594 val.i_int |= KEY_MODIFIER_ALT;
596 var_Set( p_vout->p_vlc, "key-pressed", val );
600 else if( xevent.type == ButtonPress )
602 switch( ((XButtonEvent *)&xevent)->button )
605 var_Get( p_vout, "mouse-button-down", &val );
607 var_Set( p_vout, "mouse-button-down", val );
609 /* detect double-clicks */
610 if( ( ((XButtonEvent *)&xevent)->time -
611 p_vout->p_sys->i_time_button_last_pressed ) < 300 )
613 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
616 p_vout->p_sys->i_time_button_last_pressed =
617 ((XButtonEvent *)&xevent)->time;
620 var_Get( p_vout, "mouse-button-down", &val );
622 var_Set( p_vout, "mouse-button-down", val );
626 var_Get( p_vout, "mouse-button-down", &val );
628 var_Set( p_vout, "mouse-button-down", val );
632 var_Get( p_vout, "mouse-button-down", &val );
634 var_Set( p_vout, "mouse-button-down", val );
635 input_Seek( p_vout, 15, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
639 var_Get( p_vout, "mouse-button-down", &val );
641 var_Set( p_vout, "mouse-button-down", val );
642 input_Seek( p_vout, -15, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
647 else if( xevent.type == ButtonRelease )
649 switch( ((XButtonEvent *)&xevent)->button )
652 var_Get( p_vout, "mouse-button-down", &val );
654 var_Set( p_vout, "mouse-button-down", val );
656 val.b_bool = VLC_TRUE;
657 var_Set( p_vout, "mouse-clicked", val );
662 playlist_t *p_playlist;
664 var_Get( p_vout, "mouse-button-down", &val );
666 var_Set( p_vout, "mouse-button-down", val );
668 p_playlist = vlc_object_find( p_vout,
671 if( p_playlist != NULL )
674 var_Get( p_playlist, "intf-show", &val );
675 val.b_bool = !val.b_bool;
676 var_Set( p_playlist, "intf-show", val );
677 vlc_object_release( p_playlist );
684 intf_thread_t *p_intf;
685 playlist_t *p_playlist;
687 var_Get( p_vout, "mouse-button-down", &val );
689 var_Set( p_vout, "mouse-button-down", val );
690 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
694 p_intf->b_menu_change = 1;
695 vlc_object_release( p_intf );
698 p_playlist = vlc_object_find( p_vout,
701 if( p_playlist != NULL )
704 var_Set( p_playlist, "intf-popupmenu", val );
705 vlc_object_release( p_playlist );
711 var_Get( p_vout, "mouse-button-down", &val );
713 var_Set( p_vout, "mouse-button-down", val );
717 var_Get( p_vout, "mouse-button-down", &val );
719 var_Set( p_vout, "mouse-button-down", val );
725 else if( xevent.type == MotionNotify )
727 int i_width, i_height, i_x, i_y;
730 /* somewhat different use for vout_PlacePicture:
731 * here the values are needed to give to mouse coordinates
732 * in the original picture space */
733 vout_PlacePicture( p_vout, p_vout->p_sys->p_win->i_width,
734 p_vout->p_sys->p_win->i_height,
735 &i_x, &i_y, &i_width, &i_height );
737 val.i_int = ( xevent.xmotion.x - i_x )
738 * p_vout->render.i_width / i_width;
739 var_Set( p_vout, "mouse-x", val );
740 val.i_int = ( xevent.xmotion.y - i_y )
741 * p_vout->render.i_height / i_height;
742 var_Set( p_vout, "mouse-y", val );
744 val.b_bool = VLC_TRUE;
745 var_Set( p_vout, "mouse-moved", val );
747 p_vout->p_sys->i_time_mouse_last_moved = mdate();
748 if( ! p_vout->p_sys->b_mouse_pointer_visible )
750 ToggleCursor( p_vout );
753 else if( xevent.type == ReparentNotify /* XXX: why do we get this? */
754 || xevent.type == MapNotify
755 || xevent.type == UnmapNotify )
757 /* Ignore these events */
759 else /* Other events */
761 msg_Warn( p_vout, "unhandled event %d received", xevent.type );
765 /* Handle events for video output sub-window */
766 while( XCheckWindowEvent( p_vout->p_sys->p_display,
767 p_vout->p_sys->p_win->video_window,
768 ExposureMask, &xevent ) == True )
770 /* Window exposed (only handled if stream playback is paused) */
771 if( xevent.type == Expose )
773 if( ((XExposeEvent *)&xevent)->count == 0 )
775 /* (if this is the last a collection of expose events...) */
777 if( p_vout->p_vlc->p_input_bank->pp_input[0] != NULL )
779 if( PAUSE_S == p_vout->p_vlc->p_input_bank->pp_input[0]
780 ->stream.control.i_status )
782 /* XVideoDisplay( p_vout )*/;
790 /* ClientMessage event - only WM_PROTOCOLS with WM_DELETE_WINDOW data
791 * are handled - according to the man pages, the format is always 32
793 while( XCheckTypedEvent( p_vout->p_sys->p_display,
794 ClientMessage, &xevent ) )
796 if( (xevent.xclient.message_type == p_vout->p_sys->p_win->wm_protocols)
797 && ((Atom)xevent.xclient.data.l[0]
798 == p_vout->p_sys->p_win->wm_delete_window ) )
800 /* the user wants to close the window */
801 playlist_t * p_playlist =
802 (playlist_t *)vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
804 if( p_playlist != NULL )
806 playlist_Stop( p_playlist );
807 vlc_object_release( p_playlist );
815 if ( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
819 /* Update the object variable and trigger callback */
820 val.b_bool = !p_vout->b_fullscreen;
821 var_Set( p_vout, "fullscreen", val );
823 ToggleFullScreen( p_vout );
824 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
830 * (Needs to be placed after VOUT_FULLSREEN_CHANGE because we can activate
831 * the size flag inside the fullscreen routine)
833 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
835 int i_width, i_height, i_x, i_y;
837 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
839 #ifdef MODULE_NAME_IS_x11
840 /* We need to signal the vout thread about the size change because it
841 * is doing the rescaling */
842 p_vout->i_changes |= VOUT_SIZE_CHANGE;
845 vout_PlacePicture( p_vout, p_vout->p_sys->p_win->i_width,
846 p_vout->p_sys->p_win->i_height,
847 &i_x, &i_y, &i_width, &i_height );
849 XMoveResizeWindow( p_vout->p_sys->p_display,
850 p_vout->p_sys->p_win->video_window,
851 i_x, i_y, i_width, i_height );
854 /* Autohide Cursour */
855 if( mdate() - p_vout->p_sys->i_time_mouse_last_moved > 2000000 )
857 /* Hide the mouse automatically */
858 if( p_vout->p_sys->b_mouse_pointer_visible )
860 ToggleCursor( p_vout );
864 vlc_mutex_unlock( &p_vout->p_sys->lock );
869 /*****************************************************************************
870 * EndVideo: terminate X11 video thread output method
871 *****************************************************************************
872 * Destroy the X11 XImages created by Init. It is called at the end of
873 * the thread, but also each time the window is resized.
874 *****************************************************************************/
875 static void EndVideo( vout_thread_t *p_vout )
879 /* Free the direct buffers we allocated */
880 for( i_index = I_OUTPUTPICTURES ; i_index ; )
883 FreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
887 /* following functions are local */
889 /*****************************************************************************
890 * CreateWindow: open and set-up X11 main window
891 *****************************************************************************/
892 static int CreateWindow( vout_thread_t *p_vout, x11_window_t *p_win )
894 XSizeHints xsize_hints;
895 XSetWindowAttributes xwindow_attributes;
899 vlc_bool_t b_expose = VLC_FALSE;
900 vlc_bool_t b_configure_notify = VLC_FALSE;
901 vlc_bool_t b_map_notify = VLC_FALSE;
903 /* Prepare window manager hints and properties */
904 p_win->wm_protocols =
905 XInternAtom( p_vout->p_sys->p_display, "WM_PROTOCOLS", True );
906 p_win->wm_delete_window =
907 XInternAtom( p_vout->p_sys->p_display, "WM_DELETE_WINDOW", True );
909 /* Never have a 0-pixel-wide window */
910 xsize_hints.min_width = 2;
911 xsize_hints.min_height = 1;
913 /* Prepare window attributes */
914 xwindow_attributes.backing_store = Always; /* save the hidden part */
915 xwindow_attributes.background_pixel = BlackPixel(p_vout->p_sys->p_display,
916 p_vout->p_sys->i_screen);
917 xwindow_attributes.event_mask = ExposureMask | StructureNotifyMask;
919 if( !p_vout->b_fullscreen )
921 p_win->owner_window =
922 (Window)vout_RequestWindow( p_vout, &p_win->i_x, &p_win->i_y,
923 &p_win->i_width, &p_win->i_height );
925 xsize_hints.base_width = xsize_hints.width = p_win->i_width;
926 xsize_hints.base_height = xsize_hints.height = p_win->i_height;
927 xsize_hints.flags = PSize | PMinSize;
929 if( p_win->i_x >=0 || p_win->i_y >= 0 )
931 xsize_hints.x = p_win->i_x;
932 xsize_hints.y = p_win->i_y;
933 xsize_hints.flags |= PPosition;
938 /* Fullscreen window size and position */
939 p_win->owner_window = 0;
940 p_win->i_x = p_win->i_y = 0;
942 DisplayWidth( p_vout->p_sys->p_display, p_vout->p_sys->i_screen );
944 DisplayHeight( p_vout->p_sys->p_display, p_vout->p_sys->i_screen );
947 if( !p_win->owner_window )
949 /* Create the window and set hints - the window must receive
950 * ConfigureNotify events, and until it is displayed, Expose and
951 * MapNotify events. */
954 XCreateWindow( p_vout->p_sys->p_display,
955 DefaultRootWindow( p_vout->p_sys->p_display ),
956 p_win->i_x, p_win->i_y,
957 p_win->i_width, p_win->i_height,
960 CWBackingStore | CWBackPixel | CWEventMask,
961 &xwindow_attributes );
963 if( !p_vout->b_fullscreen )
965 /* Set window manager hints and properties: size hints, command,
966 * window's name, and accepted protocols */
967 XSetWMNormalHints( p_vout->p_sys->p_display,
968 p_win->base_window, &xsize_hints );
969 XSetCommand( p_vout->p_sys->p_display, p_win->base_window,
970 p_vout->p_vlc->ppsz_argv, p_vout->p_vlc->i_argc );
972 XStoreName( p_vout->p_sys->p_display, p_win->base_window,
973 #ifdef MODULE_NAME_IS_x11
974 VOUT_TITLE " (X11 output)"
976 VOUT_TITLE " (XVideo output)"
984 unsigned int dummy2, dummy3;
986 /* Select events we are interested in. */
987 XSelectInput( p_vout->p_sys->p_display, p_win->owner_window,
988 StructureNotifyMask );
990 /* Get the parent window's geometry information */
991 XGetGeometry( p_vout->p_sys->p_display, p_win->owner_window,
992 &dummy1, &dummy2, &dummy3,
997 /* We are already configured */
998 b_configure_notify = VLC_TRUE;
1000 /* From man XSelectInput: only one client at a time can select a
1001 * ButtonPress event, so we need to open a new window anyway. */
1002 p_win->base_window =
1003 XCreateWindow( p_vout->p_sys->p_display,
1004 p_win->owner_window,
1006 p_win->i_width, p_win->i_height,
1008 0, CopyFromParent, 0,
1009 CWBackingStore | CWBackPixel | CWEventMask,
1010 &xwindow_attributes );
1013 if( (p_win->wm_protocols == None) /* use WM_DELETE_WINDOW */
1014 || (p_win->wm_delete_window == None)
1015 || !XSetWMProtocols( p_vout->p_sys->p_display, p_win->base_window,
1016 &p_win->wm_delete_window, 1 ) )
1018 /* WM_DELETE_WINDOW is not supported by window manager */
1019 msg_Warn( p_vout, "missing or bad window manager" );
1022 /* Creation of a graphic context that doesn't generate a GraphicsExpose
1023 * event when using functions like XCopyArea */
1024 xgcvalues.graphics_exposures = False;
1025 p_win->gc = XCreateGC( p_vout->p_sys->p_display,
1027 GCGraphicsExposures, &xgcvalues );
1029 /* Send orders to server, and wait until window is displayed - three
1030 * events must be received: a MapNotify event, an Expose event allowing
1031 * drawing in the window, and a ConfigureNotify to get the window
1032 * dimensions. Once those events have been received, only
1033 * ConfigureNotify events need to be received. */
1034 XMapWindow( p_vout->p_sys->p_display, p_win->base_window );
1037 XNextEvent( p_vout->p_sys->p_display, &xevent);
1038 if( (xevent.type == Expose)
1039 && (xevent.xexpose.window == p_win->base_window) )
1041 b_expose = VLC_TRUE;
1043 else if( (xevent.type == MapNotify)
1044 && (xevent.xmap.window == p_win->base_window) )
1046 b_map_notify = VLC_TRUE;
1048 else if( (xevent.type == ConfigureNotify)
1049 && (xevent.xconfigure.window == p_win->base_window) )
1051 b_configure_notify = VLC_TRUE;
1052 p_win->i_width = xevent.xconfigure.width;
1053 p_win->i_height = xevent.xconfigure.height;
1055 } while( !( b_expose && b_configure_notify && b_map_notify ) );
1057 XSelectInput( p_vout->p_sys->p_display, p_win->base_window,
1058 StructureNotifyMask | KeyPressMask |
1059 ButtonPressMask | ButtonReleaseMask |
1060 PointerMotionMask );
1062 #ifdef MODULE_NAME_IS_x11
1063 if( XDefaultDepth(p_vout->p_sys->p_display, p_vout->p_sys->i_screen) == 8 )
1065 /* Allocate a new palette */
1066 p_vout->p_sys->colormap =
1067 XCreateColormap( p_vout->p_sys->p_display,
1068 DefaultRootWindow( p_vout->p_sys->p_display ),
1069 DefaultVisual( p_vout->p_sys->p_display,
1070 p_vout->p_sys->i_screen ),
1073 xwindow_attributes.colormap = p_vout->p_sys->colormap;
1074 XChangeWindowAttributes( p_vout->p_sys->p_display, p_win->base_window,
1075 CWColormap, &xwindow_attributes );
1079 /* Create video output sub-window. */
1080 p_win->video_window = XCreateSimpleWindow(
1081 p_vout->p_sys->p_display,
1082 p_win->base_window, 0, 0,
1083 p_win->i_width, p_win->i_height,
1085 BlackPixel( p_vout->p_sys->p_display,
1086 p_vout->p_sys->i_screen ),
1087 WhitePixel( p_vout->p_sys->p_display,
1088 p_vout->p_sys->i_screen ) );
1090 XSetWindowBackground( p_vout->p_sys->p_display, p_win->video_window,
1091 BlackPixel( p_vout->p_sys->p_display,
1092 p_vout->p_sys->i_screen ) );
1094 XMapWindow( p_vout->p_sys->p_display, p_win->video_window );
1095 XSelectInput( p_vout->p_sys->p_display, p_win->video_window,
1098 /* make sure the video window will be centered in the next ManageVideo() */
1099 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1101 /* If the cursor was formerly blank than blank it again */
1102 if( !p_vout->p_sys->b_mouse_pointer_visible )
1104 ToggleCursor( p_vout );
1105 ToggleCursor( p_vout );
1108 /* Do NOT use XFlush here ! */
1109 XSync( p_vout->p_sys->p_display, False );
1111 /* At this stage, the window is open, displayed, and ready to
1113 p_vout->p_sys->p_win = p_win;
1118 /*****************************************************************************
1119 * DestroyWindow: destroy the window
1120 *****************************************************************************
1122 *****************************************************************************/
1123 static void DestroyWindow( vout_thread_t *p_vout, x11_window_t *p_win )
1125 /* Do NOT use XFlush here ! */
1126 XSync( p_vout->p_sys->p_display, False );
1128 XDestroyWindow( p_vout->p_sys->p_display, p_win->video_window );
1129 XFreeGC( p_vout->p_sys->p_display, p_win->gc );
1131 XUnmapWindow( p_vout->p_sys->p_display, p_win->base_window );
1132 XDestroyWindow( p_vout->p_sys->p_display, p_win->base_window );
1134 if( p_win->owner_window )
1135 vout_ReleaseWindow( p_vout, (void *)p_win->owner_window );
1138 /*****************************************************************************
1139 * NewPicture: allocate a picture
1140 *****************************************************************************
1141 * Returns 0 on success, -1 otherwise
1142 *****************************************************************************/
1143 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
1145 #ifdef MODULE_NAME_IS_xvideo
1149 /* We know the chroma, allocate a buffer which will be used
1150 * directly by the decoder */
1151 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
1153 if( p_pic->p_sys == NULL )
1158 /* Fill in picture_t fields */
1159 vout_InitPicture( VLC_OBJECT(p_vout), p_pic, p_vout->output.i_chroma,
1160 p_vout->output.i_width, p_vout->output.i_height,
1161 p_vout->output.i_aspect );
1163 #ifdef HAVE_SYS_SHM_H
1164 if( p_vout->p_sys->b_shm )
1166 /* Create image using XShm extension */
1167 p_pic->p_sys->p_image =
1168 CreateShmImage( p_vout, p_vout->p_sys->p_display,
1169 # ifdef MODULE_NAME_IS_xvideo
1170 p_vout->p_sys->i_xvport,
1171 VLC2X11_FOURCC(p_vout->output.i_chroma),
1173 p_vout->p_sys->p_visual,
1174 p_vout->p_sys->i_screen_depth,
1176 &p_pic->p_sys->shminfo,
1177 p_vout->output.i_width, p_vout->output.i_height );
1180 #endif /* HAVE_SYS_SHM_H */
1182 /* Create image without XShm extension */
1183 p_pic->p_sys->p_image =
1184 CreateImage( p_vout, p_vout->p_sys->p_display,
1185 #ifdef MODULE_NAME_IS_xvideo
1186 p_vout->p_sys->i_xvport,
1187 VLC2X11_FOURCC(p_vout->output.i_chroma),
1188 p_pic->format.i_bits_per_pixel,
1190 p_vout->p_sys->p_visual,
1191 p_vout->p_sys->i_screen_depth,
1192 p_vout->p_sys->i_bytes_per_pixel,
1194 p_vout->output.i_width, p_vout->output.i_height );
1197 if( p_pic->p_sys->p_image == NULL )
1199 free( p_pic->p_sys );
1203 switch( p_vout->output.i_chroma )
1205 #ifdef MODULE_NAME_IS_xvideo
1206 case VLC_FOURCC('I','4','2','0'):
1207 case VLC_FOURCC('Y','V','1','2'):
1208 case VLC_FOURCC('Y','2','1','1'):
1209 case VLC_FOURCC('Y','U','Y','2'):
1210 case VLC_FOURCC('U','Y','V','Y'):
1211 case VLC_FOURCC('R','V','1','5'):
1212 case VLC_FOURCC('R','V','1','6'):
1213 case VLC_FOURCC('R','V','2','4'): /* Fixme: pixel pitch == 4 ? */
1214 case VLC_FOURCC('R','V','3','2'):
1216 for( i_plane = 0; i_plane < p_pic->p_sys->p_image->num_planes;
1219 p_pic->p[i_plane].p_pixels = p_pic->p_sys->p_image->data
1220 + p_pic->p_sys->p_image->offsets[i_plane];
1221 p_pic->p[i_plane].i_pitch =
1222 p_pic->p_sys->p_image->pitches[i_plane];
1224 if( p_vout->output.i_chroma == VLC_FOURCC('Y','V','1','2') )
1226 /* U and V inverted compared to I420
1227 * Fixme: this should be handled by the vout core */
1228 p_pic->U_PIXELS = p_pic->p_sys->p_image->data
1229 + p_pic->p_sys->p_image->offsets[2];
1230 p_pic->V_PIXELS = p_pic->p_sys->p_image->data
1231 + p_pic->p_sys->p_image->offsets[1];
1236 case VLC_FOURCC('R','G','B','2'):
1237 case VLC_FOURCC('R','V','1','6'):
1238 case VLC_FOURCC('R','V','1','5'):
1239 case VLC_FOURCC('R','V','2','4'):
1240 case VLC_FOURCC('R','V','3','2'):
1242 p_pic->p->i_lines = p_pic->p_sys->p_image->height;
1243 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1244 + p_pic->p_sys->p_image->xoffset;
1245 p_pic->p->i_pitch = p_pic->p_sys->p_image->bytes_per_line;
1247 /* p_pic->p->i_pixel_pitch = 4 for RV24 but this should be set
1248 * properly by vout_InitPicture() */
1249 p_pic->p->i_visible_pitch = p_pic->p->i_pixel_pitch
1250 * p_pic->p_sys->p_image->width;
1255 /* Unknown chroma, tell the guy to get lost */
1256 IMAGE_FREE( p_pic->p_sys->p_image );
1257 free( p_pic->p_sys );
1258 msg_Err( p_vout, "never heard of chroma 0x%.8x (%4.4s)",
1259 p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma );
1260 p_pic->i_planes = 0;
1267 /*****************************************************************************
1268 * FreePicture: destroy a picture allocated with NewPicture
1269 *****************************************************************************
1270 * Destroy XImage AND associated data. If using Shm, detach shared memory
1271 * segment from server and process, then free it. The XDestroyImage manpage
1272 * says that both the image structure _and_ the data pointed to by the
1273 * image structure are freed, so no need to free p_image->data.
1274 *****************************************************************************/
1275 static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
1277 /* The order of operations is correct */
1278 #ifdef HAVE_SYS_SHM_H
1279 if( p_vout->p_sys->b_shm )
1281 XShmDetach( p_vout->p_sys->p_display, &p_pic->p_sys->shminfo );
1282 IMAGE_FREE( p_pic->p_sys->p_image );
1284 shmctl( p_pic->p_sys->shminfo.shmid, IPC_RMID, 0 );
1285 if( shmdt( p_pic->p_sys->shminfo.shmaddr ) )
1287 msg_Err( p_vout, "cannot detach shared memory (%s)",
1294 IMAGE_FREE( p_pic->p_sys->p_image );
1297 /* Do NOT use XFlush here ! */
1298 XSync( p_vout->p_sys->p_display, False );
1300 free( p_pic->p_sys );
1303 /*****************************************************************************
1304 * ToggleFullScreen: Enable or disable full screen mode
1305 *****************************************************************************
1306 * This function will switch between fullscreen and window mode.
1307 *****************************************************************************/
1308 static void ToggleFullScreen ( vout_thread_t *p_vout )
1312 mwmhints_t mwmhints;
1313 XSetWindowAttributes attributes;
1315 #ifdef HAVE_XINERAMA
1319 p_vout->b_fullscreen = !p_vout->b_fullscreen;
1321 if( p_vout->b_fullscreen )
1323 msg_Dbg( p_vout, "entering fullscreen mode" );
1325 p_vout->p_sys->b_altfullscreen =
1326 config_GetInt( p_vout, MODULE_STRING "-altfullscreen" );
1328 XUnmapWindow( p_vout->p_sys->p_display,
1329 p_vout->p_sys->p_win->base_window);
1331 p_vout->p_sys->p_win = &p_vout->p_sys->fullscreen_window;
1333 CreateWindow( p_vout, p_vout->p_sys->p_win );
1335 /* To my knowledge there are two ways to create a borderless window.
1336 * There's the generic way which is to tell x to bypass the window
1337 * manager, but this creates problems with the focus of other
1339 * The other way is to use the motif property "_MOTIF_WM_HINTS" which
1340 * luckily seems to be supported by most window managers. */
1341 if( !p_vout->p_sys->b_altfullscreen )
1343 mwmhints.flags = MWM_HINTS_DECORATIONS;
1344 mwmhints.decorations = False;
1346 prop = XInternAtom( p_vout->p_sys->p_display, "_MOTIF_WM_HINTS",
1348 XChangeProperty( p_vout->p_sys->p_display,
1349 p_vout->p_sys->p_win->base_window,
1350 prop, prop, 32, PropModeReplace,
1351 (unsigned char *)&mwmhints,
1352 PROP_MWM_HINTS_ELEMENTS );
1356 /* brute force way to remove decorations */
1357 attributes.override_redirect = True;
1358 XChangeWindowAttributes( p_vout->p_sys->p_display,
1359 p_vout->p_sys->p_win->base_window,
1363 /* Make sure the change is effective */
1364 XReparentWindow( p_vout->p_sys->p_display,
1365 p_vout->p_sys->p_win->base_window,
1366 DefaultRootWindow( p_vout->p_sys->p_display ),
1370 if( p_vout->p_sys->b_net_wm_state_fullscreen )
1372 XClientMessageEvent event;
1374 memset( &event, 0, sizeof( XClientMessageEvent ) );
1376 event.type = ClientMessage;
1377 event.message_type = p_vout->p_sys->net_wm_state;
1378 event.display = p_vout->p_sys->p_display;
1379 event.window = p_vout->p_sys->p_win->base_window;
1381 event.data.l[ 0 ] = 1; /* set property */
1382 event.data.l[ 1 ] = p_vout->p_sys->net_wm_state_fullscreen;
1384 XSendEvent( p_vout->p_sys->p_display,
1385 DefaultRootWindow( p_vout->p_sys->p_display ),
1386 False, SubstructureRedirectMask,
1390 /* Make sure the change is effective */
1391 XReparentWindow( p_vout->p_sys->p_display,
1392 p_vout->p_sys->p_win->base_window,
1393 DefaultRootWindow( p_vout->p_sys->p_display ),
1396 #ifdef HAVE_XINERAMA
1397 if( XineramaQueryExtension( p_vout->p_sys->p_display, &i_d1, &i_d2 ) &&
1398 XineramaIsActive( p_vout->p_sys->p_display ) )
1400 XineramaScreenInfo *screens; /* infos for xinerama */
1403 msg_Dbg( p_vout, "using XFree Xinerama extension");
1405 #define SCREEN p_vout->p_sys->p_win->i_screen
1407 /* Get Informations about Xinerama (num of screens) */
1408 screens = XineramaQueryScreens( p_vout->p_sys->p_display,
1412 SCREEN = config_GetInt( p_vout,
1413 MODULE_STRING "-xineramascreen" );
1415 /* just check that user has entered a good value */
1416 if( SCREEN >= i_num_screens || SCREEN < 0 )
1418 msg_Dbg( p_vout, "requested screen number invalid" );
1422 /* Get the X/Y upper left corner coordinate of the above screen */
1423 p_vout->p_sys->p_win->i_x = screens[SCREEN].x_org;
1424 p_vout->p_sys->p_win->i_y = screens[SCREEN].y_org;
1426 /* Set the Height/width to the screen resolution */
1427 p_vout->p_sys->p_win->i_width = screens[SCREEN].width;
1428 p_vout->p_sys->p_win->i_height = screens[SCREEN].height;
1437 XMoveResizeWindow( p_vout->p_sys->p_display,
1438 p_vout->p_sys->p_win->base_window,
1439 p_vout->p_sys->p_win->i_x,
1440 p_vout->p_sys->p_win->i_y,
1441 p_vout->p_sys->p_win->i_width,
1442 p_vout->p_sys->p_win->i_height );
1446 msg_Dbg( p_vout, "leaving fullscreen mode" );
1447 DestroyWindow( p_vout, &p_vout->p_sys->fullscreen_window );
1448 p_vout->p_sys->p_win = &p_vout->p_sys->original_window;
1450 XMapWindow( p_vout->p_sys->p_display,
1451 p_vout->p_sys->p_win->base_window);
1454 /* Unfortunately, using XSync() here is not enough to ensure the
1455 * window has already been mapped because the XMapWindow() request
1456 * has not necessarily been sent directly to our window (remember,
1457 * the call is first redirected to the window manager) */
1460 XWindowEvent( p_vout->p_sys->p_display,
1461 p_vout->p_sys->p_win->base_window,
1462 StructureNotifyMask, &xevent );
1463 } while( xevent.type != MapNotify );
1465 /* Be careful, this can generate a BadMatch error if the window is not
1466 * already mapped by the server (see above) */
1467 XSetInputFocus(p_vout->p_sys->p_display,
1468 p_vout->p_sys->p_win->base_window,
1472 /* signal that the size needs to be updated */
1473 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1476 /*****************************************************************************
1477 * EnableXScreenSaver: enable screen saver
1478 *****************************************************************************
1479 * This function enables the screen saver on a display after it has been
1480 * disabled by XDisableScreenSaver.
1481 * FIXME: what happens if multiple vlc sessions are running at the same
1483 *****************************************************************************/
1484 static void EnableXScreenSaver( vout_thread_t *p_vout )
1486 #ifdef DPMSINFO_IN_DPMS_H
1490 if( p_vout->p_sys->i_ss_timeout )
1492 XSetScreenSaver( p_vout->p_sys->p_display, p_vout->p_sys->i_ss_timeout,
1493 p_vout->p_sys->i_ss_interval,
1494 p_vout->p_sys->i_ss_blanking,
1495 p_vout->p_sys->i_ss_exposure );
1498 /* Restore DPMS settings */
1499 #ifdef DPMSINFO_IN_DPMS_H
1500 if( DPMSQueryExtension( p_vout->p_sys->p_display, &dummy, &dummy ) )
1502 if( p_vout->p_sys->b_ss_dpms )
1504 DPMSEnable( p_vout->p_sys->p_display );
1510 /*****************************************************************************
1511 * DisableXScreenSaver: disable screen saver
1512 *****************************************************************************
1513 * See XEnableXScreenSaver
1514 *****************************************************************************/
1515 static void DisableXScreenSaver( vout_thread_t *p_vout )
1517 #ifdef DPMSINFO_IN_DPMS_H
1521 /* Save screen saver informations */
1522 XGetScreenSaver( p_vout->p_sys->p_display, &p_vout->p_sys->i_ss_timeout,
1523 &p_vout->p_sys->i_ss_interval,
1524 &p_vout->p_sys->i_ss_blanking,
1525 &p_vout->p_sys->i_ss_exposure );
1527 /* Disable screen saver */
1528 if( p_vout->p_sys->i_ss_timeout )
1530 XSetScreenSaver( p_vout->p_sys->p_display, 0,
1531 p_vout->p_sys->i_ss_interval,
1532 p_vout->p_sys->i_ss_blanking,
1533 p_vout->p_sys->i_ss_exposure );
1537 #ifdef DPMSINFO_IN_DPMS_H
1538 if( DPMSQueryExtension( p_vout->p_sys->p_display, &dummy, &dummy ) )
1541 /* Save DPMS current state */
1542 DPMSInfo( p_vout->p_sys->p_display, &unused,
1543 &p_vout->p_sys->b_ss_dpms );
1544 DPMSDisable( p_vout->p_sys->p_display );
1549 /*****************************************************************************
1550 * CreateCursor: create a blank mouse pointer
1551 *****************************************************************************/
1552 static void CreateCursor( vout_thread_t *p_vout )
1554 XColor cursor_color;
1556 p_vout->p_sys->cursor_pixmap =
1557 XCreatePixmap( p_vout->p_sys->p_display,
1558 DefaultRootWindow( p_vout->p_sys->p_display ),
1561 XParseColor( p_vout->p_sys->p_display,
1562 XCreateColormap( p_vout->p_sys->p_display,
1564 p_vout->p_sys->p_display ),
1566 p_vout->p_sys->p_display,
1567 p_vout->p_sys->i_screen ),
1569 "black", &cursor_color );
1571 p_vout->p_sys->blank_cursor =
1572 XCreatePixmapCursor( p_vout->p_sys->p_display,
1573 p_vout->p_sys->cursor_pixmap,
1574 p_vout->p_sys->cursor_pixmap,
1575 &cursor_color, &cursor_color, 1, 1 );
1578 /*****************************************************************************
1579 * DestroyCursor: destroy the blank mouse pointer
1580 *****************************************************************************/
1581 static void DestroyCursor( vout_thread_t *p_vout )
1583 XFreePixmap( p_vout->p_sys->p_display, p_vout->p_sys->cursor_pixmap );
1586 /*****************************************************************************
1587 * ToggleCursor: hide or show the mouse pointer
1588 *****************************************************************************
1589 * This function hides the X pointer if it is visible by setting the pointer
1590 * sprite to a blank one. To show it again, we disable the sprite.
1591 *****************************************************************************/
1592 static void ToggleCursor( vout_thread_t *p_vout )
1594 if( p_vout->p_sys->b_mouse_pointer_visible )
1596 XDefineCursor( p_vout->p_sys->p_display,
1597 p_vout->p_sys->p_win->base_window,
1598 p_vout->p_sys->blank_cursor );
1599 p_vout->p_sys->b_mouse_pointer_visible = 0;
1603 XUndefineCursor( p_vout->p_sys->p_display,
1604 p_vout->p_sys->p_win->base_window );
1605 p_vout->p_sys->b_mouse_pointer_visible = 1;
1609 #ifdef MODULE_NAME_IS_xvideo
1610 /*****************************************************************************
1611 * XVideoGetPort: get YUV12 port
1612 *****************************************************************************/
1613 static int XVideoGetPort( vout_thread_t *p_vout,
1614 vlc_fourcc_t i_chroma, vlc_fourcc_t *pi_newchroma )
1616 XvAdaptorInfo *p_adaptor;
1618 int i_adaptor, i_num_adaptors, i_requested_adaptor;
1619 int i_selected_port;
1621 switch( XvQueryExtension( p_vout->p_sys->p_display, &i, &i, &i, &i, &i ) )
1626 case XvBadExtension:
1627 msg_Warn( p_vout, "XvBadExtension" );
1631 msg_Warn( p_vout, "XvBadAlloc" );
1635 msg_Warn( p_vout, "XvQueryExtension failed" );
1639 switch( XvQueryAdaptors( p_vout->p_sys->p_display,
1640 DefaultRootWindow( p_vout->p_sys->p_display ),
1641 &i_num_adaptors, &p_adaptor ) )
1646 case XvBadExtension:
1647 msg_Warn( p_vout, "XvBadExtension for XvQueryAdaptors" );
1651 msg_Warn( p_vout, "XvBadAlloc for XvQueryAdaptors" );
1655 msg_Warn( p_vout, "XvQueryAdaptors failed" );
1659 i_selected_port = -1;
1660 i_requested_adaptor = config_GetInt( p_vout, "xvideo-adaptor" );
1662 for( i_adaptor = 0; i_adaptor < i_num_adaptors; ++i_adaptor )
1664 XvImageFormatValues *p_formats;
1665 int i_format, i_num_formats;
1668 /* If we requested an adaptor and it's not this one, we aren't
1670 if( i_requested_adaptor != -1 && i_adaptor != i_requested_adaptor )
1675 /* If the adaptor doesn't have the required properties, skip it */
1676 if( !( p_adaptor[ i_adaptor ].type & XvInputMask ) ||
1677 !( p_adaptor[ i_adaptor ].type & XvImageMask ) )
1682 /* Check that adaptor supports our requested format... */
1683 p_formats = XvListImageFormats( p_vout->p_sys->p_display,
1684 p_adaptor[i_adaptor].base_id,
1688 i_format < i_num_formats && ( i_selected_port == -1 );
1691 /* Code removed, we can get this through xvinfo anyway */
1693 XvEncodingInfo *p_enc;
1694 int i_enc, i_num_encodings;
1695 XvAttribute *p_attr;
1696 int i_attr, i_num_attributes;
1699 /* If this is not the format we want, or at least a
1700 * similar one, forget it */
1701 if( !vout_ChromaCmp( p_formats[ i_format ].id, i_chroma ) )
1706 /* Look for the first available port supporting this format */
1707 for( i_port = p_adaptor[i_adaptor].base_id;
1708 ( i_port < (int)(p_adaptor[i_adaptor].base_id
1709 + p_adaptor[i_adaptor].num_ports) )
1710 && ( i_selected_port == -1 );
1713 if( XvGrabPort( p_vout->p_sys->p_display, i_port, CurrentTime )
1716 i_selected_port = i_port;
1717 *pi_newchroma = p_formats[ i_format ].id;
1721 /* If no free port was found, forget it */
1722 if( i_selected_port == -1 )
1727 /* If we found a port, print information about it */
1728 msg_Dbg( p_vout, "adaptor %i, port %i, format 0x%x (%4.4s) %s",
1729 i_adaptor, i_selected_port, p_formats[ i_format ].id,
1730 (char *)&p_formats[ i_format ].id,
1731 ( p_formats[ i_format ].format == XvPacked ) ?
1732 "packed" : "planar" );
1735 msg_Dbg( p_vout, " encoding list:" );
1737 if( XvQueryEncodings( p_vout->p_sys->p_display, i_selected_port,
1738 &i_num_encodings, &p_enc )
1741 msg_Dbg( p_vout, " XvQueryEncodings failed" );
1745 for( i_enc = 0; i_enc < i_num_encodings; i_enc++ )
1747 msg_Dbg( p_vout, " id=%ld, name=%s, size=%ldx%ld,"
1748 " numerator=%d, denominator=%d",
1749 p_enc[i_enc].encoding_id, p_enc[i_enc].name,
1750 p_enc[i_enc].width, p_enc[i_enc].height,
1751 p_enc[i_enc].rate.numerator,
1752 p_enc[i_enc].rate.denominator );
1757 XvFreeEncodingInfo( p_enc );
1760 msg_Dbg( p_vout, " attribute list:" );
1761 p_attr = XvQueryPortAttributes( p_vout->p_sys->p_display,
1763 &i_num_attributes );
1764 for( i_attr = 0; i_attr < i_num_attributes; i_attr++ )
1766 msg_Dbg( p_vout, " name=%s, flags=[%s%s ], min=%i, max=%i",
1767 p_attr[i_attr].name,
1768 (p_attr[i_attr].flags & XvGettable) ? " get" : "",
1769 (p_attr[i_attr].flags & XvSettable) ? " set" : "",
1770 p_attr[i_attr].min_value, p_attr[i_attr].max_value );
1773 if( p_attr != NULL )
1780 if( p_formats != NULL )
1787 if( i_num_adaptors > 0 )
1789 XvFreeAdaptorInfo( p_adaptor );
1792 if( i_selected_port == -1 )
1794 int i_chroma_tmp = X112VLC_FOURCC( i_chroma );
1795 if( i_requested_adaptor == -1 )
1797 msg_Warn( p_vout, "no free XVideo port found for format "
1798 "0x%.8x (%4.4s)", i_chroma_tmp, (char*)&i_chroma_tmp );
1802 msg_Warn( p_vout, "XVideo adaptor %i does not have a free "
1803 "XVideo port for format 0x%.8x (%4.4s)",
1804 i_requested_adaptor, i_chroma_tmp, (char*)&i_chroma_tmp );
1808 return i_selected_port;
1811 /*****************************************************************************
1812 * XVideoReleasePort: release YUV12 port
1813 *****************************************************************************/
1814 static void XVideoReleasePort( vout_thread_t *p_vout, int i_port )
1816 XvUngrabPort( p_vout->p_sys->p_display, i_port, CurrentTime );
1820 /*****************************************************************************
1821 * InitDisplay: open and initialize X11 device
1822 *****************************************************************************
1823 * Create a window according to video output given size, and set other
1824 * properties according to the display properties.
1825 *****************************************************************************/
1826 static int InitDisplay( vout_thread_t *p_vout )
1828 #ifdef MODULE_NAME_IS_x11
1829 XPixmapFormatValues * p_formats; /* pixmap formats */
1830 XVisualInfo * p_xvisual; /* visuals informations */
1831 XVisualInfo xvisual_template; /* visual template */
1832 int i_count; /* array size */
1835 #ifdef HAVE_SYS_SHM_H
1836 p_vout->p_sys->b_shm = 0;
1838 if( config_GetInt( p_vout, MODULE_STRING "-shm" ) )
1841 /* FIXME: As of 2001-03-16, XFree4 for MacOS X does not support Xshm */
1843 p_vout->p_sys->b_shm =
1844 ( XShmQueryExtension( p_vout->p_sys->p_display ) == True );
1847 if( !p_vout->p_sys->b_shm )
1849 msg_Warn( p_vout, "XShm video extension is unavailable" );
1854 msg_Dbg( p_vout, "disabling XShm video extension" );
1858 msg_Warn( p_vout, "XShm video extension is unavailable" );
1862 #ifdef MODULE_NAME_IS_xvideo
1863 /* XXX The brightness and contrast values should be read from environment
1864 * XXX variables... */
1866 XVideoSetAttribute( p_vout, "XV_BRIGHTNESS", 0.5 );
1867 XVideoSetAttribute( p_vout, "XV_CONTRAST", 0.5 );
1871 #ifdef MODULE_NAME_IS_x11
1872 /* Initialize structure */
1873 p_vout->p_sys->i_screen = DefaultScreen( p_vout->p_sys->p_display );
1875 /* Get screen depth */
1876 p_vout->p_sys->i_screen_depth = XDefaultDepth( p_vout->p_sys->p_display,
1877 p_vout->p_sys->i_screen );
1878 switch( p_vout->p_sys->i_screen_depth )
1882 * Screen depth is 8bpp. Use PseudoColor visual with private colormap.
1884 xvisual_template.screen = p_vout->p_sys->i_screen;
1885 xvisual_template.class = DirectColor;
1886 p_xvisual = XGetVisualInfo( p_vout->p_sys->p_display,
1887 VisualScreenMask | VisualClassMask,
1888 &xvisual_template, &i_count );
1889 if( p_xvisual == NULL )
1891 msg_Err( p_vout, "no PseudoColor visual available" );
1892 return VLC_EGENERIC;
1894 p_vout->p_sys->i_bytes_per_pixel = 1;
1895 p_vout->output.pf_setpalette = SetPalette;
1902 * Screen depth is higher than 8bpp. TrueColor visual is used.
1904 xvisual_template.screen = p_vout->p_sys->i_screen;
1905 xvisual_template.class = TrueColor;
1906 p_xvisual = XGetVisualInfo( p_vout->p_sys->p_display,
1907 VisualScreenMask | VisualClassMask,
1908 &xvisual_template, &i_count );
1909 if( p_xvisual == NULL )
1911 msg_Err( p_vout, "no TrueColor visual available" );
1912 return VLC_EGENERIC;
1915 p_vout->output.i_rmask = p_xvisual->red_mask;
1916 p_vout->output.i_gmask = p_xvisual->green_mask;
1917 p_vout->output.i_bmask = p_xvisual->blue_mask;
1919 /* There is no difference yet between 3 and 4 Bpp. The only way
1920 * to find the actual number of bytes per pixel is to list supported
1921 * pixmap formats. */
1922 p_formats = XListPixmapFormats( p_vout->p_sys->p_display, &i_count );
1923 p_vout->p_sys->i_bytes_per_pixel = 0;
1925 for( ; i_count-- ; p_formats++ )
1927 /* Under XFree4.0, the list contains pixmap formats available
1928 * through all video depths ; so we have to check against current
1930 if( p_formats->depth == (int)p_vout->p_sys->i_screen_depth )
1932 if( p_formats->bits_per_pixel / 8
1933 > (int)p_vout->p_sys->i_bytes_per_pixel )
1935 p_vout->p_sys->i_bytes_per_pixel =
1936 p_formats->bits_per_pixel / 8;
1942 p_vout->p_sys->p_visual = p_xvisual->visual;
1949 #ifdef HAVE_SYS_SHM_H
1950 /*****************************************************************************
1951 * CreateShmImage: create an XImage or XvImage using shared memory extension
1952 *****************************************************************************
1953 * Prepare an XImage or XvImage for display function.
1954 * The order of the operations respects the recommandations of the mit-shm
1955 * document by J.Corbet and K.Packard. Most of the parameters were copied from
1956 * there. See http://ftp.xfree86.org/pub/XFree86/4.0/doc/mit-shm.TXT
1957 *****************************************************************************/
1958 static IMAGE_TYPE * CreateShmImage( vout_thread_t *p_vout,
1959 Display* p_display, EXTRA_ARGS_SHM,
1960 int i_width, int i_height )
1962 IMAGE_TYPE *p_image;
1964 /* Create XImage / XvImage */
1965 #ifdef MODULE_NAME_IS_xvideo
1966 p_image = XvShmCreateImage( p_display, i_xvport, i_chroma, 0,
1967 i_width, i_height, p_shm );
1969 p_image = XShmCreateImage( p_display, p_visual, i_depth, ZPixmap, 0,
1970 p_shm, i_width, i_height );
1972 if( p_image == NULL )
1974 msg_Err( p_vout, "image creation failed" );
1978 /* Allocate shared memory segment - 0776 set the access permission
1979 * rights (like umask), they are not yet supported by all X servers */
1980 p_shm->shmid = shmget( IPC_PRIVATE, DATA_SIZE(p_image), IPC_CREAT | 0776 );
1981 if( p_shm->shmid < 0 )
1983 msg_Err( p_vout, "cannot allocate shared image data (%s)",
1984 strerror( errno ) );
1985 IMAGE_FREE( p_image );
1989 /* Attach shared memory segment to process (read/write) */
1990 p_shm->shmaddr = p_image->data = shmat( p_shm->shmid, 0, 0 );
1991 if(! p_shm->shmaddr )
1993 msg_Err( p_vout, "cannot attach shared memory (%s)",
1995 IMAGE_FREE( p_image );
1996 shmctl( p_shm->shmid, IPC_RMID, 0 );
2000 /* Read-only data. We won't be using XShmGetImage */
2001 p_shm->readOnly = True;
2003 /* Attach shared memory segment to X server */
2004 if( XShmAttach( p_display, p_shm ) == False )
2006 msg_Err( p_vout, "cannot attach shared memory to X server" );
2007 IMAGE_FREE( p_image );
2008 shmctl( p_shm->shmid, IPC_RMID, 0 );
2009 shmdt( p_shm->shmaddr );
2013 /* Send image to X server. This instruction is required, since having
2014 * built a Shm XImage and not using it causes an error on XCloseDisplay,
2015 * and remember NOT to use XFlush ! */
2016 XSync( p_display, False );
2019 /* Mark the shm segment to be removed when there are no more
2020 * attachements, so it is automatic on process exit or after shmdt */
2021 shmctl( p_shm->shmid, IPC_RMID, 0 );
2028 /*****************************************************************************
2029 * CreateImage: create an XImage or XvImage
2030 *****************************************************************************
2031 * Create a simple image used as a buffer.
2032 *****************************************************************************/
2033 static IMAGE_TYPE * CreateImage( vout_thread_t *p_vout,
2034 Display *p_display, EXTRA_ARGS,
2035 int i_width, int i_height )
2037 byte_t * p_data; /* image data storage zone */
2038 IMAGE_TYPE *p_image;
2039 #ifdef MODULE_NAME_IS_x11
2040 int i_quantum; /* XImage quantum (see below) */
2041 int i_bytes_per_line;
2044 /* Allocate memory for image */
2045 #ifdef MODULE_NAME_IS_xvideo
2046 p_data = (byte_t *) malloc( i_width * i_height * i_bits_per_pixel / 8 );
2048 i_bytes_per_line = i_width * i_bytes_per_pixel;
2049 p_data = (byte_t *) malloc( i_bytes_per_line * i_height );
2053 msg_Err( p_vout, "out of memory" );
2057 #ifdef MODULE_NAME_IS_x11
2058 /* Optimize the quantum of a scanline regarding its size - the quantum is
2059 a diviser of the number of bits between the start of two scanlines. */
2060 if( i_bytes_per_line & 0xf )
2064 else if( i_bytes_per_line & 0x10 )
2074 /* Create XImage. p_data will be automatically freed */
2075 #ifdef MODULE_NAME_IS_xvideo
2076 p_image = XvCreateImage( p_display, i_xvport, i_chroma,
2077 p_data, i_width, i_height );
2079 p_image = XCreateImage( p_display, p_visual, i_depth, ZPixmap, 0,
2080 p_data, i_width, i_height, i_quantum, 0 );
2082 if( p_image == NULL )
2084 msg_Err( p_vout, "XCreateImage() failed" );
2092 #ifdef MODULE_NAME_IS_x11
2093 /*****************************************************************************
2094 * SetPalette: sets an 8 bpp palette
2095 *****************************************************************************
2096 * This function sets the palette given as an argument. It does not return
2097 * anything, but could later send information on which colors it was unable
2099 *****************************************************************************/
2100 static void SetPalette( vout_thread_t *p_vout,
2101 uint16_t *red, uint16_t *green, uint16_t *blue )
2104 XColor p_colors[255];
2106 /* allocate palette */
2107 for( i = 0; i < 255; i++ )
2109 /* kludge: colors are indexed reversely because color 255 seems
2110 * to be reserved for black even if we try to set it to white */
2111 p_colors[ i ].pixel = 255 - i;
2112 p_colors[ i ].pad = 0;
2113 p_colors[ i ].flags = DoRed | DoGreen | DoBlue;
2114 p_colors[ i ].red = red[ 255 - i ];
2115 p_colors[ i ].blue = blue[ 255 - i ];
2116 p_colors[ i ].green = green[ 255 - i ];
2119 XStoreColors( p_vout->p_sys->p_display,
2120 p_vout->p_sys->colormap, p_colors, 255 );
2124 /*****************************************************************************
2125 * Control: control facility for the vout
2126 *****************************************************************************/
2127 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
2135 if( p_vout->p_sys->p_win->owner_window )
2136 return vout_ControlWindow( p_vout,
2137 (void *)p_vout->p_sys->p_win->owner_window, i_query, args);
2139 f_arg = va_arg( args, double );
2141 vlc_mutex_lock( &p_vout->p_sys->lock );
2143 /* Update dimensions */
2144 /* FIXME: export InitWindowSize() from vout core */
2145 XResizeWindow( p_vout->p_sys->p_display,
2146 p_vout->p_sys->p_win->base_window,
2147 p_vout->i_window_width * f_arg,
2148 p_vout->i_window_height * f_arg );
2150 vlc_mutex_unlock( &p_vout->p_sys->lock );
2154 vlc_mutex_lock( &p_vout->p_sys->lock );
2155 XReparentWindow( p_vout->p_sys->p_display,
2156 p_vout->p_sys->p_win->base_window,
2157 DefaultRootWindow( p_vout->p_sys->p_display ),
2159 XSync( p_vout->p_sys->p_display, False );
2160 p_vout->p_sys->p_win->owner_window = 0;
2161 vlc_mutex_unlock( &p_vout->p_sys->lock );
2164 case VOUT_SET_STAY_ON_TOP:
2165 if( p_vout->p_sys->p_win->owner_window )
2166 return vout_ControlWindow( p_vout,
2167 (void *)p_vout->p_sys->p_win->owner_window, i_query, args);
2169 b_arg = va_arg( args, vlc_bool_t );
2170 vlc_mutex_lock( &p_vout->p_sys->lock );
2171 WindowOnTop( p_vout, b_arg );
2172 vlc_mutex_unlock( &p_vout->p_sys->lock );
2176 msg_Dbg( p_vout, "control query not supported" );
2177 return VLC_EGENERIC;
2181 /*****************************************************************************
2182 * TestNetWMSupport: tests for Extended Window Manager Hints support
2183 *****************************************************************************/
2184 static void TestNetWMSupport( vout_thread_t *p_vout )
2186 int i_ret, i_format;
2187 unsigned long i, i_items, i_bytesafter;
2188 Atom net_wm_supported, *p_args = NULL;
2190 p_vout->p_sys->b_net_wm_state_fullscreen = VLC_FALSE;
2191 p_vout->p_sys->b_net_wm_state_above = VLC_FALSE;
2192 p_vout->p_sys->b_net_wm_state_below = VLC_FALSE;
2193 p_vout->p_sys->b_net_wm_state_stays_on_top = VLC_FALSE;
2196 XInternAtom( p_vout->p_sys->p_display, "_NET_SUPPORTED", False );
2198 i_ret = XGetWindowProperty( p_vout->p_sys->p_display,
2199 DefaultRootWindow( p_vout->p_sys->p_display ),
2201 0, 16384, False, AnyPropertyType,
2203 &i_format, &i_items, &i_bytesafter,
2204 (unsigned char **)(intptr_t)&p_args );
2206 if( i_ret != Success || i_items == 0 ) return;
2208 msg_Dbg( p_vout, "Window manager supports NetWM" );
2210 p_vout->p_sys->net_wm_state =
2211 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE", False );
2212 p_vout->p_sys->net_wm_state_fullscreen =
2213 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE_FULLSCREEN",
2215 p_vout->p_sys->net_wm_state_above =
2216 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE_ABOVE", False );
2217 p_vout->p_sys->net_wm_state_below =
2218 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE_BELOW", False );
2219 p_vout->p_sys->net_wm_state_stays_on_top =
2220 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE_STAYS_ON_TOP",
2223 for( i = 0; i < i_items; i++ )
2225 if( p_args[i] == p_vout->p_sys->net_wm_state_fullscreen )
2228 "Window manager supports _NET_WM_STATE_FULLSCREEN" );
2229 p_vout->p_sys->b_net_wm_state_fullscreen = VLC_TRUE;
2231 else if( p_args[i] == p_vout->p_sys->net_wm_state_above )
2233 msg_Dbg( p_vout, "Window manager supports _NET_WM_STATE_ABOVE" );
2234 p_vout->p_sys->b_net_wm_state_above = VLC_TRUE;
2236 else if( p_args[i] == p_vout->p_sys->net_wm_state_below )
2238 msg_Dbg( p_vout, "Window manager supports _NET_WM_STATE_BELOW" );
2239 p_vout->p_sys->b_net_wm_state_below = VLC_TRUE;
2241 else if( p_args[i] == p_vout->p_sys->net_wm_state_stays_on_top )
2244 "Window manager supports _NET_WM_STATE_STAYS_ON_TOP" );
2245 p_vout->p_sys->b_net_wm_state_stays_on_top = VLC_TRUE;
2252 /*****************************************************************************
2253 * Key events handling
2254 *****************************************************************************/
2260 } x11keys_to_vlckeys[] =
2262 { XK_F1, KEY_F1 }, { XK_F2, KEY_F2 }, { XK_F3, KEY_F3 }, { XK_F4, KEY_F4 },
2263 { XK_F5, KEY_F5 }, { XK_F6, KEY_F6 }, { XK_F7, KEY_F7 }, { XK_F8, KEY_F8 },
2264 { XK_F9, KEY_F9 }, { XK_F10, KEY_F10 }, { XK_F11, KEY_F11 },
2265 { XK_F12, KEY_F12 },
2267 { XK_Return, KEY_ENTER },
2268 { XK_KP_Enter, KEY_ENTER },
2269 { XK_space, KEY_SPACE },
2270 { XK_Escape, KEY_ESC },
2272 { XK_Menu, KEY_MENU },
2273 { XK_Left, KEY_LEFT },
2274 { XK_Right, KEY_RIGHT },
2276 { XK_Down, KEY_DOWN },
2278 { XK_Home, KEY_HOME },
2279 { XK_End, KEY_END },
2280 { XK_Page_Up, KEY_PAGEUP },
2281 { XK_Page_Down, KEY_PAGEDOWN },
2285 static int ConvertKey( int i_key )
2289 for( i = 0; x11keys_to_vlckeys[i].i_x11key != 0; i++ )
2291 if( x11keys_to_vlckeys[i].i_x11key == i_key )
2293 return x11keys_to_vlckeys[i].i_vlckey;
2300 /*****************************************************************************
2301 * WindowOnTop: Switches the "always on top" state of the video window.
2302 *****************************************************************************/
2303 static int WindowOnTop( vout_thread_t *p_vout, vlc_bool_t b_on_top )
2305 if( p_vout->p_sys->b_net_wm_state_stays_on_top )
2307 XClientMessageEvent event;
2309 memset( &event, 0, sizeof( XClientMessageEvent ) );
2311 event.type = ClientMessage;
2312 event.message_type = p_vout->p_sys->net_wm_state;
2313 event.display = p_vout->p_sys->p_display;
2314 event.window = p_vout->p_sys->p_win->base_window;
2316 event.data.l[ 0 ] = b_on_top; /* set property */
2317 event.data.l[ 1 ] = p_vout->p_sys->net_wm_state_stays_on_top;
2319 XSendEvent( p_vout->p_sys->p_display,
2320 DefaultRootWindow( p_vout->p_sys->p_display ),
2321 False, SubstructureRedirectMask,