Skip to content

Instantly share code, notes, and snippets.

@psychon
Created September 11, 2015 07:50
Show Gist options
  • Save psychon/72bdf3c72551d1ab003a to your computer and use it in GitHub Desktop.
Save psychon/72bdf3c72551d1ab003a to your computer and use it in GitHub Desktop.
commit e689d373588fd07567b7a9a64c76a5278c159849
Author: Uli Schlachter <[email protected]>
Date: Fri Sep 11 09:49:15 2015 +0200
Make luaA_keystore() easier to follow
This now first unsets state and then sets the new state.
Signed-off-by: Uli Schlachter <[email protected]>
diff --git a/objects/key.c b/objects/key.c
index 3c8172f..f5c9520 100644
--- a/objects/key.c
+++ b/objects/key.c
@@ -66,8 +66,13 @@ luaA_keystore(lua_State *L, int ud, const char *str, ssize_t len)
if(!len)
return;
keyb_t *key = luaA_checkudata(L, ud, &key_class);
+
+ /* First, unset everything */
key->utf8 = NULL;
+ key->keycode = 0;
+ key->keysym = 0;
+ /* Then set up the new state */
if(*str != '#' || len == 1)
{
key->keysym = xkb_keysym_from_name(str, 0);
@@ -77,12 +82,10 @@ luaA_keystore(lua_State *L, int ud, const char *str, ssize_t len)
warn("There is no keysym named \"%s\". Will be handled as utf8 key.", str);
key->utf8 = a_strdup(str);
}
- key->keycode = 0;
}
else
{
key->keycode = atoi(str + 1);
- key->keysym = 0;
}
luaA_object_emit_signal(L, ud, "property::key", 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment