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

wl_window.c

Blame
  • wl_window.c 29.71 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;