From f2546d15cecd6e70066285245312a55010379d65 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Wed, 4 Dec 2019 16:15:31 +0300 Subject: [PATCH] Taskbar: Add a quick launch bar This is a tiny bar at the left of the taskbar where you can put your most used apps to launch them with a single click. In a way, it's another replacement for the Launcher, in addition to the app menu. Unlike the launcher and the menu, it's not meant to be the primary way to launch apps; it's only a faster way to launch a few most often used utilities. --- Applications/Taskbar/TaskbarWindow.cpp | 57 ++++++++++++++++++++++++++ Applications/Taskbar/TaskbarWindow.h | 1 + Applications/Taskbar/main.cpp | 7 ++++ Base/home/anon/Taskbar.ini | 4 ++ 4 files changed, 69 insertions(+) create mode 100644 Base/home/anon/Taskbar.ini diff --git a/Applications/Taskbar/TaskbarWindow.cpp b/Applications/Taskbar/TaskbarWindow.cpp index 8213df6698..6aba1a0a61 100644 --- a/Applications/Taskbar/TaskbarWindow.cpp +++ b/Applications/Taskbar/TaskbarWindow.cpp @@ -1,6 +1,7 @@ #include "TaskbarWindow.h" #include "TaskbarButton.h" #include +#include #include #include #include @@ -32,12 +33,68 @@ TaskbarWindow::TaskbarWindow() WindowList::the().aid_create_button = [this](auto& identifier) { return create_button(identifier); }; + + create_quick_launch_bar(); } TaskbarWindow::~TaskbarWindow() { } +void TaskbarWindow::create_quick_launch_bar() +{ + auto quick_launch_bar = GFrame::construct(main_widget()); + quick_launch_bar->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); + quick_launch_bar->set_layout(make(Orientation::Horizontal)); + quick_launch_bar->layout()->set_spacing(3); + quick_launch_bar->layout()->set_margins({ 3, 0, 3, 0 }); + quick_launch_bar->set_frame_thickness(1); + quick_launch_bar->set_frame_shape(FrameShape::Container); + quick_launch_bar->set_frame_shadow(FrameShadow::Raised); + + int total_width = 6; + bool first = true; + + auto config = CConfigFile::get_for_app("Taskbar"); + constexpr const char* quick_launch = "QuickLaunch"; + + // FIXME: CConfigFile does not keep the order of the entries. + for (auto& name : config->keys(quick_launch)) { + auto af_name = config->read_entry(quick_launch, name); + ASSERT(!af_name.is_null()); + auto af_path = String::format("/res/apps/%s", af_name.characters()); + auto af = CConfigFile::open(af_path); + auto app_executable = af->read_entry("App", "Executable"); + auto app_icon_path = af->read_entry("Icons", "16x16"); + + auto button = GButton::construct(quick_launch_bar); + button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); + button->set_preferred_size(22, 22); + button->set_button_style(ButtonStyle::CoolBar); + + button->set_icon(GraphicsBitmap::load_from_file(app_icon_path)); + // FIXME: the tooltip ends up outside the screen rect. + button->set_tooltip(name); + button->on_click = [app_executable](auto&) { + pid_t pid = fork(); + if (pid < 0) { + perror("fork"); + } else if (pid == 0) { + execl(app_executable.characters(), app_executable.characters(), nullptr); + perror("execl"); + ASSERT_NOT_REACHED(); + } + }; + + if (!first) + total_width += 3; + first = false; + total_width += 22; + } + + quick_launch_bar->set_preferred_size(total_width, 22); +} + void TaskbarWindow::on_screen_rect_change(const Rect& rect) { Rect new_rect { rect.x(), rect.bottom() - taskbar_height() + 1, rect.width(), taskbar_height() }; diff --git a/Applications/Taskbar/TaskbarWindow.h b/Applications/Taskbar/TaskbarWindow.h index 49f222adbd..b38269a230 100644 --- a/Applications/Taskbar/TaskbarWindow.h +++ b/Applications/Taskbar/TaskbarWindow.h @@ -11,6 +11,7 @@ public: int taskbar_height() const { return 28; } private: + void create_quick_launch_bar(); void on_screen_rect_change(const Rect&); NonnullRefPtr create_button(const WindowIdentifier&); diff --git a/Applications/Taskbar/main.cpp b/Applications/Taskbar/main.cpp index 73356d2588..d2d03f9b5c 100644 --- a/Applications/Taskbar/main.cpp +++ b/Applications/Taskbar/main.cpp @@ -1,10 +1,17 @@ #include "TaskbarWindow.h" #include +#include int main(int argc, char** argv) { GApplication app(argc, argv); TaskbarWindow window; window.show(); + + signal(SIGCHLD, [](int signo) { + (void)signo; + wait(nullptr); + }); + return app.exec(); } diff --git a/Base/home/anon/Taskbar.ini b/Base/home/anon/Taskbar.ini new file mode 100644 index 0000000000..4e39d0b316 --- /dev/null +++ b/Base/home/anon/Taskbar.ini @@ -0,0 +1,4 @@ +[QuickLaunch] +SystemMonitor=SystemMonitor.af +Terminal=Terminal.af +FileManager=FileManager.af