aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-08-02 21:49:16 +0200
committerDavid Robillard <d@drobilla.net>2019-08-02 23:28:15 +0200
commit1c1e053d3403a6e03a00db8f3551f6a19302876b (patch)
treed17ecd6498434ef5d24a59e5416aa22d542e48b1
parent9f4a5e733b20f2de1619b46e0f7a36b3b5558f6e (diff)
Replace puglIgnoreKeyRepeat() with a hint
-rw-r--r--pugl/detail/implementation.c7
-rw-r--r--pugl/detail/mac.m2
-rw-r--r--pugl/detail/types.h2
-rw-r--r--pugl/detail/win.c2
-rw-r--r--pugl/detail/x11.c2
-rw-r--r--pugl/pugl.h5
-rw-r--r--test/pugl_cairo_test.c2
-rw-r--r--test/pugl_test.c2
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', ' ',