diff options
Diffstat (limited to 'source/blender/windowmanager/intern/wm_window.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_window.c | 77 |
1 files changed, 42 insertions, 35 deletions
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index c0427f9be9a..d2182f759e5 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -23,6 +23,7 @@ #include "BLI_blenlib.h" #include "BLI_math.h" +#include "BLI_system.h" #include "BLI_utildefines.h" #include "BLT_translation.h" @@ -919,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); } @@ -948,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 { @@ -962,7 +971,7 @@ typedef enum { /* check if specified modifier key type is pressed */ static int query_qual(modifierKeyType qual) { - GHOST_TModifierKeyMask left, right; + GHOST_TModifierKey left, right; switch (qual) { case SHIFT: left = GHOST_kModifierKeyLeftShift; @@ -982,7 +991,7 @@ static int query_qual(modifierKeyType qual) break; } - int val = 0; + bool val = false; GHOST_GetModifierKeyState(g_system, left, &val); if (!val) { GHOST_GetModifierKeyState(g_system, right, &val); @@ -1052,7 +1061,7 @@ void wm_window_reset_drawable(void) * * Mouse coordinate conversion happens here. */ -static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr) +static bool ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr) { bContext *C = C_void_ptr; wmWindowManager *wm = CTX_wm_manager(C); @@ -1090,17 +1099,17 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr * but it should return if WM didn't initialize yet. * Can happen on file read (especially full size window). */ if ((wm->initialized & WM_WINDOW_IS_INIT) == 0) { - return 1; + return true; } if (!ghostwin) { /* XXX: should be checked, why are we getting an event here, and what is it? */ puts("<!> event has no window"); - return 1; + return true; } if (!GHOST_ValidWindow(g_system, ghostwin)) { /* XXX: should be checked, why are we getting an event here, and what is it? */ puts("<!> event has invalid window"); - return 1; + return true; } wmWindow *win = GHOST_GetWindowUserData(ghostwin); @@ -1115,7 +1124,6 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr break; case GHOST_kEventWindowActivate: { - GHOST_TEventKeyData kdata; const int keymodifier = ((query_qual(SHIFT) ? KM_SHIFT : 0) | (query_qual(CONTROL) ? KM_CTRL : 0) | (query_qual(ALT) ? KM_ALT : 0) | (query_qual(OS) ? KM_OSKEY : 0)); @@ -1138,9 +1146,11 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr * * For now don't send GHOST_kEventKeyDown events, just set the 'eventstate'. */ - kdata.ascii = '\0'; - kdata.utf8_buf[0] = '\0'; - + GHOST_TEventKeyData kdata = { + .key = GHOST_kKeyUnknown, + .utf8_buf = {'\0'}, + .is_repeat = false, + }; if (win->eventstate->modifier & KM_SHIFT) { if ((keymodifier & KM_SHIFT) == 0) { kdata.key = GHOST_kKeyLeftShift; @@ -1352,6 +1362,11 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr 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. */ @@ -1415,14 +1430,14 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr 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; } @@ -1443,7 +1458,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr } } } - return 1; + return true; } /** @@ -1543,6 +1558,8 @@ void wm_ghost_init(bContext *C) consumer = GHOST_CreateEventConsumer(ghost_event_proc, C); } + GHOST_SetBacktraceHandler((GHOST_TBacktraceFn)BLI_system_backtrace); + g_system = GHOST_CreateSystem(); GHOST_Debug debug = {0}; @@ -1861,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]); @@ -1869,11 +1886,10 @@ wmWindow *WM_window_find_under_cursor(wmWindow *win, const int mval[2], int r_mv return NULL; } - wmWindow *r_win = GHOST_GetWindowUserData(ghostwin); - wm_cursor_position_from_ghost(r_win, &tmp[0], &tmp[1]); + wmWindow *win_other = GHOST_GetWindowUserData(ghostwin); + wm_cursor_position_from_ghost_screen_coords(win_other, &tmp[0], &tmp[1]); copy_v2_v2_int(r_mval, tmp); - - return r_win; + return win_other; } void WM_window_pixel_sample_read(const wmWindowManager *wm, @@ -2011,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; @@ -2022,15 +2038,6 @@ void WM_cursor_warp(wmWindow *win, int x, int y) } } -void WM_cursor_compatible_xy(wmWindow *win, int *x, int *y) -{ - float f = GHOST_GetNativePixelSize(win->ghostwin); - if (f != 1.0f) { - *x = (int)(*x / f) * f; - *y = (int)(*y / f) * f; - } -} - /** \} */ /* -------------------------------------------------------------------- */ |