mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
LibGUI+WindowServer: Add option to hide a widow's close button
This allows windows to be closed only programatically, and not from e.g. the user clicking the X button on the window frame.
This commit is contained in:
parent
8a57885494
commit
176155c695
8 changed files with 29 additions and 7 deletions
|
@ -142,6 +142,7 @@ void Window::show()
|
|||
m_has_alpha_channel,
|
||||
m_modal,
|
||||
m_minimizable,
|
||||
m_closeable,
|
||||
m_resizable,
|
||||
m_fullscreen,
|
||||
m_frameless,
|
||||
|
|
|
@ -53,6 +53,9 @@ public:
|
|||
bool is_minimizable() const { return m_minimizable; }
|
||||
void set_minimizable(bool minimizable) { m_minimizable = minimizable; }
|
||||
|
||||
bool is_closeable() const { return m_closeable; }
|
||||
void set_closeable(bool closeable) { m_closeable = closeable; }
|
||||
|
||||
void set_double_buffering_enabled(bool);
|
||||
void set_has_alpha_channel(bool);
|
||||
bool has_alpha_channel() const { return m_has_alpha_channel; }
|
||||
|
@ -269,6 +272,7 @@ private:
|
|||
bool m_resizable { true };
|
||||
Optional<Gfx::IntSize> m_resize_aspect_ratio {};
|
||||
bool m_minimizable { true };
|
||||
bool m_closeable { true };
|
||||
bool m_maximized_when_windowless { false };
|
||||
bool m_fullscreen { false };
|
||||
bool m_frameless { false };
|
||||
|
|
|
@ -481,7 +481,7 @@ Window* ClientConnection::window_from_id(i32 window_id)
|
|||
}
|
||||
|
||||
void ClientConnection::create_window(i32 window_id, Gfx::IntRect const& rect,
|
||||
bool auto_position, bool has_alpha_channel, bool modal, bool minimizable, bool resizable,
|
||||
bool auto_position, bool has_alpha_channel, bool modal, bool minimizable, bool closeable, bool resizable,
|
||||
bool fullscreen, bool frameless, bool forced_shadow, bool accessory, float opacity,
|
||||
float alpha_hit_threshold, Gfx::IntSize const& base_size, Gfx::IntSize const& size_increment,
|
||||
Gfx::IntSize const& minimum_size, Optional<Gfx::IntSize> const& resize_aspect_ratio, i32 type,
|
||||
|
@ -506,7 +506,7 @@ void ClientConnection::create_window(i32 window_id, Gfx::IntRect const& rect,
|
|||
return;
|
||||
}
|
||||
|
||||
auto window = Window::construct(*this, (WindowType)type, window_id, modal, minimizable, frameless, resizable, fullscreen, accessory, parent_window);
|
||||
auto window = Window::construct(*this, (WindowType)type, window_id, modal, minimizable, closeable, frameless, resizable, fullscreen, accessory, parent_window);
|
||||
|
||||
window->set_forced_shadow(forced_shadow);
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ private:
|
|||
virtual void add_menu_item(i32, i32, i32, String const&, bool, bool, bool, bool, String const&, Gfx::ShareableBitmap const&, bool) override;
|
||||
virtual void add_menu_separator(i32) override;
|
||||
virtual void update_menu_item(i32, i32, i32, String const&, bool, bool, bool, bool, String const&) override;
|
||||
virtual void create_window(i32, Gfx::IntRect const&, bool, bool, bool, bool,
|
||||
virtual void create_window(i32, Gfx::IntRect const&, bool, bool, bool, bool, bool,
|
||||
bool, bool, bool, bool, bool, float, float, Gfx::IntSize const&, Gfx::IntSize const&, Gfx::IntSize const&,
|
||||
Optional<Gfx::IntSize> const&, i32, String const&, i32, Gfx::IntRect const&) override;
|
||||
virtual Messages::WindowServer::DestroyWindowResponse destroy_window(i32) override;
|
||||
|
|
|
@ -87,12 +87,13 @@ Window::Window(Core::Object& parent, WindowType type)
|
|||
WindowManager::the().add_window(*this);
|
||||
}
|
||||
|
||||
Window::Window(ClientConnection& client, WindowType window_type, int window_id, bool modal, bool minimizable, bool frameless, bool resizable, bool fullscreen, bool accessory, Window* parent_window)
|
||||
Window::Window(ClientConnection& client, WindowType window_type, int window_id, bool modal, bool minimizable, bool closeable, bool frameless, bool resizable, bool fullscreen, bool accessory, Window* parent_window)
|
||||
: Core::Object(&client)
|
||||
, m_client(&client)
|
||||
, m_type(window_type)
|
||||
, m_modal(modal)
|
||||
, m_minimizable(minimizable)
|
||||
, m_closeable(closeable)
|
||||
, m_frameless(frameless)
|
||||
, m_resizable(resizable)
|
||||
, m_fullscreen(fullscreen)
|
||||
|
@ -282,6 +283,8 @@ void Window::update_window_menu_items()
|
|||
m_window_menu_maximize_item->set_text(m_maximized ? "&Restore" : "Ma&ximize");
|
||||
m_window_menu_maximize_item->set_enabled(m_resizable);
|
||||
|
||||
m_window_menu_close_item->set_enabled(m_closeable);
|
||||
|
||||
m_window_menu_move_item->set_enabled(m_minimized_state == WindowMinimizedState::None && !m_maximized && !m_fullscreen);
|
||||
|
||||
if (m_window_menu_pin_item)
|
||||
|
@ -335,6 +338,14 @@ void Window::set_minimizable(bool minimizable)
|
|||
// TODO: Hide/show (or alternatively change enabled state of) window minimize button dynamically depending on value of m_minimizable
|
||||
}
|
||||
|
||||
void Window::set_closeable(bool closeable)
|
||||
{
|
||||
if (m_closeable == closeable)
|
||||
return;
|
||||
m_closeable = closeable;
|
||||
update_window_menu_items();
|
||||
}
|
||||
|
||||
void Window::set_taskbar_rect(const Gfx::IntRect& rect)
|
||||
{
|
||||
m_taskbar_rect = rect;
|
||||
|
|
|
@ -98,6 +98,9 @@ public:
|
|||
bool is_minimizable() const { return m_type == WindowType::Normal && m_minimizable; }
|
||||
void set_minimizable(bool);
|
||||
|
||||
bool is_closeable() const { return m_closeable; }
|
||||
void set_closeable(bool);
|
||||
|
||||
bool is_resizable() const { return m_resizable && !m_fullscreen; }
|
||||
void set_resizable(bool);
|
||||
|
||||
|
@ -378,7 +381,7 @@ public:
|
|||
bool is_stealable_by_client(i32 client_id) const { return m_stealable_by_client_ids.contains_slow(client_id); }
|
||||
|
||||
private:
|
||||
Window(ClientConnection&, WindowType, int window_id, bool modal, bool minimizable, bool frameless, bool resizable, bool fullscreen, bool accessory, Window* parent_window = nullptr);
|
||||
Window(ClientConnection&, WindowType, int window_id, bool modal, bool minimizable, bool closeable, bool frameless, bool resizable, bool fullscreen, bool accessory, Window* parent_window = nullptr);
|
||||
Window(Core::Object&, WindowType);
|
||||
|
||||
virtual void event(Core::Event&) override;
|
||||
|
@ -414,6 +417,7 @@ private:
|
|||
bool m_has_alpha_channel { false };
|
||||
bool m_modal { false };
|
||||
bool m_minimizable { false };
|
||||
bool m_closeable { false };
|
||||
bool m_frameless { false };
|
||||
bool m_forced_shadow { false };
|
||||
bool m_resizable { false };
|
||||
|
|
|
@ -71,7 +71,7 @@ WindowFrame::WindowFrame(Window& window)
|
|||
|
||||
void WindowFrame::window_was_constructed(Badge<Window>)
|
||||
{
|
||||
{
|
||||
if (m_window.is_closeable()) {
|
||||
auto button = make<Button>(*this, [this](auto&) {
|
||||
m_window.handle_window_menu_action(WindowMenuAction::Close);
|
||||
});
|
||||
|
@ -113,7 +113,8 @@ void WindowFrame::set_button_icons()
|
|||
if (m_window.is_frameless())
|
||||
return;
|
||||
|
||||
m_close_button->set_icon(m_window.is_modified() ? *s_close_modified_icon : *s_close_icon);
|
||||
if (m_window.is_closeable())
|
||||
m_close_button->set_icon(m_window.is_modified() ? *s_close_modified_icon : *s_close_icon);
|
||||
if (m_window.is_minimizable())
|
||||
m_minimize_button->set_icon(s_minimize_icon);
|
||||
if (m_window.is_resizable())
|
||||
|
|
|
@ -32,6 +32,7 @@ endpoint WindowServer
|
|||
bool has_alpha_channel,
|
||||
bool modal,
|
||||
bool minimizable,
|
||||
bool closeable,
|
||||
bool resizable,
|
||||
bool fullscreen,
|
||||
bool frameless,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue