Code

Split data mode apart from UI and added button trackers
[inkscape.git] / src / device-manager.cpp
2 /*
3  * Inkscape::DeviceManager - a view of input devices available.
4  *
5  * Copyright 2006  Jon A. Cruz  <jon@joncruz.org>
6  *
7  * Released under GNU GPL, read the file 'COPYING' for more information
8  */
10 #include <glib.h>
12 #include "device-manager.h"
15 static void createFakeList();
16 GdkDevice fakeout[5];
17 static GList* fakeList = 0;
20 namespace Inkscape {
22 InputDevice::InputDevice() {}
23 InputDevice::~InputDevice() {}
25 class InputDeviceImpl : public InputDevice {
26 public:
27     virtual Glib::ustring getName() const {return Glib::ustring(device->name);}
28     virtual Gdk::InputSource getSource() const {return static_cast<Gdk::InputSource>(device->source);}
29     virtual Gdk::InputMode getMode() const {return static_cast<Gdk::InputMode>(device->mode);}
30     virtual bool hasCursor() const {return device->has_cursor;}
31     virtual gint getNumAxes() const {return device->num_axes;}
32     virtual gint getNumKeys() const {return device->num_keys;}
34     InputDeviceImpl(GdkDevice* device);
35     virtual ~InputDeviceImpl() {}
37 private:
38     InputDeviceImpl(InputDeviceImpl const &); // no copy
39     void operator=(InputDeviceImpl const &); // no assign
41     GdkDevice* device;
42 };
44 InputDeviceImpl::InputDeviceImpl(GdkDevice* device)
45     : InputDevice(),
46       device(device)
47 {
48 }
57 class DeviceManagerImpl : public DeviceManager {
58 public:
59     DeviceManagerImpl();
60     virtual std::list<InputDevice const *> getDevices();
62 protected:
63     std::list<InputDeviceImpl*> devices;
64 };
66 DeviceManagerImpl::DeviceManagerImpl() :
67     DeviceManager(),
68     devices()
69 {
70     GList* devList = gdk_devices_list();
72     if ( !fakeList ) {
73         createFakeList();
74     }
75     devList = fakeList;
77     for ( GList* curr = devList; curr; curr = g_list_next(curr) ) {
78         GdkDevice* dev = reinterpret_cast<GdkDevice*>(curr->data);
79         if ( dev ) {
80 //             g_message("device: name[%s] source[0x%x] mode[0x%x] cursor[%s] axis count[%d] key count[%d]", dev->name, dev->source, dev->mode,
81 //                       dev->has_cursor?"Yes":"no", dev->num_axes, dev->num_keys);
83             InputDeviceImpl* device = new InputDeviceImpl(dev);
84             devices.push_back(device);
85         }
86     }
87 }
89 std::list<InputDevice const *> DeviceManagerImpl::getDevices()
90 {
91     std::list<InputDevice const *> tmp;
92     for ( std::list<InputDeviceImpl*>::const_iterator it = devices.begin(); it != devices.end(); ++it ) {
93         tmp.push_back(*it);
94     }
95     return tmp;
96 }
99 static DeviceManagerImpl* theInstance = 0;
101 DeviceManager::DeviceManager() {
104 DeviceManager::~DeviceManager() {
107 DeviceManager& DeviceManager::getManager() {
108     if ( !theInstance ) {
109         theInstance = new DeviceManagerImpl();
110     }
112     return *theInstance;
115 } // namespace Inkscape
122 GdkDeviceAxis padAxes[] = {{GDK_AXIS_X, 0.0, 0.0},
123                            {GDK_AXIS_Y, 0.0, 0.0},
124                            {GDK_AXIS_PRESSURE, 0.0, 1.0},
125                            {GDK_AXIS_XTILT, -1.0, 1.0},
126                            {GDK_AXIS_YTILT, -1.0, 1.0},
127                            {GDK_AXIS_WHEEL, 0.0, 1.0}};
128 GdkDeviceKey padKeys[] = {{0, (GdkModifierType)0}, {0, (GdkModifierType)0}, {0, (GdkModifierType)0}, {0, (GdkModifierType)0},
129                           {0, (GdkModifierType)0}, {0, (GdkModifierType)0}, {0, (GdkModifierType)0}, {0, (GdkModifierType)0}};
131 GdkDeviceAxis eraserAxes[] = {{GDK_AXIS_X, 0.0, 0.0},
132                               {GDK_AXIS_Y, 0.0, 0.0},
133                               {GDK_AXIS_PRESSURE, 0.0, 1.0},
134                               {GDK_AXIS_XTILT, -1.0, 1.0},
135                               {GDK_AXIS_YTILT, -1.0, 1.0},
136                               {GDK_AXIS_WHEEL, 0.0, 1.0}};
137 GdkDeviceKey eraserKeys[] = {{0, (GdkModifierType)0}, {0, (GdkModifierType)0}, {0, (GdkModifierType)0}, {0, (GdkModifierType)0},
138                              {0, (GdkModifierType)0}, {0, (GdkModifierType)0}, {0, (GdkModifierType)0}};
140 GdkDeviceAxis cursorAxes[] = {{GDK_AXIS_X, 0.0, 0.0},
141                               {GDK_AXIS_Y, 0.0, 0.0},
142                               {GDK_AXIS_PRESSURE, 0.0, 1.0},
143                               {GDK_AXIS_XTILT, -1.0, 1.0},
144                               {GDK_AXIS_YTILT, -1.0, 1.0},
145                               {GDK_AXIS_WHEEL, 0.0, 1.0}};
146 GdkDeviceKey cursorKeys[] = {{0, (GdkModifierType)0}, {0, (GdkModifierType)0}, {0, (GdkModifierType)0}, {0, (GdkModifierType)0},
147                              {0, (GdkModifierType)0}, {0, (GdkModifierType)0}, {0, (GdkModifierType)0}};
149 GdkDeviceAxis stylusAxes[] = {{GDK_AXIS_X, 0.0, 0.0},
150                               {GDK_AXIS_Y, 0.0, 0.0},
151                               {GDK_AXIS_PRESSURE, 0.0, 1.0},
152                               {GDK_AXIS_XTILT, -1.0, 1.0},
153                               {GDK_AXIS_YTILT, -1.0, 1.0},
154                               {GDK_AXIS_WHEEL, 0.0, 1.0}};
155 GdkDeviceKey stylusKeys[] = {{0, (GdkModifierType)0}, {0, (GdkModifierType)0}, {0, (GdkModifierType)0}, {0, (GdkModifierType)0},
156                              {0, (GdkModifierType)0}, {0, (GdkModifierType)0}, {0, (GdkModifierType)0}};
159 GdkDeviceAxis coreAxes[] = {{GDK_AXIS_X, 0.0, 0.0},
160                             {GDK_AXIS_Y, 0.0, 0.0}};
162 static void createFakeList() {
163     if ( !fakeList ) {
164         fakeout[0].name = "pad";
165         fakeout[0].source = GDK_SOURCE_PEN;
166         fakeout[0].mode = GDK_MODE_SCREEN;
167         fakeout[0].has_cursor = TRUE;
168         fakeout[0].num_axes = 6;
169         fakeout[0].axes = padAxes;
170         fakeout[0].num_keys = 8;
171         fakeout[0].keys = padKeys;
173         fakeout[1].name = "eraser";
174         fakeout[1].source = GDK_SOURCE_ERASER;
175         fakeout[1].mode = GDK_MODE_SCREEN;
176         fakeout[1].has_cursor = TRUE;
177         fakeout[1].num_axes = 6;
178         fakeout[1].axes = eraserAxes;
179         fakeout[1].num_keys = 7;
180         fakeout[1].keys = eraserKeys;
182         fakeout[2].name = "cursor";
183         fakeout[2].source = GDK_SOURCE_CURSOR;
184         fakeout[2].mode = GDK_MODE_SCREEN;
185         fakeout[2].has_cursor = TRUE;
186         fakeout[2].num_axes = 6;
187         fakeout[2].axes = cursorAxes;
188         fakeout[2].num_keys = 7;
189         fakeout[2].keys = cursorKeys;
191         fakeout[3].name = "stylus";
192         fakeout[3].source = GDK_SOURCE_PEN;
193         fakeout[3].mode = GDK_MODE_SCREEN;
194         fakeout[3].has_cursor = TRUE;
195         fakeout[3].num_axes = 6;
196         fakeout[3].axes = stylusAxes;
197         fakeout[3].num_keys = 7;
198         fakeout[3].keys = stylusKeys;
200         fakeout[4].name = "Core Pointer";
201         fakeout[4].source = GDK_SOURCE_MOUSE;
202         fakeout[4].mode = GDK_MODE_SCREEN;
203         fakeout[4].has_cursor = TRUE;
204         fakeout[4].num_axes = 2;
205         fakeout[4].axes = coreAxes;
206         fakeout[4].num_keys = 0;
207         fakeout[4].keys = NULL;
209         for ( guint pos = 0; pos < G_N_ELEMENTS(fakeout); pos++) {
210             fakeList = g_list_append(fakeList, &(fakeout[pos]));
211         }
212     }
216 /*
217   Local Variables:
218   mode:c++
219   c-file-style:"stroustrup"
220   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
221   indent-tabs-mode:nil
222   fill-column:99
223   End:
224 */
225 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :