[gnome-robots/arnaudb/wip/gtk4: 2/33] Use GtkEventControllerKey.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-robots/arnaudb/wip/gtk4: 2/33] Use GtkEventControllerKey.
- Date: Mon, 25 May 2020 20:26:15 +0000 (UTC)
commit 9d77ee34a5a24cebe9ca8fc868aa2ff4804dea7e
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sat May 23 21:07:20 2020 +0200
Use GtkEventControllerKey.
Bump Gtk required version to 3.24.
meson.build | 2 +-
src/game.c | 22 ++++++++++++++++++++--
src/keyboard.c | 22 ++++++++++++++--------
src/keyboard.h | 6 +++++-
4 files changed, 40 insertions(+), 12 deletions(-)
---
diff --git a/meson.build b/meson.build
index c76a34c..3e5cf64 100644
--- a/meson.build
+++ b/meson.build
@@ -11,7 +11,7 @@ gio_dependency = dependency('gio-2.0', version: '>= 2.32')
glib_dependency = dependency('glib-2.0', version: '>= 2.32')
gnome_games_dependency = dependency('libgnome-games-support-1')
gsound_dependency = dependency('gsound', version: '>= 1.0.2')
-gtk_dependency = dependency('gtk+-3.0', version: '>= 3.15.0')
+gtk_dependency = dependency('gtk+-3.0', version: '>= 3.24.0')
rsvg_dependency = dependency('librsvg-2.0', version: '>= 2.36.2')
pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
diff --git a/src/game.c b/src/game.c
index ab30ffe..b340ce8 100644
--- a/src/game.c
+++ b/src/game.c
@@ -78,6 +78,7 @@ static void update_arena (void);
static gint timeout_cb (void *data);
static void destroy_game_timer (void);
static void create_game_timer (void);
+void init_keyboard (void);
static void move_all_robots (void);
static void move_type2_robots (void);
static void move_robots (void);
@@ -542,6 +543,24 @@ create_game_timer (void)
}
+/**
+ * init_keyboard
+ *
+ * Description:
+ * Initialises the keyboard actions when the game first starts up
+ **/
+void
+init_keyboard (void)
+{
+ GtkEventController *key_controller;
+
+ key_controller = gtk_event_controller_key_new (window);
+
+ g_signal_connect (G_OBJECT (key_controller), "key-pressed",
+ G_CALLBACK (keyboard_cb), 0);
+}
+
+
/**
* init_game
*
@@ -553,8 +572,7 @@ init_game (void)
{
create_game_timer ();
- g_signal_connect (GTK_WIDGET (window), "key-press-event",
- G_CALLBACK (keyboard_cb), 0);
+ init_keyboard ();
start_new_game ();
}
diff --git a/src/keyboard.c b/src/keyboard.c
index dec6ed3..04aa968 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -65,9 +65,11 @@ keyboard_set (guint * keys)
/**
* keyboard_cb
- * @widget: widget
- * @event: event
- * @data: callback data
+ * @controller: key controller
+ * @keyval: pressed key value
+ * @keycode: pressed key code
+ * @state: modifiers state
+ * @user_data: callback data
*
* Description:
* handles keyboard events
@@ -75,19 +77,23 @@ keyboard_set (guint * keys)
* Returns:
* TRUE if the event is handled
**/
-gint
-keyboard_cb (GtkWidget * widget, GdkEventKey * event, gpointer data)
+gboolean
+keyboard_cb (GtkEventControllerKey *controller,
+ guint keyval,
+ guint keycode,
+ GdkModifierType state,
+ gpointer user_data)
{
- gint i, keyval;
+ gint i;
/* This is a bit of a kludge to let through accelerator keys, otherwise
* if N is used as a key, then Ctrl-N is never picked up. The cleaner
* option, making the signal a connect_after signal skims the arrow keys
* before we can get to them which is a bigger problem. */
- if (event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))
+ if (state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))
return FALSE;
- keyval = toupper (event->keyval);
+ keyval = toupper (keyval);
for (i = 0; i < 12; ++i) {
if (keyval == toupper (control_keys[i])) {
diff --git a/src/keyboard.h b/src/keyboard.h
index 7998225..da4893f 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -6,7 +6,11 @@
/* Exported functions */
/**********************************************************************/
void keyboard_set (guint *);
-gint keyboard_cb (GtkWidget *, GdkEventKey *, gpointer);
+gboolean keyboard_cb (GtkEventControllerKey *controller,
+ guint keyval,
+ guint keycode,
+ GdkModifierType state,
+ gpointer user_data);
/**********************************************************************/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]