2012-01-16 17:18:32 +00:00
|
|
|
/*
|
|
|
|
* 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
|
2014-01-23 12:57:27 +01:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2012-01-16 17:18:32 +00:00
|
|
|
*
|
|
|
|
* Authors: Peter Hutterer <peter.hutterer@redhat.com>
|
|
|
|
* Bastien Nocera <hadess@hadess.net>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include "cc-wacom-stylus-page.h"
|
|
|
|
#include "cc-wacom-nav-button.h"
|
|
|
|
#include <gtk/gtk.h>
|
2016-06-06 14:49:13 +02:00
|
|
|
#include <gdesktop-enums.h>
|
2012-01-16 17:18:32 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2018-06-03 09:42:43 +04:00
|
|
|
#define WID(x) (GtkWidget *) gtk_builder_get_object (page->builder, x)
|
|
|
|
#define CWID(x) (GtkContainer *) gtk_builder_get_object (page->builder, x)
|
2012-01-16 17:18:32 +00:00
|
|
|
|
2018-06-03 09:42:43 +04:00
|
|
|
struct _CcWacomStylusPage
|
2012-01-16 17:18:32 +00:00
|
|
|
{
|
2018-06-03 09:42:43 +04:00
|
|
|
GtkBox parent_instance;
|
|
|
|
|
2016-06-06 14:49:13 +02:00
|
|
|
CcWacomTool *stylus;
|
2012-01-16 17:18:32 +00:00
|
|
|
GtkBuilder *builder;
|
|
|
|
GtkWidget *nav;
|
2016-06-06 14:49:13 +02:00
|
|
|
GSettings *stylus_settings;
|
2012-01-16 17:18:32 +00:00
|
|
|
};
|
|
|
|
|
2018-06-03 09:42:43 +04:00
|
|
|
G_DEFINE_TYPE (CcWacomStylusPage, cc_wacom_stylus_page, GTK_TYPE_BOX)
|
|
|
|
|
2012-01-16 17:18:32 +00:00
|
|
|
/* Button combo box storage columns */
|
|
|
|
enum {
|
|
|
|
BUTTONNUMBER_COLUMN,
|
|
|
|
BUTTONNAME_COLUMN,
|
|
|
|
N_BUTTONCOLUMNS
|
|
|
|
};
|
|
|
|
|
|
|
|
/* 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
|
2016-06-06 14:49:13 +02:00
|
|
|
set_pressurecurve (GtkRange *range, GSettings *settings, const gchar *key)
|
2012-01-16 17:18:32 +00:00
|
|
|
{
|
|
|
|
gint slider_val = gtk_range_get_value (range);
|
|
|
|
GVariant *values[4],
|
|
|
|
*array;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (values); i++)
|
|
|
|
values[i] = g_variant_new_int32 (PRESSURE_CURVES[slider_val][i]);
|
|
|
|
|
|
|
|
array = g_variant_new_array (G_VARIANT_TYPE_INT32, values, G_N_ELEMENTS (values));
|
|
|
|
|
2016-06-06 14:49:13 +02:00
|
|
|
g_settings_set_value (settings, key, array);
|
2012-01-16 17:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-22 15:54:43 +13:00
|
|
|
tip_feel_value_changed_cb (CcWacomStylusPage *page)
|
2012-01-16 17:18:32 +00:00
|
|
|
{
|
2019-11-22 15:54:43 +13:00
|
|
|
set_pressurecurve (GTK_RANGE (WID ("scale-tip-feel")), page->stylus_settings, "pressure-curve");
|
2012-01-16 17:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-22 15:54:43 +13:00
|
|
|
eraser_feel_value_changed_cb (CcWacomStylusPage *page)
|
2012-01-16 17:18:32 +00:00
|
|
|
{
|
2019-11-22 15:54:43 +13:00
|
|
|
set_pressurecurve (GTK_RANGE (WID ("scale-eraser-feel")), page->stylus_settings, "eraser-pressure-curve");
|
2012-01-16 17:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-06-06 14:49:13 +02:00
|
|
|
set_feel_from_gsettings (GtkAdjustment *adjustment, GSettings *settings, const gchar *key)
|
2012-01-16 17:18:32 +00:00
|
|
|
{
|
|
|
|
GVariant *variant;
|
|
|
|
const gint32 *values;
|
|
|
|
gsize nvalues;
|
|
|
|
int i;
|
|
|
|
|
2016-06-06 14:49:13 +02:00
|
|
|
variant = g_settings_get_value (settings, key);
|
2012-01-16 17:18:32 +00:00
|
|
|
values = g_variant_get_fixed_array (variant, &nvalues, sizeof (gint32));
|
|
|
|
|
|
|
|
if (nvalues != 4) {
|
|
|
|
g_warning ("Invalid pressure curve format, expected 4 values (got %"G_GSIZE_FORMAT")", 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
|
2016-06-06 14:49:13 +02:00
|
|
|
set_button_mapping_from_gsettings (GtkComboBox *combo, GSettings* settings, const gchar *key)
|
2012-01-16 17:18:32 +00:00
|
|
|
{
|
2016-06-06 14:49:13 +02:00
|
|
|
GDesktopStylusButtonAction action;
|
2012-01-16 17:18:32 +00:00
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean valid;
|
|
|
|
|
2016-06-06 14:49:13 +02:00
|
|
|
action = g_settings_get_enum (settings, key);
|
2012-01-16 17:18:32 +00:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2016-06-06 14:49:13 +02:00
|
|
|
if (button == action) {
|
2012-01-16 17:18:32 +00:00
|
|
|
gtk_combo_box_set_active_iter (combo, &iter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
valid = gtk_tree_model_iter_next (model, &iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-22 15:54:43 +13:00
|
|
|
button_changed_cb (CcWacomStylusPage *page)
|
2012-01-16 17:18:32 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkListStore *liststore;
|
|
|
|
gint mapping_b2,
|
2017-10-10 07:57:49 -07:00
|
|
|
mapping_b3,
|
|
|
|
mapping_b4;
|
2012-01-16 17:18:32 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-06-03 09:42:43 +04:00
|
|
|
if (cc_wacom_tool_get_num_buttons (page->stylus) > 1) {
|
2015-03-15 20:55:07 -04:00
|
|
|
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (WID ("combo-topbutton")), &iter))
|
|
|
|
return;
|
2012-01-16 17:18:32 +00:00
|
|
|
|
2015-03-15 20:55:07 -04:00
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (liststore), &iter,
|
|
|
|
BUTTONNUMBER_COLUMN, &mapping_b3,
|
|
|
|
-1);
|
|
|
|
} else {
|
|
|
|
mapping_b3 = 0;
|
|
|
|
}
|
2012-01-16 17:18:32 +00:00
|
|
|
|
2018-06-03 09:42:43 +04:00
|
|
|
if (cc_wacom_tool_get_num_buttons (page->stylus) > 2) {
|
2017-10-10 07:57:49 -07:00
|
|
|
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (WID ("combo-thirdbutton")), &iter))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (liststore), &iter,
|
|
|
|
BUTTONNUMBER_COLUMN, &mapping_b4,
|
|
|
|
-1);
|
|
|
|
} else {
|
|
|
|
mapping_b4 = 0;
|
|
|
|
}
|
|
|
|
|
2018-06-03 09:42:43 +04:00
|
|
|
g_settings_set_enum (page->stylus_settings, "button-action", mapping_b2);
|
|
|
|
g_settings_set_enum (page->stylus_settings, "secondary-button-action", mapping_b3);
|
|
|
|
g_settings_set_enum (page->stylus_settings, "tertiary-button-action", mapping_b4);
|
2012-01-16 17:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Boilerplate code goes below */
|
|
|
|
|
|
|
|
static void
|
|
|
|
cc_wacom_stylus_page_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_stylus_page_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_stylus_page_dispose (GObject *object)
|
|
|
|
{
|
2018-06-03 09:42:43 +04:00
|
|
|
CcWacomStylusPage *page = CC_WACOM_STYLUS_PAGE (object);
|
2012-01-16 17:18:32 +00:00
|
|
|
|
2018-06-03 10:22:08 +04:00
|
|
|
g_clear_object (&page->builder);
|
2012-01-16 17:18:32 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (cc_wacom_stylus_page_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cc_wacom_stylus_page_class_init (CcWacomStylusPageClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->get_property = cc_wacom_stylus_page_get_property;
|
|
|
|
object_class->set_property = cc_wacom_stylus_page_set_property;
|
|
|
|
object_class->dispose = cc_wacom_stylus_page_dispose;
|
|
|
|
}
|
|
|
|
|
2019-04-24 16:46:41 +02:00
|
|
|
static void
|
|
|
|
add_marks (GtkScale *scale)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < N_PRESSURE_CURVES; i++)
|
|
|
|
gtk_scale_add_mark (scale, i, GTK_POS_BOTTOM, NULL);
|
|
|
|
}
|
|
|
|
|
2012-01-16 17:18:32 +00:00
|
|
|
static void
|
2018-06-03 09:42:43 +04:00
|
|
|
cc_wacom_stylus_page_init (CcWacomStylusPage *page)
|
2012-01-16 17:18:32 +00:00
|
|
|
{
|
2018-06-03 10:22:08 +04:00
|
|
|
g_autoptr(GError) error = NULL;
|
2012-01-16 17:18:32 +00:00
|
|
|
GtkComboBox *combo;
|
|
|
|
GtkWidget *box;
|
|
|
|
char *objects[] = {
|
|
|
|
"stylus-grid",
|
|
|
|
"liststore-buttons",
|
|
|
|
"adjustment-tip-feel",
|
|
|
|
"adjustment-eraser-feel",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-06-03 09:42:43 +04:00
|
|
|
page->builder = gtk_builder_new ();
|
2012-01-16 17:18:32 +00:00
|
|
|
|
2018-06-03 09:42:43 +04:00
|
|
|
gtk_builder_add_objects_from_resource (page->builder,
|
2013-01-04 16:36:56 +01:00
|
|
|
"/org/gnome/control-center/wacom/wacom-stylus-page.ui",
|
|
|
|
objects,
|
|
|
|
&error);
|
2012-01-16 17:18:32 +00:00
|
|
|
if (error != NULL) {
|
|
|
|
g_warning ("Error loading UI file: %s", error->message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
box = WID ("stylus-grid");
|
2018-06-03 09:42:43 +04:00
|
|
|
gtk_container_add (GTK_CONTAINER (page), box);
|
2012-01-16 17:18:32 +00:00
|
|
|
gtk_widget_set_vexpand (GTK_WIDGET (box), TRUE);
|
|
|
|
|
2019-04-24 16:46:41 +02:00
|
|
|
add_marks (GTK_SCALE (WID ("scale-tip-feel")));
|
|
|
|
add_marks (GTK_SCALE (WID ("scale-eraser-feel")));
|
|
|
|
|
2019-11-22 15:54:43 +13:00
|
|
|
g_signal_connect_object (WID ("scale-tip-feel"), "value-changed",
|
|
|
|
G_CALLBACK (tip_feel_value_changed_cb), page, G_CONNECT_SWAPPED);
|
|
|
|
g_signal_connect_object (WID ("scale-eraser-feel"), "value-changed",
|
|
|
|
G_CALLBACK (eraser_feel_value_changed_cb), page, G_CONNECT_SWAPPED);
|
2012-01-16 17:18:32 +00:00
|
|
|
|
|
|
|
combo = GTK_COMBO_BOX (WID ("combo-topbutton"));
|
|
|
|
combobox_text_cellrenderer (combo, BUTTONNAME_COLUMN);
|
2019-11-22 15:54:43 +13:00
|
|
|
g_signal_connect_object (combo, "changed",
|
|
|
|
G_CALLBACK (button_changed_cb), page, G_CONNECT_SWAPPED);
|
2012-01-16 17:18:32 +00:00
|
|
|
|
|
|
|
combo = GTK_COMBO_BOX (WID ("combo-bottombutton"));
|
|
|
|
combobox_text_cellrenderer (combo, BUTTONNAME_COLUMN);
|
2019-11-22 15:54:43 +13:00
|
|
|
g_signal_connect_object (combo, "changed",
|
|
|
|
G_CALLBACK (button_changed_cb), page, G_CONNECT_SWAPPED);
|
2012-01-16 17:18:32 +00:00
|
|
|
|
2017-10-10 07:57:49 -07:00
|
|
|
combo = GTK_COMBO_BOX (WID ("combo-thirdbutton"));
|
|
|
|
combobox_text_cellrenderer (combo, BUTTONNAME_COLUMN);
|
2019-11-22 15:54:43 +13:00
|
|
|
g_signal_connect_object (G_OBJECT (combo), "changed",
|
|
|
|
G_CALLBACK (button_changed_cb), page, G_CONNECT_SWAPPED);
|
2017-10-10 07:57:49 -07:00
|
|
|
|
2018-06-03 09:42:43 +04:00
|
|
|
page->nav = cc_wacom_nav_button_new ();
|
|
|
|
gtk_widget_set_halign (page->nav, GTK_ALIGN_END);
|
|
|
|
gtk_widget_set_margin_start (page->nav, 10);
|
|
|
|
gtk_widget_show (page->nav);
|
|
|
|
gtk_container_add (CWID ("navigation-placeholder"), page->nav);
|
2012-01-16 17:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_icon_name (CcWacomStylusPage *page,
|
|
|
|
const char *widget_name,
|
|
|
|
const char *icon_name)
|
|
|
|
{
|
2018-06-03 10:22:08 +04:00
|
|
|
g_autofree gchar *resource = NULL;
|
2012-01-16 17:18:32 +00:00
|
|
|
|
2013-01-04 16:36:56 +01:00
|
|
|
resource = g_strdup_printf ("/org/gnome/control-center/wacom/%s.svg", icon_name);
|
|
|
|
gtk_image_set_from_resource (GTK_IMAGE (WID (widget_name)), resource);
|
2012-01-16 17:18:32 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 15:42:51 +00:00
|
|
|
/* Different types of layout for the stylus config */
|
|
|
|
enum {
|
2015-03-13 13:11:10 -04:00
|
|
|
LAYOUT_NORMAL, /* eraser, 2 buttons, tip */
|
|
|
|
LAYOUT_INKING, /* tip */
|
|
|
|
LAYOUT_AIRBRUSH, /* eraser, 1 button, tip */
|
|
|
|
LAYOUT_GENERIC_2_BUTTONS_NO_ERASER, /* 2 buttons, tip, no eraser */
|
2017-10-10 07:56:17 -07:00
|
|
|
LAYOUT_3DPEN, /* 3 buttons, tip, no eraser */
|
2012-01-26 15:42:51 +00:00
|
|
|
LAYOUT_OTHER
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2018-06-03 09:42:43 +04:00
|
|
|
remove_buttons (CcWacomStylusPage *page, int n)
|
2012-01-26 15:42:51 +00:00
|
|
|
{
|
2017-10-10 07:57:49 -07:00
|
|
|
if (n < 3) {
|
|
|
|
gtk_widget_destroy (WID ("combo-thirdbutton"));
|
|
|
|
gtk_widget_destroy (WID ("label-third-button"));
|
|
|
|
}
|
2017-10-10 07:44:02 -07:00
|
|
|
if (n < 2) {
|
|
|
|
gtk_widget_destroy (WID ("combo-topbutton"));
|
|
|
|
gtk_widget_destroy (WID ("label-top-button"));
|
|
|
|
gtk_label_set_text (GTK_LABEL (WID ("label-lower-button")), _("Button"));
|
|
|
|
}
|
|
|
|
if (n < 1) {
|
|
|
|
gtk_widget_destroy (WID ("combo-bottombutton"));
|
|
|
|
gtk_widget_destroy (WID ("label-lower-button"));
|
|
|
|
}
|
2012-01-26 15:42:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-06-03 09:42:43 +04:00
|
|
|
remove_eraser (CcWacomStylusPage *page)
|
2012-01-26 15:42:51 +00:00
|
|
|
{
|
|
|
|
gtk_widget_destroy (WID ("eraser-box"));
|
|
|
|
gtk_widget_destroy (WID ("label-eraser-feel"));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_stylus_ui (CcWacomStylusPage *page,
|
|
|
|
int layout)
|
|
|
|
{
|
|
|
|
switch (layout) {
|
|
|
|
case LAYOUT_NORMAL:
|
2018-06-03 09:42:43 +04:00
|
|
|
remove_buttons (page, 2);
|
2012-01-26 15:42:51 +00:00
|
|
|
break;
|
|
|
|
case LAYOUT_INKING:
|
2018-06-03 09:42:43 +04:00
|
|
|
remove_buttons (page, 0);
|
|
|
|
remove_eraser (page);
|
2012-02-16 19:37:09 +01:00
|
|
|
gtk_container_child_set (CWID ("stylus-controls-grid"),
|
2012-01-26 15:42:51 +00:00
|
|
|
WID ("label-tip-feel"),
|
2012-02-16 19:37:09 +01:00
|
|
|
"top_attach", 0, NULL);
|
|
|
|
gtk_container_child_set (CWID ("stylus-controls-grid"),
|
2012-01-26 15:42:51 +00:00
|
|
|
WID ("box-tip-feel"),
|
2012-02-16 19:37:09 +01:00
|
|
|
"top_attach", 0, NULL);
|
2012-01-26 15:42:51 +00:00
|
|
|
break;
|
|
|
|
case LAYOUT_AIRBRUSH:
|
2018-06-03 09:42:43 +04:00
|
|
|
remove_buttons (page, 1);
|
2012-02-16 19:37:09 +01:00
|
|
|
gtk_container_child_set (CWID ("stylus-controls-grid"),
|
2012-01-26 15:42:51 +00:00
|
|
|
WID ("label-lower-button"),
|
2012-02-16 19:37:09 +01:00
|
|
|
"top_attach", 1, NULL);
|
|
|
|
gtk_container_child_set (CWID ("stylus-controls-grid"),
|
2012-01-26 15:42:51 +00:00
|
|
|
WID ("combo-bottombutton"),
|
2012-02-16 19:37:09 +01:00
|
|
|
"top_attach", 1, NULL);
|
|
|
|
gtk_container_child_set (CWID ("stylus-controls-grid"),
|
2012-01-26 15:42:51 +00:00
|
|
|
WID ("label-tip-feel"),
|
2012-02-16 19:37:09 +01:00
|
|
|
"top_attach", 2, NULL);
|
|
|
|
gtk_container_child_set (CWID ("stylus-controls-grid"),
|
2012-01-26 15:42:51 +00:00
|
|
|
WID ("box-tip-feel"),
|
2012-02-16 19:37:09 +01:00
|
|
|
"top_attach", 2, NULL);
|
2015-03-13 13:11:10 -04:00
|
|
|
break;
|
|
|
|
case LAYOUT_GENERIC_2_BUTTONS_NO_ERASER:
|
2018-06-03 09:42:43 +04:00
|
|
|
remove_buttons (page, 2);
|
|
|
|
remove_eraser (page);
|
2015-03-13 13:11:10 -04:00
|
|
|
break;
|
2017-10-10 07:56:17 -07:00
|
|
|
case LAYOUT_3DPEN:
|
2018-06-03 09:42:43 +04:00
|
|
|
remove_buttons (page, 3);
|
|
|
|
remove_eraser (page);
|
2017-10-10 07:56:17 -07:00
|
|
|
break;
|
2012-01-26 15:42:51 +00:00
|
|
|
case LAYOUT_OTHER:
|
|
|
|
/* We already warn about it in cc_wacom_stylus_page_new () */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-16 17:18:32 +00:00
|
|
|
GtkWidget *
|
2016-06-06 14:49:13 +02:00
|
|
|
cc_wacom_stylus_page_new (CcWacomTool *stylus)
|
2012-01-16 17:18:32 +00:00
|
|
|
{
|
|
|
|
CcWacomStylusPage *page;
|
2016-06-06 14:49:13 +02:00
|
|
|
guint num_buttons;
|
2012-01-26 15:42:51 +00:00
|
|
|
int layout;
|
2016-06-06 14:49:13 +02:00
|
|
|
gboolean has_eraser;
|
2012-01-16 17:18:32 +00:00
|
|
|
|
2016-06-06 14:49:13 +02:00
|
|
|
g_return_val_if_fail (CC_IS_WACOM_TOOL (stylus), NULL);
|
2012-01-16 17:18:32 +00:00
|
|
|
|
|
|
|
page = g_object_new (CC_TYPE_WACOM_STYLUS_PAGE, NULL);
|
|
|
|
|
2018-06-03 09:42:43 +04:00
|
|
|
page->stylus = stylus;
|
2012-01-16 17:18:32 +00:00
|
|
|
|
|
|
|
/* Icon */
|
2016-06-06 14:49:13 +02:00
|
|
|
set_icon_name (page, "image-stylus", cc_wacom_tool_get_icon_name (stylus));
|
2012-01-16 17:18:32 +00:00
|
|
|
|
|
|
|
/* Settings */
|
2018-06-03 09:42:43 +04:00
|
|
|
page->stylus_settings = cc_wacom_tool_get_settings (stylus);
|
2016-06-06 14:49:13 +02:00
|
|
|
has_eraser = cc_wacom_tool_get_has_eraser (stylus);
|
2012-01-16 17:18:32 +00:00
|
|
|
|
|
|
|
/* Stylus name */
|
2016-06-06 14:49:13 +02:00
|
|
|
gtk_label_set_text (GTK_LABEL (WID ("label-stylus")), cc_wacom_tool_get_name (stylus));
|
2012-01-16 17:18:32 +00:00
|
|
|
|
2016-06-06 14:49:13 +02:00
|
|
|
num_buttons = cc_wacom_tool_get_num_buttons (stylus);
|
2015-03-13 13:11:10 -04:00
|
|
|
if (num_buttons == 0 && !has_eraser)
|
2012-01-26 15:42:51 +00:00
|
|
|
layout = LAYOUT_INKING;
|
2015-03-13 13:11:10 -04:00
|
|
|
else if (num_buttons == 2 && has_eraser)
|
2012-01-26 15:42:51 +00:00
|
|
|
layout = LAYOUT_NORMAL;
|
2015-03-13 13:11:10 -04:00
|
|
|
else if (num_buttons == 1 && has_eraser)
|
2012-01-26 15:42:51 +00:00
|
|
|
layout = LAYOUT_AIRBRUSH;
|
2015-03-13 13:11:10 -04:00
|
|
|
else if (num_buttons == 2 && !has_eraser)
|
|
|
|
layout = LAYOUT_GENERIC_2_BUTTONS_NO_ERASER;
|
2017-10-10 07:56:17 -07:00
|
|
|
else if (num_buttons == 3 && !has_eraser)
|
|
|
|
layout = LAYOUT_3DPEN;
|
2012-01-26 15:42:51 +00:00
|
|
|
else {
|
|
|
|
layout = LAYOUT_OTHER;
|
2018-06-03 09:42:43 +04:00
|
|
|
remove_buttons (page, num_buttons);
|
2012-01-26 15:42:51 +00:00
|
|
|
|
2015-03-13 13:11:10 -04:00
|
|
|
/* Gray out eraser if not available */
|
|
|
|
gtk_widget_set_sensitive (WID ("eraser-box"), has_eraser);
|
|
|
|
gtk_widget_set_sensitive (WID ("label-eraser-feel"), has_eraser);
|
2012-01-26 15:42:51 +00:00
|
|
|
|
|
|
|
g_warning ("The layout of this page is not known, %d buttons, %s eraser",
|
2015-03-13 13:11:10 -04:00
|
|
|
num_buttons, has_eraser ? "with" : "without");
|
2012-01-16 17:18:32 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 15:42:51 +00:00
|
|
|
update_stylus_ui (page, layout);
|
|
|
|
|
2017-10-10 07:57:49 -07:00
|
|
|
if (num_buttons >= 3)
|
|
|
|
set_button_mapping_from_gsettings (GTK_COMBO_BOX (WID ("combo-thirdbutton")),
|
2018-06-03 09:42:43 +04:00
|
|
|
page->stylus_settings, "tertiary-button-action");
|
2017-10-10 07:57:29 -07:00
|
|
|
if (num_buttons >= 2)
|
2016-06-06 14:49:13 +02:00
|
|
|
set_button_mapping_from_gsettings (GTK_COMBO_BOX (WID ("combo-topbutton")),
|
2018-06-03 09:42:43 +04:00
|
|
|
page->stylus_settings, "secondary-button-action");
|
2012-01-27 11:08:17 +00:00
|
|
|
if (num_buttons >= 1)
|
2016-06-06 14:49:13 +02:00
|
|
|
set_button_mapping_from_gsettings (GTK_COMBO_BOX (WID ("combo-bottombutton")),
|
2018-06-03 09:42:43 +04:00
|
|
|
page->stylus_settings, "button-action");
|
2016-06-06 14:49:13 +02:00
|
|
|
set_feel_from_gsettings (GTK_ADJUSTMENT (WID ("adjustment-tip-feel")),
|
2018-06-03 09:42:43 +04:00
|
|
|
page->stylus_settings, "pressure-curve");
|
2012-01-16 17:18:32 +00:00
|
|
|
|
2015-03-13 13:11:10 -04:00
|
|
|
if (has_eraser)
|
2016-06-06 14:49:13 +02:00
|
|
|
set_feel_from_gsettings (GTK_ADJUSTMENT (WID ("adjustment-eraser-feel")),
|
2018-06-03 09:42:43 +04:00
|
|
|
page->stylus_settings, "eraser-pressure-curve");
|
2012-01-30 17:00:00 +00:00
|
|
|
|
2012-01-16 17:18:32 +00:00
|
|
|
return GTK_WIDGET (page);
|
|
|
|
}
|
|
|
|
|
2016-06-06 14:49:13 +02:00
|
|
|
CcWacomTool *
|
|
|
|
cc_wacom_stylus_page_get_tool (CcWacomStylusPage *page)
|
2012-02-20 17:09:53 +01:00
|
|
|
{
|
2018-06-03 09:42:43 +04:00
|
|
|
return page->stylus;
|
2012-02-20 17:09:53 +01:00
|
|
|
}
|
|
|
|
|
2012-01-16 17:18:32 +00:00
|
|
|
void
|
|
|
|
cc_wacom_stylus_page_set_navigation (CcWacomStylusPage *page,
|
|
|
|
GtkNotebook *notebook)
|
|
|
|
{
|
|
|
|
g_return_if_fail (CC_IS_WACOM_STYLUS_PAGE (page));
|
|
|
|
|
2018-06-03 09:42:43 +04:00
|
|
|
g_object_set (G_OBJECT (page->nav),
|
2012-01-16 17:18:32 +00:00
|
|
|
"notebook", notebook,
|
2016-06-24 19:21:37 +02:00
|
|
|
"ignore-first", TRUE,
|
2012-01-16 17:18:32 +00:00
|
|
|
NULL);
|
|
|
|
}
|