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 /* Object variables callbacks */
126 static int OnTopCallback( vlc_object_t *, char const *,
127 vlc_value_t, vlc_value_t, void * );
129 /*****************************************************************************
130 * Activate: allocate X11 video thread output method
131 *****************************************************************************
132 * This function allocate and initialize a X11 vout method. It uses some of the
133 * vout properties to choose the window size, and change them according to the
134 * actual properties of the display.
135 *****************************************************************************/
136 int E_(Activate) ( vlc_object_t *p_this )
138 vout_thread_t *p_vout = (vout_thread_t *)p_this;
140 vlc_value_t val, text;
142 #ifdef MODULE_NAME_IS_xvideo
144 vlc_fourcc_t i_chroma = 0;
145 vlc_bool_t b_chroma = 0;
148 p_vout->pf_init = InitVideo;
149 p_vout->pf_end = EndVideo;
150 p_vout->pf_manage = ManageVideo;
151 p_vout->pf_render = NULL;
152 p_vout->pf_display = DisplayVideo;
153 p_vout->pf_control = Control;
155 /* Allocate structure */
156 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
157 if( p_vout->p_sys == NULL )
159 msg_Err( p_vout, "out of memory" );
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 /* Add a variable to indicate if the window should be on top of others */
287 var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
288 text.psz_string = _("Always on top");
289 var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
290 var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
291 /* Trigger a callback right now */
292 var_Get( p_vout, "video-on-top", &val );
293 var_Set( p_vout, "video-on-top", val );
298 /*****************************************************************************
299 * Deactivate: destroy X11 video thread output method
300 *****************************************************************************
301 * Terminate an output method created by Open
302 *****************************************************************************/
303 void E_(Deactivate) ( vlc_object_t *p_this )
305 vout_thread_t *p_vout = (vout_thread_t *)p_this;
307 /* If the fullscreen window is still open, close it */
308 if( p_vout->b_fullscreen )
310 ToggleFullScreen( p_vout );
313 /* Restore cursor if it was blanked */
314 if( !p_vout->p_sys->b_mouse_pointer_visible )
316 ToggleCursor( p_vout );
319 #ifdef MODULE_NAME_IS_x11
320 /* Destroy colormap */
321 if( XDefaultDepth(p_vout->p_sys->p_display, p_vout->p_sys->i_screen) == 8 )
323 XFreeColormap( p_vout->p_sys->p_display, p_vout->p_sys->colormap );
326 XVideoReleasePort( p_vout, p_vout->p_sys->i_xvport );
329 DestroyCursor( p_vout );
330 EnableXScreenSaver( p_vout );
331 DestroyWindow( p_vout, &p_vout->p_sys->original_window );
333 XCloseDisplay( p_vout->p_sys->p_display );
335 /* Destroy structure */
336 free( p_vout->p_sys );
339 /*****************************************************************************
340 * InitVideo: initialize X11 video thread output method
341 *****************************************************************************
342 * This function create the XImages needed by the output thread. It is called
343 * at the beginning of the thread, but also each time the window is resized.
344 *****************************************************************************/
345 static int InitVideo( vout_thread_t *p_vout )
350 I_OUTPUTPICTURES = 0;
352 #ifdef MODULE_NAME_IS_xvideo
353 /* Initialize the output structure; we already found an XVideo port,
354 * and the corresponding chroma we will be using. Since we can
355 * arbitrary scale, stick to the coordinates and aspect. */
356 p_vout->output.i_width = p_vout->render.i_width;
357 p_vout->output.i_height = p_vout->render.i_height;
358 p_vout->output.i_aspect = p_vout->render.i_aspect;
360 switch( p_vout->output.i_chroma )
362 case VLC_FOURCC('R','V','1','5'):
363 p_vout->output.i_rmask = 0x001f;
364 p_vout->output.i_gmask = 0x07e0;
365 p_vout->output.i_bmask = 0xf800;
367 case VLC_FOURCC('R','V','1','6'):
368 p_vout->output.i_rmask = 0x001f;
369 p_vout->output.i_gmask = 0x03e0;
370 p_vout->output.i_bmask = 0x7c00;
375 /* Initialize the output structure: RGB with square pixels, whatever
376 * the input format is, since it's the only format we know */
377 switch( p_vout->p_sys->i_screen_depth )
379 case 8: /* FIXME: set the palette */
380 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2'); break;
382 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5'); break;
384 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); break;
386 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4'); break;
388 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); break;
390 msg_Err( p_vout, "unknown screen depth %i",
391 p_vout->p_sys->i_screen_depth );
395 vout_PlacePicture( p_vout, p_vout->p_sys->p_win->i_width,
396 p_vout->p_sys->p_win->i_height,
398 &p_vout->output.i_width, &p_vout->output.i_height );
400 /* Assume we have square pixels */
401 p_vout->output.i_aspect = p_vout->output.i_width
402 * VOUT_ASPECT_FACTOR / p_vout->output.i_height;
405 /* Try to initialize up to MAX_DIRECTBUFFERS direct buffers */
406 while( I_OUTPUTPICTURES < MAX_DIRECTBUFFERS )
410 /* Find an empty picture slot */
411 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
413 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
415 p_pic = p_vout->p_picture + i_index;
420 /* Allocate the picture */
421 if( p_pic == NULL || NewPicture( p_vout, p_pic ) )
426 p_pic->i_status = DESTROYED_PICTURE;
427 p_pic->i_type = DIRECT_PICTURE;
429 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
437 /*****************************************************************************
438 * DisplayVideo: displays previously rendered output
439 *****************************************************************************
440 * This function sends the currently rendered image to X11 server.
441 * (The Xv extension takes care of "double-buffering".)
442 *****************************************************************************/
443 static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
445 int i_width, i_height, i_x, i_y;
447 vout_PlacePicture( p_vout, p_vout->p_sys->p_win->i_width,
448 p_vout->p_sys->p_win->i_height,
449 &i_x, &i_y, &i_width, &i_height );
451 #ifdef HAVE_SYS_SHM_H
452 if( p_vout->p_sys->b_shm )
454 /* Display rendered image using shared memory extension */
455 # ifdef MODULE_NAME_IS_xvideo
456 XvShmPutImage( p_vout->p_sys->p_display, p_vout->p_sys->i_xvport,
457 p_vout->p_sys->p_win->video_window,
458 p_vout->p_sys->p_win->gc, p_pic->p_sys->p_image,
459 0 /*src_x*/, 0 /*src_y*/,
460 p_vout->output.i_width, p_vout->output.i_height,
461 0 /*dest_x*/, 0 /*dest_y*/, i_width, i_height,
462 False /* Don't put True here or you'll waste your CPU */ );
464 XShmPutImage( p_vout->p_sys->p_display,
465 p_vout->p_sys->p_win->video_window,
466 p_vout->p_sys->p_win->gc, p_pic->p_sys->p_image,
467 0 /*src_x*/, 0 /*src_y*/, 0 /*dest_x*/, 0 /*dest_y*/,
468 p_vout->output.i_width, p_vout->output.i_height,
469 False /* Don't put True here ! */ );
473 #endif /* HAVE_SYS_SHM_H */
475 /* Use standard XPutImage -- this is gonna be slow ! */
476 #ifdef MODULE_NAME_IS_xvideo
477 XvPutImage( p_vout->p_sys->p_display, p_vout->p_sys->i_xvport,
478 p_vout->p_sys->p_win->video_window,
479 p_vout->p_sys->p_win->gc, p_pic->p_sys->p_image,
480 0 /*src_x*/, 0 /*src_y*/,
481 p_vout->output.i_width, p_vout->output.i_height,
482 0 /*dest_x*/, 0 /*dest_y*/, i_width, i_height );
484 XPutImage( p_vout->p_sys->p_display,
485 p_vout->p_sys->p_win->video_window,
486 p_vout->p_sys->p_win->gc, p_pic->p_sys->p_image,
487 0 /*src_x*/, 0 /*src_y*/, 0 /*dest_x*/, 0 /*dest_y*/,
488 p_vout->output.i_width, p_vout->output.i_height );
492 /* Make sure the command is sent now - do NOT use XFlush !*/
493 XSync( p_vout->p_sys->p_display, False );
496 /*****************************************************************************
497 * ManageVideo: handle X11 events
498 *****************************************************************************
499 * This function should be called regularly by video output thread. It manages
500 * X11 events and allows window resizing. It returns a non null value on
502 *****************************************************************************/
503 static int ManageVideo( vout_thread_t *p_vout )
505 XEvent xevent; /* X11 event */
508 /* Handle events from the owner window */
509 if( p_vout->p_sys->p_win->owner_window )
511 while( XCheckWindowEvent( p_vout->p_sys->p_display,
512 p_vout->p_sys->p_win->owner_window,
513 StructureNotifyMask, &xevent ) == True )
515 /* ConfigureNotify event: prepare */
516 if( xevent.type == ConfigureNotify )
518 if( (unsigned int)xevent.xconfigure.width
519 != p_vout->p_sys->p_win->i_width ||
520 (unsigned int)xevent.xconfigure.height
521 != p_vout->p_sys->p_win->i_height )
523 /* Update dimensions */
524 XResizeWindow( p_vout->p_sys->p_display,
525 p_vout->p_sys->p_win->base_window,
526 xevent.xconfigure.width,
527 xevent.xconfigure.height );
533 /* Handle X11 events: ConfigureNotify events are parsed to know if the
534 * output window's size changed, MapNotify and UnmapNotify to know if the
535 * window is mapped (and if the display is useful), and ClientMessages
536 * to intercept window destruction requests */
538 while( XCheckWindowEvent( p_vout->p_sys->p_display,
539 p_vout->p_sys->p_win->base_window,
540 StructureNotifyMask | KeyPressMask |
541 ButtonPressMask | ButtonReleaseMask |
542 PointerMotionMask | Button1MotionMask , &xevent )
545 /* ConfigureNotify event: prepare */
546 if( xevent.type == ConfigureNotify )
548 if( (unsigned int)xevent.xconfigure.width
549 != p_vout->p_sys->p_win->i_width
550 || (unsigned int)xevent.xconfigure.height
551 != p_vout->p_sys->p_win->i_height )
553 /* Update dimensions */
554 p_vout->i_changes |= VOUT_SIZE_CHANGE;
555 p_vout->p_sys->p_win->i_width = xevent.xconfigure.width;
556 p_vout->p_sys->p_win->i_height = xevent.xconfigure.height;
560 else if( xevent.type == KeyPress )
562 unsigned int state = xevent.xkey.state;
564 char i_key; /* ISO Latin-1 key */
566 /* We may have keys like F1 trough F12, ESC ... */
567 x_key_symbol = XKeycodeToKeysym( p_vout->p_sys->p_display,
568 xevent.xkey.keycode, 0 );
569 val.i_int = ConvertKey( (int)x_key_symbol );
571 xevent.xkey.state &= ~ShiftMask;
572 xevent.xkey.state &= ~ControlMask;
573 xevent.xkey.state &= ~Mod1Mask;
576 XLookupString( &xevent.xkey, &i_key, 1, NULL, NULL ) )
579 * The reason why I use this instead of XK_0 is that
580 * with XLookupString, we don't have to care about
587 if( state & ShiftMask )
589 val.i_int |= KEY_MODIFIER_SHIFT;
591 if( state & ControlMask )
593 val.i_int |= KEY_MODIFIER_CTRL;
595 if( state & Mod1Mask )
597 val.i_int |= KEY_MODIFIER_ALT;
599 var_Set( p_vout->p_vlc, "key-pressed", val );
603 else if( xevent.type == ButtonPress )
605 switch( ((XButtonEvent *)&xevent)->button )
608 var_Get( p_vout, "mouse-button-down", &val );
610 var_Set( p_vout, "mouse-button-down", val );
612 /* detect double-clicks */
613 if( ( ((XButtonEvent *)&xevent)->time -
614 p_vout->p_sys->i_time_button_last_pressed ) < 300 )
616 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
619 p_vout->p_sys->i_time_button_last_pressed =
620 ((XButtonEvent *)&xevent)->time;
623 var_Get( p_vout, "mouse-button-down", &val );
625 var_Set( p_vout, "mouse-button-down", val );
629 var_Get( p_vout, "mouse-button-down", &val );
631 var_Set( p_vout, "mouse-button-down", val );
635 var_Get( p_vout, "mouse-button-down", &val );
637 var_Set( p_vout, "mouse-button-down", val );
638 input_Seek( p_vout, 15, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
642 var_Get( p_vout, "mouse-button-down", &val );
644 var_Set( p_vout, "mouse-button-down", val );
645 input_Seek( p_vout, -15, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
650 else if( xevent.type == ButtonRelease )
652 switch( ((XButtonEvent *)&xevent)->button )
655 var_Get( p_vout, "mouse-button-down", &val );
657 var_Set( p_vout, "mouse-button-down", val );
659 val.b_bool = VLC_TRUE;
660 var_Set( p_vout, "mouse-clicked", val );
665 playlist_t *p_playlist;
667 var_Get( p_vout, "mouse-button-down", &val );
669 var_Set( p_vout, "mouse-button-down", val );
671 p_playlist = vlc_object_find( p_vout,
674 if( p_playlist != NULL )
677 var_Get( p_playlist, "intf-show", &val );
678 val.b_bool = !val.b_bool;
679 var_Set( p_playlist, "intf-show", val );
680 vlc_object_release( p_playlist );
687 intf_thread_t *p_intf;
688 playlist_t *p_playlist;
690 var_Get( p_vout, "mouse-button-down", &val );
692 var_Set( p_vout, "mouse-button-down", val );
693 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
697 p_intf->b_menu_change = 1;
698 vlc_object_release( p_intf );
701 p_playlist = vlc_object_find( p_vout,
704 if( p_playlist != NULL )
707 var_Set( p_playlist, "intf-popupmenu", val );
708 vlc_object_release( p_playlist );
714 var_Get( p_vout, "mouse-button-down", &val );
716 var_Set( p_vout, "mouse-button-down", val );
720 var_Get( p_vout, "mouse-button-down", &val );
722 var_Set( p_vout, "mouse-button-down", val );
728 else if( xevent.type == MotionNotify )
730 int i_width, i_height, i_x, i_y;
733 /* somewhat different use for vout_PlacePicture:
734 * here the values are needed to give to mouse coordinates
735 * in the original picture space */
736 vout_PlacePicture( p_vout, p_vout->p_sys->p_win->i_width,
737 p_vout->p_sys->p_win->i_height,
738 &i_x, &i_y, &i_width, &i_height );
740 val.i_int = ( xevent.xmotion.x - i_x )
741 * p_vout->render.i_width / i_width;
742 var_Set( p_vout, "mouse-x", val );
743 val.i_int = ( xevent.xmotion.y - i_y )
744 * p_vout->render.i_height / i_height;
745 var_Set( p_vout, "mouse-y", val );
747 val.b_bool = VLC_TRUE;
748 var_Set( p_vout, "mouse-moved", val );
750 p_vout->p_sys->i_time_mouse_last_moved = mdate();
751 if( ! p_vout->p_sys->b_mouse_pointer_visible )
753 ToggleCursor( p_vout );
756 else if( xevent.type == ReparentNotify /* XXX: why do we get this? */
757 || xevent.type == MapNotify
758 || xevent.type == UnmapNotify )
760 /* Ignore these events */
762 else /* Other events */
764 msg_Warn( p_vout, "unhandled event %d received", xevent.type );
768 /* Handle events for video output sub-window */
769 while( XCheckWindowEvent( p_vout->p_sys->p_display,
770 p_vout->p_sys->p_win->video_window,
771 ExposureMask, &xevent ) == True )
773 /* Window exposed (only handled if stream playback is paused) */
774 if( xevent.type == Expose )
776 if( ((XExposeEvent *)&xevent)->count == 0 )
778 /* (if this is the last a collection of expose events...) */
780 if( p_vout->p_vlc->p_input_bank->pp_input[0] != NULL )
782 if( PAUSE_S == p_vout->p_vlc->p_input_bank->pp_input[0]
783 ->stream.control.i_status )
785 /* XVideoDisplay( p_vout )*/;
793 /* ClientMessage event - only WM_PROTOCOLS with WM_DELETE_WINDOW data
794 * are handled - according to the man pages, the format is always 32
796 while( XCheckTypedEvent( p_vout->p_sys->p_display,
797 ClientMessage, &xevent ) )
799 if( (xevent.xclient.message_type == p_vout->p_sys->p_win->wm_protocols)
800 && ((Atom)xevent.xclient.data.l[0]
801 == p_vout->p_sys->p_win->wm_delete_window ) )
803 /* the user wants to close the window */
804 playlist_t * p_playlist =
805 (playlist_t *)vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
807 if( p_playlist != NULL )
809 playlist_Stop( p_playlist );
810 vlc_object_release( p_playlist );
818 if ( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
822 /* Update the object variable and trigger callback */
823 val.b_bool = !p_vout->b_fullscreen;
824 var_Set( p_vout, "fullscreen", val );
826 ToggleFullScreen( p_vout );
827 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
833 * (Needs to be placed after VOUT_FULLSREEN_CHANGE because we can activate
834 * the size flag inside the fullscreen routine)
836 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
838 int i_width, i_height, i_x, i_y;
840 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
842 #ifdef MODULE_NAME_IS_x11
843 /* We need to signal the vout thread about the size change because it
844 * is doing the rescaling */
845 p_vout->i_changes |= VOUT_SIZE_CHANGE;
848 vout_PlacePicture( p_vout, p_vout->p_sys->p_win->i_width,
849 p_vout->p_sys->p_win->i_height,
850 &i_x, &i_y, &i_width, &i_height );
852 XMoveResizeWindow( p_vout->p_sys->p_display,
853 p_vout->p_sys->p_win->video_window,
854 i_x, i_y, i_width, i_height );
857 /* Autohide Cursour */
858 if( mdate() - p_vout->p_sys->i_time_mouse_last_moved > 2000000 )
860 /* Hide the mouse automatically */
861 if( p_vout->p_sys->b_mouse_pointer_visible )
863 ToggleCursor( p_vout );
870 /*****************************************************************************
871 * EndVideo: terminate X11 video thread output method
872 *****************************************************************************
873 * Destroy the X11 XImages created by Init. It is called at the end of
874 * the thread, but also each time the window is resized.
875 *****************************************************************************/
876 static void EndVideo( vout_thread_t *p_vout )
880 /* Free the direct buffers we allocated */
881 for( i_index = I_OUTPUTPICTURES ; i_index ; )
884 FreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
888 /* following functions are local */
890 /*****************************************************************************
891 * CreateWindow: open and set-up X11 main window
892 *****************************************************************************/
893 static int CreateWindow( vout_thread_t *p_vout, x11_window_t *p_win )
895 XSizeHints xsize_hints;
896 XSetWindowAttributes xwindow_attributes;
900 vlc_bool_t b_expose = VLC_FALSE;
901 vlc_bool_t b_configure_notify = VLC_FALSE;
902 vlc_bool_t b_map_notify = VLC_FALSE;
904 /* Prepare window manager hints and properties */
905 p_win->wm_protocols =
906 XInternAtom( p_vout->p_sys->p_display, "WM_PROTOCOLS", True );
907 p_win->wm_delete_window =
908 XInternAtom( p_vout->p_sys->p_display, "WM_DELETE_WINDOW", True );
910 /* Prepare window attributes */
911 xwindow_attributes.backing_store = Always; /* save the hidden part */
912 xwindow_attributes.background_pixel = BlackPixel(p_vout->p_sys->p_display,
913 p_vout->p_sys->i_screen);
914 xwindow_attributes.event_mask = ExposureMask | StructureNotifyMask;
916 if( !p_vout->b_fullscreen )
918 p_win->owner_window =
919 (Window)vout_RequestWindow( p_vout, &p_win->i_x, &p_win->i_y,
920 &p_win->i_width, &p_win->i_height );
922 xsize_hints.base_width = xsize_hints.width = p_win->i_width;
923 xsize_hints.base_height = xsize_hints.height = p_win->i_height;
924 xsize_hints.flags = PSize;
926 if( p_win->i_x >=0 || p_win->i_y >= 0 )
928 xsize_hints.x = p_win->i_x;
929 xsize_hints.y = p_win->i_y;
930 xsize_hints.flags |= PPosition;
935 /* Fullscreen window size and position */
936 p_win->owner_window = 0;
937 p_win->i_x = p_win->i_y = 0;
939 DisplayWidth( p_vout->p_sys->p_display, p_vout->p_sys->i_screen );
941 DisplayHeight( p_vout->p_sys->p_display, p_vout->p_sys->i_screen );
944 if( !p_win->owner_window )
946 /* Create the window and set hints - the window must receive
947 * ConfigureNotify events, and until it is displayed, Expose and
948 * MapNotify events. */
951 XCreateWindow( p_vout->p_sys->p_display,
952 DefaultRootWindow( p_vout->p_sys->p_display ),
953 p_win->i_x, p_win->i_y,
954 p_win->i_width, p_win->i_height,
957 CWBackingStore | CWBackPixel | CWEventMask,
958 &xwindow_attributes );
960 if( !p_vout->b_fullscreen )
962 /* Set window manager hints and properties: size hints, command,
963 * window's name, and accepted protocols */
964 XSetWMNormalHints( p_vout->p_sys->p_display,
965 p_win->base_window, &xsize_hints );
966 XSetCommand( p_vout->p_sys->p_display, p_win->base_window,
967 p_vout->p_vlc->ppsz_argv, p_vout->p_vlc->i_argc );
969 XStoreName( p_vout->p_sys->p_display, p_win->base_window,
970 #ifdef MODULE_NAME_IS_x11
971 VOUT_TITLE " (X11 output)"
973 VOUT_TITLE " (XVideo output)"
981 unsigned int dummy2, dummy3;
983 /* Select events we are interested in. */
984 XSelectInput( p_vout->p_sys->p_display, p_win->owner_window,
985 StructureNotifyMask );
987 /* Get the parent window's geometry information */
988 XGetGeometry( p_vout->p_sys->p_display, p_win->owner_window,
989 &dummy1, &dummy2, &dummy3,
994 /* We are already configured */
995 b_configure_notify = VLC_TRUE;
997 /* From man XSelectInput: only one client at a time can select a
998 * ButtonPress event, so we need to open a new window anyway. */
1000 XCreateWindow( p_vout->p_sys->p_display,
1001 p_win->owner_window,
1003 p_win->i_width, p_win->i_height,
1005 0, CopyFromParent, 0,
1006 CWBackingStore | CWBackPixel | CWEventMask,
1007 &xwindow_attributes );
1010 if( (p_win->wm_protocols == None) /* use WM_DELETE_WINDOW */
1011 || (p_win->wm_delete_window == None)
1012 || !XSetWMProtocols( p_vout->p_sys->p_display, p_win->base_window,
1013 &p_win->wm_delete_window, 1 ) )
1015 /* WM_DELETE_WINDOW is not supported by window manager */
1016 msg_Warn( p_vout, "missing or bad window manager" );
1019 /* Creation of a graphic context that doesn't generate a GraphicsExpose
1020 * event when using functions like XCopyArea */
1021 xgcvalues.graphics_exposures = False;
1022 p_win->gc = XCreateGC( p_vout->p_sys->p_display,
1024 GCGraphicsExposures, &xgcvalues );
1026 /* Send orders to server, and wait until window is displayed - three
1027 * events must be received: a MapNotify event, an Expose event allowing
1028 * drawing in the window, and a ConfigureNotify to get the window
1029 * dimensions. Once those events have been received, only
1030 * ConfigureNotify events need to be received. */
1031 XMapWindow( p_vout->p_sys->p_display, p_win->base_window );
1034 XNextEvent( p_vout->p_sys->p_display, &xevent);
1035 if( (xevent.type == Expose)
1036 && (xevent.xexpose.window == p_win->base_window) )
1038 b_expose = VLC_TRUE;
1040 else if( (xevent.type == MapNotify)
1041 && (xevent.xmap.window == p_win->base_window) )
1043 b_map_notify = VLC_TRUE;
1045 else if( (xevent.type == ConfigureNotify)
1046 && (xevent.xconfigure.window == p_win->base_window) )
1048 b_configure_notify = VLC_TRUE;
1049 p_win->i_width = xevent.xconfigure.width;
1050 p_win->i_height = xevent.xconfigure.height;
1052 } while( !( b_expose && b_configure_notify && b_map_notify ) );
1054 XSelectInput( p_vout->p_sys->p_display, p_win->base_window,
1055 StructureNotifyMask | KeyPressMask |
1056 ButtonPressMask | ButtonReleaseMask |
1057 PointerMotionMask );
1059 #ifdef MODULE_NAME_IS_x11
1060 if( XDefaultDepth(p_vout->p_sys->p_display, p_vout->p_sys->i_screen) == 8 )
1062 /* Allocate a new palette */
1063 p_vout->p_sys->colormap =
1064 XCreateColormap( p_vout->p_sys->p_display,
1065 DefaultRootWindow( p_vout->p_sys->p_display ),
1066 DefaultVisual( p_vout->p_sys->p_display,
1067 p_vout->p_sys->i_screen ),
1070 xwindow_attributes.colormap = p_vout->p_sys->colormap;
1071 XChangeWindowAttributes( p_vout->p_sys->p_display, p_win->base_window,
1072 CWColormap, &xwindow_attributes );
1076 /* Create video output sub-window. */
1077 p_win->video_window = XCreateSimpleWindow(
1078 p_vout->p_sys->p_display,
1079 p_win->base_window, 0, 0,
1080 p_win->i_width, p_win->i_height,
1082 BlackPixel( p_vout->p_sys->p_display,
1083 p_vout->p_sys->i_screen ),
1084 WhitePixel( p_vout->p_sys->p_display,
1085 p_vout->p_sys->i_screen ) );
1087 XSetWindowBackground( p_vout->p_sys->p_display, p_win->video_window,
1088 BlackPixel( p_vout->p_sys->p_display,
1089 p_vout->p_sys->i_screen ) );
1091 XMapWindow( p_vout->p_sys->p_display, p_win->video_window );
1092 XSelectInput( p_vout->p_sys->p_display, p_win->video_window,
1095 /* make sure the video window will be centered in the next ManageVideo() */
1096 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1098 /* If the cursor was formerly blank than blank it again */
1099 if( !p_vout->p_sys->b_mouse_pointer_visible )
1101 ToggleCursor( p_vout );
1102 ToggleCursor( p_vout );
1105 /* Do NOT use XFlush here ! */
1106 XSync( p_vout->p_sys->p_display, False );
1108 /* At this stage, the window is open, displayed, and ready to
1110 p_vout->p_sys->p_win = p_win;
1115 /*****************************************************************************
1116 * DestroyWindow: destroy the window
1117 *****************************************************************************
1119 *****************************************************************************/
1120 static void DestroyWindow( vout_thread_t *p_vout, x11_window_t *p_win )
1122 /* Do NOT use XFlush here ! */
1123 XSync( p_vout->p_sys->p_display, False );
1125 XDestroyWindow( p_vout->p_sys->p_display, p_win->video_window );
1126 XFreeGC( p_vout->p_sys->p_display, p_win->gc );
1128 XUnmapWindow( p_vout->p_sys->p_display, p_win->base_window );
1129 XDestroyWindow( p_vout->p_sys->p_display, p_win->base_window );
1131 if( p_win->owner_window )
1132 vout_ReleaseWindow( p_vout, (void *)p_win->owner_window );
1135 /*****************************************************************************
1136 * NewPicture: allocate a picture
1137 *****************************************************************************
1138 * Returns 0 on success, -1 otherwise
1139 *****************************************************************************/
1140 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
1142 #ifdef MODULE_NAME_IS_xvideo
1146 /* We know the chroma, allocate a buffer which will be used
1147 * directly by the decoder */
1148 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
1150 if( p_pic->p_sys == NULL )
1155 /* Fill in picture_t fields */
1156 vout_InitPicture( VLC_OBJECT(p_vout), p_pic, p_vout->output.i_chroma,
1157 p_vout->output.i_width, p_vout->output.i_height,
1158 p_vout->output.i_aspect );
1160 #ifdef HAVE_SYS_SHM_H
1161 if( p_vout->p_sys->b_shm )
1163 /* Create image using XShm extension */
1164 p_pic->p_sys->p_image =
1165 CreateShmImage( p_vout, p_vout->p_sys->p_display,
1166 # ifdef MODULE_NAME_IS_xvideo
1167 p_vout->p_sys->i_xvport, p_vout->output.i_chroma,
1169 p_vout->p_sys->p_visual,
1170 p_vout->p_sys->i_screen_depth,
1172 &p_pic->p_sys->shminfo,
1173 p_vout->output.i_width, p_vout->output.i_height );
1176 #endif /* HAVE_SYS_SHM_H */
1178 /* Create image without XShm extension */
1179 p_pic->p_sys->p_image =
1180 CreateImage( p_vout, p_vout->p_sys->p_display,
1181 #ifdef MODULE_NAME_IS_xvideo
1182 p_vout->p_sys->i_xvport, p_vout->output.i_chroma,
1183 p_pic->format.i_bits_per_pixel,
1185 p_vout->p_sys->p_visual,
1186 p_vout->p_sys->i_screen_depth,
1187 p_vout->p_sys->i_bytes_per_pixel,
1189 p_vout->output.i_width, p_vout->output.i_height );
1192 if( p_pic->p_sys->p_image == NULL )
1194 free( p_pic->p_sys );
1198 switch( p_vout->output.i_chroma )
1200 #ifdef MODULE_NAME_IS_xvideo
1201 case VLC_FOURCC('I','4','2','0'):
1202 case VLC_FOURCC('Y','V','1','2'):
1203 case VLC_FOURCC('Y','2','1','1'):
1204 case VLC_FOURCC('Y','U','Y','2'):
1205 case VLC_FOURCC('U','Y','V','Y'):
1206 case VLC_FOURCC('R','V','1','5'):
1207 case VLC_FOURCC('R','V','1','6'):
1208 case VLC_FOURCC('R','V','2','4'): /* Fixme: pixel pitch == 4 ? */
1209 case VLC_FOURCC('R','V','3','2'):
1211 for( i_plane = 0; i_plane < p_pic->p_sys->p_image->num_planes;
1214 p_pic->p[i_plane].p_pixels = p_pic->p_sys->p_image->data
1215 + p_pic->p_sys->p_image->offsets[i_plane];
1216 p_pic->p[i_plane].i_pitch =
1217 p_pic->p_sys->p_image->pitches[i_plane];
1219 if( p_vout->output.i_chroma == VLC_FOURCC('Y','V','1','2') )
1221 /* U and V inverted compared to I420
1222 * Fixme: this should be handled by the vout core */
1223 p_pic->U_PIXELS = p_pic->p_sys->p_image->data
1224 + p_pic->p_sys->p_image->offsets[2];
1225 p_pic->V_PIXELS = p_pic->p_sys->p_image->data
1226 + p_pic->p_sys->p_image->offsets[1];
1231 case VLC_FOURCC('R','G','B','2'):
1232 case VLC_FOURCC('R','V','1','6'):
1233 case VLC_FOURCC('R','V','1','5'):
1234 case VLC_FOURCC('R','V','2','4'):
1235 case VLC_FOURCC('R','V','3','2'):
1237 p_pic->p->i_lines = p_pic->p_sys->p_image->height;
1238 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1239 + p_pic->p_sys->p_image->xoffset;
1240 p_pic->p->i_pitch = p_pic->p_sys->p_image->bytes_per_line;
1242 /* p_pic->p->i_pixel_pitch = 4 for RV24 but this should be set
1243 * properly by vout_InitPicture() */
1244 p_pic->p->i_visible_pitch = p_pic->p->i_pixel_pitch
1245 * p_pic->p_sys->p_image->width;
1250 /* Unknown chroma, tell the guy to get lost */
1251 IMAGE_FREE( p_pic->p_sys->p_image );
1252 free( p_pic->p_sys );
1253 msg_Err( p_vout, "never heard of chroma 0x%.8x (%4.4s)",
1254 p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma );
1255 p_pic->i_planes = 0;
1262 /*****************************************************************************
1263 * FreePicture: destroy a picture allocated with NewPicture
1264 *****************************************************************************
1265 * Destroy XImage AND associated data. If using Shm, detach shared memory
1266 * segment from server and process, then free it. The XDestroyImage manpage
1267 * says that both the image structure _and_ the data pointed to by the
1268 * image structure are freed, so no need to free p_image->data.
1269 *****************************************************************************/
1270 static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
1272 /* The order of operations is correct */
1273 #ifdef HAVE_SYS_SHM_H
1274 if( p_vout->p_sys->b_shm )
1276 XShmDetach( p_vout->p_sys->p_display, &p_pic->p_sys->shminfo );
1277 IMAGE_FREE( p_pic->p_sys->p_image );
1279 shmctl( p_pic->p_sys->shminfo.shmid, IPC_RMID, 0 );
1280 if( shmdt( p_pic->p_sys->shminfo.shmaddr ) )
1282 msg_Err( p_vout, "cannot detach shared memory (%s)",
1289 IMAGE_FREE( p_pic->p_sys->p_image );
1292 /* Do NOT use XFlush here ! */
1293 XSync( p_vout->p_sys->p_display, False );
1295 free( p_pic->p_sys );
1298 /*****************************************************************************
1299 * ToggleFullScreen: Enable or disable full screen mode
1300 *****************************************************************************
1301 * This function will switch between fullscreen and window mode.
1302 *****************************************************************************/
1303 static void ToggleFullScreen ( vout_thread_t *p_vout )
1307 mwmhints_t mwmhints;
1308 XSetWindowAttributes attributes;
1310 #ifdef HAVE_XINERAMA
1314 p_vout->b_fullscreen = !p_vout->b_fullscreen;
1316 if( p_vout->b_fullscreen )
1318 msg_Dbg( p_vout, "entering fullscreen mode" );
1320 p_vout->p_sys->b_altfullscreen =
1321 config_GetInt( p_vout, MODULE_STRING "-altfullscreen" );
1323 XUnmapWindow( p_vout->p_sys->p_display,
1324 p_vout->p_sys->p_win->base_window);
1326 p_vout->p_sys->p_win = &p_vout->p_sys->fullscreen_window;
1328 CreateWindow( p_vout, p_vout->p_sys->p_win );
1330 /* To my knowledge there are two ways to create a borderless window.
1331 * There's the generic way which is to tell x to bypass the window
1332 * manager, but this creates problems with the focus of other
1334 * The other way is to use the motif property "_MOTIF_WM_HINTS" which
1335 * luckily seems to be supported by most window managers. */
1336 if( !p_vout->p_sys->b_altfullscreen )
1338 mwmhints.flags = MWM_HINTS_DECORATIONS;
1339 mwmhints.decorations = False;
1341 prop = XInternAtom( p_vout->p_sys->p_display, "_MOTIF_WM_HINTS",
1343 XChangeProperty( p_vout->p_sys->p_display,
1344 p_vout->p_sys->p_win->base_window,
1345 prop, prop, 32, PropModeReplace,
1346 (unsigned char *)&mwmhints,
1347 PROP_MWM_HINTS_ELEMENTS );
1351 /* brute force way to remove decorations */
1352 attributes.override_redirect = True;
1353 XChangeWindowAttributes( p_vout->p_sys->p_display,
1354 p_vout->p_sys->p_win->base_window,
1358 /* Make sure the change is effective */
1359 XReparentWindow( p_vout->p_sys->p_display,
1360 p_vout->p_sys->p_win->base_window,
1361 DefaultRootWindow( p_vout->p_sys->p_display ),
1365 if( p_vout->p_sys->b_net_wm_state_fullscreen )
1367 XClientMessageEvent event;
1369 memset( &event, 0, sizeof( XClientMessageEvent ) );
1371 event.type = ClientMessage;
1372 event.message_type = p_vout->p_sys->net_wm_state;
1373 event.display = p_vout->p_sys->p_display;
1374 event.window = p_vout->p_sys->p_win->base_window;
1376 event.data.l[ 0 ] = 1; /* set property */
1377 event.data.l[ 1 ] = p_vout->p_sys->net_wm_state_fullscreen;
1379 XSendEvent( p_vout->p_sys->p_display,
1380 DefaultRootWindow( p_vout->p_sys->p_display ),
1381 False, SubstructureRedirectMask,
1385 /* Make sure the change is effective */
1386 XReparentWindow( p_vout->p_sys->p_display,
1387 p_vout->p_sys->p_win->base_window,
1388 DefaultRootWindow( p_vout->p_sys->p_display ),
1391 #ifdef HAVE_XINERAMA
1392 if( XineramaQueryExtension( p_vout->p_sys->p_display, &i_d1, &i_d2 ) &&
1393 XineramaIsActive( p_vout->p_sys->p_display ) )
1395 XineramaScreenInfo *screens; /* infos for xinerama */
1398 msg_Dbg( p_vout, "using XFree Xinerama extension");
1400 #define SCREEN p_vout->p_sys->p_win->i_screen
1402 /* Get Informations about Xinerama (num of screens) */
1403 screens = XineramaQueryScreens( p_vout->p_sys->p_display,
1407 SCREEN = config_GetInt( p_vout,
1408 MODULE_STRING "-xineramascreen" );
1410 /* just check that user has entered a good value */
1411 if( SCREEN >= i_num_screens || SCREEN < 0 )
1413 msg_Dbg( p_vout, "requested screen number invalid" );
1417 /* Get the X/Y upper left corner coordinate of the above screen */
1418 p_vout->p_sys->p_win->i_x = screens[SCREEN].x_org;
1419 p_vout->p_sys->p_win->i_y = screens[SCREEN].y_org;
1421 /* Set the Height/width to the screen resolution */
1422 p_vout->p_sys->p_win->i_width = screens[SCREEN].width;
1423 p_vout->p_sys->p_win->i_height = screens[SCREEN].height;
1432 XMoveResizeWindow( p_vout->p_sys->p_display,
1433 p_vout->p_sys->p_win->base_window,
1434 p_vout->p_sys->p_win->i_x,
1435 p_vout->p_sys->p_win->i_y,
1436 p_vout->p_sys->p_win->i_width,
1437 p_vout->p_sys->p_win->i_height );
1441 msg_Dbg( p_vout, "leaving fullscreen mode" );
1442 DestroyWindow( p_vout, &p_vout->p_sys->fullscreen_window );
1443 p_vout->p_sys->p_win = &p_vout->p_sys->original_window;
1445 XMapWindow( p_vout->p_sys->p_display,
1446 p_vout->p_sys->p_win->base_window);
1449 /* Unfortunately, using XSync() here is not enough to ensure the
1450 * window has already been mapped because the XMapWindow() request
1451 * has not necessarily been sent directly to our window (remember,
1452 * the call is first redirected to the window manager) */
1455 XWindowEvent( p_vout->p_sys->p_display,
1456 p_vout->p_sys->p_win->base_window,
1457 StructureNotifyMask, &xevent );
1458 } while( xevent.type != MapNotify );
1460 /* Be careful, this can generate a BadMatch error if the window is not
1461 * already mapped by the server (see above) */
1462 XSetInputFocus(p_vout->p_sys->p_display,
1463 p_vout->p_sys->p_win->base_window,
1467 /* signal that the size needs to be updated */
1468 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1471 /*****************************************************************************
1472 * EnableXScreenSaver: enable screen saver
1473 *****************************************************************************
1474 * This function enables the screen saver on a display after it has been
1475 * disabled by XDisableScreenSaver.
1476 * FIXME: what happens if multiple vlc sessions are running at the same
1478 *****************************************************************************/
1479 static void EnableXScreenSaver( vout_thread_t *p_vout )
1481 #ifdef DPMSINFO_IN_DPMS_H
1485 if( p_vout->p_sys->i_ss_timeout )
1487 XSetScreenSaver( p_vout->p_sys->p_display, p_vout->p_sys->i_ss_timeout,
1488 p_vout->p_sys->i_ss_interval,
1489 p_vout->p_sys->i_ss_blanking,
1490 p_vout->p_sys->i_ss_exposure );
1493 /* Restore DPMS settings */
1494 #ifdef DPMSINFO_IN_DPMS_H
1495 if( DPMSQueryExtension( p_vout->p_sys->p_display, &dummy, &dummy ) )
1497 if( p_vout->p_sys->b_ss_dpms )
1499 DPMSEnable( p_vout->p_sys->p_display );
1505 /*****************************************************************************
1506 * DisableXScreenSaver: disable screen saver
1507 *****************************************************************************
1508 * See XEnableXScreenSaver
1509 *****************************************************************************/
1510 static void DisableXScreenSaver( vout_thread_t *p_vout )
1512 #ifdef DPMSINFO_IN_DPMS_H
1516 /* Save screen saver informations */
1517 XGetScreenSaver( p_vout->p_sys->p_display, &p_vout->p_sys->i_ss_timeout,
1518 &p_vout->p_sys->i_ss_interval,
1519 &p_vout->p_sys->i_ss_blanking,
1520 &p_vout->p_sys->i_ss_exposure );
1522 /* Disable screen saver */
1523 if( p_vout->p_sys->i_ss_timeout )
1525 XSetScreenSaver( p_vout->p_sys->p_display, 0,
1526 p_vout->p_sys->i_ss_interval,
1527 p_vout->p_sys->i_ss_blanking,
1528 p_vout->p_sys->i_ss_exposure );
1532 #ifdef DPMSINFO_IN_DPMS_H
1533 if( DPMSQueryExtension( p_vout->p_sys->p_display, &dummy, &dummy ) )
1536 /* Save DPMS current state */
1537 DPMSInfo( p_vout->p_sys->p_display, &unused,
1538 &p_vout->p_sys->b_ss_dpms );
1539 DPMSDisable( p_vout->p_sys->p_display );
1544 /*****************************************************************************
1545 * CreateCursor: create a blank mouse pointer
1546 *****************************************************************************/
1547 static void CreateCursor( vout_thread_t *p_vout )
1549 XColor cursor_color;
1551 p_vout->p_sys->cursor_pixmap =
1552 XCreatePixmap( p_vout->p_sys->p_display,
1553 DefaultRootWindow( p_vout->p_sys->p_display ),
1556 XParseColor( p_vout->p_sys->p_display,
1557 XCreateColormap( p_vout->p_sys->p_display,
1559 p_vout->p_sys->p_display ),
1561 p_vout->p_sys->p_display,
1562 p_vout->p_sys->i_screen ),
1564 "black", &cursor_color );
1566 p_vout->p_sys->blank_cursor =
1567 XCreatePixmapCursor( p_vout->p_sys->p_display,
1568 p_vout->p_sys->cursor_pixmap,
1569 p_vout->p_sys->cursor_pixmap,
1570 &cursor_color, &cursor_color, 1, 1 );
1573 /*****************************************************************************
1574 * DestroyCursor: destroy the blank mouse pointer
1575 *****************************************************************************/
1576 static void DestroyCursor( vout_thread_t *p_vout )
1578 XFreePixmap( p_vout->p_sys->p_display, p_vout->p_sys->cursor_pixmap );
1581 /*****************************************************************************
1582 * ToggleCursor: hide or show the mouse pointer
1583 *****************************************************************************
1584 * This function hides the X pointer if it is visible by setting the pointer
1585 * sprite to a blank one. To show it again, we disable the sprite.
1586 *****************************************************************************/
1587 static void ToggleCursor( vout_thread_t *p_vout )
1589 if( p_vout->p_sys->b_mouse_pointer_visible )
1591 XDefineCursor( p_vout->p_sys->p_display,
1592 p_vout->p_sys->p_win->base_window,
1593 p_vout->p_sys->blank_cursor );
1594 p_vout->p_sys->b_mouse_pointer_visible = 0;
1598 XUndefineCursor( p_vout->p_sys->p_display,
1599 p_vout->p_sys->p_win->base_window );
1600 p_vout->p_sys->b_mouse_pointer_visible = 1;
1604 #ifdef MODULE_NAME_IS_xvideo
1605 /*****************************************************************************
1606 * XVideoGetPort: get YUV12 port
1607 *****************************************************************************/
1608 static int XVideoGetPort( vout_thread_t *p_vout,
1609 vlc_fourcc_t i_chroma, vlc_fourcc_t *pi_newchroma )
1611 XvAdaptorInfo *p_adaptor;
1613 int i_adaptor, i_num_adaptors, i_requested_adaptor;
1614 int i_selected_port;
1616 switch( XvQueryExtension( p_vout->p_sys->p_display, &i, &i, &i, &i, &i ) )
1621 case XvBadExtension:
1622 msg_Warn( p_vout, "XvBadExtension" );
1626 msg_Warn( p_vout, "XvBadAlloc" );
1630 msg_Warn( p_vout, "XvQueryExtension failed" );
1634 switch( XvQueryAdaptors( p_vout->p_sys->p_display,
1635 DefaultRootWindow( p_vout->p_sys->p_display ),
1636 &i_num_adaptors, &p_adaptor ) )
1641 case XvBadExtension:
1642 msg_Warn( p_vout, "XvBadExtension for XvQueryAdaptors" );
1646 msg_Warn( p_vout, "XvBadAlloc for XvQueryAdaptors" );
1650 msg_Warn( p_vout, "XvQueryAdaptors failed" );
1654 i_selected_port = -1;
1655 i_requested_adaptor = config_GetInt( p_vout, "xvideo-adaptor" );
1657 for( i_adaptor = 0; i_adaptor < i_num_adaptors; ++i_adaptor )
1659 XvImageFormatValues *p_formats;
1660 int i_format, i_num_formats;
1663 /* If we requested an adaptor and it's not this one, we aren't
1665 if( i_requested_adaptor != -1 && i_adaptor != i_requested_adaptor )
1670 /* If the adaptor doesn't have the required properties, skip it */
1671 if( !( p_adaptor[ i_adaptor ].type & XvInputMask ) ||
1672 !( p_adaptor[ i_adaptor ].type & XvImageMask ) )
1677 /* Check that adaptor supports our requested format... */
1678 p_formats = XvListImageFormats( p_vout->p_sys->p_display,
1679 p_adaptor[i_adaptor].base_id,
1683 i_format < i_num_formats && ( i_selected_port == -1 );
1686 /* Code removed, we can get this through xvinfo anyway */
1688 XvEncodingInfo *p_enc;
1689 int i_enc, i_num_encodings;
1690 XvAttribute *p_attr;
1691 int i_attr, i_num_attributes;
1694 /* If this is not the format we want, or at least a
1695 * similar one, forget it */
1696 if( !vout_ChromaCmp( p_formats[ i_format ].id, i_chroma ) )
1701 /* Look for the first available port supporting this format */
1702 for( i_port = p_adaptor[i_adaptor].base_id;
1703 ( i_port < (int)(p_adaptor[i_adaptor].base_id
1704 + p_adaptor[i_adaptor].num_ports) )
1705 && ( i_selected_port == -1 );
1708 if( XvGrabPort( p_vout->p_sys->p_display, i_port, CurrentTime )
1711 i_selected_port = i_port;
1712 *pi_newchroma = p_formats[ i_format ].id;
1716 /* If no free port was found, forget it */
1717 if( i_selected_port == -1 )
1722 /* If we found a port, print information about it */
1723 msg_Dbg( p_vout, "adaptor %i, port %i, format 0x%x (%4.4s) %s",
1724 i_adaptor, i_selected_port, p_formats[ i_format ].id,
1725 (char *)&p_formats[ i_format ].id,
1726 ( p_formats[ i_format ].format == XvPacked ) ?
1727 "packed" : "planar" );
1730 msg_Dbg( p_vout, " encoding list:" );
1732 if( XvQueryEncodings( p_vout->p_sys->p_display, i_selected_port,
1733 &i_num_encodings, &p_enc )
1736 msg_Dbg( p_vout, " XvQueryEncodings failed" );
1740 for( i_enc = 0; i_enc < i_num_encodings; i_enc++ )
1742 msg_Dbg( p_vout, " id=%ld, name=%s, size=%ldx%ld,"
1743 " numerator=%d, denominator=%d",
1744 p_enc[i_enc].encoding_id, p_enc[i_enc].name,
1745 p_enc[i_enc].width, p_enc[i_enc].height,
1746 p_enc[i_enc].rate.numerator,
1747 p_enc[i_enc].rate.denominator );
1752 XvFreeEncodingInfo( p_enc );
1755 msg_Dbg( p_vout, " attribute list:" );
1756 p_attr = XvQueryPortAttributes( p_vout->p_sys->p_display,
1758 &i_num_attributes );
1759 for( i_attr = 0; i_attr < i_num_attributes; i_attr++ )
1761 msg_Dbg( p_vout, " name=%s, flags=[%s%s ], min=%i, max=%i",
1762 p_attr[i_attr].name,
1763 (p_attr[i_attr].flags & XvGettable) ? " get" : "",
1764 (p_attr[i_attr].flags & XvSettable) ? " set" : "",
1765 p_attr[i_attr].min_value, p_attr[i_attr].max_value );
1768 if( p_attr != NULL )
1775 if( p_formats != NULL )
1782 if( i_num_adaptors > 0 )
1784 XvFreeAdaptorInfo( p_adaptor );
1787 if( i_selected_port == -1 )
1789 int i_chroma_tmp = X112VLC_FOURCC( i_chroma );
1790 if( i_requested_adaptor == -1 )
1792 msg_Warn( p_vout, "no free XVideo port found for format "
1793 "0x%.8x (%4.4s)", i_chroma_tmp, (char*)&i_chroma_tmp );
1797 msg_Warn( p_vout, "XVideo adaptor %i does not have a free "
1798 "XVideo port for format 0x%.8x (%4.4s)",
1799 i_requested_adaptor, i_chroma_tmp, (char*)&i_chroma_tmp );
1803 return i_selected_port;
1806 /*****************************************************************************
1807 * XVideoReleasePort: release YUV12 port
1808 *****************************************************************************/
1809 static void XVideoReleasePort( vout_thread_t *p_vout, int i_port )
1811 XvUngrabPort( p_vout->p_sys->p_display, i_port, CurrentTime );
1815 /*****************************************************************************
1816 * InitDisplay: open and initialize X11 device
1817 *****************************************************************************
1818 * Create a window according to video output given size, and set other
1819 * properties according to the display properties.
1820 *****************************************************************************/
1821 static int InitDisplay( vout_thread_t *p_vout )
1823 #ifdef MODULE_NAME_IS_x11
1824 XPixmapFormatValues * p_formats; /* pixmap formats */
1825 XVisualInfo * p_xvisual; /* visuals informations */
1826 XVisualInfo xvisual_template; /* visual template */
1827 int i_count; /* array size */
1830 #ifdef HAVE_SYS_SHM_H
1831 p_vout->p_sys->b_shm = 0;
1833 if( config_GetInt( p_vout, MODULE_STRING "-shm" ) )
1836 /* FIXME: As of 2001-03-16, XFree4 for MacOS X does not support Xshm */
1838 p_vout->p_sys->b_shm =
1839 ( XShmQueryExtension( p_vout->p_sys->p_display ) == True );
1842 if( !p_vout->p_sys->b_shm )
1844 msg_Warn( p_vout, "XShm video extension is unavailable" );
1849 msg_Dbg( p_vout, "disabling XShm video extension" );
1853 msg_Warn( p_vout, "XShm video extension is unavailable" );
1857 #ifdef MODULE_NAME_IS_xvideo
1858 /* XXX The brightness and contrast values should be read from environment
1859 * XXX variables... */
1861 XVideoSetAttribute( p_vout, "XV_BRIGHTNESS", 0.5 );
1862 XVideoSetAttribute( p_vout, "XV_CONTRAST", 0.5 );
1866 #ifdef MODULE_NAME_IS_x11
1867 /* Initialize structure */
1868 p_vout->p_sys->i_screen = DefaultScreen( p_vout->p_sys->p_display );
1870 /* Get screen depth */
1871 p_vout->p_sys->i_screen_depth = XDefaultDepth( p_vout->p_sys->p_display,
1872 p_vout->p_sys->i_screen );
1873 switch( p_vout->p_sys->i_screen_depth )
1877 * Screen depth is 8bpp. Use PseudoColor visual with private colormap.
1879 xvisual_template.screen = p_vout->p_sys->i_screen;
1880 xvisual_template.class = DirectColor;
1881 p_xvisual = XGetVisualInfo( p_vout->p_sys->p_display,
1882 VisualScreenMask | VisualClassMask,
1883 &xvisual_template, &i_count );
1884 if( p_xvisual == NULL )
1886 msg_Err( p_vout, "no PseudoColor visual available" );
1887 return VLC_EGENERIC;
1889 p_vout->p_sys->i_bytes_per_pixel = 1;
1890 p_vout->output.pf_setpalette = SetPalette;
1897 * Screen depth is higher than 8bpp. TrueColor visual is used.
1899 xvisual_template.screen = p_vout->p_sys->i_screen;
1900 xvisual_template.class = TrueColor;
1901 p_xvisual = XGetVisualInfo( p_vout->p_sys->p_display,
1902 VisualScreenMask | VisualClassMask,
1903 &xvisual_template, &i_count );
1904 if( p_xvisual == NULL )
1906 msg_Err( p_vout, "no TrueColor visual available" );
1907 return VLC_EGENERIC;
1910 p_vout->output.i_rmask = p_xvisual->red_mask;
1911 p_vout->output.i_gmask = p_xvisual->green_mask;
1912 p_vout->output.i_bmask = p_xvisual->blue_mask;
1914 /* There is no difference yet between 3 and 4 Bpp. The only way
1915 * to find the actual number of bytes per pixel is to list supported
1916 * pixmap formats. */
1917 p_formats = XListPixmapFormats( p_vout->p_sys->p_display, &i_count );
1918 p_vout->p_sys->i_bytes_per_pixel = 0;
1920 for( ; i_count-- ; p_formats++ )
1922 /* Under XFree4.0, the list contains pixmap formats available
1923 * through all video depths ; so we have to check against current
1925 if( p_formats->depth == (int)p_vout->p_sys->i_screen_depth )
1927 if( p_formats->bits_per_pixel / 8
1928 > (int)p_vout->p_sys->i_bytes_per_pixel )
1930 p_vout->p_sys->i_bytes_per_pixel =
1931 p_formats->bits_per_pixel / 8;
1937 p_vout->p_sys->p_visual = p_xvisual->visual;
1944 #ifdef HAVE_SYS_SHM_H
1945 /*****************************************************************************
1946 * CreateShmImage: create an XImage or XvImage using shared memory extension
1947 *****************************************************************************
1948 * Prepare an XImage or XvImage for display function.
1949 * The order of the operations respects the recommandations of the mit-shm
1950 * document by J.Corbet and K.Packard. Most of the parameters were copied from
1951 * there. See http://ftp.xfree86.org/pub/XFree86/4.0/doc/mit-shm.TXT
1952 *****************************************************************************/
1953 static IMAGE_TYPE * CreateShmImage( vout_thread_t *p_vout,
1954 Display* p_display, EXTRA_ARGS_SHM,
1955 int i_width, int i_height )
1957 IMAGE_TYPE *p_image;
1959 /* Create XImage / XvImage */
1960 #ifdef MODULE_NAME_IS_xvideo
1961 p_image = XvShmCreateImage( p_display, i_xvport, i_chroma, 0,
1962 i_width, i_height, p_shm );
1964 p_image = XShmCreateImage( p_display, p_visual, i_depth, ZPixmap, 0,
1965 p_shm, i_width, i_height );
1967 if( p_image == NULL )
1969 msg_Err( p_vout, "image creation failed" );
1973 /* Allocate shared memory segment - 0776 set the access permission
1974 * rights (like umask), they are not yet supported by all X servers */
1975 p_shm->shmid = shmget( IPC_PRIVATE, DATA_SIZE(p_image), IPC_CREAT | 0776 );
1976 if( p_shm->shmid < 0 )
1978 msg_Err( p_vout, "cannot allocate shared image data (%s)",
1979 strerror( errno ) );
1980 IMAGE_FREE( p_image );
1984 /* Attach shared memory segment to process (read/write) */
1985 p_shm->shmaddr = p_image->data = shmat( p_shm->shmid, 0, 0 );
1986 if(! p_shm->shmaddr )
1988 msg_Err( p_vout, "cannot attach shared memory (%s)",
1990 IMAGE_FREE( p_image );
1991 shmctl( p_shm->shmid, IPC_RMID, 0 );
1995 /* Read-only data. We won't be using XShmGetImage */
1996 p_shm->readOnly = True;
1998 /* Attach shared memory segment to X server */
1999 if( XShmAttach( p_display, p_shm ) == False )
2001 msg_Err( p_vout, "cannot attach shared memory to X server" );
2002 IMAGE_FREE( p_image );
2003 shmctl( p_shm->shmid, IPC_RMID, 0 );
2004 shmdt( p_shm->shmaddr );
2008 /* Send image to X server. This instruction is required, since having
2009 * built a Shm XImage and not using it causes an error on XCloseDisplay,
2010 * and remember NOT to use XFlush ! */
2011 XSync( p_display, False );
2014 /* Mark the shm segment to be removed when there are no more
2015 * attachements, so it is automatic on process exit or after shmdt */
2016 shmctl( p_shm->shmid, IPC_RMID, 0 );
2023 /*****************************************************************************
2024 * CreateImage: create an XImage or XvImage
2025 *****************************************************************************
2026 * Create a simple image used as a buffer.
2027 *****************************************************************************/
2028 static IMAGE_TYPE * CreateImage( vout_thread_t *p_vout,
2029 Display *p_display, EXTRA_ARGS,
2030 int i_width, int i_height )
2032 byte_t * p_data; /* image data storage zone */
2033 IMAGE_TYPE *p_image;
2034 #ifdef MODULE_NAME_IS_x11
2035 int i_quantum; /* XImage quantum (see below) */
2036 int i_bytes_per_line;
2039 /* Allocate memory for image */
2040 #ifdef MODULE_NAME_IS_xvideo
2041 p_data = (byte_t *) malloc( i_width * i_height * i_bits_per_pixel / 8 );
2043 i_bytes_per_line = i_width * i_bytes_per_pixel;
2044 p_data = (byte_t *) malloc( i_bytes_per_line * i_height );
2048 msg_Err( p_vout, "out of memory" );
2052 #ifdef MODULE_NAME_IS_x11
2053 /* Optimize the quantum of a scanline regarding its size - the quantum is
2054 a diviser of the number of bits between the start of two scanlines. */
2055 if( i_bytes_per_line & 0xf )
2059 else if( i_bytes_per_line & 0x10 )
2069 /* Create XImage. p_data will be automatically freed */
2070 #ifdef MODULE_NAME_IS_xvideo
2071 p_image = XvCreateImage( p_display, i_xvport, i_chroma,
2072 p_data, i_width, i_height );
2074 p_image = XCreateImage( p_display, p_visual, i_depth, ZPixmap, 0,
2075 p_data, i_width, i_height, i_quantum, 0 );
2077 if( p_image == NULL )
2079 msg_Err( p_vout, "XCreateImage() failed" );
2087 #ifdef MODULE_NAME_IS_x11
2088 /*****************************************************************************
2089 * SetPalette: sets an 8 bpp palette
2090 *****************************************************************************
2091 * This function sets the palette given as an argument. It does not return
2092 * anything, but could later send information on which colors it was unable
2094 *****************************************************************************/
2095 static void SetPalette( vout_thread_t *p_vout,
2096 uint16_t *red, uint16_t *green, uint16_t *blue )
2099 XColor p_colors[255];
2101 /* allocate palette */
2102 for( i = 0; i < 255; i++ )
2104 /* kludge: colors are indexed reversely because color 255 seems
2105 * to be reserved for black even if we try to set it to white */
2106 p_colors[ i ].pixel = 255 - i;
2107 p_colors[ i ].pad = 0;
2108 p_colors[ i ].flags = DoRed | DoGreen | DoBlue;
2109 p_colors[ i ].red = red[ 255 - i ];
2110 p_colors[ i ].blue = blue[ 255 - i ];
2111 p_colors[ i ].green = green[ 255 - i ];
2114 XStoreColors( p_vout->p_sys->p_display,
2115 p_vout->p_sys->colormap, p_colors, 255 );
2119 /*****************************************************************************
2120 * Control: control facility for the vout
2121 *****************************************************************************/
2122 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
2129 if( p_vout->p_sys->p_win->owner_window )
2130 return vout_ControlWindow( p_vout,
2131 (void *)p_vout->p_sys->p_win->owner_window, i_query, args);
2133 f_arg = va_arg( args, double );
2135 /* Update dimensions */
2136 XResizeWindow( p_vout->p_sys->p_display,
2137 p_vout->p_sys->p_win->base_window,
2138 p_vout->render.i_width * f_arg,
2139 p_vout->render.i_height * f_arg );
2144 XReparentWindow( p_vout->p_sys->p_display,
2145 p_vout->p_sys->p_win->base_window,
2146 DefaultRootWindow( p_vout->p_sys->p_display ),
2148 XSync( p_vout->p_sys->p_display, False );
2149 p_vout->p_sys->p_win->owner_window = 0;
2153 msg_Dbg( p_vout, "control query not supported" );
2154 return VLC_EGENERIC;
2158 /*****************************************************************************
2159 * TestNetWMSupport: tests for Extended Window Manager Hints support
2160 *****************************************************************************/
2161 static void TestNetWMSupport( vout_thread_t *p_vout )
2163 int i_ret, i_format;
2164 unsigned long i, i_items, i_bytesafter;
2165 Atom net_wm_supported, *p_args = NULL;
2167 p_vout->p_sys->b_net_wm_state_fullscreen = VLC_FALSE;
2168 p_vout->p_sys->b_net_wm_state_above = VLC_FALSE;
2169 p_vout->p_sys->b_net_wm_state_below = VLC_FALSE;
2170 p_vout->p_sys->b_net_wm_state_stays_on_top = VLC_FALSE;
2173 XInternAtom( p_vout->p_sys->p_display, "_NET_SUPPORTED", False );
2175 i_ret = XGetWindowProperty( p_vout->p_sys->p_display,
2176 DefaultRootWindow( p_vout->p_sys->p_display ),
2178 0, 16384, False, AnyPropertyType,
2180 &i_format, &i_items, &i_bytesafter,
2181 (unsigned char **)(intptr_t)&p_args );
2183 if( i_ret != Success || i_items == 0 ) return;
2185 msg_Dbg( p_vout, "Window manager supports NetWM" );
2187 p_vout->p_sys->net_wm_state =
2188 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE", False );
2189 p_vout->p_sys->net_wm_state_fullscreen =
2190 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE_FULLSCREEN",
2192 p_vout->p_sys->net_wm_state_above =
2193 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE_ABOVE", False );
2194 p_vout->p_sys->net_wm_state_below =
2195 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE_BELOW", False );
2196 p_vout->p_sys->net_wm_state_stays_on_top =
2197 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE_STAYS_ON_TOP",
2200 for( i = 0; i < i_items; i++ )
2202 if( p_args[i] == p_vout->p_sys->net_wm_state_fullscreen )
2205 "Window manager supports _NET_WM_STATE_FULLSCREEN" );
2206 p_vout->p_sys->b_net_wm_state_fullscreen = VLC_TRUE;
2208 else if( p_args[i] == p_vout->p_sys->net_wm_state_above )
2210 msg_Dbg( p_vout, "Window manager supports _NET_WM_STATE_ABOVE" );
2211 p_vout->p_sys->b_net_wm_state_above = VLC_TRUE;
2213 else if( p_args[i] == p_vout->p_sys->net_wm_state_below )
2215 msg_Dbg( p_vout, "Window manager supports _NET_WM_STATE_BELOW" );
2216 p_vout->p_sys->b_net_wm_state_below = VLC_TRUE;
2218 else if( p_args[i] == p_vout->p_sys->net_wm_state_stays_on_top )
2221 "Window manager supports _NET_WM_STATE_STAYS_ON_TOP" );
2222 p_vout->p_sys->b_net_wm_state_stays_on_top = VLC_TRUE;
2229 /*****************************************************************************
2230 * Key events handling
2231 *****************************************************************************/
2237 } x11keys_to_vlckeys[] =
2239 { XK_F1, KEY_F1 }, { XK_F2, KEY_F2 }, { XK_F3, KEY_F3 }, { XK_F4, KEY_F4 },
2240 { XK_F5, KEY_F5 }, { XK_F6, KEY_F6 }, { XK_F7, KEY_F7 }, { XK_F8, KEY_F8 },
2241 { XK_F9, KEY_F9 }, { XK_F10, KEY_F10 }, { XK_F11, KEY_F11 },
2242 { XK_F12, KEY_F12 },
2244 { XK_Return, KEY_ENTER },
2245 { XK_KP_Enter, KEY_ENTER },
2246 { XK_space, KEY_SPACE },
2247 { XK_Escape, KEY_ESC },
2249 { XK_Menu, KEY_MENU },
2250 { XK_Left, KEY_LEFT },
2251 { XK_Right, KEY_RIGHT },
2253 { XK_Down, KEY_DOWN },
2255 { XK_Home, KEY_HOME },
2256 { XK_End, KEY_END },
2257 { XK_Page_Up, KEY_PAGEUP },
2258 { XK_Page_Down, KEY_PAGEDOWN },
2262 static int ConvertKey( int i_key )
2266 for( i = 0; x11keys_to_vlckeys[i].i_x11key != 0; i++ )
2268 if( x11keys_to_vlckeys[i].i_x11key == i_key )
2270 return x11keys_to_vlckeys[i].i_vlckey;
2277 /*****************************************************************************
2278 * object variables callbacks: a bunch of object variables are used by the
2279 * interfaces to interact with the vout.
2280 *****************************************************************************/
2281 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
2282 vlc_value_t oldval, vlc_value_t newval, void *p_data )
2284 vout_thread_t *p_vout = (vout_thread_t *)p_this;
2286 if( p_vout->p_sys->b_net_wm_state_stays_on_top )
2288 XClientMessageEvent event;
2290 memset( &event, 0, sizeof( XClientMessageEvent ) );
2292 event.type = ClientMessage;
2293 event.message_type = p_vout->p_sys->net_wm_state;
2294 event.display = p_vout->p_sys->p_display;
2295 event.window = p_vout->p_sys->p_win->base_window;
2297 event.data.l[ 0 ] = newval.b_bool; /* set property */
2298 event.data.l[ 1 ] = p_vout->p_sys->net_wm_state_stays_on_top;
2300 XSendEvent( p_vout->p_sys->p_display,
2301 DefaultRootWindow( p_vout->p_sys->p_display ),
2302 False, SubstructureRedirectMask,