Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
52cf8a64
Commit
52cf8a64
authored
Feb 02, 2011
by
Sam Lantinga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added functions to watch events as they go through the event queue.
parent
b231d0b9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
0 deletions
+70
-0
SDL_events.h
include/SDL_events.h
+12
-0
SDL_events.c
src/events/SDL_events.c
+58
-0
No files found.
include/SDL_events.h
View file @
52cf8a64
...
...
@@ -580,6 +580,18 @@ extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter,
extern
DECLSPEC
SDL_bool
SDLCALL
SDL_GetEventFilter
(
SDL_EventFilter
*
filter
,
void
**
userdata
);
/**
* Add a function which is called when an event is added to the queue.
*/
extern
DECLSPEC
void
SDLCALL
SDL_AddEventWatch
(
SDL_EventFilter
filter
,
void
*
userdata
);
/**
* Remove an event watch function added with SDL_AddEventWatch()
*/
extern
DECLSPEC
void
SDLCALL
SDL_DelEventWatch
(
SDL_EventFilter
filter
,
void
*
userdata
);
/**
* Run the filter function on the current event queue, removing any
* events for which the filter returns 0.
...
...
src/events/SDL_events.c
View file @
52cf8a64
...
...
@@ -38,6 +38,14 @@
SDL_EventFilter
SDL_EventOK
=
NULL
;
void
*
SDL_EventOKParam
;
typedef
struct
SDL_EventWatcher
{
SDL_EventFilter
callback
;
void
*
userdata
;
struct
SDL_EventWatcher
*
next
;
}
SDL_EventWatcher
;
static
SDL_EventWatcher
*
SDL_event_watchers
=
NULL
;
typedef
struct
{
Uint32
bits
[
8
];
}
SDL_DisabledEventBlock
;
...
...
@@ -96,6 +104,12 @@ SDL_StopEventLoop(void)
SDL_disabled_events
[
i
]
=
NULL
;
}
}
while
(
SDL_event_watchers
)
{
SDL_EventWatcher
*
tmp
=
SDL_event_watchers
;
SDL_event_watchers
=
tmp
->
next
;
SDL_free
(
tmp
);
}
}
/* This function (and associated calls) may be called more than once */
...
...
@@ -340,9 +354,16 @@ SDL_WaitEventTimeout(SDL_Event * event, int timeout)
int
SDL_PushEvent
(
SDL_Event
*
event
)
{
SDL_EventWatcher
*
curr
;
if
(
SDL_EventOK
&&
!
SDL_EventOK
(
SDL_EventOKParam
,
event
))
{
return
0
;
}
for
(
curr
=
SDL_event_watchers
;
curr
;
curr
=
curr
->
next
)
{
curr
->
callback
(
curr
->
userdata
,
event
);
}
if
(
SDL_PeepEvents
(
event
,
1
,
SDL_ADDEVENT
,
0
,
0
)
<=
0
)
{
return
-
1
;
}
...
...
@@ -376,6 +397,43 @@ SDL_GetEventFilter(SDL_EventFilter * filter, void **userdata)
return
SDL_EventOK
?
SDL_TRUE
:
SDL_FALSE
;
}
/* FIXME: This is not thread-safe yet */
void
SDL_AddEventWatch
(
SDL_EventFilter
filter
,
void
*
userdata
)
{
SDL_EventWatcher
*
watcher
;
watcher
=
(
SDL_EventWatcher
*
)
SDL_malloc
(
sizeof
(
*
watcher
));
if
(
!
watcher
)
{
/* Uh oh... */
return
;
}
watcher
->
callback
=
filter
;
watcher
->
userdata
=
userdata
;
watcher
->
next
=
SDL_event_watchers
;
SDL_event_watchers
=
watcher
;
}
/* FIXME: This is not thread-safe yet */
void
SDL_DelEventWatch
(
SDL_EventFilter
filter
,
void
*
userdata
)
{
SDL_EventWatcher
*
prev
=
NULL
;
SDL_EventWatcher
*
curr
;
for
(
curr
=
SDL_event_watchers
;
curr
;
prev
=
curr
,
curr
=
curr
->
next
)
{
if
(
curr
->
callback
==
filter
&&
curr
->
userdata
==
userdata
)
{
if
(
prev
)
{
prev
->
next
=
curr
->
next
;
}
else
{
SDL_event_watchers
=
curr
->
next
;
}
SDL_free
(
curr
);
break
;
}
}
}
void
SDL_FilterEvents
(
SDL_EventFilter
filter
,
void
*
userdata
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment