diff options
author | Sergey Bugaev <bugaevc@gmail.com> | 2019-12-04 16:15:31 +0300 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-12-04 14:32:15 +0100 |
commit | f2546d15cecd6e70066285245312a55010379d65 (patch) | |
tree | 312e5129e231c6a34f0f5b1f4b25df6848acd2f8 /Applications | |
parent | d111b6ead445590148a4b5f352c925a5f9eb0ca0 (diff) | |
download | serenity-f2546d15cecd6e70066285245312a55010379d65.zip |
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.
Diffstat (limited to 'Applications')
-rw-r--r-- | Applications/Taskbar/TaskbarWindow.cpp | 57 | ||||
-rw-r--r-- | Applications/Taskbar/TaskbarWindow.h | 1 | ||||
-rw-r--r-- | Applications/Taskbar/main.cpp | 7 |
3 files changed, 65 insertions, 0 deletions
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 <LibC/SharedBuffer.h> +#include <LibCore/CConfigFile.h> #include <LibGUI/GBoxLayout.h> #include <LibGUI/GButton.h> #include <LibGUI/GDesktop.h> @@ -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<GBoxLayout>(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<GButton> 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 <LibGUI/GApplication.h> +#include <signal.h> 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(); } |