apio
fb3333a086
All checks were successful
Build and test / build (push) Successful in 1m38s
Two layers are accessible to all apps: global and global_top (for popups and similar windows). Three other layers are accessible to privileged clients (background, system and lock), for things that need to be on a different level than user apps, like the taskbar, system popups, menus and the lock screen.
116 lines
2.6 KiB
C++
116 lines
2.6 KiB
C++
/**
|
|
* @file Window.h
|
|
* @author apio (cloudapio.eu)
|
|
* @brief UI windows.
|
|
*
|
|
* @copyright Copyright (c) 2023, the Luna authors.
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
#include <luna/OwnedPtr.h>
|
|
#include <luna/String.h>
|
|
#include <luna/StringView.h>
|
|
#include <ui/Canvas.h>
|
|
#include <ui/Mouse.h>
|
|
#include <ui/Rect.h>
|
|
#include <ui/Widget.h>
|
|
#include <ui/ipc/Server.h>
|
|
|
|
namespace ui
|
|
{
|
|
enum class WindowType : u8
|
|
{
|
|
Normal,
|
|
NotDecorated,
|
|
System,
|
|
};
|
|
|
|
struct [[gnu::packed]] Shortcut
|
|
{
|
|
moon::KeyCode key;
|
|
int modifiers;
|
|
|
|
bool operator==(const Shortcut& other) const
|
|
{
|
|
return key == other.key && modifiers == other.modifiers;
|
|
}
|
|
};
|
|
|
|
class Window
|
|
{
|
|
public:
|
|
static Result<Window*> create(Rect rect, WindowType type = WindowType::Normal);
|
|
|
|
void set_title(StringView title);
|
|
|
|
void set_background(Color color)
|
|
{
|
|
m_background = color;
|
|
}
|
|
|
|
void set_main_widget(Widget& widget)
|
|
{
|
|
check(!m_main_widget);
|
|
widget.set_window(this, m_window_canvas.rect(), {});
|
|
m_main_widget = &widget;
|
|
}
|
|
|
|
Canvas& canvas()
|
|
{
|
|
return m_window_canvas;
|
|
}
|
|
|
|
void update();
|
|
|
|
void close();
|
|
|
|
void set_layer(Layer layer);
|
|
|
|
Result<void> draw();
|
|
Result<ui::EventResult> handle_mouse_leave();
|
|
Result<ui::EventResult> handle_mouse_move(ui::Point position);
|
|
Result<ui::EventResult> handle_mouse_buttons(ui::Point position, int buttons);
|
|
Result<ui::EventResult> handle_key_event(const ui::KeyEventRequest& request);
|
|
|
|
Result<void> add_keyboard_shortcut(ui::Shortcut shortcut, bool intercept, Function<ui::Shortcut>&& action);
|
|
|
|
int id() const
|
|
{
|
|
return m_id;
|
|
}
|
|
|
|
void on_close(Action&& action)
|
|
{
|
|
m_on_close_action = move(action);
|
|
m_has_on_close_action = true;
|
|
}
|
|
|
|
~Window();
|
|
|
|
private:
|
|
int m_id;
|
|
Canvas m_canvas;
|
|
Canvas m_titlebar_canvas;
|
|
Canvas m_window_canvas;
|
|
String m_name;
|
|
Widget* m_main_widget { nullptr };
|
|
Option<Color> m_background {};
|
|
Option<int> m_old_mouse_buttons;
|
|
bool m_decorated { false };
|
|
|
|
Action m_on_close_action;
|
|
bool m_has_on_close_action { false };
|
|
|
|
struct ShortcutAction
|
|
{
|
|
bool intercept;
|
|
Function<Shortcut> action;
|
|
};
|
|
|
|
HashMap<Shortcut, ShortcutAction> m_shortcuts;
|
|
|
|
Result<void> draw_titlebar();
|
|
};
|
|
}
|