aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-06-29 14:49:56 +0200
committerDavid Robillard <d@drobilla.net>2019-07-24 01:02:52 +0200
commit1deb98f57f7b597be941fd944a91f2daa1a1f10a (patch)
tree12420662e97aae6c71e6ded7709f23a5ce973b70
parentfd7d496d4c5dcd9377ce945989ce05f464dc3afc (diff)
Rename PuglEventKey::utf8 to "string" with char type
This matches Gtk and is generally less annoying to work with.
-rw-r--r--pugl/pugl.h22
-rw-r--r--pugl/pugl_osx.m4
-rw-r--r--pugl/pugl_win.c16
-rw-r--r--pugl/pugl_x11.c13
-rw-r--r--test/test_utils.h4
5 files changed, 29 insertions, 30 deletions
diff --git a/pugl/pugl.h b/pugl/pugl.h
index 84887e7..d3bcc7f 100644
--- a/pugl/pugl.h
+++ b/pugl/pugl.h
@@ -261,23 +261,23 @@ typedef struct {
/**
Key press/release event.
- Keys that correspond to a Unicode character have `character` and `utf8` set.
- Other keys will have `character` 0, but `special` may be set if this is a
- known special key.
+ Keys that correspond to a Unicode character have `character` and `string`
+ set. Other keys will have `character` 0, but `special` may be set if this
+ is a known special key.
A key press may be part of a multi-key sequence to generate a wide
character. If `filter` is set, this event is part of a multi-key sequence
and should be ignored if the application is reading textual input.
Following the series of filtered press events, a press event with
- `character` and `utf8` (but `keycode` 0) will be sent. This event will have
- no corresponding release event.
+ `character` and `string` (but `keycode` 0) will be sent. This event will
+ have no corresponding release event.
Generally, an application should either work with raw keyboard press/release
- events based on `keycode` (ignoring events with `keycode` 0), or
- read textual input based on `character` or `utf8` (ignoring releases and
- events with `filter` 1). Note that blindly appending `utf8` will yield
- incorrect text, since press events are sent for both individually composed
- keys and the resulting synthetic multi-byte press.
+ events based on `keycode` (ignoring events with `keycode` 0), or read
+ textual input based on `character` or `string` (ignoring releases and events
+ with `filter` 1). Note that blindly appending `string` will yield incorrect
+ text, since press events are sent for both individually composed keys and
+ the resulting synthetic multi-byte press.
*/
typedef struct {
PuglEventType type; /**< PUGL_KEY_PRESS or PUGL_KEY_RELEASE. */
@@ -291,7 +291,7 @@ typedef struct {
uint32_t keycode; /**< Raw key code. */
uint32_t character; /**< Unicode character code, or 0. */
PuglKey special; /**< Special key, or 0. */
- uint8_t utf8[8]; /**< UTF-8 string. */
+ char string[8]; /**< UTF-8 string. */
bool filter; /**< True if part of a multi-key sequence. */
} PuglEventKey;
diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m
index cdaa131..0546eec 100644
--- a/pugl/pugl_osx.m
+++ b/pugl/pugl_osx.m
@@ -439,7 +439,7 @@ handleCrossing(PuglOpenGLView* view, NSEvent* event, const PuglEventType type)
{ 0, 0, 0, 0, 0, 0, 0, 0 },
false
};
- strncpy((char*)ev.utf8, str, 8);
+ strncpy(ev.string, str, 8);
puglDispatchEvent(puglview, (const PuglEvent*)&ev);
}
@@ -464,7 +464,7 @@ handleCrossing(PuglOpenGLView* view, NSEvent* event, const PuglEventType type)
{ 0, 0, 0, 0, 0, 0, 0, 0 },
false,
};
- strncpy((char*)ev.utf8, str, 8);
+ strncpy(ev.string, str, 8);
puglDispatchEvent(puglview, (const PuglEvent*)&ev);
}
diff --git a/pugl/pugl_win.c b/pugl/pugl_win.c
index 9d5b124..c2ccff3 100644
--- a/pugl/pugl_win.c
+++ b/pugl/pugl_win.c
@@ -534,24 +534,24 @@ static void
wcharBufToEvent(wchar_t* buf, int n, PuglEvent* event)
{
if (n > 0) {
- char* charp = (char*)event->key.utf8;
+ char* charp = (char*)event->key.string;
if (!WideCharToMultiByte(CP_UTF8, 0, buf, n,
charp, 8, NULL, NULL)) {
/* error: could not convert to utf-8,
GetLastError has details */
- memset(event->key.utf8, 0, 8);
+ memset(event->key.string, 0, 8);
// replacement character
- event->key.utf8[0] = 0xEF;
- event->key.utf8[1] = 0xBF;
- event->key.utf8[2] = 0xBD;
+ event->key.string[0] = 0xEF;
+ event->key.string[1] = 0xBF;
+ event->key.string[2] = 0xBD;
}
event->key.character = utf16_to_code_point(buf, n);
} else {
// replacement character
- event->key.utf8[0] = 0xEF;
- event->key.utf8[1] = 0xBF;
- event->key.utf8[2] = 0xBD;
+ event->key.string[0] = 0xEF;
+ event->key.string[1] = 0xBF;
+ event->key.string[2] = 0xBD;
event->key.character = 0xFFFD;
}
}
diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c
index 59fb29c..d5e51b4 100644
--- a/pugl/pugl_x11.c
+++ b/pugl/pugl_x11.c
@@ -257,12 +257,11 @@ static void
translateKey(PuglView* view, XEvent* xevent, PuglEventKey* event)
{
KeySym sym = 0;
- char* str = (char*)event->utf8;
- memset(str, 0, 8);
+ memset(event->string, 0, 8);
event->filter = XFilterEvent(xevent, None);
if (xevent->type == KeyRelease || event->filter || !view->impl->xic) {
- if (XLookupString(&xevent->xkey, str, 7, &sym, NULL) == 1) {
- event->character = (uint8_t)str[0];
+ if (XLookupString(&xevent->xkey, event->string, 7, &sym, NULL) == 1) {
+ event->character = (uint8_t)event->string[0];
}
} else {
/* TODO: Not sure about this. On my system, some characters work with
@@ -271,13 +270,13 @@ translateKey(PuglView* view, XEvent* xevent, PuglEventKey* event)
Status status = 0;
#ifdef X_HAVE_UTF8_STRING
const int n = Xutf8LookupString(
- view->impl->xic, &xevent->xkey, str, 7, &sym, &status);
+ view->impl->xic, &xevent->xkey, event->string, 7, &sym, &status);
#else
const int n = XmbLookupString(
- view->impl->xic, &xevent->xkey, str, 7, &sym, &status);
+ view->impl->xic, &xevent->xkey, event->string, 7, &sym, &status);
#endif
if (n > 0) {
- event->character = puglDecodeUTF8((const uint8_t*)str);
+ event->character = puglDecodeUTF8((const uint8_t*)event->string);
}
}
event->special = keySymToSpecial(sym);
diff --git a/test/test_utils.h b/test/test_utils.h
index d92d53c..285cc83 100644
--- a/test/test_utils.h
+++ b/test/test_utils.h
@@ -104,13 +104,13 @@ printEvent(const PuglEvent* event, const char* prefix)
return fprintf(stderr, "%sKey %u (char U+%04X special U+%04X) press (%s)%s\n",
prefix,
event->key.keycode, event->key.character, event->key.special,
- event->key.utf8, event->key.filter ? " (filtered)" : "");
+ event->key.string, event->key.filter ? " (filtered)" : "");
case PUGL_KEY_RELEASE:
return fprintf(stderr, "%sKey %u (char U+%04X special U+%04X) release (%s)%s\n",
prefix,
event->key.keycode, event->key.character, event->key.special,
- event->key.utf8, event->key.filter ? " (filtered)" : "");
+ event->key.string, event->key.filter ? " (filtered)" : "");
case PUGL_BUTTON_PRESS:
case PUGL_BUTTON_RELEASE:
return (fprintf(stderr, "%sMouse %d %s at %f,%f ",