Skip to content

Commit 38ace2e

Browse files
committed
mac windows resizing
1 parent b4ac538 commit 38ace2e

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

src/gui/sdl/sdlWindow.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22
#include "util/fastMath.h"
33
#include "app.h"
44

5+
#include <SDL3/SDL_events.h>
6+
7+
bool resizingEventWatcher(void* data, SDL_Event* event) {
8+
if (event->type == SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED) {
9+
SDL_Window* win = SDL_GetWindowFromID(event->window.windowID);
10+
if (((SdlWindow*)data)->getHandle() == win) {
11+
if (((SdlWindow*)data)->doRecieveEvent) {
12+
((SdlWindow*)data)->doRecieveEvent(*event);
13+
}
14+
}
15+
}
16+
return 0;
17+
}
18+
519
SdlWindow::SdlWindow(const std::string& name, unsigned int width, unsigned int height) {
620
logInfo("Creating SDL window...");
721

@@ -11,6 +25,8 @@ SdlWindow::SdlWindow(const std::string& name, unsigned int width, unsigned int h
1125
throwFatalError("SDL could not create window! SDL_Error: " + std::string(SDL_GetError()));
1226
}
1327

28+
SDL_AddEventWatch(resizingEventWatcher, this);
29+
1430
int winW, winH, drawW, drawH;
1531
SDL_GetWindowSize(handle, &winW, &winH);
1632
SDL_GetWindowSizeInPixels(handle, &drawW, &drawH);
@@ -33,19 +49,19 @@ SdlWindow::~SdlWindow() {
3349
}
3450

3551
bool SdlWindow::recieveEvent(SDL_Event& event) {
36-
if (doRecieveEvent) {
37-
return doRecieveEvent(event);
38-
}
39-
if (isThisMyEvent(event)) {
40-
if (event.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED) {
41-
App::get().deregisterWindow(this);
42-
}
43-
return true;
52+
if (doRecieveEvent) {
53+
return doRecieveEvent(event);
54+
}
55+
if (isThisMyEvent(event)) {
56+
if (event.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED) {
57+
App::get().deregisterWindow(this);
4458
}
45-
46-
return false;
59+
return true;
4760
}
4861

62+
return false;
63+
}
64+
4965
bool SdlWindow::isThisMyEvent(const SDL_Event& event) {
5066
if (event.type == 2050) return true; // the fuck is this? - jack quay jamison
5167
return SDL_GetWindowFromEvent(&event) == handle;

src/gui/sdl/sdlWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <SDL3/SDL_vulkan.h>
77

88
class SdlWindow {
9+
friend bool resizingEventWatcher(void* data, SDL_Event* event);
910
public:
1011
SdlWindow(const std::string& name, unsigned int width = 800, unsigned int height = 600);
1112
~SdlWindow();

0 commit comments

Comments
 (0)