2023-09-11 17:15:26 +00:00
|
|
|
#include <os/File.h>
|
2024-02-01 20:58:44 +00:00
|
|
|
#include <os/IPC.h>
|
2023-08-15 13:33:44 +00:00
|
|
|
#include <os/Process.h>
|
2024-02-01 20:58:44 +00:00
|
|
|
#include <os/ipc/Launcher.h>
|
2023-08-16 14:49:08 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/wait.h>
|
2023-08-15 10:56:55 +00:00
|
|
|
#include <ui/App.h>
|
2023-08-15 13:33:44 +00:00
|
|
|
#include <ui/Button.h>
|
2023-08-15 12:42:21 +00:00
|
|
|
#include <ui/Container.h>
|
|
|
|
#include <ui/Image.h>
|
2023-08-15 10:56:55 +00:00
|
|
|
#include <ui/Layout.h>
|
|
|
|
|
2023-09-20 17:45:01 +00:00
|
|
|
static constexpr ui::Color TASKBAR_COLOR = ui::Color::from_rgb(83, 83, 83);
|
|
|
|
|
2024-02-03 18:16:39 +00:00
|
|
|
static OwnedPtr<os::IPC::Client> launcher_client;
|
2024-02-01 20:58:44 +00:00
|
|
|
|
2023-08-16 14:49:08 +00:00
|
|
|
void sigchld_handler(int)
|
|
|
|
{
|
|
|
|
wait(nullptr);
|
|
|
|
}
|
|
|
|
|
2024-02-01 20:58:44 +00:00
|
|
|
Result<void> create_widget_group_for_app(ui::HorizontalLayout& layout, StringView path, StringView icon)
|
2023-09-27 16:52:17 +00:00
|
|
|
{
|
|
|
|
auto* button = new (std::nothrow) ui::Button({ 0, 0, 50, 50 });
|
|
|
|
if (!button) return err(ENOMEM);
|
|
|
|
layout.add_widget(*button);
|
|
|
|
|
|
|
|
auto* container = new (std::nothrow)
|
|
|
|
ui::Container({ 0, 0, 50, 50 }, ui::VerticalAlignment::Center, ui::HorizontalAlignment::Center);
|
|
|
|
if (!container) return err(ENOMEM);
|
|
|
|
button->set_widget(*container);
|
2024-02-01 20:58:44 +00:00
|
|
|
button->set_action([=] {
|
|
|
|
os::Launcher::LaunchDetachedRequest request;
|
|
|
|
SET_IPC_STRING(request.command, path.chars());
|
2024-02-03 18:16:39 +00:00
|
|
|
launcher_client->send_async(request);
|
2024-02-01 20:58:44 +00:00
|
|
|
});
|
2023-09-27 16:52:17 +00:00
|
|
|
|
|
|
|
auto image = TRY(ui::ImageWidget::load(icon));
|
|
|
|
container->set_widget(*image);
|
|
|
|
|
|
|
|
image.leak();
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2024-02-01 20:15:31 +00:00
|
|
|
Result<int> luna_main(int, char**)
|
2023-08-15 10:56:55 +00:00
|
|
|
{
|
|
|
|
ui::App app;
|
2024-02-01 20:58:44 +00:00
|
|
|
TRY(app.init("/tmp/wsys.sock"));
|
2023-08-15 10:56:55 +00:00
|
|
|
|
2023-10-09 20:14:34 +00:00
|
|
|
TRY(os::EventLoop::the().register_signal_handler(SIGCHLD, sigchld_handler));
|
2023-08-16 14:49:08 +00:00
|
|
|
|
2024-02-03 18:16:39 +00:00
|
|
|
launcher_client = TRY(os::IPC::Client::connect("/tmp/launch.sock", false));
|
2024-02-01 20:58:44 +00:00
|
|
|
|
2023-08-15 10:56:55 +00:00
|
|
|
ui::Rect screen = app.screen_rect();
|
|
|
|
|
|
|
|
ui::Rect bar = ui::Rect { ui::Point { 0, screen.height - 50 }, screen.width, 50 };
|
|
|
|
|
2023-09-27 16:14:32 +00:00
|
|
|
auto window = TRY(ui::Window::create(bar, ui::WindowType::System));
|
2023-08-15 10:56:55 +00:00
|
|
|
app.set_main_window(window);
|
2023-10-10 20:24:11 +00:00
|
|
|
|
2023-09-20 17:45:01 +00:00
|
|
|
window->set_background(TASKBAR_COLOR);
|
2024-02-04 12:35:50 +00:00
|
|
|
window->set_special_attributes(ui::UNFOCUSEABLE);
|
2023-08-15 10:56:55 +00:00
|
|
|
|
2023-09-27 16:52:17 +00:00
|
|
|
ui::HorizontalLayout layout(ui::Margins { 0, 0, 0, 0 }, ui::AdjustHeight::Yes, ui::AdjustWidth::No);
|
2023-08-15 10:56:55 +00:00
|
|
|
window->set_main_widget(layout);
|
|
|
|
|
2024-02-01 20:58:44 +00:00
|
|
|
TRY(create_widget_group_for_app(layout, "/usr/bin/terminal", "/usr/share/icons/32x32/app-terminal.tga"));
|
|
|
|
TRY(create_widget_group_for_app(layout, "/usr/bin/about", "/usr/share/icons/32x32/app-about.tga"));
|
|
|
|
TRY(create_widget_group_for_app(layout, "/usr/bin/gol", "/usr/share/icons/32x32/app-gol.tga"));
|
|
|
|
TRY(create_widget_group_for_app(layout, "/usr/bin/clock", "/usr/share/icons/32x32/app-clock.tga"));
|
2023-10-09 20:05:30 +00:00
|
|
|
|
2023-08-15 10:56:55 +00:00
|
|
|
return app.run();
|
|
|
|
}
|