diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-02-02 07:14:51 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-02-02 07:23:55 +0300 |
commit | 141c6073ca39f0d59c67ebef89b094395b903a4a (patch) | |
tree | 372d9246e92117f7d74ef7688848b28710e906fd /source/blender/windowmanager/intern | |
parent | 99b8eef6a534c2c9846b48736cb9eb007c120ec7 (diff) |
WM: Event simulation support for Python
This feature is intended only for testing,
to automate simulating user input.
- Enabled by '--enable-event-simulate'.
- Disables handling all real input events.
- Access by calling `Window.event_simulate(..)`
- Disabling `bpy.app.use_event_simulate`
to allow handling real events (can only disable).
Currently only mouse & keyboard events work well,
NDOF, IME... etc could be added as needed.
See D4286 for example usage.
Diffstat (limited to 'source/blender/windowmanager/intern')
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 16 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_window.c | 5 |
2 files changed, 21 insertions, 0 deletions
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 8ccc2457a90..a2ee5f04449 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -127,6 +127,18 @@ wmEvent *wm_event_add(wmWindow *win, const wmEvent *event_to_add) return wm_event_add_ex(win, event_to_add, NULL); } +wmEvent *WM_event_add_simulate(wmWindow *win, const wmEvent *event_to_add) +{ + if ((G.f & G_FLAG_EVENT_SIMULATE) == 0) { + BLI_assert(0); + return NULL; + } + wmEvent *event = wm_event_add(win, event_to_add); + win->eventstate->x = event->x; + win->eventstate->y = event->y; + return event; +} + void wm_event_free(wmEvent *event) { if (event->customdata) { @@ -3899,6 +3911,10 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U { wmWindow *owin; + if (UNLIKELY(G.f & G_FLAG_EVENT_SIMULATE)) { + return; + } + /* Having both, event and evt, can be highly confusing to work with, but is necessary for * our current event system, so let's clear things up a bit: * - data added to event only will be handled immediately, but will not be copied to the next event diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index fa11979e39e..79e6b5104a3 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -1049,6 +1049,11 @@ void wm_cursor_position_to_ghost(wmWindow *win, int *x, int *y) void wm_get_cursor_position(wmWindow *win, int *x, int *y) { + if (UNLIKELY(G.f & G_FLAG_EVENT_SIMULATE)) { + *x = win->eventstate->x; + *y = win->eventstate->y; + return; + } GHOST_GetCursorPosition(g_system, x, y); wm_cursor_position_from_ghost(win, x, y); } |