2012-08-20 19:24:03 +02:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Written by: Ondrej Holy <oholy@redhat.com>,
|
2023-01-05 13:30:37 +01:00
|
|
|
* Felipe Borges <felipeborges@gnome.org>,
|
2012-08-20 19:24:03 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-23 12:57:27 +01:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2012-08-20 19:24:03 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
2018-11-09 12:06:59 +13:00
|
|
|
#include "cc-mouse-test.h"
|
2012-08-20 19:24:03 +02:00
|
|
|
|
2018-05-28 12:02:48 +12:00
|
|
|
struct _CcMouseTest
|
2013-03-15 11:57:28 +01:00
|
|
|
{
|
2023-01-05 13:30:37 +01:00
|
|
|
AdwWindow parent_instance;
|
|
|
|
|
|
|
|
GtkWidget *arrow_down;
|
|
|
|
GtkWidget *arrow_up;
|
2023-12-20 12:59:07 +01:00
|
|
|
GtkWidget *primary_click_image;
|
|
|
|
GtkWidget *secondary_click_image;
|
|
|
|
GtkWidget *double_click_image;
|
2023-01-05 13:30:37 +01:00
|
|
|
GtkWidget *image;
|
|
|
|
GtkAdjustment *scrolled_window_adjustment;
|
|
|
|
GtkWidget *viewport;
|
|
|
|
|
2023-12-20 12:59:07 +01:00
|
|
|
gint double_click_delay;
|
|
|
|
guint reset_timeout_id;
|
|
|
|
guint primary_timeout_id;
|
2012-08-20 19:24:03 +02:00
|
|
|
};
|
|
|
|
|
2023-01-03 13:30:58 +01:00
|
|
|
G_DEFINE_TYPE (CcMouseTest, cc_mouse_test, ADW_TYPE_WINDOW);
|
2013-03-15 11:57:28 +01:00
|
|
|
|
2023-01-05 13:30:37 +01:00
|
|
|
static void
|
|
|
|
on_scroll_adjustment_changed_cb (GtkAdjustment *adjustment,
|
|
|
|
gpointer user_data)
|
2012-08-23 15:10:19 +02:00
|
|
|
{
|
2023-01-05 13:30:37 +01:00
|
|
|
CcMouseTest *self = CC_MOUSE_TEST (user_data);
|
|
|
|
gboolean is_bottom, is_top;
|
|
|
|
gdouble value;
|
2012-08-20 19:24:03 +02:00
|
|
|
|
2023-01-05 13:30:37 +01:00
|
|
|
value = gtk_adjustment_get_value (adjustment);
|
|
|
|
is_top = value == gtk_adjustment_get_lower (adjustment);
|
|
|
|
is_bottom = value == (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_page_size (adjustment));
|
2012-08-20 19:24:03 +02:00
|
|
|
|
2023-01-05 13:30:37 +01:00
|
|
|
gtk_widget_set_visible (self->arrow_up, !is_top);
|
|
|
|
gtk_widget_set_visible (self->arrow_down, !is_bottom);
|
2012-08-20 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:28:41 +02:00
|
|
|
static gboolean
|
2023-12-20 12:59:07 +01:00
|
|
|
reset_indicators (CcMouseTest *self)
|
2012-08-22 19:28:41 +02:00
|
|
|
{
|
2024-02-02 00:49:33 +01:00
|
|
|
g_clear_handle_id (&self->reset_timeout_id, g_source_remove);
|
2012-08-22 19:28:41 +02:00
|
|
|
|
2023-12-20 12:59:07 +01:00
|
|
|
gtk_widget_remove_css_class (self->primary_click_image, "success");
|
|
|
|
gtk_widget_remove_css_class (self->secondary_click_image, "success");
|
|
|
|
gtk_widget_remove_css_class (self->double_click_image, "success");
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
primary_click_timeout (CcMouseTest *self)
|
|
|
|
{
|
2024-02-02 00:49:33 +01:00
|
|
|
g_clear_handle_id (&self->primary_timeout_id, g_source_remove);
|
2023-12-20 12:59:07 +01:00
|
|
|
|
|
|
|
gtk_widget_add_css_class (self->primary_click_image, "success");
|
2012-08-22 19:28:41 +02:00
|
|
|
|
2023-01-05 13:30:37 +01:00
|
|
|
return FALSE;
|
2012-08-22 19:28:41 +02:00
|
|
|
}
|
|
|
|
|
2012-08-23 15:10:19 +02:00
|
|
|
static void
|
2023-01-05 13:30:37 +01:00
|
|
|
on_test_button_clicked_cb (GtkGestureClick *gesture,
|
|
|
|
gint n_press,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gpointer user_data)
|
2012-08-23 15:10:19 +02:00
|
|
|
{
|
2023-01-05 13:30:37 +01:00
|
|
|
CcMouseTest *self = CC_MOUSE_TEST (user_data);
|
2023-12-20 12:59:07 +01:00
|
|
|
guint button;
|
|
|
|
guint reset_indicators_delay = self->double_click_delay * 2;
|
|
|
|
|
2024-02-02 00:49:33 +01:00
|
|
|
g_clear_handle_id (&self->reset_timeout_id, g_source_remove);
|
|
|
|
g_clear_handle_id (&self->primary_timeout_id, g_source_remove);
|
2023-12-20 12:59:07 +01:00
|
|
|
|
|
|
|
reset_indicators (self);
|
|
|
|
|
|
|
|
button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
|
|
|
|
if (button == 3) {
|
|
|
|
gtk_widget_add_css_class (self->secondary_click_image, "success");
|
|
|
|
} else if (n_press == 2) {
|
|
|
|
gtk_widget_add_css_class (self->double_click_image, "success");
|
|
|
|
} else if (n_press == 1) {
|
|
|
|
self->primary_timeout_id =
|
|
|
|
g_timeout_add (self->double_click_delay, (GSourceFunc) primary_click_timeout, self);
|
|
|
|
reset_indicators_delay = self->double_click_delay * 3;
|
2023-01-05 13:30:37 +01:00
|
|
|
}
|
|
|
|
|
2023-12-20 12:59:07 +01:00
|
|
|
/* Reset the buttons to default state after double_click_delay * 2 for double or secondary
|
|
|
|
click, or double_click_delay * 3 for primary click to always indicate equally long. */
|
|
|
|
self->reset_timeout_id =
|
|
|
|
g_timeout_add (reset_indicators_delay, (GSourceFunc) reset_indicators, self);
|
2012-08-23 15:10:19 +02:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:28:41 +02:00
|
|
|
static void
|
2023-01-05 13:30:37 +01:00
|
|
|
on_mouse_test_show_cb (CcMouseTest *self)
|
2012-08-22 19:28:41 +02:00
|
|
|
{
|
2023-01-05 13:30:37 +01:00
|
|
|
/* Always scroll back to the top */
|
|
|
|
gtk_adjustment_set_value (self->scrolled_window_adjustment, 0);
|
2012-08-20 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-05-28 12:02:48 +12:00
|
|
|
setup_dialog (CcMouseTest *self)
|
2012-08-20 19:24:03 +02:00
|
|
|
{
|
2023-01-05 13:30:37 +01:00
|
|
|
g_autoptr(GtkCssProvider) provider = NULL;
|
|
|
|
|
|
|
|
provider = gtk_css_provider_new ();
|
|
|
|
gtk_css_provider_load_from_resource (provider, "/org/gnome/control-center/mouse/mouse-test.css");
|
|
|
|
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
|
|
|
|
GTK_STYLE_PROVIDER (provider),
|
|
|
|
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
2012-08-20 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
2013-03-15 11:57:28 +01:00
|
|
|
static void
|
|
|
|
cc_mouse_test_finalize (GObject *object)
|
2012-08-20 19:24:03 +02:00
|
|
|
{
|
2023-01-05 13:30:37 +01:00
|
|
|
CcMouseTest *self = CC_MOUSE_TEST (object);
|
2013-03-15 11:57:28 +01:00
|
|
|
|
2024-02-02 00:49:33 +01:00
|
|
|
g_clear_handle_id (&self->reset_timeout_id, g_source_remove);
|
|
|
|
g_clear_handle_id (&self->primary_timeout_id, g_source_remove);
|
2012-08-20 19:24:03 +02:00
|
|
|
|
2023-01-05 13:30:37 +01:00
|
|
|
G_OBJECT_CLASS (cc_mouse_test_parent_class)->finalize (object);
|
2012-08-20 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
2013-03-15 11:57:28 +01:00
|
|
|
static void
|
2018-05-28 12:40:11 +12:00
|
|
|
cc_mouse_test_class_init (CcMouseTestClass *klass)
|
2012-08-20 19:24:03 +02:00
|
|
|
{
|
2023-01-05 13:30:37 +01:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2012-08-23 15:10:19 +02:00
|
|
|
|
2023-01-05 13:30:37 +01:00
|
|
|
object_class->finalize = cc_mouse_test_finalize;
|
2018-05-28 12:40:11 +12:00
|
|
|
|
2023-05-24 14:44:57 +02:00
|
|
|
gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Escape, 0, "window.close", NULL);
|
|
|
|
|
2023-01-05 13:30:37 +01:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/mouse/cc-mouse-test.ui");
|
2018-05-28 12:40:11 +12:00
|
|
|
|
2023-01-05 13:30:37 +01:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, arrow_down);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, arrow_up);
|
2023-12-20 12:59:07 +01:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, primary_click_image);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, secondary_click_image);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, double_click_image);
|
2023-01-05 13:30:37 +01:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, image);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, scrolled_window_adjustment);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, viewport);
|
2018-05-30 09:12:11 +12:00
|
|
|
|
2023-01-05 13:30:37 +01:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_mouse_test_show_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_scroll_adjustment_changed_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_test_button_clicked_cb);
|
2013-03-15 11:57:28 +01:00
|
|
|
}
|
2012-08-22 19:28:41 +02:00
|
|
|
|
2013-03-15 11:57:28 +01:00
|
|
|
static void
|
2018-05-28 12:02:48 +12:00
|
|
|
cc_mouse_test_init (CcMouseTest *self)
|
2013-03-15 11:57:28 +01:00
|
|
|
{
|
2023-12-20 12:59:07 +01:00
|
|
|
g_autoptr(GSettings) mouse_settings = NULL;
|
|
|
|
|
2023-01-05 13:30:37 +01:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (self));
|
2013-03-15 11:57:28 +01:00
|
|
|
|
2023-12-20 12:59:07 +01:00
|
|
|
mouse_settings = g_settings_new ("org.gnome.desktop.peripherals.mouse");
|
|
|
|
self->double_click_delay = g_settings_get_int (mouse_settings, "double-click");
|
2013-03-15 11:57:28 +01:00
|
|
|
|
2023-01-05 13:30:37 +01:00
|
|
|
setup_dialog (self);
|
2012-08-20 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
2013-03-15 11:57:28 +01:00
|
|
|
GtkWidget *
|
|
|
|
cc_mouse_test_new (void)
|
|
|
|
{
|
2023-01-05 13:30:37 +01:00
|
|
|
return (GtkWidget *) g_object_new (CC_TYPE_MOUSE_TEST, NULL);
|
2013-03-15 11:57:28 +01:00
|
|
|
}
|