xref: /aosp_15_r20/external/libchrome-gestures/include/stuck_button_inhibitor_filter_interpreter.h (revision aed3e5085e770be5b69ce25295ecf6ddf906af95)
1 // Copyright 2012 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <gtest/gtest.h>  // for FRIEND_TEST
6 
7 #include "include/filter_interpreter.h"
8 #include "include/gestures.h"
9 #include "include/tracer.h"
10 
11 #ifndef GESTURES_STUCK_BUTTON_INHIBITOR_FILTER_INTERPRETER_H_
12 #define GESTURES_STUCK_BUTTON_INHIBITOR_FILTER_INTERPRETER_H_
13 
14 // This class monitors the input and output button state and finger count
15 // on the touchpad. It make sure that if all fingers have left the touchpad
16 // and the physical button is up, that we don't get in a situation where we've
17 // sent a button-down gesture, but never sent a button-up gesture. If that
18 // were to happen, the user would be in the unfortunate situation of having
19 // the mouse button seemingly stuck down.
20 
21 namespace gestures {
22 
23 class StuckButtonInhibitorFilterInterpreter : public FilterInterpreter {
24  public:
25   // Takes ownership of |next|:
26   explicit StuckButtonInhibitorFilterInterpreter(Interpreter* next,
27                                                  Tracer* tracer);
~StuckButtonInhibitorFilterInterpreter()28   virtual ~StuckButtonInhibitorFilterInterpreter() {}
29   virtual void ConsumeGesture(const Gesture& gesture);
30 
31  protected:
32   virtual void SyncInterpretImpl(HardwareState& hwstate, stime_t* timeout);
33 
34   virtual void HandleTimerImpl(stime_t now, stime_t* timeout);
35 
36  private:
37   void HandleHardwareState(const HardwareState& hwstate);
38   void HandleTimeouts(stime_t next_timeout, stime_t* timeout);
39 
40   bool incoming_button_must_be_up_;
41 
42   // these buttons have been reported as down via a gesture:
43   unsigned sent_buttons_down_;
44 
45   bool next_expects_timer_;  // True if next_ is expecting a call to HandleTimer
46 
47   Gesture result_;  // For when we return a button up
48 };
49 
50 }  // namespace gestures
51 
52 #endif  // GESTURES_STUCK_BUTTON_INHIBITOR_FILTER_INTERPRETER_H_
53