[common/client] platform: abstract runtime services

This commit is contained in:
Geoffrey McRae
2026-09-12 12:51:17 +10:00
parent a7d2e4592f
commit eabc56a6de
49 changed files with 4064 additions and 940 deletions

View File

@@ -20,6 +20,8 @@
#include <stdbool.h>
#include "interface/event_source.h"
/**
* initialize configuration options
*/
@@ -46,14 +48,9 @@ void evdev_free(void);
void evdev_setGrab(bool keyboard, bool pointer);
/**
* return the event fd used to dispatch captured input
* return the event source used to dispatch captured input
*/
int evdev_getEventFD(void);
/**
* dispatch captured input on the display server's event thread
*/
void evdev_dispatch(void * opaque);
LG_DSEventSource evdev_getEventSource(void);
/**
* return true if keyboard input should only be processed by evdev

View File

@@ -0,0 +1,45 @@
/**
* Looking Glass
* Copyright © 2017-2026 The Looking Glass Authors
* https://looking-glass.io
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _H_LG_EVENT_SOURCE_
#define _H_LG_EVENT_SOURCE_
#include "interface/event_source.h"
#include "common/locking.h"
typedef struct LGEventSourceState
{
LG_Lock lock;
LG_DSEventWake callback;
void * callbackOpaque;
LG_DSEventDispatch dispatch;
void * dispatchOpaque;
bool pending;
}
LGEventSourceState;
bool lgEventSourceInit(LGEventSourceState * state,
LG_DSEventDispatch dispatch, void * dispatchOpaque);
void lgEventSourceFree(LGEventSourceState * state);
LG_DSEventSource lgEventSourceGet(LGEventSourceState * state);
void lgEventSourceNotify(LGEventSourceState * state);
#endif

View File

@@ -24,7 +24,17 @@
#include <stdbool.h>
#include <stddef.h>
struct ImFont;
struct ImFontAtlas;
bool font_isStbTruetypeCompatible(
const void * data, size_t size, int fontIndex);
bool font_init(void);
void font_free(void);
char * font_get(const char * fontName);
bool font_addText(const char * text);
bool font_buildAtlas(struct ImFontAtlas * atlas, float size,
struct ImFont ** large);
#endif

View File

@@ -27,6 +27,7 @@
#include "common/types.h"
#include "common/debug.h"
#include "interface/clipboard.h"
#include "interface/event_source.h"
typedef enum LG_DSProperty
{
@@ -103,18 +104,6 @@ LG_DSWaitFrameResult;
#define LG_POINTER_COUNT (LG_POINTER_NOT_ALLOWED + 1)
typedef void (*LG_DSEventCallback)(void * opaque);
typedef struct LG_DSEventSource
{
/* The callback must be nonblocking and tolerate spurious calls. The caller
* retains ownership of fd and opaque until display-server shutdown. */
int fd;
LG_DSEventCallback callback;
void * opaque;
}
LG_DSEventSource;
typedef struct LG_DSInitParams
{
const char * title;

View File

@@ -0,0 +1,53 @@
/**
* Looking Glass
* Copyright © 2017-2026 The Looking Glass Authors
* https://looking-glass.io
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _H_I_EVENT_SOURCE_
#define _H_I_EVENT_SOURCE_
#include <stdbool.h>
typedef bool (*LG_DSEventWake)(void * opaque);
typedef bool (*LG_DSEventSubscribe)(void * opaque,
LG_DSEventWake callback, void * callbackOpaque);
typedef void (*LG_DSEventUnsubscribe)(void * opaque);
typedef void (*LG_DSEventDispatch)(void * opaque);
typedef struct LG_DSEventSource
{
void * opaque;
LG_DSEventSubscribe subscribe;
LG_DSEventUnsubscribe unsubscribe;
LG_DSEventDispatch dispatch;
}
LG_DSEventSource;
/* Notifications are coalesced until dispatch. The subscriber wake callback
* must be nonblocking, must not call back into the source, and returns true
* when the wake was delivered. Failed wakes may be retried by a later
* notification. Unsubscribe is synchronous with any wake already in
* progress. */
static inline bool lgEventSourceValid(const LG_DSEventSource * source)
{
return source && source->subscribe && source->unsubscribe &&
source->dispatch;
}
#endif

View File

@@ -0,0 +1,37 @@
/**
* Looking Glass
* Copyright © 2017-2026 The Looking Glass Authors
* https://looking-glass.io
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _H_LG_PLATFORM_INPUT_
#define _H_LG_PLATFORM_INPUT_
#include "interface/event_source.h"
#include <stdbool.h>
void inputPlatformEarlyInit(void);
bool inputPlatformStart(void);
void inputPlatformStop(void);
void inputPlatformFree(void);
void inputPlatformSetGrab(bool keyboard, bool pointer);
bool inputPlatformIsKeyboardExclusive(void);
bool inputPlatformIsPointerExclusive(void);
LG_DSEventSource inputPlatformGetEventSource(void);
#endif

View File

@@ -0,0 +1,45 @@
/**
* Looking Glass
* Copyright © 2017-2026 The Looking Glass Authors
* https://looking-glass.io
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _H_LG_PLATFORM_PROCESS_
#define _H_LG_PLATFORM_PROCESS_
#include <stdbool.h>
enum LG_ProcessPrivilege
{
LG_PROCESS_PRIVILEGE_NORMAL,
LG_PROCESS_PRIVILEGE_ROOT,
LG_PROCESS_PRIVILEGE_SETUID
};
/* Return true when the request was handled. Returning false asks the platform
* to continue with its default forced-termination behavior. */
typedef bool (*LG_ProcessStopHandler)(void * opaque);
enum LG_ProcessPrivilege lgProcessGetPrivilege(void);
char * lgProcessGetExecutablePath(const char * argv0);
bool lgProcessInstallStopHandler(LG_ProcessStopHandler handler, void * opaque);
void lgProcessRemoveStopHandler(void);
int lgClientMain(int argc, char * argv[]);
#endif