[vlc-devel] Proposal for a new hotkeys design (one more)

Laurent Aimar fenrir at via.ecp.fr
Fri Nov 7 12:46:42 CET 2008

On Wed, Nov 05, 2008, brezhoneg1 wrote:
> 2- We think globally
> --------------------
> We decide to collect all key-pressed from all entities within an
> instance into a single processing thread. This is today's situation.
> This is okay. The only thing is to that key-pressed variable must be
> changed to a {key-pressed + p_origin_object} variable (see previous
> email). WE MUST NOT forget the origin of key-pressed.
 I think it could be simpler for the time being.

 Btw, for this solution you do not need to modify vlc_variable_t.
You can use a pointer to a local structure as long as everyone registering
a callback on "key-pressed" do not store the pointer.

 Something like that can work:

SetKey( vlc_object_t *p_obj, int i_key )
    vlc_key_t k;
    vlc_variable_t v;
    k.i_key = i_key;
    k.p_origin = p_obj;

    v.p_address = &k
    var_Set( p_obj->p_libvlc, "key-pressed", &v );

KeyCallback( ..., vlc_variable_t newval, void *p_user )
   user_t *p_sys = p_data;
   const vlc_key_t *p_key = newval.p_address;

  /* Here you can use p_key->i_key and p_key->p_origin */
  fprintf( stderr, "%d %p", p_key->i_key, p_key->p_origin );
  /* You cannot store p_key directly AND you have to vlc_object_hold p_origin
      if you need it (and then you will have to release it later) */
  user_lock( p_sys );
  user_push_key( p_sys, p_key->i_key, vlc_object_hold( p_key->p_origin ) );
  user_unlock( p_sys );


More information about the vlc-devel mailing list