Use --x11-display whenever calling XOpenDisplay (except Qt4 this far)
[vlc.git] / modules / access / screen / x11.c
index c4f9d83..177f382 100644 (file)
@@ -1,10 +1,11 @@
 /*****************************************************************************
  * x11.c: Screen capture module.
  *****************************************************************************
- * Copyright (C) 2004 the VideoLAN team
+ * Copyright (C) 2004-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
+ *          Antoine Cellerier <dionoea at videolan dot org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -40,11 +41,13 @@ int screen_InitCapture( demux_t *p_demux )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
     Display *p_display;
+    char *psz_display = var_CreateGetNonEmptyString( p_demux, "x11-display" );
     XWindowAttributes win_info;
     int i_chroma;
 
     /* Open the display */
-    p_display = XOpenDisplay( NULL );
+    p_display = XOpenDisplay( psz_display );
+    free( psz_display );
     if( !p_display )
     {
         msg_Err( p_demux, "cannot open display" );
@@ -107,7 +110,7 @@ int screen_CloseCapture( demux_t *p_demux )
     XCloseDisplay( p_display );
     if( p_sys->p_blend )
     {
-        module_Unneed( p_sys->p_blend, p_sys->p_blend->p_module );
+        module_unneed( p_sys->p_blend, p_sys->p_blend->p_module );
         vlc_object_detach( p_sys->p_blend );
         vlc_object_release( p_sys->p_blend );
     }
@@ -133,16 +136,7 @@ block_t *screen_Capture( demux_t *p_demux )
             &mask ) )
         {
             if( p_sys->b_follow_mouse )
-            {
-                root_x -= p_sys->i_width/2;
-                if( root_x < 0 ) root_x = 0;
-                p_sys->i_left = __MIN( (unsigned int)root_x,
-                                       p_sys->i_screen_width - p_sys->i_width );
-                root_y -= p_sys->i_height/2;
-                if( root_y < 0 ) root_y = 0;
-                p_sys->i_top = __MIN( (unsigned int)root_y,
-                                      p_sys->i_screen_height - p_sys->i_height );
-            }
+                FollowMouse( p_sys, root_x, root_y );
         }
         else
             msg_Dbg( p_demux, "XQueryPointer() failed" );
@@ -168,56 +162,11 @@ block_t *screen_Capture( demux_t *p_demux )
         return 0;
     }
 
-    if( !p_sys->p_mouse )
-        vlc_memcpy( p_block->p_buffer, image->data, i_size );
-    else
-    {
-        if( !p_sys->dst.i_planes )
-            vout_InitPicture( p_demux, &p_sys->dst,
-                              p_sys->fmt.video.i_chroma,
-                              p_sys->fmt.video.i_width,
-                              p_sys->fmt.video.i_height,
-                              p_sys->fmt.video.i_aspect );
-        if( !p_sys->p_blend )
-        {
-            p_sys->p_blend = vlc_object_create( p_demux, sizeof(filter_t) );
-            if( !p_sys->p_blend )
-                msg_Err( p_demux, "Could not allocate memory for blending module" );
-            else
-            {
-                es_format_Init( &p_sys->p_blend->fmt_in, VIDEO_ES,
-                                VLC_FOURCC('R','G','B','A') );
-                p_sys->p_blend->fmt_in.video = p_sys->p_mouse->format;
-                p_sys->p_blend->fmt_out = p_sys->fmt;
-                p_sys->p_blend->p_module =
-                    module_Need( p_sys->p_blend, "video blending", 0, 0 );
-                if( !p_sys->p_blend->p_module )
-                {
-                    msg_Err( p_demux, "Could not load video blending module" );
-                    vlc_object_detach( p_sys->p_blend );
-                    vlc_object_release( p_sys->p_blend );
-                    p_sys->p_blend = NULL;
-                }
-            }
-        }
-        if( p_sys->p_blend )
-        {
-            vlc_memcpy( p_block->p_buffer, image->data, i_size );
-            p_sys->dst.p->p_pixels = p_block->p_buffer;
-            p_sys->p_blend->pf_video_blend( p_sys->p_blend,
-                                            &p_sys->dst,
-                                            p_sys->p_mouse,
-                                            root_x,
-                                            root_y,
-                                            255 );
-        }
-        else
-        {
-            picture_Release( p_sys->p_mouse );
-            p_sys->p_mouse = NULL;
-            vlc_memcpy( p_block->p_buffer, image->data, i_size );
-        }
-    }
+    vlc_memcpy( p_block->p_buffer, image->data, i_size );
+
+    if( p_sys->p_mouse )
+        RenderCursor( p_demux, root_x, root_y,
+                      p_block->p_buffer );
 
     XDestroyImage( image );