From ded81a2d4642d488c19fb3913e596c93eca2e2b8 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sun, 15 Nov 2009 19:17:04 +0000 Subject: [PATCH] Added helpers for accelerators --- include/Desktop/accel.h | 12 ++++++++++++ src/accel.c | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/Desktop/accel.h b/include/Desktop/accel.h index 5679777..c82d110 100644 --- a/include/Desktop/accel.h +++ b/include/Desktop/accel.h @@ -20,5 +20,17 @@ /* Accel */ +/* types */ +typedef struct _DesktopAccel +{ + GtkSignalFunc callback; + GdkModifierType modifier; + unsigned int accel; +} DesktopAccel; + + +/* functions */ +void desktop_accel_create(DesktopAccel * accel, gpointer data, + GtkAccelGroup * group); #endif /* !LIBDESKTOP_ACCEL_H */ diff --git a/src/accel.c b/src/accel.c index 820a6ed..fbff82d 100644 --- a/src/accel.c +++ b/src/accel.c @@ -19,3 +19,18 @@ /* Accel */ +void desktop_accel_create(DesktopAccel * accel, gpointer data, + GtkAccelGroup * group) +{ + size_t i; + GClosure * cc; + + if(group == NULL) + return; + for(i = 0; accel[i].callback != NULL; i++) + { + cc = g_cclosure_new_swap(accel[i].callback, data, NULL); + gtk_accel_group_connect(group, accel[i].accel, + accel[i].modifier, GTK_ACCEL_VISIBLE, cc); + } +}