Draw the window frame on windows and on x11

The engine already draws the bar on wayland; the GLFW backend now does the
same where the client may move its own window, and keeps the native frame
elsewhere: wayland forbids client side positioning, and macOS has its own
frame.

On windows the native frame is kept and only its caption is hidden, so the
thick frame, the shadow, the animations and the snap layouts keep working.
A window procedure returns HTCAPTION for the bar, HTCLIENT for the controls
and HT* for the edges. On x11 the window manager runs the interactive move
or resize (_NET_WM_MOVERESIZE), which keeps window snapping and tiling
native too. Where neither is available the frame moves and resizes the
window itself, as before.

The X11 accessors of GLFW are resolved with dlsym, so a wayland-only build
still links, and the window manager operations are only compiled in when
X11 is found.

The title of the window is stored on creation now: the bar draws it, and
the GLFW backend used to leave it empty.
This commit is contained in:
alexei-zebra 2026-10-10 15:30:55 +03:00
parent b9a13c853d
commit 56a225fe15
No known key found for this signature in database
GPG key ID: D19D450AC3D9A80E
5 changed files with 765 additions and 6 deletions

View file

@ -7,8 +7,24 @@ target_compile_options(VoxelWindowBase PRIVATE ${VOXEL_COMPILE_OPTIONS})
target_link_libraries(VoxelWindowBase PRIVATE VoxelCoreInterface)
add_library(VoxelGLFW STATIC GLFWWindow.cpp)
add_library(VoxelGLFW STATIC GLFWWindow.cpp FrameOperations.cpp)
target_compile_options(VoxelGLFW PRIVATE ${VOXEL_COMPILE_OPTIONS})
target_link_libraries(VoxelGLFW PRIVATE VoxelWindowBase VoxelCoreInterface)
target_link_libraries(
VoxelGLFW PRIVATE VoxelWindowBase VoxelCoreInterface ${CMAKE_DL_LIBS})
# On X11 the window manager moves and resizes the window when the engine draws
# the frame. A wayland-only build of GLFW does not answer, and the frame then
# falls back to moving the window itself.
if(UNIX AND NOT APPLE)
find_package(X11)
if(X11_FOUND)
target_compile_definitions(VoxelGLFW PRIVATE VOXEL_X11_FRAME=1)
target_include_directories(VoxelGLFW PRIVATE ${X11_INCLUDE_DIR})
target_link_libraries(VoxelGLFW PRIVATE ${X11_LIBRARIES})
message(STATUS "window frame: window manager operations are on")
else()
message(STATUS "window frame: window manager operations are off")
endif()
endif()

View file

@ -0,0 +1,97 @@
#pragma once
/// @brief Geometry of the window frame the engine draws itself.
///
/// Wayland has its own implementation because it also talks to the compositor,
/// this one is used by the backends that decorate their window by themselves.
/// It deliberately depends on nothing but the standard library, so the layout
/// and the hit testing can be checked without a window.
namespace frame {
constexpr int BAR_HEIGHT = 48;
constexpr int BAR_HEIGHT_COMPACT = 24;
constexpr int BUTTON = 24;
constexpr int PADDING = 12;
constexpr int GAP = 12;
constexpr int EDGE = 8;
constexpr int MAX_BUTTONS = 4;
constexpr int EDGE_TOP = 1;
constexpr int EDGE_BOTTOM = 2;
constexpr int EDGE_LEFT = 4;
constexpr int EDGE_RIGHT = 8;
struct Rect {
float x = 0.0f;
float width = 0.0f;
};
/// @brief Places the controls of the bar flush against the right edge.
/// @param count number of controls, ordered from left to right
/// @return number of placed controls, which is 0 for a window too narrow
inline int layoutButtons(
float windowWidth, int count, bool compact, Rect* out
) {
if (count > MAX_BUTTONS) {
count = MAX_BUTTONS;
}
const float padding = compact ? 0.0f : PADDING;
const float gap = compact ? 0.0f : GAP;
const float pitch = BUTTON + gap;
int placed = 0;
for (int i = 0; i < count; i++) {
const float x = windowWidth - padding - (count - i) * pitch + gap;
if (x < 0.0f) {
break;
}
out[placed++] = {x, static_cast<float>(BUTTON)};
}
return placed;
}
/// @brief Control under the pointer, or -1
inline int buttonAt(
const Rect* buttons, int count, int barHeight, float x, float y
) {
const int top = (barHeight - BUTTON) / 2;
if (y < top || y >= top + BUTTON) {
return -1;
}
for (int i = 0; i < count; i++) {
if (x >= buttons[i].x && x < buttons[i].x + buttons[i].width) {
return i;
}
}
return -1;
}
/// @brief What the pointer is over, in client coordinates
struct Hit {
/// the bar drags the window, which on win32 is the OS caption
bool caption = false;
/// resize edges, 0 when the pointer is not near any of them
int edges = 0;
};
/// @brief Resize edges grab-able at the given position, 0 when none
inline int edgesAt(
int width, int height, int barHeight, float x, float y
) {
int edges = 0;
if (y < EDGE) {
edges |= EDGE_TOP;
} else if (y >= height - EDGE) {
edges |= EDGE_BOTTOM;
}
// Inside the bar only its top strip resizes the window, the rest
// belongs to the controls and to dragging.
if (y < barHeight && y >= EDGE) {
return edges;
}
if (x < EDGE) {
edges |= EDGE_LEFT;
} else if (x >= width - EDGE) {
edges |= EDGE_RIGHT;
}
return edges;
}
}

View file

@ -0,0 +1,248 @@
#include "window/detail/FrameOperations.hpp"
#if defined(VOXEL_X11_FRAME)
#include <X11/Xlib.h>
#include <dlfcn.h>
#include <GLFW/glfw3.h>
namespace {
/// @brief X11 accessors of GLFW, resolved when they are really there
///
/// A wayland-only build of GLFW does not export them, and then the frame
/// moves the window itself instead of asking the window manager.
struct X11Api {
Display* (*display)() = nullptr;
Window (*window)(GLFWwindow*) = nullptr;
X11Api() {
display = reinterpret_cast<Display* (*)()>(
dlsym(RTLD_DEFAULT, "glfwGetX11Display")
);
window = reinterpret_cast<Window (*)(GLFWwindow*)>(
dlsym(RTLD_DEFAULT, "glfwGetX11Window")
);
if (display == nullptr || window == nullptr) {
display = nullptr;
window = nullptr;
}
}
bool available() const {
return display != nullptr && window != nullptr;
}
};
X11Api& x11_api() {
static X11Api api;
return api;
}
/// @brief Edge mask to the _NET_WM_MOVERESIZE direction
int x11_direction(int edges) {
switch (edges) {
case frame::EDGE_TOP | frame::EDGE_LEFT:
return 0;
case frame::EDGE_TOP:
return 1;
case frame::EDGE_TOP | frame::EDGE_RIGHT:
return 2;
case frame::EDGE_RIGHT:
return 3;
case frame::EDGE_BOTTOM | frame::EDGE_RIGHT:
return 4;
case frame::EDGE_BOTTOM:
return 5;
case frame::EDGE_BOTTOM | frame::EDGE_LEFT:
return 6;
default:
return 7;
}
}
constexpr int MOVERESIZE_MOVE = 8;
constexpr int SOURCE_APPLICATION = 1;
bool x11_request(GLFWwindow* glfwWindow, int direction) {
X11Api& api = x11_api();
if (!api.available()) {
return false;
}
Display* display = api.display();
const Window window = api.window(glfwWindow);
if (display == nullptr || window == 0) {
return false;
}
const Window root = DefaultRootWindow(display);
int rootX = 0, rootY = 0, windowX = 0, windowY = 0;
Window child = 0, rootReturn = 0;
unsigned int mask = 0;
XQueryPointer(
display,
root,
&rootReturn,
&child,
&rootX,
&rootY,
&windowX,
&windowY,
&mask
);
XEvent event {};
event.xclient.type = ClientMessage;
event.xclient.message_type =
XInternAtom(display, "_NET_WM_MOVERESIZE", False);
event.xclient.display = display;
event.xclient.window = window;
event.xclient.format = 32;
event.xclient.data.l[0] = rootX;
event.xclient.data.l[1] = rootY;
event.xclient.data.l[2] = direction;
event.xclient.data.l[3] = Button1;
event.xclient.data.l[4] = SOURCE_APPLICATION;
XUngrabPointer(display, CurrentTime);
XSendEvent(
display,
root,
False,
SubstructureRedirectMask | SubstructureNotifyMask,
&event
);
XFlush(display);
return true;
}
}
#elif defined(_WIN32)
#define NOMINMAX
#include <windows.h>
#include <windowsx.h>
#define GLFW_EXPOSE_NATIVE_WIN32
#include <GLFW/glfw3native.h>
namespace {
WNDPROC original_window_proc = nullptr;
frame::Hit (*hit_test_callback)(void*, int, int) = nullptr;
void* hit_test_userdata = nullptr;
LRESULT CALLBACK frame_window_proc(
HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam
) {
switch (message) {
case WM_NCCALCSIZE:
// the caption is gone, the whole window is the client area
if (wparam == TRUE) {
return 0;
}
break;
case WM_NCPAINT:
// the frame is not drawn by us
return 0;
case WM_NCACTIVATE:
// and it is not repainted when the window is activated
return TRUE;
case WM_NCHITTEST: {
if (hit_test_callback == nullptr) {
break;
}
POINT point {GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)};
ScreenToClient(hwnd, &point);
const frame::Hit hit =
hit_test_callback(hit_test_userdata, point.x, point.y);
if (hit.caption) {
return HTCAPTION;
}
switch (hit.edges) {
case frame::EDGE_TOP | frame::EDGE_LEFT:
return HTTOPLEFT;
case frame::EDGE_TOP:
return HTTOP;
case frame::EDGE_TOP | frame::EDGE_RIGHT:
return HTTOPRIGHT;
case frame::EDGE_RIGHT:
return HTRIGHT;
case frame::EDGE_BOTTOM | frame::EDGE_RIGHT:
return HTBOTTOMRIGHT;
case frame::EDGE_BOTTOM:
return HTBOTTOM;
case frame::EDGE_BOTTOM | frame::EDGE_LEFT:
return HTBOTTOMLEFT;
case frame::EDGE_LEFT:
return HTLEFT;
default:
return HTCLIENT;
}
}
}
return CallWindowProc(
original_window_proc, hwnd, message, wparam, lparam
);
}
}
#endif
bool frame_has_native_operations() {
#if defined(VOXEL_X11_FRAME)
return x11_api().available();
#else
return false;
#endif
}
bool frame_start_move(GLFWwindow* window) {
#if defined(VOXEL_X11_FRAME)
return x11_request(window, MOVERESIZE_MOVE);
#else
(void)window;
return false;
#endif
}
bool frame_start_resize(GLFWwindow* window, int edges) {
#if defined(VOXEL_X11_FRAME)
return edges != 0 && x11_request(window, x11_direction(edges));
#else
(void)window;
(void)edges;
return false;
#endif
}
void frame_setup_native(
GLFWwindow* window,
frame::Hit (*hitTest)(void*, int, int),
void* userdata
) {
#if defined(_WIN32)
HWND hwnd = glfwGetWin32Window(window);
if (hwnd == nullptr) {
return;
}
hit_test_callback = hitTest;
hit_test_userdata = userdata;
// The native frame stays: its thick frame is what gives the window the
// resize border, the shadow, the animations and the snap layouts. Only
// the caption is hidden, and the client area covers the whole window.
LONG_PTR style = GetWindowLongPtr(hwnd, GWL_STYLE);
style |= WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU;
style &= ~WS_CAPTION;
SetWindowLongPtr(hwnd, GWL_STYLE, style);
original_window_proc = reinterpret_cast<WNDPROC>(SetWindowLongPtr(
hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(frame_window_proc)
));
SetWindowPos(
hwnd,
nullptr,
0,
0,
0,
0,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
);
#else
(void)window;
(void)hitTest;
(void)userdata;
#endif
}

View file

@ -0,0 +1,28 @@
#pragma once
#include "window/detail/FrameLayout.hpp"
struct GLFWwindow;
/// @name Window operations the window manager performs itself
///
/// The frame is drawn by the engine, but moving and resizing are better left
/// to the window manager: it keeps window snapping, tiling and the resize
/// feedback native. Every function returns false when that is not available
/// and the caller has to move or resize the window on its own.
/// @{
/// @brief Whether the window manager can be asked to do it
bool frame_has_native_operations();
/// @brief Ask the window manager to start moving the window
bool frame_start_move(GLFWwindow* window);
/// @brief Ask the window manager to start resizing the window
bool frame_start_resize(GLFWwindow* window, int edges);
/// @brief Hide the caption of the native frame, keeping the rest of it
/// @param hitTest tells what the pointer is over
void frame_setup_native(GLFWwindow* window, frame::Hit (*hitTest)(void*, int, int), void* userdata);
/// @}

View file

@ -1,5 +1,7 @@
#include "window/Window.hpp"
#include "window/detail/BaseInput.hpp"
#include "window/detail/FrameLayout.hpp"
#include "window/detail/FrameOperations.hpp"
#include "window/detail/WindowBackends.hpp"
#include <GL/glew.h>
@ -7,6 +9,7 @@
#include <unordered_set>
#include <chrono>
#include <cmath>
#include <stack>
#include <vector>
@ -33,6 +36,26 @@ static const char* get_platform_name() {
return "unknown";
}
/// @brief Whether the engine draws the window frame itself.
///
/// Only where the client is allowed to move and resize its own window:
/// wayland forbids that, and on macOS the system frame is the expected one.
static bool use_engine_frame() {
#if defined(_WIN32)
return true;
#elif defined(__linux__)
#if GLFW_VERSION_MAJOR > 3 || \
(GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 4)
return glfwGetPlatform() == GLFW_PLATFORM_X11;
#else
// GLFW 3.3 has no wayland backend at all
return true;
#endif
#else
return false;
#endif
}
static std::unordered_set<std::string> supported_gl_extensions;
static void window_size_callback(GLFWwindow* window, int width, int height);
@ -255,12 +278,17 @@ public:
GLFWwindow* window,
DisplaySettings* settings,
int width,
int height
int height,
bool engineFrame
)
: Window({width, height}),
input(glfwInput),
settings(settings),
window(window) {
window(window),
engineFrame(engineFrame) {
if (engineFrame) {
frame_setup_native(window, &frame_hit_test, this);
}
}
~GLFWWindow() {
@ -303,6 +331,148 @@ public:
return false;
}
int barHeight() const {
if (!engineFrame || mode != WindowMode::WINDOWED) {
return 0;
}
return settings->compactWindowBar.get() ? frame::BAR_HEIGHT_COMPACT
: frame::BAR_HEIGHT;
}
int getDecorationHeight() const override {
return barHeight();
}
const std::vector<DecorationButtonLayout>& getDecorationButtons() const
override {
buttonRects.clear();
if (barHeight() <= 0) {
return buttonRects;
}
frame::Rect rects[frame::MAX_BUTTONS];
const int count = layoutFrameButtons(rects);
for (int i = 0; i < count; i++) {
buttonRects.push_back({frameButtons[i], rects[i].x, rects[i].width});
}
return buttonRects;
}
int getDecorationHoveredButton() const override {
return hoveredButton;
}
/// @brief What the pointer is over, in client coordinates
frame::Hit hitTestFrame(int x, int y) const {
const int height = barHeight();
if (height <= 0) {
return frame::Hit {};
}
frame::Rect rects[frame::MAX_BUTTONS];
const int count = layoutFrameButtons(rects);
if (frame::buttonAt(
rects,
count,
height,
static_cast<float>(x),
static_cast<float>(y)
) >= 0) {
return frame::Hit {};
}
if (y < height) {
return frame::Hit {true, 0};
}
return frame::Hit {
false,
frame::edgesAt(
getSize().x,
getSize().y,
height,
static_cast<float>(x),
static_cast<float>(y)
)};
}
/// @brief Turns a pointer move into hovering, dragging or resizing
void handleFrameMotion(double x, double y) {
if (input.isCursorLocked() || barHeight() <= 0) {
hoveredButton = -1;
return;
}
if (dragging || resizeEdges != 0) {
updateFrameDrag();
}
updateFrameHover(x, y);
}
/// @brief Turns a pointer button into a frame action
/// @return whether the frame handled the event
bool handleFrameButton(int button, bool pressed, double x, double y) {
if (button != GLFW_MOUSE_BUTTON_LEFT || input.isCursorLocked() ||
barHeight() <= 0) {
return false;
}
if (!pressed) {
if (pressedButton >= 0) {
const int index = pressedButton;
pressedButton = -1;
if (index == hoveredButton) {
activateFrameButton(index);
}
return true;
}
if (dragging) {
dragging = false;
if (frameMoved) {
lastBarClick = 0.0;
}
return true;
}
if (resizeEdges != 0) {
resizeEdges = 0;
return true;
}
return false;
}
updateFrameHover(x, y);
if (hoveredButton >= 0) {
pressedButton = hoveredButton;
return true;
}
const frame::Hit hit = hitTestFrame(
static_cast<int>(x), static_cast<int>(y)
);
if (hit.caption) {
const double now = glfwGetTime();
if (lastBarClick > 0.0 && now - lastBarClick < DOUBLE_CLICK_TIME) {
lastBarClick = 0.0;
toggleMaximize();
return true;
}
lastBarClick = now;
if (frame_start_move(window)) {
return true;
}
dragging = true;
frameMoved = false;
grabX = x;
grabY = y;
return true;
}
if (hit.edges == 0) {
return false;
}
if (frame_start_resize(window, hit.edges)) {
return true;
}
resizeEdges = hit.edges;
resizeStartW = getSize().x;
resizeStartH = getSize().y;
glfwGetWindowPos(window, &resizeStartX, &resizeStartY);
grabScreenX = resizeStartX + x;
grabScreenY = resizeStartY + y;
return true;
}
bool isMaximized() const override {
return glfwGetWindowAttrib(window, GLFW_MAXIMIZED);
}
@ -364,7 +534,7 @@ public:
settings->height.get(),
GLFW_DONT_CARE
);
glfwSetWindowAttrib(window, GLFW_DECORATED, GLFW_TRUE);
applyDecoration();
glfwSetWindowAttrib(window, GLFW_RESIZABLE, GLFW_TRUE);
window_size_callback(window, settings->width.get(), settings->height.get());
}
@ -441,7 +611,191 @@ public:
}
private:
int layoutFrameButtons(frame::Rect* rects) const {
return frame::layoutButtons(
static_cast<float>(getSize().x),
static_cast<int>(frameButtons.size()),
settings->compactWindowBar.get(),
rects
);
}
void updateFrameHover(double x, double y) {
const int height = barHeight();
frame::Rect rects[frame::MAX_BUTTONS];
const int count = layoutFrameButtons(rects);
hoveredButton = frame::buttonAt(
rects, count, height, static_cast<float>(x), static_cast<float>(y)
);
if (dragging || resizeEdges != 0) {
return;
}
// inside the bar the controls win over the resize edges
const int edges = hoveredButton < 0
? frame::edgesAt(
getSize().x,
getSize().y,
height,
static_cast<float>(x),
static_cast<float>(y)
)
: 0;
if (edges != 0) {
setCursor(edgeCursor(edges));
} else if (y < height) {
setCursor(CursorShape::ARROW);
}
}
void updateFrameDrag() {
double x = 0.0, y = 0.0;
glfwGetCursorPos(window, &x, &y);
int windowX = 0, windowY = 0;
glfwGetWindowPos(window, &windowX, &windowY);
if (dragging) {
const double dx = x - grabX;
const double dy = y - grabY;
if (std::abs(dx) > MOVE_THRESHOLD || std::abs(dy) > MOVE_THRESHOLD) {
frameMoved = true;
}
glfwSetWindowPos(
window,
windowX + static_cast<int>(std::lround(dx)),
windowY + static_cast<int>(std::lround(dy))
);
return;
}
const double dx = (windowX + x) - grabScreenX;
const double dy = (windowY + y) - grabScreenY;
int width = resizeStartW;
int height = resizeStartH;
int newX = resizeStartX;
int newY = resizeStartY;
if (resizeEdges & frame::EDGE_LEFT) {
width = resizeStartW - static_cast<int>(std::lround(dx));
newX = resizeStartX + static_cast<int>(std::lround(dx));
} else if (resizeEdges & frame::EDGE_RIGHT) {
width = resizeStartW + static_cast<int>(std::lround(dx));
}
if (resizeEdges & frame::EDGE_TOP) {
height = resizeStartH - static_cast<int>(std::lround(dy));
newY = resizeStartY + static_cast<int>(std::lround(dy));
} else if (resizeEdges & frame::EDGE_BOTTOM) {
height = resizeStartH + static_cast<int>(std::lround(dy));
}
if (width < MIN_WIDTH) {
if (resizeEdges & frame::EDGE_LEFT) {
newX = resizeStartX + (resizeStartW - MIN_WIDTH);
}
width = MIN_WIDTH;
}
if (height < MIN_HEIGHT) {
if (resizeEdges & frame::EDGE_TOP) {
newY = resizeStartY + (resizeStartH - MIN_HEIGHT);
}
height = MIN_HEIGHT;
}
glfwSetWindowSize(window, width, height);
glfwSetWindowPos(window, newX, newY);
}
void activateFrameButton(int index) {
if (index < 0 || index >= static_cast<int>(frameButtons.size())) {
return;
}
switch (frameButtons[index]) {
case DecorationButton::MINIMIZE:
glfwIconifyWindow(window);
break;
case DecorationButton::MAXIMIZE:
toggleMaximize();
break;
case DecorationButton::CLOSE:
glfwSetWindowShouldClose(window, true);
break;
}
}
void toggleMaximize() {
if (glfwGetWindowAttrib(window, GLFW_MAXIMIZED)) {
glfwRestoreWindow(window);
} else {
glfwMaximizeWindow(window);
}
setShouldRefresh();
}
void applyDecoration() {
if (engineFrame) {
// frame_setup_native() owns the window style, GLFW would drop the
// thick frame the native resize border and snapping need
return;
}
glfwSetWindowAttrib(window, GLFW_DECORATED, GLFW_TRUE);
}
static frame::Hit frame_hit_test(void* userdata, int x, int y) {
return static_cast<GLFWWindow*>(userdata)->hitTestFrame(x, y);
}
static CursorShape edgeCursor(int edges) {
const bool left = edges & frame::EDGE_LEFT;
const bool right = edges & frame::EDGE_RIGHT;
const bool top = edges & frame::EDGE_TOP;
const bool bottom = edges & frame::EDGE_BOTTOM;
if (left && top) {
return CursorShape::NW_RESIZE;
}
if (right && top) {
return CursorShape::NE_RESIZE;
}
if (left && bottom) {
return CursorShape::SW_RESIZE;
}
if (right && bottom) {
return CursorShape::SE_RESIZE;
}
if (left) {
return CursorShape::W_RESIZE;
}
if (right) {
return CursorShape::E_RESIZE;
}
if (top) {
return CursorShape::N_RESIZE;
}
if (bottom) {
return CursorShape::S_RESIZE;
}
return CursorShape::ARROW;
}
GLFWwindow* window;
bool engineFrame = false;
std::vector<DecorationButton> frameButtons {
DecorationButton::MINIMIZE,
DecorationButton::MAXIMIZE,
DecorationButton::CLOSE,
};
mutable std::vector<DecorationButtonLayout> buttonRects;
int hoveredButton = -1;
int pressedButton = -1;
bool dragging = false;
bool frameMoved = false;
double grabX = 0.0;
double grabY = 0.0;
int resizeEdges = 0;
int resizeStartX = 0;
int resizeStartY = 0;
int resizeStartW = 0;
int resizeStartH = 0;
double grabScreenX = 0.0;
double grabScreenY = 0.0;
double lastBarClick = 0.0;
static constexpr double DOUBLE_CLICK_TIME = 0.4;
static constexpr double MOVE_THRESHOLD = 4.0;
static constexpr int MIN_WIDTH = 320;
static constexpr int MIN_HEIGHT = 200;
CursorShape cursor = CursorShape::ARROW;
int framerate = -1;
double prevSwap = 0.0;
@ -453,6 +807,12 @@ static_assert(!std::is_abstract<GLFWWindow>());
static void mouse_button_callback(GLFWwindow* window, int button, int action, int) {
auto handler = static_cast<GLFWWindow*>(glfwGetWindowUserPointer(window));
double x = 0.0, y = 0.0;
glfwGetCursorPos(window, &x, &y);
if (handler->handleFrameButton(button, action == GLFW_PRESS, x, y)) {
handler->setShouldRefresh();
return;
}
handler->input.onMouseCallback(button, action == GLFW_PRESS);
handler->setShouldRefresh();
}
@ -499,6 +859,7 @@ static void scroll_callback(GLFWwindow* window, double, double yoffset) {
static void cursor_pos_callback(GLFWwindow* window, double xpos, double ypos) {
auto handler = static_cast<GLFWWindow*>(glfwGetWindowUserPointer(window));
handler->input.setCursorPosition(xpos, ypos);
handler->handleFrameMotion(xpos, ypos);
handler->setShouldRefresh();
}
@ -557,6 +918,12 @@ std::tuple<
}
logger.info() << "windowing platform: " << get_platform_name();
const bool engineFrame = use_engine_frame();
if (engineFrame) {
// the engine draws the window bar, the system frame must be gone
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
#if GLFW_VERSION_MAJOR >= 3 && GLFW_VERSION_MINOR >= 4
@ -636,8 +1003,11 @@ std::tuple<
auto inputPtr = std::make_unique<GLFWInput>(window);
auto windowPtr = std::make_unique<GLFWWindow>(
*inputPtr, window, settings, width, height
*inputPtr, window, settings, width, height, engineFrame
);
// the engine draws the window bar from the title, and this is the only
// place the initial one is known
windowPtr->setTitle(title);
glfwSetWindowUserPointer(window, windowPtr.get());
return {std::move(windowPtr), std::move(inputPtr)};
}