1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:27:44 +00:00

LibGUI: Make focus events more aware of why focus is changing

This patch adds GUI::FocusEvent which has a GUI::FocusSource.
The focus source is one of three things:

- Programmatic
- Mouse
- Keyboard

This allows receivers of focus events to implement different behaviors
depending on how they receive/lose focus.
This commit is contained in:
Andreas Kling 2020-08-14 19:56:40 +02:00
parent 110b3d89d3
commit 75b8f4e4e6
14 changed files with 94 additions and 41 deletions

View file

@ -30,6 +30,7 @@
#include <AK/Vector.h>
#include <Kernel/API/KeyCode.h>
#include <LibCore/Event.h>
#include <LibGUI/FocusSource.h>
#include <LibGUI/WindowType.h>
#include <LibGfx/Point.h>
#include <LibGfx/Rect.h>
@ -76,12 +77,12 @@ public:
__End_WM_Events,
};
Event() {}
Event() { }
explicit Event(Type type)
: Core::Event(type)
{
}
virtual ~Event() {}
virtual ~Event() { }
bool is_key_event() const { return type() == KeyUp || type() == KeyDown; }
bool is_paint_event() const { return type() == Paint; }
@ -387,4 +388,18 @@ public:
}
};
class FocusEvent final : public Event {
public:
explicit FocusEvent(Type type, FocusSource source)
: Event(type)
, m_source(source)
{
}
FocusSource source() const { return m_source; }
private:
FocusSource m_source { FocusSource::Programmatic };
};
}