This commit is contained in:
linkmauve 2019-04-17 00:56:25 +00:00 committed by GitHub
commit d0daffee2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 119 additions and 40 deletions

View File

@ -2536,8 +2536,8 @@ GLFWAPI void glfwWindowHintString(int hint, const char* value);
* instance a keybind mechanism. If neither of these protocols is supported,
* the window won't be decorated.
*
* @remark @wayland A full screen window will not attempt to change the mode,
* no matter what the requested size or refresh rate.
* @remark @wayland The wp_viewporter protocol is required for a full screen
* window to set the video mode, otherwise the current mode will be used.
*
* @remark @wayland Screensaver inhibition requires the idle-inhibit protocol
* to be implemented in the user's compositor.
@ -2904,8 +2904,8 @@ GLFWAPI void glfwSetWindowAspectRatio(GLFWwindow* window, int numer, int denom);
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_ERROR.
*
* @remark @wayland A full screen window will not attempt to change the mode,
* no matter what the requested size.
* @remark @wayland The wp_viewporter protocol is required for a full screen
* window to change the video mode, otherwise this function does nothing.
*
* @thread_safety This function must only be called from the main thread.
*
@ -3338,8 +3338,8 @@ GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* window);
* @remark @wayland The desired window position is ignored, as there is no way
* for an application to set this property.
*
* @remark @wayland Setting the window to full screen will not attempt to
* change the mode, no matter what the requested size or refresh rate.
* @remark @wayland The wp_viewporter protocol is required for a full screen
* window to set its video mode, otherwise the current mode will be used.
*
* @thread_safety This function must only be called from the main thread.
*

View File

@ -183,18 +183,17 @@ static void pointerHandleMotion(void* data,
if (window->cursorMode == GLFW_CURSOR_DISABLED)
return;
else
{
window->wl.cursorPosX = wl_fixed_to_double(sx);
window->wl.cursorPosY = wl_fixed_to_double(sy);
}
window->wl.cursorPosX = wl_fixed_to_double(sx) * window->wl.cursorScale;
window->wl.cursorPosY = wl_fixed_to_double(sy) * window->wl.cursorScale;
printf("cursor: %fx%f @%f\n", window->wl.cursorPosX, window->wl.cursorPosY, window->wl.cursorScale);
switch (window->wl.decorations.focus)
{
case mainWindow:
_glfwInputCursorPos(window,
wl_fixed_to_double(sx),
wl_fixed_to_double(sy));
window->wl.cursorPosX,
window->wl.cursorPosY);
return;
case topDecoration:
if (window->wl.cursorPosY < _GLFW_DECORATION_WIDTH)

View File

@ -191,6 +191,7 @@ typedef struct _GLFWwindowWayland
_GLFWcursor* currentCursor;
double cursorPosX, cursorPosY;
double cursorScale;
char* title;
@ -217,6 +218,8 @@ typedef struct _GLFWwindowWayland
int focus;
} decorations;
struct wp_viewport* viewport;
} _GLFWwindowWayland;
// Wayland-specific global data

View File

@ -46,6 +46,20 @@ static void shellSurfaceHandlePing(void* data,
wl_shell_surface_pong(shellSurface, serial);
}
static void resizeWindow(_GLFWwindow* window);
static void computeFullscreenSize(_GLFWwindow* window, float* width, float* height)
{
float aspectRatio = *width / *height;
float targetRatio = (float)window->wl.width / (float)window->wl.height;
if (aspectRatio < targetRatio)
*height = *width / targetRatio;
else if (aspectRatio > targetRatio)
*width = *height * targetRatio;
window->wl.cursorScale = (float)window->wl.width / *width;
}
static void shellSurfaceHandleConfigure(void* data,
struct wl_shell_surface* shellSurface,
uint32_t edges,
@ -56,6 +70,7 @@ static void shellSurfaceHandleConfigure(void* data,
float aspectRatio;
float targetRatio;
printf("before: configure=%dx%d window->wl=%dx%d videoMode=%dx%d\n", width, height, window->wl.width, window->wl.height, window->videoMode.width, window->videoMode.height);
if (!window->monitor)
{
if (_glfw.wl.viewporter && window->decorated)
@ -87,10 +102,23 @@ static void shellSurfaceHandleConfigure(void* data,
height = window->minheight;
else if (window->maxheight != GLFW_DONT_CARE && height > window->maxheight)
height = window->maxheight;
window->wl.cursorScale = 1.0;
window->wl.width = width;
window->wl.height = height;
resizeWindow(window);
}
else if (window->wl.viewport)
{
float floatWidth = width, floatHeight = height;
computeFullscreenSize(window, &floatWidth, &floatHeight);
width = floatWidth;
height = floatHeight;
wp_viewport_set_destination(window->wl.viewport, width, height);
}
printf("after: configure=%dx%d window->wl=%dx%d videoMode=%dx%d\n", width, height, window->wl.width, window->wl.height, window->videoMode.width, window->videoMode.height);
_glfwInputWindowSize(window, width, height);
_glfwPlatformSetWindowSize(window, width, height);
_glfwInputWindowDamage(window);
}
@ -363,9 +391,30 @@ static void setOpaqueRegion(_GLFWwindow* window)
static void resizeWindow(_GLFWwindow* window)
{
int width = window->wl.width;
int height = window->wl.height;
int scale = window->wl.scale;
int scaledWidth = window->wl.width * scale;
int scaledHeight = window->wl.height * scale;
printf("resizeWindow\n");
if (window->monitor)
{
if (window->wl.xdg.toplevel)
{
xdg_toplevel_set_fullscreen(
window->wl.xdg.toplevel,
window->monitor->wl.output);
}
else if (window->wl.shellSurface)
{
wl_shell_surface_set_fullscreen(
window->wl.shellSurface,
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
0, window->monitor->wl.output);
}
}
int scaledWidth = width * scale;
int scaledHeight = height * scale;
wl_egl_window_resize(window->wl.native, scaledWidth, scaledHeight, 0, 0);
if (!window->wl.transparent)
setOpaqueRegion(window);
@ -377,26 +426,26 @@ static void resizeWindow(_GLFWwindow* window)
// Top decoration.
wp_viewport_set_destination(window->wl.decorations.top.viewport,
window->wl.width, _GLFW_DECORATION_TOP);
width, _GLFW_DECORATION_TOP);
wl_surface_commit(window->wl.decorations.top.surface);
// Left decoration.
wp_viewport_set_destination(window->wl.decorations.left.viewport,
_GLFW_DECORATION_WIDTH, window->wl.height + _GLFW_DECORATION_TOP);
_GLFW_DECORATION_WIDTH, height + _GLFW_DECORATION_TOP);
wl_surface_commit(window->wl.decorations.left.surface);
// Right decoration.
wl_subsurface_set_position(window->wl.decorations.right.subsurface,
window->wl.width, -_GLFW_DECORATION_TOP);
width, -_GLFW_DECORATION_TOP);
wp_viewport_set_destination(window->wl.decorations.right.viewport,
_GLFW_DECORATION_WIDTH, window->wl.height + _GLFW_DECORATION_TOP);
_GLFW_DECORATION_WIDTH, height + _GLFW_DECORATION_TOP);
wl_surface_commit(window->wl.decorations.right.surface);
// Bottom decoration.
wl_subsurface_set_position(window->wl.decorations.bottom.subsurface,
-_GLFW_DECORATION_WIDTH, window->wl.height);
-_GLFW_DECORATION_WIDTH, height);
wp_viewport_set_destination(window->wl.decorations.bottom.viewport,
window->wl.width + _GLFW_DECORATION_HORIZONTAL, _GLFW_DECORATION_WIDTH);
width + _GLFW_DECORATION_HORIZONTAL, _GLFW_DECORATION_WIDTH);
wl_surface_commit(window->wl.decorations.bottom.surface);
}
@ -406,6 +455,7 @@ static void checkScaleChange(_GLFWwindow* window)
int i;
int monitorScale;
printf("checkScaleChange\n");
// Check if we will be able to set the buffer scale or not.
if (_glfw.wl.compositorVersion < 3)
return;
@ -521,6 +571,7 @@ static GLFWbool createSurface(_GLFWwindow* window,
}
static void setFullscreen(_GLFWwindow* window, _GLFWmonitor* monitor,
int width, int height,
int refreshRate)
{
if (window->wl.xdg.toplevel)
@ -540,9 +591,13 @@ static void setFullscreen(_GLFWwindow* window, _GLFWmonitor* monitor,
setIdleInhibitor(window, GLFW_TRUE);
if (!window->wl.decorations.serverSide)
destroyDecorations(window);
if (_glfw.wl.viewporter) {
window->wl.viewport =
wp_viewporter_get_viewport(_glfw.wl.viewporter, window->wl.surface);
}
}
static GLFWbool createShellSurface(_GLFWwindow* window)
static GLFWbool createShellSurface(_GLFWwindow* window, int width, int height)
{
if (!_glfw.wl.shell)
{
@ -569,7 +624,7 @@ static GLFWbool createShellSurface(_GLFWwindow* window)
if (window->monitor)
{
setFullscreen(window, window->monitor, 0);
setFullscreen(window, window->monitor, width, height, 0);
}
else if (window->wl.maximized)
{
@ -623,7 +678,25 @@ static void xdgToplevelHandleConfigure(void* data,
if (width != 0 && height != 0)
{
if (!maximized && !fullscreen)
if (fullscreen)
{
if (window->wl.viewport)
{
aspectRatio = (float)width / (float)height;
targetRatio = (float)window->wl.width / (float)window->wl.height;
if (aspectRatio < targetRatio)
height = width / targetRatio;
else if (aspectRatio > targetRatio)
width = height * targetRatio;
wp_viewport_set_destination(window->wl.viewport, width, height);
width = window->wl.width;
height = window->wl.height;
}
}
else
{
if (!maximized)
{
if (window->numer != GLFW_DONT_CARE && window->denom != GLFW_DONT_CARE)
{
@ -635,9 +708,9 @@ static void xdgToplevelHandleConfigure(void* data,
width = height * targetRatio;
}
}
}
_glfwInputWindowSize(window, width, height);
_glfwPlatformSetWindowSize(window, width, height);
_glfwInputWindowDamage(window);
}
@ -698,7 +771,7 @@ static void setXdgDecorations(_GLFWwindow* window)
}
}
static GLFWbool createXdgSurface(_GLFWwindow* window)
static GLFWbool createXdgSurface(_GLFWwindow* window, int width, int height)
{
window->wl.xdg.surface = xdg_wm_base_get_xdg_surface(_glfw.wl.wmBase,
window->wl.surface);
@ -737,9 +810,7 @@ static GLFWbool createXdgSurface(_GLFWwindow* window)
if (window->monitor)
{
xdg_toplevel_set_fullscreen(window->wl.xdg.toplevel,
window->monitor->wl.output);
setIdleInhibitor(window, GLFW_TRUE);
setFullscreen(window, window->monitor, width, height, 0);
}
else if (window->wl.maximized)
{
@ -951,12 +1022,12 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
{
if (_glfw.wl.wmBase)
{
if (!createXdgSurface(window))
if (!createXdgSurface(window, wndconfig->width, wndconfig->height))
return GLFW_FALSE;
}
else
{
if (!createShellSurface(window))
if (!createShellSurface(window, wndconfig->width, wndconfig->height))
return GLFW_FALSE;
}
@ -1069,6 +1140,7 @@ void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
{
printf("SetWindowSize\n");
window->wl.width = width;
window->wl.height = height;
resizeWindow(window);
@ -1192,9 +1264,9 @@ void _glfwPlatformShowWindow(_GLFWwindow* window)
if (!window->wl.visible)
{
if (_glfw.wl.wmBase)
createXdgSurface(window);
createXdgSurface(window, window->wl.width, window->wl.height);
else if (!window->wl.shellSurface)
createShellSurface(window);
createShellSurface(window, window->wl.width, window->wl.height);
window->wl.visible = GLFW_TRUE;
}
}
@ -1237,7 +1309,7 @@ void _glfwPlatformSetWindowMonitor(_GLFWwindow* window,
{
if (monitor)
{
setFullscreen(window, monitor, refreshRate);
setFullscreen(window, monitor, width, height, refreshRate);
}
else
{
@ -1246,8 +1318,10 @@ void _glfwPlatformSetWindowMonitor(_GLFWwindow* window,
else if (window->wl.shellSurface)
wl_shell_surface_set_toplevel(window->wl.shellSurface);
setIdleInhibitor(window, GLFW_FALSE);
if (!_glfw.wl.decorationManager)
if (!_glfw.wl.decorationManager && window->decorated)
createDecorations(window);
if (window->wl.viewport)
wp_viewport_destroy(window->wl.viewport);
}
_glfwInputWindowMonitor(window, monitor);
}

View File

@ -188,8 +188,8 @@ int main(int argc, char** argv)
monitor = glfwGetPrimaryMonitor();
mode = glfwGetVideoMode(monitor);
width = mode->width;
height = mode->height;
width = 640;
height = 480;
}
else
{
@ -230,6 +230,9 @@ int main(int argc, char** argv)
glfwPollEvents();
sample_input(window);
if (frame_count == 30)
glfwSetWindowSize(window, 640, rand() % 1200);
glfwGetWindowSize(window, &width, &height);
area = nk_rect(0.f, 0.f, (float) width, (float) height);