Commit 7b213472 authored by Peter Hutterer's avatar Peter Hutterer Committed by Bastien Nocera

wacom: add a wacom control panel.

https://bugzilla.gnome.org/show_bug.cgi?id=640981
parent a999160b
......@@ -123,6 +123,8 @@ PKG_CHECK_MODULES(USER_ACCOUNTS_PANEL, $COMMON_MODULES dbus-glib-1
polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION
gnome-desktop-3.0
gdk-pixbuf-2.0 >= $GDKPIXBUF_REQUIRED_VERSION)
PKG_CHECK_MODULES(WACOM_PANEL, $COMMON_MODULES
gnome-settings-daemon >= $GSD_REQUIRED_VERSION)
GDESKTOP_PREFIX=`$PKG_CONFIG --variable prefix gsettings-desktop-schemas`
AC_SUBST(GDESKTOP_PREFIX)
......@@ -390,6 +392,8 @@ panels/user-accounts/data/Makefile
panels/user-accounts/data/gnome-user-accounts-panel.desktop.in
panels/user-accounts/data/faces/Makefile
panels/user-accounts/data/icons/Makefile
panels/wacom/Makefile
panels/wacom/gnome-wacom-panel.desktop.in
po/Makefile.in
shell/Makefile
shell/gnome-control-center.desktop.in
......
......@@ -14,7 +14,8 @@ SUBDIRS= \
keyboard \
universal-access \
user-accounts \
datetime
datetime \
wacom
if BUILD_PRINTERS
SUBDIRS += printers
......
# This is used in PANEL_CFLAGS
cappletname = wacom
INCLUDES = \
$(PANEL_CFLAGS) \
$(WACOM_PANEL_CFLAGS) \
-DGNOMELOCALEDIR="\"$(datadir)/locale\"" \
-DGNOMECC_DATA_DIR="\"$(pkgdatadir)\"" \
-DGNOMECC_UI_DIR="\"$(uidir)\"" \
-DPIXMAP_DIR=\""$(datadir)/gnome-control-center/pixmaps"\" \
$(NULL)
ccpanelsdir = $(PANELS_DIR)
ccpanels_LTLIBRARIES = libwacom-properties.la
libwacom_properties_la_SOURCES = \
wacom-module.c \
cc-wacom-panel.c \
cc-wacom-panel.h
libwacom_properties_la_LIBADD = $(PANEL_LIBS) $(WACOM_PANEL_LIBS)
libwacom_properties_la_LDFLAGS = $(PANEL_LDFLAGS)
@INTLTOOL_DESKTOP_RULE@
pixmapdir = $(pkgdatadir)/pixmaps
pixmap_DATA = \
wacom-tablet.png \
wacom-stylus.png
uidir = $(pkgdatadir)/ui
ui_DATA = gnome-wacom-properties.ui
desktopdir = $(datadir)/applications
desktop_in_files = gnome-wacom-panel.desktop.in
desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
CLEANFILES = $(Desktop_in_files) $(desktop_DATA)
EXTRA_DIST = $(ui_DATA) $(pixmap_DATA)
-include $(top_srcdir)/git.mk
/*
* Copyright © 2011 Red Hat, Inc.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: Peter Hutterer <peter.hutterer@redhat.com>
*
*/
#include <config.h>
#include "cc-wacom-panel.h"
#include <gtk/gtk.h>
#include <string.h>
#define WID(x) (GtkWidget *) gtk_builder_get_object (dialog, x)
G_DEFINE_DYNAMIC_TYPE (CcWacomPanel, cc_wacom_panel, CC_TYPE_PANEL)
#define WACOM_PANEL_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_WACOM_PANEL, CcWacomPanelPrivate))
struct _CcWacomPanelPrivate
{
GtkBuilder *builder;
GSettings *wacom_settings;
GSettings *stylus_settings;
GSettings *eraser_settings;
/* The UI doesn't support cursor/pad at the moment */
};
/* Button combo box storage columns */
enum {
BUTTONNUMBER_COLUMN,
BUTTONNAME_COLUMN,
N_BUTTONCOLUMNS
};
/* Tablet mode combo box storage columns */
enum {
MODENUMBER_COLUMN,
MODELABEL_COLUMN,
N_MODECOLUMNS
};
/* Tablet mode options - keep in sync with .ui */
enum {
MODE_ABSOLUTE, /* stylus + eraser absolute */
MODE_RELATIVE, /* stylus + eraser relative */
};
/* GSettings stores pressurecurve as 4 values like the driver. We map slider
* scale to these values given the array below. These settings were taken from
* wacomcpl, where they've been around for years.
*/
#define N_PRESSURE_CURVES 7
static const gint32 PRESSURE_CURVES[N_PRESSURE_CURVES][4] = {
{ 0, 75, 25, 100 }, /* soft */
{ 0, 50, 50, 100 },
{ 0, 25, 75, 100 },
{ 0, 0, 100, 100 }, /* neutral */
{ 25, 0, 100, 75 },
{ 50, 0, 100, 50 },
{ 75, 0, 100, 25 } /* firm */
};
static void
set_pressurecurve (GtkRange *range, GSettings *settings)
{
gint slider_val = gtk_range_get_value (range);
GVariant *values[4],
*array;
int i;
for (i = 0; i < 4; i++)
values[i] = g_variant_new_int32 (PRESSURE_CURVES[slider_val][i]);
array = g_variant_new_array (G_VARIANT_TYPE_INT32, values, 4);
g_settings_set_value (settings, "pressurecurve", array);
g_variant_unref (array);
}
static void
tip_feel_value_changed_cb (GtkRange *range, gpointer user_data)
{
set_pressurecurve (range, CC_WACOM_PANEL(user_data)->priv->stylus_settings);
}
static void
eraser_feel_value_changed_cb (GtkRange *range, gpointer user_data)
{
set_pressurecurve (range, CC_WACOM_PANEL(user_data)->priv->eraser_settings);
}
static void
set_feel_from_gsettings (GtkAdjustment *adjustment, GSettings *settings)
{
GVariant *variant;
const gint32 *values;
gsize nvalues;
int i;
variant = g_settings_get_value (settings, "pressurecurve");
values = g_variant_get_fixed_array (variant, &nvalues, sizeof (gint32));
if (nvalues != 4) {
g_warning ("Invalid pressure curve format, expected 4 values (got %ld)", nvalues);
return;
}
for (i = 0; i < N_PRESSURE_CURVES; i++) {
if (memcmp (PRESSURE_CURVES[i], values, sizeof (gint32) * 4) == 0) {
gtk_adjustment_set_value (adjustment, i);
break;
}
}
}
static void
tabletmode_changed_cb (GtkComboBox *combo, gpointer user_data)
{
CcWacomPanelPrivate *priv = CC_WACOM_PANEL(user_data)->priv;
GtkBuilder *dialog = GTK_BUILDER (priv->builder);
GtkListStore *liststore;
GtkTreeIter iter;
gint mode;
if (!gtk_combo_box_get_active_iter (combo, &iter))
return;
liststore = GTK_LIST_STORE (WID ("liststore-tabletmode"));
gtk_tree_model_get (GTK_TREE_MODEL (liststore), &iter,
MODENUMBER_COLUMN, &mode,
-1);
switch (mode)
{
case MODE_ABSOLUTE:
g_settings_set_boolean (priv->stylus_settings, "is-absolute", TRUE);
g_settings_set_boolean (priv->eraser_settings, "is-absolute", TRUE);
break;
case MODE_RELATIVE:
g_settings_set_boolean (priv->stylus_settings, "is-absolute", FALSE);
g_settings_set_boolean (priv->eraser_settings, "is-absolute", FALSE);
break;
default:
g_warning ("Ignoring unknown tablet mode %d.\n", mode);
break;
}
}
static void
set_mode_from_gsettings (GtkComboBox *combo, CcWacomPanel *panel)
{
CcWacomPanelPrivate *priv = CC_WACOM_PANEL(panel)->priv;
gboolean stylus_is_absolute,
eraser_is_absolute;
stylus_is_absolute = g_settings_get_boolean (priv->stylus_settings, "is-absolute");
eraser_is_absolute = g_settings_get_boolean (priv->eraser_settings, "is-absolute");
/* this must be kept in sync with the .ui file */
if (stylus_is_absolute && eraser_is_absolute)
gtk_combo_box_set_active (combo, MODE_ABSOLUTE);
else if (!stylus_is_absolute && !eraser_is_absolute)
gtk_combo_box_set_active (combo, MODE_RELATIVE);
else
gtk_combo_box_set_active (combo, -1);
}
static void
set_button_mapping_from_gsettings (GtkComboBox *combo, GSettings* settings, gint current_button)
{
GVariant *current;
gsize nvalues;
const gint *values;
GtkTreeModel *model;
GtkTreeIter iter;
gboolean valid;
current = g_settings_get_value (settings, "buttonmapping");
values = g_variant_get_fixed_array (current, &nvalues, sizeof (gint32));
model = gtk_combo_box_get_model (combo);
valid = gtk_tree_model_get_iter_first (model, &iter);
while (valid) {
gint button;
gtk_tree_model_get (model, &iter,
BUTTONNUMBER_COLUMN, &button,
-1);
/* Currently button values match logical X buttons. If we
* introduce things like double-click, this code must
* change. Recommendation: use negative buttons numbers for
* special ones.
*/
/* 0 vs 1-indexed array/button numbers */
if (button == values[current_button - 1]) {
gtk_combo_box_set_active_iter (combo, &iter);
break;
}
valid = gtk_tree_model_iter_next (model, &iter);
}
}
static void
map_button (GSettings *settings, int button2, int button3)
{
GVariant *current; /* current mapping */
GVariant *array; /* new mapping */
GVariant **tmp;
gsize nvalues;
const gint *values;
gint i;
current = g_settings_get_value (settings, "buttonmapping");
values = g_variant_get_fixed_array (current, &nvalues, sizeof (gint32));
tmp = g_malloc (nvalues * sizeof (GVariant*));
for (i = 0; i < nvalues; i++) {
if (i == 1) /* zero indexed array vs one-indexed buttons */
tmp[i] = g_variant_new_int32 (button2);
else if (i == 2)
tmp[i] = g_variant_new_int32 (button3);
else
tmp[i] = g_variant_new_int32 (values[i]);
}
array = g_variant_new_array (G_VARIANT_TYPE_INT32, tmp, nvalues);
g_settings_set_value (settings, "buttonmapping", array);
g_free (tmp);
g_variant_unref (array);
}
static void
button_changed_cb (GtkComboBox *combo, gpointer user_data)
{
CcWacomPanelPrivate *priv = CC_WACOM_PANEL(user_data)->priv;
GtkBuilder *dialog = priv->builder;
GtkTreeIter iter;
GtkListStore *liststore;
gint mapping_b2,
mapping_b3;
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (WID ("combo-bottombutton")), &iter))
return;
liststore = GTK_LIST_STORE (WID ("liststore-buttons"));
gtk_tree_model_get (GTK_TREE_MODEL (liststore), &iter,
BUTTONNUMBER_COLUMN, &mapping_b2,
-1);
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (WID ("combo-topbutton")), &iter))
return;
gtk_tree_model_get (GTK_TREE_MODEL (liststore), &iter,
BUTTONNUMBER_COLUMN, &mapping_b3,
-1);
map_button (priv->stylus_settings, mapping_b2, mapping_b3);
}
static void
combobox_text_cellrenderer (GtkComboBox *combo, int name_column)
{
GtkCellRenderer *renderer;
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer,
"text", BUTTONNAME_COLUMN, NULL);
}
static void
gnome_wacom_properties_init (CcWacomPanel *panel)
{
CcWacomPanelPrivate *priv = CC_WACOM_PANEL(panel)->priv;
GtkBuilder *dialog = priv->builder;
GtkComboBox *combo;
priv->wacom_settings = g_settings_new ("org.gnome.settings-daemon.peripherals.wacom");
priv->stylus_settings = g_settings_new ("org.gnome.settings-daemon.peripherals.wacom.stylus");
priv->eraser_settings = g_settings_new ("org.gnome.settings-daemon.peripherals.wacom.eraser");
g_signal_connect (WID ("scale-tip-feel"), "value-changed",
G_CALLBACK (tip_feel_value_changed_cb), panel);
g_signal_connect (WID ("scale-eraser-feel"), "value-changed",
G_CALLBACK (eraser_feel_value_changed_cb), panel);
combo = GTK_COMBO_BOX (WID ("combo-topbutton"));
combobox_text_cellrenderer (combo, BUTTONNAME_COLUMN);
g_signal_connect (G_OBJECT (combo), "changed",
G_CALLBACK (button_changed_cb), panel);
combo = GTK_COMBO_BOX (WID ("combo-bottombutton"));
combobox_text_cellrenderer (combo, BUTTONNAME_COLUMN);
g_signal_connect (G_OBJECT (combo), "changed",
G_CALLBACK (button_changed_cb), panel);
combo = GTK_COMBO_BOX (WID ("combo-tabletmode"));
combobox_text_cellrenderer (combo, MODELABEL_COLUMN);
g_signal_connect (G_OBJECT (combo), "changed",
G_CALLBACK (tabletmode_changed_cb), panel);
set_button_mapping_from_gsettings (GTK_COMBO_BOX (WID ("combo-topbutton")), priv->stylus_settings, 3);
set_button_mapping_from_gsettings (GTK_COMBO_BOX (WID ("combo-bottombutton")), priv->stylus_settings, 2);
set_mode_from_gsettings (GTK_COMBO_BOX (WID ("combo-tabletmode")), panel);
set_feel_from_gsettings (GTK_ADJUSTMENT (WID ("adjustment-tip-feel")), priv->stylus_settings);
set_feel_from_gsettings (GTK_ADJUSTMENT (WID ("adjustment-eraser-feel")), priv->eraser_settings);
gtk_image_set_from_file (GTK_IMAGE (WID ("image-tablet")), PIXMAP_DIR "/wacom-tablet.png");
gtk_image_set_from_file (GTK_IMAGE (WID ("image-stylus")), PIXMAP_DIR "/wacom-stylus.png");
}
/* Boilerplate code goes below */
static void
cc_wacom_panel_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
switch (property_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
cc_wacom_panel_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
switch (property_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
cc_wacom_panel_dispose (GObject *object)
{
CcWacomPanelPrivate *priv = CC_WACOM_PANEL (object)->priv;
if (priv->builder)
{
g_object_unref (priv->builder);
priv->builder = NULL;
}
G_OBJECT_CLASS (cc_wacom_panel_parent_class)->dispose (object);
}
static void
cc_wacom_panel_finalize (GObject *object)
{
G_OBJECT_CLASS (cc_wacom_panel_parent_class)->finalize (object);
}
static void
cc_wacom_panel_class_init (CcWacomPanelClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (CcWacomPanelPrivate));
object_class->get_property = cc_wacom_panel_get_property;
object_class->set_property = cc_wacom_panel_set_property;
object_class->dispose = cc_wacom_panel_dispose;
object_class->finalize = cc_wacom_panel_finalize;
}
static void
cc_wacom_panel_class_finalize (CcWacomPanelClass *klass)
{
}
static void
cc_wacom_panel_init (CcWacomPanel *self)
{
CcWacomPanelPrivate *priv;
GtkWidget *grid;
GError *error = NULL;
priv = self->priv = WACOM_PANEL_PRIVATE (self);
priv->builder = gtk_builder_new ();
gtk_builder_add_from_file (priv->builder,
GNOMECC_UI_DIR "/gnome-wacom-properties.ui",
&error);
if (error != NULL)
{
g_warning ("Error loading UI file: %s", error->message);
g_object_unref (priv->builder);
return;
}
gnome_wacom_properties_init (self);
grid = (GtkWidget*) gtk_builder_get_object (priv->builder, "main-grid");
gtk_widget_reparent (grid, GTK_WIDGET (self));
}
void
cc_wacom_panel_register (GIOModule *module)
{
cc_wacom_panel_register_type (G_TYPE_MODULE (module));
g_io_extension_point_implement (CC_SHELL_PANEL_EXTENSION_POINT,
CC_TYPE_WACOM_PANEL, "wacom", 0);
}
/*
* Copyright © Red Hat, Inc.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Author: Peter Hutterer <peter.hutterer@redhat.com>
*/
#ifndef _CC_WACOM_PANEL_H
#define _CC_WACOM_PANEL_H
#include <libgnome-control-center/cc-panel.h>
G_BEGIN_DECLS
#define CC_TYPE_WACOM_PANEL cc_wacom_panel_get_type()
#define CC_WACOM_PANEL(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
CC_TYPE_WACOM_PANEL, CcWacomPanel))
#define CC_WACOM_PANEL_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), \
CC_TYPE_WACOM_PANEL, CcWacomPanelClass))
#define CC_IS_WACOM_PANEL(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
CC_TYPE_WACOM_PANEL))
#define CC_IS_WACOM_PANEL_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
CC_TYPE_WACOM_PANEL))
#define CC_WACOM_PANEL_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
CC_TYPE_WACOM_PANEL, CcWacomPanelClass))
typedef struct _CcWacomPanel CcWacomPanel;
typedef struct _CcWacomPanelClass CcWacomPanelClass;
typedef struct _CcWacomPanelPrivate CcWacomPanelPrivate;
struct _CcWacomPanel
{
CcPanel parent;
CcWacomPanelPrivate *priv;
};
struct _CcWacomPanelClass
{
CcPanelClass parent_class;
};
GType cc_wacom_panel_get_type (void) G_GNUC_CONST;
void cc_wacom_panel_register (GIOModule *module);
G_END_DECLS
#endif /* _CC_WACOM_PANEL_H */
[Desktop Entry]
_Name=Wacom
_Comment=Set your Wacom tablet preferences
Exec=gnome-control-center wacom
Icon=input-tablet
Terminal=false
Type=Application
StartupNotify=true
Categories=GNOME;GTK;Settings;HardwareSettings;X-GNOME-Settings-Panel;
OnlyShowIn=GNOME;
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=gnome-control-center
X-GNOME-Bugzilla-Component=wacom
X-GNOME-Bugzilla-Version=@VERSION@
X-GNOME-Settings-Panel=wacom
# Translators: those are keywords for the wacom tablet control-center panel
_X-GNOME-Keywords=Tablet;Wacom;Stylus;Eraser;Mouse;
This diff is collapsed.
/*
* Copyright © Red Hat, Inc.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Author: Peter Hutterer <peter.hutterer@redhat.com>
*
*/
#include <config.h>
#include "cc-wacom-panel.h"
#include <glib/gi18n-lib.h>
void
g_io_module_load (GIOModule *module)
{
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
/* register the panel */
cc_wacom_panel_register (module);
}
void
g_io_module_unload (GIOModule *module)
{
}
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