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