]> git.sesse.net Git - vlc/blobdiff - modules/control/globalhotkeys/win32.c
I422_YUY2: clobber lists for MMX and SSE2
[vlc] / modules / control / globalhotkeys / win32.c
index af88dd2f6ee63c9d8377f509a428792dc4bf091b..055b32a6ecb438d2ac178a24427eeddfc610fddb 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * globalhotkeys.c: Global-Hotkey handling for vlc
+ * win32.c: Global-Hotkey WIN32 handling for vlc
  *****************************************************************************
  * Copyright (C) 2008-2009 the VideoLAN team
  *
@@ -42,14 +42,14 @@ LRESULT CALLBACK WMHOTKEYPROC( HWND, UINT, WPARAM, LPARAM );
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-vlc_module_begin();
-    set_shortname( _("Global Hotkeys") );
-    set_category( CAT_INTERFACE );
-    set_subcategory( SUBCAT_INTERFACE_HOTKEYS );
-    set_description( _("Global Hotkeys interface") );
-    set_capability( "interface", 0 );
-    set_callbacks( Open, Close );
-vlc_module_end();
+vlc_module_begin()
+    set_shortname( N_("Global Hotkeys") )
+    set_category( CAT_INTERFACE )
+    set_subcategory( SUBCAT_INTERFACE_HOTKEYS )
+    set_description( N_("Global Hotkeys interface") )
+    set_capability( "interface", 0 )
+    set_callbacks( Open, Close )
+vlc_module_end()
 
 struct intf_sys_t
 {
@@ -130,9 +130,6 @@ static void Close( vlc_object_t *p_this )
 static void *Thread( void *p_data )
 {
     MSG message;
-    UINT i_key, i_keyMod, i_vk;
-    ATOM atom;
-    char *psz_hotkey = NULL;
 
     intf_thread_t *p_intf = p_data;
     intf_sys_t *p_sys = p_intf->p_sys;
@@ -162,24 +159,29 @@ static void *Thread( void *p_data )
     vlc_cond_signal( &p_sys->wait );
     vlc_mutex_unlock( &p_sys->lock );
 
-    SetWindowLongPtr( p_sys->hotkeyWindow, GWL_WNDPROC,
+    SetWindowLongPtr( p_sys->hotkeyWindow, GWLP_WNDPROC,
             (LONG_PTR)WMHOTKEYPROC );
-    SetWindowLongPtr( p_sys->hotkeyWindow, GWL_USERDATA,
+    SetWindowLongPtr( p_sys->hotkeyWindow, GWLP_USERDATA,
             (LONG_PTR)p_intf );
 
     /* Registering of Hotkeys */
-    for( struct hotkey *p_hotkey = p_intf->p_libvlc->p_hotkeys;
+    for( const struct hotkey *p_hotkey = p_intf->p_libvlc->p_hotkeys;
             p_hotkey->psz_action != NULL;
             p_hotkey++ )
     {
-        if( asprintf( &psz_hotkey, "global-%s", p_hotkey->psz_action ) < 0 )
-            break;
+        char varname[12 + strlen( p_hotkey->psz_action )];
+        sprintf( varname, "global-key-%s", p_hotkey->psz_action );
 
-        i_key = config_GetInt( p_intf, psz_hotkey );
+        char *key = var_InheritString( p_intf, varname );
+        if( key == NULL )
+            continue;
 
-        free( psz_hotkey );
+        UINT i_key = vlc_str2keycode( key );
+        free( key );
+        if( i_key == KEY_UNSET )
+            continue;
 
-        i_keyMod = 0;
+        UINT i_keyMod = 0;
         if( i_key & KEY_MODIFIER_SHIFT ) i_keyMod |= MOD_SHIFT;
         if( i_key & KEY_MODIFIER_ALT ) i_keyMod |= MOD_ALT;
         if( i_key & KEY_MODIFIER_CTRL ) i_keyMod |= MOD_CONTROL;
@@ -187,6 +189,8 @@ static void *Thread( void *p_data )
 #define HANDLE( key ) case KEY_##key: i_vk = VK_##key; break
 #define HANDLE2( key, key2 ) case KEY_##key: i_vk = VK_##key2; break
 
+#define KEY_SPACE ' '
+
 #ifndef VK_VOLUME_DOWN
 #define VK_VOLUME_DOWN          0xAE
 #define VK_VOLUME_UP            0xAF
@@ -204,7 +208,7 @@ static void *Thread( void *p_data )
 #define VK_PAGEDOWN             0x22
 #endif
 
-        i_vk = 0;
+        UINT i_vk = 0;
         switch( i_key & ~KEY_MODIFIER )
         {
             HANDLE( LEFT );
@@ -240,7 +244,7 @@ static void *Thread( void *p_data )
             HANDLE( MEDIA_NEXT_TRACK );
 
             default:
-                i_vk = toupper( i_key & ~KEY_MODIFIER );
+                i_vk = toupper( (uint8_t)(i_key & ~KEY_MODIFIER) );
                 break;
         }
         if( !i_vk ) continue;
@@ -248,7 +252,7 @@ static void *Thread( void *p_data )
 #undef HANDLE
 #undef HANDLE2
 
-        atom = GlobalAddAtomA( p_hotkey->psz_action );
+        ATOM atom = GlobalAddAtomA( p_hotkey->psz_action );
         if( !atom ) continue;
 
         if( !RegisterHotKey( p_sys->hotkeyWindow, atom, i_keyMod, i_vk ) )
@@ -260,11 +264,11 @@ static void *Thread( void *p_data )
         DispatchMessage( &message );
 
     /* Unregistering of Hotkeys */
-    for( struct hotkey *p_hotkey = p_intf->p_libvlc->p_hotkeys;
+    for( const struct hotkey *p_hotkey = p_intf->p_libvlc->p_hotkeys;
             p_hotkey->psz_action != NULL;
             p_hotkey++ )
     {
-        atom = GlobalFindAtomA( p_hotkey->psz_action );
+        ATOM atom = GlobalFindAtomA( p_hotkey->psz_action );
         if( !atom ) continue;
 
         if( UnregisterHotKey( p_sys->hotkeyWindow, atom ) )
@@ -290,26 +294,21 @@ LRESULT CALLBACK WMHOTKEYPROC( HWND hwnd, UINT uMsg, WPARAM wParam,
     {
         case WM_HOTKEY:
             {
-                int i;
                 char psz_atomName[40];
 
-                intf_thread_t *p_intf =
-                    (intf_thread_t*)GetWindowLongPtr( hwnd, GWL_USERDATA );
-                struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
+                LONG_PTR ret = GetWindowLongPtr( hwnd, GWLP_USERDATA );
+                intf_thread_t *p_intf = (intf_thread_t*)ret;
 
-                i = GlobalGetAtomNameA(
-                        wParam, psz_atomName, sizeof( psz_atomName ) );
-                if( !i ) return 0;
+                if( !GlobalGetAtomNameA(
+                        wParam, psz_atomName, sizeof( psz_atomName ) ) )
+                    return 0;
 
                 /* search for key associated with VLC */
-                for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
+                vlc_action_t action = vlc_GetActionId( psz_atomName );
+                if( action != ACTIONID_NONE )
                 {
-                    if( strcmp( p_hotkeys[i].psz_action, psz_atomName ) )
-                        continue;
-
                     var_SetInteger( p_intf->p_libvlc,
-                            "key-action", p_hotkeys[i].i_action );
-
+                            "key-action", action );
                     return 1;
                 }
             }