diff options
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/ScintillaGTK.cxx | 35 | ||||
-rw-r--r-- | gtk/ScintillaGTK.h | 2 |
2 files changed, 37 insertions, 0 deletions
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index 753a52c3b..993aa8fbd 100644 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -7,6 +7,7 @@ #include <string.h> #include <stdio.h> #include <time.h> +#include <math.h> #include <assert.h> #include <ctype.h> @@ -22,6 +23,9 @@ #include <gdk/gdk.h> #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> +#if defined(GDK_WINDOWING_WAYLAND) +#include <gdk/gdkwayland.h> +#endif #if defined(__WIN32__) || defined(_MSC_VER) #include <windows.h> @@ -165,6 +169,8 @@ ScintillaGTK::ScintillaGTK(_ScintillaObject *sci_) : im_context(NULL), lastNonCommonScript(PANGO_SCRIPT_INVALID_CODE), lastWheelMouseDirection(0), wheelMouseIntensity(0), + smoothScrollY(0), + smoothScrollX(0), rgnUpdate(0), repaintFullWindow(false), styleIdleID(0), @@ -545,11 +551,21 @@ void ScintillaGTK::Initialise() { parentClass = reinterpret_cast<GtkWidgetClass *>( g_type_class_ref(gtk_container_get_type())); + gint maskSmooth = 0; +#if defined(GDK_WINDOWING_WAYLAND) + GdkDisplay *pdisplay = gdk_display_get_default(); + if (GDK_IS_WAYLAND_DISPLAY(pdisplay)) { + // On Wayland, touch pads only produce smooth scroll events + maskSmooth = GDK_SMOOTH_SCROLL_MASK; + } +#endif + gtk_widget_set_can_focus(PWidget(wMain), TRUE); gtk_widget_set_sensitive(PWidget(wMain), TRUE); gtk_widget_set_events(PWidget(wMain), GDK_EXPOSURE_MASK | GDK_SCROLL_MASK + | maskSmooth | GDK_STRUCTURE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK @@ -1784,6 +1800,25 @@ gint ScintillaGTK::ScrollEvent(GtkWidget *widget, GdkEventScroll *event) { if (widget == NULL || event == NULL) return FALSE; +#if defined(GDK_WINDOWING_WAYLAND) + if (event->direction == GDK_SCROLL_SMOOTH) { + const int smoothScrollFactor = 4; + sciThis->smoothScrollY += event->delta_y * smoothScrollFactor; + sciThis->smoothScrollX += event->delta_x * smoothScrollFactor;; + if (ABS(sciThis->smoothScrollY) >= 1.0) { + const int scrollLines = trunc(sciThis->smoothScrollY); + sciThis->ScrollTo(sciThis->topLine + scrollLines); + sciThis->smoothScrollY -= scrollLines; + } + if (ABS(sciThis->smoothScrollX) >= 1.0) { + const int scrollPixels = trunc(sciThis->smoothScrollX); + sciThis->HorizontalScrollTo(sciThis->xOffset + scrollPixels); + sciThis->smoothScrollX -= scrollPixels; + } + return TRUE; + } +#endif + // Compute amount and direction to scroll (even tho on win32 there is // intensity of scrolling info in the native message, gtk doesn't // support this so we simulate similarly adaptive scrolling) diff --git a/gtk/ScintillaGTK.h b/gtk/ScintillaGTK.h index 35778c520..6f69661f2 100644 --- a/gtk/ScintillaGTK.h +++ b/gtk/ScintillaGTK.h @@ -57,6 +57,8 @@ class ScintillaGTK : public ScintillaBase { GTimeVal lastWheelMouseTime; gint lastWheelMouseDirection; gint wheelMouseIntensity; + gdouble smoothScrollY; + gdouble smoothScrollX; #if GTK_CHECK_VERSION(3,0,0) cairo_rectangle_list_t *rgnUpdate; |