[gnome-software] Add a utility function for focus grabbing
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Add a utility function for focus grabbing
- Date: Sat, 31 Aug 2013 22:33:47 +0000 (UTC)
commit bbe92f8d795a9e6c7283899c1c3792cc622c73ef
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Aug 31 18:31:30 2013 -0400
Add a utility function for focus grabbing
Grabbing focus to a widget is a little tricky, since it
must be mapped for that to work. Add a utility function
that waits for that to happen.
src/gs-utils.c | 16 ++++++++++++++++
src/gs-utils.h | 1 +
2 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-utils.c b/src/gs-utils.c
index 613ea7a..052bce4 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -95,3 +95,19 @@ gs_container_remove_all (GtkContainer *container)
gtk_container_foreach (container, remove_all_cb, container);
}
+static void
+grab_focus (GtkWidget *widget)
+{
+ g_signal_handlers_disconnect_by_func (widget, grab_focus, NULL);
+ gtk_widget_grab_focus (widget);
+}
+
+void
+gs_grab_focus_when_mapped (GtkWidget *widget)
+{
+ if (gtk_widget_get_mapped (widget))
+ gtk_widget_grab_focus (widget);
+ else
+ g_signal_connect_after (widget, "map",
+ G_CALLBACK (grab_focus), NULL);
+}
diff --git a/src/gs-utils.h b/src/gs-utils.h
index 0ebf5a1..c60e9a9 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -29,6 +29,7 @@ G_BEGIN_DECLS
void gs_start_spinner (GtkSpinner *spinner);
void gs_stop_spinner (GtkSpinner *spinner);
void gs_container_remove_all (GtkContainer *container);
+void gs_grab_focus_when_mapped (GtkWidget *widget);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]