1 /* === S Y N F I G ========================================================= */
2 /*! \file devicetracker.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2009 Gerco Ballintijn
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 // FIXME: The code here doesn't use the GTKmm layer but uses GTK+ directly
25 // since the GTKmm wrapper for Gdk::Device is incomplete. When the wrapper
26 // gets fixed, this code should be updated accoordingly.
28 /* === H E A D E R S ======================================================= */
37 #include "devicetracker.h"
40 #include <synfigapp/main.h>
46 /* === U S I N G =========================================================== */
50 using namespace synfig;
51 using namespace synfigapp;
52 using namespace studio;
54 /* === M A C R O S ========================================================= */
56 /* === G L O B A L S ======================================================= */
58 /* === P R O C E D U R E S ================================================= */
60 /* === M E T H O D S ======================================================= */
62 DeviceTracker::DeviceTracker()
66 device_list=gdk_devices_list();
68 for(iter=device_list;iter;iter=g_list_next(iter))
70 GdkDevice* device=reinterpret_cast<GdkDevice*>(iter->data);
72 synfigapp::InputDevice::Handle input_device;
73 input_device=synfigapp::Main::add_input_device(device->name,synfigapp::InputDevice::Type(device->source));
74 //Disable all extended devices by default. This tries to fix several
75 // bugs reported in track and forums
76 if( input_device->get_type()==synfigapp::InputDevice::TYPE_MOUSE ||
77 input_device->get_type()==synfigapp::InputDevice::TYPE_PEN ||
78 input_device->get_type()==synfigapp::InputDevice::TYPE_ERASER ||
79 input_device->get_type()==synfigapp::InputDevice::TYPE_CURSOR ) {
80 input_device->set_mode(synfigapp::InputDevice::MODE_DISABLED);
81 //synfigapp::Main::select_input_device(input_device);
84 // Once all devices are disabled be sure that the core pointer is the
85 // one selected. The user should decide later whether enable and save the
86 // rest of input devices found.
87 synfigapp::Main::select_input_device(gdk_device_get_core_pointer()->name);
90 DeviceTracker::~DeviceTracker()
95 DeviceTracker::save_preferences()
97 GList * device_list = gdk_devices_list();
98 for (GList * itr = device_list; itr; itr = g_list_next(itr))
100 GdkDevice * gdk_device = reinterpret_cast<GdkDevice*>(itr->data);
102 InputDevice::Handle synfig_device = synfigapp::Main::find_input_device(gdk_device->name);
103 if (synfig_device == NULL)
106 synfig_device->set_mode(InputDevice::Mode(gdk_device->mode));
107 if (gdk_device->num_axes > 0) {
108 vector<synfigapp::InputDevice::AxisUse> axes;
109 axes.resize(gdk_device->num_axes);
110 for (int i = 0; i < gdk_device->num_axes; i++)
111 axes[i] = InputDevice::AxisUse(gdk_device->axes[i].use);
112 synfig_device->set_axes(axes);
115 if (gdk_device->num_keys > 0) {
116 vector<synfigapp::InputDevice::DeviceKey> keys;
117 keys.resize(gdk_device->num_keys);
118 for (int i = 0; i < gdk_device->num_keys; i++) {
119 keys[i].keyval = gdk_device->keys[i].keyval;
120 keys[i].modifiers = gdk_device->keys[i].modifiers;
122 synfig_device->set_keys(keys);
128 DeviceTracker::load_preferences()
130 GList * device_list = gdk_devices_list();
131 for (GList * itr = device_list; itr; itr = g_list_next(itr))
133 GdkDevice * gdk_device = reinterpret_cast<GdkDevice*>(itr->data);
135 InputDevice::Handle synfig_device = synfigapp::Main::find_input_device(gdk_device->name);
136 if (synfig_device == NULL)
139 gdk_device_set_mode(gdk_device, GdkInputMode(synfig_device->get_mode()));
141 const std::vector<synfigapp::InputDevice::AxisUse> axes = synfig_device->get_axes();
142 for (int axis = 0; axis < (int) axes.size(); axis++)
143 gdk_device_set_axis_use(gdk_device, axis, GdkAxisUse(axes[axis]));
145 const std::vector<synfigapp::InputDevice::DeviceKey> keys = synfig_device->get_keys();
146 for (int key = 0; key < (int) keys.size(); key++)
147 gdk_device_set_key(gdk_device, key, keys[key].keyval,
148 GdkModifierType(keys[key].modifiers));