Add --screen-mouse-follow option (x11 only).
[vlc.git] / modules / access / screen / x11.c
index e8ba1df..a8cf374 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * x11.c: Screen capture module.
  *****************************************************************************
- * Copyright (C) 2004 VideoLAN
+ * Copyright (C) 2004 the VideoLAN team
  * $Id$
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <vlc/vlc.h>
-#include <vlc/input.h>
 
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
@@ -69,9 +71,10 @@ int screen_InitCapture( demux_t *p_demux )
     case 16:
         i_chroma = VLC_FOURCC('R','V','1','6'); break;
     case 24:
-        i_chroma = VLC_FOURCC('R','V','2','4'); break;
     case 32:
-        i_chroma = VLC_FOURCC('R','V','3','2'); break;
+        i_chroma = VLC_FOURCC('R','V','3','2');
+        win_info.depth = 32;
+        break;
     default:
         msg_Err( p_demux, "unknown screen depth %i", win_info.depth );
         XCloseDisplay( p_display );
@@ -110,8 +113,28 @@ block_t *screen_Capture( demux_t *p_demux )
     XImage *image;
     int i_size;
 
+    if( p_sys->b_follow_mouse )
+    {
+        Window root = DefaultRootWindow( p_display ), child;
+        int root_x, root_y;
+        int win_x, win_y;
+        unsigned int mask;
+        if( XQueryPointer( p_display, root,
+            &root, &child, &root_x, &root_y, &win_x, &win_y,
+            &mask ) )
+        {
+            p_sys->i_left = __MIN( (unsigned int)root_x,
+                                   p_sys->i_screen_width - p_sys->i_width );
+            p_sys->i_top = __MIN( (unsigned int)root_y,
+                                  p_sys->i_screen_height - p_sys->i_height );
+        }
+        else
+            msg_Dbg( p_demux, "XQueryPointer() failed" );
+
+    }
+
     image = XGetImage( p_display, DefaultRootWindow( p_display ),
-                       0, 0, p_sys->fmt.video.i_width,
+                       p_sys->i_left, p_sys->i_top, p_sys->fmt.video.i_width,
                        p_sys->fmt.video.i_height, AllPlanes, ZPixmap );
 
     if( !image )
@@ -129,7 +152,7 @@ block_t *screen_Capture( demux_t *p_demux )
         return 0;
     }
 
-    memcpy( p_block->p_buffer, image->data, i_size );
+    vlc_memcpy( p_block->p_buffer, image->data, i_size );
 
     XDestroyImage( image );