Compare commits
No commits in common. "cf21eb4b39af7ed63c96c325506506f5532a26a7" and "a82f00cb70cbd4aed76482686ed8fb1e2eabd21c" have entirely different histories.
cf21eb4b39
...
a82f00cb70
|
@ -325,6 +325,7 @@ namespace BAN::Math
|
|||
template<floating_point T>
|
||||
inline constexpr T sin(T x)
|
||||
{
|
||||
x = fmod<T>(x, (T)2.0 * numbers::pi_v<T>);
|
||||
asm("fsin" : "+t"(x));
|
||||
return x;
|
||||
}
|
||||
|
@ -332,16 +333,12 @@ namespace BAN::Math
|
|||
template<floating_point T>
|
||||
inline constexpr T cos(T x)
|
||||
{
|
||||
if (abs(x) >= (T)9223372036854775808.0)
|
||||
x = fmod<T>(x, (T)2.0 * numbers::pi_v<T>);
|
||||
asm("fcos" : "+t"(x));
|
||||
return x;
|
||||
}
|
||||
|
||||
template<floating_point T>
|
||||
inline constexpr void sincos(T x, T& sin, T& cos)
|
||||
{
|
||||
asm("fsincos" : "=t"(cos), "=u"(sin) : "0"(x));
|
||||
}
|
||||
|
||||
template<floating_point T>
|
||||
inline constexpr T tan(T x)
|
||||
{
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __banan_os__
|
||||
inline void* operator new(size_t, void* addr) { return addr; }
|
||||
inline void* operator new[](size_t, void* addr) { return addr; }
|
||||
#else
|
||||
#include <new>
|
||||
#endif
|
||||
|
|
|
@ -191,9 +191,9 @@ long lroundl(long double);
|
|||
double modf(double, double*);
|
||||
float modff(float, float*);
|
||||
long double modfl(long double, long double*);
|
||||
double nan(const char*);
|
||||
float nanf(const char*);
|
||||
long double nanl(const char*);
|
||||
#define nan(tagp) __builtin_nan(tagp)
|
||||
#define nanf(tagp) __builtin_nanf(tagp)
|
||||
#define nanl(tagp) __builtin_nanl(tagp)
|
||||
double nearbyint(double);
|
||||
float nearbyintf(float);
|
||||
long double nearbyintl(long double);
|
||||
|
|
|
@ -249,9 +249,6 @@ BAN_FUNC1(logb)
|
|||
FUNC_EXPR1_RET(lrint, long, BAN::Math::rint(a))
|
||||
FUNC_EXPR1_RET(lround, long, BAN::Math::round(a))
|
||||
BAN_FUNC2_PTR(modf)
|
||||
double nan(const char* tagp) { return __builtin_nan(tagp); }
|
||||
float nanf(const char* tagp) { return __builtin_nanf(tagp); }
|
||||
long double nanl(const char* tagp) { return __builtin_nanl(tagp); }
|
||||
FUNC_EXPR1(nearbyint, BAN::Math::rint(a))
|
||||
FUNC_EXPR2(nextafter, nextafter_impl(a, b))
|
||||
FUNC_EXPR2_TYPE(nexttoward, long double, nextafter_impl(a, b))
|
||||
|
|
|
@ -43,11 +43,6 @@ void exit(int status)
|
|||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
void _Exit(int status)
|
||||
{
|
||||
_exit(status);
|
||||
}
|
||||
|
||||
int abs(int val)
|
||||
{
|
||||
return val < 0 ? -val : val;
|
||||
|
|
|
@ -267,20 +267,6 @@ namespace LibGUI
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Window::set_mouse_capture(bool captured)
|
||||
{
|
||||
WindowPacket::WindowSetMouseCapture packet;
|
||||
packet.captured = captured;
|
||||
|
||||
if (auto ret = packet.send_serialized(m_server_fd); ret.is_error())
|
||||
{
|
||||
dprintln("failed to set mouse capture: {}", ret.error());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Window::set_position(int32_t x, int32_t y)
|
||||
{
|
||||
WindowPacket::WindowSetPosition packet;
|
||||
|
@ -299,7 +285,10 @@ namespace LibGUI
|
|||
bool Window::set_attributes(Attributes attributes)
|
||||
{
|
||||
WindowPacket::WindowSetAttributes packet;
|
||||
packet.attributes = attributes;
|
||||
packet.title_bar = attributes.title_bar;
|
||||
packet.movable = attributes.movable;
|
||||
packet.rounded_corners = attributes.rounded_corners;
|
||||
packet.alpha_channel = attributes.alpha_channel;
|
||||
|
||||
if (auto ret = packet.send_serialized(m_server_fd); ret.is_error())
|
||||
{
|
||||
|
|
|
@ -162,7 +162,6 @@ namespace LibGUI
|
|||
WindowInvalidate,
|
||||
WindowSetPosition,
|
||||
WindowSetAttributes,
|
||||
WindowSetMouseCapture,
|
||||
|
||||
DestroyWindowEvent,
|
||||
CloseWindowEvent,
|
||||
|
@ -175,49 +174,35 @@ namespace LibGUI
|
|||
namespace WindowPacket
|
||||
{
|
||||
|
||||
DEFINE_PACKET(
|
||||
WindowCreate,
|
||||
DEFINE_PACKET(WindowCreate,
|
||||
uint32_t, width,
|
||||
uint32_t, height,
|
||||
BAN::String, title
|
||||
);
|
||||
|
||||
DEFINE_PACKET(
|
||||
WindowCreateResponse,
|
||||
DEFINE_PACKET(WindowCreateResponse,
|
||||
uint32_t, width,
|
||||
uint32_t, height,
|
||||
long, smo_key
|
||||
);
|
||||
|
||||
DEFINE_PACKET(
|
||||
WindowInvalidate,
|
||||
DEFINE_PACKET(WindowInvalidate,
|
||||
uint32_t, x,
|
||||
uint32_t, y,
|
||||
uint32_t, width,
|
||||
uint32_t, height
|
||||
);
|
||||
|
||||
DEFINE_PACKET(
|
||||
WindowSetPosition,
|
||||
DEFINE_PACKET(WindowSetPosition,
|
||||
int32_t, x,
|
||||
int32_t, y
|
||||
);
|
||||
|
||||
DEFINE_PACKET_EXTRA(
|
||||
WindowSetAttributes,
|
||||
struct Attributes {
|
||||
bool title_bar;
|
||||
bool movable;
|
||||
bool focusable;
|
||||
bool rounded_corners;
|
||||
bool alpha_channel;
|
||||
},
|
||||
Attributes, attributes
|
||||
);
|
||||
|
||||
DEFINE_PACKET(
|
||||
WindowSetMouseCapture,
|
||||
bool, captured
|
||||
DEFINE_PACKET(WindowSetAttributes,
|
||||
bool, title_bar,
|
||||
bool, rounded_corners,
|
||||
bool, movable,
|
||||
bool, alpha_channel
|
||||
);
|
||||
|
||||
}
|
||||
|
|
|
@ -14,14 +14,12 @@ namespace LibGUI
|
|||
class Window
|
||||
{
|
||||
public:
|
||||
using Attributes = WindowPacket::WindowSetAttributes::Attributes;
|
||||
|
||||
static constexpr Attributes default_attributes = {
|
||||
.title_bar = true,
|
||||
.movable = true,
|
||||
.focusable = true,
|
||||
.rounded_corners = true,
|
||||
.alpha_channel = false,
|
||||
struct Attributes
|
||||
{
|
||||
bool title_bar { true };
|
||||
bool movable { true };
|
||||
bool rounded_corners { true };
|
||||
bool alpha_channel { false };
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -60,8 +58,6 @@ namespace LibGUI
|
|||
bool invalidate(int32_t x, int32_t y, uint32_t width, uint32_t height);
|
||||
bool invalidate() { return invalidate(0, 0, width(), height()); }
|
||||
|
||||
bool set_mouse_capture(bool captured);
|
||||
|
||||
bool set_position(int32_t x, int32_t y);
|
||||
|
||||
Attributes get_attributes() const { return m_attributes; }
|
||||
|
|
|
@ -3,17 +3,6 @@
|
|||
|
||||
#include <time.h>
|
||||
|
||||
static BAN::String get_task_bar_string()
|
||||
{
|
||||
BAN::String result;
|
||||
|
||||
const time_t current_time = time(nullptr);
|
||||
if (!result.append(ctime(¤t_time)).is_error())
|
||||
result.pop_back();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
constexpr uint32_t padding = 3;
|
||||
|
@ -24,14 +13,12 @@ int main()
|
|||
|
||||
auto window = MUST(LibGUI::Window::create(0, font.height() + 2 * padding, "TaskBar"));
|
||||
|
||||
auto attributes = LibGUI::Window::default_attributes;
|
||||
auto attributes = window->get_attributes();
|
||||
attributes.title_bar = false;
|
||||
attributes.movable = false;
|
||||
attributes.focusable = false;
|
||||
attributes.alpha_channel = false;
|
||||
attributes.rounded_corners = false;
|
||||
window->set_attributes(attributes);
|
||||
|
||||
window->set_close_window_event_callback([]() {});
|
||||
|
||||
window->set_position(0, 0);
|
||||
|
@ -41,18 +28,21 @@ int main()
|
|||
|
||||
bool is_running = true;
|
||||
|
||||
time_t last_update;
|
||||
const auto update_time_string =
|
||||
[&]()
|
||||
{
|
||||
const auto text = get_task_bar_string();
|
||||
last_update = time(nullptr);
|
||||
BAN::StringView time_sv = ctime(&last_update);
|
||||
time_sv = time_sv.substring(0, time_sv.size() - 1); // new line
|
||||
|
||||
const uint32_t text_w = text.size() * font.width();
|
||||
const uint32_t text_w = time_sv.size() * font.width();
|
||||
const uint32_t text_h = font.height();
|
||||
const uint32_t text_x = window->width() - text_w - padding;
|
||||
const uint32_t text_y = padding;
|
||||
|
||||
window->fill_rect(text_x, text_y, text_w, text_h, bg_color);
|
||||
window->draw_text(text, font, text_x, text_y, fg_color);
|
||||
window->draw_text(time_sv, font, text_x, text_y, fg_color);
|
||||
if (!window->invalidate(text_x, text_y, text_w, text_h))
|
||||
is_running = false;
|
||||
};
|
||||
|
|
|
@ -112,7 +112,7 @@ void Terminal::run()
|
|||
|
||||
m_window = MUST(LibGUI::Window::create(600, 400, "Terminal"_sv));
|
||||
|
||||
auto attributes = LibGUI::Window::default_attributes;
|
||||
auto attributes = m_window->get_attributes();
|
||||
attributes.alpha_channel = true;
|
||||
m_window->set_attributes(attributes);
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ private:
|
|||
uint32_t* m_title_bar_data { nullptr };
|
||||
BAN::String m_title;
|
||||
|
||||
LibGUI::Window::Attributes m_attributes { LibGUI::Window::default_attributes };
|
||||
LibGUI::Window::Attributes m_attributes;
|
||||
|
||||
friend class BAN::RefPtr<Window>;
|
||||
};
|
||||
|
|
|
@ -181,55 +181,14 @@ void WindowServer::on_window_set_attributes(int fd, const LibGUI::WindowPacket::
|
|||
}
|
||||
|
||||
const auto old_client_area = target_window->full_area();
|
||||
target_window->set_attributes(packet.attributes);
|
||||
target_window->set_attributes({
|
||||
.title_bar = packet.title_bar,
|
||||
.movable = packet.movable,
|
||||
.rounded_corners = packet.rounded_corners,
|
||||
.alpha_channel = packet.alpha_channel,
|
||||
});
|
||||
const auto new_client_area = target_window->full_area();
|
||||
invalidate(new_client_area.get_bounding_box(old_client_area));
|
||||
|
||||
if (!packet.attributes.focusable && m_focused_window == target_window)
|
||||
{
|
||||
m_focused_window = nullptr;
|
||||
for (size_t i = m_client_windows.size(); i > 0; i--)
|
||||
{
|
||||
if (auto& window = m_client_windows[i - 1]; window->get_attributes().focusable)
|
||||
{
|
||||
set_focused_window(window);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WindowServer::on_window_set_mouse_capture(int fd, const LibGUI::WindowPacket::WindowSetMouseCapture& packet)
|
||||
{
|
||||
if (m_is_mouse_captured && packet.captured)
|
||||
{
|
||||
ASSERT(m_focused_window);
|
||||
if (fd != m_focused_window->client_fd())
|
||||
dwarnln("client tried to set mouse capture while other window has it already captured");
|
||||
return;
|
||||
}
|
||||
|
||||
BAN::RefPtr<Window> target_window;
|
||||
for (auto& window : m_client_windows)
|
||||
{
|
||||
if (window->client_fd() != fd)
|
||||
continue;
|
||||
target_window = window;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!target_window)
|
||||
{
|
||||
dwarnln("client tried to set mouse capture while not owning a window");
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet.captured == m_is_mouse_captured)
|
||||
return;
|
||||
|
||||
set_focused_window(target_window);
|
||||
m_is_mouse_captured = packet.captured;
|
||||
invalidate(cursor_area());
|
||||
}
|
||||
|
||||
void WindowServer::on_key_event(LibInput::KeyEvent event)
|
||||
|
@ -288,20 +247,6 @@ void WindowServer::on_key_event(LibInput::KeyEvent event)
|
|||
|
||||
void WindowServer::on_mouse_button(LibInput::MouseButtonEvent event)
|
||||
{
|
||||
if (m_is_mouse_captured)
|
||||
{
|
||||
ASSERT(m_focused_window);
|
||||
|
||||
LibGUI::EventPacket::MouseButtonEvent packet;
|
||||
packet.event.button = event.button;
|
||||
packet.event.pressed = event.pressed;
|
||||
packet.event.x = 0;
|
||||
packet.event.y = 0;
|
||||
if (auto ret = packet.send_serialized(m_focused_window->client_fd()); ret.is_error())
|
||||
dwarnln("could not send mouse button event: {}", ret.error());
|
||||
return;
|
||||
}
|
||||
|
||||
BAN::RefPtr<Window> target_window;
|
||||
for (size_t i = m_client_windows.size(); i > 0; i--)
|
||||
{
|
||||
|
@ -316,8 +261,7 @@ void WindowServer::on_mouse_button(LibInput::MouseButtonEvent event)
|
|||
if (!target_window)
|
||||
return;
|
||||
|
||||
if (target_window->get_attributes().focusable)
|
||||
set_focused_window(target_window);
|
||||
set_focused_window(target_window);
|
||||
|
||||
// Handle window moving when mod key is held or mouse press on title bar
|
||||
const bool can_start_move = m_is_mod_key_held || target_window->title_text_area().contains(m_cursor);
|
||||
|
@ -345,7 +289,7 @@ void WindowServer::on_mouse_button(LibInput::MouseButtonEvent event)
|
|||
packet.event.y = m_cursor.y - m_focused_window->client_y();
|
||||
if (auto ret = packet.send_serialized(m_focused_window->client_fd()); ret.is_error())
|
||||
{
|
||||
dwarnln("could not send mouse button event: {}", ret.error());
|
||||
dwarnln("could not send mouse button event event: {}", ret.error());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -353,18 +297,6 @@ void WindowServer::on_mouse_button(LibInput::MouseButtonEvent event)
|
|||
|
||||
void WindowServer::on_mouse_move(LibInput::MouseMoveEvent event)
|
||||
{
|
||||
if (m_is_mouse_captured)
|
||||
{
|
||||
ASSERT(m_focused_window);
|
||||
|
||||
LibGUI::EventPacket::MouseMoveEvent packet;
|
||||
packet.event.x = event.rel_x;
|
||||
packet.event.y = -event.rel_y;
|
||||
if (auto ret = packet.send_serialized(m_focused_window->client_fd()); ret.is_error())
|
||||
dwarnln("could not send mouse move event: {}", ret.error());
|
||||
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);
|
||||
|
||||
|
@ -409,7 +341,7 @@ void WindowServer::on_mouse_move(LibInput::MouseMoveEvent event)
|
|||
packet.event.y = m_cursor.y - m_focused_window->client_y();
|
||||
if (auto ret = packet.send_serialized(m_focused_window->client_fd()); ret.is_error())
|
||||
{
|
||||
dwarnln("could not send mouse move event: {}", ret.error());
|
||||
dwarnln("could not send mouse move event event: {}", ret.error());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -423,7 +355,7 @@ void WindowServer::on_mouse_scroll(LibInput::MouseScrollEvent event)
|
|||
packet.event.scroll = event.scroll;
|
||||
if (auto ret = packet.send_serialized(m_focused_window->client_fd()); ret.is_error())
|
||||
{
|
||||
dwarnln("could not send mouse scroll event: {}", ret.error());
|
||||
dwarnln("could not send mouse scroll event event: {}", ret.error());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -434,12 +366,6 @@ void WindowServer::set_focused_window(BAN::RefPtr<Window> window)
|
|||
if (m_focused_window == window)
|
||||
return;
|
||||
|
||||
if (m_is_mouse_captured)
|
||||
{
|
||||
m_is_mouse_captured = false;
|
||||
invalidate(cursor_area());
|
||||
}
|
||||
|
||||
for (size_t i = m_client_windows.size(); i > 0; i--)
|
||||
{
|
||||
if (m_client_windows[i - 1] == window)
|
||||
|
@ -663,25 +589,22 @@ void WindowServer::invalidate(Rectangle area)
|
|||
}
|
||||
}
|
||||
|
||||
if (!m_is_mouse_captured)
|
||||
auto cursor = cursor_area();
|
||||
if (auto overlap = cursor.get_overlap(area); overlap.has_value())
|
||||
{
|
||||
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++)
|
||||
{
|
||||
for (int32_t y_off = 0; y_off < overlap->height; y_off++)
|
||||
for (int32_t x_off = 0; x_off < overlap->width; x_off++)
|
||||
{
|
||||
for (int32_t x_off = 0; x_off < overlap->width; x_off++)
|
||||
{
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -695,9 +618,7 @@ void WindowServer::invalidate(Rectangle area)
|
|||
size_t index = (mmap_addr - reinterpret_cast<uintptr_t>(m_framebuffer.mmap)) / 4096;
|
||||
size_t byte = index / 8;
|
||||
size_t bit = index % 8;
|
||||
//dprintln("{}/{}", byte, m_pages_to_sync_bitmap.size());
|
||||
if (byte < m_pages_to_sync_bitmap.size())
|
||||
m_pages_to_sync_bitmap[byte] |= 1 << bit;
|
||||
m_pages_to_sync_bitmap[byte] |= 1 << bit;
|
||||
mmap_addr += 4096;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ public:
|
|||
void on_window_invalidate(int fd, const LibGUI::WindowPacket::WindowInvalidate&);
|
||||
void on_window_set_position(int fd, const LibGUI::WindowPacket::WindowSetPosition&);
|
||||
void on_window_set_attributes(int fd, const LibGUI::WindowPacket::WindowSetAttributes&);
|
||||
void on_window_set_mouse_capture(int fd, const LibGUI::WindowPacket::WindowSetMouseCapture&);
|
||||
|
||||
void on_key_event(LibInput::KeyEvent event);
|
||||
void on_mouse_button(LibInput::MouseButtonEvent event);
|
||||
|
@ -71,8 +70,6 @@ private:
|
|||
BAN::RefPtr<Window> m_focused_window;
|
||||
Position m_cursor;
|
||||
|
||||
bool m_is_mouse_captured { false };
|
||||
|
||||
bool m_deleted_window { false };
|
||||
bool m_is_stopped { false };
|
||||
bool m_is_bouncing_window = false;
|
||||
|
|
|
@ -350,10 +350,6 @@ int main()
|
|||
if (auto ret = LibGUI::WindowPacket::WindowSetAttributes::deserialize(client_data.packet_buffer.span()); !ret.is_error())
|
||||
window_server.on_window_set_attributes(fd, ret.release_value());
|
||||
break;
|
||||
case LibGUI::PacketType::WindowSetMouseCapture:
|
||||
if (auto ret = LibGUI::WindowPacket::WindowSetMouseCapture::deserialize(client_data.packet_buffer.span()); !ret.is_error())
|
||||
window_server.on_window_set_mouse_capture(fd, ret.release_value());
|
||||
break;
|
||||
default:
|
||||
dprintln("unhandled packet type: {}", *reinterpret_cast<uint32_t*>(client_data.packet_buffer.data()));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue