taskbar: Make taskbar entries configurable
This commit is contained in:
parent
ff10e5f3b2
commit
82985d691d
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,6 +10,7 @@ base/usr/*
|
|||||||
base/usr/share/*
|
base/usr/share/*
|
||||||
!base/usr/share/fonts
|
!base/usr/share/fonts
|
||||||
!base/usr/share/icons
|
!base/usr/share/icons
|
||||||
|
!base/usr/share/applications
|
||||||
base/etc/skel/LICENSE
|
base/etc/skel/LICENSE
|
||||||
.fakeroot
|
.fakeroot
|
||||||
kernel/config.cmake
|
kernel/config.cmake
|
||||||
|
132
apps/taskbar.cpp
132
apps/taskbar.cpp
@ -1,4 +1,8 @@
|
|||||||
|
#include <luna/Sort.h>
|
||||||
|
#include <luna/StringBuilder.h>
|
||||||
|
#include <os/Directory.h>
|
||||||
#include <os/File.h>
|
#include <os/File.h>
|
||||||
|
#include <os/FileSystem.h>
|
||||||
#include <os/IPC.h>
|
#include <os/IPC.h>
|
||||||
#include <os/Process.h>
|
#include <os/Process.h>
|
||||||
#include <os/ipc/Launcher.h>
|
#include <os/ipc/Launcher.h>
|
||||||
@ -19,15 +23,20 @@ void sigchld_handler(int)
|
|||||||
wait(nullptr);
|
wait(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sighup_handler(int)
|
||||||
|
{
|
||||||
|
// Reload the taskbar by exec-ing the executable, resetting everything.
|
||||||
|
StringView args[] = { "/usr/bin/taskbar" };
|
||||||
|
os::Process::exec(args[0], { args, 1 });
|
||||||
|
}
|
||||||
|
|
||||||
Result<void> create_widget_group_for_app(ui::HorizontalLayout& layout, StringView path, StringView icon)
|
Result<void> create_widget_group_for_app(ui::HorizontalLayout& layout, StringView path, StringView icon)
|
||||||
{
|
{
|
||||||
auto* button = new (std::nothrow) ui::Button({ 0, 0, 50, 50 });
|
auto* button = TRY(make<ui::Button>(ui::Rect { 0, 0, 50, 50 }));
|
||||||
if (!button) return err(ENOMEM);
|
|
||||||
layout.add_widget(*button);
|
layout.add_widget(*button);
|
||||||
|
|
||||||
auto* container = new (std::nothrow)
|
auto* container = TRY(
|
||||||
ui::Container({ 0, 0, 50, 50 }, ui::VerticalAlignment::Center, ui::HorizontalAlignment::Center);
|
make<ui::Container>(ui::Rect { 0, 0, 50, 50 }, ui::VerticalAlignment::Center, ui::HorizontalAlignment::Center));
|
||||||
if (!container) return err(ENOMEM);
|
|
||||||
button->set_widget(*container);
|
button->set_widget(*container);
|
||||||
button->set_action([=] {
|
button->set_action([=] {
|
||||||
os::Launcher::LaunchDetachedRequest request;
|
os::Launcher::LaunchDetachedRequest request;
|
||||||
@ -43,12 +52,106 @@ Result<void> create_widget_group_for_app(ui::HorizontalLayout& layout, StringVie
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ApplicationFile
|
||||||
|
{
|
||||||
|
String name;
|
||||||
|
String command;
|
||||||
|
String icon;
|
||||||
|
};
|
||||||
|
|
||||||
|
Vector<ApplicationFile> s_app_files;
|
||||||
|
|
||||||
|
// Pretty much copied from init.cpp.
|
||||||
|
static Result<void> load_application_file(const os::Path& path)
|
||||||
|
{
|
||||||
|
os::println("[taskbar] reading app file: %s", path.name().chars());
|
||||||
|
|
||||||
|
auto file = TRY(os::File::open(path, os::File::ReadOnly));
|
||||||
|
|
||||||
|
ApplicationFile app_file;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
auto line = TRY(file->read_line());
|
||||||
|
if (line.is_empty()) break;
|
||||||
|
|
||||||
|
line.trim("\n");
|
||||||
|
if (line.is_empty()) continue;
|
||||||
|
|
||||||
|
auto parts = TRY(line.split_once('='));
|
||||||
|
if (parts.size() < 2 || parts[0].is_empty() || parts[1].is_empty())
|
||||||
|
{
|
||||||
|
os::println("[taskbar] file contains invalid line, aborting: '%s'", line.chars());
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parts[0].view() == "Name")
|
||||||
|
{
|
||||||
|
app_file.name = move(parts[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parts[0].view() == "Description")
|
||||||
|
{
|
||||||
|
// We let users specify this in the config file, but taskbar doesn't actually use it.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parts[0].view() == "Command")
|
||||||
|
{
|
||||||
|
app_file.command = move(parts[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parts[0].view() == "Icon")
|
||||||
|
{
|
||||||
|
app_file.icon = move(parts[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
os::println("[taskbar] skipping unknown entry name %s", parts[0].chars());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (app_file.icon.is_empty())
|
||||||
|
{
|
||||||
|
os::println("[taskbar] app file is missing 'Icon' entry, aborting!");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (app_file.command.is_empty())
|
||||||
|
{
|
||||||
|
os::println("[taskbar] app file is missing 'Command' entry, aborting!");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
os::println("[taskbar] loaded app %s into memory", app_file.name.chars());
|
||||||
|
|
||||||
|
TRY(s_app_files.try_append(move(app_file)));
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
static Result<void> load_app_files_from_path(StringView path)
|
||||||
|
{
|
||||||
|
os::println("[taskbar] loading app files from %s", path.chars());
|
||||||
|
|
||||||
|
auto dir = TRY(os::Directory::open(path));
|
||||||
|
|
||||||
|
auto services = TRY(dir->list_names(os::Directory::Filter::ParentAndBase));
|
||||||
|
sort(services.begin(), services.end(), String::compare);
|
||||||
|
|
||||||
|
for (const auto& entry : services) TRY(load_application_file({ dir->fd(), entry.view() }));
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
Result<int> luna_main(int, char**)
|
Result<int> luna_main(int, char**)
|
||||||
{
|
{
|
||||||
ui::App app;
|
ui::App app;
|
||||||
TRY(app.init("/tmp/wsys.sock"));
|
TRY(app.init("/tmp/wsys.sock"));
|
||||||
|
|
||||||
TRY(os::EventLoop::the().register_signal_handler(SIGCHLD, sigchld_handler));
|
TRY(os::EventLoop::the().register_signal_handler(SIGCHLD, sigchld_handler));
|
||||||
|
TRY(os::EventLoop::the().register_signal_handler(SIGHUP, sighup_handler));
|
||||||
|
|
||||||
launcher_client = TRY(os::IPC::Client::connect("/tmp/launch.sock", false));
|
launcher_client = TRY(os::IPC::Client::connect("/tmp/launch.sock", false));
|
||||||
|
|
||||||
@ -65,10 +168,21 @@ Result<int> luna_main(int, char**)
|
|||||||
ui::HorizontalLayout layout(ui::Margins { 0, 0, 0, 0 }, ui::AdjustHeight::Yes, ui::AdjustWidth::No);
|
ui::HorizontalLayout layout(ui::Margins { 0, 0, 0, 0 }, ui::AdjustHeight::Yes, ui::AdjustWidth::No);
|
||||||
window->set_main_widget(layout);
|
window->set_main_widget(layout);
|
||||||
|
|
||||||
TRY(create_widget_group_for_app(layout, "/usr/bin/terminal", "/usr/share/icons/32x32/app-terminal.tga"));
|
load_app_files_from_path("/usr/share/applications/");
|
||||||
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"));
|
auto home = TRY(os::FileSystem::home_directory());
|
||||||
TRY(create_widget_group_for_app(layout, "/usr/bin/clock", "/usr/share/icons/32x32/app-clock.tga"));
|
|
||||||
|
StringBuilder sb;
|
||||||
|
TRY(sb.add(home.view()));
|
||||||
|
TRY(sb.add("/.applications/"_sv));
|
||||||
|
auto local_app_file_dir = TRY(sb.string());
|
||||||
|
|
||||||
|
load_app_files_from_path(local_app_file_dir.view());
|
||||||
|
|
||||||
|
for (const auto& app_file : s_app_files)
|
||||||
|
{
|
||||||
|
create_widget_group_for_app(layout, app_file.command.view(), app_file.icon.view());
|
||||||
|
}
|
||||||
|
|
||||||
return app.run();
|
return app.run();
|
||||||
}
|
}
|
||||||
|
3
base/usr/share/applications/00-terminal
Normal file
3
base/usr/share/applications/00-terminal
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Name=terminal
|
||||||
|
Icon=/usr/share/icons/32x32/app-terminal.tga
|
||||||
|
Command=/usr/bin/terminal
|
3
base/usr/share/applications/01-about
Normal file
3
base/usr/share/applications/01-about
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Name=about
|
||||||
|
Icon=/usr/share/icons/32x32/app-about.tga
|
||||||
|
Command=/usr/bin/about
|
3
base/usr/share/applications/02-gol
Normal file
3
base/usr/share/applications/02-gol
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Name=gol
|
||||||
|
Icon=/usr/share/icons/32x32/app-gol.tga
|
||||||
|
Command=/usr/bin/gol
|
3
base/usr/share/applications/03-clock
Normal file
3
base/usr/share/applications/03-clock
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Name=clock
|
||||||
|
Icon=/usr/share/icons/32x32/app-clock.tga
|
||||||
|
Command=/usr/bin/clock
|
Loading…
Reference in New Issue
Block a user