summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/window.h5
-rw-r--r--src/window_glfm.c4
-rw-r--r--src/window_glfw.c34
-rw-r--r--src/window_glfw.h6
-rw-r--r--src/window_wayland.c7
-rw-r--r--src/window_wayland.h1
-rw-r--r--src/window_x11.c3
-rw-r--r--src/window_x11.h1
8 files changed, 45 insertions, 16 deletions
diff --git a/src/window.h b/src/window.h
index 37146ea..afe797e 100644
--- a/src/window.h
+++ b/src/window.h
@@ -15,7 +15,6 @@
#endif
#include <al/types.h>
-#include <al/array.h>
#include <al/lib.h>
#include <al/ring_buffer.h>
@@ -86,8 +85,8 @@ struct stl_window {
const char *const *(*vk_get_extensions)(u32 *);
#elif defined STELA_API_OPENGL
#ifdef STELA_USE_EGL
- EGLDisplay display;
- EGLContext context;
+ EGLDisplay egl_display;
+ EGLContext egl_context;
#endif
void (*(*get_gl_proc_address)(const char *))(void);
bool (*gl_loader_load)(void *);
diff --git a/src/window_glfm.c b/src/window_glfm.c
index 74310f7..4e4f034 100644
--- a/src/window_glfm.c
+++ b/src/window_glfm.c
@@ -37,6 +37,10 @@ static bool window_glfm_create_window(struct stl_window *window, s32 width, s32
glfmGetDisplaySize(glfm->display, &width, &height);
glfm->w.width = width;
glfm->w.height = height;
+#ifdef STELA_USE_EGL
+ glfm->w.egl_display = (EGLDisplay)glfmGetEglDisplay(glfm->display);
+ glfm->w.egl_context = (EGLContext)glfmGetEglContext(glfm->display);
+#endif
return true;
}
diff --git a/src/window_glfw.c b/src/window_glfw.c
index c85c14c..dbf6a70 100644
--- a/src/window_glfw.c
+++ b/src/window_glfw.c
@@ -172,6 +172,10 @@ static bool window_glfw_create_window(struct stl_window *window, s32 width, s32
}
#ifdef STELA_API_OPENGL
+#ifdef STELA_USE_EGL
+ glfw->w.egl_display = glfwGetEGLDisplay();
+ glfw->w.egl_context = glfwGetEGLContext(glfw->window);
+#endif
glfwMakeContextCurrent(glfw->window);
glfwSwapInterval((flags & STELA_WINDOW_VSYNC) ? 1 : 0);
glfwMakeContextCurrent(NULL);
@@ -182,6 +186,11 @@ static bool window_glfw_create_window(struct stl_window *window, s32 width, s32
glfwGetFramebufferSize(glfw->window, &glfw->w.width, &glfw->w.height);
glfwSetWindowSizeLimits(glfw->window, STELA_MIN_WIDTH, STELA_MIN_HEIGHT, GLFW_DONT_CARE, GLFW_DONT_CARE);
+ glfw->prev.x = 0;
+ glfw->prev.y = 0;
+ glfw->prev.width = 0;
+ glfw->prev.height = 0;
+
glfwSetWindowUserPointer(glfw->window, glfw);
glfwSetKeyCallback(glfw->window, key_callback);
@@ -213,17 +222,21 @@ static void window_glfw_resize(struct stl_window *window, s32 width, s32 height)
}
// https://stackoverflow.com/a/31526753
-static GLFWmonitor *get_current_monitor(GLFWwindow *window)
+static GLFWmonitor *get_current_monitor(GLFWwindow *window, s32 wx, s32 wy)
{
+ if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) {
+ // Calculating the current monitor doesn't work on Wayland
+ // because we can't know the position of the window.
+ return glfwGetPrimaryMonitor();
+ }
+
s32 monitor_count;
GLFWmonitor **monitors = glfwGetMonitors(&monitor_count);
if (monitor_count == 0) return NULL;
GLFWmonitor *best_monitor = monitors[0];
- s32 wx, wy;
s32 ww, wh;
- glfwGetWindowPos(window, &wx, &wy);
glfwGetWindowSize(window, &ww, &wh);
const GLFWvidmode *mode;
@@ -257,13 +270,18 @@ static void window_glfw_toggle_fullscreen(struct stl_window *window)
{
struct stl_window_glfw *glfw = (struct stl_window_glfw *)window;
if (!glfw->w.fullscreen) {
- glfwGetWindowPos(glfw->window, &glfw->prev.x, &glfw->prev.y);
- glfw->prev.width = glfw->w.width;
- glfw->prev.height = glfw->w.height;
- GLFWmonitor *monitor = get_current_monitor(glfw->window);
+ if (glfwGetPlatform() != GLFW_PLATFORM_WAYLAND) {
+ glfwGetWindowPos(glfw->window, &glfw->prev.x, &glfw->prev.y);
+ }
+ GLFWmonitor *monitor = get_current_monitor(glfw->window, glfw->prev.x, glfw->prev.y);
if (!monitor) return;
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
- glfwSetWindowMonitor(glfw->window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
+ f32 xscale, yscale;
+ glfwGetMonitorContentScale(monitor, &xscale, &yscale);
+ glfw->prev.width = glfw->w.width / xscale;
+ glfw->prev.height = glfw->w.height / yscale;
+ glfwSetWindowMonitor(glfw->window, monitor, 0, 0,
+ mode->width / xscale, mode->height / yscale, mode->refreshRate);
//glfwSetInputMode(glfw->window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
} else {
glfwSetWindowMonitor(glfw->window, NULL, glfw->prev.x, glfw->prev.y,
diff --git a/src/window_glfw.h b/src/window_glfw.h
index 67cf63a..f834f29 100644
--- a/src/window_glfw.h
+++ b/src/window_glfw.h
@@ -2,10 +2,14 @@
#ifdef STELA_API_VULKAN
#define GLFW_INCLUDE_VULKAN
+#else
+#define GLFW_INCLUDE_NONE
#endif
#include <GLFW/glfw3.h>
-#ifndef _WIN32
+#ifdef STELA_USE_EGL
#define GLFW_EXPOSE_NATIVE_EGL
+#define GLFW_NATIVE_INCLUDE_NONE
+#include "egl_common.h"
#include <GLFW/glfw3native.h>
#endif
diff --git a/src/window_wayland.c b/src/window_wayland.c
index d37d5d6..40886c2 100644
--- a/src/window_wayland.c
+++ b/src/window_wayland.c
@@ -215,6 +215,7 @@ static void pointer_enter(void *data, struct wl_pointer *pointer,
struct stl_window_wayland *wl = (struct stl_window_wayland *)data;
(void)pointer;
global.active_surface = surface;
+ //wl_pointer_set_cursor(wl->pointer, serial, NULL, 0, 0);
if (wl->cursor_shape_device) {
wp_cursor_shape_device_v1_set_shape(wl->cursor_shape_device, serial, WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT);
}
@@ -681,8 +682,8 @@ static bool wl_egl_init(struct stl_window_wayland *wl)
}
wl->w.get_gl_proc_address = eglGetProcAddress;
- wl->w.display = wl->egl.display;
- wl->w.context = wl->egl.context;
+ wl->w.egl_display = wl->egl.display;
+ wl->w.egl_context = wl->egl.context;
const EGLint surface_attr[] = {
EGL_RENDER_BUFFER, EGL_BACK_BUFFER,
@@ -703,7 +704,7 @@ static bool create_context_internal(struct stl_window_wayland *wl)
wl->fds[0].fd = global.display_fd;
wl->fds[0].events = POLLIN;
#if defined STELA_POLL_INLINE && defined STELA_PAUSE
- wl->fds[1].fd = eventfd(0, 0);
+ wl->fds[1].fd = nn_eventfd(0, 0);
wl->fds[1].events = POLLIN;
#endif
wl->registry = wl_display_get_registry(wl->display);
diff --git a/src/window_wayland.h b/src/window_wayland.h
index 9895463..05208d8 100644
--- a/src/window_wayland.h
+++ b/src/window_wayland.h
@@ -1,6 +1,7 @@
#pragma once
#include <al/lib.h>
+#include <al/array.h>
#include <nnwt/socket.h>
#include <wayland-client-core.h>
diff --git a/src/window_x11.c b/src/window_x11.c
index a0e9c69..b02d639 100644
--- a/src/window_x11.c
+++ b/src/window_x11.c
@@ -1,4 +1,5 @@
#include <al/log.h>
+#include <sys/eventfd.h>
#include "window_x11.h"
#include "common.h"
@@ -177,7 +178,7 @@ static bool window_x11_create_window(struct stl_window *window, s32 width, s32 h
xw->fds[0].events = POLLIN;
#if defined STELA_POLL_INLINE && defined STELA_PAUSE
- xw->fds[1].fd = eventfd(0, 0);
+ xw->fds[1].fd = nn_eventfd(0, 0);
xw->fds[1].events = POLLIN;
#endif
diff --git a/src/window_x11.h b/src/window_x11.h
index d198115..f8305dd 100644
--- a/src/window_x11.h
+++ b/src/window_x11.h
@@ -1,5 +1,6 @@
#pragma once
+#include <al/array.h>
#include <nnwt/socket.h>
#include <X11/Xlib.h>