mouse wheel support
Shane Harper
shanegh at optusnet.com.au
Mon Apr 30 03:42:38 CEST 2001
Hi.
Here's another patch for adding mouse wheel support.
This patch lets the user decide the function to be performed by the mouse
wheel. vlc_mouse_wheel can be set to one of:
stream_position
volume
speed
none
The default is "stream_position". (I find this useful when I want to skip
past a scene when I'm watching "fullscreen" and the interface window isn't
visible.)
This currently only works with the XVideo output module. (I don't know how
to detect mouse wheel movement with the SDL.) The amount of code that has
to be added to output modules is minimal: Just call
intf_HandleMouseWheel( 1 ) when the wheel is moved forwards and
intf_HandleMouseWheel( 0 ) when it's moved backwards.
Shane.
-- Attached file included as plaintext by Listar --
-- File: patch.txt
diff -urN vlc.bk/include/config.h.in vlc/include/config.h.in
--- vlc.bk/include/config.h.in Sat Apr 28 13:36:25 2001
+++ vlc/include/config.h.in Mon Apr 30 11:14:05 2001
@@ -142,6 +142,9 @@
/* Maximum number of channels */
#define INTF_MAX_CHANNELS 10
+#define INTF_MOUSE_WHEEL_VAR "vlc_mouse_wheel"
+#define INTF_MOUSE_WHEEL_DEFAULT "stream_position"
+
/*****************************************************************************
* Input thread configuration
*****************************************************************************/
diff -urN vlc.bk/include/input_ext-intf.h vlc/include/input_ext-intf.h
--- vlc.bk/include/input_ext-intf.h Fri Apr 20 15:40:03 2001
+++ vlc/include/input_ext-intf.h Mon Apr 30 09:51:04 2001
@@ -349,6 +349,7 @@
void input_SetStatus( struct input_thread_s *, int );
void input_SetRate ( struct input_thread_s *, int );
void input_Seek ( struct input_thread_s *, off_t );
+int input_SeekFromCurrentPosition( struct input_thread_s *, float );
void input_DumpStream( struct input_thread_s * );
char * input_OffsetToTime( struct input_thread_s *, char * psz_buffer, off_t );
int input_ChangeES ( struct input_thread_s *, struct es_descriptor_s *, u8 );
diff -urN vlc.bk/include/interface.h vlc/include/interface.h
--- vlc.bk/include/interface.h Thu Mar 22 00:42:33 2001
+++ vlc/include/interface.h Mon Apr 30 09:45:20 2001
@@ -107,4 +107,4 @@
void intf_AssignKey( intf_thread_t *p_intf, int r_key, int f_key, int param);
keyparm intf_GetKey( intf_thread_t *p_intf, int r_key);
void intf_AssignNormalKeys( intf_thread_t *p_intf);
-
+void intf_HandleMouseWheel( boolean_t up );
diff -urN vlc.bk/plugins/x11/vout_xvideo.c vlc/plugins/x11/vout_xvideo.c
--- vlc.bk/plugins/x11/vout_xvideo.c Sat Apr 28 05:29:11 2001
+++ vlc/plugins/x11/vout_xvideo.c Mon Apr 30 09:42:17 2001
@@ -474,6 +474,12 @@
/* FIXME: need locking ! */
p_main->p_intf->b_menu_change = 1;
break;
+ case Button4: /* mouse wheel moved forwards */
+ intf_HandleMouseWheel( 1 );
+ break;
+ case Button5: /* mouse wheel moved backwards */
+ intf_HandleMouseWheel( 0 );
+ break;
}
}
/* Mouse move */
diff -urN vlc.bk/src/input/input_ext-intf.c vlc/src/input/input_ext-intf.c
--- vlc.bk/src/input/input_ext-intf.c Sat Apr 28 13:36:25 2001
+++ vlc/src/input/input_ext-intf.c Mon Apr 30 10:05:00 2001
@@ -74,6 +74,9 @@
break;
case INPUT_STATUS_FASTER:
+ /* XXX It'd be nice if this always doubled the playback speed. E.g. if
+ * speed was 2x it'd become 4x, if it was 1/4 it'd be increased to 1/2.
+ */
/* If we are already going too fast, go back to default rate */
if( p_input->stream.control.i_rate * 8 <= DEFAULT_RATE )
{
@@ -100,6 +103,9 @@
break;
case INPUT_STATUS_SLOWER:
+ /* XXX It'd be nice if this always halved the playback speed. E.g. if
+ * speed was 1/2 it'd become 1/4, if it was 4x it'd be reduced to 2x.
+ */
/* If we are already going too slow, go back to default rate */
if( p_input->stream.control.i_rate >= 8 * DEFAULT_RATE )
{
@@ -149,6 +155,11 @@
char psz_time1[OFFSETTOTIME_MAX_SIZE];
char psz_time2[OFFSETTOTIME_MAX_SIZE];
+ if( i_position < 0 )
+ i_position = 0;
+ if( i_position >= p_input->stream.p_selected_area->i_size )
+ i_position = p_input->stream.p_selected_area->i_size-1;
+
vlc_mutex_lock( &p_input->stream.stream_lock );
p_input->stream.p_selected_area->i_seek = i_position;
@@ -160,6 +171,22 @@
vlc_cond_signal( &p_input->stream.stream_wait );
vlc_mutex_unlock( &p_input->stream.stream_lock );
+}
+
+/*****************************************************************************
+ * input_SeekFromCurrentPosition: changes the stream postion
+ *****************************************************************************/
+int input_SeekFromCurrentPosition( input_thread_t *p_input,
+ float f_offsetInSeconds )
+{
+ if( ! p_input )
+ return -1;
+ if( ! p_input->stream.b_seekable )
+ return -1;
+
+ input_Seek( p_input, p_input->stream.p_selected_area->i_tell +
+ ( f_offsetInSeconds * 50 * p_input->stream.i_mux_rate ) );
+ return 0;
}
/*****************************************************************************
diff -urN vlc.bk/src/interface/interface.c vlc/src/interface/interface.c
--- vlc.bk/src/interface/interface.c Sat Apr 28 13:36:25 2001
+++ vlc/src/interface/interface.c Mon Apr 30 09:44:23 2001
@@ -61,6 +61,8 @@
* Local prototypes
*****************************************************************************/
static void intf_Manage( intf_thread_t *p_intf );
+static void intf_IncreaseVolume( void );
+static void intf_DecreaseVolume( void );
/*****************************************************************************
* intf_Create: prepare interface before main loop
@@ -311,6 +313,32 @@
intf_AssignKey( p_intf , 'd', INTF_KEY_DUMP_STREAM, 0);
}
+
+void intf_HandleMouseWheel( boolean_t up )
+{
+ char *psz_mouse_wheel_function = main_GetPszVariable(
+ INTF_MOUSE_WHEEL_VAR,
+ INTF_MOUSE_WHEEL_DEFAULT );
+
+ if( strcmp( psz_mouse_wheel_function, "stream_position" ) == 0 )
+ {
+ input_SeekFromCurrentPosition( p_main->p_intf->p_input,
+ up ? 10 : -10 /*seconds*/ );
+ }
+ else if( strcmp( psz_mouse_wheel_function, "volume" ) == 0 )
+ {
+ if( up ) intf_IncreaseVolume(); else intf_DecreaseVolume();
+ }
+ else if( strcmp( psz_mouse_wheel_function, "speed" ) == 0 )
+ {
+ if( p_main->p_intf->p_input )
+ input_SetStatus( p_main->p_intf->p_input,
+ up ? INPUT_STATUS_FASTER : INPUT_STATUS_SLOWER );
+ }
+ /* else... do nothing */
+}
+
+
/*****************************************************************************
* intf_ProcessKey: process standard keys
*****************************************************************************
@@ -336,13 +364,11 @@
/* FIXME : keyboard event is for the time being half handled by the interface
* half handled directly by the plugins. We should decide what to do. */
break;
- case INTF_KEY_INC_VOLUME: /* volume + */
- if( (p_main->p_aout != NULL) && (p_main->p_aout->vol < VOLUME_MAX) )
- p_main->p_aout->vol += VOLUME_STEP;
+ case INTF_KEY_INC_VOLUME:
+ intf_IncreaseVolume();
break;
- case INTF_KEY_DEC_VOLUME: /* volume - */
- if( (p_main->p_aout != NULL) && (p_main->p_aout->vol > VOLUME_STEP) )
- p_main->p_aout->vol -= VOLUME_STEP;
+ case INTF_KEY_DEC_VOLUME:
+ intf_DecreaseVolume();
break;
case INTF_KEY_TOGGLE_VOLUME: /* toggle mute */
if( (p_main->p_aout != NULL) && (p_main->p_aout->vol))
@@ -382,4 +408,17 @@
}
return( 0 );
+}
+
+
+static void intf_IncreaseVolume( void )
+{
+ if( (p_main->p_aout != NULL) && (p_main->p_aout->vol < VOLUME_MAX) )
+ p_main->p_aout->vol += VOLUME_STEP;
+}
+
+static void intf_DecreaseVolume( void )
+{
+ if( (p_main->p_aout != NULL) && (p_main->p_aout->vol > VOLUME_STEP) )
+ p_main->p_aout->vol -= VOLUME_STEP;
}
More information about the vlc-devel
mailing list