Commit 90ee09e8 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

KeyToString: allocate key on heap

This will allow returning dynamically generated strings
parent 4acb3f1f
......@@ -86,7 +86,7 @@
#define KEY_MOUSEWHEELLEFT 0x00F20000
#define KEY_MOUSEWHEELRIGHT 0x00F30000
VLC_EXPORT( const char *, KeyToString, (uint_fast32_t i_key) ) LIBVLC_USED;
VLC_EXPORT( char *, KeyToString, (uint_fast32_t i_key) ) LIBVLC_USED;
VLC_EXPORT( uint_fast32_t, StringToKey, (char *psz_key) ) LIBVLC_USED;
typedef enum vlc_key {
......
......@@ -86,9 +86,12 @@ static VLCSimplePrefs *_o_sharedInstance = nil;
if( val & KEY_MODIFIER_COMMAND )
[o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\x98"]];
const char *base = KeyToString( val & ~KEY_MODIFIER );
char *base = KeyToString( val & ~KEY_MODIFIER );
if( base )
{
[o_temp_str appendString: [NSString stringWithUTF8String: base]];
free( base );
}
else
o_temp_str = [NSMutableString stringWithString:_NS("Not Set")];
return o_temp_str;
......
......@@ -231,16 +231,23 @@ int qtWheelEventToVLCKey( QWheelEvent *e )
QString VLCKeyToString( int val )
{
const char *base = KeyToString (val & ~KEY_MODIFIER);
char *base = KeyToString (val & ~KEY_MODIFIER);
QString r = "";
if( val & KEY_MODIFIER_CTRL )
r+= "Ctrl+";
r+= qfu( "Ctrl+" );
if( val & KEY_MODIFIER_ALT )
r+= "Alt+";
r+= qfu( "Alt+" );
if( val & KEY_MODIFIER_SHIFT )
r+= "Shift+";
r+= qfu( "Shift+" );
return r + (base ? base : qtr( "Unset" ) );
if (base)
{
r += qfu( base );
free( base );
}
else
r += qtr( "Unset" );
return r;
}
......@@ -39,9 +39,12 @@ const string EvtKey::getAsString() const
msg_Warn( getIntf(), "Unknown action type" );
// Add the key
const char *keyName = KeyToString( m_key );
char *keyName = KeyToString( m_key );
if( keyName )
{
event += (string)":" + keyName;
free( keyName );
}
else
msg_Warn( getIntf(), "Unknown key: %d", m_key );
......
......@@ -171,14 +171,14 @@ static int cmpkey (const void *key, const void *elem)
return ((uintptr_t)key) - ((key_descriptor_t *)elem)->i_key_code;
}
const char *KeyToString (uint_fast32_t sym)
char *KeyToString (uint_fast32_t sym)
{
key_descriptor_t *d;
d = (key_descriptor_t *)
bsearch ((void *)(uintptr_t)sym, vlc_keys, vlc_num_keys,
sizeof (vlc_keys[0]), cmpkey);
return d ? d->psz_key_string : NULL;
return d ? strdup (d->psz_key_string) : NULL;
}
uint_fast32_t StringToKey (char *name)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment