wind+libui+taskbar: Add various window types and never focus the taskbar
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
f0844c9f69
commit
9a9c7e577a
@ -26,7 +26,7 @@ Result<int> luna_main(int argc, char** argv)
|
||||
|
||||
ui::Rect bar = ui::Rect { ui::Point { 0, screen.height - 50 }, screen.width, 50 };
|
||||
|
||||
auto window = TRY(ui::Window::create(bar, false));
|
||||
auto window = TRY(ui::Window::create(bar, ui::WindowType::System));
|
||||
app.set_main_window(window);
|
||||
window->set_background(TASKBAR_COLOR);
|
||||
|
||||
|
@ -14,13 +14,14 @@
|
||||
#include <ui/Mouse.h>
|
||||
#include <ui/Rect.h>
|
||||
#include <ui/Widget.h>
|
||||
#include <ui/ipc/Server.h>
|
||||
|
||||
namespace ui
|
||||
{
|
||||
class Window
|
||||
{
|
||||
public:
|
||||
static Result<Window*> create(Rect rect, bool decorated = true);
|
||||
static Result<Window*> create(Rect rect, WindowType type = WindowType::Normal);
|
||||
|
||||
void set_title(StringView title);
|
||||
|
||||
|
@ -25,13 +25,20 @@ namespace ui
|
||||
GET_SCREEN_RECT_ID,
|
||||
};
|
||||
|
||||
enum class WindowType : u8
|
||||
{
|
||||
Normal,
|
||||
NotDecorated,
|
||||
System,
|
||||
};
|
||||
|
||||
struct CreateWindowRequest
|
||||
{
|
||||
using ResponseType = CreateWindowResponse;
|
||||
static constexpr u8 ID = CREATE_WINDOW_ID;
|
||||
|
||||
ui::Rect rect;
|
||||
bool decorated;
|
||||
WindowType type;
|
||||
};
|
||||
|
||||
struct SetWindowTitleRequest
|
||||
|
@ -16,13 +16,13 @@
|
||||
|
||||
namespace ui
|
||||
{
|
||||
Result<Window*> Window::create(Rect rect, bool decorated)
|
||||
Result<Window*> Window::create(Rect rect, WindowType type)
|
||||
{
|
||||
auto window = TRY(make_owned<Window>());
|
||||
|
||||
ui::CreateWindowRequest request;
|
||||
request.rect = rect;
|
||||
request.decorated = decorated;
|
||||
request.type = type;
|
||||
auto response = TRY(os::IPC::send_sync<ui::CreateWindowResponse>(App::the().client(), request));
|
||||
|
||||
auto path = COPY_IPC_STRING(response.shm_path);
|
||||
|
@ -56,7 +56,7 @@ static Result<void> handle_create_window_message(Client& client)
|
||||
ui::CreateWindowRequest request;
|
||||
READ_MESSAGE(request);
|
||||
|
||||
if (request.decorated)
|
||||
if (request.type == ui::WindowType::Normal)
|
||||
{
|
||||
request.rect.height +=
|
||||
Window::titlebar_height(); // Make sure we provide the full contents rect that was asked for.
|
||||
@ -69,7 +69,7 @@ static Result<void> handle_create_window_message(Client& client)
|
||||
|
||||
auto shm_path = TRY(String::format("/wind-shm-%d-%lu"_sv, client.conn.fd(), time(NULL)));
|
||||
|
||||
auto* window = new (std::nothrow) Window(request.rect, move(name), request.decorated);
|
||||
auto* window = new (std::nothrow) Window(request.rect, move(name), request.type);
|
||||
if (!window)
|
||||
{
|
||||
os::IPC::send_error(client.conn, ENOMEM);
|
||||
|
@ -82,7 +82,7 @@ void Mouse::update(const moon::MousePacket& packet)
|
||||
}
|
||||
else if (window->surface.absolute(window->contents).contains(m_position))
|
||||
{
|
||||
window->focus();
|
||||
if (window->type != ui::WindowType::System) window->focus();
|
||||
break; // We don't want to continue iterating, otherwise this would take into account windows whose
|
||||
// titlebar is underneath another window's contents!
|
||||
}
|
||||
|
@ -43,9 +43,10 @@ void Window::focus()
|
||||
g_windows.append(this);
|
||||
}
|
||||
|
||||
Window::Window(ui::Rect r, String&& n, bool d) : surface(r), name(move(n)), decorated(d)
|
||||
Window::Window(ui::Rect r, String&& n, ui::WindowType t) : surface(r), name(move(n)), type(t)
|
||||
{
|
||||
auto font = ui::Font::default_font();
|
||||
bool decorated { type == ui::WindowType::Normal };
|
||||
if (decorated && surface.width < 36) surface.width = 36;
|
||||
if (decorated && surface.height < (font->height() + 20)) surface.height = font->height() + 20;
|
||||
titlebar = decorated ? ui::Rect { 0, 0, surface.width, font->height() + 20 } : ui::Rect { 0, 0, 0, 0 };
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <ui/Canvas.h>
|
||||
#include <ui/Color.h>
|
||||
#include <ui/Rect.h>
|
||||
#include <ui/ipc/Server.h>
|
||||
|
||||
struct Client;
|
||||
|
||||
@ -18,11 +19,11 @@ struct Window : public LinkedListNode<Window>
|
||||
bool dirty { false };
|
||||
Client* client;
|
||||
int id;
|
||||
bool decorated;
|
||||
ui::WindowType type;
|
||||
|
||||
static int titlebar_height();
|
||||
|
||||
Window(ui::Rect, String&&, bool);
|
||||
Window(ui::Rect, String&&, ui::WindowType);
|
||||
~Window();
|
||||
|
||||
void focus();
|
||||
|
@ -36,9 +36,9 @@ static void debug(const Vector<OwnedPtr<Client>>& clients)
|
||||
for (const auto& window : g_windows)
|
||||
{
|
||||
os::println("Window of client (fd %d), id %d, %sdecorated, %sdirty (\"%s\") (%d,%d,%d,%d)",
|
||||
window->client->conn.fd(), window->id, window->decorated ? "" : "not ", window->dirty ? "" : "not ",
|
||||
window->name.chars(), window->surface.pos.x, window->surface.pos.y, window->surface.width,
|
||||
window->surface.height);
|
||||
window->client->conn.fd(), window->id, window->type == ui::WindowType::Normal ? "" : "not ",
|
||||
window->dirty ? "" : "not ", window->name.chars(), window->surface.pos.x, window->surface.pos.y,
|
||||
window->surface.width, window->surface.height);
|
||||
}
|
||||
|
||||
os::println("-- wind: Listing processes --");
|
||||
|
Loading…
Reference in New Issue
Block a user