Fix T76794: Number button cursor overrides eyedropper cursor

Pressing 'E' over a number button to pick a distance was keeping
left-right arrows instead of using the eye-dropper cursor.

Workaround this by clearing the active button before setting the cursor.
This commit is contained in:
Campbell Barton 2020-05-20 22:04:59 +10:00
parent 7d3bf5166d
commit eb57377f12
Notes: blender-bot 2023-02-14 08:10:06 +01:00
Referenced by issue #76794, Strange behavior of Eyedropper (E) with Object Data
10 changed files with 47 additions and 11 deletions

View File

@ -2380,6 +2380,8 @@ uiBut *UI_context_active_but_prop_get(const struct bContext *C,
struct PropertyRNA **r_prop,
int *r_index);
void UI_context_active_but_prop_handle(struct bContext *C);
void UI_context_active_but_clear(struct bContext *C, struct wmWindow *win, struct ARegion *region);
struct wmOperator *UI_context_active_operator_get(const struct bContext *C);
void UI_context_update_anim_flag(const struct bContext *C);
void UI_context_active_but_prop_get_filebrowser(const struct bContext *C,

View File

@ -292,7 +292,10 @@ static int eyedropper_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(
{
/* init */
if (eyedropper_init(C, op)) {
WM_cursor_modal_set(CTX_wm_window(C), WM_CURSOR_EYEDROPPER);
wmWindow *win = CTX_wm_window(C);
/* Workaround for de-activating the button clearing the cursor, see T76794 */
UI_context_active_but_clear(C, win, CTX_wm_region(C));
WM_cursor_modal_set(win, WM_CURSOR_EYEDROPPER);
/* add temp handler */
WM_event_add_modal_handler(C, op);

View File

@ -304,7 +304,10 @@ static int eyedropper_colorband_invoke(bContext *C, wmOperator *op, const wmEven
{
/* init */
if (eyedropper_colorband_init(C, op)) {
WM_cursor_modal_set(CTX_wm_window(C), WM_CURSOR_EYEDROPPER);
wmWindow *win = CTX_wm_window(C);
/* Workaround for de-activating the button clearing the cursor, see T76794 */
UI_context_active_but_clear(C, win, CTX_wm_region(C));
WM_cursor_modal_set(win, WM_CURSOR_EYEDROPPER);
/* add temp handler */
WM_event_add_modal_handler(C, op);

View File

@ -316,7 +316,10 @@ static int datadropper_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED
{
/* init */
if (datadropper_init(C, op)) {
WM_cursor_modal_set(CTX_wm_window(C), WM_CURSOR_EYEDROPPER);
wmWindow *win = CTX_wm_window(C);
/* Workaround for de-activating the button clearing the cursor, see T76794 */
UI_context_active_but_clear(C, win, CTX_wm_region(C));
WM_cursor_modal_set(win, WM_CURSOR_EYEDROPPER);
/* add temp handler */
WM_event_add_modal_handler(C, op);

View File

@ -311,7 +311,10 @@ static int depthdropper_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE
{
/* init */
if (depthdropper_init(C, op)) {
WM_cursor_modal_set(CTX_wm_window(C), WM_CURSOR_EYEDROPPER);
wmWindow *win = CTX_wm_window(C);
/* Workaround for de-activating the button clearing the cursor, see T76794 */
UI_context_active_but_clear(C, win, CTX_wm_region(C));
WM_cursor_modal_set(win, WM_CURSOR_EYEDROPPER);
/* add temp handler */
WM_event_add_modal_handler(C, op);

View File

@ -180,7 +180,10 @@ static int driverdropper_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS
{
/* init */
if (driverdropper_init(C, op)) {
WM_cursor_modal_set(CTX_wm_window(C), WM_CURSOR_EYEDROPPER);
wmWindow *win = CTX_wm_window(C);
/* Workaround for de-activating the button clearing the cursor, see T76794 */
UI_context_active_but_clear(C, win, CTX_wm_region(C));
WM_cursor_modal_set(win, WM_CURSOR_EYEDROPPER);
/* add temp handler */
WM_event_add_modal_handler(C, op);

View File

@ -8276,6 +8276,11 @@ void UI_context_active_but_prop_handle(bContext *C)
}
}
void UI_context_active_but_clear(bContext *C, wmWindow *win, ARegion *region)
{
wm_event_handler_ui_cancel_ex(C, win, region, false);
}
wmOperator *UI_context_active_operator_get(const struct bContext *C)
{
ARegion *region_ctx = CTX_wm_region(C);
@ -8807,7 +8812,7 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
if (post_but) {
button_activate_init(C, region, post_but, post_type);
}
else {
else if (!((event->type == EVT_BUT_CANCEL) && (event->val == 1))) {
/* XXX issue is because WM_event_add_mousemove(wm) is a bad hack and not reliable,
* if that gets coded better this bypass can go away too.
*

View File

@ -640,11 +640,11 @@ static int wm_handler_ui_call(bContext *C,
return WM_HANDLER_CONTINUE;
}
static void wm_handler_ui_cancel(bContext *C)
void wm_event_handler_ui_cancel_ex(bContext *C,
wmWindow *win,
ARegion *region,
bool reactivate_button)
{
wmWindow *win = CTX_wm_window(C);
ARegion *region = CTX_wm_region(C);
if (!region) {
return;
}
@ -656,11 +656,19 @@ static void wm_handler_ui_cancel(bContext *C)
wmEvent event;
wm_event_init_from_window(win, &event);
event.type = EVT_BUT_CANCEL;
event.val = reactivate_button ? 0 : 1;
handler->handle_fn(C, &event, handler->user_data);
}
}
}
static void wm_event_handler_ui_cancel(bContext *C)
{
wmWindow *win = CTX_wm_window(C);
ARegion *region = CTX_wm_region(C);
wm_event_handler_ui_cancel_ex(C, win, region, true);
}
/** \} */
/* -------------------------------------------------------------------- */
@ -1365,7 +1373,7 @@ static int wm_operator_invoke(bContext *C,
* while dragging the view or worse, that stay there permanently
* after the modal operator has swallowed all events and passed
* none to the UI handler */
wm_handler_ui_cancel(C);
wm_event_handler_ui_cancel(C);
}
else {
WM_operator_free(op);

View File

@ -149,6 +149,11 @@ void wm_event_do_depsgraph(bContext *C, bool is_after_open_file);
void wm_event_do_refresh_wm_and_depsgraph(bContext *C);
void wm_event_do_notifiers(bContext *C);
void wm_event_handler_ui_cancel_ex(bContext *C,
wmWindow *win,
ARegion *region,
bool reactivate_button);
/* wm_event_query.c */
float wm_pressure_curve(float raw_pressure);
void wm_tablet_data_from_ghost(const struct GHOST_TabletData *tablet_data, wmTabletData *wmtab);

View File

@ -333,6 +333,7 @@ enum {
EVT_BUT_OPEN = 0x5021, /* 20513 */
EVT_MODAL_MAP = 0x5022, /* 20514 */
EVT_DROP = 0x5023, /* 20515 */
/* When value is 0, re-activate, when 1, don't re-activate the button under the cursor. */
EVT_BUT_CANCEL = 0x5024, /* 20516 */
/* could become gizmo callback */