1 //
2 // Created by ulrich on 22.04.19.
3 //
4 
5 #include "TouchDisableGdk.h"
6 
7 #include <gdk/gdk.h>
8 
9 #include "gui/XournalView.h"
10 
TouchDisableGdk(GtkWidget * widget)11 TouchDisableGdk::TouchDisableGdk(GtkWidget* widget): widget(widget) {}
12 
13 TouchDisableGdk::~TouchDisableGdk() = default;
14 
init()15 void TouchDisableGdk::init() {}
16 
enableTouch()17 void TouchDisableGdk::enableTouch() {
18 #ifdef DEBUG_INPUT
19     g_message("Enable touch");
20 #endif
21 
22     gtk_grab_remove(this->widget);
23     // Todo(@ulrich): replace this with gdk_device_ungrab
24     //                but gdk_device_ungrab is deprecated too, since GTK 3.20
25     //                gtk_seat_ungrab has to be used instead,
26     gdk_pointer_ungrab(GDK_CURRENT_TIME);  // NOLINT
27 }
28 
disableTouch()29 void TouchDisableGdk::disableTouch() {
30 #ifdef DEBUG_INPUT
31     g_message("Disable touch using GDK grabs");
32 #endif
33     GdkWindow* window = gtk_widget_get_window(this->widget);
34 
35     /**
36      * See the following link if window dragging by double clicks on empty widget space occurs
37      * https://www.reddit.com/r/kde/comments/aaeo91
38      */
39     // Todo(@ulrich): replace this with gdk_device_grab
40     //                but gdk_device_grab is deprecated too, since GTK 3.20
41     //                gtk_seat_grab has to be used instead,
42     gdk_pointer_grab(window, false, GDK_TOUCH_MASK, nullptr, nullptr, GDK_CURRENT_TIME);  // NOLINT
43     gtk_grab_add(this->widget);
44 }
45