mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Taskbar: Made it possible to add a system menu to taskbar later
This makes it possible to construct the taskbar before the system menu and remove the awkward reference in Taskbar/main.cpp
This commit is contained in:
parent
7456a84e68
commit
7afb7e65d5
Notes:
sideshowbarker
2024-07-17 04:03:05 +09:00
Author: https://github.com/kuzux Commit: https://github.com/SerenityOS/serenity/commit/7afb7e65d5 Pull-request: https://github.com/SerenityOS/serenity/pull/16183
3 changed files with 28 additions and 14 deletions
|
@ -52,8 +52,7 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
TaskbarWindow::TaskbarWindow(NonnullRefPtr<GUI::Menu> system_menu)
|
||||
: m_system_menu(move(system_menu))
|
||||
TaskbarWindow::TaskbarWindow()
|
||||
{
|
||||
set_window_type(GUI::WindowType::Taskbar);
|
||||
set_title("Taskbar");
|
||||
|
@ -64,15 +63,8 @@ TaskbarWindow::TaskbarWindow(NonnullRefPtr<GUI::Menu> system_menu)
|
|||
main_widget.set_layout<GUI::HorizontalBoxLayout>();
|
||||
main_widget.layout()->set_margins({ 2, 3, 0, 3 });
|
||||
|
||||
m_start_button = GUI::Button::construct("Serenity");
|
||||
set_start_button_font(Gfx::FontDatabase::default_font().bold_variant());
|
||||
m_start_button->set_icon_spacing(0);
|
||||
auto app_icon = GUI::Icon::default_icon("ladyball"sv);
|
||||
m_start_button->set_icon(app_icon.bitmap_for_size(16));
|
||||
m_start_button->set_menu(m_system_menu);
|
||||
|
||||
main_widget.add_child(*m_start_button);
|
||||
main_widget.add<Taskbar::QuickLaunchWidget>();
|
||||
m_quick_launch = Taskbar::QuickLaunchWidget::construct();
|
||||
main_widget.add_child(*m_quick_launch);
|
||||
|
||||
m_task_button_container = main_widget.add<GUI::Widget>();
|
||||
m_task_button_container->set_layout<GUI::HorizontalBoxLayout>();
|
||||
|
@ -99,6 +91,21 @@ TaskbarWindow::TaskbarWindow(NonnullRefPtr<GUI::Menu> system_menu)
|
|||
m_assistant_app_file = Desktop::AppFile::open(af_path);
|
||||
}
|
||||
|
||||
void TaskbarWindow::add_system_menu(NonnullRefPtr<GUI::Menu> system_menu)
|
||||
{
|
||||
m_system_menu = move(system_menu);
|
||||
|
||||
m_start_button = GUI::Button::construct("Serenity");
|
||||
set_start_button_font(Gfx::FontDatabase::default_font().bold_variant());
|
||||
m_start_button->set_icon_spacing(0);
|
||||
auto app_icon = GUI::Icon::default_icon("ladyball"sv);
|
||||
m_start_button->set_icon(app_icon.bitmap_for_size(16));
|
||||
m_start_button->set_menu(m_system_menu);
|
||||
|
||||
GUI::Widget* main = main_widget();
|
||||
main->insert_child_before(*m_start_button, *m_quick_launch);
|
||||
}
|
||||
|
||||
void TaskbarWindow::config_string_did_change(String const& domain, String const& group, String const& key, String const& value)
|
||||
{
|
||||
if (domain == "Taskbar" && group == "Clock" && key == "TimeFormat") {
|
||||
|
@ -296,6 +303,9 @@ void TaskbarWindow::wm_event(GUI::WMEvent& event)
|
|||
break;
|
||||
}
|
||||
case GUI::Event::WM_SuperKeyPressed: {
|
||||
if (!m_system_menu)
|
||||
break;
|
||||
|
||||
if (m_system_menu->is_visible()) {
|
||||
m_system_menu->dismiss();
|
||||
} else {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "ClockWidget.h"
|
||||
#include "Taskbar/QuickLaunchWidget.h"
|
||||
#include "WindowList.h"
|
||||
#include <LibConfig/Listener.h>
|
||||
#include <LibDesktop/AppFile.h>
|
||||
|
@ -26,9 +27,10 @@ public:
|
|||
static int taskbar_icon_size() { return 16; }
|
||||
|
||||
virtual void config_string_did_change(String const&, String const&, String const&, String const&) override;
|
||||
virtual void add_system_menu(NonnullRefPtr<GUI::Menu> system_menu);
|
||||
|
||||
private:
|
||||
explicit TaskbarWindow(NonnullRefPtr<GUI::Menu> system_menu);
|
||||
explicit TaskbarWindow();
|
||||
static void show_desktop_button_clicked(unsigned);
|
||||
static void toggle_show_desktop();
|
||||
void set_quick_launch_button_data(GUI::Button&, String const&, NonnullRefPtr<Desktop::AppFile>);
|
||||
|
@ -49,7 +51,7 @@ private:
|
|||
|
||||
void set_start_button_font(Gfx::Font const&);
|
||||
|
||||
NonnullRefPtr<GUI::Menu> m_system_menu;
|
||||
RefPtr<GUI::Menu> m_system_menu;
|
||||
RefPtr<GUI::Widget> m_task_button_container;
|
||||
RefPtr<Gfx::Bitmap> m_default_icon;
|
||||
|
||||
|
@ -57,6 +59,7 @@ private:
|
|||
RefPtr<GUI::Frame> m_applet_area_container;
|
||||
RefPtr<GUI::Button> m_start_button;
|
||||
RefPtr<GUI::Button> m_show_desktop_button;
|
||||
RefPtr<Taskbar::QuickLaunchWidget> m_quick_launch;
|
||||
RefPtr<Taskbar::ClockWidget> m_clock_widget;
|
||||
|
||||
RefPtr<Desktop::AppFile> m_assistant_app_file;
|
||||
|
|
|
@ -70,7 +70,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto menu = TRY(build_system_menu(window_ref));
|
||||
menu->realize_menu_if_needed();
|
||||
|
||||
auto window = TRY(TaskbarWindow::try_create(move(menu)));
|
||||
auto window = TRY(TaskbarWindow::try_create());
|
||||
window->add_system_menu(menu);
|
||||
window_ref.window = window.ptr();
|
||||
|
||||
window->show();
|
||||
|
|
Loading…
Reference in a new issue