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
path: root/source
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
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')
-rw-r--r--source/blender/windowmanager/intern/wm_cursors.c6
-rw-r--r--source/blender/windowmanager/intern/wm_playanim.c11
-rw-r--r--source/blender/windowmanager/intern/wm_window.c32
-rw-r--r--source/blender/windowmanager/wm_window.h7
4 files changed, 33 insertions, 23 deletions
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_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..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;
diff --git a/source/blender/windowmanager/wm_window.h b/source/blender/windowmanager/wm_window.h
index 67557768413..3644aa085f7 100644
--- a/source/blender/windowmanager/wm_window.h
+++ b/source/blender/windowmanager/wm_window.h
@@ -100,8 +100,11 @@ void wm_window_set_swap_interval(wmWindow *win, int interval);
bool wm_window_get_swap_interval(wmWindow *win, int *intervalOut);
void wm_cursor_position_get(wmWindow *win, int *r_x, int *r_y);
-void wm_cursor_position_from_ghost(wmWindow *win, int *r_x, int *r_y);
-void wm_cursor_position_to_ghost(wmWindow *win, int *x, int *y);
+void wm_cursor_position_from_ghost_screen_coords(wmWindow *win, int *r_x, int *r_y);
+void wm_cursor_position_to_ghost_screen_coords(wmWindow *win, int *x, int *y);
+
+void wm_cursor_position_from_ghost_client_coords(wmWindow *win, int *x, int *y);
+void wm_cursor_position_to_ghost_client_coords(wmWindow *win, int *x, int *y);
#ifdef WITH_INPUT_IME
void wm_window_IME_begin(wmWindow *win, int x, int y, int w, int h, bool complete);