Fix warnings calling system in callbacks without checking the result. For that task the wrapper Util::systemWithMessage was created.

presentation
Pablo Alvarado-Moya 6 years ago committed by Fabian Keßler
parent 3e9874e496
commit 6a8b7a3b43
  1. 1
      src/control/pagetype/PageTypeHandler.cpp
  2. 4
      src/gui/dialog/SettingsDialog.cpp
  3. 7
      src/gui/inputdevices/touchdisable/TouchDisableCustom.cpp
  4. 6
      src/gui/inputdevices/touchdisable/TouchDisableGdk.cpp
  5. 8
      src/util/Util.cpp
  6. 5
      src/util/Util.h
  7. 4
      test/SpeedTest.cpp

@ -145,4 +145,5 @@ auto PageTypeHandler::getStringForPageTypeFormat(const PageTypeFormat& format) -
case PageTypeFormat::Copy:
return ":copy";
}
return "ruled";
}

@ -36,12 +36,12 @@ SettingsDialog::SettingsDialog(GladeSearchpath* gladeSearchPath, Settings* setti
g_signal_connect(get("btTestEnable"), "clicked", G_CALLBACK(+[](GtkButton* bt, SettingsDialog* self) {
system(gtk_entry_get_text(GTK_ENTRY(self->get("txtEnableTouchCommand"))));
Util::systemWithMessage(gtk_entry_get_text(GTK_ENTRY(self->get("txtEnableTouchCommand"))));
}),
this);
g_signal_connect(get("btTestDisable"), "clicked", G_CALLBACK(+[](GtkButton* bt, SettingsDialog* self) {
system(gtk_entry_get_text(GTK_ENTRY(self->get("txtDisableTouchCommand"))));
Util::systemWithMessage(gtk_entry_get_text(GTK_ENTRY(self->get("txtDisableTouchCommand"))));
}),
this);

@ -2,11 +2,14 @@
#include <utility>
#include "Util.h"
TouchDisableCustom::TouchDisableCustom(string enableCommand, string disableCommand):
enableCommand(std::move(enableCommand)), disableCommand(std::move(disableCommand)) {}
TouchDisableCustom::~TouchDisableCustom() = default;
void TouchDisableCustom::enableTouch() { system(enableCommand.c_str()); }
void TouchDisableCustom::enableTouch() { Util::systemWithMessage(enableCommand.c_str()); }
void TouchDisableCustom::disableTouch() { system(disableCommand.c_str()); }
void TouchDisableCustom::disableTouch() { Util::systemWithMessage(disableCommand.c_str()); }

@ -21,6 +21,8 @@ void TouchDisableGdk::enableTouch() {
gtk_grab_remove(this->widget);
// Todo(@ulrich): replace this with gdk_device_ungrab
// but gdk_device_ungrab is deprecated too, since GTK 3.20
// gtk_seat_ungrab has to be used instead,
gdk_pointer_ungrab(GDK_CURRENT_TIME); // NOLINT
}
@ -34,7 +36,9 @@ void TouchDisableGdk::disableTouch() {
* See the following link if window dragging by double clicks on empty widget space occurs
* https://www.reddit.com/r/kde/comments/aaeo91
*/
// Todo(@ulrich): replace this with gdk_device_ungrab
// Todo(@ulrich): replace this with gdk_device_grab
// but gdk_device_grab is deprecated too, since GTK 3.20
// gtk_seat_grab has to be used instead,
gdk_pointer_grab(window, false, GDK_TOUCH_MASK, nullptr, nullptr, GDK_CURRENT_TIME); // NOLINT
gtk_grab_add(this->widget);
}

@ -1,6 +1,7 @@
#include "Util.h"
#include <array>
#include <cstdlib>
#include <utility>
#include <unistd.h>
@ -160,3 +161,10 @@ void Util::writeCoordinateString(OutputStream* out, double xVal, double yVal) {
g_ascii_formatd(coordString.data(), G_ASCII_DTOSTR_BUF_SIZE, Util::PRECISION_FORMAT_STRING, yVal);
out->write(coordString.data());
}
void Util::systemWithMessage(const char* command) {
if (auto errc = std::system(command); errc != 0) {
string msg = FS(_F("Error {1} executing system command: {2}") % errc % command);
XojMsgBox::showErrorToUser(nullptr, msg);
}
}

@ -44,6 +44,11 @@ Path getTmpDirSubfolder(const Path& subfolder = "");
Path ensureFolderExists(const Path& p);
/**
* Wrap the system call to redirect errors to a dialog
*/
void systemWithMessage(const char* command);
/**
* Execute the callback in the UI Thread.
*

@ -50,6 +50,8 @@ private:
static void printMemory() {
string cmd = "bash -c \"cat /proc/";
cmd += std::to_string(::getpid()) + "/status | grep Vm\"";
system(cmd.c_str());
if (system(cmd.c_str()) != 0) {
cout << "Error executing " << cmd.c_str() << endl;
};
}
};

Loading…
Cancel
Save