]> git.sesse.net Git - vlc/blobdiff - modules/video_output/ggi.c
Make mouse-moved and mouse-clicked coordinates, remove mouse-x and -y
[vlc] / modules / video_output / ggi.c
index 2e9b4f75ded1ce501b1b88fcd81c3e73fa534b14..3ec10a7459693bef6b38671d9afd0d08ba9b7aeb 100644 (file)
@@ -1,17 +1,17 @@
 /*****************************************************************************
  * ggi.c : GGI plugin for vlc
  *****************************************************************************
- * Copyright (C) 2000, 2001 VideoLAN
- * $Id: ggi.c,v 1.1 2002/08/13 11:59:36 sam Exp $
+ * Copyright (C) 2000-2009 the VideoLAN team
+ * $Id$
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.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
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *
  * 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>                                      /* malloc(), free() */
-#include <string.h>
-#include <errno.h>                                                 /* ENOMEM */
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <ggi/ggi.h>
 
-#include <vlc/vlc.h>
-#include <vlc/intf.h>
-#include <vlc/vout.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_interface.h>
+#include <vlc_vout.h>
 
 /*****************************************************************************
  * Local prototypes
@@ -42,29 +43,29 @@ static int  Create    ( vlc_object_t * );
 static void Destroy   ( vlc_object_t * );
 
 static int  Init      ( vout_thread_t * );
-static void End       ( vout_thread_t * );                         
-static int  Manage    ( vout_thread_t * );               
-static void Display   ( vout_thread_t *, picture_t * );            
+static void End       ( vout_thread_t * );
+static int  Manage    ( vout_thread_t * );
+static void Display   ( vout_thread_t *, picture_t * );
 
 static int  OpenDisplay    ( vout_thread_t * );
 static void CloseDisplay   ( vout_thread_t * );
-static void SetPalette     ( vout_thread_t *, u16 *, u16 *, u16 * );
+static void SetPalette     ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
 
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-#define DISPLAY_TEXT N_("X11 display name")
-#define DISPLAY_LONGTEXT N_("Specify the X11 hardware display you want to use."\
-                           "\nBy default vlc will use the value of the DISPLAY"\
-                           " environment variable.")
-
-vlc_module_begin();                                
-    add_category_hint( N_("Miscellaneous"), NULL );
-    add_string( "ggi-display", NULL, NULL, DISPLAY_TEXT, DISPLAY_LONGTEXT );
-    set_description( "General Graphics Interface video output" );
-    set_capability( "video output", 30 );
-    set_callbacks( Create, Destroy );
-vlc_module_end();
+#define DISPLAY_TEXT N_("X11 display")
+#define DISPLAY_LONGTEXT N_( \
+            "X11 hardware display to use.\n" \
+            "By default, VLC will use the value of the DISPLAY " \
+            "environment variable.")
+
+vlc_module_begin ()
+    add_string( "ggi-display", NULL, NULL, DISPLAY_TEXT, DISPLAY_LONGTEXT, true )
+    set_description( "General Graphics Interface video output" )
+    set_capability( "video output", 30 )
+    set_callbacks( Create, Destroy )
+vlc_module_end ()
 
 /*****************************************************************************
  * vout_sys_t: video output GGI method descriptor
@@ -74,7 +75,7 @@ vlc_module_end();
  *****************************************************************************/
 struct vout_sys_t
 {
-    /* GGI system informations */
+    /* GGI system information */
     ggi_visual_t        p_display;                         /* display device */
 
     ggi_mode            mode;                             /* mode descriptor */
@@ -84,7 +85,7 @@ struct vout_sys_t
     ggi_directbuffer *  pp_buffer[2];                             /* buffers */
     int                 i_index;
 
-    vlc_bool_t          b_must_acquire;   /* must be acquired before writing */
+    bool          b_must_acquire;   /* must be acquired before writing */
 };
 
 /*****************************************************************************
@@ -101,17 +102,14 @@ static int Create( vlc_object_t *p_this )
     /* Allocate structure */
     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
     if( p_vout->p_sys == NULL )
-    {
-        msg_Err( p_vout, "out of memory" );
-        return( 1 );
-    }
+        return VLC_ENOMEM;
 
     /* Open and initialize device */
     if( OpenDisplay( p_vout ) )
     {
         msg_Err( p_vout, "cannot initialize GGI display" );
         free( p_vout->p_sys );
-        return( 1 );
+        return VLC_EGENERIC;
     }
 
     p_vout->pf_init = Init;
@@ -120,7 +118,7 @@ static int Create( vlc_object_t *p_this )
     p_vout->pf_render = NULL;
     p_vout->pf_display = Display;
 
-    return( 0 );
+    return VLC_SUCCESS;
 }
 
 /*****************************************************************************
@@ -145,21 +143,21 @@ static int Init( vout_thread_t *p_vout )
     switch( p_vout->p_sys->i_bits_per_pixel )
     {
         case 8:
-            p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
+            p_vout->output.i_chroma = VLC_CODEC_RGB8;
             p_vout->output.pf_setpalette = SetPalette;
             break;
         case 15:
-            p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5'); break;
+            p_vout->output.i_chroma = VLC_CODEC_RGB15; break;
         case 16:
-            p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); break;
+            p_vout->output.i_chroma = VLC_CODEC_RGB16; break;
         case 24:
-            p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4'); break;
+            p_vout->output.i_chroma = VLC_CODEC_RGB24; break;
         case 32:
-            p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); break;
+            p_vout->output.i_chroma = VLC_CODEC_RGB32; break;
         default:
             msg_Err( p_vout, "unknown screen depth %i",
                      p_vout->p_sys->i_bits_per_pixel );
-            return 0;
+            return VLC_EGENERIC;
     }
 
     /* Only useful for bits_per_pixel != 8 */
@@ -181,7 +179,7 @@ static int Init( vout_thread_t *p_vout )
 
     if( p_pic == NULL )
     {
-        return 0;
+        return VLC_EGENERIC;
     }
 
     /* We know the chroma, allocate a buffer which will be used
@@ -190,6 +188,7 @@ static int Init( vout_thread_t *p_vout )
     p_pic->p->p_pixels = p_b[ 0 ]->write;
     p_pic->p->i_pixel_pitch = p_b[ 0 ]->buffer.plb.pixelformat->size / 8;
     p_pic->p->i_lines = p_vout->p_sys->mode.visible.y;
+    p_pic->p->i_visible_lines = p_vout->p_sys->mode.visible.y;
 
     p_pic->p->i_pitch = p_b[ 0 ]->buffer.plb.stride;
 
@@ -228,7 +227,7 @@ static int Init( vout_thread_t *p_vout )
     /* Set asynchronous display mode -- usually quite faster */
     ggiAddFlags( p_vout->p_sys->p_display, GGIFLAG_ASYNC );
 
-    return( 0 );
+    return VLC_SUCCESS;
 #undef p_b
 }
 
@@ -254,9 +253,9 @@ static void End( vout_thread_t *p_vout )
  * Terminate an output method created by Create
  *****************************************************************************/
 static void Destroy( vlc_object_t *p_this )
-{   
-    vout_thread_t *p_vout = (vout_thread_t *)p_this; 
-    
+{
+    vout_thread_t *p_vout = (vout_thread_t *)p_this;
+
     CloseDisplay( p_vout );
 
     free( p_vout->p_sys );
@@ -266,7 +265,7 @@ static void Destroy( vlc_object_t *p_this )
  * Manage: handle GGI events
  *****************************************************************************
  * This function should be called regularly by video output thread. It returns
- * a non null value if an error occured.
+ * a non null value if an error occurred.
  *****************************************************************************/
 static int Manage( vout_thread_t *p_vout )
 {
@@ -277,7 +276,7 @@ static int Manage( vout_thread_t *p_vout )
     mask = emKeyboard | emPtrButtonPress | emPtrButtonRelease;
 
     ggiEventPoll( p_vout->p_sys->p_display, mask, &tv );
-    
+
     while( ggiEventsQueued( p_vout->p_sys->p_display, mask) )
     {
         ggiEventRead( p_vout->p_sys->p_display, &event, mask);
@@ -291,8 +290,7 @@ static int Manage( vout_thread_t *p_vout )
                     case 'q':
                     case 'Q':
                     case GIIUC_Escape:
-                        /* FIXME pass message ! */
-                        p_vout->p_vlc->b_die = 1;
+                        libvlc_Quit( p_vout->p_libvlc );
                         break;
 
                     default:
@@ -304,17 +302,13 @@ static int Manage( vout_thread_t *p_vout )
 
                 switch( event.pbutton.button )
                 {
+                    case GII_PBUTTON_LEFT:
+                        /*FIXME
+                        var_SetCoords( p_vout, "mouse-clicked", x, y );*/
+                        break;
+
                     case GII_PBUTTON_RIGHT:
-                        {
-                            intf_thread_t *p_intf;
-                            p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
-                                                              FIND_ANYWHERE );
-                            if( p_intf )
-                            {
-                                p_intf->b_menu_change = 1;
-                                vlc_object_release( p_intf );
-                            }
-                        }
+                        var_SetBool( p_vout->p_libvlc, "intf-popupmenu", true );
                         break;
                 }
                 break;
@@ -380,26 +374,26 @@ static int OpenDisplay( vout_thread_t *p_vout )
     if( ggiInit() )
     {
         msg_Err( p_vout, "cannot initialize GGI library" );
-        return( 1 );
+        return VLC_EGENERIC;
     }
 
     /* Open display */
-    psz_display = config_GetPsz( p_vout, "ggi_display" );
+    psz_display = var_InheritString( p_vout, "ggi-display" );
 
     p_vout->p_sys->p_display = ggiOpen( psz_display, NULL );
-    if( psz_display ) free( psz_display );
+    free( psz_display );
 
     if( p_vout->p_sys->p_display == NULL )
     {
         msg_Err( p_vout, "cannot open GGI default display" );
         ggiExit();
-        return( 1 );
+        return VLC_EGENERIC;
     }
 
     /* Find most appropriate mode */
     p_vout->p_sys->mode.frames =    2;                          /* 2 buffers */
-    p_vout->p_sys->mode.visible.x = config_GetInt( p_vout, "width" );
-    p_vout->p_sys->mode.visible.y = config_GetInt( p_vout, "height" );
+    p_vout->p_sys->mode.visible.x = var_InheritInteger( p_vout, "width" );
+    p_vout->p_sys->mode.visible.y = var_InheritInteger( p_vout, "height" );
     p_vout->p_sys->mode.virt.x =    GGI_AUTO;
     p_vout->p_sys->mode.virt.y =    GGI_AUTO;
     p_vout->p_sys->mode.size.x =    GGI_AUTO;
@@ -417,7 +411,7 @@ static int OpenDisplay( vout_thread_t *p_vout )
         msg_Err( p_vout, "cannot set GGI mode" );
         ggiClose( p_vout->p_sys->p_display );
         ggiExit();
-        return( 1 );
+        return VLC_EGENERIC;
     }
 
     /* Check buffers properties */
@@ -433,7 +427,7 @@ static int OpenDisplay( vout_thread_t *p_vout )
             msg_Err( p_vout, "double buffering is not possible" );
             ggiClose( p_vout->p_sys->p_display );
             ggiExit();
-            return( 1 );
+            return VLC_EGENERIC;
         }
 
         /* Check buffer properties */
@@ -446,7 +440,7 @@ static int OpenDisplay( vout_thread_t *p_vout )
             msg_Err( p_vout, "incorrect video memory type" );
             ggiClose( p_vout->p_sys->p_display );
             ggiExit();
-            return( 1 );
+            return VLC_EGENERIC;
         }
 
         /* Check if buffer needs to be acquired before write */
@@ -467,7 +461,7 @@ static int OpenDisplay( vout_thread_t *p_vout )
         msg_Err( p_vout, "cannot set colors" );
         ggiClose( p_vout->p_sys->p_display );
         ggiExit();
-        return( 1 );
+        return VLC_EGENERIC;
     }
 
     /* Set clipping for text */
@@ -478,13 +472,13 @@ static int OpenDisplay( vout_thread_t *p_vout )
         msg_Err( p_vout, "cannot set clipping" );
         ggiClose( p_vout->p_sys->p_display );
         ggiExit();
-        return( 1 );
+        return VLC_EGENERIC;
     }
 
     /* FIXME: set palette in 8bpp */
     p_vout->p_sys->i_bits_per_pixel = p_b[ 0 ]->buffer.plb.pixelformat->depth;
 
-    return( 0 );
+    return VLC_SUCCESS;
 #undef p_b
 }
 
@@ -506,11 +500,12 @@ static void CloseDisplay( vout_thread_t *p_vout )
 /*****************************************************************************
  * SetPalette: sets an 8 bpp palette
  *****************************************************************************/
-static void SetPalette( vout_thread_t *p_vout, u16 *red, u16 *green, u16 *blue )
+static void SetPalette( vout_thread_t *p_vout,
+                        uint16_t *red, uint16_t *green, uint16_t *blue )
 {
     ggi_color colors[256];
     int i;
-  
+
     /* Fill colors with color information */
     for( i = 0; i < 256; i++ )
     {
@@ -523,7 +518,7 @@ static void SetPalette( vout_thread_t *p_vout, u16 *red, u16 *green, u16 *blue )
     /* Set palette */
     if( ggiSetPalette( p_vout->p_sys->p_display, 0, 256, colors ) < 0 )
     {
-        msg_Err( p_vout, "failed setting palette" );
+        msg_Err( p_vout, "failed to set palette" );
     }
 }