| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
#ifdef HAVE_CONFIG_H |
|---|
| 29 |
# include "config.h" |
|---|
| 30 |
#endif |
|---|
| 31 |
|
|---|
| 32 |
#include <vlc_common.h> |
|---|
| 33 |
#include <vlc_plugin.h> |
|---|
| 34 |
#include <vlc_interface.h> |
|---|
| 35 |
#include <vlc_vout.h> |
|---|
| 36 |
#include <vlc_playlist.h> |
|---|
| 37 |
|
|---|
| 38 |
#ifdef HAVE_UNISTD_H |
|---|
| 39 |
# include <unistd.h> |
|---|
| 40 |
#endif |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
struct intf_sys_t |
|---|
| 46 |
{ |
|---|
| 47 |
vlc_object_t * p_vout; |
|---|
| 48 |
bool b_button_pressed; |
|---|
| 49 |
bool b_triggered; |
|---|
| 50 |
int i_threshold; |
|---|
| 51 |
}; |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
int Open ( vlc_object_t * ); |
|---|
| 57 |
void Close( vlc_object_t * ); |
|---|
| 58 |
static void RunIntf( intf_thread_t *p_intf ); |
|---|
| 59 |
static int InitThread( intf_thread_t *p_intf ); |
|---|
| 60 |
static int MouseEvent( vlc_object_t *, char const *, |
|---|
| 61 |
vlc_value_t, vlc_value_t, void * ); |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
#define THRESHOLD_TEXT N_( "Threshold" ) |
|---|
| 67 |
#define THRESHOLD_LONGTEXT N_( "Height of the zone triggering the interface." ) |
|---|
| 68 |
|
|---|
| 69 |
vlc_module_begin(); |
|---|
| 70 |
set_shortname( "Showintf" ); |
|---|
| 71 |
add_integer( "showintf-threshold", 10, NULL, THRESHOLD_TEXT, THRESHOLD_LONGTEXT, true ); |
|---|
| 72 |
set_description( N_("Show interface with mouse") ); |
|---|
| 73 |
|
|---|
| 74 |
set_capability( "interface", 0 ); |
|---|
| 75 |
set_callbacks( Open, Close ); |
|---|
| 76 |
vlc_module_end(); |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
int Open( vlc_object_t *p_this ) |
|---|
| 82 |
{ |
|---|
| 83 |
intf_thread_t *p_intf = (intf_thread_t *)p_this; |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
p_intf->p_sys = malloc( sizeof( intf_sys_t ) ); |
|---|
| 87 |
if( p_intf->p_sys == NULL ) |
|---|
| 88 |
{ |
|---|
| 89 |
return( 1 ); |
|---|
| 90 |
}; |
|---|
| 91 |
|
|---|
| 92 |
p_intf->pf_run = RunIntf; |
|---|
| 93 |
|
|---|
| 94 |
return( 0 ); |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
void Close( vlc_object_t *p_this ) |
|---|
| 101 |
{ |
|---|
| 102 |
intf_thread_t *p_intf = (intf_thread_t *)p_this; |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
free( p_intf->p_sys ); |
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
static void RunIntf( intf_thread_t *p_intf ) |
|---|
| 113 |
{ |
|---|
| 114 |
int canc = vlc_savecancel( ); |
|---|
| 115 |
p_intf->p_sys->p_vout = NULL; |
|---|
| 116 |
|
|---|
| 117 |
if( InitThread( p_intf ) < 0 ) |
|---|
| 118 |
{ |
|---|
| 119 |
msg_Err( p_intf, "cannot initialize interface" ); |
|---|
| 120 |
return; |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
while( vlc_object_alive( p_intf ) ) |
|---|
| 125 |
{ |
|---|
| 126 |
vlc_mutex_lock( &p_intf->change_lock ); |
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
if( p_intf->p_sys->b_triggered ) |
|---|
| 130 |
{ |
|---|
| 131 |
var_SetBool( p_intf->p_libvlc, "intf-show", true ); |
|---|
| 132 |
p_intf->p_sys->b_triggered = false; |
|---|
| 133 |
} |
|---|
| 134 |
|
|---|
| 135 |
vlc_mutex_unlock( &p_intf->change_lock ); |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
if( p_intf->p_sys->p_vout && !vlc_object_alive (p_intf->p_sys->p_vout) ) |
|---|
| 140 |
{ |
|---|
| 141 |
var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved", |
|---|
| 142 |
MouseEvent, p_intf ); |
|---|
| 143 |
var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down", |
|---|
| 144 |
MouseEvent, p_intf ); |
|---|
| 145 |
vlc_object_release( p_intf->p_sys->p_vout ); |
|---|
| 146 |
p_intf->p_sys->p_vout = NULL; |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
if( p_intf->p_sys->p_vout == NULL ) |
|---|
| 150 |
{ |
|---|
| 151 |
p_intf->p_sys->p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT, |
|---|
| 152 |
FIND_ANYWHERE ); |
|---|
| 153 |
if( p_intf->p_sys->p_vout ) |
|---|
| 154 |
{ |
|---|
| 155 |
var_AddCallback( p_intf->p_sys->p_vout, "mouse-moved", |
|---|
| 156 |
MouseEvent, p_intf ); |
|---|
| 157 |
var_AddCallback( p_intf->p_sys->p_vout, "mouse-button-down", |
|---|
| 158 |
MouseEvent, p_intf ); |
|---|
| 159 |
} |
|---|
| 160 |
} |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
msleep( INTF_IDLE_SLEEP ); |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
if( p_intf->p_sys->p_vout ) |
|---|
| 167 |
{ |
|---|
| 168 |
var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved", |
|---|
| 169 |
MouseEvent, p_intf ); |
|---|
| 170 |
var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down", |
|---|
| 171 |
MouseEvent, p_intf ); |
|---|
| 172 |
vlc_object_release( p_intf->p_sys->p_vout ); |
|---|
| 173 |
} |
|---|
| 174 |
vlc_restorecancel( canc ); |
|---|
| 175 |
} |
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
static int InitThread( intf_thread_t * p_intf ) |
|---|
| 181 |
{ |
|---|
| 182 |
if( vlc_object_alive( p_intf ) ) |
|---|
| 183 |
{ |
|---|
| 184 |
vlc_mutex_lock( &p_intf->change_lock ); |
|---|
| 185 |
|
|---|
| 186 |
p_intf->p_sys->b_triggered = false; |
|---|
| 187 |
p_intf->p_sys->b_button_pressed = false; |
|---|
| 188 |
p_intf->p_sys->i_threshold = |
|---|
| 189 |
config_GetInt( p_intf, "showintf-threshold" ); |
|---|
| 190 |
|
|---|
| 191 |
vlc_mutex_unlock( &p_intf->change_lock ); |
|---|
| 192 |
|
|---|
| 193 |
return 0; |
|---|
| 194 |
} |
|---|
| 195 |
else |
|---|
| 196 |
{ |
|---|
| 197 |
return -1; |
|---|
| 198 |
} |
|---|
| 199 |
} |
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
static int MouseEvent( vlc_object_t *p_this, char const *psz_var, |
|---|
| 205 |
vlc_value_t oldval, vlc_value_t newval, void *p_data ) |
|---|
| 206 |
{ |
|---|
| 207 |
VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(newval); |
|---|
| 208 |
vlc_value_t val; |
|---|
| 209 |
|
|---|
| 210 |
int i_mouse_x, i_mouse_y; |
|---|
| 211 |
intf_thread_t *p_intf = (intf_thread_t *)p_data; |
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
if( p_intf->p_sys->b_triggered ) |
|---|
| 215 |
return VLC_SUCCESS; |
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
var_Get( p_intf->p_sys->p_vout, "fullscreen", &val ); |
|---|
| 219 |
if( !val.i_int ) |
|---|
| 220 |
return VLC_SUCCESS; |
|---|
| 221 |
|
|---|
| 222 |
vlc_mutex_lock( &p_intf->change_lock ); |
|---|
| 223 |
if( !strcmp( psz_var, "mouse-moved" ) && !p_intf->p_sys->b_button_pressed ) |
|---|
| 224 |
{ |
|---|
| 225 |
var_Get( p_intf->p_sys->p_vout, "mouse-x", &val ); |
|---|
| 226 |
i_mouse_x = val.i_int; |
|---|
| 227 |
var_Get( p_intf->p_sys->p_vout, "mouse-y", &val ); |
|---|
| 228 |
i_mouse_y = val.i_int; |
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
if ( i_mouse_y < p_intf->p_sys->i_threshold ) |
|---|
| 232 |
{ |
|---|
| 233 |
msg_Dbg( p_intf, "interface showing requested" ); |
|---|
| 234 |
p_intf->p_sys->b_triggered = true; |
|---|
| 235 |
} |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
if( !p_intf->p_sys->b_button_pressed && |
|---|
| 241 |
!strcmp( psz_var, "mouse-button-down" ) ) |
|---|
| 242 |
{ |
|---|
| 243 |
p_intf->p_sys->b_button_pressed = true; |
|---|
| 244 |
} |
|---|
| 245 |
if( p_intf->p_sys->b_button_pressed && |
|---|
| 246 |
!strcmp( psz_var, "mouse-button-down" ) ) |
|---|
| 247 |
{ |
|---|
| 248 |
p_intf->p_sys->b_button_pressed = false; |
|---|
| 249 |
} |
|---|
| 250 |
|
|---|
| 251 |
vlc_mutex_unlock( &p_intf->change_lock ); |
|---|
| 252 |
|
|---|
| 253 |
return VLC_SUCCESS; |
|---|
| 254 |
} |
|---|