diff --git a/src/backend/x11.c b/src/backend/x11.c index 20e16ca..d2a84eb 100644 --- a/src/backend/x11.c +++ b/src/backend/x11.c @@ -182,11 +182,10 @@ void MwLLNextEvent(MwLL handle) { MwLLDispatch(handle, move, &p); } else if(ev.type == KeyPress) { - int n = -1; - KeySym sym = XLookupKeysym(&ev.xkey, 0); - char* str = XKeysymToString(sym); - - if(strcmp(str, "space") == 0) str = " "; + int n = -1; + char str[512]; + KeySym sym; + XLookupString(&ev.xkey, str, 512, &sym, NULL); /* HACK: this is bad, you can guess why */ if(strlen(str) == 1) { diff --git a/src/widget/entry.c b/src/widget/entry.c index 46cf749..91a8f7b 100644 --- a/src/widget/entry.c +++ b/src/widget/entry.c @@ -24,6 +24,7 @@ static void draw(MwWidget handle) { MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground)); const char* str = MwGetText(handle, MwNtext); + if(str == NULL) str = ""; r.x = 0; r.y = 0; diff --git a/src/widget/numberentry.c b/src/widget/numberentry.c index b3a78c6..3835971 100644 --- a/src/widget/numberentry.c +++ b/src/widget/numberentry.c @@ -18,7 +18,20 @@ static void draw(MwWidget handle) { } static void key(MwWidget handle, int code) { - MwEntryClass->key(handle, code); + MwEntry e = handle->internal; + const char* str = MwGetText(handle, MwNtext); + int ok = 0; + if(str == NULL) str = ""; + + if(code == '-' && e->cursor == 0 && strchr(str, (int)'-') == NULL) { + ok = 1; + } else if('0' <= code && code <= '9') { + ok = 1; + } else if(code == '.' && strchr(str, (int)'.') == NULL) { + ok = 1; + } + + if(ok) MwEntryClass->key(handle, code); } MwClassRec MwNumberEntryClassRec = {