1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00

WindowServer+LibGUI: Implement minimizable property to windows

This commit is contained in:
Jami Kettunen 2020-01-04 13:12:02 +02:00 committed by Andreas Kling
parent a641f4d213
commit eab34a7de3
8 changed files with 46 additions and 8 deletions

View file

@ -61,6 +61,7 @@ void GWindow::show()
m_rect_when_windowless, m_rect_when_windowless,
m_has_alpha_channel, m_has_alpha_channel,
m_modal, m_modal,
m_minimizable,
m_resizable, m_resizable,
m_fullscreen, m_fullscreen,
m_show_titlebar, m_show_titlebar,
@ -549,6 +550,7 @@ void GWindow::save_to(AK::JsonObject& json)
json.set("title", title()); json.set("title", title());
json.set("visible", is_visible()); json.set("visible", is_visible());
json.set("active", is_active()); json.set("active", is_active());
json.set("minimizable", is_minimizable());
json.set("resizable", is_resizable()); json.set("resizable", is_resizable());
json.set("fullscreen", is_fullscreen()); json.set("fullscreen", is_fullscreen());
json.set("rect", rect().to_string()); json.set("rect", rect().to_string());

View file

@ -40,6 +40,9 @@ public:
bool is_resizable() const { return m_resizable; } bool is_resizable() const { return m_resizable; }
void set_resizable(bool resizable) { m_resizable = resizable; } void set_resizable(bool resizable) { m_resizable = resizable; }
bool is_minimizable() const { return m_minimizable; }
void set_minimizable(bool minimizable) { m_minimizable = minimizable; }
void set_double_buffering_enabled(bool); void set_double_buffering_enabled(bool);
void set_has_alpha_channel(bool); void set_has_alpha_channel(bool);
void set_opacity(float); void set_opacity(float);
@ -175,6 +178,7 @@ private:
bool m_double_buffering_enabled { true }; bool m_double_buffering_enabled { true };
bool m_modal { false }; bool m_modal { false };
bool m_resizable { true }; bool m_resizable { true };
bool m_minimizable { true };
bool m_fullscreen { false }; bool m_fullscreen { false };
bool m_show_titlebar { true }; bool m_show_titlebar { true };
bool m_layout_pending { false }; bool m_layout_pending { false };

View file

@ -394,7 +394,7 @@ OwnPtr<WindowServer::GetClipboardContentsResponse> WSClientConnection::handle(co
OwnPtr<WindowServer::CreateWindowResponse> WSClientConnection::handle(const WindowServer::CreateWindow& message) OwnPtr<WindowServer::CreateWindowResponse> WSClientConnection::handle(const WindowServer::CreateWindow& message)
{ {
int window_id = m_next_window_id++; int window_id = m_next_window_id++;
auto window = WSWindow::construct(*this, (WSWindowType)message.type(), window_id, message.modal(), message.resizable(), message.fullscreen()); auto window = WSWindow::construct(*this, (WSWindowType)message.type(), window_id, message.modal(), message.minimizable(), message.resizable(), message.fullscreen());
window->set_has_alpha_channel(message.has_alpha_channel()); window->set_has_alpha_channel(message.has_alpha_channel());
window->set_title(message.title()); window->set_title(message.title());
if (!message.fullscreen()) if (!message.fullscreen())

View file

@ -28,11 +28,12 @@ WSWindow::WSWindow(CObject& parent, WSWindowType type)
WSWindowManager::the().add_window(*this); WSWindowManager::the().add_window(*this);
} }
WSWindow::WSWindow(WSClientConnection& client, WSWindowType window_type, int window_id, bool modal, bool resizable, bool fullscreen) WSWindow::WSWindow(WSClientConnection& client, WSWindowType window_type, int window_id, bool modal, bool minimizable, bool resizable, bool fullscreen)
: CObject(&client) : CObject(&client)
, m_client(&client) , m_client(&client)
, m_type(window_type) , m_type(window_type)
, m_modal(modal) , m_modal(modal)
, m_minimizable(minimizable)
, m_resizable(resizable) , m_resizable(resizable)
, m_fullscreen(fullscreen) , m_fullscreen(fullscreen)
, m_window_id(window_id) , m_window_id(window_id)
@ -102,6 +103,8 @@ void WSWindow::set_minimized(bool minimized)
{ {
if (m_minimized == minimized) if (m_minimized == minimized)
return; return;
if (minimized && !m_minimizable)
return;
m_minimized = minimized; m_minimized = minimized;
start_minimize_animation(); start_minimize_animation();
if (!minimized) if (!minimized)
@ -110,6 +113,14 @@ void WSWindow::set_minimized(bool minimized)
WSWindowManager::the().notify_minimization_state_changed(*this); WSWindowManager::the().notify_minimization_state_changed(*this);
} }
void WSWindow::set_minimizable(bool minimizable)
{
if (m_minimizable == minimizable)
return;
m_minimizable = minimizable;
// TODO: Hide/show (or alternatively change enabled state of) window minimize button dynamically depending on value of m_minimizable
}
void WSWindow::set_opacity(float opacity) void WSWindow::set_opacity(float opacity)
{ {
if (m_opacity == opacity) if (m_opacity == opacity)
@ -130,6 +141,8 @@ void WSWindow::set_maximized(bool maximized)
{ {
if (m_maximized == maximized) if (m_maximized == maximized)
return; return;
if (maximized && !is_resizable())
return;
m_maximized = maximized; m_maximized = maximized;
auto old_rect = m_rect; auto old_rect = m_rect;
if (maximized) { if (maximized) {
@ -142,6 +155,14 @@ void WSWindow::set_maximized(bool maximized)
CEventLoop::current().post_event(*this, make<WSResizeEvent>(old_rect, m_rect)); CEventLoop::current().post_event(*this, make<WSResizeEvent>(old_rect, m_rect));
} }
void WSWindow::set_resizable(bool resizable)
{
if (m_resizable == resizable)
return;
m_resizable = resizable;
// TODO: Hide/show (or alternatively change enabled state of) window maximize button dynamically depending on value of is_resizable()
}
void WSWindow::event(CEvent& event) void WSWindow::event(CEvent& event)
{ {
if (!m_client) { if (!m_client) {

View file

@ -31,7 +31,7 @@ class WSWindow final : public CObject
, public InlineLinkedListNode<WSWindow> { , public InlineLinkedListNode<WSWindow> {
C_OBJECT(WSWindow) C_OBJECT(WSWindow)
public: public:
WSWindow(WSClientConnection&, WSWindowType, int window_id, bool modal, bool resizable, bool fullscreen); WSWindow(WSClientConnection&, WSWindowType, int window_id, bool modal, bool minimizable, bool resizable, bool fullscreen);
WSWindow(CObject&, WSWindowType); WSWindow(CObject&, WSWindowType);
virtual ~WSWindow() override; virtual ~WSWindow() override;
@ -44,6 +44,12 @@ public:
bool is_minimized() const { return m_minimized; } bool is_minimized() const { return m_minimized; }
void set_minimized(bool); void set_minimized(bool);
bool is_minimizable() const { return m_minimizable; }
void set_minimizable(bool);
bool is_resizable() const { return m_resizable && !m_fullscreen; }
void set_resizable(bool);
bool is_maximized() const { return m_maximized; } bool is_maximized() const { return m_maximized; }
void set_maximized(bool); void set_maximized(bool);
@ -95,8 +101,6 @@ public:
bool is_modal() const { return m_modal; } bool is_modal() const { return m_modal; }
bool is_resizable() const { return m_resizable && !m_fullscreen; }
Rect rect() const { return m_rect; } Rect rect() const { return m_rect; }
void set_rect(const Rect&); void set_rect(const Rect&);
void set_rect(int x, int y, int width, int height) { set_rect({ x, y, width, height }); } void set_rect(int x, int y, int width, int height) { set_rect({ x, y, width, height }); }
@ -198,6 +202,7 @@ private:
bool m_visible { true }; bool m_visible { true };
bool m_has_alpha_channel { false }; bool m_has_alpha_channel { false };
bool m_modal { false }; bool m_modal { false };
bool m_minimizable { false };
bool m_resizable { false }; bool m_resizable { false };
bool m_listens_to_wm_events { false }; bool m_listens_to_wm_events { false };
bool m_minimized { false }; bool m_minimized { false };

View file

@ -102,9 +102,13 @@ WSWindowFrame::WSWindowFrame(WSWindow& window)
m_buttons.append(move(button)); m_buttons.append(move(button));
} }
m_buttons.append(make<WSButton>(*this, *s_minimize_button_bitmap, [this](auto&) { if (window.is_minimizable()) {
m_window.set_minimized(true); auto button = make<WSButton>(*this, *s_minimize_button_bitmap, [this](auto&) {
})); m_window.set_minimized(true);
});
m_minimize_button = button.ptr();
m_buttons.append(move(button));
}
} }
WSWindowFrame::~WSWindowFrame() WSWindowFrame::~WSWindowFrame()

View file

@ -30,4 +30,5 @@ private:
WSWindow& m_window; WSWindow& m_window;
NonnullOwnPtrVector<WSButton> m_buttons; NonnullOwnPtrVector<WSButton> m_buttons;
WSButton* m_maximize_button { nullptr }; WSButton* m_maximize_button { nullptr };
WSButton* m_minimize_button { nullptr };
}; };

View file

@ -20,6 +20,7 @@ endpoint WindowServer = 2
Rect rect, Rect rect,
bool has_alpha_channel, bool has_alpha_channel,
bool modal, bool modal,
bool minimizable,
bool resizable, bool resizable,
bool fullscreen, bool fullscreen,
bool show_titlebar, bool show_titlebar,