mirror of
https://github.com/glfw/glfw.git
synced 2024-12-01 22:37:12 +00:00
Merge branch 'glfw:master' into taskbar-progress
This commit is contained in:
commit
e597552e75
@ -385,6 +385,7 @@ information on what to include when reporting a bug.
|
|||||||
decorations
|
decorations
|
||||||
- [Wayland] Bugfix: Connecting a mouse after `glfwInit` would segfault (#1450)
|
- [Wayland] Bugfix: Connecting a mouse after `glfwInit` would segfault (#1450)
|
||||||
- [Wayland] Bugfix: Joysticks connected after `glfwInit` were not detected (#2198)
|
- [Wayland] Bugfix: Joysticks connected after `glfwInit` were not detected (#2198)
|
||||||
|
- [Wayland] Bugfix: Fallback decorations emitted `GLFW_CURSOR_UNAVAILABLE` errors
|
||||||
- [POSIX] Removed use of deprecated function `gettimeofday`
|
- [POSIX] Removed use of deprecated function `gettimeofday`
|
||||||
- [POSIX] Bugfix: `CLOCK_MONOTONIC` was not correctly tested for or enabled
|
- [POSIX] Bugfix: `CLOCK_MONOTONIC` was not correctly tested for or enabled
|
||||||
- [Linux] Bugfix: Joysticks without buttons were ignored (#2042,#2043)
|
- [Linux] Bugfix: Joysticks without buttons were ignored (#2042,#2043)
|
||||||
|
138
src/wl_window.c
138
src/wl_window.c
@ -1308,11 +1308,64 @@ static void pointerHandleLeave(void* userData,
|
|||||||
_glfwInputCursorEnter(window, GLFW_FALSE);
|
_glfwInputCursorEnter(window, GLFW_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setCursor(_GLFWwindow* window, const char* name)
|
static void pointerHandleMotion(void* userData,
|
||||||
|
struct wl_pointer* pointer,
|
||||||
|
uint32_t time,
|
||||||
|
wl_fixed_t sx,
|
||||||
|
wl_fixed_t sy)
|
||||||
|
{
|
||||||
|
_GLFWwindow* window = _glfw.wl.pointerFocus;
|
||||||
|
if (!window)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const double xpos = wl_fixed_to_double(sx);
|
||||||
|
const double ypos = wl_fixed_to_double(sy);
|
||||||
|
window->wl.cursorPosX = xpos;
|
||||||
|
window->wl.cursorPosY = ypos;
|
||||||
|
|
||||||
|
const char* cursorName = NULL;
|
||||||
|
|
||||||
|
switch (window->wl.decorations.focus)
|
||||||
|
{
|
||||||
|
case GLFW_MAIN_WINDOW:
|
||||||
|
_glfw.wl.cursorPreviousName = NULL;
|
||||||
|
_glfwInputCursorPos(window, xpos, ypos);
|
||||||
|
return;
|
||||||
|
case GLFW_TOP_DECORATION:
|
||||||
|
if (ypos < GLFW_BORDER_SIZE)
|
||||||
|
cursorName = "n-resize";
|
||||||
|
else
|
||||||
|
cursorName = "left_ptr";
|
||||||
|
break;
|
||||||
|
case GLFW_LEFT_DECORATION:
|
||||||
|
if (ypos < GLFW_BORDER_SIZE)
|
||||||
|
cursorName = "nw-resize";
|
||||||
|
else
|
||||||
|
cursorName = "w-resize";
|
||||||
|
break;
|
||||||
|
case GLFW_RIGHT_DECORATION:
|
||||||
|
if (ypos < GLFW_BORDER_SIZE)
|
||||||
|
cursorName = "ne-resize";
|
||||||
|
else
|
||||||
|
cursorName = "e-resize";
|
||||||
|
break;
|
||||||
|
case GLFW_BOTTOM_DECORATION:
|
||||||
|
if (xpos < GLFW_BORDER_SIZE)
|
||||||
|
cursorName = "sw-resize";
|
||||||
|
else if (xpos > window->wl.width + GLFW_BORDER_SIZE)
|
||||||
|
cursorName = "se-resize";
|
||||||
|
else
|
||||||
|
cursorName = "s-resize";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_glfw.wl.cursorPreviousName != cursorName)
|
||||||
{
|
{
|
||||||
struct wl_buffer* buffer;
|
|
||||||
struct wl_cursor* cursor;
|
|
||||||
struct wl_cursor_image* image;
|
|
||||||
struct wl_surface* surface = _glfw.wl.cursorSurface;
|
struct wl_surface* surface = _glfw.wl.cursorSurface;
|
||||||
struct wl_cursor_theme* theme = _glfw.wl.cursorTheme;
|
struct wl_cursor_theme* theme = _glfw.wl.cursorTheme;
|
||||||
int scale = 1;
|
int scale = 1;
|
||||||
@ -1325,91 +1378,30 @@ static void setCursor(_GLFWwindow* window, const char* name)
|
|||||||
theme = _glfw.wl.cursorThemeHiDPI;
|
theme = _glfw.wl.cursorThemeHiDPI;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor = wl_cursor_theme_get_cursor(theme, name);
|
struct wl_cursor* cursor = wl_cursor_theme_get_cursor(theme, cursorName);
|
||||||
if (!cursor)
|
if (!cursor)
|
||||||
{
|
|
||||||
_glfwInputError(GLFW_CURSOR_UNAVAILABLE,
|
|
||||||
"Wayland: Standard cursor shape unavailable");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
// TODO: handle animated cursors too.
|
|
||||||
image = cursor->images[0];
|
|
||||||
|
|
||||||
|
// TODO: handle animated cursors too.
|
||||||
|
struct wl_cursor_image* image = cursor->images[0];
|
||||||
if (!image)
|
if (!image)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
buffer = wl_cursor_image_get_buffer(image);
|
struct wl_buffer* buffer = wl_cursor_image_get_buffer(image);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wl_pointer_set_cursor(_glfw.wl.pointer, _glfw.wl.pointerEnterSerial,
|
wl_pointer_set_cursor(_glfw.wl.pointer, _glfw.wl.pointerEnterSerial,
|
||||||
surface,
|
surface,
|
||||||
image->hotspot_x / scale,
|
image->hotspot_x / scale,
|
||||||
image->hotspot_y / scale);
|
image->hotspot_y / scale);
|
||||||
wl_surface_set_buffer_scale(surface, scale);
|
wl_surface_set_buffer_scale(surface, scale);
|
||||||
wl_surface_attach(surface, buffer, 0, 0);
|
wl_surface_attach(surface, buffer, 0, 0);
|
||||||
wl_surface_damage(surface, 0, 0,
|
wl_surface_damage(surface, 0, 0, image->width, image->height);
|
||||||
image->width, image->height);
|
|
||||||
wl_surface_commit(surface);
|
wl_surface_commit(surface);
|
||||||
_glfw.wl.cursorPreviousName = name;
|
|
||||||
|
_glfw.wl.cursorPreviousName = cursorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pointerHandleMotion(void* userData,
|
|
||||||
struct wl_pointer* pointer,
|
|
||||||
uint32_t time,
|
|
||||||
wl_fixed_t sx,
|
|
||||||
wl_fixed_t sy)
|
|
||||||
{
|
|
||||||
_GLFWwindow* window = _glfw.wl.pointerFocus;
|
|
||||||
const char* cursorName = NULL;
|
|
||||||
double x, y;
|
|
||||||
|
|
||||||
if (!window)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
|
||||||
return;
|
|
||||||
x = wl_fixed_to_double(sx);
|
|
||||||
y = wl_fixed_to_double(sy);
|
|
||||||
window->wl.cursorPosX = x;
|
|
||||||
window->wl.cursorPosY = y;
|
|
||||||
|
|
||||||
switch (window->wl.decorations.focus)
|
|
||||||
{
|
|
||||||
case GLFW_MAIN_WINDOW:
|
|
||||||
_glfw.wl.cursorPreviousName = NULL;
|
|
||||||
_glfwInputCursorPos(window, x, y);
|
|
||||||
return;
|
|
||||||
case GLFW_TOP_DECORATION:
|
|
||||||
if (y < GLFW_BORDER_SIZE)
|
|
||||||
cursorName = "n-resize";
|
|
||||||
else
|
|
||||||
cursorName = "left_ptr";
|
|
||||||
break;
|
|
||||||
case GLFW_LEFT_DECORATION:
|
|
||||||
if (y < GLFW_BORDER_SIZE)
|
|
||||||
cursorName = "nw-resize";
|
|
||||||
else
|
|
||||||
cursorName = "w-resize";
|
|
||||||
break;
|
|
||||||
case GLFW_RIGHT_DECORATION:
|
|
||||||
if (y < GLFW_BORDER_SIZE)
|
|
||||||
cursorName = "ne-resize";
|
|
||||||
else
|
|
||||||
cursorName = "e-resize";
|
|
||||||
break;
|
|
||||||
case GLFW_BOTTOM_DECORATION:
|
|
||||||
if (x < GLFW_BORDER_SIZE)
|
|
||||||
cursorName = "sw-resize";
|
|
||||||
else if (x > window->wl.width + GLFW_BORDER_SIZE)
|
|
||||||
cursorName = "se-resize";
|
|
||||||
else
|
|
||||||
cursorName = "s-resize";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert(0);
|
|
||||||
}
|
|
||||||
if (_glfw.wl.cursorPreviousName != cursorName)
|
|
||||||
setCursor(window, cursorName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pointerHandleButton(void* userData,
|
static void pointerHandleButton(void* userData,
|
||||||
|
Loading…
Reference in New Issue
Block a user