diff options
Diffstat (limited to 'source/blender/windowmanager/intern')
-rw-r--r-- | source/blender/windowmanager/intern/wm.c | 10 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_cursors.c | 6 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_dragdrop.c | 19 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_query.c | 31 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.cc | 107 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_files.c | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_init_exit.c | 29 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_playanim.c | 11 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_window.c | 38 |
10 files changed, 174 insertions, 81 deletions
diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index 40d9b0b9a35..0d74bc259f4 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -81,6 +81,8 @@ static void window_manager_foreach_id(ID *id, LibraryForeachIDData *data) if (BKE_lib_query_foreachid_iter_stop(data)) { return; } + + BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, win->unpinned_scene, IDWALK_CB_NOP); } if (BKE_lib_query_foreachid_process_flags_get(data) & IDWALK_INCLUDE_UI) { @@ -224,6 +226,7 @@ static void lib_link_workspace_instance_hook(BlendLibReader *reader, { WorkSpace *workspace = BKE_workspace_active_get(hook); BLO_read_id_address(reader, id->lib, &workspace); + BKE_workspace_active_set(hook, workspace); } @@ -239,6 +242,11 @@ static void window_manager_blend_read_lib(BlendLibReader *reader, ID *id) /* deprecated, but needed for versioning (will be NULL'ed then) */ BLO_read_id_address(reader, NULL, &win->screen); + /* The unpinned scene is a UI->Scene-data pointer, and should be NULL'ed on linking (like + * WorkSpace.pin_scene). But the WindowManager ID (owning the window) is never linked. */ + BLI_assert(!ID_IS_LINKED(id)); + BLO_read_id_address(reader, id->lib, &win->unpinned_scene); + LISTBASE_FOREACH (ScrArea *, area, &win->global_areas.areabase) { BKE_screen_area_blend_read_lib(reader, &wm->id, area); } @@ -249,7 +257,7 @@ static void window_manager_blend_read_lib(BlendLibReader *reader, ID *id) IDTypeInfo IDType_ID_WM = { .id_code = ID_WM, - .id_filter = 0, + .id_filter = FILTER_ID_WM, .main_listbase_index = INDEX_ID_WM, .struct_size = sizeof(wmWindowManager), .name = "WindowManager", diff --git a/source/blender/windowmanager/intern/wm_cursors.c b/source/blender/windowmanager/intern/wm_cursors.c index 54636cb57ec..43be87fce39 100644 --- a/source/blender/windowmanager/intern/wm_cursors.c +++ b/source/blender/windowmanager/intern/wm_cursors.c @@ -231,8 +231,8 @@ void WM_cursor_grab_enable(wmWindow *win, int wrap, bool hide, int bounds[4]) GHOST_TAxisFlag mode_axis = GHOST_kAxisX | GHOST_kAxisY; if (bounds) { - wm_cursor_position_to_ghost(win, &bounds[0], &bounds[1]); - wm_cursor_position_to_ghost(win, &bounds[2], &bounds[3]); + wm_cursor_position_to_ghost_screen_coords(win, &bounds[0], &bounds[1]); + wm_cursor_position_to_ghost_screen_coords(win, &bounds[2], &bounds[3]); } if (hide) { @@ -266,7 +266,7 @@ void WM_cursor_grab_disable(wmWindow *win, const int mouse_ungrab_xy[2]) if (win && win->ghostwin) { if (mouse_ungrab_xy) { int mouse_xy[2] = {mouse_ungrab_xy[0], mouse_ungrab_xy[1]}; - wm_cursor_position_to_ghost(win, &mouse_xy[0], &mouse_xy[1]); + wm_cursor_position_to_ghost_screen_coords(win, &mouse_xy[0], &mouse_xy[1]); GHOST_SetCursorGrab(win->ghostwin, GHOST_kGrabDisable, GHOST_kAxisNone, NULL, mouse_xy); } else { diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c index 546ba795892..36bd69a9b25 100644 --- a/source/blender/windowmanager/intern/wm_dragdrop.c +++ b/source/blender/windowmanager/intern/wm_dragdrop.c @@ -175,16 +175,14 @@ static void wm_dropbox_invoke(bContext *C, wmDrag *drag) } } -wmDrag *WM_event_start_drag( +wmDrag *WM_drag_data_create( struct bContext *C, int icon, int type, void *poin, double value, unsigned int flags) { - wmWindowManager *wm = CTX_wm_manager(C); wmDrag *drag = MEM_callocN(sizeof(struct wmDrag), "new drag"); /* Keep track of future multi-touch drag too, add a mouse-pointer id or so. */ /* if multiple drags are added, they're drawn as list */ - BLI_addtail(&wm->drags, drag); drag->flags = flags; drag->icon = icon; drag->type = type; @@ -226,9 +224,22 @@ wmDrag *WM_event_start_drag( } drag->value = value; + return drag; +} + +void WM_event_start_prepared_drag(bContext *C, wmDrag *drag) +{ + wmWindowManager *wm = CTX_wm_manager(C); + + BLI_addtail(&wm->drags, drag); wm_dropbox_invoke(C, drag); +} - return drag; +void WM_event_start_drag( + struct bContext *C, int icon, int type, void *poin, double value, unsigned int flags) +{ + wmDrag *drag = WM_drag_data_create(C, icon, type, poin, value, flags); + WM_event_start_prepared_drag(C, drag); } void wm_drags_exit(wmWindowManager *wm, wmWindow *win) diff --git a/source/blender/windowmanager/intern/wm_event_query.c b/source/blender/windowmanager/intern/wm_event_query.c index b732bc91569..a1d94c33f27 100644 --- a/source/blender/windowmanager/intern/wm_event_query.c +++ b/source/blender/windowmanager/intern/wm_event_query.c @@ -112,7 +112,7 @@ void WM_event_print(const wmEvent *event) "wmEvent type:%d/%s, val:%d/%s, " "prev_type:%d/%s, prev_val:%d/%s, " "modifier=%s, keymodifier:%d, flag:%s, " - "mouse:(%d,%d), ascii:'%c', utf8:'%.*s', pointer:%p", + "mouse:(%d,%d), utf8:'%.*s', pointer:%p", event->type, type_id, event->val, @@ -126,7 +126,6 @@ void WM_event_print(const wmEvent *event) flag_id, event->xy[0], event->xy[1], - event->ascii, BLI_str_utf8_size(event->utf8_buf), event->utf8_buf, (const void *)event); @@ -254,16 +253,6 @@ bool WM_event_is_modal_drag_exit(const wmEvent *event, return 0; } -bool WM_event_is_last_mousemove(const wmEvent *event) -{ - while ((event = event->next)) { - if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { - return false; - } - } - return true; -} - bool WM_event_is_mouse_drag(const wmEvent *event) { return (ISMOUSE_BUTTON(event->type) && (event->val == KM_CLICK_DRAG)); @@ -357,8 +346,8 @@ bool WM_cursor_test_motion_and_update(const int mval[2]) int WM_event_drag_threshold(const struct wmEvent *event) { int drag_threshold; - if (ISMOUSE(event->prev_press_type)) { - BLI_assert(event->prev_press_type != MOUSEMOVE); + BLI_assert(event->prev_press_type != MOUSEMOVE); + if (ISMOUSE_BUTTON(event->prev_press_type)) { /* Using the previous type is important is we want to check the last pressed/released button, * The `event->type` would include #MOUSEMOVE which is always the case when dragging * and does not help us know which threshold to use. */ @@ -411,6 +400,20 @@ void WM_event_drag_start_xy(const wmEvent *event, int r_xy[2]) /** \} */ /* -------------------------------------------------------------------- */ +/** \name Event Text Queries + * \{ */ + +char WM_event_utf8_to_ascii(const struct wmEvent *event) +{ + if (BLI_str_utf8_size(event->utf8_buf) == 1) { + return event->utf8_buf[0]; + } + return '\0'; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ /** \name Event Preference Mapping * \{ */ diff --git a/source/blender/windowmanager/intern/wm_event_system.cc b/source/blender/windowmanager/intern/wm_event_system.cc index 51486f664c7..102441f1b4d 100644 --- a/source/blender/windowmanager/intern/wm_event_system.cc +++ b/source/blender/windowmanager/intern/wm_event_system.cc @@ -190,7 +190,7 @@ void wm_event_free(wmEvent *event) printf("%s: 'is_repeat=true' for non-keyboard event, this should not happen.\n", __func__); WM_event_print(event); } - if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE) && (event->val != KM_NOTHING)) { + if (ISMOUSE_MOTION(event->type) && (event->val != KM_NOTHING)) { printf("%s: 'val != NOTHING' for a cursor motion event, this should not happen.\n", __func__); WM_event_print(event); } @@ -1378,22 +1378,20 @@ static int wm_operator_invoke(bContext *C, } if (op->type->invoke && event) { - /* Temporarily write into `mval` (not technically `const` correct) but this is restored. */ - const int mval_prev[2] = {UNPACK2(event->mval)}; - wm_region_mouse_co(C, (wmEvent *)event); + /* Make a copy of the event as it's `const` and the #wmEvent.mval to be written into. */ + wmEvent event_temp = *event; + wm_region_mouse_co(C, &event_temp); if (op->type->flag & OPTYPE_UNDO) { wm->op_undo_depth++; } - retval = op->type->invoke(C, op, event); + retval = op->type->invoke(C, op, &event_temp); OPERATOR_RETVAL_CHECK(retval); if (op->type->flag & OPTYPE_UNDO && CTX_wm_manager(C) == wm) { wm->op_undo_depth--; } - - copy_v2_v2_int(((wmEvent *)event)->mval, mval_prev); } else if (op->type->exec) { if (op->type->flag & OPTYPE_UNDO) { @@ -2088,9 +2086,7 @@ static bool wm_eventmatch(const wmEvent *winevent, const wmKeyMapItem *kmi) /* The matching rules. */ if (kmitype == KM_TEXTINPUT) { if (winevent->val == KM_PRESS) { /* Prevent double clicks. */ - /* Not using #ISTEXTINPUT anymore because (at least on Windows) some key codes above 255 - * could have printable ascii keys, See T30479. */ - if (ISKEYBOARD(winevent->type) && (winevent->ascii || winevent->utf8_buf[0])) { + if (ISKEYBOARD(winevent->type) && winevent->utf8_buf[0]) { return true; } } @@ -2355,7 +2351,7 @@ static int wm_handler_operator_call(bContext *C, } } - /* Important to run 'wm_operator_finished' before nullptr-ing the context members. */ + /* Important to run 'wm_operator_finished' before setting the context members to null. */ if (retval & OPERATOR_FINISHED) { wm_operator_finished(C, op, false, true); handler->op = nullptr; @@ -3099,7 +3095,7 @@ static int wm_handlers_do_intern(bContext *C, wmWindow *win, wmEvent *event, Lis const bool do_debug_handler = (G.debug & G_DEBUG_HANDLERS) && /* Comment this out to flood the console! (if you really want to test). */ - !ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE); + !ISMOUSE_MOTION(event->type); wmWindowManager *wm = CTX_wm_manager(C); int action = WM_HANDLER_CONTINUE; @@ -3290,7 +3286,7 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers) return action; } - if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { + if (ISMOUSE_MOTION(event->type)) { /* Test for #KM_CLICK_DRAG events. */ /* NOTE(@campbellbarton): Needed so drag can be used for editors that support both click @@ -3825,15 +3821,14 @@ void wm_event_do_handlers(bContext *C) /* Active screen might change during handlers, update pointer. */ screen = WM_window_get_active_screen(win); - if (G.debug & (G_DEBUG_HANDLERS | G_DEBUG_EVENTS) && - !ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { + if (G.debug & (G_DEBUG_HANDLERS | G_DEBUG_EVENTS) && !ISMOUSE_MOTION(event->type)) { printf("\n%s: Handling event\n", __func__); WM_event_print(event); } /* Take care of pie event filter. */ if (wm_event_pie_filter(win, event)) { - if (!ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { + if (!ISMOUSE_MOTION(event->type)) { CLOG_INFO(WM_LOG_HANDLERS, 1, "event filtered due to pie button pressed"); } BLI_remlink(&win->event_queue, event); @@ -3855,7 +3850,7 @@ void wm_event_do_handlers(bContext *C) /* Clear tool-tip on mouse move. */ if (screen->tool_tip && screen->tool_tip->exit_on_event) { - if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { + if (ISMOUSE_MOTION(event->type)) { if (len_manhattan_v2v2_int(screen->tool_tip->event_xy, event->xy) > WM_EVENT_CURSOR_MOTION_THRESHOLD) { WM_tooltip_clear(C, win); @@ -4979,7 +4974,7 @@ static bool wm_event_is_double_click(const wmEvent *event) { if ((event->type == event->prev_type) && (event->prev_val == KM_RELEASE) && (event->val == KM_PRESS)) { - if (ISMOUSE(event->type) && WM_event_drag_test(event, event->prev_press_xy)) { + if (ISMOUSE_BUTTON(event->type) && WM_event_drag_test(event, event->prev_press_xy)) { /* Pass. */ } else { @@ -5044,7 +5039,6 @@ static wmEvent *wm_event_add_mousemove_to_head(wmWindow *win) tevent = *event_last; tevent.flag = (eWM_EventFlag)0; - tevent.ascii = '\0'; tevent.utf8_buf[0] = '\0'; wm_event_custom_clear(&tevent); @@ -5138,6 +5132,53 @@ static void wm_event_state_update_and_click_set(wmEvent *event, wm_event_state_update_and_click_set_ex(event, event_state, is_keyboard, check_double_click); } +/* Returns true when the two events corresponds to a press of the same key with the same modifiers. + */ +static bool wm_event_is_same_key_press(const wmEvent &event_a, const wmEvent &event_b) +{ + if (event_a.val != KM_PRESS || event_b.val != KM_PRESS) { + return false; + } + + if (event_a.modifier != event_b.modifier || event_a.type != event_b.type) { + return false; + } + + return true; +} + +/** + * Returns true if the event is a key press event which is to be ignored and not added to the event + * queue. + * + * A key press event will be ignored if there is already matched key press in the queue. + * This avoids the event queue "clogging" in the situations when there is an operator bound to a + * key press event and the execution time of the operator is longer than the key repeat. + */ +static bool wm_event_is_ignorable_key_press(const wmWindow *win, const wmEvent &event) +{ + if (BLI_listbase_is_empty(&win->event_queue)) { + /* If the queue is empty never ignore the event. + * Empty queue at this point means that the events are handled fast enough, and there is no + * reason to ignore anything. */ + return false; + } + + if ((event.flag & WM_EVENT_IS_REPEAT) == 0) { + /* Only ignore repeat events from the keyboard, and allow accumulation of non-repeat events. + * + * The goal of this check is to allow events coming from a keyboard macro software, which can + * generate events quicker than the main loop handles them. In this case we want all events to + * be handled (unless the keyboard macro software tags them as repeat) because otherwise it + * will become impossible to get reliable results of automated events testing. */ + return false; + } + + const wmEvent &last_event = *reinterpret_cast<const wmEvent *>(win->event_queue.last); + + return wm_event_is_same_key_press(last_event, event); +} + void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void *customdata) { if (UNLIKELY(G.f & G_FLAG_EVENT_SIMULATE)) { @@ -5331,8 +5372,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void break; } - event.ascii = kd->ascii; - /* Might be not nullptr terminated. */ + /* Might be not null terminated. */ memcpy(event.utf8_buf, kd->utf8_buf, sizeof(event.utf8_buf)); if (kd->is_repeat) { event.flag |= WM_EVENT_IS_REPEAT; @@ -5343,8 +5383,6 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void /* Exclude arrow keys, escape, etc from text input. */ if (type == GHOST_kEventKeyUp) { - event.ascii = '\0'; - /* Ghost should do this already for key up. */ if (event.utf8_buf[0]) { CLOG_ERROR(WM_LOG_EVENTS, @@ -5353,15 +5391,28 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void event.utf8_buf[0] = '\0'; } else { - if (event.ascii < 32 && event.ascii > 0) { - event.ascii = '\0'; - } if (event.utf8_buf[0] < 32 && event.utf8_buf[0] > 0) { event.utf8_buf[0] = '\0'; } } if (event.utf8_buf[0]) { + /* NOTE(@campbellbarton): Detect non-ASCII characters stored in `utf8_buf`, + * ideally this would never happen but it can't be ruled out for X11 which has + * special handling of Latin1 when building without UTF8 support. + * Avoid regressions by adding this conversions, it should eventually be removed. */ + if ((event.utf8_buf[0] >= 0x80) && (event.utf8_buf[1] == '\0')) { + const uint c = (uint)event.utf8_buf[0]; + int utf8_buf_len = BLI_str_utf8_from_unicode(c, event.utf8_buf, sizeof(event.utf8_buf)); + CLOG_ERROR(WM_LOG_EVENTS, + "ghost detected non-ASCII single byte character '%u', converting to utf8 " + "('%.*s', length=%d)", + c, + utf8_buf_len, + event.utf8_buf, + utf8_buf_len); + } + if (BLI_str_utf8_size(event.utf8_buf) == -1) { CLOG_ERROR(WM_LOG_EVENTS, "ghost detected an invalid unicode character '%d'", @@ -5434,7 +5485,9 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void G.is_break = true; } - wm_event_add(win, &event); + if (!wm_event_is_ignorable_key_press(win, event)) { + wm_event_add(win, &event); + } break; } diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 5f4c39e33f7..a4d5bed21da 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -3063,7 +3063,7 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op) Main *bmain = CTX_data_main(C); char path[FILE_MAX]; const bool is_save_as = (op->type->invoke == wm_save_as_mainfile_invoke); - const bool use_save_as_copy = RNA_boolean_get(op->ptr, "copy"); + const bool use_save_as_copy = is_save_as && RNA_boolean_get(op->ptr, "copy"); /* We could expose all options to the users however in most cases remapping * existing relative paths is a good default. diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 252cfc6e143..7f5ec77e16d 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -169,6 +169,10 @@ void WM_init_opengl(void) wm_ghost_init(NULL); } + if (!GPU_backend_supported()) { + return; + } + /* Needs to be first to have an OpenGL context bound. */ DRW_opengl_context_create(); @@ -572,14 +576,6 @@ void WM_exit_ex(bContext *C, const bool do_python) BLF_exit(); - if (opengl_is_init) { - DRW_opengl_context_enable_ex(false); - GPU_pass_cache_free(); - GPU_exit(); - DRW_opengl_context_disable_ex(false); - DRW_opengl_context_destroy(); - } - BLT_lang_free(); ANIM_keyingset_infos_exit(); @@ -604,13 +600,24 @@ void WM_exit_ex(bContext *C, const bool do_python) ED_file_exit(); /* for fsmenu */ - UI_exit(); + /* Delete GPU resources and context. The UI also uses GPU resources and so + * is also deleted with the context active. */ + if (opengl_is_init) { + DRW_opengl_context_enable_ex(false); + UI_exit(); + GPU_pass_cache_free(); + GPU_exit(); + DRW_opengl_context_disable_ex(false); + DRW_opengl_context_destroy(); + } + else { + UI_exit(); + } + BKE_blender_userdef_data_free(&U, false); RNA_exit(); /* should be after BPY_python_end so struct python slots are cleared */ - GPU_backend_exit(); - wm_ghost_exit(); CTX_free(C); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 33c69a23558..315e4c994ad 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -939,7 +939,7 @@ int WM_generic_select_modal(bContext *C, wmOperator *op, const wmEvent *event) return ret_value | OPERATOR_PASS_THROUGH; } - if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { + if (ISMOUSE_MOTION(event->type)) { const int drag_delta[2] = { mval[0] - event->mval[0], mval[1] - event->mval[1], diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c index baba64b2230..99f117f267a 100644 --- a/source/blender/windowmanager/intern/wm_playanim.c +++ b/source/blender/windowmanager/intern/wm_playanim.c @@ -1217,8 +1217,7 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void) GHOST_TEventButtonData *bd = GHOST_GetEventData(evt); int cx, cy, sizex, sizey, inside_window; - GHOST_GetCursorPosition(g_WS.ghost_system, &cx, &cy); - GHOST_ScreenToClient(g_WS.ghost_window, cx, cy, &cx, &cy); + GHOST_GetCursorPosition(g_WS.ghost_system, g_WS.ghost_window, &cx, &cy); playanim_window_get_size(&sizex, &sizey); inside_window = (cx >= 0 && cx < sizex && cy >= 0 && cy <= sizey); @@ -1267,15 +1266,15 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void) * however the API currently doesn't support this. */ { int x_test, y_test; - GHOST_GetCursorPosition(g_WS.ghost_system, &x_test, &y_test); - if (x_test != cd->x || y_test != cd->y) { + GHOST_GetCursorPosition(g_WS.ghost_system, g_WS.ghost_window, &cx, &cy); + GHOST_ScreenToClient(g_WS.ghost_window, cd->x, cd->y, &x_test, &y_test); + + if (cx != x_test || cy != y_test) { /* we're not the last event... skipping */ break; } } - GHOST_ScreenToClient(g_WS.ghost_window, cd->x, cd->y, &cx, &cy); - tag_change_frame(ps, cx); } break; diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index baf137e6665..d2182f759e5 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -920,25 +920,33 @@ int wm_window_fullscreen_toggle_exec(bContext *C, wmOperator *UNUSED(op)) /* ************ events *************** */ -void wm_cursor_position_from_ghost(wmWindow *win, int *x, int *y) +void wm_cursor_position_from_ghost_client_coords(wmWindow *win, int *x, int *y) { float fac = GHOST_GetNativePixelSize(win->ghostwin); - - GHOST_ScreenToClient(win->ghostwin, *x, *y, x, y); *x *= fac; *y = (win->sizey - 1) - *y; *y *= fac; } -void wm_cursor_position_to_ghost(wmWindow *win, int *x, int *y) +void wm_cursor_position_to_ghost_client_coords(wmWindow *win, int *x, int *y) { float fac = GHOST_GetNativePixelSize(win->ghostwin); *x /= fac; *y /= fac; *y = win->sizey - *y - 1; +} + +void wm_cursor_position_from_ghost_screen_coords(wmWindow *win, int *x, int *y) +{ + GHOST_ScreenToClient(win->ghostwin, *x, *y, x, y); + wm_cursor_position_from_ghost_client_coords(win, x, y); +} +void wm_cursor_position_to_ghost_screen_coords(wmWindow *win, int *x, int *y) +{ + wm_cursor_position_to_ghost_client_coords(win, x, y); GHOST_ClientToScreen(win->ghostwin, *x, *y, x, y); } @@ -949,8 +957,8 @@ void wm_cursor_position_get(wmWindow *win, int *r_x, int *r_y) *r_y = win->eventstate->xy[1]; return; } - GHOST_GetCursorPosition(g_system, r_x, r_y); - wm_cursor_position_from_ghost(win, r_x, r_y); + GHOST_GetCursorPosition(g_system, win->ghostwin, r_x, r_y); + wm_cursor_position_from_ghost_client_coords(win, r_x, r_y); } typedef enum { @@ -1140,7 +1148,6 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_pt */ GHOST_TEventKeyData kdata = { .key = GHOST_kKeyUnknown, - .ascii = '\0', .utf8_buf = {'\0'}, .is_repeat = false, }; @@ -1355,6 +1362,11 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_pt event.type = MOUSEMOVE; 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; + event.flag = 0; /* No context change! C->wm->windrawable is drawable, or for area queues. */ @@ -1418,14 +1430,14 @@ static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_pt case GHOST_kEventTrackpad: { GHOST_TEventTrackpadData *pd = data; - wm_cursor_position_from_ghost(win, &pd->x, &pd->y); + 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 = data; - wm_cursor_position_from_ghost(win, &cd->x, &cd->y); + wm_cursor_position_from_ghost_screen_coords(win, &cd->x, &cd->y); wm_event_add_ghostevent(wm, win, type, data); break; } @@ -1866,7 +1878,7 @@ wmWindow *WM_window_find_under_cursor(wmWindow *win, const int mval[2], int r_mv { int tmp[2]; copy_v2_v2_int(tmp, mval); - wm_cursor_position_to_ghost(win, &tmp[0], &tmp[1]); + wm_cursor_position_to_ghost_screen_coords(win, &tmp[0], &tmp[1]); GHOST_WindowHandle ghostwin = GHOST_GetWindowUnderCursor(g_system, tmp[0], tmp[1]); @@ -1875,7 +1887,7 @@ wmWindow *WM_window_find_under_cursor(wmWindow *win, const int mval[2], int r_mv } wmWindow *win_other = GHOST_GetWindowUserData(ghostwin); - wm_cursor_position_from_ghost(win_other, &tmp[0], &tmp[1]); + wm_cursor_position_from_ghost_screen_coords(win_other, &tmp[0], &tmp[1]); copy_v2_v2_int(r_mval, tmp); return win_other; } @@ -2015,8 +2027,8 @@ void WM_cursor_warp(wmWindow *win, int x, int y) if (win && win->ghostwin) { int oldx = x, oldy = y; - wm_cursor_position_to_ghost(win, &x, &y); - GHOST_SetCursorPosition(g_system, x, y); + wm_cursor_position_to_ghost_client_coords(win, &x, &y); + GHOST_SetCursorPosition(g_system, win->ghostwin, x, y); win->eventstate->prev_xy[0] = oldx; win->eventstate->prev_xy[1] = oldy; |