From 00df79bfbb7bb583f4d9a1e0f10254c06ba86188 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Thu, 14 Nov 2024 16:03:32 +0100 Subject: [PATCH] Keep sending FL_DRAG until all mouse buttons are released > Backported from branch 'master' (1.4.0), > commit 12592753166337548c9f80f7247803070433b2fd (Jul 14, 2023) The old version would send FL_MOVE events after dragging with more than one mouse buttons pressed, as soon as the first button was released. The new version sends FL_DRAG until the last mouse button is released and then FL_MOVE, as usual. This change affects dragging only if more than one mouse button is pushed and held while dragging. The order of pushing and releasing mouse buttons does not affect the behavior. --- src/Fl.cxx | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/Fl.cxx b/src/Fl.cxx index 1ca1cc7da..dd8656cb7 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -1,9 +1,7 @@ // -// "$Id$" -// // Main event handling code for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2018 by Bill Spitzak and others. +// Copyright 1998-2024 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -1404,19 +1402,46 @@ int Fl::handle_(int e, Fl_Window* window) return ret;} case FL_RELEASE: { -// printf("FL_RELEASE: window=%p, pushed() = %p, grab() = %p, modal() = %p\n", -// window, pushed(), grab(), modal()); + + // Mouse drag release mode + // - in branch 'master' (1.4.0) on Jul 14, 2023, Albrecht (WIP): + // - backported to 'branch-1.3' for 1.3.10 on Nov 14, 2024 (Albrecht) + // 0 = old: *first* mouse button release ("up") turns drag mode off + // 1 = new: *last* mouse button release ("up") turns drag mode off + // The latter enables dragging with two or more pressed mouse buttons + // and to continue dragging (i.e. sending FL_DRAG) until the *last* + // mouse button is released. + // See fltk.general, thread started on Jul 12, 2023 + // "Is handling simultaneous Left-click and Right-click drags supported?" + + static const int drag_release = 1; // should be 1 => new behavior since Jul 2023 + + // Implementation notes: + // (1) Mode 1 (new): only if *all* mouse buttons have been released, the + // Fl::pushed_ widget is reset to 0 (NULL) so subsequent system "move" + // events are no longer sent as FL_DRAG events. + // (2) Mode 0 (old): Fl::pushed_ was reset on the *first* mouse button release. + // (3) The constant 'drag_release' should be removed once the new mode has been + // confirmed to work correctly and no side effects have been observed. + // Hint: remove condition "!drag_release || " twice (below). + + // printf("FL_RELEASE: window=%p, pushed() = %p, grab() = %p, modal() = %p, drag_release = %d, buttons = 0x%x\n", + // window, pushed(), grab(), modal(), drag_release, Fl::event_buttons()>>24); if (grab()) { wi = grab(); - pushed_ = 0; // must be zero before callback is done! + if (!drag_release || !Fl::event_buttons()) + pushed_ = 0; // must be zero before callback is done! } else if (pushed()) { wi = pushed(); - pushed_ = 0; // must be zero before callback is done! - } else if (modal() && wi != modal()) return 0; + if (!drag_release || !Fl::event_buttons()) + pushed_ = 0; // must be zero before callback is done! + } else if (modal() && wi != modal()) + return 0; int r = send_event(e, wi, window); fl_fix_focus(); - return r;} + return r; + } case FL_UNFOCUS: window = 0;