Skip to content

Commit

Permalink
Add GLFW_X11_DPI_RESIZE
Browse files Browse the repository at this point in the history
Related to #676.
Related to #1115.
  • Loading branch information
elmindreda committed Aug 22, 2018
1 parent cd89176 commit 67edd2b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/window.dox
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ __GLFW_X11_CLASS_NAME__ and __GLFW_X11_INSTANCE_NAME__ specifies the desired
ASCII encoded class and instance parts of the ICCCM `WM_CLASS` window property.
These are set with @ref glfwWindowHintString.

@anchor GLFW_X11_DPI_RESIZE
__GLFW_X11_DPI_RESIZE__ specifies whether to scale the window content size at
creation by the desktop content scale. Possible values are `GLFW_TRUE` and
`GLFW_FALSE`. This is ignored on other platforms.


@subsubsection window_hints_win32 Win32 specific window hints

Expand Down Expand Up @@ -532,6 +537,7 @@ GLFW_COCOA_FRAME_NAME | `""` | A UTF-8 encoded fr
GLFW_COCOA_GRAPHICS_SWITCHING | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
GLFW_X11_CLASS_NAME | `""` | An ASCII encoded `WM_CLASS` class name
GLFW_X11_INSTANCE_NAME | `""` | An ASCII encoded `WM_CLASS` instance name
GLFW_X11_DPI_RESIZE | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
GLFW_WIN32_DPI_RESIZE | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`


Expand Down
1 change: 1 addition & 0 deletions examples/boing.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ int main( void )
exit( EXIT_FAILURE );

glfwWindowHint(GLFW_WIN32_DPI_RESIZE, GLFW_TRUE);
glfwWindowHint(GLFW_X11_DPI_RESIZE, GLFW_TRUE);

window = glfwCreateWindow( 400, 400, "Boing (classic Amiga demo)", NULL, NULL );
if (!window)
Expand Down
1 change: 1 addition & 0 deletions include/GLFW/glfw3.h
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ extern "C" {

#define GLFW_X11_CLASS_NAME 0x00024001
#define GLFW_X11_INSTANCE_NAME 0x00024002
#define GLFW_X11_DPI_RESIZE 0x00024003

#define GLFW_WIN32_DPI_RESIZE 0x00025001
/*! @} */
Expand Down
1 change: 1 addition & 0 deletions src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ struct _GLFWwndconfig
struct {
char className[256];
char instanceName[256];
GLFWbool dpiResize;
} x11;
struct {
GLFWbool dpiResize;
Expand Down
3 changes: 3 additions & 0 deletions src/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ GLFWAPI void glfwWindowHint(int hint, int value)
case GLFW_COCOA_GRAPHICS_SWITCHING:
_glfw.hints.context.nsgl.offline = value ? GLFW_TRUE : GLFW_FALSE;
return;
case GLFW_X11_DPI_RESIZE:
_glfw.hints.window.x11.dpiResize = value ? GLFW_TRUE : GLFW_FALSE;
return;
case GLFW_WIN32_DPI_RESIZE:
_glfw.hints.window.win32.dpiResize = value ? GLFW_TRUE : GLFW_FALSE;
return;
Expand Down
13 changes: 11 additions & 2 deletions src/x11_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,15 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig,
Visual* visual, int depth)
{
int width = wndconfig->width;
int height = wndconfig->height;

if (wndconfig->x11.dpiResize)
{
width *= _glfw.x11.contentScaleX;
height *= _glfw.x11.contentScaleY;
}

// Create a colormap based on the visual used by the current context
window->x11.colormap = XCreateColormap(_glfw.x11.display,
_glfw.x11.root,
Expand All @@ -657,7 +666,7 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
window->x11.handle = XCreateWindow(_glfw.x11.display,
_glfw.x11.root,
0, 0,
wndconfig->width, wndconfig->height,
width, height,
0, // Border width
depth, // Color depth
InputOutput,
Expand Down Expand Up @@ -760,7 +769,7 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
XFree(hints);
}

updateNormalHints(window, wndconfig->width, wndconfig->height);
updateNormalHints(window, width, height);

// Set ICCCM WM_CLASS property
{
Expand Down

0 comments on commit 67edd2b

Please sign in to comment.