mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-19 20:46:05 +00:00
Add callback to file watch.
This commit is contained in:
parent
5ed86c7580
commit
7b8d6155cc
9 changed files with 116 additions and 64 deletions
|
|
@ -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_WATCH_ERROR = 0x1500, /**< Watched files may have been modified, but the events are lost. */
|
||||
SDL_EVENT_FILE_CHANGED, /**< A watched file was written. */
|
||||
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. */
|
||||
|
||||
/* Render events */
|
||||
SDL_EVENT_RENDER_TARGETS_RESET = 0x2000, /**< The render targets have been reset and their contents need to be updated */
|
||||
|
|
@ -976,6 +976,10 @@ typedef struct SDL_SensorEvent
|
|||
|
||||
/**
|
||||
* File watch event structure (event.file_watch.*)
|
||||
*
|
||||
* You can add file to the watch list with SDL_WatchFileForChanges().
|
||||
*
|
||||
* \sa SDL_WatchFileForChanges
|
||||
*/
|
||||
typedef struct SDL_FileWatchEvent
|
||||
{
|
||||
|
|
|
|||
|
|
@ -529,6 +529,38 @@ extern SDL_DECLSPEC char ** SDLCALL SDL_GlobDirectory(const char *path, const ch
|
|||
*/
|
||||
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_WatchFileForChanges().
|
||||
* \param path path of file that was modified.
|
||||
*
|
||||
* \threadsafety SDL may call this callback at any time from any thread; the
|
||||
* application is responsible for locking resources the callback
|
||||
* touches that need to be protected.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \param path file or directory path to watch.
|
||||
* \param callback a function that is called when the watched file is modified.
|
||||
* Can be NULL if you only want to receive event.
|
||||
* \param userdata a pointer that is passed to `callback`.
|
||||
*
|
||||
* \returns true on success or false on failure; call SDL_GetError() for more
|
||||
* information.
|
||||
*
|
||||
* \threadsafety It is safe to call this function from any thread.
|
||||
*
|
||||
* \sa SDL_FileWatchEvent
|
||||
*/
|
||||
extern SDL_DECLSPEC bool SDLCALL SDL_WatchFileForChanges(const char *path, SDL_FileWatchCallback callback, void *userdata);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue