From 934fa2ccd4391d31185e514410070b52d3723a66 Mon Sep 17 00:00:00 2001 From: Andreas Butti Date: Mon, 28 Jan 2019 20:03:55 +0100 Subject: [PATCH] Fixed #764 Do not allow to configure GTK Touch Screen - there is a separated tab for this, and this causes crashes on some devices --- src/gui/dialog/ButtonConfigGui.cpp | 15 +++++++++------ src/gui/dialog/ButtonConfigGui.h | 3 +++ src/gui/dialog/SettingsDialog.cpp | 2 +- src/util/DeviceListHelper.cpp | 8 +++++++- src/util/DeviceListHelper.h | 4 +++- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/gui/dialog/ButtonConfigGui.cpp b/src/gui/dialog/ButtonConfigGui.cpp index 5609f2d6..a86d9588 100644 --- a/src/gui/dialog/ButtonConfigGui.cpp +++ b/src/gui/dialog/ButtonConfigGui.cpp @@ -34,8 +34,8 @@ ButtonConfigGui::ButtonConfigGui(SettingsDialog* dlg, GladeSearchpath* gladeSear { gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(this->cbDevice), _("No device")); - DeviceListHelper devList; - for (InputDevice& dev : devList.getDeviceList()) + this->deviceList = new DeviceListHelper(true); + for (InputDevice& dev : this->deviceList->getDeviceList()) { string txt = dev.getName() + " (" + dev.getType() + ")"; gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(this->cbDevice), txt.c_str()); @@ -111,6 +111,11 @@ ButtonConfigGui::ButtonConfigGui(SettingsDialog* dlg, GladeSearchpath* gladeSear ButtonConfigGui::~ButtonConfigGui() { + XOJ_CHECK_TYPE(ButtonConfigGui); + + delete this->deviceList; + this->deviceList = NULL; + XOJ_RELEASE_TYPE(ButtonConfigGui); } @@ -198,8 +203,7 @@ void ButtonConfigGui::loadSettings() int i = 0; - DeviceListHelper devList; - for (InputDevice& dev : devList.getDeviceList()) + for (InputDevice& dev : this->deviceList->getDeviceList()) { if (cfg->device == dev.getName()) { @@ -283,8 +287,7 @@ void ButtonConfigGui::saveSettings() if (this->withDevice) { - DeviceListHelper devList; - std::vector& devices = devList.getDeviceList(); + std::vector& devices = this->deviceList->getDeviceList(); int dev = gtk_combo_box_get_active(GTK_COMBO_BOX(cbDevice)) - 1; if (dev < 0 || (int)devices.size() <= dev) diff --git a/src/gui/dialog/ButtonConfigGui.h b/src/gui/dialog/ButtonConfigGui.h index ccd92ef5..548d02cf 100644 --- a/src/gui/dialog/ButtonConfigGui.h +++ b/src/gui/dialog/ButtonConfigGui.h @@ -16,6 +16,7 @@ #include +class DeviceListHelper; class Settings; class SettingsDialog; @@ -44,6 +45,8 @@ private: int button; bool withDevice; + DeviceListHelper* deviceList = NULL; + GtkWidget* cbDevice; GtkWidget* cbDisableDrawing; diff --git a/src/gui/dialog/SettingsDialog.cpp b/src/gui/dialog/SettingsDialog.cpp index f90c6476..f69c0e2d 100644 --- a/src/gui/dialog/SettingsDialog.cpp +++ b/src/gui/dialog/SettingsDialog.cpp @@ -75,7 +75,7 @@ void SettingsDialog::initMouseButtonEvents(const char* hbox, int button, bool wi { XOJ_CHECK_TYPE(SettingsDialog); - this->buttonConfigs.push_back(new ButtonConfigGui(this, getGladeSearchPath(), get(hbox),settings, button, withDevice)); + this->buttonConfigs.push_back(new ButtonConfigGui(this, getGladeSearchPath(), get(hbox), settings, button, withDevice)); } void SettingsDialog::initMouseButtonEvents() diff --git a/src/util/DeviceListHelper.cpp b/src/util/DeviceListHelper.cpp index f70ecfdc..93aa071d 100644 --- a/src/util/DeviceListHelper.cpp +++ b/src/util/DeviceListHelper.cpp @@ -3,7 +3,8 @@ #include -DeviceListHelper::DeviceListHelper() +DeviceListHelper::DeviceListHelper(bool ignoreTouchDevices) + : ignoreTouchDevices(ignoreTouchDevices) { // For never GTK versions, see example here: // https://cvs.gnucash.org/docs/MASTER/gnc-cell-renderer-popup_8c_source.html @@ -33,6 +34,11 @@ void DeviceListHelper::addDevicesToList(GList* devList) devList = devList->next; continue; } + if (ignoreTouchDevices && GDK_SOURCE_TOUCHSCREEN == gdk_device_get_source(dev)) + { + devList = devList->next; + continue; + } deviceList.push_back(InputDevice(dev)); devList = devList->next; diff --git a/src/util/DeviceListHelper.h b/src/util/DeviceListHelper.h index e8d95217..3630c1f0 100644 --- a/src/util/DeviceListHelper.h +++ b/src/util/DeviceListHelper.h @@ -40,7 +40,7 @@ private: class DeviceListHelper { public: - DeviceListHelper(); + DeviceListHelper(bool ignoreTouchDevices = false); virtual ~DeviceListHelper(); public: @@ -50,5 +50,7 @@ private: void addDevicesToList(GList* devList); private: + bool ignoreTouchDevices; + vector deviceList; };