[gnome-control-center] wacom: add different action types to mapping dialog
- From: Olivier Fourdan <ofourdan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] wacom: add different action types to mapping dialog
- Date: Tue, 21 Aug 2012 16:08:59 +0000 (UTC)
commit a2e515ea39e136ed19c52e3572da64f5dc6944a7
Author: Olivier Fourdan <ofourdan redhat com>
Date: Tue Jun 26 11:06:07 2012 +0200
wacom: add different action types to mapping dialog
https://bugzilla.gnome.org/show_bug.cgi?id=679067
panels/wacom/cc-wacom-mapping-panel.c | 4 +-
panels/wacom/cc-wacom-page.c | 181 +++++++++++++++++++++++++++++++--
2 files changed, 172 insertions(+), 13 deletions(-)
---
diff --git a/panels/wacom/cc-wacom-mapping-panel.c b/panels/wacom/cc-wacom-mapping-panel.c
index 97f2d9e..e8654a8 100644
--- a/panels/wacom/cc-wacom-mapping-panel.c
+++ b/panels/wacom/cc-wacom-mapping-panel.c
@@ -109,7 +109,7 @@ update_monitor_chooser (CcWacomMappingPanel *self)
settings = gsd_wacom_device_get_settings (self->priv->device);
monitor = gsd_wacom_device_get_display_monitor (self->priv->device);
- single_mon = (monitor != -1);
+ single_mon = (monitor != GSD_WACOM_SET_ALL_MONITORS);
g_signal_handlers_block_by_func (G_OBJECT (self->priv->checkbutton), checkbutton_toggled_cb, self);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(self->priv->checkbutton), single_mon);
@@ -182,7 +182,7 @@ update_ui (CcWacomMappingPanel *self)
static void
update_mapping (CcWacomMappingPanel *self)
{
- int monitor = -1;
+ int monitor = GSD_WACOM_SET_ALL_MONITORS;
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->checkbutton))) {
GtkTreeIter iter;
diff --git a/panels/wacom/cc-wacom-page.c b/panels/wacom/cc-wacom-page.c
index ae84e1c..1d40c46 100644
--- a/panels/wacom/cc-wacom-page.c
+++ b/panels/wacom/cc-wacom-page.c
@@ -52,11 +52,18 @@ G_DEFINE_TYPE (CcWacomPage, cc_wacom_page, GTK_TYPE_BOX)
enum {
MAPPING_DESCRIPTION_COLUMN,
+ MAPPING_TYPE_COLUMN,
MAPPING_BUTTON_COLUMN,
MAPPING_BUTTON_DIRECTION,
MAPPING_N_COLUMNS
};
+enum {
+ ACTION_NAME_COLUMN,
+ ACTION_TYPE_COLUMN,
+ ACTION_N_COLUMNS
+};
+
struct _CcWacomPagePrivate
{
CcWacomPanel *panel;
@@ -70,6 +77,7 @@ struct _CcWacomPagePrivate
/* Button mapping */
GtkBuilder *mapping_builder;
GtkWidget *button_map;
+ GtkListStore *action_store;
/* Display mapping */
GtkWidget *mapping;
@@ -103,6 +111,15 @@ enum {
LAYOUT_SCREEN /* button mapping, calibration, display resolution */
};
+static struct {
+ GsdWacomActionType action_type;
+ const gchar *action_name;
+} action_table[] = {
+ { GSD_WACOM_ACTION_TYPE_NONE, N_("None") },
+ { GSD_WACOM_ACTION_TYPE_CUSTOM, N_("Send Keystroke") },
+ { GSD_WACOM_ACTION_TYPE_SWITCH_MONITOR, N_("Switch Monitor") }
+};
+
static void
update_tablet_ui (CcWacomPage *page,
int layout);
@@ -314,7 +331,7 @@ accel_set_func (GtkTreeViewColumn *tree_column,
"accel-key", 0,
"accel-mods", 0,
"style", PANGO_STYLE_NORMAL,
- "text", _("Switch Modes"),
+ "text", "",
NULL);
return;
}
@@ -325,14 +342,14 @@ accel_set_func (GtkTreeViewColumn *tree_column,
}
type = g_settings_get_enum (button->settings, ACTION_TYPE_KEY);
- if (type == GSD_WACOM_ACTION_TYPE_NONE) {
+ if (type != GSD_WACOM_ACTION_TYPE_CUSTOM) {
g_object_set (cell,
"visible", TRUE,
"editable", TRUE,
"accel-key", 0,
"accel-mods", 0,
"style", PANGO_STYLE_NORMAL,
- "text", _("None"),
+ "text", "",
NULL);
return;
}
@@ -373,10 +390,12 @@ start_editing_cb (GtkTreeView *tree_view,
{
GtkTreePath *path;
GtkTreeViewColumn *column;
+ gboolean handled;
if (event->window != gtk_tree_view_get_bin_window (tree_view))
return FALSE;
+ handled = FALSE;
if (gtk_tree_view_get_path_at_pos (tree_view,
(gint) event->x,
(gint) event->y,
@@ -386,22 +405,37 @@ start_editing_cb (GtkTreeView *tree_view,
GtkTreeModel *model;
GtkTreeIter iter;
GsdWacomTabletButton *button;
+ GsdWacomActionType type;
+
+ if (column == gtk_tree_view_get_column (tree_view, MAPPING_TYPE_COLUMN))
+ goto out;
model = gtk_tree_view_get_model (tree_view);
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter,
MAPPING_BUTTON_COLUMN, &button,
-1);
+ if (button == NULL)
+ goto out;
+
+ if (button->settings == NULL)
+ goto out;
+
+ type = g_settings_get_enum (button->settings, ACTION_TYPE_KEY);
+ if (type != GSD_WACOM_ACTION_TYPE_CUSTOM)
+ goto out;
gtk_widget_grab_focus (GTK_WIDGET (tree_view));
gtk_tree_view_set_cursor (tree_view,
path,
- gtk_tree_view_get_column (tree_view, 1),
+ gtk_tree_view_get_column (tree_view, MAPPING_BUTTON_COLUMN),
TRUE);
g_signal_stop_emission_by_name (tree_view, "button_press_event");
+ handled = TRUE;
+out:
gtk_tree_path_free (path);
}
- return TRUE;
+ return handled;
}
static void
@@ -423,7 +457,7 @@ start_editing_kb_cb (GtkTreeView *treeview,
gtk_widget_grab_focus (GTK_WIDGET (treeview));
gtk_tree_view_set_cursor (treeview,
path,
- gtk_tree_view_get_column (treeview, 1),
+ gtk_tree_view_get_column (treeview, MAPPING_BUTTON_COLUMN),
TRUE);
}
@@ -553,7 +587,8 @@ accel_cleared_callback (GtkCellRendererText *cell,
static void
add_button_to_store (GtkListStore *model,
GsdWacomTabletButton *button,
- GtkDirectionType dir)
+ GtkDirectionType dir,
+ GsdWacomActionType type)
{
GtkTreeIter new_row;
char *dir_name;
@@ -569,6 +604,7 @@ add_button_to_store (GtkListStore *model,
gtk_list_store_append (model, &new_row);
gtk_list_store_set (model, &new_row,
MAPPING_DESCRIPTION_COLUMN, dir_name ? dir_name : button->name,
+ MAPPING_TYPE_COLUMN, _(action_table[type].action_name),
MAPPING_BUTTON_COLUMN, button,
MAPPING_BUTTON_DIRECTION, dir,
-1);
@@ -576,6 +612,91 @@ add_button_to_store (GtkListStore *model,
}
static void
+action_set_func (GtkTreeViewColumn *tree_column,
+ GtkCellRenderer *cell,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ GsdWacomTabletButton *button;
+ GsdWacomActionType type;
+
+ gtk_tree_model_get (model, iter, MAPPING_BUTTON_COLUMN, &button, -1);
+
+ if (button == NULL) {
+ g_object_set (cell, "visible", FALSE, NULL);
+ return;
+ }
+
+ if (button->type == WACOM_TABLET_BUTTON_TYPE_HARDCODED) {
+ g_object_set (cell,
+ "visible", TRUE,
+ "editable", FALSE,
+ "style", PANGO_STYLE_NORMAL,
+ "text", _("Switch Modes"),
+ NULL);
+ return;
+ }
+
+ if (button->type == WACOM_TABLET_BUTTON_TYPE_ELEVATOR) {
+ g_object_set (cell,
+ "visible", TRUE,
+ "editable", FALSE,
+ "style", PANGO_STYLE_NORMAL,
+ "text", _(action_table[GSD_WACOM_ACTION_TYPE_CUSTOM].action_name),
+ NULL);
+ return;
+ }
+
+ if (button->settings == NULL) {
+ g_warning ("Button '%s' does not have an associated GSettings", button->id);
+ return;
+ }
+
+ type = g_settings_get_enum (button->settings, ACTION_TYPE_KEY);
+ g_object_set (cell,
+ "visible", TRUE,
+ "editable", TRUE,
+ "style", PANGO_STYLE_NORMAL,
+ "text", _(action_table[type].action_name),
+ NULL);
+}
+
+static void
+combo_action_cell_changed (GtkCellRendererCombo *cell,
+ const gchar *path_string,
+ GtkTreeIter *new_iter,
+ CcWacomPage *page)
+{
+ GtkTreeView *tree_view;
+ GtkTreePath *path;
+ GtkTreeModel *model;
+ CcWacomPagePrivate *priv;
+ GsdWacomActionType type;
+ GtkTreeIter iter;
+ GsdWacomTabletButton *button;
+
+ priv = page->priv;
+ tree_view = GTK_TREE_VIEW (MWID("shortcut_treeview"));
+ model = gtk_tree_view_get_model (tree_view);
+ path = gtk_tree_path_new_from_string (path_string);
+
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->action_store), new_iter, ACTION_TYPE_COLUMN, &type, -1);
+ gtk_tree_model_get_iter (model, &iter, path);
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, MAPPING_TYPE_COLUMN, _(action_table[type].action_name), -1);
+ gtk_tree_path_free (path);
+
+ gtk_tree_model_get (model, &iter, MAPPING_BUTTON_COLUMN, &button, -1);
+ if (button == NULL)
+ return;
+ if (button->settings == NULL)
+ return;
+ g_settings_set_enum (button->settings, ACTION_TYPE_KEY, type);
+
+ gtk_widget_grab_focus (GTK_WIDGET (tree_view));
+}
+
+static void
setup_mapping_treeview (CcWacomPage *page)
{
CcWacomPagePrivate *priv;
@@ -583,7 +704,9 @@ setup_mapping_treeview (CcWacomPage *page)
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
GtkListStore *model;
+ GtkTreeIter iter;
GList *list, *l;
+ gint i;
priv = page->priv;
treeview = GTK_TREE_VIEW(MWID ("shortcut_treeview"));
@@ -606,6 +729,38 @@ setup_mapping_treeview (CcWacomPage *page)
gtk_tree_view_append_column (treeview, column);
gtk_tree_view_column_set_sort_column_id (column, MAPPING_DESCRIPTION_COLUMN);
+ priv->action_store = gtk_list_store_new (ACTION_N_COLUMNS, G_TYPE_STRING, G_TYPE_INT);
+ for (i = 0; i < G_N_ELEMENTS (action_table); i++) {
+ /* Screen tablets cannot switch monitors (as the monitor is the tablet) */
+ if (action_table[i].action_type == GSD_WACOM_ACTION_TYPE_SWITCH_MONITOR &&
+ gsd_wacom_device_is_screen_tablet (priv->stylus))
+ continue;
+
+ gtk_list_store_append (priv->action_store, &iter);
+ gtk_list_store_set (priv->action_store, &iter,
+ ACTION_NAME_COLUMN, _(action_table[i].action_name),
+ ACTION_TYPE_COLUMN, action_table[i].action_type, -1);
+ }
+ renderer = gtk_cell_renderer_combo_new ();
+ g_object_set (renderer,
+ "text-column", ACTION_NAME_COLUMN,
+ "has-entry", FALSE,
+ "model", priv->action_store,
+ "editable", TRUE,
+ NULL);
+ g_signal_connect (renderer, "changed",
+ G_CALLBACK (combo_action_cell_changed), page);
+
+ column = gtk_tree_view_column_new_with_attributes (_("Type"),
+ renderer,
+ "text", MAPPING_TYPE_COLUMN,
+ NULL);
+ gtk_tree_view_column_set_cell_data_func (column, renderer, action_set_func, NULL, NULL);
+ gtk_tree_view_column_set_resizable (column, FALSE);
+ gtk_tree_view_column_set_expand (column, FALSE);
+
+ gtk_tree_view_append_column (treeview, column);
+
renderer = (GtkCellRenderer *) g_object_new (GTK_TYPE_CELL_RENDERER_ACCEL,
"accel-mode", GTK_CELL_RENDERER_ACCEL_MODE_OTHER,
NULL);
@@ -624,19 +779,23 @@ setup_mapping_treeview (CcWacomPage *page)
gtk_tree_view_append_column (treeview, column);
- model = gtk_list_store_new (MAPPING_N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_INT);
+ model = gtk_list_store_new (MAPPING_N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_INT);
gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (model));
/* Fill it up! */
list = gsd_wacom_device_get_buttons (page->priv->pad);
for (l = list; l != NULL; l = l->next) {
GsdWacomTabletButton *button = l->data;
+ GsdWacomActionType type = GSD_WACOM_ACTION_TYPE_NONE;
+
+ if (button->settings)
+ type = g_settings_get_enum (button->settings, ACTION_TYPE_KEY);
if (button->type == WACOM_TABLET_BUTTON_TYPE_ELEVATOR) {
- add_button_to_store (model, button, GTK_DIR_UP);
- add_button_to_store (model, button, GTK_DIR_DOWN);
+ add_button_to_store (model, button, GTK_DIR_UP, GSD_WACOM_ACTION_TYPE_CUSTOM);
+ add_button_to_store (model, button, GTK_DIR_DOWN, GSD_WACOM_ACTION_TYPE_CUSTOM);
} else {
- add_button_to_store (model, button, 0);
+ add_button_to_store (model, button, 0, type);
}
}
g_list_free (list);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]