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 if(input_device->get_type()==synfigapp::InputDevice::TYPE_MOUSE) {
75 input_device->set_mode(synfigapp::InputDevice::MODE_SCREEN);
76 synfigapp::Main::select_input_device(input_device);
81 DeviceTracker::~DeviceTracker()
86 DeviceTracker::save_preferences()
88 GList * device_list = gdk_devices_list();
89 for (GList * itr = device_list; itr; itr = g_list_next(itr))
91 GdkDevice * gdk_device = reinterpret_cast<GdkDevice*>(itr->data);
93 InputDevice::Handle synfig_device = synfigapp::Main::find_input_device(gdk_device->name);
94 if (synfig_device == NULL)
97 synfig_device->set_mode(InputDevice::Mode(gdk_device->mode));
98 if (gdk_device->num_axes > 0) {
99 vector<synfigapp::InputDevice::AxisUse> axes;
100 axes.resize(gdk_device->num_axes);
101 for (int i = 0; i < gdk_device->num_axes; i++)
102 axes[i] = InputDevice::AxisUse(gdk_device->axes[i].use);
103 synfig_device->set_axes(axes);
106 if (gdk_device->num_keys > 0) {
107 vector<synfigapp::InputDevice::DeviceKey> keys;
108 keys.resize(gdk_device->num_keys);
109 for (int i = 0; i < gdk_device->num_keys; i++) {
110 keys[i].keyval = gdk_device->keys[i].keyval;
111 keys[i].modifiers = gdk_device->keys[i].modifiers;
113 synfig_device->set_keys(keys);
119 DeviceTracker::load_preferences()
121 GList * device_list = gdk_devices_list();
122 for (GList * itr = device_list; itr; itr = g_list_next(itr))
124 GdkDevice * gdk_device = reinterpret_cast<GdkDevice*>(itr->data);
126 InputDevice::Handle synfig_device = synfigapp::Main::find_input_device(gdk_device->name);
127 if (synfig_device == NULL)
130 gdk_device_set_mode(gdk_device, GdkInputMode(synfig_device->get_mode()));
132 const std::vector<synfigapp::InputDevice::AxisUse> axes = synfig_device->get_axes();
133 for (int axis = 0; axis < (int) axes.size(); axis++)
134 gdk_device_set_axis_use(gdk_device, axis, GdkAxisUse(axes[axis]));
136 const std::vector<synfigapp::InputDevice::DeviceKey> keys = synfig_device->get_keys();
137 for (int key = 0; key < (int) keys.size(); key++)
138 gdk_device_set_key(gdk_device, key, keys[key].keyval,
139 GdkModifierType(keys[key].modifiers));