new envs
This commit is contained in:
parent
175827fd9b
commit
9246051de0
5 changed files with 74 additions and 25 deletions
5
doc/ENV.md
Normal file
5
doc/ENV.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Platforms that support both X11 and Wayland (Linux, namely) support launching Milsko programs with following environment variables:
|
||||
|
||||
- `MW_BACKEND`: set to either `wayland` or `x11` to force which display protocol Wayland uses
|
||||
- `MW_FORCE_CSD`: set to force the wayland backend to use CSD instead of SSD
|
||||
- `MW_LIGHT_THEME`/`MW_DARK_THEME`: set to have either wayland or x11 ignore the system's appearence settings and either just use light theme/dark theme.
|
||||
|
|
@ -41,6 +41,11 @@ struct _MwLLCommon {
|
|||
MwBool supports_transparency;
|
||||
|
||||
MwLLHandler handler;
|
||||
|
||||
#if defined(USE_WAYLAND) || defined(USE_X11)
|
||||
/* 0 = default, 1 = light, 2 = dark */
|
||||
int theme_override;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct _MwLLCommonColor {
|
||||
|
|
@ -364,9 +369,9 @@ MWDECL void* (*MwFLFontLoad)(unsigned char* data, unsigned int size, int px);
|
|||
MWDECL void (*MwFLFontFree)(void* handle);
|
||||
|
||||
#ifdef _WIN32
|
||||
MWDECL void *MwLL_winmmLib;
|
||||
MWDECL long (__stdcall* MwLL_PFN_timeGetTime)(void);
|
||||
MWDECL unsigned int (__stdcall* MwLL_PFN_timeBeginPeriod)(unsigned int period);
|
||||
MWDECL void* MwLL_winmmLib;
|
||||
MWDECL long(__stdcall* MwLL_PFN_timeGetTime)(void);
|
||||
MWDECL unsigned int(__stdcall* MwLL_PFN_timeBeginPeriod)(unsigned int period);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -942,11 +942,13 @@ static void dark_theme_listener(MwLL handle, MwU32 new_value) {
|
|||
static void detect_dark_theme(MwLL handle) {
|
||||
MwU32 value = 0;
|
||||
|
||||
MwLLDBusPortalGet(&wl_call_tbl.dbus, &handle->wayland.dbus, "org.freedesktop.portal.Settings", "org.freedesktop.appearance", "color-scheme", &value);
|
||||
handle->wayland.dark_theme = (value == 1) ? 1 : 0;
|
||||
|
||||
MwLLDBusPortalWatch(&wl_call_tbl.dbus, &handle->wayland.dbus, "org.freedesktop.portal.Settings");
|
||||
|
||||
if(handle->common.theme_override != 0) {
|
||||
handle->wayland.dark_theme = (handle->common.theme_override == 2) ? 1 : 0;
|
||||
} else {
|
||||
MwLLDBusPortalGet(&wl_call_tbl.dbus, &handle->wayland.dbus, "org.freedesktop.portal.Settings", "org.freedesktop.appearance", "color-scheme", &value);
|
||||
handle->wayland.dark_theme = (value == 1) ? 1 : 0;
|
||||
MwLLDBusPortalWatch(&wl_call_tbl.dbus, &handle->wayland.dbus, "org.freedesktop.portal.Settings");
|
||||
}
|
||||
MwLLDispatch(handle, dark_theme, &handle->wayland.dark_theme);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1381,9 +1383,8 @@ static int MwLLPendingImpl(MwLL handle) {
|
|||
}
|
||||
|
||||
#ifdef USE_DBUS
|
||||
if(wl_call_tbl.has_dbus) {
|
||||
if(wl_call_tbl.has_dbus || handle->common.theme_override == 0) {
|
||||
if(handle->wayland.dark_theme_detection) {
|
||||
|
||||
handle->wayland.dark_theme_detection = MwFALSE;
|
||||
detect_dark_theme(handle);
|
||||
MwLLDispatch(handle, draw, NULL);
|
||||
|
|
@ -1907,10 +1908,22 @@ static void MwLLClipImpl(MwLL handle, MwRect* rect) {
|
|||
|
||||
static int MwLLWaylandCallInitImpl(void) {
|
||||
#ifdef __linux__
|
||||
MwBool loadWayland = MwFALSE;
|
||||
if(getenv("MILSKO_BACKEND")) {
|
||||
loadWayland |=
|
||||
(strcmp(getenv("MILSKO_BACKEND"), "wayland") == 0);
|
||||
MwBool loadWayland = MwFALSE;
|
||||
char* milsko_backend_env = getenv("MILSKO_BACKEND");
|
||||
char* mw_backend_env = getenv("MW_BACKEND");
|
||||
|
||||
if(milsko_backend_env || mw_backend_env) {
|
||||
if(milsko_backend_env) {
|
||||
/*
|
||||
* (deprecated since 1.5+ but we have no reason to ever remove the old variable.
|
||||
* MW_BACKEND is just the one that's documented)
|
||||
*/
|
||||
printf("[WARNING] MILSKO_BACKEND env is deprecated, use MW_BACKEND instead.\n");
|
||||
loadWayland |= (strcmp(milsko_backend_env, "wayland") == 0);
|
||||
} else {
|
||||
loadWayland |= (strcmp(mw_backend_env, "wayland") == 0);
|
||||
}
|
||||
|
||||
} else if(getenv("WAYLAND_DISPLAY")) {
|
||||
loadWayland |= (getenv("WAYLAND_DISPLAY") != NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -327,9 +327,12 @@ static XVisualInfo* get_visual_info(Display* display) {
|
|||
static void detect_dark_theme(MwLL handle) {
|
||||
MwU32 value = 0;
|
||||
MwU32 dark_theme = 0;
|
||||
MwLLDBusPortalGet(&xsymtbl.dbus, &handle->x11.dbus, "org.freedesktop.portal.Settings", "org.freedesktop.appearance", "color-scheme", &value);
|
||||
|
||||
dark_theme = (value == 1) ? 1 : 0;
|
||||
if(handle->common.theme_override != 0) {
|
||||
dark_theme = (handle->common.theme_override == 2) ? 1 : 0;
|
||||
} else {
|
||||
MwLLDBusPortalGet(&xsymtbl.dbus, &handle->x11.dbus, "org.freedesktop.portal.Settings", "org.freedesktop.appearance", "color-scheme", &value);
|
||||
dark_theme = (value == 1) ? 1 : 0;
|
||||
}
|
||||
|
||||
MwLLDispatch(handle, dark_theme, &dark_theme);
|
||||
}
|
||||
|
|
@ -652,7 +655,7 @@ static int MwLLPendingImpl(MwLL handle) {
|
|||
if(handle->x11.dark_theme_detection) {
|
||||
handle->x11.dark_theme_detection = MwFALSE;
|
||||
#ifdef USE_DBUS
|
||||
if(xsymtbl.has_dbus) {
|
||||
if(xsymtbl.has_dbus || handle->common.theme_override == 0) {
|
||||
detect_dark_theme(handle);
|
||||
MwLLDispatch(handle, draw, NULL);
|
||||
}
|
||||
|
|
@ -1403,10 +1406,21 @@ static void MwLLClipImpl(MwLL handle, MwRect* rect) {
|
|||
}
|
||||
|
||||
static int MwLLX11CallInitImpl(void) {
|
||||
MwBool loadX11 = MwFALSE;
|
||||
if(getenv("MILSKO_BACKEND")) {
|
||||
loadX11 |=
|
||||
(strcmp(getenv("MILSKO_BACKEND"), "x11") == 0);
|
||||
MwBool loadX11 = MwFALSE;
|
||||
char* milsko_backend_env = getenv("MILSKO_BACKEND");
|
||||
char* mw_backend_env = getenv("MW_BACKEND");
|
||||
|
||||
if(milsko_backend_env || mw_backend_env) {
|
||||
if(milsko_backend_env) {
|
||||
/*
|
||||
* (deprecated since 1.5+ but we have no reason to ever remove the old variable.
|
||||
* MW_BACKEND is just the one that's documented)
|
||||
*/
|
||||
printf("[WARNING] MILSKO_BACKEND env is deprecated, use MW_BACKEND instead.\n");
|
||||
loadX11 |= (strcmp(milsko_backend_env, "x11") == 0);
|
||||
} else {
|
||||
loadX11 |= (strcmp(mw_backend_env, "x11") == 0);
|
||||
}
|
||||
} else if(getenv("DISPLAY")) {
|
||||
loadX11 |= (getenv("DISPLAY") != NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
void *MwLL_winmmLib;
|
||||
long (__stdcall* MwLL_PFN_timeGetTime)(void);
|
||||
unsigned int (__stdcall* MwLL_PFN_timeBeginPeriod)(unsigned int period);
|
||||
void* MwLL_winmmLib;
|
||||
long(__stdcall* MwLL_PFN_timeGetTime)(void);
|
||||
unsigned int(__stdcall* MwLL_PFN_timeBeginPeriod)(unsigned int period);
|
||||
#endif
|
||||
|
||||
MwLL (*MwLLCreate)(MwLL parent, int x, int y, int width, int height) = NULL;
|
||||
|
|
@ -66,10 +66,22 @@ void (*MwLLRaise)(MwLL handle) = NULL;
|
|||
void (*MwLLClip)(MwLL handle, MwRect* rect) = NULL;
|
||||
|
||||
void MwLLCreateCommon(MwLL handle) {
|
||||
#if defined(USE_WAYLAND) || defined(USE_X11)
|
||||
char* light_theme = getenv("MW_LIGHT_THEME");
|
||||
char* dark_theme = getenv("MW_DARK_THEME");
|
||||
#endif
|
||||
|
||||
handle->common.handler = malloc(sizeof(*handle->common.handler));
|
||||
memset(handle->common.handler, 0, sizeof(*handle->common.handler));
|
||||
|
||||
handle->common.supports_transparency = 0;
|
||||
|
||||
#if defined(USE_WAYLAND) || defined(USE_X11)
|
||||
if(light_theme || dark_theme) {
|
||||
handle->common.theme_override = (light_theme != NULL) ? 1 : ((dark_theme != NULL) ? 2 : 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void MwLLDestroyCommon(MwLL handle) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue