mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +00:00
WindowServer+LibGUI+Taskbar: Store window progress as Optional<int>
We were previously using the magical constant -1 to signify that a window had no progress state. Be more explicit an use an Optional. :^)
This commit is contained in:
parent
8af7cda17a
commit
cc6db526a6
9 changed files with 20 additions and 21 deletions
|
@ -126,7 +126,7 @@ public:
|
||||||
|
|
||||||
class WMWindowStateChangedEvent : public WMEvent {
|
class WMWindowStateChangedEvent : public WMEvent {
|
||||||
public:
|
public:
|
||||||
WMWindowStateChangedEvent(int client_id, int window_id, int parent_client_id, int parent_window_id, const StringView& title, const Gfx::IntRect& rect, bool is_active, bool is_modal, WindowType window_type, bool is_minimized, bool is_frameless, int progress)
|
WMWindowStateChangedEvent(int client_id, int window_id, int parent_client_id, int parent_window_id, const StringView& title, const Gfx::IntRect& rect, bool is_active, bool is_modal, WindowType window_type, bool is_minimized, bool is_frameless, Optional<int> progress)
|
||||||
: WMEvent(Event::Type::WM_WindowStateChanged, client_id, window_id)
|
: WMEvent(Event::Type::WM_WindowStateChanged, client_id, window_id)
|
||||||
, m_parent_client_id(parent_client_id)
|
, m_parent_client_id(parent_client_id)
|
||||||
, m_parent_window_id(parent_window_id)
|
, m_parent_window_id(parent_window_id)
|
||||||
|
@ -150,7 +150,7 @@ public:
|
||||||
WindowType window_type() const { return m_window_type; }
|
WindowType window_type() const { return m_window_type; }
|
||||||
bool is_minimized() const { return m_minimized; }
|
bool is_minimized() const { return m_minimized; }
|
||||||
bool is_frameless() const { return m_frameless; }
|
bool is_frameless() const { return m_frameless; }
|
||||||
int progress() const { return m_progress; }
|
Optional<int> progress() const { return m_progress; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_parent_client_id;
|
int m_parent_client_id;
|
||||||
|
@ -162,7 +162,7 @@ private:
|
||||||
bool m_modal;
|
bool m_modal;
|
||||||
bool m_minimized;
|
bool m_minimized;
|
||||||
bool m_frameless;
|
bool m_frameless;
|
||||||
int m_progress;
|
Optional<int> m_progress;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WMWindowRectChangedEvent : public WMEvent {
|
class WMWindowRectChangedEvent : public WMEvent {
|
||||||
|
|
|
@ -1021,7 +1021,7 @@ void Window::did_remove_widget(Badge<Widget>, Widget& widget)
|
||||||
m_automatic_cursor_tracking_widget = nullptr;
|
m_automatic_cursor_tracking_widget = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::set_progress(int progress)
|
void Window::set_progress(Optional<int> progress)
|
||||||
{
|
{
|
||||||
VERIFY(m_window_id);
|
VERIFY(m_window_id);
|
||||||
WindowServerConnection::the().post_message(Messages::WindowServer::SetWindowProgress(m_window_id, progress));
|
WindowServerConnection::the().post_message(Messages::WindowServer::SetWindowProgress(m_window_id, progress));
|
||||||
|
|
|
@ -190,7 +190,7 @@ public:
|
||||||
|
|
||||||
Window* find_parent_window();
|
Window* find_parent_window();
|
||||||
|
|
||||||
void set_progress(int);
|
void set_progress(Optional<int>);
|
||||||
|
|
||||||
void update_cursor(Badge<Widget>) { update_cursor(); }
|
void update_cursor(Badge<Widget>) { update_cursor(); }
|
||||||
|
|
||||||
|
|
|
@ -103,8 +103,6 @@ void TaskbarButton::paint_event(GUI::PaintEvent& event)
|
||||||
if (text().is_empty())
|
if (text().is_empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool has_progress = window.progress() >= 0 && window.progress() <= 100;
|
|
||||||
|
|
||||||
auto content_rect = rect().shrunken(8, 2);
|
auto content_rect = rect().shrunken(8, 2);
|
||||||
auto icon_location = content_rect.center().translated(-(icon.width() / 2), -(icon.height() / 2));
|
auto icon_location = content_rect.center().translated(-(icon.width() / 2), -(icon.height() / 2));
|
||||||
if (!text().is_empty())
|
if (!text().is_empty())
|
||||||
|
@ -125,12 +123,12 @@ void TaskbarButton::paint_event(GUI::PaintEvent& event)
|
||||||
icon_location.move_by(1, 1);
|
icon_location.move_by(1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_progress) {
|
if (window.progress().has_value()) {
|
||||||
auto adjusted_rect = rect().shrunken(4, 4);
|
auto adjusted_rect = rect().shrunken(4, 4);
|
||||||
if (is_being_pressed() || is_checked()) {
|
if (is_being_pressed() || is_checked()) {
|
||||||
adjusted_rect.set_height(adjusted_rect.height() + 1);
|
adjusted_rect.set_height(adjusted_rect.height() + 1);
|
||||||
}
|
}
|
||||||
paint_custom_progressbar(painter, adjusted_rect, text_rect, palette(), 0, 100, window.progress(), text(), font, text_alignment());
|
paint_custom_progressbar(painter, adjusted_rect, text_rect, palette(), 0, 100, window.progress().value(), text(), font, text_alignment());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_enabled()) {
|
if (is_enabled()) {
|
||||||
|
@ -142,6 +140,6 @@ void TaskbarButton::paint_event(GUI::PaintEvent& event)
|
||||||
painter.blit_disabled(icon_location, icon, icon.rect(), palette());
|
painter.blit_disabled(icon_location, icon, icon.rect(), palette());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!has_progress)
|
if (!window.progress().has_value())
|
||||||
paint_text(painter, text_rect, font, text_alignment());
|
paint_text(painter, text_rect, font, text_alignment());
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ public:
|
||||||
void set_modal(bool modal) { m_modal = modal; }
|
void set_modal(bool modal) { m_modal = modal; }
|
||||||
bool is_modal() const { return m_modal; }
|
bool is_modal() const { return m_modal; }
|
||||||
|
|
||||||
void set_progress(int progress)
|
void set_progress(Optional<int> progress)
|
||||||
{
|
{
|
||||||
if (m_progress == progress)
|
if (m_progress == progress)
|
||||||
return;
|
return;
|
||||||
|
@ -57,7 +57,7 @@ public:
|
||||||
m_button->update();
|
m_button->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
int progress() const { return m_progress; }
|
Optional<int> progress() const { return m_progress; }
|
||||||
|
|
||||||
const Gfx::Bitmap* icon() const { return m_icon.ptr(); }
|
const Gfx::Bitmap* icon() const { return m_icon.ptr(); }
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ private:
|
||||||
bool m_active { false };
|
bool m_active { false };
|
||||||
bool m_minimized { false };
|
bool m_minimized { false };
|
||||||
bool m_modal { false };
|
bool m_modal { false };
|
||||||
int m_progress { -1 };
|
Optional<int> m_progress;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WindowList {
|
class WindowList {
|
||||||
|
|
|
@ -918,7 +918,7 @@ bool Window::is_modal() const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::set_progress(int progress)
|
void Window::set_progress(Optional<int> progress)
|
||||||
{
|
{
|
||||||
if (m_progress == progress)
|
if (m_progress == progress)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -72,8 +72,6 @@ class Window final : public Core::Object
|
||||||
, public InlineLinkedListNode<Window> {
|
, public InlineLinkedListNode<Window> {
|
||||||
C_OBJECT(Window)
|
C_OBJECT(Window)
|
||||||
public:
|
public:
|
||||||
Window(ClientConnection&, WindowType, int window_id, bool modal, bool minimizable, bool frameless, bool resizable, bool fullscreen, bool accessory, Window* parent_window = nullptr);
|
|
||||||
Window(Core::Object&, WindowType);
|
|
||||||
virtual ~Window() override;
|
virtual ~Window() override;
|
||||||
|
|
||||||
bool is_modified() const { return m_modified; }
|
bool is_modified() const { return m_modified; }
|
||||||
|
@ -295,8 +293,8 @@ public:
|
||||||
|
|
||||||
bool should_show_menubar() const { return m_should_show_menubar; }
|
bool should_show_menubar() const { return m_should_show_menubar; }
|
||||||
|
|
||||||
int progress() const { return m_progress; }
|
Optional<int> progress() const { return m_progress; }
|
||||||
void set_progress(int);
|
void set_progress(Optional<int>);
|
||||||
|
|
||||||
bool is_destroyed() const { return m_destroyed; }
|
bool is_destroyed() const { return m_destroyed; }
|
||||||
void destroy();
|
void destroy();
|
||||||
|
@ -324,6 +322,9 @@ public:
|
||||||
void set_menubar(Menubar*);
|
void set_menubar(Menubar*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Window(ClientConnection&, WindowType, int window_id, bool modal, bool minimizable, bool frameless, bool resizable, bool fullscreen, bool accessory, Window* parent_window = nullptr);
|
||||||
|
Window(Core::Object&, WindowType);
|
||||||
|
|
||||||
virtual void event(Core::Event&) override;
|
virtual void event(Core::Event&) override;
|
||||||
void handle_mouse_event(const MouseEvent&);
|
void handle_mouse_event(const MouseEvent&);
|
||||||
void handle_keydown_event(const KeyEvent&);
|
void handle_keydown_event(const KeyEvent&);
|
||||||
|
@ -398,7 +399,7 @@ private:
|
||||||
MenuItem* m_window_menu_close_item { nullptr };
|
MenuItem* m_window_menu_close_item { nullptr };
|
||||||
MenuItem* m_window_menu_menubar_visibility_item { nullptr };
|
MenuItem* m_window_menu_menubar_visibility_item { nullptr };
|
||||||
int m_minimize_animation_step { -1 };
|
int m_minimize_animation_step { -1 };
|
||||||
int m_progress { -1 };
|
Optional<int> m_progress;
|
||||||
bool m_should_show_menubar { true };
|
bool m_should_show_menubar { true };
|
||||||
bool m_modified { false };
|
bool m_modified { false };
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
endpoint WindowManagerClient
|
endpoint WindowManagerClient
|
||||||
{
|
{
|
||||||
WindowRemoved(i32 wm_id, i32 client_id, i32 window_id) =|
|
WindowRemoved(i32 wm_id, i32 client_id, i32 window_id) =|
|
||||||
WindowStateChanged(i32 wm_id, i32 client_id, i32 window_id, i32 parent_client_id, i32 parent_window_id, bool is_active, bool is_minimized, bool is_modal, bool is_frameless, i32 window_type, [UTF8] String title, Gfx::IntRect rect, i32 progress) =|
|
WindowStateChanged(i32 wm_id, i32 client_id, i32 window_id, i32 parent_client_id, i32 parent_window_id, bool is_active, bool is_minimized, bool is_modal, bool is_frameless, i32 window_type, [UTF8] String title, Gfx::IntRect rect, Optional<i32> progress) =|
|
||||||
WindowIconBitmapChanged(i32 wm_id, i32 client_id, i32 window_id, Gfx::ShareableBitmap bitmap) =|
|
WindowIconBitmapChanged(i32 wm_id, i32 client_id, i32 window_id, Gfx::ShareableBitmap bitmap) =|
|
||||||
WindowRectChanged(i32 wm_id, i32 client_id, i32 window_id, Gfx::IntRect rect) =|
|
WindowRectChanged(i32 wm_id, i32 client_id, i32 window_id, Gfx::IntRect rect) =|
|
||||||
AppletAreaSizeChanged(i32 wm_id, Gfx::IntSize size) =|
|
AppletAreaSizeChanged(i32 wm_id, Gfx::IntSize size) =|
|
||||||
|
|
|
@ -54,7 +54,7 @@ endpoint WindowServer
|
||||||
SetWindowTitle(i32 window_id, [UTF8] String title) => ()
|
SetWindowTitle(i32 window_id, [UTF8] String title) => ()
|
||||||
GetWindowTitle(i32 window_id) => ([UTF8] String title)
|
GetWindowTitle(i32 window_id) => ([UTF8] String title)
|
||||||
|
|
||||||
SetWindowProgress(i32 window_id, i32 progress) =|
|
SetWindowProgress(i32 window_id, Optional<i32> progress) =|
|
||||||
|
|
||||||
SetWindowModified(i32 window_id, bool modified) =|
|
SetWindowModified(i32 window_id, bool modified) =|
|
||||||
IsWindowModified(i32 window_id) => (bool modified)
|
IsWindowModified(i32 window_id) => (bool modified)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue