From 4928517e27bf261d667eaa4417cecef0a04b3609 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sat, 16 Nov 2019 22:43:27 +0100 Subject: Selectively disable motion event compression for specific tools It was globally disabled in ab71599ea1af1ea5042e35502e9aa722cc4ab51e However most of the time we do not care for intermediate motion events, and forcing to process them only causes unnecessary performance overhead. --- src/display/sp-canvas.cpp | 1 - src/ui/tools/calligraphic-tool.cpp | 2 ++ src/ui/tools/pencil-tool.cpp | 3 +++ src/ui/tools/spray-tool.cpp | 2 ++ src/ui/tools/tool-base.cpp | 17 +++++++++++++++++ src/ui/tools/tool-base.h | 2 ++ 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index 3a338c53b..88fec767f 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -1133,7 +1133,6 @@ void SPCanvas::handle_realize(GtkWidget *widget) GdkWindow *window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); gtk_widget_set_window (widget, window); gdk_window_set_user_data (window, widget); - gdk_window_set_event_compression (window, FALSE); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/options/useextinput/value", true)) { diff --git a/src/ui/tools/calligraphic-tool.cpp b/src/ui/tools/calligraphic-tool.cpp index ac9db6f0d..c7c1c3aa3 100644 --- a/src/ui/tools/calligraphic-tool.cpp +++ b/src/ui/tools/calligraphic-tool.cpp @@ -471,6 +471,7 @@ bool CalligraphicTool::root_handler(GdkEvent* event) { ret = TRUE; desktop->canvas->forceFullRedrawAfterInterruptions(3); + set_high_motion_precision(); this->is_drawing = true; this->just_started_drawing = true; } @@ -729,6 +730,7 @@ bool CalligraphicTool::root_handler(GdkEvent* event) { sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate)); desktop->canvas->endForcedFullRedraws(); + set_high_motion_precision(false); this->is_drawing = false; if (this->dragging && event->button.button == 1 && !this->space_panning) { diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index d3e226a84..fd876270d 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -257,6 +257,7 @@ bool PencilTool::_handleButtonPress(GdkEventButton const &bevent) { break; } + set_high_motion_precision(); this->_is_drawing = true; } return ret; @@ -399,6 +400,8 @@ bool PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { bool PencilTool::_handleButtonRelease(GdkEventButton const &revent) { bool ret = false; + set_high_motion_precision(false); + if ( revent.button == 1 && this->_is_drawing && !this->space_panning) { this->_is_drawing = false; diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 52a8d114d..bc5eac75f 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -1245,6 +1245,7 @@ bool SprayTool::root_handler(GdkEvent* event) { sp_spray_extinput(this, event); desktop->canvas->forceFullRedrawAfterInterruptions(3); + set_high_motion_precision(); this->is_drawing = true; this->is_dilating = true; this->has_dilated = false; @@ -1341,6 +1342,7 @@ bool SprayTool::root_handler(GdkEvent* event) { Geom::Point const motion_dt(desktop->w2d(motion_w)); desktop->canvas->endForcedFullRedraws(); + set_high_motion_precision(false); this->is_drawing = false; if (this->is_dilating && event->button.button == 1 && !this->space_panning) { diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index eb2f2119a..0047e32ef 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -1057,6 +1057,23 @@ bool ToolBase::deleteSelectedDrag(bool just_one) { return FALSE; } +/** Enable (or disable) high precision for motion events + * + * This is intended to be used by drawing tools, that need to process motion events with high accuracy + * and high update rate (for example free hand tools) + * + * With standard accuracy some intermediate motion events might be discarded + * + * Call this function when an operation that requires high accuracy is started (e.g. mouse button is pressed + * to draw a line). Make sure to call it again and restore standard precision afterwards. **/ +void ToolBase::set_high_motion_precision(bool high_precision) { + Glib::RefPtr window = desktop->getToplevel()->get_window(); + + if (window) { + window->set_event_compression(!high_precision); + } +} + /** * Calls virtual set() function of ToolBase. */ diff --git a/src/ui/tools/tool-base.h b/src/ui/tools/tool-base.h index dc68c4b7f..c9c223823 100644 --- a/src/ui/tools/tool-base.h +++ b/src/ui/tools/tool-base.h @@ -232,6 +232,8 @@ protected: gchar const *const *cursor_shape; bool sp_event_context_knot_mouseover() const; + void set_high_motion_precision(bool high_precision = true); + private: bool _keyboardMove(GdkEventKey const &event, Geom::Point const &dir); void sp_event_context_set_cursor(GdkCursorType cursor_type); -- cgit v1.2.3