mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:27:44 +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:
parent
ecbedda34c
commit
c4b1456c88
2 changed files with 12 additions and 1 deletions
|
@ -322,6 +322,10 @@ void GWindow::event(CEvent& event)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.type() == GEvent::WindowCloseRequest) {
|
if (event.type() == GEvent::WindowCloseRequest) {
|
||||||
|
if (on_close_request) {
|
||||||
|
if (on_close_request() == GWindow::CloseRequestDecision::StayOpen)
|
||||||
|
return;
|
||||||
|
}
|
||||||
close();
|
close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/WeakPtr.h>
|
#include <AK/WeakPtr.h>
|
||||||
#include <LibCore/CObject.h>
|
#include <LibCore/CObject.h>
|
||||||
#include <LibGUI/GWindowType.h>
|
|
||||||
#include <LibDraw/GraphicsBitmap.h>
|
#include <LibDraw/GraphicsBitmap.h>
|
||||||
#include <LibDraw/Rect.h>
|
#include <LibDraw/Rect.h>
|
||||||
|
#include <LibGUI/GWindowType.h>
|
||||||
|
|
||||||
class GWidget;
|
class GWidget;
|
||||||
class GWMEvent;
|
class GWMEvent;
|
||||||
|
@ -57,6 +57,13 @@ public:
|
||||||
bool should_destroy_on_close() { return m_destroy_on_close; }
|
bool should_destroy_on_close() { return m_destroy_on_close; }
|
||||||
void set_should_destroy_on_close(bool b) { m_destroy_on_close = b; }
|
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 x() const { return rect().x(); }
|
||||||
int y() const { return rect().y(); }
|
int y() const { return rect().y(); }
|
||||||
int width() const { return rect().width(); }
|
int width() const { return rect().width(); }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue