Commit a7e84dcf authored by Robert Ancell's avatar Robert Ancell Committed by Georges Basile Stavracas Neto

mouse: Use GtkTemplate

parent 02f0353f
Pipeline #13350 passed with stages
in 3 minutes and 7 seconds
......@@ -42,13 +42,30 @@
#include <sys/stat.h>
#include <dirent.h>
#define WID(x) (GtkWidget *) gtk_builder_get_object (self->builder, x)
struct _CcMouseProperties
{
GtkBin parent_instance;
GtkBuilder *builder;
GtkWidget *edge_scrolling_row;
GtkWidget *edge_scrolling_switch;
GtkWidget *general_listbox;
GtkWidget *mouse_frame;
GtkWidget *mouse_listbox;
GtkWidget *mouse_natural_scrolling_switch;
GtkWidget *mouse_speed_scale;
GtkWidget *primary_button_left;
GtkWidget *primary_button_right;
GtkWidget *scrolled_window;
GtkWidget *tap_to_click_row;
GtkWidget *tap_to_click_switch;
GtkWidget *touchpad_frame;
GtkWidget *touchpad_listbox;
GtkWidget *touchpad_natural_scrolling_switch;
GtkWidget *touchpad_options_listbox;
GtkWidget *touchpad_speed_scale;
GtkWidget *touchpad_toggle_switch;
GtkWidget *two_finger_scrolling_row;
GtkWidget *two_finger_scrolling_switch;
GSettings *mouse_settings;
GSettings *gsd_mouse_settings;
......@@ -81,34 +98,34 @@ setup_touchpad_options (CcMouseProperties *self)
gboolean have_edge_scrolling;
gboolean have_tap_to_click;
gtk_widget_set_visible (WID ("touchpad-frame"), !self->have_synaptics);
gtk_widget_set_visible (self->touchpad_frame, !self->have_synaptics);
if (self->have_synaptics)
return;
gtk_widget_set_visible (WID ("touchpad-frame"), self->have_touchpad);
gtk_widget_set_visible (self->touchpad_frame, self->have_touchpad);
if (!self->have_touchpad)
return;
cc_touchpad_check_capabilities (&have_two_finger_scrolling, &have_edge_scrolling, &have_tap_to_click);
gtk_widget_show_all (WID ("touchpad-frame"));
gtk_widget_show_all (self->touchpad_frame);
gtk_widget_set_visible (WID ("two-finger-scrolling-row"), have_two_finger_scrolling);
gtk_widget_set_visible (WID ("edge-scrolling-row"), have_edge_scrolling);
gtk_widget_set_visible (WID ("tap-to-click-row"), have_tap_to_click);
gtk_widget_set_visible (self->two_finger_scrolling_row, have_two_finger_scrolling);
gtk_widget_set_visible (self->edge_scrolling_row, have_edge_scrolling);
gtk_widget_set_visible (self->tap_to_click_row, have_tap_to_click);
edge_scroll_enabled = g_settings_get_boolean (self->touchpad_settings, "edge-scrolling-enabled");
two_finger_scroll_enabled = g_settings_get_boolean (self->touchpad_settings, "two-finger-scrolling-enabled");
if (edge_scroll_enabled && two_finger_scroll_enabled) {
/* You cunning user set both, but you can only have one set in that UI */
self->changing_scroll = TRUE;
gtk_switch_set_active (GTK_SWITCH (WID ("two-finger-scrolling-switch")), two_finger_scroll_enabled);
gtk_switch_set_active (GTK_SWITCH (self->two_finger_scrolling_switch), two_finger_scroll_enabled);
self->changing_scroll = FALSE;
gtk_switch_set_active (GTK_SWITCH (WID ("edge-scrolling-switch")), FALSE);
gtk_switch_set_active (GTK_SWITCH (self->edge_scrolling_switch), FALSE);
} else {
self->changing_scroll = TRUE;
gtk_switch_set_active (GTK_SWITCH (WID ("edge-scrolling-switch")), edge_scroll_enabled);
gtk_switch_set_active (GTK_SWITCH (WID ("two-finger-scrolling-switch")), two_finger_scroll_enabled);
gtk_switch_set_active (GTK_SWITCH (self->edge_scrolling_switch), edge_scroll_enabled);
gtk_switch_set_active (GTK_SWITCH (self->two_finger_scrolling_switch), two_finger_scroll_enabled);
self->changing_scroll = FALSE;
}
}
......@@ -126,9 +143,9 @@ two_finger_scrolling_changed_event (GtkSwitch *button,
g_settings_set_boolean (self->touchpad_settings, "two-finger-scrolling-enabled", state);
gtk_switch_set_state (button, state);
if (state && gtk_widget_get_visible (WID ("edge-scrolling-row"))) {
if (state && gtk_widget_get_visible (self->edge_scrolling_row)) {
/* Disable edge scrolling if two-finger scrolling is enabled */
gtk_switch_set_state (GTK_SWITCH (WID ("edge-scrolling-switch")), FALSE);
gtk_switch_set_state (GTK_SWITCH (self->edge_scrolling_switch), FALSE);
}
}
......@@ -145,9 +162,9 @@ edge_scrolling_changed_event (GtkSwitch *button,
g_settings_set_boolean (self->touchpad_settings, "edge-scrolling-enabled", state);
gtk_switch_set_state (button, state);
if (state && gtk_widget_get_visible (WID ("two-finger-scrolling-row"))) {
if (state && gtk_widget_get_visible (self->two_finger_scrolling_row)) {
/* Disable two-finger scrolling if edge scrolling is enabled */
gtk_switch_set_state (GTK_SWITCH (WID ("two-finger-scrolling-switch")), FALSE);
gtk_switch_set_state (GTK_SWITCH (self->two_finger_scrolling_switch), FALSE);
}
}
......@@ -227,77 +244,77 @@ setup_dialog (CcMouseProperties *self)
GtkWidget *button;
self->left_handed = g_settings_get_boolean (self->mouse_settings, "left-handed");
button = WID (self->left_handed ? "primary-button-right" : "primary-button-left");
button = self->left_handed ? self->primary_button_right : self->primary_button_left;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
g_settings_bind (self->mouse_settings, "left-handed",
WID ("primary-button-left"), "active",
self->primary_button_left, "active",
G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_INVERT_BOOLEAN);
g_settings_bind (self->mouse_settings, "left-handed",
WID ("primary-button-right"), "active",
self->primary_button_right, "active",
G_SETTINGS_BIND_DEFAULT);
/* Allow changing orientation with either button */
button = WID ("primary-button-right");
button = self->primary_button_right;
self->right_gesture = gtk_gesture_multi_press_new (button);
handle_secondary_button (self, button, self->right_gesture);
button = WID ("primary-button-left");
button = self->primary_button_left;
self->left_gesture = gtk_gesture_multi_press_new (button);
handle_secondary_button (self, button, self->left_gesture);
g_settings_bind (self->mouse_settings, "natural-scroll",
WID ("mouse-natural-scrolling-switch"), "active",
self->mouse_natural_scrolling_switch, "active",
G_SETTINGS_BIND_DEFAULT);
gtk_list_box_set_header_func (GTK_LIST_BOX (WID ("general-listbox")), cc_list_box_update_header_func, NULL, NULL);
gtk_list_box_set_header_func (GTK_LIST_BOX (WID ("touchpad-listbox")), cc_list_box_update_header_func, NULL, NULL);
gtk_list_box_set_header_func (GTK_LIST_BOX (self->general_listbox), cc_list_box_update_header_func, NULL, NULL);
gtk_list_box_set_header_func (GTK_LIST_BOX (self->touchpad_listbox), cc_list_box_update_header_func, NULL, NULL);
/* Mouse section */
gtk_widget_set_visible (WID ("mouse-frame"), self->have_mouse);
gtk_widget_set_visible (self->mouse_frame, self->have_mouse);
g_settings_bind (self->mouse_settings, "speed",
gtk_range_get_adjustment (GTK_RANGE (WID ("mouse-speed-scale"))), "value",
gtk_range_get_adjustment (GTK_RANGE (self->mouse_speed_scale)), "value",
G_SETTINGS_BIND_DEFAULT);
gtk_list_box_set_header_func (GTK_LIST_BOX (WID ("mouse-listbox")), cc_list_box_update_header_func, NULL, NULL);
gtk_list_box_set_header_func (GTK_LIST_BOX (self->mouse_listbox), cc_list_box_update_header_func, NULL, NULL);
/* Touchpad section */
gtk_widget_set_visible (WID ("touchpad-toggle-switch"),
gtk_widget_set_visible (self->touchpad_toggle_switch,
show_touchpad_enabling_switch (self));
g_settings_bind_with_mapping (self->touchpad_settings, "send-events",
WID ("touchpad-toggle-switch"), "active",
self->touchpad_toggle_switch, "active",
G_SETTINGS_BIND_DEFAULT,
touchpad_enabled_get_mapping,
touchpad_enabled_set_mapping,
NULL, NULL);
g_settings_bind_with_mapping (self->touchpad_settings, "send-events",
WID ("touchpad-options-listbox"), "sensitive",
self->touchpad_options_listbox, "sensitive",
G_SETTINGS_BIND_GET,
touchpad_enabled_get_mapping,
touchpad_enabled_set_mapping,
NULL, NULL);
g_settings_bind (self->touchpad_settings, "natural-scroll",
WID ("touchpad-natural-scrolling-switch"), "active",
self->touchpad_natural_scrolling_switch, "active",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (self->touchpad_settings, "speed",
gtk_range_get_adjustment (GTK_RANGE (WID ("touchpad-speed-scale"))), "value",
gtk_range_get_adjustment (GTK_RANGE (self->touchpad_speed_scale)), "value",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (self->touchpad_settings, "tap-to-click",
WID ("tap-to-click-switch"), "active",
self->tap_to_click_switch, "active",
G_SETTINGS_BIND_DEFAULT);
setup_touchpad_options (self);
g_signal_connect (WID ("edge-scrolling-switch"), "state-set",
g_signal_connect (self->edge_scrolling_switch, "state-set",
G_CALLBACK (edge_scrolling_changed_event), self);
g_signal_connect (WID ("two-finger-scrolling-switch"), "state-set",
g_signal_connect (self->two_finger_scrolling_switch, "state-set",
G_CALLBACK (two_finger_scrolling_changed_event), self);
gtk_list_box_set_header_func (GTK_LIST_BOX (WID ("touchpad-options-listbox")), cc_list_box_update_header_func, NULL, NULL);
gtk_list_box_set_header_func (GTK_LIST_BOX (self->touchpad_options_listbox), cc_list_box_update_header_func, NULL, NULL);
}
/* Callback issued when a button is clicked on the dialog */
......@@ -311,8 +328,8 @@ device_changed (GsdDeviceManager *device_manager,
setup_touchpad_options (self);
self->have_mouse = mouse_is_present ();
gtk_widget_set_visible (WID ("mouse-frame"), self->have_mouse);
gtk_widget_set_visible (WID ("touchpad-toggle-switch"),
gtk_widget_set_visible (self->mouse_frame, self->have_mouse);
gtk_widget_set_visible (self->touchpad_toggle_switch,
show_touchpad_enabling_switch (self));
}
......@@ -339,7 +356,6 @@ cc_mouse_properties_finalize (GObject *object)
g_clear_object (&self->mouse_settings);
g_clear_object (&self->gsd_mouse_settings);
g_clear_object (&self->touchpad_settings);
g_clear_object (&self->builder);
g_clear_object (&self->right_gesture);
g_clear_object (&self->left_gesture);
......@@ -355,12 +371,35 @@ cc_mouse_properties_finalize (GObject *object)
}
static void
cc_mouse_properties_class_init (CcMousePropertiesClass *class)
cc_mouse_properties_class_init (CcMousePropertiesClass *klass)
{
GObjectClass *object_class;
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class = G_OBJECT_CLASS (class);
object_class->finalize = cc_mouse_properties_finalize;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/mouse/gnome-mouse-properties.ui");
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, edge_scrolling_row);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, edge_scrolling_switch);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, general_listbox);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, mouse_frame);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, mouse_listbox);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, mouse_natural_scrolling_switch);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, mouse_speed_scale);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, primary_button_left);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, primary_button_right);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, scrolled_window);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, tap_to_click_row);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, tap_to_click_switch);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, touchpad_frame);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, touchpad_listbox);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, touchpad_natural_scrolling_switch);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, touchpad_options_listbox);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, touchpad_speed_scale);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, touchpad_toggle_switch);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, two_finger_scrolling_row);
gtk_widget_class_bind_template_child (widget_class, CcMouseProperties, two_finger_scrolling_switch);
}
static void
......@@ -368,10 +407,7 @@ cc_mouse_properties_init (CcMouseProperties *self)
{
g_autoptr(GError) error = NULL;
self->builder = gtk_builder_new ();
gtk_builder_add_from_resource (self->builder,
"/org/gnome/control-center/mouse/gnome-mouse-properties.ui",
&error);
gtk_widget_init_template (GTK_WIDGET (self));
self->mouse_settings = g_settings_new ("org.gnome.desktop.peripherals.mouse");
self->gsd_mouse_settings = g_settings_new ("org.gnome.settings-daemon.peripherals.mouse");
......@@ -392,11 +428,9 @@ cc_mouse_properties_init (CcMouseProperties *self)
self->changing_scroll = FALSE;
gtk_container_add (GTK_CONTAINER (self), WID ("scrolled-window"));
setup_dialog (self);
g_signal_connect (WID ("scrolled-window"), "size-allocate", G_CALLBACK (on_content_size_changed), NULL);
g_signal_connect (self->scrolled_window, "size-allocate", G_CALLBACK (on_content_size_changed), NULL);
}
GtkWidget *
......
This diff is collapsed.
......@@ -32,8 +32,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#define WID(x) (GtkWidget *) gtk_builder_get_object (self->builder, x)
/* Click test button sizes. */
#define SHADOW_SIZE (10.0 / 180 * size)
#define SHADOW_SHIFT_Y (-1.0 / 180 * size)
......@@ -59,7 +57,11 @@ struct _CcMouseTest
{
GtkBin parent_instance;
GtkBuilder *builder;
GtkWidget *button_drawing_area;
GtkWidget *information_label;
GtkWidget *image;
GtkWidget *scrolled_window_adjustment;
GtkWidget *viewport;
guint32 double_click_timestamp;
gint double_click_state;
......@@ -81,7 +83,7 @@ test_maybe_timeout (CcMouseTest *self)
{
self->double_click_state = DOUBLE_CLICK_TEST_OFF;
gtk_widget_queue_draw (WID ("button_drawing_area"));
gtk_widget_queue_draw (self->button_drawing_area);
self->button_drawing_area_timeout_id = 0;
......@@ -127,7 +129,7 @@ setup_information_label (CcMouseTest *self)
}
if (self->double_click_state == DOUBLE_CLICK_TEST_OFF) {
gtk_label_set_label (GTK_LABEL (WID ("information_label")), _("Try clicking, double clicking, scrolling"));
gtk_label_set_label (GTK_LABEL (self->information_label), _("Try clicking, double clicking, scrolling"));
return;
}
......@@ -149,7 +151,7 @@ setup_information_label (CcMouseTest *self)
}
label_text = g_strconcat ("<b>", message, "</b>", NULL);
gtk_label_set_markup (GTK_LABEL (WID ("information_label")), label_text);
gtk_label_set_markup (GTK_LABEL (self->information_label), label_text);
self->information_label_timeout_id = g_timeout_add (2500, (GSourceFunc) information_label_timeout, self);
}
......@@ -170,7 +172,7 @@ setup_scroll_image (CcMouseTest *self)
resource = "/org/gnome/control-center/mouse/scroll-test-gegl.svg";
else
resource = "/org/gnome/control-center/mouse/scroll-test.svg";
gtk_image_set_from_resource (GTK_IMAGE (WID ("image")), resource);
gtk_image_set_from_resource (GTK_IMAGE (self->image), resource);
if (self->double_click_state != DOUBLE_CLICK_TEST_GEGL)
return;
......@@ -224,7 +226,7 @@ button_drawing_area_button_press_event (GtkWidget *widget,
self->double_click_timestamp = event->time;
gtk_widget_queue_draw (WID ("button_drawing_area"));
gtk_widget_queue_draw (self->button_drawing_area);
self->button_state = event->button;
setup_information_label (self);
......@@ -297,23 +299,23 @@ setup_dialog (CcMouseTest *self)
GtkAdjustment *adjustment;
GtkStyleProvider *provider;
g_signal_connect (WID ("button_drawing_area"), "button_press_event",
g_signal_connect (self->button_drawing_area, "button_press_event",
G_CALLBACK (button_drawing_area_button_press_event),
self);
g_signal_connect (WID ("button_drawing_area"), "draw",
g_signal_connect (self->button_drawing_area, "draw",
G_CALLBACK (button_drawing_area_draw_event),
self);
adjustment = GTK_ADJUSTMENT (WID ("scrolled_window_adjustment"));
adjustment = GTK_ADJUSTMENT (self->scrolled_window_adjustment);
gtk_adjustment_set_value (adjustment,
gtk_adjustment_get_upper (adjustment));
provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (provider), "* {background: #565854}", -1, NULL);
gtk_style_context_add_provider (gtk_widget_get_style_context (WID ("viewport")),
gtk_style_context_add_provider (gtk_widget_get_style_context (self->viewport),
provider,
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
gtk_style_context_add_provider (gtk_widget_get_style_context (WID ("button_drawing_area")),
gtk_style_context_add_provider (gtk_widget_get_style_context (self->button_drawing_area),
provider,
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref (provider);
......@@ -325,7 +327,6 @@ cc_mouse_test_finalize (GObject *object)
CcMouseTest *self = CC_MOUSE_TEST (object);
g_clear_object (&self->mouse_settings);
g_clear_object (&self->builder);
if (self->information_label_timeout_id != 0) {
g_source_remove (self->information_label_timeout_id);
......@@ -346,12 +347,20 @@ cc_mouse_test_finalize (GObject *object)
}
static void
cc_mouse_test_class_init (CcMouseTestClass *class)
cc_mouse_test_class_init (CcMouseTestClass *klass)
{
GObjectClass *object_class;
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class = G_OBJECT_CLASS (class);
object_class->finalize = cc_mouse_test_finalize;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/mouse/gnome-mouse-test.ui");
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, button_drawing_area);
gtk_widget_class_bind_template_child (widget_class, CcMouseTest, information_label);
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);
}
static void
......@@ -359,10 +368,7 @@ cc_mouse_test_init (CcMouseTest *self)
{
g_autoptr(GError) error = NULL;
self->builder = gtk_builder_new ();
gtk_builder_add_from_resource (self->builder,
"/org/gnome/control-center/mouse/gnome-mouse-test.ui",
&error);
gtk_widget_init_template (GTK_WIDGET (self));
self->double_click_timestamp = 0;
self->double_click_state = DOUBLE_CLICK_TEST_OFF;
......@@ -374,8 +380,6 @@ cc_mouse_test_init (CcMouseTest *self)
self->button_drawing_area_timeout_id = 0;
self->scroll_image_timeout_id = 0;
gtk_container_add (GTK_CONTAINER (self), WID ("test_widget"));
setup_dialog (self);
}
......
......@@ -7,6 +7,8 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<template class="CcMouseTest" parent="GtkBin">
<child>
<object class="GtkGrid" id="test_widget">
<property name="visible">True</property>
<property name="can_focus">False</property>
......@@ -95,4 +97,6 @@
</packing>
</child>
</object>
</child>
</template>
</interface>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment