Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-06-30 15:53:20 +0300
committerCampbell Barton <campbell@blender.org>2022-06-30 16:46:57 +0300
commit6bd2c6789b244a03bccdb254502567691c42b944 (patch)
tree264949e98f2d99a91e9a393c0cd3478ef1701a77 /source/blender/windowmanager/intern/wm_window.c
parentdf40e9d0aad0c2a5b649d99c25e991a3664501c5 (diff)
GHOST: get/set cursor position now uses client instead of screen coords
Use client (window) relative coordinates for cursor position access, this only moves the conversion from window-manager into GHOST, (no functional changes). This is needed for fix a bug in GHOST/Wayland which doesn't support accessing absolute cursor coordinates & the window is needed to properly access the cursor coordinates. As it happens every caller to GHOST_GetCursorPosition was already making the values window-relative, so there is little benefit in attempting to workaround the problem on the Wayland side. If needed the screen-space versions of functions can be exposed again.
Diffstat (limited to 'source/blender/windowmanager/intern/wm_window.c')
-rw-r--r--source/blender/windowmanager/intern/wm_window.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index baf137e6665..36f91f8414a 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 {
@@ -1418,14 +1426,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 +1874,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 +1883,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 +2023,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;