1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:28:12 +00:00
serenity/Widgets/Window.h
Andreas Kling b0e3f73375 Start refactoring the windowing system to use an event loop.
Userspace programs can now open /dev/gui_events and read a stream of GUI_Event
structs one at a time.

I was stuck on a stupid problem where we'd reenter Scheduler::yield() due to
having one of the has_data_available_for_reading() implementations using locks.
2019-01-14 14:42:49 +01:00

68 lines
1.8 KiB
C++

#pragma once
#include "Object.h"
#include "Rect.h"
#include "GraphicsBitmap.h"
#include <AK/AKString.h>
#include <AK/InlineLinkedList.h>
#include <AK/WeakPtr.h>
class Process;
class Widget;
class Window final : public Object, public InlineLinkedListNode<Window> {
public:
Window(Process&, int window_id);
virtual ~Window() override;
int window_id() const { return m_window_id; }
String title() const { return m_title; }
void setTitle(String&&);
int x() const { return m_rect.x(); }
int y() const { return m_rect.y(); }
int width() const { return m_rect.width(); }
int height() const { return m_rect.height(); }
const Rect& rect() const { return m_rect; }
void setRect(const Rect&);
void setRectWithoutRepaint(const Rect& rect) { m_rect = rect; }
Point position() const { return m_rect.location(); }
void setPosition(const Point& position) { setRect({ position.x(), position.y(), width(), height() }); }
void setPositionWithoutRepaint(const Point& position) { setRectWithoutRepaint({ position.x(), position.y(), width(), height() }); }
virtual void event(Event&) override;
bool isBeingDragged() const { return m_isBeingDragged; }
void setIsBeingDragged(bool b) { m_isBeingDragged = b; }
void repaint(const Rect& = Rect());
void update(const Rect& = Rect());
bool isActive() const;
bool isVisible() const;
void close();
GraphicsBitmap* backing() { return m_backing.ptr(); }
void did_paint();
// For InlineLinkedList.
// FIXME: Maybe make a ListHashSet and then WindowManager can just use that.
Window* m_next { nullptr };
Window* m_prev { nullptr };
private:
String m_title;
Rect m_rect;
bool m_isBeingDragged { false };
RetainPtr<GraphicsBitmap> m_backing;
Process& m_process;
int m_window_id { -1 };
};