Line |
Branch |
Exec |
Source |
1 |
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2012 Red Hat, Inc. |
4 |
|
|
* |
5 |
|
|
* Written by: Ondrej Holy <oholy@redhat.com>, |
6 |
|
|
* Felipe Borges <felipeborges@gnome.org>, |
7 |
|
|
* |
8 |
|
|
* This program is free software; you can redistribute it and/or modify |
9 |
|
|
* it under the terms of the GNU General Public License as published by |
10 |
|
|
* the Free Software Foundation; either version 2, or (at your option) |
11 |
|
|
* any later version. |
12 |
|
|
* |
13 |
|
|
* This program is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* You should have received a copy of the GNU General Public License |
19 |
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include <config.h> |
23 |
|
|
|
24 |
|
|
#include <glib/gi18n.h> |
25 |
|
|
|
26 |
|
|
#include "cc-mouse-test.h" |
27 |
|
|
|
28 |
|
|
struct _CcMouseTest |
29 |
|
|
{ |
30 |
|
|
AdwWindow parent_instance; |
31 |
|
|
|
32 |
|
|
GtkWidget *arrow_down; |
33 |
|
|
GtkWidget *arrow_up; |
34 |
|
|
GtkWidget *primary_click_image; |
35 |
|
|
GtkWidget *secondary_click_image; |
36 |
|
|
GtkWidget *double_click_image; |
37 |
|
|
GtkWidget *image; |
38 |
|
|
GtkAdjustment *scrolled_window_adjustment; |
39 |
|
|
GtkWidget *viewport; |
40 |
|
|
|
41 |
|
|
gint double_click_delay; |
42 |
|
|
guint reset_timeout_id; |
43 |
|
|
guint primary_timeout_id; |
44 |
|
|
}; |
45 |
|
|
|
46 |
|
✗ |
G_DEFINE_TYPE (CcMouseTest, cc_mouse_test, ADW_TYPE_WINDOW); |
47 |
|
|
|
48 |
|
|
static void |
49 |
|
✗ |
on_scroll_adjustment_changed_cb (GtkAdjustment *adjustment, |
50 |
|
|
gpointer user_data) |
51 |
|
|
{ |
52 |
|
✗ |
CcMouseTest *self = CC_MOUSE_TEST (user_data); |
53 |
|
|
gboolean is_bottom, is_top; |
54 |
|
|
gdouble value; |
55 |
|
|
|
56 |
|
✗ |
value = gtk_adjustment_get_value (adjustment); |
57 |
|
✗ |
is_top = value == gtk_adjustment_get_lower (adjustment); |
58 |
|
✗ |
is_bottom = value == (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_page_size (adjustment)); |
59 |
|
|
|
60 |
|
✗ |
gtk_widget_set_visible (self->arrow_up, !is_top); |
61 |
|
✗ |
gtk_widget_set_visible (self->arrow_down, !is_bottom); |
62 |
|
✗ |
} |
63 |
|
|
|
64 |
|
|
static gboolean |
65 |
|
✗ |
reset_indicators (CcMouseTest *self) |
66 |
|
|
{ |
67 |
|
✗ |
g_clear_handle_id (&self->reset_timeout_id, g_source_remove); |
68 |
|
|
|
69 |
|
✗ |
gtk_widget_remove_css_class (self->primary_click_image, "success"); |
70 |
|
✗ |
gtk_widget_remove_css_class (self->secondary_click_image, "success"); |
71 |
|
✗ |
gtk_widget_remove_css_class (self->double_click_image, "success"); |
72 |
|
|
|
73 |
|
✗ |
return FALSE; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
static gboolean |
77 |
|
✗ |
primary_click_timeout (CcMouseTest *self) |
78 |
|
|
{ |
79 |
|
✗ |
g_clear_handle_id (&self->primary_timeout_id, g_source_remove); |
80 |
|
|
|
81 |
|
✗ |
gtk_widget_add_css_class (self->primary_click_image, "success"); |
82 |
|
|
|
83 |
|
✗ |
return FALSE; |
84 |
|
|
} |
85 |
|
|
|
86 |
|
|
static void |
87 |
|
✗ |
on_test_button_clicked_cb (GtkGestureClick *gesture, |
88 |
|
|
gint n_press, |
89 |
|
|
gdouble x, |
90 |
|
|
gdouble y, |
91 |
|
|
gpointer user_data) |
92 |
|
|
{ |
93 |
|
✗ |
CcMouseTest *self = CC_MOUSE_TEST (user_data); |
94 |
|
|
guint button; |
95 |
|
✗ |
guint reset_indicators_delay = self->double_click_delay * 2; |
96 |
|
|
|
97 |
|
✗ |
g_clear_handle_id (&self->reset_timeout_id, g_source_remove); |
98 |
|
✗ |
g_clear_handle_id (&self->primary_timeout_id, g_source_remove); |
99 |
|
|
|
100 |
|
✗ |
reset_indicators (self); |
101 |
|
|
|
102 |
|
✗ |
button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)); |
103 |
|
✗ |
if (button == 3) { |
104 |
|
✗ |
gtk_widget_add_css_class (self->secondary_click_image, "success"); |
105 |
|
✗ |
} else if (n_press == 2) { |
106 |
|
✗ |
gtk_widget_add_css_class (self->double_click_image, "success"); |
107 |
|
✗ |
} else if (n_press == 1) { |
108 |
|
✗ |
self->primary_timeout_id = |
109 |
|
✗ |
g_timeout_add (self->double_click_delay, (GSourceFunc) primary_click_timeout, self); |
110 |
|
✗ |
reset_indicators_delay = self->double_click_delay * 3; |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
/* Reset the buttons to default state after double_click_delay * 2 for double or secondary |
114 |
|
|
click, or double_click_delay * 3 for primary click to always indicate equally long. */ |
115 |
|
✗ |
self->reset_timeout_id = |
116 |
|
✗ |
g_timeout_add (reset_indicators_delay, (GSourceFunc) reset_indicators, self); |
117 |
|
✗ |
} |
118 |
|
|
|
119 |
|
|
static void |
120 |
|
✗ |
on_mouse_test_show_cb (CcMouseTest *self) |
121 |
|
|
{ |
122 |
|
|
/* Always scroll back to the top */ |
123 |
|
✗ |
gtk_adjustment_set_value (self->scrolled_window_adjustment, 0); |
124 |
|
✗ |
} |
125 |
|
|
|
126 |
|
|
static void |
127 |
|
✗ |
setup_dialog (CcMouseTest *self) |
128 |
|
|
{ |
129 |
|
✗ |
g_autoptr(GtkCssProvider) provider = NULL; |
130 |
|
|
|
131 |
|
✗ |
provider = gtk_css_provider_new (); |
132 |
|
✗ |
gtk_css_provider_load_from_resource (provider, "/org/gnome/control-center/mouse/mouse-test.css"); |
133 |
|
✗ |
gtk_style_context_add_provider_for_display (gdk_display_get_default (), |
134 |
|
✗ |
GTK_STYLE_PROVIDER (provider), |
135 |
|
|
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); |
136 |
|
✗ |
} |
137 |
|
|
|
138 |
|
|
static void |
139 |
|
✗ |
cc_mouse_test_finalize (GObject *object) |
140 |
|
|
{ |
141 |
|
✗ |
CcMouseTest *self = CC_MOUSE_TEST (object); |
142 |
|
|
|
143 |
|
✗ |
g_clear_handle_id (&self->reset_timeout_id, g_source_remove); |
144 |
|
✗ |
g_clear_handle_id (&self->primary_timeout_id, g_source_remove); |
145 |
|
|
|
146 |
|
✗ |
G_OBJECT_CLASS (cc_mouse_test_parent_class)->finalize (object); |
147 |
|
✗ |
} |
148 |
|
|
|
149 |
|
|
static void |
150 |
|
✗ |
cc_mouse_test_class_init (CcMouseTestClass *klass) |
151 |
|
|
{ |
152 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
153 |
|
✗ |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
154 |
|
|
|
155 |
|
✗ |
object_class->finalize = cc_mouse_test_finalize; |
156 |
|
|
|
157 |
|
✗ |
gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Escape, 0, "window.close", NULL); |
158 |
|
|
|
159 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/mouse/cc-mouse-test.ui"); |
160 |
|
|
|
161 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, arrow_down); |
162 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, arrow_up); |
163 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, primary_click_image); |
164 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, secondary_click_image); |
165 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, double_click_image); |
166 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, image); |
167 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, scrolled_window_adjustment); |
168 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, viewport); |
169 |
|
|
|
170 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, on_mouse_test_show_cb); |
171 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, on_scroll_adjustment_changed_cb); |
172 |
|
✗ |
gtk_widget_class_bind_template_callback (widget_class, on_test_button_clicked_cb); |
173 |
|
✗ |
} |
174 |
|
|
|
175 |
|
|
static void |
176 |
|
✗ |
cc_mouse_test_init (CcMouseTest *self) |
177 |
|
|
{ |
178 |
|
✗ |
g_autoptr(GSettings) mouse_settings = NULL; |
179 |
|
|
|
180 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
181 |
|
|
|
182 |
|
✗ |
mouse_settings = g_settings_new ("org.gnome.desktop.peripherals.mouse"); |
183 |
|
✗ |
self->double_click_delay = g_settings_get_int (mouse_settings, "double-click"); |
184 |
|
|
|
185 |
|
✗ |
setup_dialog (self); |
186 |
|
✗ |
} |
187 |
|
|
|
188 |
|
|
GtkWidget * |
189 |
|
✗ |
cc_mouse_test_new (void) |
190 |
|
|
{ |
191 |
|
✗ |
return (GtkWidget *) g_object_new (CC_TYPE_MOUSE_TEST, NULL); |
192 |
|
|
} |
193 |
|
|
|