summaryrefslogtreecommitdiff
path: root/Userland/Services
diff options
context:
space:
mode:
authorArda Cinar <kuzux92@gmail.com>2022-12-23 22:00:17 +0300
committerAndreas Kling <kling@serenityos.org>2022-12-26 09:31:44 +0100
commit1acc788500c99ed6334db513326023236f3f00fc (patch)
treed851a035d3ca23a037ad2f346421762b2305fc8f /Userland/Services
parentf40cb8d7719d9b9d16c2c692a5f1a993883fe8ee (diff)
downloadserenity-1acc788500c99ed6334db513326023236f3f00fc.zip
Taskbar: Add a factory function for TaskbarWindow
This means the errors all the way from Individual widgets get propagated up.
Diffstat (limited to 'Userland/Services')
-rw-r--r--Userland/Services/Taskbar/TaskbarWindow.cpp39
-rw-r--r--Userland/Services/Taskbar/TaskbarWindow.h5
-rw-r--r--Userland/Services/Taskbar/main.cpp2
3 files changed, 36 insertions, 10 deletions
diff --git a/Userland/Services/Taskbar/TaskbarWindow.cpp b/Userland/Services/Taskbar/TaskbarWindow.cpp
index 3730a7d49a..f22a8991ca 100644
--- a/Userland/Services/Taskbar/TaskbarWindow.cpp
+++ b/Userland/Services/Taskbar/TaskbarWindow.cpp
@@ -10,6 +10,8 @@
#include "QuickLaunchWidget.h"
#include "TaskbarButton.h"
#include <AK/Debug.h>
+#include <AK/Error.h>
+#include <AK/String.h>
#include <LibCore/StandardPaths.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
@@ -52,6 +54,13 @@ private:
}
};
+ErrorOr<NonnullRefPtr<TaskbarWindow>> TaskbarWindow::create()
+{
+ auto window = TRY(AK::adopt_nonnull_ref_or_enomem(new (nothrow) TaskbarWindow()));
+ TRY(window->populate_taskbar());
+ return window;
+}
+
TaskbarWindow::TaskbarWindow()
{
set_window_type(GUI::WindowType::Taskbar);
@@ -62,23 +71,28 @@ TaskbarWindow::TaskbarWindow()
auto& main_widget = set_main_widget<TaskbarWidget>();
main_widget.set_layout<GUI::HorizontalBoxLayout>();
main_widget.layout()->set_margins({ 2, 3, 0, 3 });
+}
- // FIXME: Propagate this error up as well
- m_quick_launch = MUST(Taskbar::QuickLaunchWidget::create());
- main_widget.add_child(*m_quick_launch);
+ErrorOr<void> TaskbarWindow::populate_taskbar()
+{
+ if (!main_widget())
+ return Error::from_string_literal("TaskbarWindow::populate_taskbar: main_widget is not set");
- m_task_button_container = main_widget.add<GUI::Widget>();
+ m_quick_launch = TRY(Taskbar::QuickLaunchWidget::create());
+ main_widget()->add_child(*m_quick_launch);
+
+ m_task_button_container = main_widget()->add<GUI::Widget>();
m_task_button_container->set_layout<GUI::HorizontalBoxLayout>();
m_task_button_container->layout()->set_spacing(3);
- m_default_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/window.png"sv).release_value_but_fixme_should_propagate_errors();
+ m_default_icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/window.png"sv));
- m_applet_area_container = main_widget.add<GUI::Frame>();
+ m_applet_area_container = main_widget()->add<GUI::Frame>();
m_applet_area_container->set_frame_thickness(1);
m_applet_area_container->set_frame_shape(Gfx::FrameShape::Box);
m_applet_area_container->set_frame_shadow(Gfx::FrameShadow::Sunken);
- m_clock_widget = main_widget.add<Taskbar::ClockWidget>();
+ m_clock_widget = main_widget()->add<Taskbar::ClockWidget>();
m_show_desktop_button = GUI::Button::construct();
m_show_desktop_button->set_tooltip("Show Desktop");
@@ -86,10 +100,17 @@ TaskbarWindow::TaskbarWindow()
m_show_desktop_button->set_button_style(Gfx::ButtonStyle::Coolbar);
m_show_desktop_button->set_fixed_size(24, 24);
m_show_desktop_button->on_click = TaskbarWindow::show_desktop_button_clicked;
- main_widget.add_child(*m_show_desktop_button);
+ main_widget()->add_child(*m_show_desktop_button);
+
+ return {};
+}
- auto af_path = DeprecatedString::formatted("{}/{}", Desktop::AppFile::APP_FILES_DIRECTORY, "Assistant.af");
+ErrorOr<void> TaskbarWindow::load_assistant()
+{
+ auto af_path = TRY(String::formatted("{}/{}", Desktop::AppFile::APP_FILES_DIRECTORY, "Assistant.af"));
m_assistant_app_file = Desktop::AppFile::open(af_path);
+
+ return {};
}
void TaskbarWindow::add_system_menu(NonnullRefPtr<GUI::Menu> system_menu)
diff --git a/Userland/Services/Taskbar/TaskbarWindow.h b/Userland/Services/Taskbar/TaskbarWindow.h
index 3b25756b97..bf36457cf4 100644
--- a/Userland/Services/Taskbar/TaskbarWindow.h
+++ b/Userland/Services/Taskbar/TaskbarWindow.h
@@ -8,6 +8,7 @@
#include "ClockWidget.h"
#include "WindowList.h"
+#include <AK/NonnullRefPtr.h>
#include <LibConfig/Listener.h>
#include <LibDesktop/AppFile.h>
#include <LibGUI/Widget.h>
@@ -21,6 +22,7 @@ class TaskbarWindow final : public GUI::Window
C_OBJECT(TaskbarWindow);
public:
+ static ErrorOr<NonnullRefPtr<TaskbarWindow>> create();
virtual ~TaskbarWindow() override = default;
static int taskbar_height() { return 27; }
@@ -40,6 +42,9 @@ private:
void remove_window_button(::Window&, bool);
void update_window_button(::Window&, bool);
+ ErrorOr<void> populate_taskbar();
+ ErrorOr<void> load_assistant();
+
virtual void event(Core::Event&) override;
virtual void wm_event(GUI::WMEvent&) override;
virtual void screen_rects_change_event(GUI::ScreenRectsChangeEvent&) override;
diff --git a/Userland/Services/Taskbar/main.cpp b/Userland/Services/Taskbar/main.cpp
index e488189b93..eb24883eb4 100644
--- a/Userland/Services/Taskbar/main.cpp
+++ b/Userland/Services/Taskbar/main.cpp
@@ -58,7 +58,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::pledge("stdio recvfd sendfd proc exec rpath"));
- auto window = TRY(TaskbarWindow::try_create());
+ auto window = TRY(TaskbarWindow::create());
auto menu = TRY(build_system_menu(*window));
menu->realize_menu_if_needed();