From 1c1e053d3403a6e03a00db8f3551f6a19302876b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 2 Aug 2019 21:49:16 +0200 Subject: Replace puglIgnoreKeyRepeat() with a hint --- pugl/detail/implementation.c | 7 +++++-- pugl/detail/mac.m | 2 +- pugl/detail/types.h | 2 +- pugl/detail/win.c | 2 +- pugl/detail/x11.c | 2 +- pugl/pugl.h | 5 ++++- test/pugl_cairo_test.c | 2 +- test/pugl_test.c | 2 +- 8 files changed, 15 insertions(+), 9 deletions(-) diff --git a/pugl/detail/implementation.c b/pugl/detail/implementation.c index 45e21c5..7eeba01 100644 --- a/pugl/detail/implementation.c +++ b/pugl/detail/implementation.c @@ -29,7 +29,7 @@ static PuglHints puglDefaultHints(void) { static const PuglHints hints = { - 2, 0, 4, 4, 4, 4, 24, 8, 0, true, true, false + 2, 0, 4, 4, 4, 4, 24, 8, 0, true, true, false, false }; return hints; } @@ -97,6 +97,9 @@ puglInitWindowHint(PuglView* view, PuglWindowHint hint, int value) case PUGL_RESIZABLE: view->hints.resizable = value; break; + case PUGL_IGNORE_KEY_REPEAT: + view->hints.ignoreKeyRepeat = value; + break; } } @@ -208,7 +211,7 @@ puglLeaveContext(PuglView* view, bool drawing) void puglIgnoreKeyRepeat(PuglView* view, bool ignore) { - view->ignoreKeyRepeat = ignore; + puglInitWindowHint(view, PUGL_IGNORE_KEY_REPEAT, ignore); } void diff --git a/pugl/detail/mac.m b/pugl/detail/mac.m index ce82d78..e3568f5 100644 --- a/pugl/detail/mac.m +++ b/pugl/detail/mac.m @@ -330,7 +330,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type) - (void) keyDown:(NSEvent*)event { - if (puglview->ignoreKeyRepeat && [event isARepeat]) { + if (puglview->hints.ignoreKeyRepeat && [event isARepeat]) { return; } diff --git a/pugl/detail/types.h b/pugl/detail/types.h index 0cf9a99..60f7682 100644 --- a/pugl/detail/types.h +++ b/pugl/detail/types.h @@ -52,6 +52,7 @@ typedef struct { int double_buffer; bool use_compat_profile; bool resizable; + bool ignoreKeyRepeat; } PuglHints; /** Cross-platform view definition. */ @@ -73,7 +74,6 @@ struct PuglViewImpl { int min_aspect_y; int max_aspect_x; int max_aspect_y; - bool ignoreKeyRepeat; bool visible; }; diff --git a/pugl/detail/win.c b/pugl/detail/win.c index 6e176b6..5922769 100644 --- a/pugl/detail/win.c +++ b/pugl/detail/win.c @@ -360,7 +360,7 @@ initCharEvent(PuglEvent* event, PuglView* view, WPARAM wParam, LPARAM lParam) static bool ignoreKeyEvent(PuglView* view, LPARAM lParam) { - return view->ignoreKeyRepeat && (lParam & (1 << 30)); + return view->hints.ignoreKeyRepeat && (lParam & (1 << 30)); } static RECT diff --git a/pugl/detail/x11.c b/pugl/detail/x11.c index 32f1393..d014b2e 100644 --- a/pugl/detail/x11.c +++ b/pugl/detail/x11.c @@ -506,7 +506,7 @@ puglProcessEvents(PuglView* view) XNextEvent(impl->display, &xevent); if (xevent.type == KeyRelease) { // Ignore key repeat if necessary - if (view->ignoreKeyRepeat && + if (view->hints.ignoreKeyRepeat && XEventsQueued(impl->display, QueuedAfterReading)) { XEvent next; XPeekEvent(impl->display, &next); diff --git a/pugl/pugl.h b/pugl/pugl.h index 850fe62..d04f1aa 100644 --- a/pugl/pugl.h +++ b/pugl/pugl.h @@ -109,6 +109,7 @@ typedef enum { PUGL_SAMPLES, /**< Number of samples per pixel (AA) */ PUGL_DOUBLE_BUFFER, /**< True if double buffering should be used */ PUGL_RESIZABLE, /**< True if window should be resizable */ + PUGL_IGNORE_KEY_REPEAT, /**< True if key repeat events are ignored */ } PuglWindowHint; /** @@ -631,8 +632,10 @@ puglSetEventFunc(PuglView* view, PuglEventFunc eventFunc); /** Ignore synthetic repeated key events. + + @deprecated Use puglInitWindowHint() with @ref PUGL_IGNORE_KEY_REPEAT. */ -PUGL_API void +PUGL_API PUGL_DEPRECATED_BY("puglInitWindowHint") void puglIgnoreKeyRepeat(PuglView* view, bool ignore); /** diff --git a/test/pugl_cairo_test.c b/test/pugl_cairo_test.c index d3b157e..a16c821 100644 --- a/test/pugl_cairo_test.c +++ b/test/pugl_cairo_test.c @@ -209,7 +209,7 @@ main(int argc, char** argv) puglInitWindowHint(view, PUGL_RESIZABLE, resizable); puglInitBackend(view, puglCairoBackend()); - puglIgnoreKeyRepeat(view, ignoreKeyRepeat); + puglInitWindowHint(view, PUGL_IGNORE_KEY_REPEAT, ignoreKeyRepeat); puglSetEventFunc(view, onEvent); if (puglCreateWindow(view, "Pugl Test")) { diff --git a/test/pugl_test.c b/test/pugl_test.c index 7c8d5f2..3c4612e 100644 --- a/test/pugl_test.c +++ b/test/pugl_test.c @@ -180,7 +180,7 @@ main(int argc, char** argv) puglInitWindowHint(view, PUGL_SAMPLES, samples); puglInitWindowHint(view, PUGL_DOUBLE_BUFFER, doubleBuffer); - puglIgnoreKeyRepeat(view, ignoreKeyRepeat); + puglInitWindowHint(view, PUGL_IGNORE_KEY_REPEAT, ignoreKeyRepeat); puglSetEventFunc(view, onEvent); const uint8_t title[] = { 'P', 'u', 'g', 'l', ' ', -- cgit v1.2.1