diff options
Diffstat (limited to 'src/device-manager.cpp')
| -rw-r--r-- | src/device-manager.cpp | 93 |
1 files changed, 89 insertions, 4 deletions
diff --git a/src/device-manager.cpp b/src/device-manager.cpp index e5864e84b..adac83fed 100644 --- a/src/device-manager.cpp +++ b/src/device-manager.cpp @@ -17,16 +17,53 @@ #define noDEBUG_VERBOSE 1 + +// This is a copy of the private fields of the GdkDevice object, used in order +// to create a list of "fake" devices. +struct GdkDeviceFake { + gchar *name; + GdkInputSource source; + GdkInputMode mode; + gboolean has_cursor; + gint num_axes; + GdkDeviceAxis *axes; + gint num_keys; + GdkDeviceKey *keys; +}; + + static void createFakeList(); -GdkDevice fakeout[5]; +GdkDeviceFake fakeout[5]; static GList* fakeList = 0; static bool isValidDevice(GdkDevice *device) { bool valid = true; for (size_t i = 0; (i < G_N_ELEMENTS(fakeout)) && valid; i++) { - valid = (device != &fakeout[i]); + // Ideally, we should probably check all fields of the GdkDevice +#if GTK_CHECK_VERSION (2, 22, 0) + gboolean name_matches = (g_strcmp0 (gdk_device_get_name (device), fakeout[i].name) == 0); + gboolean source_matches = (gdk_device_get_source (device) == fakeout[i].source); + gboolean mode_matches = (gdk_device_get_mode (device) == fakeout[i].mode); + gboolean num_axes_matches = (gdk_device_get_n_axes (device) == fakeout[i].num_axes); +#else + gboolean name_matches = (g_strcmp0 (device->name, fakeout[i].name) == 0); + gboolean source_matches = (device->source == fakeout[i].source); + gboolean mode_matches = (device->mode == fakeout[i].mode); + gboolean num_axes_matches = (device->num_axes == fakeout[i].num_axes); +#endif + +#if GTK_CHECK_VERSION (2, 24, 0) + gboolean num_keys_matches = (gdk_device_get_n_keys (device) == fakeout[i].num_keys); +#else + gboolean num_keys_matches = (device->num_keys == fakeout[i].num_keys); +#endif + + if (name_matches && source_matches && mode_matches + && num_axes_matches && num_keys_matches) + valid = false; } + return valid; } @@ -141,9 +178,16 @@ public: virtual Glib::ustring getId() const {return id;} virtual Glib::ustring getName() const {return name;} virtual Gdk::InputSource getSource() const {return source;} + +#if GTK_CHECK_VERSION (2, 22, 0) virtual Gdk::InputMode getMode() const {return static_cast<Gdk::InputMode>(gdk_device_get_mode (device));} - virtual bool hasCursor() const {return gdk_device_get_has_cursor (device);} virtual gint getNumAxes() const {return gdk_device_get_n_axes (device);} +#else + virtual Gdk::InputMode getMode() const {return static_cast<Gdk::InputMode>(device->mode);} + virtual gint getNumAxes() const {return device->num_axes;} +#endif + + virtual bool hasCursor() const {return gdk_device_get_has_cursor (device);} virtual gint getNumKeys() const { // Backward-compatibility: The GSEAL-compliant // gdk_device_get_n_keys function was only introduced @@ -201,8 +245,13 @@ InputDeviceImpl::InputDeviceImpl(GdkDevice* device, std::set<Glib::ustring> &kno : InputDevice(), device(device), id(), +#if GTK_CHECK_VERSION (2, 22, 0) name(gdk_device_get_name (device) ? gdk_device_get_name (device) : ""), source(static_cast<Gdk::InputSource>(gdk_device_get_source (device))), +#else + name(device->name ? device->name : ""), + source(static_cast<Gdk::InputSource>(device->source)), +#endif link(), liveAxes(0), liveButtons(0) @@ -384,7 +433,11 @@ void DeviceManagerImpl::saveConfig() tmp += ";"; } GdkDevice *device = (*it)->getDevice(); +#if GTK_CHECK_VERSION (2, 22, 0) tmp += getAxisToString()[static_cast<Gdk::AxisUse>(gdk_device_get_axis_use (device, i))]; +#else + tmp += getAxisToString()[static_cast<Gdk::AxisUse>(device->axis[i].use)]; +#endif } prefs->setString( path + "/axes", tmp ); @@ -394,10 +447,14 @@ void DeviceManagerImpl::saveConfig() tmp += ";"; } GdkDevice *device = (*it)->getDevice(); +#if GTK_CHECK_VERSION (2, 22, 0) guint keyval; GdkModifierType modifiers; gdk_device_get_key (device, i, &keyval, &modifiers); tmp += gtk_accelerator_name(keyval, modifiers); +#else + tmp += gtk_accelerator_name(device->keys[i].keyval, device->keys[i].modifiers); +#endif } prefs->setString( path + "/keys", tmp ); } @@ -436,7 +493,11 @@ void DeviceManagerImpl::setAxisUse( Glib::ustring const & id, guint index, Gdk:: if (static_cast<gint>(index) <= (*it)->getNumAxes()) { GdkDevice *device = (*it)->getDevice(); +#if GTK_CHECK_VERSION (2, 22, 0) if (gdk_device_get_axis_use (device, index) != static_cast<GdkAxisUse>(use)) { +#else + if (device->axes[index].use != static_cast<GdkAxisUse>(use)) { +#endif gdk_device_set_axis_use(device, index, static_cast<GdkAxisUse>(use)); signalDeviceChangedPriv.emit(*it); } @@ -674,11 +735,35 @@ static void createFakeList() { // try to find the first *real* core pointer GList* devList = gdk_devices_list(); +#if GTK_CHECK_VERSION (2, 22, 0) while ( devList && devList->data && (gdk_device_get_source ((GdkDevice*)devList->data) != GDK_SOURCE_MOUSE)) { +#else + while ( devList && devList->data && (((GdkDevice*)devList->data)->source != GDK_SOURCE_MOUSE)) { +#endif devList = g_list_next(devList); } if ( devList && devList->data ) { - fakeout[4] = *((GdkDevice*)devList->data); + //fakeout[4] = *((GdkDevice*)devList->data); + // We should probably copy the axes and keys too + GdkDevice *device = (GdkDevice*)devList->data; +#if GTK_CHECK_VERSION (2, 22, 0) + fakeout[4].name = g_strdup(gdk_device_get_name (device)); + fakeout[4].source = gdk_device_get_source (device); + fakeout[4].mode = gdk_device_get_mode (device); + fakeout[4].has_cursor = gdk_device_get_has_cursor (device); + fakeout[4].num_axes = gdk_device_get_n_axes (device); +#else + fakeout[4].name = g_strdup(device->name); + fakeout[4].source = device->source; + fakeout[4].mode = device->mode; + fakeout[4].num_axes = device->num_axes; +#endif + fakeout[4].has_cursor = gdk_device_get_has_cursor (device); +#if GTK_CHECK_VERSION (2, 24, 0) + fakeout[4].num_keys = gdk_device_get_n_keys (device); +#else + fakeout[4].num_keys = device->num_keys; +#endif } else { fakeout[4].name = g_strdup("Core Pointer"); fakeout[4].source = GDK_SOURCE_MOUSE; |
