80 lines
2.1 KiB
C++
80 lines
2.1 KiB
C++
|
#include "Layer.h"
|
||
|
#include "Client.h"
|
||
|
#include "Window.h"
|
||
|
|
||
|
Layer l_background;
|
||
|
Layer l_global;
|
||
|
Layer l_global_top;
|
||
|
Layer l_system;
|
||
|
Layer l_lock;
|
||
|
|
||
|
constexpr int NUM_LAYERS = 5;
|
||
|
|
||
|
static Layer* const layers_front_to_back[NUM_LAYERS] = { &l_lock, &l_system, &l_global_top, &l_global, &l_background };
|
||
|
static Layer* const layers_back_to_front[NUM_LAYERS] = { &l_background, &l_global, &l_global_top, &l_system, &l_lock };
|
||
|
|
||
|
Window* Layer::focused_window()
|
||
|
{
|
||
|
for (int i = 0; i < NUM_LAYERS; i++)
|
||
|
{
|
||
|
Layer* l = layers_front_to_back[i];
|
||
|
if (l->windows.last().has_value()) return l->windows.last().value();
|
||
|
}
|
||
|
|
||
|
return nullptr;
|
||
|
}
|
||
|
|
||
|
void Layer::draw_all_windows(ui::Canvas& canvas)
|
||
|
{
|
||
|
for (int i = 0; i < NUM_LAYERS; i++)
|
||
|
{
|
||
|
Layer* l = layers_back_to_front[i];
|
||
|
for (Window* w : l->windows) { w->draw(canvas); }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Window* Layer::propagate_mouse_event(ui::Point position, u8 buttons)
|
||
|
{
|
||
|
for (int i = 0; i < NUM_LAYERS; i++)
|
||
|
{
|
||
|
Layer* l = layers_front_to_back[i];
|
||
|
for (Window* window = l->windows.last().value_or(nullptr); window;
|
||
|
window = l->windows.previous(window).value_or(nullptr))
|
||
|
{
|
||
|
if (window->surface.contains(position))
|
||
|
{
|
||
|
ui::MouseEventRequest request;
|
||
|
request.window = window->id;
|
||
|
request.position = window->surface.relative(position);
|
||
|
request.buttons = buttons;
|
||
|
window->client->conn->send_async(request);
|
||
|
return window;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return nullptr;
|
||
|
}
|
||
|
|
||
|
Window* Layer::propagate_drag_event(ui::Point position)
|
||
|
{
|
||
|
for (int i = 0; i < NUM_LAYERS; i++)
|
||
|
{
|
||
|
Layer* l = layers_front_to_back[i];
|
||
|
for (Window* window = l->windows.last().value_or(nullptr); window;
|
||
|
window = l->windows.previous(window).value_or(nullptr))
|
||
|
{
|
||
|
if (window->surface.contains(position))
|
||
|
{
|
||
|
window->focus();
|
||
|
|
||
|
if (window->surface.absolute(window->titlebar).contains(position)) return window;
|
||
|
|
||
|
return nullptr;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return nullptr;
|
||
|
}
|