1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 20:27:35 +00:00

GWindow: Allow clients to prevent close requests from closing

This is done by hooking the new on_close_request callback and returning
GWindow::CloseRequestDecision::StayOpen (instead of ...::Close.)
This commit is contained in:
Andreas Kling 2019-08-27 20:35:37 +02:00
parent ecbedda34c
commit c4b1456c88
2 changed files with 12 additions and 1 deletions

View file

@ -322,6 +322,10 @@ void GWindow::event(CEvent& event)
}
if (event.type() == GEvent::WindowCloseRequest) {
if (on_close_request) {
if (on_close_request() == GWindow::CloseRequestDecision::StayOpen)
return;
}
close();
return;
}

View file

@ -4,9 +4,9 @@
#include <AK/HashMap.h>
#include <AK/WeakPtr.h>
#include <LibCore/CObject.h>
#include <LibGUI/GWindowType.h>
#include <LibDraw/GraphicsBitmap.h>
#include <LibDraw/Rect.h>
#include <LibGUI/GWindowType.h>
class GWidget;
class GWMEvent;
@ -57,6 +57,13 @@ public:
bool should_destroy_on_close() { return m_destroy_on_close; }
void set_should_destroy_on_close(bool b) { m_destroy_on_close = b; }
enum class CloseRequestDecision {
StayOpen,
Close,
};
Function<CloseRequestDecision()> on_close_request;
int x() const { return rect().x(); }
int y() const { return rect().y(); }
int width() const { return rect().width(); }