diff src/timer.c @ 10:42ac054c0231

*: huge refactoring dirtools now uses wchar (wayyy overdue) the timer doesn't have a stupid design anymore we don't use windows.h at all now ...
author Paper <paper@paper.us.eu.org>
date Sun, 11 Feb 2024 19:43:31 -0500
parents 07f0e2f43204
children e6a594f16403
line wrap: on
line diff
--- a/src/timer.c	Fri Dec 16 21:55:37 2022 -0500
+++ b/src/timer.c	Sun Feb 11 19:43:31 2024 -0500
@@ -1,32 +1,23 @@
-#include <assert.h>
-#ifndef WIN32_LEAN_AND_MEAN
-#  define WIN32_LEAN_AND_MEAN
-#endif
-#include <windows.h>
 #include "timer.h"
 
-void timer_init(struct timer* restrict timer, HWND winampClientWindow, TIMERPROC timer_proc) {
-	timer->winampClientWindow = winampClientWindow;
+#include <assert.h>
+
+void timer_init(struct timer* restrict timer, UINT interval, TIMERPROC timer_proc) {
+	timer->id = 0;
+	timer->interval = interval;
 	timer->timer_proc = timer_proc;
-	timer->initialized = 1;
 }
 
-void timer_set(struct timer* restrict timer, HWND winampClientWindow) {
-	assert(timer->initialized);
+int timer_set(struct timer* restrict timer) {
+	assert(!timer->id);
 
-	if (timer->is_timer_alive)
-		return;
-
-	timer->is_timer_alive = 1;
-	SetTimer(winampClientWindow, 1, timer->interval, timer->timer_proc);
+	return !!(timer->id = SetTimer(NULL, timer->id, timer->interval, timer->timer_proc));
 }
 
-void timer_stop(struct timer* restrict timer, HWND winampClientWindow) {
-	assert(timer->initialized);
+int timer_stop(struct timer* restrict timer) {
+	assert(timer->id);
 
-	if (!timer->is_timer_alive)
-		return;
-
-	timer->is_timer_alive = 0;
-	KillTimer(winampClientWindow, 1);
+	BOOL ret = KillTimer(NULL, timer->id);
+	timer->id = 0;
+	return ret;
 }
\ No newline at end of file