Skip to content

Commit

Permalink
UserInputHandler: add virtual method OnRawKey()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Sep 6, 2024
1 parent 0375403 commit 96a7e36
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/AsyncUserInput.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ AsyncUserInput::OnSocketReady(unsigned) noexcept
}
#endif

if (handler.OnRawKey(key)) {
// TODO: begin_input_event() ?
end_input_event();
return;
}

Command cmd = translate_key(key);
if (cmd == Command::NONE)
return;
Expand Down
7 changes: 7 additions & 0 deletions src/Instance.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,10 @@ Instance::Run()

event_loop.Run();
}

bool
Instance::OnRawKey(int key) noexcept
{
(void)key;
return false;
}
1 change: 1 addition & 0 deletions src/Instance.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ private:
#endif

// virtual methods from AsyncUserInputHandler
bool OnRawKey(int key) noexcept override;
bool OnCommand(Command cmd) noexcept override;
#ifdef HAVE_GETMOUSE
bool OnMouse(Point p, mmask_t bstate) noexcept override;
Expand Down
10 changes: 10 additions & 0 deletions src/UserInputHandler.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ struct Point;
*/
class UserInputHandler {
public:
/**
* Implementing this method gives the handler a chance to
* handle a key code pressed by the user. This is called
* before looking up hot keys.
*
* @return true if the character was consumed, false to pass
* it on to the hot key checker
*/
virtual bool OnRawKey(int key) noexcept = 0;

/**
* A hot key for a #Command was pressed.
*
Expand Down

0 comments on commit 96a7e36

Please sign in to comment.