1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 00:17:46 +00:00

WindowServer: Add support for per-window override cursors.

Use this to implement automatic switching to an I-beam cursor when hovering
over a GTextEditor. :^)
This commit is contained in:
Andreas Kling 2019-03-31 23:52:02 +02:00
parent 42c95959a8
commit dcf6726487
13 changed files with 110 additions and 0 deletions

View file

@ -3,6 +3,7 @@
#include <LibGUI/GFontDatabase.h>
#include <LibGUI/GClipboard.h>
#include <LibGUI/GPainter.h>
#include <LibGUI/GWindow.h>
#include <Kernel/KeyCode.h>
#include <AK/StringBuilder.h>
#include <unistd.h>
@ -801,3 +802,15 @@ void GTextEditor::paste()
printf("Paste: \"%s\"\n", paste_text.characters());
insert_at_cursor_or_replace_selection(paste_text);
}
void GTextEditor::enter_event(GEvent&)
{
ASSERT(window());
window()->set_override_cursor(GStandardCursor::IBeam);
}
void GTextEditor::leave_event(GEvent&)
{
ASSERT(window());
window()->set_override_cursor(GStandardCursor::None);
}

View file

@ -111,6 +111,9 @@ private:
virtual void focusout_event(GEvent&) override;
virtual void timer_event(GTimerEvent&) override;
virtual bool accepts_focus() const override { return true; }
virtual void enter_event(GEvent&) override;
virtual void leave_event(GEvent&) override;
void paint_ruler(Painter&);
void update_content_size();

View file

@ -140,6 +140,17 @@ void GWindow::set_rect(const Rect& a_rect)
GEventLoop::current().post_message_to_server(request);
}
void GWindow::set_override_cursor(GStandardCursor cursor)
{
if (!m_window_id)
return;
WSAPI_ClientMessage request;
request.type = WSAPI_ClientMessage::Type::SetWindowOverrideCursor;
request.window_id = m_window_id;
request.cursor.cursor = (WSAPI_StandardCursor)cursor;
GEventLoop::current().post_message_to_server(request);
}
void GWindow::event(GEvent& event)
{
if (event.is_mouse_event()) {

View file

@ -8,6 +8,12 @@
class GWidget;
enum class GStandardCursor {
None = 0,
Arrow,
IBeam,
};
class GWindow : public GObject {
public:
GWindow(GObject* parent = nullptr);
@ -84,6 +90,8 @@ public:
Size base_size() const { return m_base_size; }
void set_base_size(const Size& size) { m_base_size = size; }
void set_override_cursor(GStandardCursor);
virtual const char* class_name() const override { return "GWindow"; }
private: