[vlc-devel] [PATCH] Global Hotkeys for windows

Laurent Aimar fenrir at via.ecp.fr
Thu Jan 15 19:16:02 CET 2009


Hi,

On Thu, Jan 15, 2009, Hannes Domani wrote:
> I've included (most of) your ideas.  But I didn't add the additional add_key() parameter -> both the normal and the global hotkey have the same text. You can add that or probably change the qui to highlight the "global-" hotkeys differently (I'm really not good with this kind of things, texts or guis).
 I am not sure, I will wait for jb to comment on that. But it can be done
as a separate patch (so it will not prevent this one to be applied).
> +/*****************************************************************************
> + * Close: destroy interface
> + *****************************************************************************/
> +static void Close( vlc_object_t *p_this )
> +{
> +    intf_thread_t *p_intf = (intf_thread_t *)p_this;
> +    intf_sys_t *p_sys = p_intf->p_sys;
> +
> +    /* stop hotkey window */
> +    PostMessage( p_sys->hotkeyWindow, WM_CLOSE, 0, 0 );
 Here you have a race condition between the post of this message and the
creation of the window handle (in case Close is called too fast).
 You need to make sure in the Open or in the Close before the post that the
window have been created (or have failed).
 And you probably need to protect( using lock) hotkeyWindow access (see below).

> +/*****************************************************************************
> + * Thread: main loop
> + *****************************************************************************/
> +static void *Thread( void *p_data )
> +{
> +    /* Window which receives Hotkeys */
> +    p_sys->hotkeyWindow =
> +        (void*)CreateWindow( _T("STATIC"),           /* name of window class */
> +                _T("VLC ghk ") _T(VERSION),         /* window title bar text */
> +                0,                                           /* window style */
> +                0,                                   /* default X coordinate */
> +                0,                                   /* default Y coordinate */
> +                0,                                           /* window width */
> +                0,                                          /* window height */
> +                NULL,                                    /* no parent window */
> +                NULL,                              /* no menu in this window */
> +                GetModuleHandle(NULL),    /* handle of this program instance */
> +                NULL );                                 /* sent to WM_CREATE */
> +
> +    if( p_sys->hotkeyWindow == NULL )
> +        return( NULL );
 You should protect p_sys->hotkeyWindow and probably signal its creation or
the failure.

> +    /* close window */
> +    DestroyWindow( p_sys->hotkeyWindow );
 You should also protect the destruction (specially if GetMessage can fail
for another reason that your WM_CLOSE post).

 For locking and signal, you can have a look at:
 vlc_mutex_t
 vlc_cond_t

 vlc_mutex_init/vlc_mutex_destroy
 vlc_mutex_lock/unlock

 vlc_cond_init/destroy
 vlc_cond_signal/wait
(becarefull that vlc_cond_wait can have supurious wake up).

 Other than that and courmish comments, it seems fine, thanks for your work.

-- 
fenrir




More information about the vlc-devel mailing list