mirror of https://github.com/nirenjan/libx52.git
fix stub
parent
f9b58bc19d
commit
ef9cf14837
113
vkm/vkm_stub.c
113
vkm/vkm_stub.c
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (C) 2026 Nirenjan Krishnan <nirenjan@nirenjan.org>
|
* Copyright (C) 2026 Nirenjan Krishnan <nirenjan@nirenjan.org>
|
||||||
*
|
*
|
||||||
* SPDX-LicenseIdentifier: GPL-2.0-only WITH Classpath-exception-2.0
|
* SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -11,36 +11,50 @@
|
||||||
|
|
||||||
#include "vkm.h"
|
#include "vkm.h"
|
||||||
|
|
||||||
// Dummy struct
|
|
||||||
struct vkm_context {
|
struct vkm_context {
|
||||||
|
bool started;
|
||||||
|
bool mouse_hi_res_scroll;
|
||||||
|
bool mouse_horizontal_scroll;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DUMMY_CTX (vkm_context *)0xDEADBEEF
|
|
||||||
|
|
||||||
vkm_result vkm_init(vkm_context **ctx)
|
vkm_result vkm_init(vkm_context **ctx)
|
||||||
{
|
{
|
||||||
if (ctx != NULL) {
|
if (ctx == NULL) {
|
||||||
*ctx = DUMMY_CTX;
|
return VKM_ERROR_INVALID_PARAM;
|
||||||
return VKM_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return VKM_ERROR_INVALID_PARAM;
|
*ctx = calloc(1, sizeof(**ctx));
|
||||||
|
if (*ctx == NULL) {
|
||||||
|
return VKM_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return VKM_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vkm_exit(vkm_context *ctx)
|
void vkm_exit(vkm_context *ctx)
|
||||||
{
|
{
|
||||||
(void)ctx;
|
free(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
vkm_result vkm_start(vkm_context *ctx)
|
vkm_result vkm_start(vkm_context *ctx)
|
||||||
{
|
{
|
||||||
if (ctx != DUMMY_CTX) {
|
if (ctx == NULL) {
|
||||||
return VKM_ERROR_INVALID_PARAM;
|
return VKM_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx->started = true;
|
||||||
return VKM_SUCCESS;
|
return VKM_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool vkm_is_ready(vkm_context *ctx)
|
||||||
|
{
|
||||||
|
if (ctx == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx->started;
|
||||||
|
}
|
||||||
|
|
||||||
bool vkm_platform_supported(void)
|
bool vkm_platform_supported(void)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -59,28 +73,32 @@ vkm_result vkm_set_option(vkm_context *ctx, vkm_option option, ...)
|
||||||
char *name;
|
char *name;
|
||||||
vkm_result rc;
|
vkm_result rc;
|
||||||
|
|
||||||
if (ctx != DUMMY_CTX) {
|
if (ctx == NULL) {
|
||||||
return VKM_ERROR_INVALID_PARAM;
|
return VKM_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
va_start(ap, option);
|
va_start(ap, option);
|
||||||
rc = VKM_SUCCESS;
|
rc = VKM_SUCCESS;
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case VKM_OPT_HI_RES_SCROLL:
|
case VKM_OPT_HI_RES_SCROLL:
|
||||||
case VKM_OPT_HORIZONTAL_SCROLL:
|
flag = (bool)va_arg(ap, int);
|
||||||
// read as int, as bool is promoted to int when passed as a va_arg
|
ctx->mouse_hi_res_scroll = flag;
|
||||||
flag = va_arg(ap, int);
|
break;
|
||||||
(void)flag;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VKM_OPT_DEVICE_NAME:
|
case VKM_OPT_HORIZONTAL_SCROLL:
|
||||||
name = va_arg(ap, char *);
|
flag = (bool)va_arg(ap, int);
|
||||||
(void)name;
|
ctx->mouse_horizontal_scroll = flag;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case VKM_OPT_DEVICE_NAME:
|
||||||
rc = VKM_ERROR_INVALID_PARAM;
|
name = va_arg(ap, char *);
|
||||||
break;
|
(void)name;
|
||||||
|
rc = VKM_ERROR_NOT_SUPPORTED;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
rc = VKM_ERROR_INVALID_PARAM;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
@ -89,18 +107,24 @@ vkm_result vkm_set_option(vkm_context *ctx, vkm_option option, ...)
|
||||||
|
|
||||||
vkm_result vkm_mouse_move(vkm_context *ctx, int dx, int dy)
|
vkm_result vkm_mouse_move(vkm_context *ctx, int dx, int dy)
|
||||||
{
|
{
|
||||||
(void)dx;
|
if (ctx == NULL) {
|
||||||
(void)dy;
|
|
||||||
if (ctx != DUMMY_CTX) {
|
|
||||||
return VKM_ERROR_INVALID_PARAM;
|
return VKM_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
return VKM_SUCCESS;
|
if (!vkm_is_ready(ctx)) {
|
||||||
|
return VKM_ERROR_NOT_READY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dx == 0 && dy == 0) {
|
||||||
|
return VKM_ERROR_NO_CHANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return VKM_ERROR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
vkm_result vkm_mouse_click(vkm_context *ctx, vkm_mouse_button button, vkm_button_state state)
|
vkm_result vkm_mouse_click(vkm_context *ctx, vkm_mouse_button button, vkm_button_state state)
|
||||||
{
|
{
|
||||||
if (ctx != DUMMY_CTX) {
|
if (ctx == NULL) {
|
||||||
return VKM_ERROR_INVALID_PARAM;
|
return VKM_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,12 +136,16 @@ vkm_result vkm_mouse_click(vkm_context *ctx, vkm_mouse_button button, vkm_button
|
||||||
return VKM_ERROR_INVALID_PARAM;
|
return VKM_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
return VKM_SUCCESS;
|
if (!vkm_is_ready(ctx)) {
|
||||||
|
return VKM_ERROR_NOT_READY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return VKM_ERROR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
vkm_result vkm_mouse_scroll(vkm_context *ctx, vkm_mouse_scroll_direction dir)
|
vkm_result vkm_mouse_scroll(vkm_context *ctx, vkm_mouse_scroll_direction dir)
|
||||||
{
|
{
|
||||||
if (ctx != DUMMY_CTX) {
|
if (ctx == NULL) {
|
||||||
return VKM_ERROR_INVALID_PARAM;
|
return VKM_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,5 +153,28 @@ vkm_result vkm_mouse_scroll(vkm_context *ctx, vkm_mouse_scroll_direction dir)
|
||||||
return VKM_ERROR_INVALID_PARAM;
|
return VKM_ERROR_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!vkm_is_ready(ctx)) {
|
||||||
|
return VKM_ERROR_NOT_READY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dir == VKM_MOUSE_SCROLL_LEFT || dir == VKM_MOUSE_SCROLL_RIGHT) {
|
||||||
|
if (!ctx->mouse_horizontal_scroll) {
|
||||||
|
return VKM_ERROR_INVALID_PARAM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return VKM_ERROR_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
vkm_result vkm_sync(vkm_context *ctx)
|
||||||
|
{
|
||||||
|
if (ctx == NULL) {
|
||||||
|
return VKM_ERROR_INVALID_PARAM;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!vkm_is_ready(ctx)) {
|
||||||
|
return VKM_ERROR_NOT_READY;
|
||||||
|
}
|
||||||
|
|
||||||
return VKM_SUCCESS;
|
return VKM_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue