1
1

Cleanup: move Event.is_repeat & is_direction_inverted to flags

Use a flag for events to avoid adding struct members every time a new
kind of tag is needed - so events remain small.

This also simplifies copying settings as flags can be copied at once
with a mask.
This commit is contained in:
2022-03-01 11:59:21 +11:00
parent eb0f8317e2
commit 8a8424021c
12 changed files with 56 additions and 48 deletions

View File

@@ -6529,7 +6529,7 @@ void UI_but_focus_on_enter_event(wmWindow *win, uiBut *but)
event.type = EVT_BUT_OPEN;
event.val = KM_PRESS;
event.is_repeat = false;
event.flag = 0;
event.customdata = but;
event.customdata_free = false;

View File

@@ -8974,7 +8974,7 @@ void ui_but_activate_event(bContext *C, ARegion *region, uiBut *but)
wm_event_init_from_window(win, &event);
event.type = EVT_BUT_OPEN;
event.val = KM_PRESS;
event.is_repeat = false;
event.flag = 0;
event.customdata = but;
event.customdata_free = false;
@@ -9538,7 +9538,7 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *regi
ui_pan_to_scroll(event, &type, &val);
/* 'ui_pan_to_scroll' gives the absolute direction. */
if (event->is_direction_inverted) {
if (event->flag & WM_EVENT_SCROLL_INVERT) {
scroll_dir = -1;
}
@@ -10459,7 +10459,7 @@ static int ui_handle_menu_event(bContext *C,
/* Only respond to explicit press to avoid the event that opened the menu
* activating an item when the key is held. */
if (event->is_repeat) {
if (event->flag & WM_EVENT_IS_REPEAT) {
break;
}
@@ -10546,7 +10546,7 @@ static int ui_handle_menu_event(bContext *C,
((event->modifier & (KM_SHIFT | KM_CTRL | KM_OSKEY)) == 0) &&
/* Only respond to explicit press to avoid the event that opened the menu
* activating an item when the key is held. */
!event->is_repeat) {
(event->flag & WM_EVENT_IS_REPEAT) == 0) {
if (ui_menu_pass_event_to_parent_if_nonactive(menu, but, level, retval)) {
break;
}

View File

@@ -1023,7 +1023,7 @@ static void actionzone_apply(bContext *C, wmOperator *op, int type)
}
event.val = KM_NOTHING;
event.is_repeat = false;
event.flag = 0;
event.customdata = op->customdata;
event.customdata_free = true;
op->customdata = NULL;

View File

@@ -383,7 +383,7 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
int event_xy[2];
if (event->type == MOUSEPAN) {
if (event->is_direction_inverted) {
if (event->flag & WM_EVENT_SCROLL_INVERT) {
event_xy[0] = 2 * event->xy[0] - event->prev_xy[0];
event_xy[1] = 2 * event->xy[1] - event->prev_xy[1];
}

View File

@@ -1150,7 +1150,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
else if (event->val == KM_PRESS) {
switch (event->type) {
case EVT_CKEY:
if (event->is_repeat) {
if (event->flag & WM_EVENT_IS_REPEAT) {
break;
}
if (event->modifier & KM_ALT) {
@@ -1164,7 +1164,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
}
break;
case EVT_OKEY:
if (event->is_repeat) {
if (event->flag & WM_EVENT_IS_REPEAT) {
break;
}
if ((t->flag & T_PROP_EDIT) && (event->modifier & KM_SHIFT)) {
@@ -1202,7 +1202,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
}
break;
case EVT_NKEY:
if (event->is_repeat) {
if (event->flag & WM_EVENT_IS_REPEAT) {
break;
}
if (ELEM(t->mode, TFM_ROTATION)) {

View File

@@ -668,7 +668,7 @@ static int rna_Event_unicode_length(PointerRNA *ptr)
static bool rna_Event_is_repeat_get(PointerRNA *ptr)
{
const wmEvent *event = ptr->data;
return event->is_repeat;
return (event->flag & WM_EVENT_IS_REPEAT) != 0;
}
static float rna_Event_pressure_get(PointerRNA *ptr)

View File

@@ -635,7 +635,7 @@ static wmEvent *rna_Window_event_add_simulate(wmWindow *win,
wmEvent e = *win->eventstate;
e.type = type;
e.val = value;
e.is_repeat = false;
e.flag = 0;
e.xy[0] = x;
e.xy[1] = y;

View File

@@ -560,6 +560,22 @@ typedef struct wmGesture {
/* ************** wmEvent ************************ */
typedef enum eWM_EventFlag {
/**
* True if the operating system inverted the delta x/y values and resulting
* `prev_xy` values, for natural scroll direction.
* For absolute scroll direction, the delta must be negated again.
*/
WM_EVENT_SCROLL_INVERT = (1 << 0),
/**
* Generated by auto-repeat, note that this must only ever be set for keyboard events
* where `ISKEYBOARD(event->type) == true`.
*
* See #KMI_REPEAT_IGNORE for details on how key-map handling uses this.
*/
WM_EVENT_IS_REPEAT = (1 << 1),
} eWM_EventFlag;
typedef struct wmTabletData {
/** 0=EVT_TABLET_NONE, 1=EVT_TABLET_STYLUS, 2=EVT_TABLET_ERASER. */
int active;
@@ -616,14 +632,6 @@ typedef struct wmEvent {
/** From ghost, fallback if utf8 isn't set. */
char ascii;
/**
* Generated by auto-repeat, note that this must only ever be set for keyboard events
* where `ISKEYBOARD(event->type) == true`.
*
* See #KMI_REPEAT_IGNORE for details on how key-map handling uses this.
*/
char is_repeat;
/** The previous value of `type`. */
short prev_type;
/** The previous value of `val`. */
@@ -656,20 +664,14 @@ typedef struct wmEvent {
/** Tablet info, available for mouse move and button events. */
wmTabletData tablet;
eWM_EventFlag flag;
/* Custom data. */
/** Custom data type, stylus, 6dof, see wm_event_types.h */
short custom;
short customdata_free;
int pad2;
/** Ascii, unicode, mouse-coords, angles, vectors, NDOF data, drag-drop info. */
void *customdata;
/**
* True if the operating system inverted the delta x/y values and resulting
* `prev_xy` values, for natural scroll direction.
* For absolute scroll direction, the delta must be negated again.
*/
char is_direction_inverted;
} wmEvent;
/**

View File

@@ -85,7 +85,7 @@ void WM_event_print(const wmEvent *event)
(event->modifier & KM_ALT) != 0,
(event->modifier & KM_OSKEY) != 0,
event->keymodifier,
event->is_repeat,
(event->flag & WM_EVENT_IS_REPEAT) != 0,
event->xy[0],
event->xy[1],
event->ascii,
@@ -440,7 +440,7 @@ int WM_event_absolute_delta_x(const struct wmEvent *event)
{
int dx = event->xy[0] - event->prev_xy[0];
if (!event->is_direction_inverted) {
if ((event->flag & WM_EVENT_SCROLL_INVERT) == 0) {
dx = -dx;
}
@@ -451,7 +451,7 @@ int WM_event_absolute_delta_y(const struct wmEvent *event)
{
int dy = event->xy[1] - event->prev_xy[1];
if (!event->is_direction_inverted) {
if ((event->flag & WM_EVENT_SCROLL_INVERT) == 0) {
dy = -dy;
}

View File

@@ -153,7 +153,7 @@ wmEvent *WM_event_add_simulate(wmWindow *win, const wmEvent *event_to_add)
win->eventstate->type = event->type;
if (event->val == KM_PRESS) {
if (event->is_repeat == false) {
if ((event->flag & WM_EVENT_IS_REPEAT) == 0) {
copy_v2_v2_int(win->eventstate->prev_click_xy, event->xy);
}
}
@@ -166,7 +166,7 @@ void wm_event_free(wmEvent *event)
#ifndef NDEBUG
/* Don't use assert here because it's fairly harmless in most cases,
* more an issue of correctness, something we should avoid in general. */
if (event->is_repeat && !ISKEYBOARD(event->type)) {
if ((event->flag & WM_EVENT_IS_REPEAT) && !ISKEYBOARD(event->type)) {
printf("%s: 'is_repeat=true' for non-keyboard event, this should not happen.\n", __func__);
WM_event_print(event);
}
@@ -739,7 +739,7 @@ void wm_event_handler_ui_cancel_ex(bContext *C,
wm_event_init_from_window(win, &event);
event.type = EVT_BUT_CANCEL;
event.val = reactivate_button ? 0 : 1;
event.is_repeat = false;
event.flag = 0;
handler->handle_fn(C, &event, handler->user_data);
}
}
@@ -1982,7 +1982,7 @@ static bool wm_eventmatch(const wmEvent *winevent, const wmKeyMapItem *kmi)
return false;
}
if (winevent->is_repeat) {
if (winevent->flag & WM_EVENT_IS_REPEAT) {
if (kmi->flag & KMI_REPEAT_IGNORE) {
return false;
}
@@ -3204,7 +3204,7 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
* wasn't handled, the KM_RELEASE will become a KM_CLICK */
if (event->val == KM_PRESS) {
if (event->is_repeat == false) {
if ((event->flag & WM_EVENT_IS_REPEAT) == 0) {
win->event_queue_check_click = true;
win->event_queue_check_drag = true;
win->event_queue_check_drag_handled = false;
@@ -3814,7 +3814,7 @@ void wm_event_do_handlers(bContext *C)
tevent.type = MOUSEMOVE;
tevent.prev_xy[0] = tevent.xy[0];
tevent.prev_xy[1] = tevent.xy[1];
tevent.is_repeat = false;
tevent.flag = 0;
wm_event_add(win, &tevent);
win->addmousemove = 0;
}
@@ -4720,7 +4720,7 @@ static wmEvent *wm_event_add_mousemove(wmWindow *win, const wmEvent *event)
* them for better performance. */
if (event_last && event_last->type == MOUSEMOVE) {
event_last->type = INBETWEEN_MOUSEMOVE;
event_last->is_repeat = false;
event_last->flag = 0;
}
wmEvent *event_new = wm_event_add(win, event);
@@ -4772,7 +4772,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void
/* Initialize and copy state (only mouse x y and modifiers). */
event = *event_state;
event.is_repeat = false;
event.flag = 0;
/**
* Always support accessing the last key press/release. This is set from `win->eventstate`,
@@ -4870,7 +4870,9 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void
event.val = KM_NOTHING;
/* The direction is inverted from the device due to system preferences. */
event.is_direction_inverted = pd->isDirectionInverted;
if (pd->isDirectionInverted) {
event.flag |= WM_EVENT_SCROLL_INVERT;
}
wm_event_add_trackpad(win, &event, pd->deltaX, -pd->deltaY);
break;
@@ -4951,12 +4953,16 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void
case GHOST_kEventKeyDown:
case GHOST_kEventKeyUp: {
GHOST_TEventKeyData *kd = customdata;
/* Only copy these flags into the `event_state`. */
const eWM_EventFlag event_state_flag_mask = WM_EVENT_IS_REPEAT;
bool keymodifier = 0;
event.type = convert_key(kd->key);
event.ascii = kd->ascii;
/* Might be not NULL terminated. */
memcpy(event.utf8_buf, kd->utf8_buf, sizeof(event.utf8_buf));
event.is_repeat = kd->is_repeat;
if (kd->is_repeat) {
event.flag |= WM_EVENT_IS_REPEAT;
}
event.val = (type == GHOST_kEventKeyDown) ? KM_PRESS : KM_RELEASE;
wm_eventemulation(&event, false);
@@ -4965,7 +4971,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void
/* Copy to event state. */
event_state->val = event.val;
event_state->type = event.type;
event_state->is_repeat = event.is_repeat;
event_state->flag = (event.flag & event_state_flag_mask);
/* Exclude arrow keys, esc, etc from text input. */
if (type == GHOST_kEventKeyUp) {
@@ -5096,7 +5102,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void
/* Double click test - only for press. */
if (event.val == KM_PRESS) {
/* Don't reset timer & location when holding the key generates repeat events. */
if (event.is_repeat == false) {
if ((event.flag & WM_EVENT_IS_REPEAT) == 0) {
wm_event_prev_click_set(&event, event_state);
}
}
@@ -5217,7 +5223,7 @@ void wm_event_add_xrevent(wmWindow *win, wmXrActionData *actiondata, short val)
wmEvent event = {
.type = EVT_XR_ACTION,
.val = val,
.is_repeat = false,
.flag = 0,
.custom = EVT_DATA_XR,
.customdata = actiondata,
.customdata_free = true,

View File

@@ -509,7 +509,7 @@ static void gesture_tweak_modal(bContext *C, const wmEvent *event)
tevent.val = val;
tevent.modifier = gesture->event_modifier;
tevent.keymodifier = gesture->event_keymodifier;
tevent.is_repeat = false;
tevent.flag = 0;
/* mouse coords! */
/* important we add immediately after this event, so future mouse releases

View File

@@ -1213,7 +1213,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
wm_event_init_from_window(win, &event);
event.type = MOUSEMOVE;
copy_v2_v2_int(event.prev_xy, event.xy);
event.is_repeat = false;
event.flag = 0;
wm_event_add(win, &event);
@@ -1344,7 +1344,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
/* activate region */
event.type = MOUSEMOVE;
copy_v2_v2_int(event.prev_xy, event.xy);
event.is_repeat = false;
event.flag = 0;
/* No context change! C->wm->windrawable is drawable, or for area queues. */
wm->winactive = win;
@@ -1485,7 +1485,7 @@ static bool wm_window_timer(const bContext *C)
event.type = wt->event_type;
event.val = KM_NOTHING;
event.keymodifier = 0;
event.is_repeat = false;
event.flag = 0;
event.custom = EVT_DATA_TIMER;
event.customdata = wt;
wm_event_add(win, &event);