Luna/apps/taskbar.cpp

64 lines
1.9 KiB
C++
Raw Normal View History

2023-09-11 17:15:26 +00:00
#include <os/File.h>
2023-08-15 13:33:44 +00:00
#include <os/Process.h>
#include <signal.h>
#include <sys/wait.h>
#include <ui/App.h>
2023-08-15 13:33:44 +00:00
#include <ui/Button.h>
#include <ui/Container.h>
#include <ui/Image.h>
#include <ui/Layout.h>
void sigchld_handler(int)
{
wait(nullptr);
}
Result<int> luna_main(int argc, char** argv)
{
ui::App app;
TRY(app.init(argc, argv));
signal(SIGCHLD, sigchld_handler);
ui::Rect screen = app.screen_rect();
ui::Rect bar = ui::Rect { ui::Point { 0, screen.height - 50 }, screen.width, 50 };
auto window = TRY(ui::Window::create(bar, false));
app.set_main_window(window);
window->set_background(ui::GRAY);
ui::HorizontalLayout layout(ui::AdjustHeight::Yes, ui::AdjustWidth::No);
window->set_main_widget(layout);
2023-09-11 17:15:26 +00:00
ui::Button start_button({ 0, 0, 50, 50 });
layout.add_widget(start_button);
2023-08-15 13:33:44 +00:00
2023-09-11 17:15:26 +00:00
ui::Container start_container({ 0, 0, 50, 50 }, ui::VerticalAlignment::Center, ui::HorizontalAlignment::Center);
start_button.set_widget(start_container);
start_button.set_action([] {
2023-08-15 13:33:44 +00:00
StringView args[] = { "/usr/bin/gclient" };
os::Process::spawn("/usr/bin/gclient", Slice<StringView> { args, 1 }, false);
});
2023-09-11 17:15:26 +00:00
auto start_image = TRY(ui::ImageWidget::load("/usr/share/icons/32x32/start-icon.tga"));
start_container.set_widget(*start_image);
ui::Button about_button({ 0, 0, 50, 50 });
layout.add_widget(about_button);
ui::Container about_container({ 0, 0, 50, 50 }, ui::VerticalAlignment::Center, ui::HorizontalAlignment::Center);
about_button.set_widget(about_container);
about_button.set_action([] {
StringView args[] = { "/usr/bin/about" };
os::Process::spawn("/usr/bin/about", Slice<StringView> { args, 1 }, false);
});
auto about_image = TRY(ui::ImageWidget::load("/usr/share/icons/32x32/app-about.tga"));
about_container.set_widget(*about_image);
window->draw();
return app.run();
}