summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/keys.h10
-rw-r--r--src/poll_common.c2
-rw-r--r--src/window.c7
-rw-r--r--src/window.h18
-rw-r--r--src/window_glfm.c29
-rw-r--r--src/window_glfw.c8
-rw-r--r--src/window_kms.c7
-rw-r--r--src/window_x11.c16
8 files changed, 67 insertions, 30 deletions
diff --git a/src/keys.h b/src/keys.h
index a055c1d..7e5dfcf 100644
--- a/src/keys.h
+++ b/src/keys.h
@@ -4,11 +4,11 @@
#include <al/lib.h>
// Expected behavior of modifiers:
-// - Window keeps an internal state of all currently held modifiers.
-// - On window focus enter, if modifier is held, send BUTTON_PRESSED event.
-// - If a modifier was held on enter, it must still receive a BUTTON_RELEASED
-// event when the key is released.
-// - On window focus exit, send BUTTON_RELEASED for every active modifier.
+// - Window keeps an internal state of currently held modifiers.
+// - On window focus enter, if a modifier is held, send BUTTON_PRESSED event.
+// - If a modifier was held on enter, it must still receive a BUTTON_RELEASED
+// event when the key is released.
+// - On window focus exit, send BUTTON_RELEASED for every held modifier.
enum {
STELA_MOD_NONE = 0,
STELA_MOD_LCONTROL = 1,
diff --git a/src/poll_common.c b/src/poll_common.c
index 0b8cb79..868fa46 100644
--- a/src/poll_common.c
+++ b/src/poll_common.c
@@ -1,6 +1,6 @@
#define AL_LOG_SECTION "poll"
#include <al/log.h>
-#include <nnwt/common.h>
+#include <nnwt/error.h>
#include "poll_common.h"
diff --git a/src/window.c b/src/window.c
index 0d448af..f85f4fc 100644
--- a/src/window.c
+++ b/src/window.c
@@ -45,11 +45,12 @@ static bool nop_key_callback(void *userdata, u8 state, u16 button)
return false;
}
-static void nop_key_immediate_callback(void *userdata, u8 state, u16 button)
+static bool nop_key_immediate_callback(void *userdata, u8 state, u16 button)
{
(void)userdata;
(void)state;
(void)button;
+ return false;
}
static void window_default_close(struct stl_window *window)
@@ -227,10 +228,10 @@ void stl_window_send_key_event(struct stl_window *window, u8 state, u16 button)
#endif
}
-void stl_window_send_key_immediate_event(struct stl_window *window, u8 state, u16 button)
+bool stl_window_send_key_immediate_event(struct stl_window *window, u8 state, u16 button)
{
// Don't send modifiers on key immediate.
- window->key_immediate_callback(window->userdata, state, button * (stl_key_to_mod(button) == STELA_MOD_NONE));
+ return window->key_immediate_callback(window->userdata, state, button * (stl_key_to_mod(button) == STELA_MOD_NONE));
}
void stl_window_drop_modifiers(struct stl_window *window)
diff --git a/src/window.h b/src/window.h
index f7f25e2..de18c83 100644
--- a/src/window.h
+++ b/src/window.h
@@ -44,6 +44,10 @@
#define STELA_MIN_HEIGHT 16u
#endif
+#ifdef STELA_WINDOW_WAYLAND
+#define STELA_ICON_AT_RUNTIME
+#endif
+
// Drag window by clicking anywhere with MOUSE2.
#define STELA_MOUSE2_DRAG
@@ -81,7 +85,7 @@ struct stl_window {
bool fullscreen;
u32 flags;
// Methods.
- bool (*create_window)(struct stl_window *, u32, u32, const char *, const char *, u32);
+ bool (*create_window)(struct stl_window *, u32, u32, u32, const char *, const char *, const char *);
void (*resize_internal)(struct stl_window *, u32, u32);
void (*resize)(struct stl_window *, u32, u32);
void (*toggle_fullscreen)(struct stl_window *);
@@ -127,8 +131,11 @@ struct stl_window {
bool (*scroll_callback)(void *, f64);
bool (*mouse_button_callback)(void *, u8, u8);
bool (*key_callback)(void *, u8, u16);
- // Always runs on the thread that received the key event.
- void (*key_immediate_callback)(void *, u8, u16);
+ // Immediate:
+ // - Always runs on the thread that received the event.
+ // - Return value decides if the event should "pass through" or not.
+ // True = Consume, False = Passthrough.
+ bool (*key_immediate_callback)(void *, u8, u16);
void (*should_close_callback)(void *);
void *userdata;
bool closed;
@@ -189,6 +196,9 @@ extern s32 stl_platform_main(u32 argc, str *argv);
f64 stl_scale_scroll(f64 v, f64 factor);
void stl_set_output_discovered_callback(void (*output_discovered)(void *, struct stl_monitor *), void *userdata);
+#ifdef STELA_ICON_AT_RUNTIME
+void stl_set_icon_data(u8 *data, u32 size);
+#endif
bool stl_global_init(bool skip_graphics);
s32 stl_global_get_poll_fd(void);
@@ -205,7 +215,7 @@ void stl_window_send_scroll_event(struct stl_window *window, f64 y);
void stl_window_send_mouse_button_event(struct stl_window *window, u8 state, u8 button);
void stl_window_drop_mouse_buttons(struct stl_window *window);
void stl_window_send_key_event(struct stl_window *window, u8 state, u16 button);
-void stl_window_send_key_immediate_event(struct stl_window *window, u8 state, u16 button);
+bool stl_window_send_key_immediate_event(struct stl_window *window, u8 state, u16 button);
void stl_window_drop_modifiers(struct stl_window *window);
void stl_window_send_should_close_event(struct stl_window *window);
#ifdef STELA_EVENT_BUFFER
diff --git a/src/window_glfm.c b/src/window_glfm.c
index 202a55f..a799f5d 100644
--- a/src/window_glfm.c
+++ b/src/window_glfm.c
@@ -4,6 +4,7 @@
#include "window_glfm.h"
#include "common.h"
+#include "keys.h"
f64 stl_scale_scroll(f64 v, f64 factor)
{
@@ -87,6 +88,28 @@ static void onOrientationChanged(GLFMDisplay *display, GLFMInterfaceOrientation
global.orientation = orientation;
}
+static u8 glfm_to_stela_button_action[] = {
+ [GLFMKeyActionPressed] = STELA_BUTTON_PRESSED,
+ [GLFMKeyActionReleased] = STELA_BUTTON_RELEASED
+};
+
+static bool onKey(GLFMDisplay *display, GLFMKeyCode key, GLFMKeyAction action, s32 modifiers)
+{
+ struct stl_window_glfm *glfm = (struct stl_window_glfm *)glfmGetUserData(display);
+ (void)modifiers;
+ u8 mapped_action = glfm_to_stela_button_action[action];
+ switch (key) {
+ case GLFMKeyCodeVolumeUp:
+ return stl_window_send_key_immediate_event(&glfm->w, mapped_action, STELA_KEY_RIGHT);
+ case GLFMKeyCodeVolumeDown:
+ return stl_window_send_key_immediate_event(&glfm->w, mapped_action, STELA_KEY_LEFT);
+ case GLFMKeyCodeNavigationBack:
+ default:
+ break;
+ }
+ return true;
+}
+
static u8 glfm_to_stela_touch[] = {
[GLFMTouchPhaseHover] = STELA_TOUCH_HOVER,
[GLFMTouchPhaseBegan] = STELA_TOUCH_BEGAN,
@@ -126,17 +149,19 @@ void glfmMain(GLFMDisplay *display)
glfmSetRenderFunc(display, onDraw);
glfmSetSurfaceDestroyedFunc(display, onSurfaceDestroyed);
glfmSetOrientationChangedFunc(display, onOrientationChanged);
+ glfmSetKeyFunc(display, onKey);
glfmSetTouchFunc(display, onTouch);
}
-static bool window_glfm_create_window(struct stl_window *window, u32 width, u32 height,
- const char *monitor, const char *name, u32 flags)
+static bool window_glfm_create_window(struct stl_window *window, u32 width, u32 height, u32 flags,
+ const char *monitor, const char *name, const char *app_id)
{
struct stl_window_glfm *glfm = (struct stl_window_glfm *)window;
(void)width;
(void)height;
(void)monitor;
(void)name;
+ (void)app_id;
glfmSetUserData(global.display, glfm);
s32 display_width, display_height;
glfmGetDisplaySize(global.display, &display_width, &display_height);
diff --git a/src/window_glfw.c b/src/window_glfw.c
index f94c9c2..0f55bc3 100644
--- a/src/window_glfw.c
+++ b/src/window_glfw.c
@@ -189,16 +189,16 @@ static void close_callback(GLFWwindow *window)
stl_window_send_should_close_event(&glfw->w);
}
-static bool window_glfw_create_window(struct stl_window *window, u32 width, u32 height,
- const char *monitor, const char *name, u32 flags)
+static bool window_glfw_create_window(struct stl_window *window, u32 width, u32 height, u32 flags,
+ const char *monitor, const char *name, const char *app_id)
{
struct stl_window_glfw *glfw = (struct stl_window_glfw *)window;
(void)monitor;
#if GLFW_VERSION_MAJOR > 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 4)
- glfwWindowHintString(GLFW_WAYLAND_APP_ID, name);
+ glfwWindowHintString(GLFW_WAYLAND_APP_ID, app_id);
#endif
- glfwWindowHintString(GLFW_X11_CLASS_NAME, name);
+ glfwWindowHintString(GLFW_X11_CLASS_NAME, app_id);
#if defined STELA_API_VULKAN
if (!glfwVulkanSupported()) {
diff --git a/src/window_kms.c b/src/window_kms.c
index 900ac59..de3f24a 100644
--- a/src/window_kms.c
+++ b/src/window_kms.c
@@ -37,16 +37,17 @@ void stl_global_close(void)
{
}
-static bool window_kms_create_window(struct stl_window *window, u32 width, u32 height,
- const char *monitor, const char *name, u32 flags)
+static bool window_kms_create_window(struct stl_window *window, u32 width, u32 height, u32 flags,
+ const char *monitor, const char *name, const char *app_id)
{
struct stl_window_kms *kms = (struct stl_window_kms *)window;
(void)kms;
(void)monitor;
(void)name;
- (void)flags;
+ (void)app_id;
(void)width;
(void)height;
+ (void)flags;
return true;
}
diff --git a/src/window_x11.c b/src/window_x11.c
index 2f84f19..998beb4 100644
--- a/src/window_x11.c
+++ b/src/window_x11.c
@@ -180,8 +180,8 @@ static void set_decorations(struct stl_window_x11 *xw, bool enabled)
}
}
-static bool window_x11_create_window(struct stl_window *window, u32 width, u32 height,
- const char *monitor, const char *name, u32 flags)
+static bool window_x11_create_window(struct stl_window *window, u32 width, u32 height, u32 flags,
+ const char *monitor, const char *name, const char *app_id)
{
struct stl_window_x11 *xw = (struct stl_window_x11 *)window;
(void)monitor;
@@ -201,7 +201,7 @@ static bool window_x11_create_window(struct stl_window *window, u32 width, u32 h
XStoreName(global.x11_d, xw->window, name);
XClassHint *class_hint = XAllocClassHint();
class_hint->res_name = (char *)name;
- class_hint->res_class = (char *)name;
+ class_hint->res_class = (char *)app_id;
XSetClassHint(global.x11_d, xw->window, class_hint);
XFree(class_hint);
@@ -553,14 +553,14 @@ static void handle_next_xevent(struct stl_window_x11 *xw)
event.xclient.send_event = True;
event.xclient.display = global.x11_d;
event.xclient.window = xw->window;
- // https://specifications.freedesktop.org/wm-spec/1.4/ar01s04.html#id-1.5.4
+ // https://specifications.freedesktop.org/wm/1.5/ar01s04.html#id-1.5.4
event.xclient.message_type = XInternAtom(global.x11_d, "_NET_WM_MOVERESIZE", False);
event.xclient.format = 32;
- event.xclient.data.l[0] = xev.xbutton.x;
- event.xclient.data.l[1] = xev.xbutton.y;
+ event.xclient.data.l[0] = xev.xbutton.x_root;
+ event.xclient.data.l[1] = xev.xbutton.y_root;
event.xclient.data.l[2] = _NET_WM_MOVERESIZE_MOVE;
- event.xclient.data.l[3] = 0;
- // https://specifications.freedesktop.org/wm-spec/1.4/ar01s09.html#sourceindication
+ event.xclient.data.l[3] = xev.xbutton.button;
+ // https://specifications.freedesktop.org/wm/1.5/ar01s09.html#sourceindication
event.xclient.data.l[4] = 1; // Source indication of "normal applications".
Window root = DefaultRootWindow(global.x11_d);
XSendEvent(global.x11_d, root, False, SubstructureRedirectMask | SubstructureNotifyMask, &event);