2024-05-29 16:00:54 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Framebuffer.h"
|
|
|
|
#include "Window.h"
|
|
|
|
|
|
|
|
#include <BAN/Function.h>
|
|
|
|
#include <BAN/Iteration.h>
|
|
|
|
#include <BAN/Vector.h>
|
|
|
|
#include <BAN/HashMap.h>
|
|
|
|
|
2024-06-02 17:27:09 +03:00
|
|
|
#include <LibFont/Font.h>
|
|
|
|
#include <LibGUI/Window.h>
|
2024-06-16 00:28:09 +03:00
|
|
|
#include <LibImage/Image.h>
|
2024-05-29 16:00:54 +03:00
|
|
|
#include <LibInput/KeyEvent.h>
|
|
|
|
#include <LibInput/MouseEvent.h>
|
|
|
|
|
2024-06-02 17:27:09 +03:00
|
|
|
#include <sys/select.h>
|
|
|
|
|
2024-05-29 16:00:54 +03:00
|
|
|
class WindowServer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WindowServer(Framebuffer& framebuffer)
|
|
|
|
: m_framebuffer(framebuffer)
|
|
|
|
, m_cursor({ framebuffer.width / 2, framebuffer.height / 2 })
|
2024-06-02 17:27:09 +03:00
|
|
|
, m_font(MUST(LibFont::Font::load("/usr/share/fonts/lat0-16.psfu"sv)))
|
2024-05-29 16:00:54 +03:00
|
|
|
{
|
|
|
|
invalidate(m_framebuffer.area());
|
|
|
|
}
|
|
|
|
|
2024-06-16 00:28:09 +03:00
|
|
|
BAN::ErrorOr<void> set_background_image(BAN::UniqPtr<LibImage::Image>);
|
|
|
|
|
2024-06-02 17:27:09 +03:00
|
|
|
void on_window_packet(int fd, LibGUI::WindowPacket);
|
2024-05-29 16:00:54 +03:00
|
|
|
|
|
|
|
void on_key_event(LibInput::KeyEvent event);
|
|
|
|
void on_mouse_button(LibInput::MouseButtonEvent event);
|
|
|
|
void on_mouse_move(LibInput::MouseMoveEvent event);
|
|
|
|
void on_mouse_scroll(LibInput::MouseScrollEvent event);
|
|
|
|
|
|
|
|
void set_focused_window(BAN::RefPtr<Window> window);
|
|
|
|
void invalidate(Rectangle area);
|
|
|
|
|
2024-05-31 03:02:58 +03:00
|
|
|
Rectangle cursor_area() const;
|
|
|
|
|
2024-06-02 17:27:09 +03:00
|
|
|
void add_client_fd(int fd);
|
|
|
|
void remove_client_fd(int fd);
|
|
|
|
int get_client_fds(fd_set& fds) const;
|
|
|
|
void for_each_client_fd(const BAN::Function<BAN::Iteration(int)>& callback);
|
|
|
|
|
|
|
|
bool is_stopped() const { return m_is_stopped; }
|
|
|
|
|
2024-05-29 16:00:54 +03:00
|
|
|
private:
|
|
|
|
Framebuffer& m_framebuffer;
|
2024-06-02 17:27:09 +03:00
|
|
|
BAN::Vector<BAN::RefPtr<Window>> m_client_windows;
|
|
|
|
BAN::Vector<int> m_client_fds;
|
2024-05-29 16:00:54 +03:00
|
|
|
|
2024-06-16 00:28:09 +03:00
|
|
|
BAN::UniqPtr<LibImage::Image> m_background_image;
|
|
|
|
|
2024-05-29 16:00:54 +03:00
|
|
|
bool m_is_mod_key_held { false };
|
|
|
|
bool m_is_moving_window { false };
|
|
|
|
BAN::RefPtr<Window> m_focused_window;
|
|
|
|
Position m_cursor;
|
2024-06-02 17:27:09 +03:00
|
|
|
|
|
|
|
bool m_deleted_window { false };
|
|
|
|
bool m_is_stopped { false };
|
|
|
|
|
|
|
|
LibFont::Font m_font;
|
2024-05-29 16:00:54 +03:00
|
|
|
};
|