2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
// Event linter (event spewer)
|
2016-11-21 15:23:59 +00:00
|
|
|
// Copyright (c) Camilla Löwy <elmindreda@glfw.org>
|
2010-09-07 15:34:51 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
//
|
|
|
|
// This test hooks every available callback and outputs their arguments
|
|
|
|
//
|
|
|
|
// Log messages go to stdout, error messages to stderr
|
|
|
|
//
|
|
|
|
// Every event also gets a (sequential) number to aid discussion of logs
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
|
2021-08-24 23:18:03 +00:00
|
|
|
#define GLAD_GL_IMPLEMENTATION
|
2019-04-14 15:34:38 +00:00
|
|
|
#include <glad/gl.h>
|
2019-05-24 15:17:15 +00:00
|
|
|
#define GLFW_INCLUDE_NONE
|
2013-05-22 20:46:34 +00:00
|
|
|
#include <GLFW/glfw3.h>
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
2012-12-09 18:19:00 +00:00
|
|
|
#include <string.h>
|
2014-12-18 02:33:13 +00:00
|
|
|
#include <locale.h>
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2013-10-09 22:17:53 +00:00
|
|
|
#include "getopt.h"
|
|
|
|
|
2012-08-07 19:40:40 +00:00
|
|
|
// Event index
|
2010-09-07 15:34:51 +00:00
|
|
|
static unsigned int counter = 0;
|
|
|
|
|
2014-02-11 23:49:26 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GLFWwindow* window;
|
|
|
|
int number;
|
|
|
|
int closeable;
|
|
|
|
} Slot;
|
|
|
|
|
|
|
|
static void usage(void)
|
|
|
|
{
|
|
|
|
printf("Usage: events [-f] [-h] [-n WINDOWS]\n");
|
|
|
|
printf("Options:\n");
|
|
|
|
printf(" -f use full screen\n");
|
|
|
|
printf(" -h show this help\n");
|
|
|
|
printf(" -n the number of windows to create\n");
|
|
|
|
}
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
static const char* get_key_name(int key)
|
|
|
|
{
|
|
|
|
switch (key)
|
|
|
|
{
|
2011-01-02 10:18:14 +00:00
|
|
|
// Printable keys
|
2011-01-03 21:07:01 +00:00
|
|
|
case GLFW_KEY_A: return "A";
|
|
|
|
case GLFW_KEY_B: return "B";
|
|
|
|
case GLFW_KEY_C: return "C";
|
|
|
|
case GLFW_KEY_D: return "D";
|
|
|
|
case GLFW_KEY_E: return "E";
|
|
|
|
case GLFW_KEY_F: return "F";
|
|
|
|
case GLFW_KEY_G: return "G";
|
|
|
|
case GLFW_KEY_H: return "H";
|
|
|
|
case GLFW_KEY_I: return "I";
|
|
|
|
case GLFW_KEY_J: return "J";
|
|
|
|
case GLFW_KEY_K: return "K";
|
|
|
|
case GLFW_KEY_L: return "L";
|
|
|
|
case GLFW_KEY_M: return "M";
|
|
|
|
case GLFW_KEY_N: return "N";
|
|
|
|
case GLFW_KEY_O: return "O";
|
|
|
|
case GLFW_KEY_P: return "P";
|
|
|
|
case GLFW_KEY_Q: return "Q";
|
|
|
|
case GLFW_KEY_R: return "R";
|
|
|
|
case GLFW_KEY_S: return "S";
|
|
|
|
case GLFW_KEY_T: return "T";
|
|
|
|
case GLFW_KEY_U: return "U";
|
|
|
|
case GLFW_KEY_V: return "V";
|
|
|
|
case GLFW_KEY_W: return "W";
|
|
|
|
case GLFW_KEY_X: return "X";
|
|
|
|
case GLFW_KEY_Y: return "Y";
|
|
|
|
case GLFW_KEY_Z: return "Z";
|
2011-01-02 10:18:14 +00:00
|
|
|
case GLFW_KEY_1: return "1";
|
|
|
|
case GLFW_KEY_2: return "2";
|
|
|
|
case GLFW_KEY_3: return "3";
|
|
|
|
case GLFW_KEY_4: return "4";
|
|
|
|
case GLFW_KEY_5: return "5";
|
|
|
|
case GLFW_KEY_6: return "6";
|
|
|
|
case GLFW_KEY_7: return "7";
|
|
|
|
case GLFW_KEY_8: return "8";
|
|
|
|
case GLFW_KEY_9: return "9";
|
|
|
|
case GLFW_KEY_0: return "0";
|
2011-01-03 21:07:01 +00:00
|
|
|
case GLFW_KEY_SPACE: return "SPACE";
|
|
|
|
case GLFW_KEY_MINUS: return "MINUS";
|
|
|
|
case GLFW_KEY_EQUAL: return "EQUAL";
|
|
|
|
case GLFW_KEY_LEFT_BRACKET: return "LEFT BRACKET";
|
|
|
|
case GLFW_KEY_RIGHT_BRACKET: return "RIGHT BRACKET";
|
|
|
|
case GLFW_KEY_BACKSLASH: return "BACKSLASH";
|
|
|
|
case GLFW_KEY_SEMICOLON: return "SEMICOLON";
|
|
|
|
case GLFW_KEY_APOSTROPHE: return "APOSTROPHE";
|
|
|
|
case GLFW_KEY_GRAVE_ACCENT: return "GRAVE ACCENT";
|
|
|
|
case GLFW_KEY_COMMA: return "COMMA";
|
|
|
|
case GLFW_KEY_PERIOD: return "PERIOD";
|
|
|
|
case GLFW_KEY_SLASH: return "SLASH";
|
|
|
|
case GLFW_KEY_WORLD_1: return "WORLD 1";
|
|
|
|
case GLFW_KEY_WORLD_2: return "WORLD 2";
|
2011-01-02 10:18:14 +00:00
|
|
|
|
2011-01-03 21:07:01 +00:00
|
|
|
// Function keys
|
2011-01-03 21:22:14 +00:00
|
|
|
case GLFW_KEY_ESCAPE: return "ESCAPE";
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_KEY_F1: return "F1";
|
|
|
|
case GLFW_KEY_F2: return "F2";
|
|
|
|
case GLFW_KEY_F3: return "F3";
|
|
|
|
case GLFW_KEY_F4: return "F4";
|
|
|
|
case GLFW_KEY_F5: return "F5";
|
|
|
|
case GLFW_KEY_F6: return "F6";
|
|
|
|
case GLFW_KEY_F7: return "F7";
|
|
|
|
case GLFW_KEY_F8: return "F8";
|
|
|
|
case GLFW_KEY_F9: return "F9";
|
|
|
|
case GLFW_KEY_F10: return "F10";
|
|
|
|
case GLFW_KEY_F11: return "F11";
|
|
|
|
case GLFW_KEY_F12: return "F12";
|
|
|
|
case GLFW_KEY_F13: return "F13";
|
|
|
|
case GLFW_KEY_F14: return "F14";
|
|
|
|
case GLFW_KEY_F15: return "F15";
|
|
|
|
case GLFW_KEY_F16: return "F16";
|
|
|
|
case GLFW_KEY_F17: return "F17";
|
|
|
|
case GLFW_KEY_F18: return "F18";
|
|
|
|
case GLFW_KEY_F19: return "F19";
|
|
|
|
case GLFW_KEY_F20: return "F20";
|
|
|
|
case GLFW_KEY_F21: return "F21";
|
|
|
|
case GLFW_KEY_F22: return "F22";
|
|
|
|
case GLFW_KEY_F23: return "F23";
|
|
|
|
case GLFW_KEY_F24: return "F24";
|
|
|
|
case GLFW_KEY_F25: return "F25";
|
2011-01-03 21:07:01 +00:00
|
|
|
case GLFW_KEY_UP: return "UP";
|
|
|
|
case GLFW_KEY_DOWN: return "DOWN";
|
|
|
|
case GLFW_KEY_LEFT: return "LEFT";
|
|
|
|
case GLFW_KEY_RIGHT: return "RIGHT";
|
|
|
|
case GLFW_KEY_LEFT_SHIFT: return "LEFT SHIFT";
|
|
|
|
case GLFW_KEY_RIGHT_SHIFT: return "RIGHT SHIFT";
|
|
|
|
case GLFW_KEY_LEFT_CONTROL: return "LEFT CONTROL";
|
|
|
|
case GLFW_KEY_RIGHT_CONTROL: return "RIGHT CONTROL";
|
|
|
|
case GLFW_KEY_LEFT_ALT: return "LEFT ALT";
|
|
|
|
case GLFW_KEY_RIGHT_ALT: return "RIGHT ALT";
|
|
|
|
case GLFW_KEY_TAB: return "TAB";
|
|
|
|
case GLFW_KEY_ENTER: return "ENTER";
|
|
|
|
case GLFW_KEY_BACKSPACE: return "BACKSPACE";
|
|
|
|
case GLFW_KEY_INSERT: return "INSERT";
|
|
|
|
case GLFW_KEY_DELETE: return "DELETE";
|
|
|
|
case GLFW_KEY_PAGE_UP: return "PAGE UP";
|
|
|
|
case GLFW_KEY_PAGE_DOWN: return "PAGE DOWN";
|
|
|
|
case GLFW_KEY_HOME: return "HOME";
|
|
|
|
case GLFW_KEY_END: return "END";
|
|
|
|
case GLFW_KEY_KP_0: return "KEYPAD 0";
|
|
|
|
case GLFW_KEY_KP_1: return "KEYPAD 1";
|
|
|
|
case GLFW_KEY_KP_2: return "KEYPAD 2";
|
|
|
|
case GLFW_KEY_KP_3: return "KEYPAD 3";
|
|
|
|
case GLFW_KEY_KP_4: return "KEYPAD 4";
|
|
|
|
case GLFW_KEY_KP_5: return "KEYPAD 5";
|
|
|
|
case GLFW_KEY_KP_6: return "KEYPAD 6";
|
|
|
|
case GLFW_KEY_KP_7: return "KEYPAD 7";
|
|
|
|
case GLFW_KEY_KP_8: return "KEYPAD 8";
|
|
|
|
case GLFW_KEY_KP_9: return "KEYPAD 9";
|
|
|
|
case GLFW_KEY_KP_DIVIDE: return "KEYPAD DIVIDE";
|
2019-08-12 10:52:31 +00:00
|
|
|
case GLFW_KEY_KP_MULTIPLY: return "KEYPAD MULTIPLY";
|
2011-01-03 21:07:01 +00:00
|
|
|
case GLFW_KEY_KP_SUBTRACT: return "KEYPAD SUBTRACT";
|
|
|
|
case GLFW_KEY_KP_ADD: return "KEYPAD ADD";
|
|
|
|
case GLFW_KEY_KP_DECIMAL: return "KEYPAD DECIMAL";
|
|
|
|
case GLFW_KEY_KP_EQUAL: return "KEYPAD EQUAL";
|
|
|
|
case GLFW_KEY_KP_ENTER: return "KEYPAD ENTER";
|
2013-02-21 17:39:22 +00:00
|
|
|
case GLFW_KEY_PRINT_SCREEN: return "PRINT SCREEN";
|
2011-01-03 21:07:01 +00:00
|
|
|
case GLFW_KEY_NUM_LOCK: return "NUM LOCK";
|
|
|
|
case GLFW_KEY_CAPS_LOCK: return "CAPS LOCK";
|
|
|
|
case GLFW_KEY_SCROLL_LOCK: return "SCROLL LOCK";
|
|
|
|
case GLFW_KEY_PAUSE: return "PAUSE";
|
|
|
|
case GLFW_KEY_LEFT_SUPER: return "LEFT SUPER";
|
|
|
|
case GLFW_KEY_RIGHT_SUPER: return "RIGHT SUPER";
|
|
|
|
case GLFW_KEY_MENU: return "MENU";
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2014-06-12 21:04:20 +00:00
|
|
|
default: return "UNKNOWN";
|
2011-01-03 21:07:01 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char* get_action_name(int action)
|
|
|
|
{
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case GLFW_PRESS:
|
2011-09-20 13:18:03 +00:00
|
|
|
return "pressed";
|
2010-09-07 15:34:51 +00:00
|
|
|
case GLFW_RELEASE:
|
2011-09-20 13:18:03 +00:00
|
|
|
return "released";
|
2013-01-12 16:06:35 +00:00
|
|
|
case GLFW_REPEAT:
|
|
|
|
return "repeated";
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return "caused unknown action";
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* get_button_name(int button)
|
|
|
|
{
|
|
|
|
switch (button)
|
|
|
|
{
|
|
|
|
case GLFW_MOUSE_BUTTON_LEFT:
|
|
|
|
return "left";
|
|
|
|
case GLFW_MOUSE_BUTTON_RIGHT:
|
|
|
|
return "right";
|
|
|
|
case GLFW_MOUSE_BUTTON_MIDDLE:
|
|
|
|
return "middle";
|
2014-06-12 21:04:20 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
static char name[16];
|
2016-09-30 03:31:07 +00:00
|
|
|
snprintf(name, sizeof(name), "%i", button);
|
2014-06-12 21:04:20 +00:00
|
|
|
return name;
|
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-09 18:19:00 +00:00
|
|
|
static const char* get_mods_name(int mods)
|
|
|
|
{
|
|
|
|
static char name[512];
|
|
|
|
|
2014-06-12 21:04:20 +00:00
|
|
|
if (mods == 0)
|
|
|
|
return " no mods";
|
|
|
|
|
2012-12-09 18:19:00 +00:00
|
|
|
name[0] = '\0';
|
|
|
|
|
|
|
|
if (mods & GLFW_MOD_SHIFT)
|
|
|
|
strcat(name, " shift");
|
2013-05-23 12:41:43 +00:00
|
|
|
if (mods & GLFW_MOD_CONTROL)
|
2012-12-09 18:19:00 +00:00
|
|
|
strcat(name, " control");
|
|
|
|
if (mods & GLFW_MOD_ALT)
|
|
|
|
strcat(name, " alt");
|
2013-05-23 11:22:27 +00:00
|
|
|
if (mods & GLFW_MOD_SUPER)
|
|
|
|
strcat(name, " super");
|
2017-11-29 19:42:37 +00:00
|
|
|
if (mods & GLFW_MOD_CAPS_LOCK)
|
|
|
|
strcat(name, " capslock-on");
|
|
|
|
if (mods & GLFW_MOD_NUM_LOCK)
|
|
|
|
strcat(name, " numlock-on");
|
2012-12-09 18:19:00 +00:00
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2019-09-26 17:22:36 +00:00
|
|
|
static size_t encode_utf8(char* s, unsigned int ch)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2019-09-26 17:22:36 +00:00
|
|
|
size_t count = 0;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2019-09-26 17:22:36 +00:00
|
|
|
if (ch < 0x80)
|
|
|
|
s[count++] = (char) ch;
|
|
|
|
else if (ch < 0x800)
|
|
|
|
{
|
|
|
|
s[count++] = (ch >> 6) | 0xc0;
|
|
|
|
s[count++] = (ch & 0x3f) | 0x80;
|
|
|
|
}
|
|
|
|
else if (ch < 0x10000)
|
|
|
|
{
|
|
|
|
s[count++] = (ch >> 12) | 0xe0;
|
|
|
|
s[count++] = ((ch >> 6) & 0x3f) | 0x80;
|
|
|
|
s[count++] = (ch & 0x3f) | 0x80;
|
|
|
|
}
|
|
|
|
else if (ch < 0x110000)
|
|
|
|
{
|
|
|
|
s[count++] = (ch >> 18) | 0xf0;
|
|
|
|
s[count++] = ((ch >> 12) & 0x3f) | 0x80;
|
|
|
|
s[count++] = ((ch >> 6) & 0x3f) | 0x80;
|
|
|
|
s[count++] = (ch & 0x3f) | 0x80;
|
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2019-09-26 17:22:36 +00:00
|
|
|
return count;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-12-30 00:42:14 +00:00
|
|
|
static void error_callback(int error, const char* description)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error: %s\n", description);
|
|
|
|
}
|
|
|
|
|
2013-01-05 20:13:28 +00:00
|
|
|
static void window_pos_callback(GLFWwindow* window, int x, int y)
|
2012-11-30 12:56:42 +00:00
|
|
|
{
|
2014-03-11 11:53:00 +00:00
|
|
|
Slot* slot = glfwGetWindowUserPointer(window);
|
2014-02-11 23:49:26 +00:00
|
|
|
printf("%08x to %i at %0.3f: Window position: %i %i\n",
|
2014-03-11 11:53:00 +00:00
|
|
|
counter++, slot->number, glfwGetTime(), x, y);
|
2012-11-30 12:56:42 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 20:13:28 +00:00
|
|
|
static void window_size_callback(GLFWwindow* window, int width, int height)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2014-03-11 11:53:00 +00:00
|
|
|
Slot* slot = glfwGetWindowUserPointer(window);
|
2014-02-11 23:49:26 +00:00
|
|
|
printf("%08x to %i at %0.3f: Window size: %i %i\n",
|
2014-03-11 11:53:00 +00:00
|
|
|
counter++, slot->number, glfwGetTime(), width, height);
|
2013-06-03 10:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|
|
|
{
|
2014-03-11 11:53:00 +00:00
|
|
|
Slot* slot = glfwGetWindowUserPointer(window);
|
2014-02-11 23:49:26 +00:00
|
|
|
printf("%08x to %i at %0.3f: Framebuffer size: %i %i\n",
|
2014-03-11 11:53:00 +00:00
|
|
|
counter++, slot->number, glfwGetTime(), width, height);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 20:26:40 +00:00
|
|
|
static void window_content_scale_callback(GLFWwindow* window, float xscale, float yscale)
|
|
|
|
{
|
|
|
|
Slot* slot = glfwGetWindowUserPointer(window);
|
|
|
|
printf("%08x to %i at %0.3f: Window content scale: %0.3f %0.3f\n",
|
|
|
|
counter++, slot->number, glfwGetTime(), xscale, yscale);
|
|
|
|
}
|
|
|
|
|
2013-03-06 22:29:37 +00:00
|
|
|
static void window_close_callback(GLFWwindow* window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2014-02-11 23:49:26 +00:00
|
|
|
Slot* slot = glfwGetWindowUserPointer(window);
|
|
|
|
printf("%08x to %i at %0.3f: Window close\n",
|
2014-03-11 11:53:00 +00:00
|
|
|
counter++, slot->number, glfwGetTime());
|
2014-02-11 23:49:26 +00:00
|
|
|
|
2019-09-26 21:31:22 +00:00
|
|
|
if (!slot->closeable)
|
|
|
|
{
|
|
|
|
printf("(( closing is disabled, press %s to re-enable )\n",
|
|
|
|
glfwGetKeyName(GLFW_KEY_C, 0));
|
|
|
|
}
|
|
|
|
|
2014-02-11 23:49:26 +00:00
|
|
|
glfwSetWindowShouldClose(window, slot->closeable);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 20:13:28 +00:00
|
|
|
static void window_refresh_callback(GLFWwindow* window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2014-03-11 11:53:00 +00:00
|
|
|
Slot* slot = glfwGetWindowUserPointer(window);
|
2014-02-11 23:49:26 +00:00
|
|
|
printf("%08x to %i at %0.3f: Window refresh\n",
|
2014-03-11 11:53:00 +00:00
|
|
|
counter++, slot->number, glfwGetTime());
|
2011-09-08 20:52:58 +00:00
|
|
|
|
2014-02-11 23:49:26 +00:00
|
|
|
glfwMakeContextCurrent(window);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
glfwSwapBuffers(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 20:13:28 +00:00
|
|
|
static void window_focus_callback(GLFWwindow* window, int focused)
|
2010-09-19 00:45:20 +00:00
|
|
|
{
|
2014-03-11 11:53:00 +00:00
|
|
|
Slot* slot = glfwGetWindowUserPointer(window);
|
2014-02-11 23:49:26 +00:00
|
|
|
printf("%08x to %i at %0.3f: Window %s\n",
|
2014-03-11 11:53:00 +00:00
|
|
|
counter++, slot->number, glfwGetTime(),
|
2012-11-22 16:04:44 +00:00
|
|
|
focused ? "focused" : "defocused");
|
2010-09-19 00:45:20 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 20:13:28 +00:00
|
|
|
static void window_iconify_callback(GLFWwindow* window, int iconified)
|
2010-09-20 00:22:35 +00:00
|
|
|
{
|
2014-03-11 11:53:00 +00:00
|
|
|
Slot* slot = glfwGetWindowUserPointer(window);
|
2014-02-11 23:49:26 +00:00
|
|
|
printf("%08x to %i at %0.3f: Window was %s\n",
|
2014-03-11 11:53:00 +00:00
|
|
|
counter++, slot->number, glfwGetTime(),
|
2016-06-16 11:09:28 +00:00
|
|
|
iconified ? "iconified" : "uniconified");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void window_maximize_callback(GLFWwindow* window, int maximized)
|
|
|
|
{
|
|
|
|
Slot* slot = glfwGetWindowUserPointer(window);
|
|
|
|
printf("%08x to %i at %0.3f: Window was %s\n",
|
|
|
|
counter++, slot->number, glfwGetTime(),
|
|
|
|
maximized ? "maximized" : "unmaximized");
|
2010-09-20 00:22:35 +00:00
|
|
|
}
|
|
|
|
|
2012-12-09 18:19:00 +00:00
|
|
|
static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2014-03-11 11:53:00 +00:00
|
|
|
Slot* slot = glfwGetWindowUserPointer(window);
|
2014-06-12 21:04:20 +00:00
|
|
|
printf("%08x to %i at %0.3f: Mouse button %i (%s) (with%s) was %s\n",
|
|
|
|
counter++, slot->number, glfwGetTime(), button,
|
|
|
|
get_button_name(button),
|
|
|
|
get_mods_name(mods),
|
|
|
|
get_action_name(action));
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2013-04-04 14:16:21 +00:00
|
|
|
static void cursor_position_callback(GLFWwindow* window, double x, double y)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2014-03-11 11:53:00 +00:00
|
|
|
Slot* slot = glfwGetWindowUserPointer(window);
|
2014-02-11 23:49:26 +00:00
|
|
|
printf("%08x to %i at %0.3f: Cursor position: %f %f\n",
|
2014-03-11 11:53:00 +00:00
|
|
|
counter++, slot->number, glfwGetTime(), x, y);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 20:13:28 +00:00
|
|
|
static void cursor_enter_callback(GLFWwindow* window, int entered)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2014-03-11 11:53:00 +00:00
|
|
|
Slot* slot = glfwGetWindowUserPointer(window);
|
2014-02-11 23:49:26 +00:00
|
|
|
printf("%08x to %i at %0.3f: Cursor %s window\n",
|
2014-03-11 11:53:00 +00:00
|
|
|
counter++, slot->number, glfwGetTime(),
|
2012-01-30 21:59:38 +00:00
|
|
|
entered ? "entered" : "left");
|
2012-01-30 21:44:51 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 20:13:28 +00:00
|
|
|
static void scroll_callback(GLFWwindow* window, double x, double y)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2014-03-11 11:53:00 +00:00
|
|
|
Slot* slot = glfwGetWindowUserPointer(window);
|
2014-02-11 23:49:26 +00:00
|
|
|
printf("%08x to %i at %0.3f: Scroll: %0.3f %0.3f\n",
|
2014-03-11 11:53:00 +00:00
|
|
|
counter++, slot->number, glfwGetTime(), x, y);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2013-05-30 15:19:12 +00:00
|
|
|
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2014-02-11 23:49:26 +00:00
|
|
|
Slot* slot = glfwGetWindowUserPointer(window);
|
2015-07-02 12:24:50 +00:00
|
|
|
const char* name = glfwGetKeyName(key, scancode);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2015-07-02 12:24:50 +00:00
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
printf("%08x to %i at %0.3f: Key 0x%04x Scancode 0x%04x (%s) (%s) (with%s) was %s\n",
|
|
|
|
counter++, slot->number, glfwGetTime(), key, scancode,
|
|
|
|
get_key_name(key),
|
|
|
|
name,
|
|
|
|
get_mods_name(mods),
|
|
|
|
get_action_name(action));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("%08x to %i at %0.3f: Key 0x%04x Scancode 0x%04x (%s) (with%s) was %s\n",
|
|
|
|
counter++, slot->number, glfwGetTime(), key, scancode,
|
|
|
|
get_key_name(key),
|
|
|
|
get_mods_name(mods),
|
|
|
|
get_action_name(action));
|
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
if (action != GLFW_PRESS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (key)
|
|
|
|
{
|
2012-02-07 15:40:26 +00:00
|
|
|
case GLFW_KEY_C:
|
|
|
|
{
|
2014-02-11 23:49:26 +00:00
|
|
|
slot->closeable = !slot->closeable;
|
2012-02-07 15:40:26 +00:00
|
|
|
|
2014-02-11 23:49:26 +00:00
|
|
|
printf("(( closing %s ))\n", slot->closeable ? "enabled" : "disabled");
|
2012-02-07 15:40:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-11-29 19:42:37 +00:00
|
|
|
|
|
|
|
case GLFW_KEY_L:
|
|
|
|
{
|
|
|
|
const int state = glfwGetInputMode(window, GLFW_LOCK_KEY_MODS);
|
|
|
|
glfwSetInputMode(window, GLFW_LOCK_KEY_MODS, !state);
|
|
|
|
|
|
|
|
printf("(( lock key mods %s ))\n", !state ? "enabled" : "disabled");
|
|
|
|
break;
|
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-10 17:41:56 +00:00
|
|
|
static void char_callback(GLFWwindow* window, unsigned int codepoint)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2014-03-11 11:53:00 +00:00
|
|
|
Slot* slot = glfwGetWindowUserPointer(window);
|
2019-09-26 17:22:36 +00:00
|
|
|
char string[5] = "";
|
|
|
|
|
|
|
|
encode_utf8(string, codepoint);
|
2014-02-11 23:49:26 +00:00
|
|
|
printf("%08x to %i at %0.3f: Character 0x%08x (%s) input\n",
|
2019-09-26 17:22:36 +00:00
|
|
|
counter++, slot->number, glfwGetTime(), codepoint, string);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 23:52:49 +00:00
|
|
|
static void drop_callback(GLFWwindow* window, int count, const char* paths[])
|
2013-12-22 15:50:01 +00:00
|
|
|
{
|
2013-12-22 18:28:46 +00:00
|
|
|
int i;
|
2014-03-11 11:53:00 +00:00
|
|
|
Slot* slot = glfwGetWindowUserPointer(window);
|
2013-12-22 18:28:46 +00:00
|
|
|
|
2014-02-11 23:49:26 +00:00
|
|
|
printf("%08x to %i at %0.3f: Drop input\n",
|
2014-03-11 11:53:00 +00:00
|
|
|
counter++, slot->number, glfwGetTime());
|
2013-12-22 18:28:46 +00:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
2015-01-27 22:04:22 +00:00
|
|
|
printf(" %i: \"%s\"\n", i, paths[i]);
|
2013-12-22 15:50:01 +00:00
|
|
|
}
|
|
|
|
|
2014-07-07 21:23:46 +00:00
|
|
|
static void monitor_callback(GLFWmonitor* monitor, int event)
|
2011-10-09 04:20:34 +00:00
|
|
|
{
|
2012-12-13 00:56:33 +00:00
|
|
|
if (event == GLFW_CONNECTED)
|
2012-11-08 17:20:31 +00:00
|
|
|
{
|
2013-01-24 18:10:17 +00:00
|
|
|
int x, y, widthMM, heightMM;
|
2013-05-22 20:16:43 +00:00
|
|
|
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
2012-11-08 17:20:31 +00:00
|
|
|
|
2013-01-24 18:10:17 +00:00
|
|
|
glfwGetMonitorPos(monitor, &x, &y);
|
|
|
|
glfwGetMonitorPhysicalSize(monitor, &widthMM, &heightMM);
|
|
|
|
|
2012-11-08 17:20:31 +00:00
|
|
|
printf("%08x at %0.3f: Monitor %s (%ix%i at %ix%i, %ix%i mm) was connected\n",
|
|
|
|
counter++,
|
|
|
|
glfwGetTime(),
|
|
|
|
glfwGetMonitorName(monitor),
|
2013-05-22 20:16:43 +00:00
|
|
|
mode->width, mode->height,
|
2013-01-24 18:10:17 +00:00
|
|
|
x, y,
|
|
|
|
widthMM, heightMM);
|
2012-11-08 17:20:31 +00:00
|
|
|
}
|
2015-12-13 18:11:21 +00:00
|
|
|
else if (event == GLFW_DISCONNECTED)
|
2012-11-08 17:20:31 +00:00
|
|
|
{
|
|
|
|
printf("%08x at %0.3f: Monitor %s was disconnected\n",
|
|
|
|
counter++,
|
|
|
|
glfwGetTime(),
|
|
|
|
glfwGetMonitorName(monitor));
|
|
|
|
}
|
2011-10-09 04:20:34 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 01:24:07 +00:00
|
|
|
static void joystick_callback(int jid, int event)
|
2015-12-13 16:38:50 +00:00
|
|
|
{
|
|
|
|
if (event == GLFW_CONNECTED)
|
|
|
|
{
|
2016-11-26 03:56:24 +00:00
|
|
|
int axisCount, buttonCount, hatCount;
|
2015-12-13 16:38:50 +00:00
|
|
|
|
2016-10-10 01:24:07 +00:00
|
|
|
glfwGetJoystickAxes(jid, &axisCount);
|
|
|
|
glfwGetJoystickButtons(jid, &buttonCount);
|
2016-11-26 03:56:24 +00:00
|
|
|
glfwGetJoystickHats(jid, &hatCount);
|
2015-12-13 16:38:50 +00:00
|
|
|
|
2016-11-26 03:56:24 +00:00
|
|
|
printf("%08x at %0.3f: Joystick %i (%s) was connected with %i axes, %i buttons, and %i hats\n",
|
2015-12-13 16:38:50 +00:00
|
|
|
counter++, glfwGetTime(),
|
2016-10-10 01:24:07 +00:00
|
|
|
jid,
|
|
|
|
glfwGetJoystickName(jid),
|
2015-12-13 16:38:50 +00:00
|
|
|
axisCount,
|
2016-11-26 03:56:24 +00:00
|
|
|
buttonCount,
|
|
|
|
hatCount);
|
2019-09-26 17:27:09 +00:00
|
|
|
|
|
|
|
if (glfwJoystickIsGamepad(jid))
|
|
|
|
{
|
|
|
|
printf(" Joystick %i (%s) has a gamepad mapping (%s)\n",
|
|
|
|
jid,
|
|
|
|
glfwGetJoystickGUID(jid),
|
|
|
|
glfwGetGamepadName(jid));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf(" Joystick %i (%s) has no gamepad mapping\n",
|
|
|
|
jid,
|
|
|
|
glfwGetJoystickGUID(jid));
|
|
|
|
}
|
2015-12-13 16:38:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("%08x at %0.3f: Joystick %i was disconnected\n",
|
2016-10-10 01:24:07 +00:00
|
|
|
counter++, glfwGetTime(), jid);
|
2015-12-13 16:38:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-07 00:01:31 +00:00
|
|
|
static void joystick_button_callback(int jid, int button, int state) {
|
|
|
|
printf("%08x at %0.3f: Joystick %i (%s) button %d state %d\n",
|
|
|
|
counter++, glfwGetTime(),
|
|
|
|
jid,
|
|
|
|
glfwGetJoystickName(jid),
|
|
|
|
button,
|
|
|
|
state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void joystick_axis_callback(int jid, int axis, float value) {
|
|
|
|
printf("%08x at %0.3f: Joystick %i (%s) axis %d value %0.4f\n",
|
|
|
|
counter++, glfwGetTime(), jid,
|
|
|
|
glfwGetJoystickName(jid),
|
|
|
|
axis,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void joystick_hat_callback(int jid, int hat, int value) {
|
|
|
|
printf("%08x at %0.3f: Joystick %i (%s) hat %d value %d\n",
|
|
|
|
counter++, glfwGetTime(),
|
|
|
|
jid,
|
|
|
|
glfwGetJoystickName(jid),
|
|
|
|
hat,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gamepad_state_callback(int jid, unsigned char buttons[15], float axes[6]) {
|
|
|
|
int i = 0;
|
|
|
|
printf("%08x at %0.3f: Gamepad %i (%s) state:",
|
|
|
|
counter++, glfwGetTime(),
|
|
|
|
jid,
|
|
|
|
glfwGetJoystickName(jid));
|
|
|
|
|
|
|
|
printf("Buttons: ");
|
|
|
|
for (i= 0 ; i < 15; i++) {
|
|
|
|
printf(" %d:%d", i, buttons[i]);
|
|
|
|
}
|
|
|
|
printf("Axes: ");
|
|
|
|
for (i= 0 ; i < 6; i++) {
|
|
|
|
printf(" %d:%0.4f", i, axes[i]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-09 22:17:53 +00:00
|
|
|
int main(int argc, char** argv)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2014-02-11 23:49:26 +00:00
|
|
|
Slot* slots;
|
2013-10-09 22:17:53 +00:00
|
|
|
GLFWmonitor* monitor = NULL;
|
2014-02-12 13:26:34 +00:00
|
|
|
int ch, i, width, height, count = 1;
|
2010-09-09 17:18:18 +00:00
|
|
|
|
2012-12-30 00:42:14 +00:00
|
|
|
glfwSetErrorCallback(error_callback);
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
if (!glfwInit())
|
2011-09-08 20:47:37 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
printf("Library initialized\n");
|
|
|
|
|
2014-03-10 12:39:30 +00:00
|
|
|
glfwSetMonitorCallback(monitor_callback);
|
2015-12-13 16:38:50 +00:00
|
|
|
glfwSetJoystickCallback(joystick_callback);
|
2019-11-07 00:01:31 +00:00
|
|
|
glfwSetJoystickAxisCallback(joystick_axis_callback);
|
|
|
|
glfwSetJoystickButtonCallback(joystick_button_callback);
|
|
|
|
glfwSetJoystickHatCallback(joystick_hat_callback);
|
|
|
|
glfwSetGamepadStateCallback(gamepad_state_callback);
|
2014-03-10 12:39:30 +00:00
|
|
|
|
2014-02-11 23:49:26 +00:00
|
|
|
while ((ch = getopt(argc, argv, "hfn:")) != -1)
|
2013-10-09 22:17:53 +00:00
|
|
|
{
|
|
|
|
switch (ch)
|
|
|
|
{
|
2014-02-11 23:49:26 +00:00
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
|
2013-10-09 22:17:53 +00:00
|
|
|
case 'f':
|
|
|
|
monitor = glfwGetPrimaryMonitor();
|
|
|
|
break;
|
2014-02-11 23:49:26 +00:00
|
|
|
|
|
|
|
case 'n':
|
2019-01-25 11:14:23 +00:00
|
|
|
count = (int) strtoul(optarg, NULL, 10);
|
2014-02-11 23:49:26 +00:00
|
|
|
break;
|
2014-03-10 12:15:50 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
exit(EXIT_FAILURE);
|
2013-10-09 22:17:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-12 13:26:34 +00:00
|
|
|
if (monitor)
|
|
|
|
{
|
|
|
|
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
|
|
|
|
|
|
|
glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);
|
|
|
|
glfwWindowHint(GLFW_RED_BITS, mode->redBits);
|
|
|
|
glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
|
|
|
|
glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
|
|
|
|
|
|
|
|
width = mode->width;
|
|
|
|
height = mode->height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = 640;
|
|
|
|
height = 480;
|
|
|
|
}
|
|
|
|
|
2014-02-11 23:49:26 +00:00
|
|
|
slots = calloc(count, sizeof(Slot));
|
2012-10-28 12:45:11 +00:00
|
|
|
|
2014-02-11 23:49:26 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
char title[128];
|
|
|
|
|
2015-08-23 17:30:04 +00:00
|
|
|
slots[i].closeable = GLFW_TRUE;
|
2014-02-11 23:49:26 +00:00
|
|
|
slots[i].number = i + 1;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2016-09-30 03:31:07 +00:00
|
|
|
snprintf(title, sizeof(title), "Event Linter (Window %i)", slots[i].number);
|
2014-02-11 23:49:26 +00:00
|
|
|
|
2014-03-10 12:12:03 +00:00
|
|
|
if (monitor)
|
|
|
|
{
|
|
|
|
printf("Creating full screen window %i (%ix%i on %s)\n",
|
|
|
|
slots[i].number,
|
|
|
|
width, height,
|
|
|
|
glfwGetMonitorName(monitor));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("Creating windowed mode window %i (%ix%i)\n",
|
|
|
|
slots[i].number,
|
|
|
|
width, height);
|
|
|
|
}
|
|
|
|
|
2014-02-12 13:26:34 +00:00
|
|
|
slots[i].window = glfwCreateWindow(width, height, title, monitor, NULL);
|
2014-02-11 23:49:26 +00:00
|
|
|
if (!slots[i].window)
|
|
|
|
{
|
|
|
|
free(slots);
|
|
|
|
glfwTerminate();
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
glfwSetWindowUserPointer(slots[i].window, slots + i);
|
|
|
|
|
|
|
|
glfwSetWindowPosCallback(slots[i].window, window_pos_callback);
|
|
|
|
glfwSetWindowSizeCallback(slots[i].window, window_size_callback);
|
|
|
|
glfwSetFramebufferSizeCallback(slots[i].window, framebuffer_size_callback);
|
2017-12-11 20:26:40 +00:00
|
|
|
glfwSetWindowContentScaleCallback(slots[i].window, window_content_scale_callback);
|
2014-02-11 23:49:26 +00:00
|
|
|
glfwSetWindowCloseCallback(slots[i].window, window_close_callback);
|
|
|
|
glfwSetWindowRefreshCallback(slots[i].window, window_refresh_callback);
|
|
|
|
glfwSetWindowFocusCallback(slots[i].window, window_focus_callback);
|
|
|
|
glfwSetWindowIconifyCallback(slots[i].window, window_iconify_callback);
|
2016-06-16 11:09:28 +00:00
|
|
|
glfwSetWindowMaximizeCallback(slots[i].window, window_maximize_callback);
|
2014-02-11 23:49:26 +00:00
|
|
|
glfwSetMouseButtonCallback(slots[i].window, mouse_button_callback);
|
|
|
|
glfwSetCursorPosCallback(slots[i].window, cursor_position_callback);
|
|
|
|
glfwSetCursorEnterCallback(slots[i].window, cursor_enter_callback);
|
|
|
|
glfwSetScrollCallback(slots[i].window, scroll_callback);
|
|
|
|
glfwSetKeyCallback(slots[i].window, key_callback);
|
|
|
|
glfwSetCharCallback(slots[i].window, char_callback);
|
|
|
|
glfwSetDropCallback(slots[i].window, drop_callback);
|
|
|
|
|
|
|
|
glfwMakeContextCurrent(slots[i].window);
|
2019-04-14 15:34:38 +00:00
|
|
|
gladLoadGL(glfwGetProcAddress);
|
2022-07-13 19:46:14 +00:00
|
|
|
glfwSwapBuffers(slots[i].window);
|
2014-02-11 23:49:26 +00:00
|
|
|
}
|
2012-08-07 11:01:19 +00:00
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
printf("Main loop starting\n");
|
|
|
|
|
2014-02-11 23:49:26 +00:00
|
|
|
for (;;)
|
2013-04-17 13:31:20 +00:00
|
|
|
{
|
2014-02-11 23:49:26 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (glfwWindowShouldClose(slots[i].window))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < count)
|
|
|
|
break;
|
|
|
|
|
2011-09-08 20:45:35 +00:00
|
|
|
glfwWaitEvents();
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2013-04-17 13:31:20 +00:00
|
|
|
// Workaround for an issue with msvcrt and mintty
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2014-02-11 23:49:26 +00:00
|
|
|
free(slots);
|
2010-09-07 15:34:51 +00:00
|
|
|
glfwTerminate();
|
2011-09-08 20:47:37 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|