Compare commits

...

6 Commits

2 changed files with 110 additions and 21 deletions

View File

@ -9,13 +9,13 @@ configure() {
}
build() {
if [ ! -f doom1.wad ]; then
wget https://distro.ibiblio.org/slitaz/sources/packages/d/doom1.wad || exit 1
if [ ! -f ../doom1.wad ]; then
wget https://distro.ibiblio.org/slitaz/sources/packages/d/doom1.wad -O ../doom1.wad || exit 1
fi
make --directory doomgeneric --file Makefile.banan_os -j$(nproc) || exit 1
}
install() {
cp doomgeneric/build/doom "${BANAN_SYSROOT}/bin/" || exit 1
cp ./doom1.wad "$BANAN_SYSROOT/home/user/" || exit 1
cp ../doom1.wad "$BANAN_SYSROOT/home/user/" || exit 1
}

View File

@ -85,7 +85,10 @@ void WindowServer::on_window_create(int fd, const LibGUI::WindowPacket::WindowCr
window_popper.disable();
set_focused_window(window);
if (packet.attributes.focusable)
set_focused_window(window);
else if (m_client_windows.size() > 1)
BAN::swap(m_client_windows[m_client_windows.size() - 1], m_client_windows[m_client_windows.size() - 2]);
}
void WindowServer::on_window_invalidate(int fd, const LibGUI::WindowPacket::WindowInvalidate& packet)
@ -93,6 +96,13 @@ void WindowServer::on_window_invalidate(int fd, const LibGUI::WindowPacket::Wind
if (packet.width == 0 || packet.height == 0)
return;
if (m_is_fullscreen_window)
{
ASSERT(m_focused_window);
if (m_focused_window->client_fd() != fd)
return;
}
BAN::RefPtr<Window> target_window;
for (auto& window : m_client_windows)
{
@ -298,7 +308,6 @@ void WindowServer::on_window_set_fullscreen(int fd, const LibGUI::WindowPacket::
m_is_fullscreen_window = true;
set_focused_window(target_window);
target_window->set_position({ 0, 0 });
invalidate(m_framebuffer.area());
}
@ -343,6 +352,15 @@ void WindowServer::on_key_event(LibInput::KeyEvent event)
return;
}
if (m_is_mod_key_held && event.pressed() && event.key == LibInput::Key::F)
{
if (!m_focused_window)
return;
m_is_fullscreen_window = !m_is_fullscreen_window;
invalidate(m_framebuffer.area());
return;
}
// Toggle window bounce with F2
if (!m_is_fullscreen_window && event.pressed() && event.key == LibInput::Key::F2)
m_is_bouncing_window = !m_is_bouncing_window;
@ -438,8 +456,21 @@ void WindowServer::on_mouse_move(LibInput::MouseMoveEvent event)
return;
}
const int32_t new_x = BAN::Math::clamp(m_cursor.x + event.rel_x, 0, m_framebuffer.width);
const int32_t new_y = BAN::Math::clamp(m_cursor.y - event.rel_y, 0, m_framebuffer.height);
const auto [new_x, new_y] =
[&]() -> Position
{
const int32_t new_x = m_cursor.x + event.rel_x;
const int32_t new_y = m_cursor.y - event.rel_y;
return m_is_fullscreen_window
? Position {
.x = BAN::Math::clamp(new_x, m_focused_window->client_x(), m_focused_window->client_x() + m_focused_window->client_width()),
.y = BAN::Math::clamp(new_y, m_focused_window->client_y(), m_focused_window->client_y() + m_focused_window->client_height())
}
: Position {
.x = BAN::Math::clamp(new_x, 0, m_framebuffer.width),
.y = BAN::Math::clamp(new_y, 0, m_framebuffer.height)
};
}();
event.rel_x = new_x - m_cursor.x;
event.rel_y = new_y - m_cursor.y;
@ -543,16 +574,38 @@ static uint32_t alpha_blend(uint32_t color_a, uint32_t color_b)
void WindowServer::invalidate(Rectangle area)
{
const auto get_cursor_pixel =
[](int32_t rel_x, int32_t rel_y) -> BAN::Optional<uint32_t>
{
const uint32_t offset = (rel_y * s_cursor_width + rel_x) * 4;
uint32_t r = (((s_cursor_data[offset + 0] - 33) << 2) | ((s_cursor_data[offset + 1] - 33) >> 4));
uint32_t g = ((((s_cursor_data[offset + 1] - 33) & 0xF) << 4) | ((s_cursor_data[offset + 2] - 33) >> 2));
uint32_t b = ((((s_cursor_data[offset + 2] - 33) & 0x3) << 6) | ((s_cursor_data[offset + 3] - 33)));
uint32_t color = (r << 16) | (g << 8) | b;
if (color == 0xFF00FF)
return {};
return color;
};
if (m_is_fullscreen_window)
{
ASSERT(m_focused_window);
area.x -= m_focused_window->client_x();
area.y -= m_focused_window->client_y();
auto focused_overlap = area.get_overlap(m_focused_window->client_area());
const Rectangle client_area {
.x = 0,
.y = 0,
.width = m_focused_window->client_width(),
.height = m_focused_window->client_height(),
};
auto focused_overlap = area.get_overlap(client_area);
if (!focused_overlap.has_value())
return;
area = focused_overlap.release_value();
if (m_focused_window->client_area() == m_framebuffer.area())
if (client_area == m_framebuffer.area())
{
for (int32_t y = area.y; y < area.y + area.height; y++)
for (int32_t x = area.x; x < area.x + area.width; x++)
@ -561,19 +614,22 @@ void WindowServer::invalidate(Rectangle area)
}
else
{
const Rectangle dst_area {
auto opt_dst_area = Rectangle {
.x = area.x * m_framebuffer.width / m_focused_window->client_width(),
.y = area.y * m_framebuffer.height / m_focused_window->client_height(),
.width = BAN::Math::div_round_up(area.width * m_framebuffer.width, m_focused_window->client_width()),
.height = BAN::Math::div_round_up(area.height * m_framebuffer.height, m_focused_window->client_height())
};
}.get_overlap(m_framebuffer.area());
if (!opt_dst_area.has_value())
return;
const auto dst_area = opt_dst_area.release_value();
for (int32_t dst_y = dst_area.y; dst_y < dst_area.y + dst_area.height; dst_y++)
{
for (int32_t dst_x = dst_area.x; dst_x < dst_area.x + dst_area.width; dst_x++)
{
const int32_t src_x = dst_x * m_focused_window->client_width() / m_framebuffer.width;
const int32_t src_y = dst_y * m_focused_window->client_height() / m_framebuffer.height;
const int32_t src_x = BAN::Math::clamp<int32_t>(dst_x * m_focused_window->client_width() / m_framebuffer.width, 0, m_focused_window->client_width());
const int32_t src_y = BAN::Math::clamp<int32_t>(dst_y * m_focused_window->client_height() / m_framebuffer.height, 0, m_focused_window->client_height());
m_framebuffer.mmap[dst_y * m_framebuffer.width + dst_x] = m_focused_window->framebuffer()[src_y * m_focused_window->client_width() + src_x];
}
}
@ -581,6 +637,43 @@ void WindowServer::invalidate(Rectangle area)
mark_pending_sync(dst_area);
}
if (!m_is_mouse_captured)
{
const Rectangle cursor_area {
.x = m_cursor.x - m_focused_window->client_x(),
.y = m_cursor.y - m_focused_window->client_y(),
.width = s_cursor_width,
.height = s_cursor_height,
};
if (!area.get_overlap(cursor_area).has_value())
return;
const int32_t cursor_tl_dst_x = cursor_area.x * m_framebuffer.width / m_focused_window->client_width();
const int32_t cursor_tl_dst_y = cursor_area.y * m_framebuffer.height / m_focused_window->client_height();
for (int32_t rel_y = 0; rel_y < s_cursor_height; rel_y++)
{
for (int32_t rel_x = 0; rel_x < s_cursor_width; rel_x++)
{
const auto pixel = get_cursor_pixel(rel_x, rel_y);
if (!pixel.has_value())
continue;
const int32_t dst_x = cursor_tl_dst_x + rel_x;
const int32_t dst_y = cursor_tl_dst_y + rel_y;
if (dst_x < 0 || dst_x >= m_framebuffer.width)
continue;
if (dst_y < 0 || dst_y >= m_framebuffer.height)
continue;
m_framebuffer.mmap[dst_y * m_framebuffer.width + dst_x] = pixel.value();
}
}
mark_pending_sync(cursor_area);
}
return;
}
@ -779,7 +872,7 @@ void WindowServer::invalidate(Rectangle area)
if (!m_is_mouse_captured)
{
auto cursor = cursor_area();
const auto cursor = cursor_area();
if (auto overlap = cursor.get_overlap(area); overlap.has_value())
{
for (int32_t y_off = 0; y_off < overlap->height; y_off++)
@ -788,13 +881,9 @@ void WindowServer::invalidate(Rectangle area)
{
const int32_t rel_x = overlap->x - m_cursor.x + x_off;
const int32_t rel_y = overlap->y - m_cursor.y + y_off;
const uint32_t offset = (rel_y * s_cursor_width + rel_x) * 4;
uint32_t r = (((s_cursor_data[offset + 0] - 33) << 2) | ((s_cursor_data[offset + 1] - 33) >> 4));
uint32_t g = ((((s_cursor_data[offset + 1] - 33) & 0xF) << 4) | ((s_cursor_data[offset + 2] - 33) >> 2));
uint32_t b = ((((s_cursor_data[offset + 2] - 33) & 0x3) << 6) | ((s_cursor_data[offset + 3] - 33)));
uint32_t color = (r << 16) | (g << 8) | b;
if (color != 0xFF00FF)
m_framebuffer.mmap[(overlap->y + y_off) * m_framebuffer.width + (overlap->x + x_off)] = color;
const auto pixel = get_cursor_pixel(rel_x, rel_y);
if (pixel.has_value())
m_framebuffer.mmap[(overlap->y + y_off) * m_framebuffer.width + (overlap->x + x_off)] = pixel.value();
}
}
}