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>
70 #ifdef MODULE_NAME_IS_glx
75 # include <X11/extensions/Xinerama.h>
80 /*****************************************************************************
82 *****************************************************************************/
83 int E_(Activate) ( vlc_object_t * );
84 void E_(Deactivate) ( vlc_object_t * );
86 static int InitVideo ( vout_thread_t * );
87 static void EndVideo ( vout_thread_t * );
88 static void DisplayVideo ( vout_thread_t *, picture_t * );
89 static int ManageVideo ( vout_thread_t * );
90 static int Control ( vout_thread_t *, int, va_list );
92 static int InitDisplay ( vout_thread_t * );
94 static int CreateWindow ( vout_thread_t *, x11_window_t * );
95 static void DestroyWindow ( vout_thread_t *, x11_window_t * );
97 static int NewPicture ( vout_thread_t *, picture_t * );
98 static void FreePicture ( vout_thread_t *, picture_t * );
100 static IMAGE_TYPE *CreateImage ( vout_thread_t *,
101 Display *, EXTRA_ARGS, int, int );
102 #ifdef HAVE_SYS_SHM_H
103 static IMAGE_TYPE *CreateShmImage ( vout_thread_t *,
104 Display *, EXTRA_ARGS_SHM, int, int );
107 static void ToggleFullScreen ( vout_thread_t * );
109 static void EnableXScreenSaver ( vout_thread_t * );
110 static void DisableXScreenSaver ( vout_thread_t * );
112 static void CreateCursor ( vout_thread_t * );
113 static void DestroyCursor ( vout_thread_t * );
114 static void ToggleCursor ( vout_thread_t * );
116 #ifdef MODULE_NAME_IS_xvideo
117 static int XVideoGetPort ( vout_thread_t *, vlc_fourcc_t, vlc_fourcc_t * );
118 static void XVideoReleasePort( vout_thread_t *, int );
121 #ifdef MODULE_NAME_IS_x11
122 static void SetPalette ( vout_thread_t *,
123 uint16_t *, uint16_t *, uint16_t * );
126 static void TestNetWMSupport( vout_thread_t * );
127 static int ConvertKey( int );
129 static int WindowOnTop( vout_thread_t *, vlc_bool_t );
131 /*****************************************************************************
132 * Activate: allocate X11 video thread output method
133 *****************************************************************************
134 * This function allocate and initialize a X11 vout method. It uses some of the
135 * vout properties to choose the window size, and change them according to the
136 * actual properties of the display.
137 *****************************************************************************/
138 int E_(Activate) ( vlc_object_t *p_this )
140 vout_thread_t *p_vout = (vout_thread_t *)p_this;
144 #ifdef MODULE_NAME_IS_xvideo
146 vlc_fourcc_t i_chroma = 0;
147 vlc_bool_t b_chroma = 0;
150 p_vout->pf_init = InitVideo;
151 p_vout->pf_end = EndVideo;
152 p_vout->pf_manage = ManageVideo;
153 p_vout->pf_render = NULL;
154 p_vout->pf_display = DisplayVideo;
155 p_vout->pf_control = Control;
157 /* Allocate structure */
158 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
159 if( p_vout->p_sys == NULL )
161 msg_Err( p_vout, "out of memory" );
165 vlc_mutex_init( p_vout, &p_vout->p_sys->lock );
167 /* Open display, using the "display" config variable or the DISPLAY
168 * environment variable */
169 psz_display = config_GetPsz( p_vout, MODULE_STRING "-display" );
171 p_vout->p_sys->p_display = XOpenDisplay( psz_display );
173 if( p_vout->p_sys->p_display == NULL ) /* error */
175 msg_Err( p_vout, "cannot open display %s",
176 XDisplayName( psz_display ) );
177 free( p_vout->p_sys );
178 if( psz_display ) free( psz_display );
181 if( psz_display ) free( psz_display );
183 /* Get a screen ID matching the XOpenDisplay return value */
184 p_vout->p_sys->i_screen = DefaultScreen( p_vout->p_sys->p_display );
186 #ifdef MODULE_NAME_IS_xvideo
187 psz_chroma = config_GetPsz( p_vout, "xvideo-chroma" );
190 if( strlen( psz_chroma ) >= 4 )
192 /* Do not use direct assignment because we are not sure of the
194 memcpy(&i_chroma, psz_chroma, 4);
203 msg_Dbg( p_vout, "forcing chroma 0x%.8x (%4.4s)",
204 i_chroma, (char*)&i_chroma );
208 i_chroma = p_vout->render.i_chroma;
211 /* Check that we have access to an XVideo port providing this chroma */
212 p_vout->p_sys->i_xvport = XVideoGetPort( p_vout, VLC2X11_FOURCC(i_chroma),
213 &p_vout->output.i_chroma );
214 if( p_vout->p_sys->i_xvport < 0 )
216 /* If a specific chroma format was requested, then we don't try to
217 * be cleverer than the user. He knew pretty well what he wanted. */
220 XCloseDisplay( p_vout->p_sys->p_display );
221 free( p_vout->p_sys );
225 /* It failed, but it's not completely lost ! We try to open an
226 * XVideo port for an YUY2 picture. We'll need to do an YUV
227 * conversion, but at least it has got scaling. */
228 p_vout->p_sys->i_xvport =
229 XVideoGetPort( p_vout, X11_FOURCC('Y','U','Y','2'),
230 &p_vout->output.i_chroma );
231 if( p_vout->p_sys->i_xvport < 0 )
233 /* It failed, but it's not completely lost ! We try to open an
234 * XVideo port for a simple 16bpp RGB picture. We'll need to do
235 * an YUV conversion, but at least it has got scaling. */
236 p_vout->p_sys->i_xvport =
237 XVideoGetPort( p_vout, X11_FOURCC('R','V','1','6'),
238 &p_vout->output.i_chroma );
239 if( p_vout->p_sys->i_xvport < 0 )
241 XCloseDisplay( p_vout->p_sys->p_display );
242 free( p_vout->p_sys );
247 p_vout->output.i_chroma = X112VLC_FOURCC(p_vout->output.i_chroma);
250 /* Create blank cursor (for mouse cursor autohiding) */
251 p_vout->p_sys->i_time_mouse_last_moved = mdate();
252 p_vout->p_sys->b_mouse_pointer_visible = 1;
253 CreateCursor( p_vout );
255 /* Set main window's size */
256 p_vout->p_sys->original_window.i_width = p_vout->i_window_width;
257 p_vout->p_sys->original_window.i_height = p_vout->i_window_height;
259 /* Spawn base window - this window will include the video output window,
260 * but also command buttons, subtitles and other indicators */
261 if( CreateWindow( p_vout, &p_vout->p_sys->original_window ) )
263 msg_Err( p_vout, "cannot create X11 window" );
264 DestroyCursor( p_vout );
265 XCloseDisplay( p_vout->p_sys->p_display );
266 free( p_vout->p_sys );
270 /* Open and initialize device. */
271 if( InitDisplay( p_vout ) )
273 msg_Err( p_vout, "cannot initialize X11 display" );
274 DestroyCursor( p_vout );
275 DestroyWindow( p_vout, &p_vout->p_sys->original_window );
276 XCloseDisplay( p_vout->p_sys->p_display );
277 free( p_vout->p_sys );
281 /* Disable screen saver */
282 DisableXScreenSaver( p_vout );
285 p_vout->p_sys->b_altfullscreen = 0;
286 p_vout->p_sys->i_time_button_last_pressed = 0;
288 TestNetWMSupport( p_vout );
290 /* Variable to indicate if the window should be on top of others */
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 );
325 #elif defined(MODULE_NAME_IS_xvideo)
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 vlc_mutex_destroy( &p_vout->p_sys->lock );
337 free( p_vout->p_sys );
340 /*****************************************************************************
341 * InitVideo: initialize X11 video thread output method
342 *****************************************************************************
343 * This function create the XImages needed by the output thread. It is called
344 * at the beginning of the thread, but also each time the window is resized.
345 *****************************************************************************/
346 static int InitVideo( vout_thread_t *p_vout )
351 I_OUTPUTPICTURES = 0;
353 #ifdef MODULE_NAME_IS_xvideo
354 /* Initialize the output structure; we already found an XVideo port,
355 * and the corresponding chroma we will be using. Since we can
356 * arbitrary scale, stick to the coordinates and aspect. */
357 p_vout->output.i_width = p_vout->render.i_width;
358 p_vout->output.i_height = p_vout->render.i_height;
359 p_vout->output.i_aspect = p_vout->render.i_aspect;
361 switch( p_vout->output.i_chroma )
363 case VLC_FOURCC('R','V','1','5'):
364 p_vout->output.i_rmask = 0x001f;
365 p_vout->output.i_gmask = 0x07e0;
366 p_vout->output.i_bmask = 0xf800;
368 case VLC_FOURCC('R','V','1','6'):
369 p_vout->output.i_rmask = 0x001f;
370 p_vout->output.i_gmask = 0x03e0;
371 p_vout->output.i_bmask = 0x7c00;
375 #elif defined(MODULE_NAME_IS_x11)
376 /* Initialize the output structure: RGB with square pixels, whatever
377 * the input format is, since it's the only format we know */
378 switch( p_vout->p_sys->i_screen_depth )
380 case 8: /* FIXME: set the palette */
381 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2'); break;
383 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5'); break;
385 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); break;
387 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4'); break;
389 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); break;
391 msg_Err( p_vout, "unknown screen depth %i",
392 p_vout->p_sys->i_screen_depth );
396 vout_PlacePicture( p_vout, p_vout->p_sys->p_win->i_width,
397 p_vout->p_sys->p_win->i_height,
399 &p_vout->output.i_width, &p_vout->output.i_height );
401 /* Assume we have square pixels */
402 p_vout->output.i_aspect = p_vout->output.i_width
403 * VOUT_ASPECT_FACTOR / p_vout->output.i_height;
406 /* Try to initialize up to MAX_DIRECTBUFFERS direct buffers */
407 while( I_OUTPUTPICTURES < MAX_DIRECTBUFFERS )
411 /* Find an empty picture slot */
412 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
414 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
416 p_pic = p_vout->p_picture + i_index;
421 /* Allocate the picture */
422 if( p_pic == NULL || NewPicture( p_vout, p_pic ) )
427 p_pic->i_status = DESTROYED_PICTURE;
428 p_pic->i_type = DIRECT_PICTURE;
430 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
438 /*****************************************************************************
439 * DisplayVideo: displays previously rendered output
440 *****************************************************************************
441 * This function sends the currently rendered image to X11 server.
442 * (The Xv extension takes care of "double-buffering".)
443 *****************************************************************************/
444 static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
446 int i_width, i_height, i_x, i_y;
448 vout_PlacePicture( p_vout, p_vout->p_sys->p_win->i_width,
449 p_vout->p_sys->p_win->i_height,
450 &i_x, &i_y, &i_width, &i_height );
452 vlc_mutex_lock( &p_vout->p_sys->lock );
454 #ifdef HAVE_SYS_SHM_H
455 if( p_vout->p_sys->b_shm )
457 /* Display rendered image using shared memory extension */
458 # ifdef MODULE_NAME_IS_xvideo
459 XvShmPutImage( p_vout->p_sys->p_display, p_vout->p_sys->i_xvport,
460 p_vout->p_sys->p_win->video_window,
461 p_vout->p_sys->p_win->gc, p_pic->p_sys->p_image,
462 0 /*src_x*/, 0 /*src_y*/,
463 p_vout->output.i_width, p_vout->output.i_height,
464 0 /*dest_x*/, 0 /*dest_y*/, i_width, i_height,
465 False /* Don't put True here or you'll waste your CPU */ );
467 XShmPutImage( p_vout->p_sys->p_display,
468 p_vout->p_sys->p_win->video_window,
469 p_vout->p_sys->p_win->gc, p_pic->p_sys->p_image,
470 0 /*src_x*/, 0 /*src_y*/, 0 /*dest_x*/, 0 /*dest_y*/,
471 p_vout->output.i_width, p_vout->output.i_height,
472 False /* Don't put True here ! */ );
476 #endif /* HAVE_SYS_SHM_H */
478 /* Use standard XPutImage -- this is gonna be slow ! */
479 #ifdef MODULE_NAME_IS_xvideo
480 XvPutImage( p_vout->p_sys->p_display, p_vout->p_sys->i_xvport,
481 p_vout->p_sys->p_win->video_window,
482 p_vout->p_sys->p_win->gc, p_pic->p_sys->p_image,
483 0 /*src_x*/, 0 /*src_y*/,
484 p_vout->output.i_width, p_vout->output.i_height,
485 0 /*dest_x*/, 0 /*dest_y*/, i_width, i_height );
487 XPutImage( p_vout->p_sys->p_display,
488 p_vout->p_sys->p_win->video_window,
489 p_vout->p_sys->p_win->gc, p_pic->p_sys->p_image,
490 0 /*src_x*/, 0 /*src_y*/, 0 /*dest_x*/, 0 /*dest_y*/,
491 p_vout->output.i_width, p_vout->output.i_height );
495 /* Make sure the command is sent now - do NOT use XFlush !*/
496 XSync( p_vout->p_sys->p_display, False );
498 vlc_mutex_unlock( &p_vout->p_sys->lock );
501 /*****************************************************************************
502 * ManageVideo: handle X11 events
503 *****************************************************************************
504 * This function should be called regularly by video output thread. It manages
505 * X11 events and allows window resizing. It returns a non null value on
507 *****************************************************************************/
508 static int ManageVideo( vout_thread_t *p_vout )
510 XEvent xevent; /* X11 event */
513 vlc_mutex_lock( &p_vout->p_sys->lock );
515 /* Handle events from the owner window */
516 if( p_vout->p_sys->p_win->owner_window )
518 while( XCheckWindowEvent( p_vout->p_sys->p_display,
519 p_vout->p_sys->p_win->owner_window,
520 StructureNotifyMask, &xevent ) == True )
522 /* ConfigureNotify event: prepare */
523 if( xevent.type == ConfigureNotify )
525 /* Update dimensions */
526 XResizeWindow( p_vout->p_sys->p_display,
527 p_vout->p_sys->p_win->base_window,
528 xevent.xconfigure.width,
529 xevent.xconfigure.height );
534 /* Handle X11 events: ConfigureNotify events are parsed to know if the
535 * output window's size changed, MapNotify and UnmapNotify to know if the
536 * window is mapped (and if the display is useful), and ClientMessages
537 * to intercept window destruction requests */
539 while( XCheckWindowEvent( p_vout->p_sys->p_display,
540 p_vout->p_sys->p_win->base_window,
541 StructureNotifyMask | KeyPressMask |
542 ButtonPressMask | ButtonReleaseMask |
543 PointerMotionMask | Button1MotionMask , &xevent )
546 /* ConfigureNotify event: prepare */
547 if( xevent.type == ConfigureNotify )
549 if( (unsigned int)xevent.xconfigure.width
550 != p_vout->p_sys->p_win->i_width
551 || (unsigned int)xevent.xconfigure.height
552 != p_vout->p_sys->p_win->i_height )
554 /* Update dimensions */
555 p_vout->i_changes |= VOUT_SIZE_CHANGE;
556 p_vout->p_sys->p_win->i_width = xevent.xconfigure.width;
557 p_vout->p_sys->p_win->i_height = xevent.xconfigure.height;
561 else if( xevent.type == KeyPress )
563 unsigned int state = xevent.xkey.state;
565 char i_key; /* ISO Latin-1 key */
567 /* We may have keys like F1 trough F12, ESC ... */
568 x_key_symbol = XKeycodeToKeysym( p_vout->p_sys->p_display,
569 xevent.xkey.keycode, 0 );
570 val.i_int = ConvertKey( (int)x_key_symbol );
572 xevent.xkey.state &= ~ShiftMask;
573 xevent.xkey.state &= ~ControlMask;
574 xevent.xkey.state &= ~Mod1Mask;
577 XLookupString( &xevent.xkey, &i_key, 1, NULL, NULL ) )
580 * The reason why I use this instead of XK_0 is that
581 * with XLookupString, we don't have to care about
588 if( state & ShiftMask )
590 val.i_int |= KEY_MODIFIER_SHIFT;
592 if( state & ControlMask )
594 val.i_int |= KEY_MODIFIER_CTRL;
596 if( state & Mod1Mask )
598 val.i_int |= KEY_MODIFIER_ALT;
600 var_Set( p_vout->p_vlc, "key-pressed", val );
604 else if( xevent.type == ButtonPress )
606 switch( ((XButtonEvent *)&xevent)->button )
609 var_Get( p_vout, "mouse-button-down", &val );
611 var_Set( p_vout, "mouse-button-down", val );
613 /* detect double-clicks */
614 if( ( ((XButtonEvent *)&xevent)->time -
615 p_vout->p_sys->i_time_button_last_pressed ) < 300 )
617 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
620 p_vout->p_sys->i_time_button_last_pressed =
621 ((XButtonEvent *)&xevent)->time;
624 var_Get( p_vout, "mouse-button-down", &val );
626 var_Set( p_vout, "mouse-button-down", val );
630 var_Get( p_vout, "mouse-button-down", &val );
632 var_Set( p_vout, "mouse-button-down", val );
636 var_Get( p_vout, "mouse-button-down", &val );
638 var_Set( p_vout, "mouse-button-down", val );
642 var_Get( p_vout, "mouse-button-down", &val );
644 var_Set( p_vout, "mouse-button-down", val );
649 else if( xevent.type == ButtonRelease )
651 switch( ((XButtonEvent *)&xevent)->button )
654 var_Get( p_vout, "mouse-button-down", &val );
656 var_Set( p_vout, "mouse-button-down", val );
658 val.b_bool = VLC_TRUE;
659 var_Set( p_vout, "mouse-clicked", val );
664 playlist_t *p_playlist;
666 var_Get( p_vout, "mouse-button-down", &val );
668 var_Set( p_vout, "mouse-button-down", val );
670 p_playlist = vlc_object_find( p_vout,
673 if( p_playlist != NULL )
676 var_Get( p_playlist, "intf-show", &val );
677 val.b_bool = !val.b_bool;
678 var_Set( p_playlist, "intf-show", val );
679 vlc_object_release( p_playlist );
686 intf_thread_t *p_intf;
687 playlist_t *p_playlist;
689 var_Get( p_vout, "mouse-button-down", &val );
691 var_Set( p_vout, "mouse-button-down", val );
692 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
696 p_intf->b_menu_change = 1;
697 vlc_object_release( p_intf );
700 p_playlist = vlc_object_find( p_vout,
703 if( p_playlist != NULL )
705 vlc_value_t val; val.b_bool = VLC_TRUE;
706 var_Set( p_playlist, "intf-popupmenu", val );
707 vlc_object_release( p_playlist );
713 var_Get( p_vout, "mouse-button-down", &val );
715 var_Set( p_vout, "mouse-button-down", val );
719 var_Get( p_vout, "mouse-button-down", &val );
721 var_Set( p_vout, "mouse-button-down", val );
727 else if( xevent.type == MotionNotify )
729 int i_width, i_height, i_x, i_y;
732 /* somewhat different use for vout_PlacePicture:
733 * here the values are needed to give to mouse coordinates
734 * in the original picture space */
735 vout_PlacePicture( p_vout, p_vout->p_sys->p_win->i_width,
736 p_vout->p_sys->p_win->i_height,
737 &i_x, &i_y, &i_width, &i_height );
739 val.i_int = ( xevent.xmotion.x - i_x )
740 * p_vout->render.i_width / i_width;
741 var_Set( p_vout, "mouse-x", val );
742 val.i_int = ( xevent.xmotion.y - i_y )
743 * p_vout->render.i_height / i_height;
744 var_Set( p_vout, "mouse-y", val );
746 val.b_bool = VLC_TRUE;
747 var_Set( p_vout, "mouse-moved", val );
749 p_vout->p_sys->i_time_mouse_last_moved = mdate();
750 if( ! p_vout->p_sys->b_mouse_pointer_visible )
752 ToggleCursor( p_vout );
755 else if( xevent.type == ReparentNotify /* XXX: why do we get this? */
756 || xevent.type == MapNotify
757 || xevent.type == UnmapNotify )
759 /* Ignore these events */
761 else /* Other events */
763 msg_Warn( p_vout, "unhandled event %d received", xevent.type );
767 /* Handle events for video output sub-window */
768 while( XCheckWindowEvent( p_vout->p_sys->p_display,
769 p_vout->p_sys->p_win->video_window,
770 ExposureMask, &xevent ) == True )
772 /* Window exposed (only handled if stream playback is paused) */
773 if( xevent.type == Expose )
775 if( ((XExposeEvent *)&xevent)->count == 0 )
777 /* (if this is the last a collection of expose events...) */
779 if( p_vout->p_vlc->p_input_bank->pp_input[0] != NULL )
781 if( PAUSE_S == p_vout->p_vlc->p_input_bank->pp_input[0]
782 ->stream.control.i_status )
784 /* XVideoDisplay( p_vout )*/;
792 /* ClientMessage event - only WM_PROTOCOLS with WM_DELETE_WINDOW data
793 * are handled - according to the man pages, the format is always 32
795 while( XCheckTypedEvent( p_vout->p_sys->p_display,
796 ClientMessage, &xevent ) )
798 if( (xevent.xclient.message_type == p_vout->p_sys->p_win->wm_protocols)
799 && ((Atom)xevent.xclient.data.l[0]
800 == p_vout->p_sys->p_win->wm_delete_window ) )
802 /* the user wants to close the window */
803 playlist_t * p_playlist =
804 (playlist_t *)vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
806 if( p_playlist != NULL )
808 playlist_Stop( p_playlist );
809 vlc_object_release( p_playlist );
817 if ( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
821 /* Update the object variable and trigger callback */
822 val.b_bool = !p_vout->b_fullscreen;
823 var_Set( p_vout, "fullscreen", val );
825 ToggleFullScreen( p_vout );
826 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
832 * (Needs to be placed after VOUT_FULLSREEN_CHANGE because we can activate
833 * the size flag inside the fullscreen routine)
835 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
837 int i_width, i_height, i_x, i_y;
839 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
841 #ifdef MODULE_NAME_IS_x11
842 /* We need to signal the vout thread about the size change because it
843 * is doing the rescaling */
844 p_vout->i_changes |= VOUT_SIZE_CHANGE;
847 vout_PlacePicture( p_vout, p_vout->p_sys->p_win->i_width,
848 p_vout->p_sys->p_win->i_height,
849 &i_x, &i_y, &i_width, &i_height );
851 XMoveResizeWindow( p_vout->p_sys->p_display,
852 p_vout->p_sys->p_win->video_window,
853 i_x, i_y, i_width, i_height );
856 /* Autohide Cursour */
857 if( mdate() - p_vout->p_sys->i_time_mouse_last_moved > 2000000 )
859 /* Hide the mouse automatically */
860 if( p_vout->p_sys->b_mouse_pointer_visible )
862 ToggleCursor( p_vout );
866 vlc_mutex_unlock( &p_vout->p_sys->lock );
871 /*****************************************************************************
872 * EndVideo: terminate X11 video thread output method
873 *****************************************************************************
874 * Destroy the X11 XImages created by Init. It is called at the end of
875 * the thread, but also each time the window is resized.
876 *****************************************************************************/
877 static void EndVideo( vout_thread_t *p_vout )
881 /* Free the direct buffers we allocated */
882 for( i_index = I_OUTPUTPICTURES ; i_index ; )
885 FreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
889 /* following functions are local */
891 /*****************************************************************************
892 * CreateWindow: open and set-up X11 main window
893 *****************************************************************************/
894 static int CreateWindow( vout_thread_t *p_vout, x11_window_t *p_win )
896 XSizeHints xsize_hints;
897 XSetWindowAttributes xwindow_attributes;
901 vlc_bool_t b_expose = VLC_FALSE;
902 vlc_bool_t b_configure_notify = VLC_FALSE;
903 vlc_bool_t b_map_notify = VLC_FALSE;
905 /* Prepare window manager hints and properties */
906 p_win->wm_protocols =
907 XInternAtom( p_vout->p_sys->p_display, "WM_PROTOCOLS", True );
908 p_win->wm_delete_window =
909 XInternAtom( p_vout->p_sys->p_display, "WM_DELETE_WINDOW", True );
911 /* Never have a 0-pixel-wide window */
912 xsize_hints.min_width = 2;
913 xsize_hints.min_height = 1;
915 /* Prepare window attributes */
916 xwindow_attributes.backing_store = Always; /* save the hidden part */
917 xwindow_attributes.background_pixel = BlackPixel(p_vout->p_sys->p_display,
918 p_vout->p_sys->i_screen);
919 xwindow_attributes.event_mask = ExposureMask | StructureNotifyMask;
921 if( !p_vout->b_fullscreen )
923 p_win->owner_window =
924 (Window)vout_RequestWindow( p_vout, &p_win->i_x, &p_win->i_y,
925 &p_win->i_width, &p_win->i_height );
927 xsize_hints.base_width = xsize_hints.width = p_win->i_width;
928 xsize_hints.base_height = xsize_hints.height = p_win->i_height;
929 xsize_hints.flags = PSize | PMinSize;
931 if( p_win->i_x >=0 || p_win->i_y >= 0 )
933 xsize_hints.x = p_win->i_x;
934 xsize_hints.y = p_win->i_y;
935 xsize_hints.flags |= PPosition;
940 /* Fullscreen window size and position */
941 p_win->owner_window = 0;
942 p_win->i_x = p_win->i_y = 0;
944 DisplayWidth( p_vout->p_sys->p_display, p_vout->p_sys->i_screen );
946 DisplayHeight( p_vout->p_sys->p_display, p_vout->p_sys->i_screen );
949 if( !p_win->owner_window )
951 /* Create the window and set hints - the window must receive
952 * ConfigureNotify events, and until it is displayed, Expose and
953 * MapNotify events. */
956 XCreateWindow( p_vout->p_sys->p_display,
957 DefaultRootWindow( p_vout->p_sys->p_display ),
958 p_win->i_x, p_win->i_y,
959 p_win->i_width, p_win->i_height,
962 CWBackingStore | CWBackPixel | CWEventMask,
963 &xwindow_attributes );
965 if( !p_vout->b_fullscreen )
967 /* Set window manager hints and properties: size hints, command,
968 * window's name, and accepted protocols */
969 XSetWMNormalHints( p_vout->p_sys->p_display,
970 p_win->base_window, &xsize_hints );
971 XSetCommand( p_vout->p_sys->p_display, p_win->base_window,
972 p_vout->p_vlc->ppsz_argv, p_vout->p_vlc->i_argc );
974 XStoreName( p_vout->p_sys->p_display, p_win->base_window,
975 #ifdef MODULE_NAME_IS_x11
976 VOUT_TITLE " (X11 output)"
977 #elif defined(MODULE_NAME_IS_glx)
978 VOUT_TITLE " (GLX output)"
980 VOUT_TITLE " (XVideo output)"
988 unsigned int dummy2, dummy3;
990 /* Select events we are interested in. */
991 XSelectInput( p_vout->p_sys->p_display, p_win->owner_window,
992 StructureNotifyMask );
994 /* Get the parent window's geometry information */
995 XGetGeometry( p_vout->p_sys->p_display, p_win->owner_window,
996 &dummy1, &dummy2, &dummy3,
1001 /* We are already configured */
1002 b_configure_notify = VLC_TRUE;
1004 /* From man XSelectInput: only one client at a time can select a
1005 * ButtonPress event, so we need to open a new window anyway. */
1006 p_win->base_window =
1007 XCreateWindow( p_vout->p_sys->p_display,
1008 p_win->owner_window,
1010 p_win->i_width, p_win->i_height,
1012 0, CopyFromParent, 0,
1013 CWBackingStore | CWBackPixel | CWEventMask,
1014 &xwindow_attributes );
1017 if( (p_win->wm_protocols == None) /* use WM_DELETE_WINDOW */
1018 || (p_win->wm_delete_window == None)
1019 || !XSetWMProtocols( p_vout->p_sys->p_display, p_win->base_window,
1020 &p_win->wm_delete_window, 1 ) )
1022 /* WM_DELETE_WINDOW is not supported by window manager */
1023 msg_Warn( p_vout, "missing or bad window manager" );
1026 /* Creation of a graphic context that doesn't generate a GraphicsExpose
1027 * event when using functions like XCopyArea */
1028 xgcvalues.graphics_exposures = False;
1029 p_win->gc = XCreateGC( p_vout->p_sys->p_display,
1031 GCGraphicsExposures, &xgcvalues );
1033 /* Send orders to server, and wait until window is displayed - three
1034 * events must be received: a MapNotify event, an Expose event allowing
1035 * drawing in the window, and a ConfigureNotify to get the window
1036 * dimensions. Once those events have been received, only
1037 * ConfigureNotify events need to be received. */
1038 XMapWindow( p_vout->p_sys->p_display, p_win->base_window );
1041 XNextEvent( p_vout->p_sys->p_display, &xevent);
1042 if( (xevent.type == Expose)
1043 && (xevent.xexpose.window == p_win->base_window) )
1045 b_expose = VLC_TRUE;
1046 /* ConfigureNotify isn't sent if there isn't a window manager.
1047 * Expose should be the last event to be received so it should
1048 * be fine to assume we won't receive it anymore. */
1049 b_configure_notify = VLC_TRUE;
1051 else if( (xevent.type == MapNotify)
1052 && (xevent.xmap.window == p_win->base_window) )
1054 b_map_notify = VLC_TRUE;
1056 else if( (xevent.type == ConfigureNotify)
1057 && (xevent.xconfigure.window == p_win->base_window) )
1059 b_configure_notify = VLC_TRUE;
1060 p_win->i_width = xevent.xconfigure.width;
1061 p_win->i_height = xevent.xconfigure.height;
1063 } while( !( b_expose && b_configure_notify && b_map_notify ) );
1065 XSelectInput( p_vout->p_sys->p_display, p_win->base_window,
1066 StructureNotifyMask | KeyPressMask |
1067 ButtonPressMask | ButtonReleaseMask |
1068 PointerMotionMask );
1070 #ifdef MODULE_NAME_IS_x11
1071 if( XDefaultDepth(p_vout->p_sys->p_display, p_vout->p_sys->i_screen) == 8 )
1073 /* Allocate a new palette */
1074 p_vout->p_sys->colormap =
1075 XCreateColormap( p_vout->p_sys->p_display,
1076 DefaultRootWindow( p_vout->p_sys->p_display ),
1077 DefaultVisual( p_vout->p_sys->p_display,
1078 p_vout->p_sys->i_screen ),
1081 xwindow_attributes.colormap = p_vout->p_sys->colormap;
1082 XChangeWindowAttributes( p_vout->p_sys->p_display, p_win->base_window,
1083 CWColormap, &xwindow_attributes );
1087 /* Create video output sub-window. */
1088 p_win->video_window = XCreateSimpleWindow(
1089 p_vout->p_sys->p_display,
1090 p_win->base_window, 0, 0,
1091 p_win->i_width, p_win->i_height,
1093 BlackPixel( p_vout->p_sys->p_display,
1094 p_vout->p_sys->i_screen ),
1095 WhitePixel( p_vout->p_sys->p_display,
1096 p_vout->p_sys->i_screen ) );
1098 XSetWindowBackground( p_vout->p_sys->p_display, p_win->video_window,
1099 BlackPixel( p_vout->p_sys->p_display,
1100 p_vout->p_sys->i_screen ) );
1102 XMapWindow( p_vout->p_sys->p_display, p_win->video_window );
1103 XSelectInput( p_vout->p_sys->p_display, p_win->video_window,
1106 /* make sure the video window will be centered in the next ManageVideo() */
1107 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1109 /* If the cursor was formerly blank than blank it again */
1110 if( !p_vout->p_sys->b_mouse_pointer_visible )
1112 ToggleCursor( p_vout );
1113 ToggleCursor( p_vout );
1116 /* Do NOT use XFlush here ! */
1117 XSync( p_vout->p_sys->p_display, False );
1119 /* At this stage, the window is open, displayed, and ready to
1121 p_vout->p_sys->p_win = p_win;
1126 /*****************************************************************************
1127 * DestroyWindow: destroy the window
1128 *****************************************************************************
1130 *****************************************************************************/
1131 static void DestroyWindow( vout_thread_t *p_vout, x11_window_t *p_win )
1133 /* Do NOT use XFlush here ! */
1134 XSync( p_vout->p_sys->p_display, False );
1136 if( p_win->video_window != None )
1137 XDestroyWindow( p_vout->p_sys->p_display, p_win->video_window );
1139 XFreeGC( p_vout->p_sys->p_display, p_win->gc );
1141 XUnmapWindow( p_vout->p_sys->p_display, p_win->base_window );
1142 XDestroyWindow( p_vout->p_sys->p_display, p_win->base_window );
1144 if( p_win->owner_window )
1145 vout_ReleaseWindow( p_vout, (void *)p_win->owner_window );
1148 /*****************************************************************************
1149 * NewPicture: allocate a picture
1150 *****************************************************************************
1151 * Returns 0 on success, -1 otherwise
1152 *****************************************************************************/
1153 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
1155 #ifndef MODULE_NAME_IS_glx
1157 #ifdef MODULE_NAME_IS_xvideo
1161 /* We know the chroma, allocate a buffer which will be used
1162 * directly by the decoder */
1163 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
1165 if( p_pic->p_sys == NULL )
1170 /* Fill in picture_t fields */
1171 vout_InitPicture( VLC_OBJECT(p_vout), p_pic, p_vout->output.i_chroma,
1172 p_vout->output.i_width, p_vout->output.i_height,
1173 p_vout->output.i_aspect );
1175 #ifdef HAVE_SYS_SHM_H
1176 if( p_vout->p_sys->b_shm )
1178 /* Create image using XShm extension */
1179 p_pic->p_sys->p_image =
1180 CreateShmImage( p_vout, p_vout->p_sys->p_display,
1181 # ifdef MODULE_NAME_IS_xvideo
1182 p_vout->p_sys->i_xvport,
1183 VLC2X11_FOURCC(p_vout->output.i_chroma),
1185 p_vout->p_sys->p_visual,
1186 p_vout->p_sys->i_screen_depth,
1188 &p_pic->p_sys->shminfo,
1189 p_vout->output.i_width, p_vout->output.i_height );
1192 #endif /* HAVE_SYS_SHM_H */
1194 /* Create image without XShm extension */
1195 p_pic->p_sys->p_image =
1196 CreateImage( p_vout, p_vout->p_sys->p_display,
1197 #ifdef MODULE_NAME_IS_xvideo
1198 p_vout->p_sys->i_xvport,
1199 VLC2X11_FOURCC(p_vout->output.i_chroma),
1200 p_pic->format.i_bits_per_pixel,
1202 p_vout->p_sys->p_visual,
1203 p_vout->p_sys->i_screen_depth,
1204 p_vout->p_sys->i_bytes_per_pixel,
1206 p_vout->output.i_width, p_vout->output.i_height );
1209 if( p_pic->p_sys->p_image == NULL )
1211 free( p_pic->p_sys );
1215 switch( p_vout->output.i_chroma )
1217 #ifdef MODULE_NAME_IS_xvideo
1218 case VLC_FOURCC('I','4','2','0'):
1219 case VLC_FOURCC('Y','V','1','2'):
1220 case VLC_FOURCC('Y','2','1','1'):
1221 case VLC_FOURCC('Y','U','Y','2'):
1222 case VLC_FOURCC('U','Y','V','Y'):
1223 case VLC_FOURCC('R','V','1','5'):
1224 case VLC_FOURCC('R','V','1','6'):
1225 case VLC_FOURCC('R','V','2','4'): /* Fixme: pixel pitch == 4 ? */
1226 case VLC_FOURCC('R','V','3','2'):
1228 for( i_plane = 0; i_plane < p_pic->p_sys->p_image->num_planes;
1231 p_pic->p[i_plane].p_pixels = p_pic->p_sys->p_image->data
1232 + p_pic->p_sys->p_image->offsets[i_plane];
1233 p_pic->p[i_plane].i_pitch =
1234 p_pic->p_sys->p_image->pitches[i_plane];
1236 if( p_vout->output.i_chroma == VLC_FOURCC('Y','V','1','2') )
1238 /* U and V inverted compared to I420
1239 * Fixme: this should be handled by the vout core */
1240 p_pic->U_PIXELS = p_pic->p_sys->p_image->data
1241 + p_pic->p_sys->p_image->offsets[2];
1242 p_pic->V_PIXELS = p_pic->p_sys->p_image->data
1243 + p_pic->p_sys->p_image->offsets[1];
1248 case VLC_FOURCC('R','G','B','2'):
1249 case VLC_FOURCC('R','V','1','6'):
1250 case VLC_FOURCC('R','V','1','5'):
1251 case VLC_FOURCC('R','V','2','4'):
1252 case VLC_FOURCC('R','V','3','2'):
1254 p_pic->p->i_lines = p_pic->p_sys->p_image->height;
1255 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1256 + p_pic->p_sys->p_image->xoffset;
1257 p_pic->p->i_pitch = p_pic->p_sys->p_image->bytes_per_line;
1259 /* p_pic->p->i_pixel_pitch = 4 for RV24 but this should be set
1260 * properly by vout_InitPicture() */
1261 p_pic->p->i_visible_pitch = p_pic->p->i_pixel_pitch
1262 * p_pic->p_sys->p_image->width;
1267 /* Unknown chroma, tell the guy to get lost */
1268 IMAGE_FREE( p_pic->p_sys->p_image );
1269 free( p_pic->p_sys );
1270 msg_Err( p_vout, "never heard of chroma 0x%.8x (%4.4s)",
1271 p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma );
1272 p_pic->i_planes = 0;
1276 #endif /* !MODULE_NAME_IS_glx */
1281 /*****************************************************************************
1282 * FreePicture: destroy a picture allocated with NewPicture
1283 *****************************************************************************
1284 * Destroy XImage AND associated data. If using Shm, detach shared memory
1285 * segment from server and process, then free it. The XDestroyImage manpage
1286 * says that both the image structure _and_ the data pointed to by the
1287 * image structure are freed, so no need to free p_image->data.
1288 *****************************************************************************/
1289 static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
1291 /* The order of operations is correct */
1292 #ifdef HAVE_SYS_SHM_H
1293 if( p_vout->p_sys->b_shm )
1295 XShmDetach( p_vout->p_sys->p_display, &p_pic->p_sys->shminfo );
1296 IMAGE_FREE( p_pic->p_sys->p_image );
1298 shmctl( p_pic->p_sys->shminfo.shmid, IPC_RMID, 0 );
1299 if( shmdt( p_pic->p_sys->shminfo.shmaddr ) )
1301 msg_Err( p_vout, "cannot detach shared memory (%s)",
1308 IMAGE_FREE( p_pic->p_sys->p_image );
1311 /* Do NOT use XFlush here ! */
1312 XSync( p_vout->p_sys->p_display, False );
1314 free( p_pic->p_sys );
1317 /*****************************************************************************
1318 * ToggleFullScreen: Enable or disable full screen mode
1319 *****************************************************************************
1320 * This function will switch between fullscreen and window mode.
1321 *****************************************************************************/
1322 static void ToggleFullScreen ( vout_thread_t *p_vout )
1326 mwmhints_t mwmhints;
1327 XSetWindowAttributes attributes;
1329 #ifdef HAVE_XINERAMA
1333 p_vout->b_fullscreen = !p_vout->b_fullscreen;
1335 if( p_vout->b_fullscreen )
1337 msg_Dbg( p_vout, "entering fullscreen mode" );
1339 p_vout->p_sys->b_altfullscreen =
1340 config_GetInt( p_vout, MODULE_STRING "-altfullscreen" );
1342 XUnmapWindow( p_vout->p_sys->p_display,
1343 p_vout->p_sys->p_win->base_window );
1345 p_vout->p_sys->p_win = &p_vout->p_sys->fullscreen_window;
1347 CreateWindow( p_vout, p_vout->p_sys->p_win );
1348 XDestroyWindow( p_vout->p_sys->p_display,
1349 p_vout->p_sys->fullscreen_window.video_window );
1350 XReparentWindow( p_vout->p_sys->p_display,
1351 p_vout->p_sys->original_window.video_window,
1352 p_vout->p_sys->fullscreen_window.base_window, 0, 0 );
1353 p_vout->p_sys->fullscreen_window.video_window =
1354 p_vout->p_sys->original_window.video_window;
1356 /* To my knowledge there are two ways to create a borderless window.
1357 * There's the generic way which is to tell x to bypass the window
1358 * manager, but this creates problems with the focus of other
1360 * The other way is to use the motif property "_MOTIF_WM_HINTS" which
1361 * luckily seems to be supported by most window managers. */
1362 if( !p_vout->p_sys->b_altfullscreen )
1364 mwmhints.flags = MWM_HINTS_DECORATIONS;
1365 mwmhints.decorations = False;
1367 prop = XInternAtom( p_vout->p_sys->p_display, "_MOTIF_WM_HINTS",
1369 XChangeProperty( p_vout->p_sys->p_display,
1370 p_vout->p_sys->p_win->base_window,
1371 prop, prop, 32, PropModeReplace,
1372 (unsigned char *)&mwmhints,
1373 PROP_MWM_HINTS_ELEMENTS );
1377 /* brute force way to remove decorations */
1378 attributes.override_redirect = True;
1379 XChangeWindowAttributes( p_vout->p_sys->p_display,
1380 p_vout->p_sys->p_win->base_window,
1384 /* Make sure the change is effective */
1385 XReparentWindow( p_vout->p_sys->p_display,
1386 p_vout->p_sys->p_win->base_window,
1387 DefaultRootWindow( p_vout->p_sys->p_display ),
1391 if( p_vout->p_sys->b_net_wm_state_fullscreen )
1393 XClientMessageEvent event;
1395 memset( &event, 0, sizeof( XClientMessageEvent ) );
1397 event.type = ClientMessage;
1398 event.message_type = p_vout->p_sys->net_wm_state;
1399 event.display = p_vout->p_sys->p_display;
1400 event.window = p_vout->p_sys->p_win->base_window;
1402 event.data.l[ 0 ] = 1; /* set property */
1403 event.data.l[ 1 ] = p_vout->p_sys->net_wm_state_fullscreen;
1405 XSendEvent( p_vout->p_sys->p_display,
1406 DefaultRootWindow( p_vout->p_sys->p_display ),
1407 False, SubstructureRedirectMask,
1411 /* Make sure the change is effective */
1412 XReparentWindow( p_vout->p_sys->p_display,
1413 p_vout->p_sys->p_win->base_window,
1414 DefaultRootWindow( p_vout->p_sys->p_display ),
1417 #ifdef HAVE_XINERAMA
1418 if( XineramaQueryExtension( p_vout->p_sys->p_display, &i_d1, &i_d2 ) &&
1419 XineramaIsActive( p_vout->p_sys->p_display ) )
1421 XineramaScreenInfo *screens; /* infos for xinerama */
1424 msg_Dbg( p_vout, "using XFree Xinerama extension");
1426 #define SCREEN p_vout->p_sys->p_win->i_screen
1428 /* Get Information about Xinerama (num of screens) */
1429 screens = XineramaQueryScreens( p_vout->p_sys->p_display,
1433 SCREEN = config_GetInt( p_vout,
1434 MODULE_STRING "-xineramascreen" );
1436 /* just check that user has entered a good value */
1437 if( SCREEN >= i_num_screens || SCREEN < 0 )
1439 msg_Dbg( p_vout, "requested screen number invalid" );
1443 /* Get the X/Y upper left corner coordinate of the above screen */
1444 p_vout->p_sys->p_win->i_x = screens[SCREEN].x_org;
1445 p_vout->p_sys->p_win->i_y = screens[SCREEN].y_org;
1447 /* Set the Height/width to the screen resolution */
1448 p_vout->p_sys->p_win->i_width = screens[SCREEN].width;
1449 p_vout->p_sys->p_win->i_height = screens[SCREEN].height;
1459 /* The window wasn't necessarily created at the requested size */
1460 p_vout->p_sys->p_win->i_x = p_vout->p_sys->p_win->i_y = 0;
1461 p_vout->p_sys->p_win->i_width =
1462 DisplayWidth( p_vout->p_sys->p_display,
1463 p_vout->p_sys->i_screen );
1464 p_vout->p_sys->p_win->i_height =
1465 DisplayHeight( p_vout->p_sys->p_display,
1466 p_vout->p_sys->i_screen );
1469 XMoveResizeWindow( p_vout->p_sys->p_display,
1470 p_vout->p_sys->p_win->base_window,
1471 p_vout->p_sys->p_win->i_x,
1472 p_vout->p_sys->p_win->i_y,
1473 p_vout->p_sys->p_win->i_width,
1474 p_vout->p_sys->p_win->i_height );
1478 msg_Dbg( p_vout, "leaving fullscreen mode" );
1480 XReparentWindow( p_vout->p_sys->p_display,
1481 p_vout->p_sys->original_window.video_window,
1482 p_vout->p_sys->original_window.base_window, 0, 0 );
1484 p_vout->p_sys->fullscreen_window.video_window = None;
1485 DestroyWindow( p_vout, &p_vout->p_sys->fullscreen_window );
1486 p_vout->p_sys->p_win = &p_vout->p_sys->original_window;
1488 XMapWindow( p_vout->p_sys->p_display,
1489 p_vout->p_sys->p_win->base_window );
1492 /* Unfortunately, using XSync() here is not enough to ensure the
1493 * window has already been mapped because the XMapWindow() request
1494 * has not necessarily been sent directly to our window (remember,
1495 * the call is first redirected to the window manager) */
1498 XWindowEvent( p_vout->p_sys->p_display,
1499 p_vout->p_sys->p_win->base_window,
1500 StructureNotifyMask, &xevent );
1501 } while( xevent.type != MapNotify );
1503 /* Be careful, this can generate a BadMatch error if the window is not
1504 * already mapped by the server (see above) */
1505 XSetInputFocus(p_vout->p_sys->p_display,
1506 p_vout->p_sys->p_win->base_window,
1510 /* signal that the size needs to be updated */
1511 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1514 /*****************************************************************************
1515 * EnableXScreenSaver: enable screen saver
1516 *****************************************************************************
1517 * This function enables the screen saver on a display after it has been
1518 * disabled by XDisableScreenSaver.
1519 * FIXME: what happens if multiple vlc sessions are running at the same
1521 *****************************************************************************/
1522 static void EnableXScreenSaver( vout_thread_t *p_vout )
1524 #ifdef DPMSINFO_IN_DPMS_H
1528 if( p_vout->p_sys->i_ss_timeout )
1530 XSetScreenSaver( p_vout->p_sys->p_display, p_vout->p_sys->i_ss_timeout,
1531 p_vout->p_sys->i_ss_interval,
1532 p_vout->p_sys->i_ss_blanking,
1533 p_vout->p_sys->i_ss_exposure );
1536 /* Restore DPMS settings */
1537 #ifdef DPMSINFO_IN_DPMS_H
1538 if( DPMSQueryExtension( p_vout->p_sys->p_display, &dummy, &dummy ) )
1540 if( p_vout->p_sys->b_ss_dpms )
1542 DPMSEnable( p_vout->p_sys->p_display );
1548 /*****************************************************************************
1549 * DisableXScreenSaver: disable screen saver
1550 *****************************************************************************
1551 * See XEnableXScreenSaver
1552 *****************************************************************************/
1553 static void DisableXScreenSaver( vout_thread_t *p_vout )
1555 #ifdef DPMSINFO_IN_DPMS_H
1559 /* Save screen saver information */
1560 XGetScreenSaver( p_vout->p_sys->p_display, &p_vout->p_sys->i_ss_timeout,
1561 &p_vout->p_sys->i_ss_interval,
1562 &p_vout->p_sys->i_ss_blanking,
1563 &p_vout->p_sys->i_ss_exposure );
1565 /* Disable screen saver */
1566 if( p_vout->p_sys->i_ss_timeout )
1568 XSetScreenSaver( p_vout->p_sys->p_display, 0,
1569 p_vout->p_sys->i_ss_interval,
1570 p_vout->p_sys->i_ss_blanking,
1571 p_vout->p_sys->i_ss_exposure );
1575 #ifdef DPMSINFO_IN_DPMS_H
1576 if( DPMSQueryExtension( p_vout->p_sys->p_display, &dummy, &dummy ) )
1579 /* Save DPMS current state */
1580 DPMSInfo( p_vout->p_sys->p_display, &unused,
1581 &p_vout->p_sys->b_ss_dpms );
1582 DPMSDisable( p_vout->p_sys->p_display );
1587 /*****************************************************************************
1588 * CreateCursor: create a blank mouse pointer
1589 *****************************************************************************/
1590 static void CreateCursor( vout_thread_t *p_vout )
1592 XColor cursor_color;
1594 p_vout->p_sys->cursor_pixmap =
1595 XCreatePixmap( p_vout->p_sys->p_display,
1596 DefaultRootWindow( p_vout->p_sys->p_display ),
1599 XParseColor( p_vout->p_sys->p_display,
1600 XCreateColormap( p_vout->p_sys->p_display,
1602 p_vout->p_sys->p_display ),
1604 p_vout->p_sys->p_display,
1605 p_vout->p_sys->i_screen ),
1607 "black", &cursor_color );
1609 p_vout->p_sys->blank_cursor =
1610 XCreatePixmapCursor( p_vout->p_sys->p_display,
1611 p_vout->p_sys->cursor_pixmap,
1612 p_vout->p_sys->cursor_pixmap,
1613 &cursor_color, &cursor_color, 1, 1 );
1616 /*****************************************************************************
1617 * DestroyCursor: destroy the blank mouse pointer
1618 *****************************************************************************/
1619 static void DestroyCursor( vout_thread_t *p_vout )
1621 XFreePixmap( p_vout->p_sys->p_display, p_vout->p_sys->cursor_pixmap );
1624 /*****************************************************************************
1625 * ToggleCursor: hide or show the mouse pointer
1626 *****************************************************************************
1627 * This function hides the X pointer if it is visible by setting the pointer
1628 * sprite to a blank one. To show it again, we disable the sprite.
1629 *****************************************************************************/
1630 static void ToggleCursor( vout_thread_t *p_vout )
1632 if( p_vout->p_sys->b_mouse_pointer_visible )
1634 XDefineCursor( p_vout->p_sys->p_display,
1635 p_vout->p_sys->p_win->base_window,
1636 p_vout->p_sys->blank_cursor );
1637 p_vout->p_sys->b_mouse_pointer_visible = 0;
1641 XUndefineCursor( p_vout->p_sys->p_display,
1642 p_vout->p_sys->p_win->base_window );
1643 p_vout->p_sys->b_mouse_pointer_visible = 1;
1647 #ifdef MODULE_NAME_IS_xvideo
1648 /*****************************************************************************
1649 * XVideoGetPort: get YUV12 port
1650 *****************************************************************************/
1651 static int XVideoGetPort( vout_thread_t *p_vout,
1652 vlc_fourcc_t i_chroma, vlc_fourcc_t *pi_newchroma )
1654 XvAdaptorInfo *p_adaptor;
1656 int i_adaptor, i_num_adaptors, i_requested_adaptor;
1657 int i_selected_port;
1659 switch( XvQueryExtension( p_vout->p_sys->p_display, &i, &i, &i, &i, &i ) )
1664 case XvBadExtension:
1665 msg_Warn( p_vout, "XvBadExtension" );
1669 msg_Warn( p_vout, "XvBadAlloc" );
1673 msg_Warn( p_vout, "XvQueryExtension failed" );
1677 switch( XvQueryAdaptors( p_vout->p_sys->p_display,
1678 DefaultRootWindow( p_vout->p_sys->p_display ),
1679 &i_num_adaptors, &p_adaptor ) )
1684 case XvBadExtension:
1685 msg_Warn( p_vout, "XvBadExtension for XvQueryAdaptors" );
1689 msg_Warn( p_vout, "XvBadAlloc for XvQueryAdaptors" );
1693 msg_Warn( p_vout, "XvQueryAdaptors failed" );
1697 i_selected_port = -1;
1698 i_requested_adaptor = config_GetInt( p_vout, "xvideo-adaptor" );
1700 for( i_adaptor = 0; i_adaptor < i_num_adaptors; ++i_adaptor )
1702 XvImageFormatValues *p_formats;
1703 int i_format, i_num_formats;
1706 /* If we requested an adaptor and it's not this one, we aren't
1708 if( i_requested_adaptor != -1 && i_adaptor != i_requested_adaptor )
1713 /* If the adaptor doesn't have the required properties, skip it */
1714 if( !( p_adaptor[ i_adaptor ].type & XvInputMask ) ||
1715 !( p_adaptor[ i_adaptor ].type & XvImageMask ) )
1720 /* Check that adaptor supports our requested format... */
1721 p_formats = XvListImageFormats( p_vout->p_sys->p_display,
1722 p_adaptor[i_adaptor].base_id,
1726 i_format < i_num_formats && ( i_selected_port == -1 );
1729 XvAttribute *p_attr;
1730 int i_attr, i_num_attributes;
1732 /* If this is not the format we want, or at least a
1733 * similar one, forget it */
1734 if( !vout_ChromaCmp( p_formats[ i_format ].id, i_chroma ) )
1739 /* Look for the first available port supporting this format */
1740 for( i_port = p_adaptor[i_adaptor].base_id;
1741 ( i_port < (int)(p_adaptor[i_adaptor].base_id
1742 + p_adaptor[i_adaptor].num_ports) )
1743 && ( i_selected_port == -1 );
1746 if( XvGrabPort( p_vout->p_sys->p_display, i_port, CurrentTime )
1749 i_selected_port = i_port;
1750 *pi_newchroma = p_formats[ i_format ].id;
1754 /* If no free port was found, forget it */
1755 if( i_selected_port == -1 )
1760 /* If we found a port, print information about it */
1761 msg_Dbg( p_vout, "adaptor %i, port %i, format 0x%x (%4.4s) %s",
1762 i_adaptor, i_selected_port, p_formats[ i_format ].id,
1763 (char *)&p_formats[ i_format ].id,
1764 ( p_formats[ i_format ].format == XvPacked ) ?
1765 "packed" : "planar" );
1767 /* Make sure XV_AUTOPAINT_COLORKEY is set */
1768 p_attr = XvQueryPortAttributes( p_vout->p_sys->p_display,
1770 &i_num_attributes );
1772 for( i_attr = 0; i_attr < i_num_attributes; i_attr++ )
1774 if( !strcmp( p_attr[i_attr].name, "XV_AUTOPAINT_COLORKEY" ) )
1776 const Atom autopaint =
1777 XInternAtom( p_vout->p_sys->p_display,
1778 "XV_AUTOPAINT_COLORKEY", False );
1779 XvSetPortAttribute( p_vout->p_sys->p_display,
1780 i_selected_port, autopaint, 1 );
1785 if( p_attr != NULL )
1791 if( p_formats != NULL )
1798 if( i_num_adaptors > 0 )
1800 XvFreeAdaptorInfo( p_adaptor );
1803 if( i_selected_port == -1 )
1805 int i_chroma_tmp = X112VLC_FOURCC( i_chroma );
1806 if( i_requested_adaptor == -1 )
1808 msg_Warn( p_vout, "no free XVideo port found for format "
1809 "0x%.8x (%4.4s)", i_chroma_tmp, (char*)&i_chroma_tmp );
1813 msg_Warn( p_vout, "XVideo adaptor %i does not have a free "
1814 "XVideo port for format 0x%.8x (%4.4s)",
1815 i_requested_adaptor, i_chroma_tmp, (char*)&i_chroma_tmp );
1819 return i_selected_port;
1822 /*****************************************************************************
1823 * XVideoReleasePort: release YUV12 port
1824 *****************************************************************************/
1825 static void XVideoReleasePort( vout_thread_t *p_vout, int i_port )
1827 XvUngrabPort( p_vout->p_sys->p_display, i_port, CurrentTime );
1831 /*****************************************************************************
1832 * InitDisplay: open and initialize X11 device
1833 *****************************************************************************
1834 * Create a window according to video output given size, and set other
1835 * properties according to the display properties.
1836 *****************************************************************************/
1837 static int InitDisplay( vout_thread_t *p_vout )
1839 #ifdef MODULE_NAME_IS_x11
1840 XPixmapFormatValues * p_formats; /* pixmap formats */
1841 XVisualInfo * p_xvisual; /* visuals information */
1842 XVisualInfo xvisual_template; /* visual template */
1843 int i_count; /* array size */
1846 #ifdef HAVE_SYS_SHM_H
1847 p_vout->p_sys->b_shm = 0;
1849 if( config_GetInt( p_vout, MODULE_STRING "-shm" ) )
1852 /* FIXME: As of 2001-03-16, XFree4 for MacOS X does not support Xshm */
1854 p_vout->p_sys->b_shm =
1855 ( XShmQueryExtension( p_vout->p_sys->p_display ) == True );
1858 if( !p_vout->p_sys->b_shm )
1860 msg_Warn( p_vout, "XShm video extension is unavailable" );
1865 msg_Dbg( p_vout, "disabling XShm video extension" );
1869 msg_Warn( p_vout, "XShm video extension is unavailable" );
1873 #ifdef MODULE_NAME_IS_xvideo
1874 /* XXX The brightness and contrast values should be read from environment
1875 * XXX variables... */
1877 XVideoSetAttribute( p_vout, "XV_BRIGHTNESS", 0.5 );
1878 XVideoSetAttribute( p_vout, "XV_CONTRAST", 0.5 );
1882 #ifdef MODULE_NAME_IS_x11
1883 /* Initialize structure */
1884 p_vout->p_sys->i_screen = DefaultScreen( p_vout->p_sys->p_display );
1886 /* Get screen depth */
1887 p_vout->p_sys->i_screen_depth = XDefaultDepth( p_vout->p_sys->p_display,
1888 p_vout->p_sys->i_screen );
1889 switch( p_vout->p_sys->i_screen_depth )
1893 * Screen depth is 8bpp. Use PseudoColor visual with private colormap.
1895 xvisual_template.screen = p_vout->p_sys->i_screen;
1896 xvisual_template.class = DirectColor;
1897 p_xvisual = XGetVisualInfo( p_vout->p_sys->p_display,
1898 VisualScreenMask | VisualClassMask,
1899 &xvisual_template, &i_count );
1900 if( p_xvisual == NULL )
1902 msg_Err( p_vout, "no PseudoColor visual available" );
1903 return VLC_EGENERIC;
1905 p_vout->p_sys->i_bytes_per_pixel = 1;
1906 p_vout->output.pf_setpalette = SetPalette;
1913 * Screen depth is higher than 8bpp. TrueColor visual is used.
1915 xvisual_template.screen = p_vout->p_sys->i_screen;
1916 xvisual_template.class = TrueColor;
1917 p_xvisual = XGetVisualInfo( p_vout->p_sys->p_display,
1918 VisualScreenMask | VisualClassMask,
1919 &xvisual_template, &i_count );
1920 if( p_xvisual == NULL )
1922 msg_Err( p_vout, "no TrueColor visual available" );
1923 return VLC_EGENERIC;
1926 p_vout->output.i_rmask = p_xvisual->red_mask;
1927 p_vout->output.i_gmask = p_xvisual->green_mask;
1928 p_vout->output.i_bmask = p_xvisual->blue_mask;
1930 /* There is no difference yet between 3 and 4 Bpp. The only way
1931 * to find the actual number of bytes per pixel is to list supported
1932 * pixmap formats. */
1933 p_formats = XListPixmapFormats( p_vout->p_sys->p_display, &i_count );
1934 p_vout->p_sys->i_bytes_per_pixel = 0;
1936 for( ; i_count-- ; p_formats++ )
1938 /* Under XFree4.0, the list contains pixmap formats available
1939 * through all video depths ; so we have to check against current
1941 if( p_formats->depth == (int)p_vout->p_sys->i_screen_depth )
1943 if( p_formats->bits_per_pixel / 8
1944 > (int)p_vout->p_sys->i_bytes_per_pixel )
1946 p_vout->p_sys->i_bytes_per_pixel =
1947 p_formats->bits_per_pixel / 8;
1953 p_vout->p_sys->p_visual = p_xvisual->visual;
1960 #ifdef HAVE_SYS_SHM_H
1961 /*****************************************************************************
1962 * CreateShmImage: create an XImage or XvImage using shared memory extension
1963 *****************************************************************************
1964 * Prepare an XImage or XvImage for display function.
1965 * The order of the operations respects the recommandations of the mit-shm
1966 * document by J.Corbet and K.Packard. Most of the parameters were copied from
1967 * there. See http://ftp.xfree86.org/pub/XFree86/4.0/doc/mit-shm.TXT
1968 *****************************************************************************/
1969 static IMAGE_TYPE * CreateShmImage( vout_thread_t *p_vout,
1970 Display* p_display, EXTRA_ARGS_SHM,
1971 int i_width, int i_height )
1973 IMAGE_TYPE *p_image;
1975 /* Create XImage / XvImage */
1976 #ifdef MODULE_NAME_IS_xvideo
1977 p_image = XvShmCreateImage( p_display, i_xvport, i_chroma, 0,
1978 i_width, i_height, p_shm );
1980 p_image = XShmCreateImage( p_display, p_visual, i_depth, ZPixmap, 0,
1981 p_shm, i_width, i_height );
1983 if( p_image == NULL )
1985 msg_Err( p_vout, "image creation failed" );
1989 /* Allocate shared memory segment - 0776 set the access permission
1990 * rights (like umask), they are not yet supported by all X servers */
1991 p_shm->shmid = shmget( IPC_PRIVATE, DATA_SIZE(p_image), IPC_CREAT | 0776 );
1992 if( p_shm->shmid < 0 )
1994 msg_Err( p_vout, "cannot allocate shared image data (%s)",
1995 strerror( errno ) );
1996 IMAGE_FREE( p_image );
2000 /* Attach shared memory segment to process (read/write) */
2001 p_shm->shmaddr = p_image->data = shmat( p_shm->shmid, 0, 0 );
2002 if(! p_shm->shmaddr )
2004 msg_Err( p_vout, "cannot attach shared memory (%s)",
2006 IMAGE_FREE( p_image );
2007 shmctl( p_shm->shmid, IPC_RMID, 0 );
2011 /* Read-only data. We won't be using XShmGetImage */
2012 p_shm->readOnly = True;
2014 /* Attach shared memory segment to X server */
2015 if( XShmAttach( p_display, p_shm ) == False )
2017 msg_Err( p_vout, "cannot attach shared memory to X server" );
2018 IMAGE_FREE( p_image );
2019 shmctl( p_shm->shmid, IPC_RMID, 0 );
2020 shmdt( p_shm->shmaddr );
2024 /* Send image to X server. This instruction is required, since having
2025 * built a Shm XImage and not using it causes an error on XCloseDisplay,
2026 * and remember NOT to use XFlush ! */
2027 XSync( p_display, False );
2030 /* Mark the shm segment to be removed when there are no more
2031 * attachements, so it is automatic on process exit or after shmdt */
2032 shmctl( p_shm->shmid, IPC_RMID, 0 );
2039 /*****************************************************************************
2040 * CreateImage: create an XImage or XvImage
2041 *****************************************************************************
2042 * Create a simple image used as a buffer.
2043 *****************************************************************************/
2044 static IMAGE_TYPE * CreateImage( vout_thread_t *p_vout,
2045 Display *p_display, EXTRA_ARGS,
2046 int i_width, int i_height )
2048 byte_t * p_data; /* image data storage zone */
2049 IMAGE_TYPE *p_image;
2050 #ifdef MODULE_NAME_IS_x11
2051 int i_quantum; /* XImage quantum (see below) */
2052 int i_bytes_per_line;
2055 /* Allocate memory for image */
2056 #ifdef MODULE_NAME_IS_xvideo
2057 p_data = (byte_t *) malloc( i_width * i_height * i_bits_per_pixel / 8 );
2058 #elif defined(MODULE_NAME_IS_x11)
2059 i_bytes_per_line = i_width * i_bytes_per_pixel;
2060 p_data = (byte_t *) malloc( i_bytes_per_line * i_height );
2064 msg_Err( p_vout, "out of memory" );
2068 #ifdef MODULE_NAME_IS_x11
2069 /* Optimize the quantum of a scanline regarding its size - the quantum is
2070 a diviser of the number of bits between the start of two scanlines. */
2071 if( i_bytes_per_line & 0xf )
2075 else if( i_bytes_per_line & 0x10 )
2085 /* Create XImage. p_data will be automatically freed */
2086 #ifdef MODULE_NAME_IS_xvideo
2087 p_image = XvCreateImage( p_display, i_xvport, i_chroma,
2088 p_data, i_width, i_height );
2089 #elif defined(MODULE_NAME_IS_x11)
2090 p_image = XCreateImage( p_display, p_visual, i_depth, ZPixmap, 0,
2091 p_data, i_width, i_height, i_quantum, 0 );
2093 if( p_image == NULL )
2095 msg_Err( p_vout, "XCreateImage() failed" );
2103 #ifdef MODULE_NAME_IS_x11
2104 /*****************************************************************************
2105 * SetPalette: sets an 8 bpp palette
2106 *****************************************************************************
2107 * This function sets the palette given as an argument. It does not return
2108 * anything, but could later send information on which colors it was unable
2110 *****************************************************************************/
2111 static void SetPalette( vout_thread_t *p_vout,
2112 uint16_t *red, uint16_t *green, uint16_t *blue )
2115 XColor p_colors[255];
2117 /* allocate palette */
2118 for( i = 0; i < 255; i++ )
2120 /* kludge: colors are indexed reversely because color 255 seems
2121 * to be reserved for black even if we try to set it to white */
2122 p_colors[ i ].pixel = 255 - i;
2123 p_colors[ i ].pad = 0;
2124 p_colors[ i ].flags = DoRed | DoGreen | DoBlue;
2125 p_colors[ i ].red = red[ 255 - i ];
2126 p_colors[ i ].blue = blue[ 255 - i ];
2127 p_colors[ i ].green = green[ 255 - i ];
2130 XStoreColors( p_vout->p_sys->p_display,
2131 p_vout->p_sys->colormap, p_colors, 255 );
2135 /*****************************************************************************
2136 * Control: control facility for the vout
2137 *****************************************************************************/
2138 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
2146 if( p_vout->p_sys->p_win->owner_window )
2147 return vout_ControlWindow( p_vout,
2148 (void *)p_vout->p_sys->p_win->owner_window, i_query, args);
2150 f_arg = va_arg( args, double );
2152 vlc_mutex_lock( &p_vout->p_sys->lock );
2154 /* Update dimensions */
2155 /* FIXME: export InitWindowSize() from vout core */
2156 XResizeWindow( p_vout->p_sys->p_display,
2157 p_vout->p_sys->p_win->base_window,
2158 p_vout->i_window_width * f_arg,
2159 p_vout->i_window_height * f_arg );
2161 vlc_mutex_unlock( &p_vout->p_sys->lock );
2165 vlc_mutex_lock( &p_vout->p_sys->lock );
2166 XUnmapWindow( p_vout->p_sys->p_display,
2167 p_vout->p_sys->original_window.base_window );
2168 vlc_mutex_unlock( &p_vout->p_sys->lock );
2172 vlc_mutex_lock( &p_vout->p_sys->lock );
2173 XReparentWindow( p_vout->p_sys->p_display,
2174 p_vout->p_sys->original_window.base_window,
2175 DefaultRootWindow( p_vout->p_sys->p_display ),
2177 XSync( p_vout->p_sys->p_display, False );
2178 p_vout->p_sys->original_window.owner_window = 0;
2179 vlc_mutex_unlock( &p_vout->p_sys->lock );
2180 return vout_vaControlDefault( p_vout, i_query, args );
2182 case VOUT_SET_STAY_ON_TOP:
2183 if( p_vout->p_sys->p_win->owner_window )
2184 return vout_ControlWindow( p_vout,
2185 (void *)p_vout->p_sys->p_win->owner_window, i_query, args);
2187 b_arg = va_arg( args, vlc_bool_t );
2188 vlc_mutex_lock( &p_vout->p_sys->lock );
2189 WindowOnTop( p_vout, b_arg );
2190 vlc_mutex_unlock( &p_vout->p_sys->lock );
2194 return vout_vaControlDefault( p_vout, i_query, args );
2198 /*****************************************************************************
2199 * TestNetWMSupport: tests for Extended Window Manager Hints support
2200 *****************************************************************************/
2201 static void TestNetWMSupport( vout_thread_t *p_vout )
2203 int i_ret, i_format;
2204 unsigned long i, i_items, i_bytesafter;
2205 Atom net_wm_supported;
2206 union { Atom *p_atom; unsigned char *p_char; } p_args;
2208 p_args.p_atom = NULL;
2210 p_vout->p_sys->b_net_wm_state_fullscreen = VLC_FALSE;
2211 p_vout->p_sys->b_net_wm_state_above = VLC_FALSE;
2212 p_vout->p_sys->b_net_wm_state_below = VLC_FALSE;
2213 p_vout->p_sys->b_net_wm_state_stays_on_top = VLC_FALSE;
2216 XInternAtom( p_vout->p_sys->p_display, "_NET_SUPPORTED", False );
2218 i_ret = XGetWindowProperty( p_vout->p_sys->p_display,
2219 DefaultRootWindow( p_vout->p_sys->p_display ),
2221 0, 16384, False, AnyPropertyType,
2223 &i_format, &i_items, &i_bytesafter,
2224 (unsigned char **)&p_args );
2226 if( i_ret != Success || i_items == 0 ) return;
2228 msg_Dbg( p_vout, "Window manager supports NetWM" );
2230 p_vout->p_sys->net_wm_state =
2231 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE", False );
2232 p_vout->p_sys->net_wm_state_fullscreen =
2233 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE_FULLSCREEN",
2235 p_vout->p_sys->net_wm_state_above =
2236 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE_ABOVE", False );
2237 p_vout->p_sys->net_wm_state_below =
2238 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE_BELOW", False );
2239 p_vout->p_sys->net_wm_state_stays_on_top =
2240 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE_STAYS_ON_TOP",
2243 for( i = 0; i < i_items; i++ )
2245 if( p_args.p_atom[i] == p_vout->p_sys->net_wm_state_fullscreen )
2248 "Window manager supports _NET_WM_STATE_FULLSCREEN" );
2249 p_vout->p_sys->b_net_wm_state_fullscreen = VLC_TRUE;
2251 else if( p_args.p_atom[i] == p_vout->p_sys->net_wm_state_above )
2253 msg_Dbg( p_vout, "Window manager supports _NET_WM_STATE_ABOVE" );
2254 p_vout->p_sys->b_net_wm_state_above = VLC_TRUE;
2256 else if( p_args.p_atom[i] == p_vout->p_sys->net_wm_state_below )
2258 msg_Dbg( p_vout, "Window manager supports _NET_WM_STATE_BELOW" );
2259 p_vout->p_sys->b_net_wm_state_below = VLC_TRUE;
2261 else if( p_args.p_atom[i] == p_vout->p_sys->net_wm_state_stays_on_top )
2264 "Window manager supports _NET_WM_STATE_STAYS_ON_TOP" );
2265 p_vout->p_sys->b_net_wm_state_stays_on_top = VLC_TRUE;
2269 XFree( p_args.p_atom );
2272 /*****************************************************************************
2273 * Key events handling
2274 *****************************************************************************/
2280 } x11keys_to_vlckeys[] =
2282 { XK_F1, KEY_F1 }, { XK_F2, KEY_F2 }, { XK_F3, KEY_F3 }, { XK_F4, KEY_F4 },
2283 { XK_F5, KEY_F5 }, { XK_F6, KEY_F6 }, { XK_F7, KEY_F7 }, { XK_F8, KEY_F8 },
2284 { XK_F9, KEY_F9 }, { XK_F10, KEY_F10 }, { XK_F11, KEY_F11 },
2285 { XK_F12, KEY_F12 },
2287 { XK_Return, KEY_ENTER },
2288 { XK_KP_Enter, KEY_ENTER },
2289 { XK_space, KEY_SPACE },
2290 { XK_Escape, KEY_ESC },
2292 { XK_Menu, KEY_MENU },
2293 { XK_Left, KEY_LEFT },
2294 { XK_Right, KEY_RIGHT },
2296 { XK_Down, KEY_DOWN },
2298 { XK_Home, KEY_HOME },
2299 { XK_End, KEY_END },
2300 { XK_Page_Up, KEY_PAGEUP },
2301 { XK_Page_Down, KEY_PAGEDOWN },
2305 static int ConvertKey( int i_key )
2309 for( i = 0; x11keys_to_vlckeys[i].i_x11key != 0; i++ )
2311 if( x11keys_to_vlckeys[i].i_x11key == i_key )
2313 return x11keys_to_vlckeys[i].i_vlckey;
2320 /*****************************************************************************
2321 * WindowOnTop: Switches the "always on top" state of the video window.
2322 *****************************************************************************/
2323 static int WindowOnTop( vout_thread_t *p_vout, vlc_bool_t b_on_top )
2325 if( p_vout->p_sys->b_net_wm_state_stays_on_top )
2327 XClientMessageEvent event;
2329 memset( &event, 0, sizeof( XClientMessageEvent ) );
2331 event.type = ClientMessage;
2332 event.message_type = p_vout->p_sys->net_wm_state;
2333 event.display = p_vout->p_sys->p_display;
2334 event.window = p_vout->p_sys->p_win->base_window;
2336 event.data.l[ 0 ] = b_on_top; /* set property */
2337 event.data.l[ 1 ] = p_vout->p_sys->net_wm_state_stays_on_top;
2339 XSendEvent( p_vout->p_sys->p_display,
2340 DefaultRootWindow( p_vout->p_sys->p_display ),
2341 False, SubstructureRedirectMask,