FLTK logo

[master] 232743c - Fix Fl_Counter event handling (#450, part 2)

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 232743c - Fix Fl_Counter event handling (#450, part 2) "Albrecht Schlosser" Jun 17, 2022  
 
commit 232743c3a5d903be813f6c4445f3f96bab25cae0
Author:     Albrecht Schlosser <albrechts.fltk@online.de>
AuthorDate: Fri Jun 17 17:12:51 2022 +0200
Commit:     Albrecht Schlosser <albrechts.fltk@online.de>
CommitDate: Fri Jun 17 17:16:59 2022 +0200

    Fix Fl_Counter event handling (#450, part 2)
    
    This fixes some issues of the repeat timeout of Fl_Counter. It could
    happen that the widget missed the FL_RELEASE event, for instance if
    a modal window like fl_message() was opened in the callback but there
    could be other reasons as well. See issue #450 for more info.

 src/Fl_Counter.cxx | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git src/Fl_Counter.cxx src/Fl_Counter.cxx
index 992f0c2..ed856c2 100644
--- src/Fl_Counter.cxx
+++ src/Fl_Counter.cxx
@@ -1,7 +1,7 @@
 //
 // Counter widget for the Fast Light Tool Kit (FLTK).
 //
-// Copyright 1998-2010 by Bill Spitzak and others.
+// Copyright 1998-2022 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
@@ -93,7 +93,9 @@ void Fl_Counter::increment_cb() {
 
 void Fl_Counter::repeat_callback(void* v) {
   Fl_Counter* b = (Fl_Counter*)v;
-  if (b->mouseobj) {
+  int buttons = Fl::event_state() & FL_BUTTONS; // any mouse button pressed
+  int focus = (Fl::focus() == b);               // the widget has focus
+  if (b->mouseobj && buttons && focus) {
     Fl::add_timeout(REPEAT, repeat_callback, b);
     b->increment_cb();
   }
@@ -136,7 +138,8 @@ int Fl_Counter::handle(int event) {
     if (i != mouseobj) {
       Fl::remove_timeout(repeat_callback, this);
       mouseobj = (uchar)i;
-      if (i) Fl::add_timeout(INITIALREPEAT, repeat_callback, this);
+      if (i > 0)
+        Fl::add_timeout(INITIALREPEAT, repeat_callback, this);
       Fl_Widget_Tracker wp(this);
       increment_cb();
       if (wp.deleted()) return 1;
@@ -155,8 +158,10 @@ int Fl_Counter::handle(int event) {
         return 0;
     }
     // break not required because of switch...
-  case FL_FOCUS : /* FALLTHROUGH */
   case FL_UNFOCUS :
+    mouseobj = 0;
+    /* FALLTHROUGH */
+  case FL_FOCUS :
     if (Fl::visible_focus()) {
       redraw();
       return 1;
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.