summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2024-04-09 12:06:27 -0400
committerAndrew Opalach <andrew@akon.city> 2024-04-09 12:06:27 -0400
commit9ba7e92a7f9d5dc67867281df40fe059c7508ada (patch)
tree6536fbb4a2ee911d645008dfbd01cbfebad05acd
parentd8699c50f808f99b6cbec981a4d02fd6ed32cc6a (diff)
downloadstela-9ba7e92a7f9d5dc67867281df40fe059c7508ada.tar.gz
stela-9ba7e92a7f9d5dc67867281df40fe059c7508ada.tar.bz2
stela-9ba7e92a7f9d5dc67867281df40fe059c7508ada.zip
Allow null graphics api, add mouse3, cleanup
Signed-off-by: Andrew Opalach <andrew@akon.city>
-rw-r--r--meson.build4
-rw-r--r--meson_options.txt2
-rw-r--r--src/common.h4
-rw-r--r--src/gl_common.h2
-rw-r--r--src/poll_common.c3
-rw-r--r--src/window.h3
-rw-r--r--src/window_glfw.c4
-rw-r--r--src/window_wayland.c105
-rw-r--r--src/window_wayland.h2
-rw-r--r--subprojects/glfw3.wrap2
10 files changed, 96 insertions, 35 deletions
diff --git a/meson.build b/meson.build
index 7999d21..96109c8 100644
--- a/meson.build
+++ b/meson.build
@@ -36,7 +36,9 @@ if get_option('pause')
sekihi_args += ['-DSEKIHI_PAUSE']
endif
-if get_option('api') == 'opengl'
+if get_option('api') == 'null'
+ sekihi_args += ['-DSEKIHI_API_NULL']
+elif get_option('api') == 'opengl'
use_glad = false
if use_glad
sekihi_deps += [subproject('glad').get_variable('glad')]
diff --git a/meson_options.txt b/meson_options.txt
index d84eace..8f77cb3 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,4 +1,4 @@
-option('api', type: 'combo', choices: ['opengl', 'vulkan', 'dx11'], value: 'opengl')
+option('api', type: 'combo', choices: ['null', 'opengl', 'vulkan', 'dx11'], value: 'null')
option('window', type: 'combo', choices: ['glfw', 'wayland', 'x11'], value: 'wayland')
option('poll', type: 'combo', choices: ['inline', 'fd'], value: 'inline')
option('event-buffer', type: 'boolean', value: false)
diff --git a/src/common.h b/src/common.h
index 2ccc502..36856da 100644
--- a/src/common.h
+++ b/src/common.h
@@ -2,6 +2,8 @@
#include "window.h"
+AL_UNUSED_FUNCTION_PUSH
+
#if defined SEKIHI_PAUSE
static bool skh_should_refresh_common(struct skh_window *window)
{
@@ -12,3 +14,5 @@ static bool skh_should_refresh_common(struct skh_window *window)
return false;
}
#endif
+
+AL_UNUSED_FUNCTION_POP
diff --git a/src/gl_common.h b/src/gl_common.h
index cb15a42..bbab137 100644
--- a/src/gl_common.h
+++ b/src/gl_common.h
@@ -13,8 +13,10 @@
#ifdef SEKIHI_USE_GLES
#include <GLES2/gl2.h>
#else
+#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glext.h>
+#include <GL/glcorearb.h>
#endif
#endif
diff --git a/src/poll_common.c b/src/poll_common.c
index 965bf1d..0b9cd61 100644
--- a/src/poll_common.c
+++ b/src/poll_common.c
@@ -21,7 +21,8 @@ bool skh_poll_common(struct aki_pollfd *fds, bool block)
}
if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) { // Fatal error.
- al_log_error("poll_common", "poll() returned error in revents.");
+ al_log_error("poll_common", "poll() returned error in revents (%d).", fds[0].revents);
+ al_assert(false);
return false;
}
diff --git a/src/window.h b/src/window.h
index e1e5dce..753b062 100644
--- a/src/window.h
+++ b/src/window.h
@@ -126,7 +126,8 @@ enum {
enum {
SEKIHI_MOUSE1 = 0,
- SEKIHI_MOUSE2
+ SEKIHI_MOUSE2,
+ SEKIHI_MOUSE3
};
#define SEKIHI_EVENT_SIZE 32
diff --git a/src/window_glfw.c b/src/window_glfw.c
index 2d8b673..3858515 100644
--- a/src/window_glfw.c
+++ b/src/window_glfw.c
@@ -205,11 +205,11 @@ static void window_glfw_toggle_fullscreen(struct skh_window *window)
GLFWmonitor *monitor = get_current_monitor(glfw->window);
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
glfwSetWindowMonitor(glfw->window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
- glfwSetInputMode(glfw->window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
+ //glfwSetInputMode(glfw->window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
} else {
glfwSetWindowMonitor(glfw->window, NULL, glfw->prev_state.x, glfw->prev_state.y,
glfw->prev_state.width, glfw->prev_state.height, GLFW_DONT_CARE);
- glfwSetInputMode(glfw->window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
+ //glfwSetInputMode(glfw->window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
glfw->w.fullscreen = !glfw->w.fullscreen;
}
diff --git a/src/window_wayland.c b/src/window_wayland.c
index 0bf1c47..6ee5b7a 100644
--- a/src/window_wayland.c
+++ b/src/window_wayland.c
@@ -21,13 +21,13 @@ static void pointer_enter(void *data, struct wl_pointer *pointer,
struct skh_window_wayland *wl = (struct skh_window_wayland *)data;
(void)pointer;
(void)surface;
- wl->pointer_x = wl_fixed_to_double(surface_x);
- wl->pointer_y = wl_fixed_to_double(surface_y);
- wl->last_pointer_x = wl->pointer_x;
- wl->last_pointer_y = wl->pointer_y;
if (wl->cursor_shape_device) {
wp_cursor_shape_device_v1_set_shape(wl->cursor_shape_device, serial, WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT);
}
+ (void)surface_x;
+ (void)surface_y;
+ //wl->pointer_x = wl_fixed_to_double(surface_x);
+ //wl->pointer_y = wl_fixed_to_double(surface_y);
}
static void pointer_leave(void *data, struct wl_pointer *pointer,
@@ -45,11 +45,9 @@ static void pointer_motion(void *data, struct wl_pointer *pointer,
struct skh_window_wayland *wl = (struct skh_window_wayland *)data;
(void)pointer;
(void)time;
- wl->last_pointer_x = wl->pointer_x;
- wl->last_pointer_y = wl->pointer_y;
- wl->pointer_x = wl_fixed_to_double(surface_x);
- wl->pointer_y = wl_fixed_to_double(surface_y);
- skh_window_send_pointer_pos_event(&wl->w, wl->pointer_x, wl->pointer_y);
+ skh_window_send_pointer_pos_event(&wl->w, wl_fixed_to_double(surface_x), wl_fixed_to_double(surface_y));
+ //wl->pointer_x += wl_fixed_to_double(surface_x);
+ //wl->pointer_y += wl_fixed_to_double(surface_y);
}
static void pointer_button(void *data, struct wl_pointer *pointer,
@@ -60,6 +58,7 @@ static void pointer_button(void *data, struct wl_pointer *pointer,
(void)time;
#define MOUSE1 0x110
#define MOUSE2 0x111
+#define MOUSE3 0x112
if (button == MOUSE1) {
if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
skh_window_send_mouse_button_event(&wl->w, SEKIHI_BUTTON_PRESSED, SEKIHI_MOUSE1);
@@ -67,7 +66,21 @@ static void pointer_button(void *data, struct wl_pointer *pointer,
skh_window_send_mouse_button_event(&wl->w, SEKIHI_BUTTON_RELEASED, SEKIHI_MOUSE1);
}
} else if (button == MOUSE2) {
- xdg_toplevel_move(wl->xdg_toplevel, wl->seat, serial);
+ if (wl->xdg_toplevel) {
+ xdg_toplevel_move(wl->xdg_toplevel, wl->seat, serial);
+ } else {
+ if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
+ skh_window_send_mouse_button_event(&wl->w, SEKIHI_BUTTON_PRESSED, SEKIHI_MOUSE2);
+ } else if (state == WL_POINTER_BUTTON_STATE_RELEASED) {
+ skh_window_send_mouse_button_event(&wl->w, SEKIHI_BUTTON_RELEASED, SEKIHI_MOUSE2);
+ }
+ }
+ } else if (button == MOUSE3) {
+ if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
+ skh_window_send_mouse_button_event(&wl->w, SEKIHI_BUTTON_PRESSED, SEKIHI_MOUSE3);
+ } else if (state == WL_POINTER_BUTTON_STATE_RELEASED) {
+ skh_window_send_mouse_button_event(&wl->w, SEKIHI_BUTTON_RELEASED, SEKIHI_MOUSE3);
+ }
}
}
@@ -77,15 +90,33 @@ static void pointer_axis(void *data, struct wl_pointer *pointer,
struct skh_window_wayland *wl = (struct skh_window_wayland *)data;
(void)pointer;
(void)time;
+ // When using a seat version that supports high resolution scrolling (>4),
+ // there's some kind of unexplained difference in behavior here.
if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) {
+ //wl->scroll_y += wl_fixed_to_double(value);
skh_window_send_scroll_event(&wl->w, wl_fixed_to_double(value));
+ } else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
+ //wl->scroll_x += wl_fixed_to_double(value);
}
}
static void pointer_frame(void *data, struct wl_pointer *pointer)
{
- (void)data;
+ struct skh_window_wayland *wl = (struct skh_window_wayland *)data;
+ (void)wl;
(void)pointer;
+ /*
+ if (wl->pointer_x || wl->pointer_y) {
+ skh_window_send_pointer_pos_event(&wl->w, wl->pointer_x, wl->pointer_y);
+ }
+ if (wl->scroll_y) {
+ skh_window_send_scroll_event(&wl->w, wl->scroll_y);
+ }
+ wl->pointer_x = 0.0;
+ wl->pointer_y = 0.0;
+ wl->scroll_x = 0.0;
+ wl->scroll_y = 0.0;
+ */
}
static void pointer_axis_source(void *data, struct wl_pointer *pointer,
@@ -123,6 +154,15 @@ static void pointer_axis_value120(void *data, struct wl_pointer *pointer,
(void)value120;
}
+static void pointer_axis_relative_direction(void *data, struct wl_pointer *pointer,
+ u32 axis, u32 direction)
+{
+ (void)data;
+ (void)pointer;
+ (void)axis;
+ (void)direction;
+}
+
static const struct wl_pointer_listener pointer_listener = {
.enter = pointer_enter,
.leave = pointer_leave,
@@ -133,7 +173,8 @@ static const struct wl_pointer_listener pointer_listener = {
.axis_source = pointer_axis_source,
.axis_stop = pointer_axis_stop,
.axis_discrete = pointer_axis_discrete,
- .axis_value120 = pointer_axis_value120
+ .axis_value120 = pointer_axis_value120,
+ .axis_relative_direction = pointer_axis_relative_direction
};
static void keyboard_keymap(void *data, struct wl_keyboard *keyboard,
@@ -325,8 +366,7 @@ static void handle_output_name(void *data, struct wl_output *output, const char
struct skh_monitor_wayland *monitor = (struct skh_monitor_wayland *)data;
(void)output;
size_t len = strlen(name) + 1;
- len = AL_MIN(len, SEKIHI_MAX_MONITOR_NAME);
- al_memcpy(monitor->m.name, name, len);
+ al_memcpy(monitor->m.name, name, AL_MIN(len, SEKIHI_MAX_MONITOR_NAME));
}
static const struct wl_output_listener output_listener = {
@@ -421,7 +461,8 @@ static void global_add(void *data, struct wl_registry *registry, u32 name,
if (strcmp(interface, wl_compositor_interface.name) == 0) {
wl->compositor = wl_registry_bind(registry, name, &wl_compositor_interface, AL_MIN(5u, version));
} else if (strcmp(interface, wl_seat_interface.name) == 0) {
- wl->seat = wl_registry_bind(registry, name, &wl_seat_interface, AL_MIN(8u, version));
+ wl->seat = wl_registry_bind(registry, name, &wl_seat_interface, AL_MIN(4u, version));
+ //wl->seat = wl_registry_bind(registry, name, &wl_seat_interface, AL_MIN(8u, version));
wl_seat_add_listener(wl->seat, &seat_listener, wl);
} else if (strcmp(interface, wl_output_interface.name) == 0) {
struct skh_monitor_wayland *monitor = al_alloc_object(struct skh_monitor_wayland);
@@ -510,9 +551,11 @@ static bool check_and_set_dimensions(struct skh_window_wayland *wl, s32 width, s
static void send_resize_internal(struct skh_window_wayland *wl)
{
+#if defined SEKIHI_API_OPENGL
if (skh_egl_is_ready(&wl->egl)) {
wl_egl_window_resize(wl->egl_window, wl->w.width, wl->w.height, 0, 0);
}
+#endif
skh_window_send_resize_event(&wl->w, wl->w.width, wl->w.height);
wl->pending = false;
}
@@ -592,6 +635,7 @@ static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
.closed = handle_layer_surface_closed
};
+#if defined SEKIHI_API_OPENGL
static bool wl_egl_init(struct skh_window_wayland *wl)
{
if (!skh_maybe_load_egl(&wl->egl)) return false;
@@ -609,9 +653,7 @@ static bool wl_egl_init(struct skh_window_wayland *wl)
return false;
}
-#if defined SEKIHI_API_OPENGL
wl->w.get_gl_proc_address = eglGetProcAddress;
-#endif
const EGLint surface_attr[] = {
EGL_RENDER_BUFFER, EGL_BACK_BUFFER,
@@ -622,6 +664,7 @@ static bool wl_egl_init(struct skh_window_wayland *wl)
return true;
}
+#endif
static bool create_context_internal(struct skh_window_wayland *wl)
{
@@ -705,10 +748,12 @@ static bool window_wayland_create_window(struct skh_window *window, s32 width, s
zxdg_toplevel_decoration_v1_set_mode(wl->zxdg_toplevel_decoration, decor);
} else {
u32 surface = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND;
+ //u32 surface = ZWLR_LAYER_SHELL_V1_LAYER_TOP;
u32 anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
| ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM
| ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
+ //u32 anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
wl->layer_surface = zwlr_layer_shell_v1_get_layer_surface(wl->layer_shell,
wl->surface, wl->monitor->output, surface, name);
if (!wl->layer_surface) goto err;
@@ -720,30 +765,28 @@ static bool window_wayland_create_window(struct skh_window *window, s32 width, s
zwlr_layer_surface_v1_add_listener(wl->layer_surface, &layer_surface_listener, wl);
}
+#if defined SEKIHI_API_OPENGL
if (!wl_egl_init(wl)) goto err;
+#endif
wl_surface_commit(wl->surface);
wl_display_roundtrip(wl->display);
- /*
- struct wl_cursor_theme *cursor_theme = wl_cursor_theme_load(NULL, 24, shm);
- struct wl_cursor *cursor = wl_cursor_theme_get_cursor(cursor_theme, "left_ptr");
- wl->cursor.image = cursor->images[0];
- struct wl_buffer *cursor_buffer = wl_cursor_image_get_buffer(wl->cursor.image);
-
- wl->cursor.surface = wl_compositor_create_surface(wl->compositor);
- wl_surface_attach(wl->cursor.surface, cursor_buffer, 0, 0);
- wl_surface_commit(wl->cursor.surface);
- */
-
+#if defined SEKIHI_API_OPENGL
skh_egl_make_current(&wl->egl);
skh_egl_swap_interval(&wl->egl, (wl->flags & SEKIHI_WINDOW_VSYNC) ? 1 : 0);
skh_egl_release_current(&wl->egl);
+#endif
//wl->frame_done = 0;
//wl->frame_callback = wl_surface_frame(wl->surface);
//wl_callback_add_listener(wl->frame_callback, &frame_listener, wl);
+ wl->pointer_x = 0.0;
+ wl->pointer_y = 0.0;
+ wl->scroll_x = 0.0;
+ wl->scroll_y = 0.0;
+
return true;
err:
al_log_error("window_wayland", "Failed to create window.");
@@ -834,10 +877,12 @@ static void destroy_surface_internal(struct skh_window_wayland *wl)
} else if (wl->layer_surface) {
zwlr_layer_surface_v1_destroy(wl->layer_surface);
}
+#if defined SEKIHI_API_OPENGL
if (wl->egl_window) {
skh_egl_destroy_surface(&wl->egl);
wl_egl_window_destroy(wl->egl_window);
}
+#endif
if (wl->surface) wl_surface_destroy(wl->surface);
}
@@ -848,6 +893,8 @@ void window_wayland_free(struct skh_window **window)
if (wl->registry) wl_registry_destroy(wl->registry);
if (wl->seat) wl_seat_destroy(wl->seat);
if (wl->pointer) wl_pointer_destroy(wl->pointer);
+ if (wl->cursor_shape) wp_cursor_shape_manager_v1_destroy(wl->cursor_shape);
+ if (wl->cursor_shape_device) wp_cursor_shape_device_v1_destroy(wl->cursor_shape_device);
if (wl->keyboard) wl_keyboard_destroy(wl->keyboard);
if (wl->compositor) wl_compositor_destroy(wl->compositor);
for (u32 i = 0; i < wl->w.monitors.size; i++) {
@@ -861,10 +908,12 @@ void window_wayland_free(struct skh_window **window)
if (wl->layer_shell) zwlr_layer_shell_v1_destroy(wl->layer_shell);
if (wl->presentation) wp_presentation_destroy(wl->presentation);
destroy_surface_internal(wl);
+#if defined SEKIHI_API_OPENGL
if (skh_egl_is_ready(&wl->egl)) {
skh_egl_destroy_context(&wl->egl);
skh_egl_terminate(&wl->egl);
}
+#endif
wl_display_disconnect(wl->display);
#if defined SEKIHI_EVENT_BUFFER
al_free(wl->w.data);
diff --git a/src/window_wayland.h b/src/window_wayland.h
index 3f0acf2..12d7763 100644
--- a/src/window_wayland.h
+++ b/src/window_wayland.h
@@ -62,6 +62,8 @@ struct skh_window_wayland {
f64 pointer_y;
f64 last_pointer_x;
f64 last_pointer_y;
+ f64 scroll_x;
+ f64 scroll_y;
};
struct skh_window *skh_window_wayland_create(void);
diff --git a/subprojects/glfw3.wrap b/subprojects/glfw3.wrap
index 1612e20..c1166ba 100644
--- a/subprojects/glfw3.wrap
+++ b/subprojects/glfw3.wrap
@@ -1,5 +1,5 @@
[wrap-git]
url = https://github.com/glfw/glfw.git
-revision = 46cebb5081820418f2a20f3e90b07f9b1bd44b42
+revision = 228e58262e18f2ee61799bd86d0be718b1e31f9f
depth = 1
method = cmake