Add glfwInitHintString

Adds string type init hints.  Adds X11 specific init hints for WM_CLASS
components.  Documentation work.

Fixes #893.
This commit is contained in:
Camilla Löwy
2017-07-25 01:55:08 +02:00
parent 00d2efb9ab
commit 213dd2d0d6
7 changed files with 139 additions and 34 deletions

View File

@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>
// The global variables below comprise all global data in GLFW.
@@ -48,10 +49,14 @@ static _GLFWerror _glfwMainThreadError;
static GLFWerrorfun _glfwErrorCallback;
static _GLFWinitconfig _glfwInitHints =
{
GLFW_TRUE, // hat buttons
GLFW_TRUE, // hat buttons
{
GLFW_TRUE, // menubar
GLFW_TRUE // chdir
GLFW_TRUE, // macOS menu bar
GLFW_TRUE // macOS bundle chdir
},
{
"", // X11 WM_CLASS name
"" // X11 WM_CLASS class
}
};
@@ -243,7 +248,28 @@ GLFWAPI void glfwInitHint(int hint, int value)
return;
}
_glfwInputError(GLFW_INVALID_ENUM, "Invalid init hint 0x%08X", hint);
_glfwInputError(GLFW_INVALID_ENUM,
"Invalid integer type init hint 0x%08X", hint);
}
GLFWAPI void glfwInitHintString(int hint, const char* value)
{
assert(value != NULL);
switch (hint)
{
case GLFW_X11_WM_CLASS_NAME:
strncpy(_glfwInitHints.x11.className, value,
sizeof(_glfwInitHints.x11.className) - 1);
break;
case GLFW_X11_WM_CLASS_CLASS:
strncpy(_glfwInitHints.x11.classClass, value,
sizeof(_glfwInitHints.x11.classClass) - 1);
break;
}
_glfwInputError(GLFW_INVALID_ENUM,
"Invalid string type init hint 0x%08X", hint);
}
GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev)

View File

@@ -277,6 +277,10 @@ struct _GLFWinitconfig
GLFWbool menubar;
GLFWbool chdir;
} ns;
struct {
char className[256];
char classClass[256];
} x11;
};
/*! @brief Window configuration.

View File

@@ -614,13 +614,25 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
updateNormalHints(window, wndconfig->width, wndconfig->height);
// Set ICCCM WM_CLASS property
// HACK: Until a mechanism for specifying the application name is added, the
// initial window title is used as the window class name
if (strlen(wndconfig->title))
{
XClassHint* hint = XAllocClassHint();
hint->res_name = (char*) wndconfig->title;
hint->res_class = (char*) wndconfig->title;
if (strlen(_glfw.hints.init.x11.className) &&
strlen(_glfw.hints.init.x11.classClass))
{
hint->res_name = (char*) _glfw.hints.init.x11.className;
hint->res_class = (char*) _glfw.hints.init.x11.classClass;
}
else if (strlen(wndconfig->title))
{
hint->res_name = (char*) wndconfig->title;
hint->res_class = (char*) wndconfig->title;
}
else
{
hint->res_name = (char*) "glfw-application";
hint->res_class = (char*) "GLFW-Application";
}
XSetClassHint(_glfw.x11.display, window->x11.handle, hint);
XFree(hint);