mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
WindowServer+LibGUI: Implement minimizable property to windows
This commit is contained in:
parent
a641f4d213
commit
eab34a7de3
8 changed files with 46 additions and 8 deletions
|
@ -61,6 +61,7 @@ void GWindow::show()
|
|||
m_rect_when_windowless,
|
||||
m_has_alpha_channel,
|
||||
m_modal,
|
||||
m_minimizable,
|
||||
m_resizable,
|
||||
m_fullscreen,
|
||||
m_show_titlebar,
|
||||
|
@ -549,6 +550,7 @@ void GWindow::save_to(AK::JsonObject& json)
|
|||
json.set("title", title());
|
||||
json.set("visible", is_visible());
|
||||
json.set("active", is_active());
|
||||
json.set("minimizable", is_minimizable());
|
||||
json.set("resizable", is_resizable());
|
||||
json.set("fullscreen", is_fullscreen());
|
||||
json.set("rect", rect().to_string());
|
||||
|
|
|
@ -40,6 +40,9 @@ public:
|
|||
bool is_resizable() const { return m_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_has_alpha_channel(bool);
|
||||
void set_opacity(float);
|
||||
|
@ -175,6 +178,7 @@ private:
|
|||
bool m_double_buffering_enabled { true };
|
||||
bool m_modal { false };
|
||||
bool m_resizable { true };
|
||||
bool m_minimizable { true };
|
||||
bool m_fullscreen { false };
|
||||
bool m_show_titlebar { true };
|
||||
bool m_layout_pending { false };
|
||||
|
|
|
@ -394,7 +394,7 @@ OwnPtr<WindowServer::GetClipboardContentsResponse> WSClientConnection::handle(co
|
|||
OwnPtr<WindowServer::CreateWindowResponse> WSClientConnection::handle(const WindowServer::CreateWindow& message)
|
||||
{
|
||||
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_title(message.title());
|
||||
if (!message.fullscreen())
|
||||
|
|
|
@ -28,11 +28,12 @@ WSWindow::WSWindow(CObject& parent, WSWindowType type)
|
|||
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)
|
||||
, m_client(&client)
|
||||
, m_type(window_type)
|
||||
, m_modal(modal)
|
||||
, m_minimizable(minimizable)
|
||||
, m_resizable(resizable)
|
||||
, m_fullscreen(fullscreen)
|
||||
, m_window_id(window_id)
|
||||
|
@ -102,6 +103,8 @@ void WSWindow::set_minimized(bool minimized)
|
|||
{
|
||||
if (m_minimized == minimized)
|
||||
return;
|
||||
if (minimized && !m_minimizable)
|
||||
return;
|
||||
m_minimized = minimized;
|
||||
start_minimize_animation();
|
||||
if (!minimized)
|
||||
|
@ -110,6 +113,14 @@ void WSWindow::set_minimized(bool minimized)
|
|||
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)
|
||||
{
|
||||
if (m_opacity == opacity)
|
||||
|
@ -130,6 +141,8 @@ void WSWindow::set_maximized(bool maximized)
|
|||
{
|
||||
if (m_maximized == maximized)
|
||||
return;
|
||||
if (maximized && !is_resizable())
|
||||
return;
|
||||
m_maximized = maximized;
|
||||
auto old_rect = m_rect;
|
||||
if (maximized) {
|
||||
|
@ -142,6 +155,14 @@ void WSWindow::set_maximized(bool maximized)
|
|||
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)
|
||||
{
|
||||
if (!m_client) {
|
||||
|
|
|
@ -31,7 +31,7 @@ class WSWindow final : public CObject
|
|||
, public InlineLinkedListNode<WSWindow> {
|
||||
C_OBJECT(WSWindow)
|
||||
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);
|
||||
virtual ~WSWindow() override;
|
||||
|
||||
|
@ -44,6 +44,12 @@ public:
|
|||
bool is_minimized() const { return m_minimized; }
|
||||
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; }
|
||||
void set_maximized(bool);
|
||||
|
||||
|
@ -95,8 +101,6 @@ public:
|
|||
|
||||
bool is_modal() const { return m_modal; }
|
||||
|
||||
bool is_resizable() const { return m_resizable && !m_fullscreen; }
|
||||
|
||||
Rect rect() const { return m_rect; }
|
||||
void set_rect(const Rect&);
|
||||
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_has_alpha_channel { false };
|
||||
bool m_modal { false };
|
||||
bool m_minimizable { false };
|
||||
bool m_resizable { false };
|
||||
bool m_listens_to_wm_events { false };
|
||||
bool m_minimized { false };
|
||||
|
|
|
@ -102,9 +102,13 @@ WSWindowFrame::WSWindowFrame(WSWindow& window)
|
|||
m_buttons.append(move(button));
|
||||
}
|
||||
|
||||
m_buttons.append(make<WSButton>(*this, *s_minimize_button_bitmap, [this](auto&) {
|
||||
m_window.set_minimized(true);
|
||||
}));
|
||||
if (window.is_minimizable()) {
|
||||
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()
|
||||
|
|
|
@ -30,4 +30,5 @@ private:
|
|||
WSWindow& m_window;
|
||||
NonnullOwnPtrVector<WSButton> m_buttons;
|
||||
WSButton* m_maximize_button { nullptr };
|
||||
WSButton* m_minimize_button { nullptr };
|
||||
};
|
||||
|
|
|
@ -20,6 +20,7 @@ endpoint WindowServer = 2
|
|||
Rect rect,
|
||||
bool has_alpha_channel,
|
||||
bool modal,
|
||||
bool minimizable,
|
||||
bool resizable,
|
||||
bool fullscreen,
|
||||
bool show_titlebar,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue