Refactor: use const event data, use static_casts
In some cases processing events was modifying them, as there can be multiple event consumers, manipulating events isn't correct. Even though in practice it didn't cause issues, it's straightforward not to do this and makes logic easier to reason about.
This commit is contained in:
@@ -5449,7 +5449,10 @@ static bool wm_event_is_ignorable_key_press(const wmWindow *win, const wmEvent &
|
||||
return wm_event_is_same_key_press(last_event, event);
|
||||
}
|
||||
|
||||
void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, const int type, void *customdata)
|
||||
void wm_event_add_ghostevent(wmWindowManager *wm,
|
||||
wmWindow *win,
|
||||
const int type,
|
||||
const void *customdata)
|
||||
{
|
||||
if (UNLIKELY(G.f & G_FLAG_EVENT_SIMULATE)) {
|
||||
return;
|
||||
@@ -5515,9 +5518,11 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, const int type,
|
||||
switch (type) {
|
||||
/* Mouse move, also to inactive window (X11 does this). */
|
||||
case GHOST_kEventCursorMove: {
|
||||
GHOST_TEventCursorData *cd = static_cast<GHOST_TEventCursorData *>(customdata);
|
||||
const GHOST_TEventCursorData *cd = static_cast<const GHOST_TEventCursorData *>(customdata);
|
||||
|
||||
copy_v2_v2_int(event.xy, &cd->x);
|
||||
wm_cursor_position_from_ghost_screen_coords(win, &event.xy[0], &event.xy[1]);
|
||||
|
||||
wm_stereo3d_mouse_offset_apply(win, event.xy);
|
||||
wm_tablet_data_from_ghost(&cd->tablet, &event.tablet);
|
||||
|
||||
@@ -5556,12 +5561,15 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, const int type,
|
||||
break;
|
||||
}
|
||||
case GHOST_kEventTrackpad: {
|
||||
GHOST_TEventTrackpadData *pd = static_cast<GHOST_TEventTrackpadData *>(customdata);
|
||||
const GHOST_TEventTrackpadData *pd = static_cast<const GHOST_TEventTrackpadData *>(
|
||||
customdata);
|
||||
|
||||
int delta[2] = {pd->deltaX, -pd->deltaY};
|
||||
switch (pd->subtype) {
|
||||
case GHOST_kTrackpadEventMagnify:
|
||||
event.type = MOUSEZOOM;
|
||||
pd->deltaX = -pd->deltaX;
|
||||
pd->deltaY = -pd->deltaY;
|
||||
delta[0] = -delta[0];
|
||||
delta[1] = -delta[1];
|
||||
break;
|
||||
case GHOST_kTrackpadEventSmartMagnify:
|
||||
event.type = MOUSESMARTZOOM;
|
||||
@@ -5575,8 +5583,9 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, const int type,
|
||||
break;
|
||||
}
|
||||
|
||||
event.xy[0] = event_state->xy[0] = pd->x;
|
||||
event.xy[1] = event_state->xy[1] = pd->y;
|
||||
copy_v2_v2_int(event.xy, &pd->x);
|
||||
wm_cursor_position_from_ghost_screen_coords(win, &event.xy[0], &event.xy[1]);
|
||||
copy_v2_v2_int(event_state->xy, event.xy);
|
||||
event.val = KM_NOTHING;
|
||||
|
||||
/* The direction is inverted from the device due to system preferences. */
|
||||
@@ -5584,13 +5593,13 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, const int type,
|
||||
event.flag |= WM_EVENT_SCROLL_INVERT;
|
||||
}
|
||||
|
||||
wm_event_add_trackpad(win, &event, pd->deltaX, -pd->deltaY);
|
||||
wm_event_add_trackpad(win, &event, delta[0], delta[1]);
|
||||
break;
|
||||
}
|
||||
/* Mouse button. */
|
||||
case GHOST_kEventButtonDown:
|
||||
case GHOST_kEventButtonUp: {
|
||||
GHOST_TEventButtonData *bd = static_cast<GHOST_TEventButtonData *>(customdata);
|
||||
const GHOST_TEventButtonData *bd = static_cast<const GHOST_TEventButtonData *>(customdata);
|
||||
|
||||
/* Get value and type from Ghost. */
|
||||
event.val = (type == GHOST_kEventButtonDown) ? KM_PRESS : KM_RELEASE;
|
||||
@@ -5653,7 +5662,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, const int type,
|
||||
/* Keyboard. */
|
||||
case GHOST_kEventKeyDown:
|
||||
case GHOST_kEventKeyUp: {
|
||||
GHOST_TEventKeyData *kd = static_cast<GHOST_TEventKeyData *>(customdata);
|
||||
const GHOST_TEventKeyData *kd = static_cast<const GHOST_TEventKeyData *>(customdata);
|
||||
event.type = convert_key(kd->key);
|
||||
if (UNLIKELY(event.type == EVENT_NONE)) {
|
||||
break;
|
||||
@@ -5813,7 +5822,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, const int type,
|
||||
}
|
||||
|
||||
case GHOST_kEventWheel: {
|
||||
GHOST_TEventWheelData *wheelData = static_cast<GHOST_TEventWheelData *>(customdata);
|
||||
const GHOST_TEventWheelData *wheelData = static_cast<const GHOST_TEventWheelData *>(
|
||||
customdata);
|
||||
|
||||
if (wheelData->z > 0) {
|
||||
event.type = WHEELUPMOUSE;
|
||||
@@ -5840,7 +5850,8 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, const int type,
|
||||
}
|
||||
|
||||
case GHOST_kEventNDOFButton: {
|
||||
GHOST_TEventNDOFButtonData *e = static_cast<GHOST_TEventNDOFButtonData *>(customdata);
|
||||
const GHOST_TEventNDOFButtonData *e = static_cast<const GHOST_TEventNDOFButtonData *>(
|
||||
customdata);
|
||||
|
||||
event.type = NDOF_BUTTON_INDEX_AS_EVENT(e->button);
|
||||
|
||||
|
||||
@@ -983,6 +983,7 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
|
||||
{
|
||||
PlayState *ps = (PlayState *)ps_void;
|
||||
const GHOST_TEventType type = GHOST_GetEventType(evt);
|
||||
GHOST_TEventDataPtr data = GHOST_GetEventData(evt);
|
||||
/* Convert ghost event into value keyboard or mouse. */
|
||||
const int val = ELEM(type, GHOST_kEventKeyDown, GHOST_kEventButtonDown);
|
||||
GHOST_SystemHandle ghost_system = ps->ghost_data.system;
|
||||
@@ -997,9 +998,7 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
|
||||
switch (type) {
|
||||
case GHOST_kEventKeyDown:
|
||||
case GHOST_kEventKeyUp: {
|
||||
GHOST_TEventKeyData *key_data;
|
||||
|
||||
key_data = (GHOST_TEventKeyData *)GHOST_GetEventData(evt);
|
||||
const GHOST_TEventKeyData *key_data = static_cast<const GHOST_TEventKeyData *>(data);
|
||||
switch (key_data->key) {
|
||||
case GHOST_kKeyEsc:
|
||||
ps->loading = false;
|
||||
@@ -1027,9 +1026,7 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
|
||||
switch (type) {
|
||||
case GHOST_kEventKeyDown:
|
||||
case GHOST_kEventKeyUp: {
|
||||
GHOST_TEventKeyData *key_data;
|
||||
|
||||
key_data = (GHOST_TEventKeyData *)GHOST_GetEventData(evt);
|
||||
const GHOST_TEventKeyData *key_data = static_cast<const GHOST_TEventKeyData *>(data);
|
||||
switch (key_data->key) {
|
||||
case GHOST_kKeyA:
|
||||
if (val) {
|
||||
@@ -1324,8 +1321,7 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
|
||||
}
|
||||
case GHOST_kEventButtonDown:
|
||||
case GHOST_kEventButtonUp: {
|
||||
GHOST_TEventButtonData *bd = reinterpret_cast<GHOST_TEventButtonData *>(
|
||||
GHOST_GetEventData(evt));
|
||||
const GHOST_TEventButtonData *bd = static_cast<const GHOST_TEventButtonData *>(data);
|
||||
int cx, cy, sizex, sizey;
|
||||
playanim_window_get_size(ghost_window, &sizex, &sizey);
|
||||
|
||||
@@ -1368,8 +1364,7 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
|
||||
}
|
||||
case GHOST_kEventCursorMove: {
|
||||
if (ps->ghost_data.qual & WS_QUAL_LMOUSE) {
|
||||
GHOST_TEventCursorData *cd = reinterpret_cast<GHOST_TEventCursorData *>(
|
||||
GHOST_GetEventData(evt));
|
||||
const GHOST_TEventCursorData *cd = static_cast<const GHOST_TEventCursorData *>(data);
|
||||
int cx, cy;
|
||||
|
||||
/* Ignore 'in-between' events, since they can make scrubbing lag.
|
||||
@@ -1431,11 +1426,10 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
|
||||
break;
|
||||
}
|
||||
case GHOST_kEventDraggingDropDone: {
|
||||
GHOST_TEventDragnDropData *ddd = reinterpret_cast<GHOST_TEventDragnDropData *>(
|
||||
GHOST_GetEventData(evt));
|
||||
const GHOST_TEventDragnDropData *ddd = static_cast<const GHOST_TEventDragnDropData *>(data);
|
||||
|
||||
if (ddd->dataType == GHOST_kDragnDropTypeFilenames) {
|
||||
GHOST_TStringArray *stra = reinterpret_cast<GHOST_TStringArray *>(ddd->data);
|
||||
const GHOST_TStringArray *stra = static_cast<const GHOST_TStringArray *>(ddd->data);
|
||||
int a;
|
||||
|
||||
for (a = 0; a < stra->count; a++) {
|
||||
|
||||
@@ -1486,7 +1486,7 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_pt
|
||||
}
|
||||
|
||||
case GHOST_kEventOpenMainFile: {
|
||||
const char *path = static_cast<const char *>(GHOST_GetEventData(evt));
|
||||
const char *path = static_cast<const char *>(data);
|
||||
|
||||
if (path) {
|
||||
wmOperatorType *ot = WM_operatortype_find("WM_OT_open_mainfile", false);
|
||||
@@ -1506,8 +1506,8 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_pt
|
||||
break;
|
||||
}
|
||||
case GHOST_kEventDraggingDropDone: {
|
||||
GHOST_TEventDragnDropData *ddd = static_cast<GHOST_TEventDragnDropData *>(
|
||||
GHOST_GetEventData(evt));
|
||||
const GHOST_TEventDragnDropData *ddd = static_cast<const GHOST_TEventDragnDropData *>(
|
||||
data);
|
||||
|
||||
/* Ensure the event state matches modifiers (window was inactive). */
|
||||
wm_window_update_eventstate_modifiers(wm, win);
|
||||
@@ -1522,9 +1522,8 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_pt
|
||||
event.val = KM_NOTHING;
|
||||
copy_v2_v2_int(event.prev_xy, event.xy);
|
||||
|
||||
wm_cursor_position_from_ghost_screen_coords(win, &ddd->x, &ddd->y);
|
||||
event.xy[0] = ddd->x;
|
||||
event.xy[1] = ddd->y;
|
||||
copy_v2_v2_int(event.xy, &ddd->x);
|
||||
wm_cursor_position_from_ghost_screen_coords(win, &event.xy[0], &event.xy[1]);
|
||||
|
||||
/* The values from #wm_window_update_eventstate may not match (under WAYLAND they don't)
|
||||
* Write this into the event state. */
|
||||
@@ -1552,7 +1551,7 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_pt
|
||||
/* add drag data to wm for paths: */
|
||||
|
||||
if (ddd->dataType == GHOST_kDragnDropTypeFilenames) {
|
||||
GHOST_TStringArray *stra = static_cast<GHOST_TStringArray *>(ddd->data);
|
||||
const GHOST_TStringArray *stra = static_cast<const GHOST_TStringArray *>(ddd->data);
|
||||
|
||||
for (int a = 0; a < stra->count; a++) {
|
||||
printf("drop file %s\n", stra->strings[a]);
|
||||
@@ -1589,20 +1588,6 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_pt
|
||||
|
||||
break;
|
||||
}
|
||||
case GHOST_kEventTrackpad: {
|
||||
GHOST_TEventTrackpadData *pd = static_cast<GHOST_TEventTrackpadData *>(data);
|
||||
|
||||
wm_cursor_position_from_ghost_screen_coords(win, &pd->x, &pd->y);
|
||||
wm_event_add_ghostevent(wm, win, type, data);
|
||||
break;
|
||||
}
|
||||
case GHOST_kEventCursorMove: {
|
||||
GHOST_TEventCursorData *cd = static_cast<GHOST_TEventCursorData *>(data);
|
||||
|
||||
wm_cursor_position_from_ghost_screen_coords(win, &cd->x, &cd->y);
|
||||
wm_event_add_ghostevent(wm, win, type, data);
|
||||
break;
|
||||
}
|
||||
case GHOST_kEventButtonDown:
|
||||
case GHOST_kEventButtonUp: {
|
||||
if (win->active == 0) {
|
||||
|
||||
@@ -134,7 +134,7 @@ void wm_event_do_handlers(bContext *C);
|
||||
/**
|
||||
* Windows store own event queues #wmWindow.event_queue (no #bContext here).
|
||||
*/
|
||||
void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void *customdata);
|
||||
void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, const void *customdata);
|
||||
#ifdef WITH_XR_OPENXR
|
||||
void wm_event_add_xrevent(wmWindow *win, wmXrActionData *actiondata, short val);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user