aboutsummaryrefslogtreecommitdiffstats
path: root/include/pugl/detail
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-10-24 13:28:22 +0200
committerDavid Robillard <d@drobilla.net>2020-10-24 13:28:22 +0200
commit612aae5147abec2be9523c1d2858550e5d8a150d (patch)
tree2f88ed8d310af34e8c401dc14ed75f589b847a73 /include/pugl/detail
parent9c2f1888f033dc577464d41cb18839b988de7987 (diff)
downloadpugl-612aae5147abec2be9523c1d2858550e5d8a150d.tar.gz
pugl-612aae5147abec2be9523c1d2858550e5d8a150d.tar.bz2
pugl-612aae5147abec2be9523c1d2858550e5d8a150d.zip
Replace live resize with loop events
This allows the application to control how recursive loops are handled rather than have Pugl impose behavior which can get in the way. For example, an application may not want to continuously animate while being resized, or set up its rendering differently in this situation. For example, with Vulkan, setting up a different swapchain can be necessary for smooth performance while live resizing on Windows, and Pugl has no ability to do this. I think it was a mistake to add this timer to Pugl itself, because it was always a bit of a leaky abstraction, and not very appropriate for a library that is supposed to be a thin abstraction layer. Though it almost seemed like things ran as usual while resizing on Windows and MacOS, the main event loop being stalled can be confusing, and there was no way to detect this. This way, applications must explicitly handle this situation and can implement the behavior they want without Pugl getting in the way. This also simplifies the Pugl implementation a bit, which is always nice.
Diffstat (limited to 'include/pugl/detail')
-rw-r--r--include/pugl/detail/implementation.c3
-rw-r--r--include/pugl/detail/mac.m15
-rw-r--r--include/pugl/detail/win.c16
-rw-r--r--include/pugl/detail/win.h1
4 files changed, 7 insertions, 28 deletions
diff --git a/include/pugl/detail/implementation.c b/include/pugl/detail/implementation.c
index e9a3450..f15b856 100644
--- a/include/pugl/detail/implementation.c
+++ b/include/pugl/detail/implementation.c
@@ -398,7 +398,8 @@ void
puglDispatchSimpleEvent(PuglView* view, const PuglEventType type)
{
assert(type == PUGL_CREATE || type == PUGL_DESTROY || type == PUGL_MAP ||
- type == PUGL_UNMAP || type == PUGL_UPDATE || type == PUGL_CLOSE);
+ type == PUGL_UNMAP || type == PUGL_UPDATE || type == PUGL_CLOSE ||
+ type == PUGL_LOOP_ENTER || type == PUGL_LOOP_LEAVE);
const PuglEvent event = {{type, 0}};
puglDispatchEvent(view, &event);
diff --git a/include/pugl/detail/mac.m b/include/pugl/detail/mac.m
index efcaca0..a807761 100644
--- a/include/pugl/detail/mac.m
+++ b/include/pugl/detail/mac.m
@@ -190,7 +190,6 @@ updateViewRect(PuglView* view)
PuglView* puglview;
NSTrackingArea* trackingArea;
NSMutableAttributedString* markedText;
- NSTimer* timer;
NSMutableDictionary* userTimers;
bool reshaped;
}
@@ -717,15 +716,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
- (void)viewWillStartLiveResize
{
- timer = [NSTimer timerWithTimeInterval:(1 / 60.0)
- target:self
- selector:@selector(resizeTick)
- userInfo:nil
- repeats:YES];
- [[NSRunLoop currentRunLoop] addTimer:timer
- forMode:NSRunLoopCommonModes];
-
- [super viewWillStartLiveResize];
+ puglDispatchSimpleEvent(puglview, PUGL_LOOP_ENTER);
}
- (void)viewWillDraw
@@ -749,9 +740,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
- (void)viewDidEndLiveResize
{
- [super viewDidEndLiveResize];
- [timer invalidate];
- timer = NULL;
+ puglDispatchSimpleEvent(puglview, PUGL_LOOP_LEAVE);
}
@end
diff --git a/include/pugl/detail/win.c b/include/pugl/detail/win.c
index 84cca27..237ebde 100644
--- a/include/pugl/detail/win.c
+++ b/include/pugl/detail/win.c
@@ -51,7 +51,6 @@
#define PUGL_LOCAL_CLOSE_MSG (WM_USER + 50)
#define PUGL_LOCAL_MARK_MSG (WM_USER + 51)
#define PUGL_LOCAL_CLIENT_MSG (WM_USER + 52)
-#define PUGL_RESIZE_TIMER_ID 9461
#define PUGL_USER_TIMER_MIN 9470
typedef BOOL (WINAPI *PFN_SetProcessDPIAware)(void);
@@ -590,17 +589,10 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
break;
case WM_ENTERSIZEMOVE:
case WM_ENTERMENULOOP:
- view->impl->resizing = true;
- SetTimer(view->impl->hwnd,
- PUGL_RESIZE_TIMER_ID,
- 1000 / (UINT)view->hints[PUGL_REFRESH_RATE],
- NULL);
+ puglDispatchSimpleEvent(view, PUGL_LOOP_ENTER);
break;
case WM_TIMER:
- if (wParam == PUGL_RESIZE_TIMER_ID) {
- RedrawWindow(view->impl->hwnd, NULL, NULL,
- RDW_INVALIDATE|RDW_ALLCHILDREN|RDW_INTERNALPAINT);
- } else if (wParam >= PUGL_USER_TIMER_MIN) {
+ if (wParam >= PUGL_USER_TIMER_MIN) {
PuglEvent ev = {{PUGL_TIMER, 0}};
ev.timer.id = wParam - PUGL_USER_TIMER_MIN;
puglDispatchEvent(view, &ev);
@@ -608,9 +600,7 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam)
break;
case WM_EXITSIZEMOVE:
case WM_EXITMENULOOP:
- KillTimer(view->impl->hwnd, PUGL_RESIZE_TIMER_ID);
- view->impl->resizing = false;
- puglPostRedisplay(view);
+ puglDispatchSimpleEvent(view, PUGL_LOOP_LEAVE);
break;
case WM_GETMINMAXINFO:
mmi = (MINMAXINFO*)lParam;
diff --git a/include/pugl/detail/win.h b/include/pugl/detail/win.h
index 0ead1fa..4c0a3c0 100644
--- a/include/pugl/detail/win.h
+++ b/include/pugl/detail/win.h
@@ -42,7 +42,6 @@ struct PuglInternalsImpl {
HDC hdc;
PuglSurface* surface;
bool flashing;
- bool resizing;
bool mouseTracked;
};