Handle bad state, if an event is missing

presentation
Andreas Butti 7 years ago
parent 6a287f248e
commit 018c68ef5e
  1. 39
      src/gui/inputdevices/InputSequence.cpp
  2. 8
      src/gui/inputdevices/InputSequence.h
  3. 16
      src/gui/inputdevices/NewGtkInputDevice.cpp

@ -48,6 +48,9 @@ InputSequence::~InputSequence()
}
clearAxes();
// Make 100% sure there is no input running
stopInput();
XOJ_RELEASE_TYPE(InputSequence);
}
@ -354,6 +357,42 @@ bool InputSequence::actionStart()
return false;
}
/**
* Check if input is still running, or if there an event was missed
*
* @return true if input is stopped now
*/
bool InputSequence::checkStillRunning()
{
if (!inputRunning)
{
// Already stopped
return true;
}
GdkModifierType mask = (GdkModifierType) 0;
GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(inputHandler->getXournal()));
gdk_device_get_state(device, window, NULL, &mask);
if ((GDK_BUTTON1_MASK & mask) ||
(GDK_BUTTON2_MASK & mask) ||
(GDK_BUTTON3_MASK & mask) ||
(GDK_BUTTON4_MASK & mask) ||
(GDK_BUTTON5_MASK & mask))
{
// Button still down
// Input is still running, probably everything OK
return false;
}
// Button is not down, stop input now!
// So the new input can start
actionEnd();
return true;
}
/**
* Mouse / Pen up / touch end
*/

@ -43,12 +43,18 @@ public:
*/
void actionEnd();
/**
* Check if input is still running, or if there an event was missed
*
* @return true if input is stopped now
*/
bool checkStillRunning();
/**
* Set current input device
*/
void setDevice(GdkDevice* device);
/**
* Clear the last stored axes
*/

@ -69,11 +69,27 @@ bool NewGtkInputDevice::startInput(InputSequence* input)
{
XOJ_CHECK_TYPE(NewGtkInputDevice);
if (inputRunning == input)
{
g_warning("Input for the same device started twice!");
return true;
}
if (inputRunning == NULL)
{
inputRunning = input;
return true;
}
else
{
if (inputRunning->checkStillRunning())
{
g_warning("Input was not stopped correctly!");
inputRunning = input;
return true;
}
}
return false;
}

Loading…
Cancel
Save