1/* testinhibitshortcuts.c
2
3 Copyright (C) 2017 Red Hat
4 Author: Olivier Fourdan <ofourdan@redhat.com>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with this library. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <gtk/gtk.h>
21
22static void
23on_shortcuts_inhibit_change (GdkSurface *surface, GParamSpec *pspec, gpointer data)
24{
25 GtkWidget *button = GTK_WIDGET (data);
26 gboolean button_active;
27 gboolean shortcuts_inhibited;
28
29 g_object_get (object: GDK_TOPLEVEL (ptr: surface), first_property_name: "shortcuts-inhibited", &shortcuts_inhibited, NULL);
30
31 gtk_check_button_set_inconsistent (GTK_CHECK_BUTTON (button), FALSE);
32
33 button_active = gtk_check_button_get_active (GTK_CHECK_BUTTON (button));
34
35 if (button_active != shortcuts_inhibited)
36 gtk_check_button_set_active (GTK_CHECK_BUTTON (button), setting: shortcuts_inhibited);
37}
38
39static void
40on_button_toggle (GtkWidget *button, gpointer data)
41{
42 GdkSurface *surface = GDK_SURFACE (data);
43
44 if (!gtk_check_button_get_active (GTK_CHECK_BUTTON (button)))
45 {
46 gdk_toplevel_restore_system_shortcuts (toplevel: GDK_TOPLEVEL (ptr: surface));
47 return;
48 }
49
50 gtk_check_button_set_inconsistent (GTK_CHECK_BUTTON (button), TRUE);
51 gdk_toplevel_inhibit_system_shortcuts (toplevel: GDK_TOPLEVEL (ptr: surface), NULL);
52}
53
54static void
55quit_cb (GtkWidget *widget,
56 gpointer user_data)
57{
58 gboolean *done = user_data;
59
60 *done = TRUE;
61
62 g_main_context_wakeup (NULL);
63}
64
65int
66main (int argc, char *argv[])
67{
68 GdkSurface *surface;
69 GtkWidget *window;
70 GtkWidget *button;
71 GtkWidget *vbox;
72 GtkWidget *text_view;
73 gboolean done = FALSE;
74
75 gtk_init ();
76
77 window = gtk_window_new ();
78 g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
79 gtk_widget_realize (widget: window);
80 surface = gtk_native_get_surface (self: gtk_widget_get_native (widget: window));
81
82 vbox = gtk_box_new (orientation: GTK_ORIENTATION_VERTICAL, spacing: 2);
83 gtk_window_set_child (GTK_WINDOW (window), child: vbox);
84
85 text_view = gtk_text_view_new ();
86 gtk_widget_set_hexpand (widget: text_view, TRUE);
87 gtk_widget_set_vexpand (widget: text_view, TRUE);
88 gtk_box_append (GTK_BOX (vbox), child: text_view);
89
90 button = gtk_check_button_new_with_label (label: "Inhibit system keyboard shortcuts");
91
92 gtk_box_append (GTK_BOX (vbox), child: button);
93 g_signal_connect (G_OBJECT (button), "toggled",
94 G_CALLBACK (on_button_toggle), surface);
95
96 g_signal_connect (G_OBJECT (surface), "notify::shortcuts-inhibited",
97 G_CALLBACK (on_shortcuts_inhibit_change), button);
98
99 gtk_widget_show (widget: window);
100
101 while (!done)
102 g_main_context_iteration (NULL, TRUE);
103
104 return 0;
105}
106

source code of gtk/tests/testinhibitshortcuts.c