mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +00:00
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.
This commit is contained in:
parent
d111b6ead4
commit
f2546d15ce
4 changed files with 69 additions and 0 deletions
|
@ -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() };
|
||||
|
|
|
@ -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&);
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
4
Base/home/anon/Taskbar.ini
Normal file
4
Base/home/anon/Taskbar.ini
Normal file
|
@ -0,0 +1,4 @@
|
|||
[QuickLaunch]
|
||||
SystemMonitor=SystemMonitor.af
|
||||
Terminal=Terminal.af
|
||||
FileManager=FileManager.af
|
Loading…
Add table
Add a link
Reference in a new issue