Skip to content
Snippets Groups Projects
Select Git revision
  • 797ee8d8e347061b1bdb79fa33c2ca39e21145e1
  • for-vairdraw default protected
  • multi-context-windows
3 results

wl_window.c

Blame
    • Camilla Löwy's avatar
      797ee8d8
      Move all cursor positioning to platform code · 797ee8d8
      Camilla Löwy authored
      Due to Wayland, shared code cannot rely on cursor positioning being
      supported by the underlying platform.
      
      This implicitly fixes #617 as it moves cursor centering into
      _glfwPlatformSetCursorMode, thus separating it from the stale value of
      _glfw.cursorWindow.
      
      Fixes #617.
      797ee8d8
      History
      Move all cursor positioning to platform code
      Camilla Löwy authored
      Due to Wayland, shared code cannot rely on cursor positioning being
      supported by the underlying platform.
      
      This implicitly fixes #617 as it moves cursor centering into
      _glfwPlatformSetCursorMode, thus separating it from the stale value of
      _glfw.cursorWindow.
      
      Fixes #617.
    wl_window.c 30.55 KiB
    //========================================================================
    // GLFW 3.2 Wayland - www.glfw.org
    //------------------------------------------------------------------------
    // Copyright (c) 2014 Jonas Ådahl <jadahl@gmail.com>
    //
    // This software is provided 'as-is', without any express or implied
    // warranty. In no event will the authors be held liable for any damages
    // arising from the use of this software.
    //
    // Permission is granted to anyone to use this software for any purpose,
    // including commercial applications, and to alter it and redistribute it
    // freely, subject to the following restrictions:
    //
    // 1. The origin of this software must not be misrepresented; you must not
    //    claim that you wrote the original software. If you use this software
    //    in a product, an acknowledgment in the product documentation would
    //    be appreciated but is not required.
    //
    // 2. Altered source versions must be plainly marked as such, and must not
    //    be misrepresented as being the original software.
    //
    // 3. This notice may not be removed or altered from any source
    //    distribution.
    //
    //========================================================================
    
    #define _GNU_SOURCE
    
    #include "internal.h"
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <errno.h>
    #include <unistd.h>
    #include <string.h>
    #include <fcntl.h>
    #include <sys/mman.h>
    #include <poll.h>
    
    #include <wayland-egl.h>
    #include <wayland-cursor.h>
    
    
    static void handlePing(void* data,
                           struct wl_shell_surface* shellSurface,
                           uint32_t serial)
    {
        wl_shell_surface_pong(shellSurface, serial);
    }
    
    static void handleConfigure(void* data,
                                struct wl_shell_surface* shellSurface,
                                uint32_t edges,
                                int32_t width,
                                int32_t height)
    {
        _GLFWwindow* window = data;
        float aspectRatio;
        float targetRatio;
    
        if (!window->monitor)
        {
            if (window->numer != GLFW_DONT_CARE && window->denom != GLFW_DONT_CARE)
            {
                aspectRatio = (float)width / (float)height;
                targetRatio = (float)window->numer / (float)window->denom;
                if (aspectRatio < targetRatio)
                    height = width / targetRatio;
                else if (aspectRatio > targetRatio)
                    width = height * targetRatio;