mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
Taskbar: Make quicklaunch bar editable
This change adds a ConfigServer Listener to TaskbarWindow. Items in the quicklaunch bar may be added or removed by editing the Taskbar config.
This commit is contained in:
parent
06cb526feb
commit
480903fe8a
Notes:
sideshowbarker
2024-07-18 01:08:39 +09:00
Author: https://github.com/faxe1008 Commit: https://github.com/SerenityOS/serenity/commit/480903fe8af Pull-request: https://github.com/SerenityOS/serenity/pull/10906
4 changed files with 83 additions and 38 deletions
|
@ -14,5 +14,5 @@ set(SOURCES
|
|||
)
|
||||
|
||||
serenity_bin(Taskbar)
|
||||
target_link_libraries(Taskbar LibGUI LibDesktop)
|
||||
target_link_libraries(Taskbar LibGUI LibDesktop LibConfig)
|
||||
serenity_install_headers(Services/Taskbar)
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
#include <serenity.h>
|
||||
#include <stdio.h>
|
||||
|
||||
constexpr const char* quick_launch = "QuickLaunch";
|
||||
constexpr int quick_launch_button_size = 24;
|
||||
|
||||
class TaskbarWidget final : public GUI::Widget {
|
||||
C_OBJECT(TaskbarWidget);
|
||||
|
||||
|
@ -108,16 +111,42 @@ void TaskbarWindow::show_desktop_button_clicked(unsigned)
|
|||
GUI::WindowManagerServerConnection::the().async_toggle_show_desktop();
|
||||
}
|
||||
|
||||
void TaskbarWindow::config_key_was_removed(String const& domain, String const& group, String const& key)
|
||||
{
|
||||
if (domain == "Taskbar" && group == quick_launch) {
|
||||
auto button = m_quick_launch_bar->find_child_of_type_named<GUI::Button>(key);
|
||||
if (button)
|
||||
m_quick_launch_bar->remove_child(*button);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskbarWindow::config_string_did_change(String const& domain, String const& group, String const& key, String const& value)
|
||||
{
|
||||
if (domain == "Taskbar" && group == quick_launch) {
|
||||
auto af_path = String::formatted("{}/{}", Desktop::AppFile::APP_FILES_DIRECTORY, value);
|
||||
auto af = Desktop::AppFile::open(af_path);
|
||||
if (!af->is_valid())
|
||||
return;
|
||||
|
||||
auto button = m_quick_launch_bar->find_child_of_type_named<GUI::Button>(key);
|
||||
if (button) {
|
||||
set_quick_launch_button_data(*button, key, af);
|
||||
} else {
|
||||
auto& new_button = m_quick_launch_bar->add<GUI::Button>();
|
||||
set_quick_launch_button_data(new_button, key, af);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TaskbarWindow::create_quick_launch_bar()
|
||||
{
|
||||
auto& quick_launch_bar = main_widget()->add<GUI::Frame>();
|
||||
quick_launch_bar.set_shrink_to_fit(true);
|
||||
quick_launch_bar.set_layout<GUI::HorizontalBoxLayout>();
|
||||
quick_launch_bar.layout()->set_spacing(0);
|
||||
quick_launch_bar.set_frame_thickness(0);
|
||||
m_quick_launch_bar = main_widget()->add<GUI::Frame>();
|
||||
m_quick_launch_bar->set_shrink_to_fit(true);
|
||||
m_quick_launch_bar->set_layout<GUI::HorizontalBoxLayout>();
|
||||
m_quick_launch_bar->layout()->set_spacing(0);
|
||||
m_quick_launch_bar->set_frame_thickness(0);
|
||||
|
||||
auto config = Core::ConfigFile::open_for_app("Taskbar");
|
||||
constexpr const char* quick_launch = "QuickLaunch";
|
||||
|
||||
// FIXME: Core::ConfigFile does not keep the order of the entries.
|
||||
for (auto& name : config->keys(quick_launch)) {
|
||||
|
@ -126,36 +155,41 @@ void TaskbarWindow::create_quick_launch_bar()
|
|||
auto af = Desktop::AppFile::open(af_path);
|
||||
if (!af->is_valid())
|
||||
continue;
|
||||
auto app_executable = af->executable();
|
||||
auto app_run_in_terminal = af->run_in_terminal();
|
||||
const int button_size = 24;
|
||||
auto& button = quick_launch_bar.add<GUI::Button>();
|
||||
button.set_fixed_size(button_size, button_size);
|
||||
button.set_button_style(Gfx::ButtonStyle::Coolbar);
|
||||
button.set_icon(af->icon().bitmap_for_size(16));
|
||||
button.set_tooltip(af->name());
|
||||
button.on_click = [app_executable, app_run_in_terminal](auto) {
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
perror("fork");
|
||||
} else if (pid == 0) {
|
||||
if (chdir(Core::StandardPaths::home_directory().characters()) < 0) {
|
||||
perror("chdir");
|
||||
exit(1);
|
||||
}
|
||||
if (app_run_in_terminal)
|
||||
execl("/bin/Terminal", "Terminal", "-e", app_executable.characters(), nullptr);
|
||||
else
|
||||
execl(app_executable.characters(), app_executable.characters(), nullptr);
|
||||
perror("execl");
|
||||
VERIFY_NOT_REACHED();
|
||||
} else {
|
||||
if (disown(pid) < 0)
|
||||
perror("disown");
|
||||
}
|
||||
};
|
||||
auto& button = m_quick_launch_bar->add<GUI::Button>();
|
||||
set_quick_launch_button_data(button, name, af);
|
||||
}
|
||||
quick_launch_bar.set_fixed_height(24);
|
||||
m_quick_launch_bar->set_fixed_height(24);
|
||||
}
|
||||
|
||||
void TaskbarWindow::set_quick_launch_button_data(GUI::Button& button, String const& button_name, NonnullRefPtr<Desktop::AppFile> app_file)
|
||||
{
|
||||
auto app_executable = app_file->executable();
|
||||
auto app_run_in_terminal = app_file->run_in_terminal();
|
||||
button.set_fixed_size(quick_launch_button_size, quick_launch_button_size);
|
||||
button.set_button_style(Gfx::ButtonStyle::Coolbar);
|
||||
button.set_icon(app_file->icon().bitmap_for_size(16));
|
||||
button.set_tooltip(app_file->name());
|
||||
button.set_name(button_name);
|
||||
button.on_click = [app_executable, app_run_in_terminal](auto) {
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
perror("fork");
|
||||
} else if (pid == 0) {
|
||||
if (chdir(Core::StandardPaths::home_directory().characters()) < 0) {
|
||||
perror("chdir");
|
||||
exit(1);
|
||||
}
|
||||
if (app_run_in_terminal)
|
||||
execl("/bin/Terminal", "Terminal", "-e", app_executable.characters(), nullptr);
|
||||
else
|
||||
execl(app_executable.characters(), app_executable.characters(), nullptr);
|
||||
perror("execl");
|
||||
VERIFY_NOT_REACHED();
|
||||
} else {
|
||||
if (disown(pid) < 0)
|
||||
perror("disown");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void TaskbarWindow::on_screen_rects_change(const Vector<Gfx::IntRect, 4>& rects, size_t main_screen_index)
|
||||
|
|
|
@ -7,11 +7,15 @@
|
|||
#pragma once
|
||||
|
||||
#include "WindowList.h"
|
||||
#include <LibConfig/Listener.h>
|
||||
#include <LibDesktop/AppFile.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <LibGfx/ShareableBitmap.h>
|
||||
#include <WindowServer/ScreenLayout.h>
|
||||
|
||||
class TaskbarWindow final : public GUI::Window {
|
||||
class TaskbarWindow final : public GUI::Window
|
||||
, public Config::Listener {
|
||||
C_OBJECT(TaskbarWindow);
|
||||
|
||||
public:
|
||||
|
@ -20,10 +24,14 @@ public:
|
|||
static int taskbar_height() { return 27; }
|
||||
static int taskbar_icon_size() { return 16; }
|
||||
|
||||
virtual void config_key_was_removed(String const&, String const&, String const&) override;
|
||||
virtual void config_string_did_change(String const&, String const&, String const&, String const&) override;
|
||||
|
||||
private:
|
||||
explicit TaskbarWindow(NonnullRefPtr<GUI::Menu> start_menu);
|
||||
static void show_desktop_button_clicked(unsigned);
|
||||
void create_quick_launch_bar();
|
||||
void set_quick_launch_button_data(GUI::Button&, String const&, NonnullRefPtr<Desktop::AppFile>);
|
||||
void on_screen_rects_change(const Vector<Gfx::IntRect, 4>&, size_t);
|
||||
NonnullRefPtr<GUI::Button> create_button(const WindowIdentifier&);
|
||||
void add_window_button(::Window&, const WindowIdentifier&);
|
||||
|
@ -45,6 +53,7 @@ private:
|
|||
NonnullRefPtr<GUI::Menu> m_start_menu;
|
||||
RefPtr<GUI::Widget> m_task_button_container;
|
||||
RefPtr<Gfx::Bitmap> m_default_icon;
|
||||
RefPtr<GUI::Frame> m_quick_launch_bar;
|
||||
|
||||
Gfx::IntSize m_applet_area_size;
|
||||
RefPtr<GUI::Frame> m_applet_area_container;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/Debug.h>
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/QuickSort.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibCore/ConfigFile.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
|
@ -37,8 +38,9 @@ int main(int argc, char** argv)
|
|||
perror("pledge");
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto app = GUI::Application::construct(argc, argv);
|
||||
Config::pledge_domains("Taskbar");
|
||||
Config::monitor_domain("Taskbar");
|
||||
app->event_loop().register_signal(SIGCHLD, [](int) {
|
||||
// Wait all available children
|
||||
while (waitpid(-1, nullptr, WNOHANG) > 0)
|
||||
|
|
Loading…
Reference in a new issue