239 lines
8.1 KiB
C
239 lines
8.1 KiB
C
/*
|
|
* Copyright (C) 2007 Gerd Kohlberger
|
|
*
|
|
* 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 of the License, 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
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <gtk/gtk.h>
|
|
#include <glib/gi18n.h>
|
|
#include <gsettings-desktop-schemas/gdesktop-enums.h>
|
|
|
|
#include "gnome-mouse-accessibility.h"
|
|
|
|
/* 5th entry in combo box */
|
|
#define DIRECTION_DISABLE 4
|
|
|
|
#define WID(x) (GtkWidget*) gtk_builder_get_object (dialog, x)
|
|
|
|
enum {
|
|
CLICK_TYPE_SINGLE,
|
|
CLICK_TYPE_DOUBLE,
|
|
CLICK_TYPE_DRAG,
|
|
CLICK_TYPE_SECONDARY,
|
|
N_CLICK_TYPES
|
|
};
|
|
|
|
GSettings *a11y_mouse_settings = NULL;
|
|
|
|
static void
|
|
update_mode_sensitivity (GtkBuilder *dialog, gint mode)
|
|
{
|
|
gtk_widget_set_sensitive (WID ("box_ctw"), !mode);
|
|
gtk_widget_set_sensitive (WID ("box_gesture"), mode);
|
|
}
|
|
|
|
/* check if a direction (gesture mode) is already in use */
|
|
static gboolean
|
|
verify_setting (gint value, gint type)
|
|
{
|
|
gint i, ct[N_CLICK_TYPES];
|
|
|
|
ct[CLICK_TYPE_SINGLE] = g_settings_get_enum (a11y_mouse_settings, "dwell-gesture-single");
|
|
ct[CLICK_TYPE_DOUBLE] = g_settings_get_enum (a11y_mouse_settings, "dwell-gesture-double");
|
|
ct[CLICK_TYPE_DRAG] = g_settings_get_enum (a11y_mouse_settings, "dwell-gesture-drag");
|
|
ct[CLICK_TYPE_SECONDARY] = g_settings_get_enum (a11y_mouse_settings, "dwell-gesture-secondary");
|
|
|
|
for (i = 0; i < N_CLICK_TYPES; ++i) {
|
|
if (i == type)
|
|
continue;
|
|
if (ct[i] == value)
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
static void
|
|
populate_gesture_combo (GtkWidget *combo)
|
|
{
|
|
GtkListStore *model;
|
|
GtkTreeIter iter;
|
|
GtkCellRenderer *cr;
|
|
|
|
model = gtk_list_store_new (1, G_TYPE_STRING);
|
|
|
|
gtk_list_store_append (model, &iter);
|
|
/* Translators: this is the gesture to trigger/choose the click type.
|
|
Don't include the prefix "gesture|" in the translation. */
|
|
gtk_list_store_set (model, &iter, 0, Q_("gesture|Move left"), -1);
|
|
|
|
gtk_list_store_append (model, &iter);
|
|
/* Translators: this is the gesture to trigger/choose the click type.
|
|
Don't include the prefix "gesture|" in the translation. */
|
|
gtk_list_store_set (model, &iter, 0, Q_("gesture|Move right"), -1);
|
|
|
|
gtk_list_store_append (model, &iter);
|
|
/* Translators: this is the gesture to trigger/choose the click type.
|
|
Don't include the prefix "gesture|" in the translation. */
|
|
gtk_list_store_set (model, &iter, 0, Q_("gesture|Move up"), -1);
|
|
|
|
gtk_list_store_append (model, &iter);
|
|
/* Translators: this is the gesture to trigger/choose the click type.
|
|
Don't include the prefix "gesture|" in the translation. */
|
|
gtk_list_store_set (model, &iter, 0, Q_("gesture|Move down"), -1);
|
|
|
|
gtk_list_store_append (model, &iter);
|
|
/* Translators: this is the gesture to trigger/choose the click type.
|
|
Don't include the prefix "gesture|" in the translation. */
|
|
gtk_list_store_set (model, &iter, 0, Q_("gesture|Disabled"), -1);
|
|
|
|
gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (model));
|
|
|
|
cr = gtk_cell_renderer_text_new ();
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cr, TRUE);
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cr,
|
|
"text", 0,
|
|
NULL);
|
|
}
|
|
|
|
static void
|
|
delay_enable_toggled_cb (GtkWidget *checkbox, GtkBuilder *dialog)
|
|
{
|
|
gtk_widget_set_sensitive (WID ("delay_box"),
|
|
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox)));
|
|
}
|
|
|
|
static void
|
|
dwell_enable_toggled_cb (GtkWidget *checkbox, GtkBuilder *dialog)
|
|
{
|
|
gtk_widget_set_sensitive (WID ("dwell_box"),
|
|
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox)));
|
|
}
|
|
|
|
static void
|
|
dwell_mode_toggled_cb (GtkWidget *checkbox, GtkBuilder *dialog)
|
|
{
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (WID ("dwell_mode_ctw"))))
|
|
g_settings_set_enum (a11y_mouse_settings, "dwell-mode", G_DESKTOP_MOUSE_DWELL_MODE_WINDOW);
|
|
else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (WID ("dwell_mode_gesture"))))
|
|
g_settings_set_enum (a11y_mouse_settings, "dwell-mode", G_DESKTOP_MOUSE_DWELL_MODE_GESTURE);
|
|
}
|
|
|
|
static void
|
|
gesture_single (GtkComboBox *combo, gpointer data)
|
|
{
|
|
if (!verify_setting (gtk_combo_box_get_active (combo), CLICK_TYPE_SINGLE))
|
|
gtk_combo_box_set_active (combo, DIRECTION_DISABLE);
|
|
}
|
|
|
|
static void
|
|
gesture_double (GtkComboBox *combo, gpointer data)
|
|
{
|
|
if (!verify_setting (gtk_combo_box_get_active (combo), CLICK_TYPE_DOUBLE))
|
|
gtk_combo_box_set_active (combo, DIRECTION_DISABLE);
|
|
}
|
|
|
|
static void
|
|
gesture_drag (GtkComboBox *combo, gpointer data)
|
|
{
|
|
if (!verify_setting (gtk_combo_box_get_active (combo), CLICK_TYPE_DRAG))
|
|
gtk_combo_box_set_active (combo, DIRECTION_DISABLE);
|
|
}
|
|
|
|
static void
|
|
gesture_secondary (GtkComboBox *combo, gpointer data)
|
|
{
|
|
if (!verify_setting (gtk_combo_box_get_active (combo), CLICK_TYPE_SECONDARY))
|
|
gtk_combo_box_set_active (combo, DIRECTION_DISABLE);
|
|
}
|
|
|
|
static void
|
|
settings_changed (GSettings *settings,
|
|
const gchar *key,
|
|
gpointer dialog)
|
|
{
|
|
if (g_str_equal (key, "dwell-mode"))
|
|
update_mode_sensitivity (dialog, g_settings_get_enum (settings, key));
|
|
}
|
|
|
|
void
|
|
setup_accessibility (GtkBuilder *dialog)
|
|
{
|
|
a11y_mouse_settings = g_settings_new ("org.gnome.desktop.a11y.mouse");
|
|
g_signal_connect (a11y_mouse_settings, "changed",
|
|
G_CALLBACK (settings_changed), dialog);
|
|
|
|
g_settings_bind (a11y_mouse_settings, "dwell-click-enabled",
|
|
WID ("dwell_enable"), "active",
|
|
G_SETTINGS_BIND_DEFAULT);
|
|
g_settings_bind (a11y_mouse_settings, "click-type-window-visible",
|
|
WID ("dwell_show_ctw"), "active",
|
|
G_SETTINGS_BIND_DEFAULT);
|
|
|
|
g_settings_bind (a11y_mouse_settings, "secondary-click-enabled",
|
|
WID ("delay_enable"), "active",
|
|
G_SETTINGS_BIND_DEFAULT);
|
|
g_settings_bind (a11y_mouse_settings, "secondary-click-time",
|
|
WID ("delay_time"), "text",
|
|
G_SETTINGS_BIND_DEFAULT);
|
|
|
|
g_settings_bind (a11y_mouse_settings, "dwell-time",
|
|
gtk_range_get_adjustment (GTK_RANGE (WID ("dwell_time"))), "value",
|
|
G_SETTINGS_BIND_DEFAULT);
|
|
g_settings_bind (a11y_mouse_settings, "dwell-threshold",
|
|
gtk_range_get_adjustment (GTK_RANGE (WID ("threshold"))), "value",
|
|
G_SETTINGS_BIND_DEFAULT);
|
|
|
|
g_signal_connect (WID ("dwell_mode_ctw"), "toggled",
|
|
G_CALLBACK (dwell_mode_toggled_cb), dialog);
|
|
g_signal_connect (WID ("dwell_mode_gesture"), "toggled",
|
|
G_CALLBACK (dwell_mode_toggled_cb), dialog);
|
|
update_mode_sensitivity (dialog,
|
|
g_settings_get_enum (a11y_mouse_settings, "dwell-mode"));
|
|
|
|
populate_gesture_combo (WID ("dwell_gest_single"));
|
|
g_settings_bind (a11y_mouse_settings, "dwell-gesture-single",
|
|
WID ("dwell_gest_single"), "active",
|
|
G_SETTINGS_BIND_DEFAULT);
|
|
g_signal_connect (WID ("dwell_gest_single"), "changed",
|
|
G_CALLBACK (gesture_single), dialog);
|
|
|
|
populate_gesture_combo (WID ("dwell_gest_double"));
|
|
g_settings_bind (a11y_mouse_settings, "dwell-gesture-double",
|
|
WID ("dwell_gest_double"), "active",
|
|
G_SETTINGS_BIND_DEFAULT);
|
|
g_signal_connect (WID ("dwell_gest_double"), "changed",
|
|
G_CALLBACK (gesture_double), dialog);
|
|
|
|
populate_gesture_combo (WID ("dwell_gest_drag"));
|
|
g_settings_bind (a11y_mouse_settings, "dwell-gesture-drag",
|
|
WID ("dwell_gest_drag"), "active",
|
|
G_SETTINGS_BIND_DEFAULT);
|
|
g_signal_connect (WID ("dwell_gest_drag"), "changed",
|
|
G_CALLBACK (gesture_drag), dialog);
|
|
|
|
populate_gesture_combo (WID ("dwell_gest_secondary"));
|
|
g_settings_bind (a11y_mouse_settings, "dwell-gesture-secondary",
|
|
WID ("dwell_gest_secondary"), "active",
|
|
G_SETTINGS_BIND_DEFAULT);
|
|
g_signal_connect (WID ("dwell_gest_secondary"), "changed",
|
|
G_CALLBACK (gesture_secondary), dialog);
|
|
|
|
g_signal_connect (WID ("delay_enable"), "toggled",
|
|
G_CALLBACK (delay_enable_toggled_cb), dialog);
|
|
delay_enable_toggled_cb (WID ("delay_enable"), dialog);
|
|
g_signal_connect (WID ("dwell_enable"), "toggled",
|
|
G_CALLBACK (dwell_enable_toggled_cb), dialog);
|
|
dwell_enable_toggled_cb (WID ("dwell_enable"), dialog);
|
|
}
|