Add SDL_RemovePathWatch().

Rename SDL_WatchPathForChange() to SDL_AddPathWatch().
Improve documentation.
This commit is contained in:
meyraud705 2026-05-07 21:30:39 +02:00
parent 3d9e800294
commit 0ea3074fa1
7 changed files with 123 additions and 21 deletions

View file

@ -260,8 +260,8 @@ typedef enum SDL_EventType
SDL_EVENT_CAMERA_DEVICE_DENIED, /**< A camera device has been denied for use by the user. */
/* File watch events */
SDL_EVENT_FILE_CHANGED = 0x1500, /**< A watched file was written. */
SDL_EVENT_FILE_WATCH_ERROR, /**< Watched files may have been modified, but the events are lost. */
SDL_EVENT_FILE_DATA_WRITTEN = 0x1500, /**< Data was written in a watched file. */
SDL_EVENT_FILE_WATCH_ERROR, /**< Watched files may have been modified, but the events are lost. */
/* Render events */
SDL_EVENT_RENDER_TARGETS_RESET = 0x2000, /**< The render targets have been reset and their contents need to be updated */
@ -977,16 +977,16 @@ typedef struct SDL_SensorEvent
/**
* File watch event structure (event.file_watch.*)
*
* You can add file to the watch list with SDL_WatchPathForChanges().
* You can add file to the watch list with SDL_AddPathWatch().
*
* \sa SDL_WatchPathForChanges
* \sa SDL_AddPathWatch
*/
typedef struct SDL_FileWatchEvent
{
SDL_EventType type; /**< SDL_EVENT_FILE_CHANGED or SDL_EVENT_FILE_WATCH_ERROR */
SDL_EventType type; /**< SDL_EVENT_FILE_DATA_WRITTEN or SDL_EVENT_FILE_WATCH_ERROR */
Uint32 reserved;
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
const char *path; /**< Path of the modified file for SDL_EVENT_FILE_CHANGED, NULL for SDL_EVENT_FILE_WATCH_ERROR */
const char *path; /**< Path of the modified file for SDL_EVENT_FILE_DATA_WRITTEN, NULL for SDL_EVENT_FILE_WATCH_ERROR */
} SDL_FileWatchEvent;
/**

View file

@ -532,7 +532,7 @@ extern SDL_DECLSPEC char * SDLCALL SDL_GetCurrentDirectory(void);
/**
* A function pointer used for callbacks that watch for files change.
*
* \param userdata what was passed as `userdata` to SDL_WatchPathForChanges().
* \param userdata what was passed as `userdata` to SDL_AddPathWatch().
* \param path path of file that was modified.
*
* \threadsafety SDL may call this callback at any time from any thread; the
@ -543,9 +543,9 @@ typedef void (SDLCALL *SDL_FileWatchCallback)(void *userdata, const char *path);
/**
* This function adds a file watcher that will fires an app-provided callback
* and send an SDL_EVENT_FILE_CHANGED event every time the file is modified. If
* path is a directory, the callback will be called for every file modified in
* that directory.
* and send an SDL_EVENT_FILE_CHANGED event every time data is written in the
* file. If path is a directory, the callback will be called for every file
* in that directory that has data written into.
*
* \param path file or directory path to watch.
* \param callback a function that is called when the watched file is modified.
@ -558,8 +558,25 @@ typedef void (SDLCALL *SDL_FileWatchCallback)(void *userdata, const char *path);
* \threadsafety It is safe to call this function from any thread.
*
* \sa SDL_FileWatchEvent
* \sa SDL_RemovePathWatch
*/
extern SDL_DECLSPEC bool SDLCALL SDL_WatchPathForChanges(const char *path, SDL_FileWatchCallback callback, void *userdata);
extern SDL_DECLSPEC bool SDLCALL SDL_AddPathWatch(const char *path, SDL_FileWatchCallback callback, void *userdata);
/**
* Remove an file watch callback added with SDL_AddPathWatch().
*
* This function takes the same input as SDL_AddPathWatch() to identify and
* delete the corresponding callback.
*
* \param path the path originally passed to SDL_AddPathWatch().
* \param callback the callback originally passed to SDL_AddPathWatch().
* \param userdata the pointer originally passed to SDL_AddPathWatch().
*
* \threadsafety It is safe to call this function from any thread.
*
* \sa SDL_AddPathWatch
*/
extern SDL_DECLSPEC void SDLCALL SDL_RemovePathWatch(const char *path, SDL_FileWatchCallback callback, void *userdata);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus