Merge branch 'master' into clipboard
This commit is contained in:
commit
5136207bf1
47 changed files with 841 additions and 345 deletions
|
|
@ -54,6 +54,8 @@
|
|||
\
|
||||
MwLLGetCursorCoord = MwLLGetCursorCoordImpl; \
|
||||
MwLLGetScreenSize = MwLLGetScreenSizeImpl; \
|
||||
\
|
||||
MwLLSetDarkTheme = MwLLSetDarkThemeImpl; \
|
||||
\
|
||||
return 0; \
|
||||
}
|
||||
|
|
|
|||
175
src/backend/classicmacos.c
Normal file
175
src/backend/classicmacos.c
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
#include "../../external/stb_ds.h"
|
||||
|
||||
static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
||||
MwLL r;
|
||||
|
||||
MwLLCreateCommon(r);
|
||||
|
||||
SetRect(&r->cmacos.winRect, 100, 100, width, height);
|
||||
|
||||
r->cmacos.window = NewCWindow(nil, &r->cmacos.winRect, (ConstStr255Param) "\p", true,
|
||||
documentProc, (WindowPtr)(-1), true, 0);
|
||||
|
||||
SetPort(r->cmacos.window);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static void MwLLDestroyImpl(MwLL handle) {
|
||||
MwLLDestroyCommon(handle);
|
||||
|
||||
free(handle);
|
||||
}
|
||||
|
||||
static void MwLLBeginDrawImpl(MwLL handle) {
|
||||
(void)handle;
|
||||
}
|
||||
|
||||
static void MwLLEndDrawImpl(MwLL handle) {
|
||||
(void)handle;
|
||||
}
|
||||
|
||||
static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) {
|
||||
int i;
|
||||
}
|
||||
|
||||
static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {
|
||||
}
|
||||
|
||||
static MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) {
|
||||
MwLLColor c = malloc(sizeof(*c));
|
||||
MwLLColorUpdate(handle, c, r, g, b);
|
||||
return c;
|
||||
}
|
||||
|
||||
static void MwLLColorUpdateImpl(MwLL handle, MwLLColor c, int r, int g, int b) {
|
||||
c->common.red = r;
|
||||
c->common.green = g;
|
||||
c->common.blue = b;
|
||||
}
|
||||
|
||||
static void MwLLGetXYWHImpl(MwLL handle, int* x, int* y, unsigned int* w, unsigned int* h) {
|
||||
*x = 0;
|
||||
*y = 0;
|
||||
*w = 0;
|
||||
*h = 0;
|
||||
}
|
||||
|
||||
static void MwLLSetXYImpl(MwLL handle, int x, int y) {
|
||||
}
|
||||
|
||||
static void MwLLSetWHImpl(MwLL handle, int w, int h) {
|
||||
}
|
||||
|
||||
static void MwLLFreeColorImpl(MwLLColor color) {
|
||||
free(color);
|
||||
}
|
||||
|
||||
static int MwLLPendingImpl(MwLL handle) {
|
||||
return GetNextEvent(everyEvent, &handle->cmacos.event);
|
||||
}
|
||||
|
||||
static void MwLLNextEventImpl(MwLL handle) {
|
||||
}
|
||||
|
||||
static void MwLLSetTitleImpl(MwLL handle, const char* title) {
|
||||
}
|
||||
|
||||
static MwLLPixmap MwLLCreatePixmapImpl(MwLL handle, unsigned char* data, int width, int height) {
|
||||
MwLLPixmap r = malloc(sizeof(*r));
|
||||
|
||||
r->common.raw = malloc(4 * width * height);
|
||||
memcpy(r->common.raw, data, 4 * width * height);
|
||||
|
||||
MwLLPixmapUpdate(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
static void MwLLPixmapUpdateImpl(MwLLPixmap r) {
|
||||
}
|
||||
|
||||
static void MwLLDestroyPixmapImpl(MwLLPixmap pixmap) {
|
||||
}
|
||||
|
||||
static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) {
|
||||
}
|
||||
|
||||
static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) {
|
||||
}
|
||||
|
||||
static void MwLLForceRenderImpl(MwLL handle) {
|
||||
}
|
||||
|
||||
static void MwLLSetCursorImpl(MwLL handle, MwCursor* image, MwCursor* mask) {
|
||||
}
|
||||
|
||||
static void MwLLDetachImpl(MwLL handle, MwPoint* point) {
|
||||
}
|
||||
|
||||
static void MwLLShowImpl(MwLL handle, int show) {
|
||||
}
|
||||
|
||||
static void MwLLMakePopupImpl(MwLL handle, MwLL parent) {
|
||||
}
|
||||
|
||||
static void MwLLSetSizeHintsImpl(MwLL handle, int minx, int miny, int maxx, int maxy) {
|
||||
}
|
||||
|
||||
static void MwLLMakeBorderlessImpl(MwLL handle, int toggle) {
|
||||
}
|
||||
|
||||
static void MwLLFocusImpl(MwLL handle) {
|
||||
}
|
||||
|
||||
static void MwLLGrabPointerImpl(MwLL handle, int toggle) {
|
||||
}
|
||||
|
||||
static void MwLLSetClipboardImpl(MwLL handle, const char* text) {
|
||||
/* TODO */
|
||||
|
||||
(void)handle;
|
||||
(void)text;
|
||||
}
|
||||
|
||||
static void MwLLGetClipboardImpl(MwLL handle) {
|
||||
}
|
||||
|
||||
static void MwLLMakeToolWindowImpl(MwLL handle) {
|
||||
}
|
||||
|
||||
static void MwLLGetCursorCoordImpl(MwLL handle, MwPoint* point) {
|
||||
}
|
||||
|
||||
static void MwLLGetScreenSizeImpl(MwLL handle, MwRect* rect) {
|
||||
}
|
||||
|
||||
static void MwLLBeginStateChangeImpl(MwLL handle) {
|
||||
MwLLShow(handle, 0);
|
||||
}
|
||||
|
||||
static void MwLLEndStateChangeImpl(MwLL handle) {
|
||||
MwLLShow(handle, 1);
|
||||
}
|
||||
|
||||
static void MwLLSetDarkThemeImpl(MwLL handle, int toggle) {
|
||||
(void)handle;
|
||||
(void)toggle;
|
||||
}
|
||||
|
||||
static int MwLLClassicMacOSCallInitImpl(void) {
|
||||
InitGraf(&qd.thePort);
|
||||
InitFonts();
|
||||
FlushEvents(everyEvent, 0);
|
||||
InitWindows();
|
||||
InitMenus();
|
||||
TEInit();
|
||||
InitDialogs(0L);
|
||||
InitCursor();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include "call.c"
|
||||
CALL(ClassicMacOS);
|
||||
|
|
@ -1084,6 +1084,11 @@ static void MwLLEndStateChangeImpl(MwLL handle) {
|
|||
MwLLShow(handle, 1);
|
||||
}
|
||||
|
||||
static void MwLLSetDarkThemeImpl(MwLL handle, int toggle){
|
||||
(void)handle;
|
||||
(void)toggle;
|
||||
}
|
||||
|
||||
static int MwLLCocoaCallInitImpl(void) {
|
||||
#ifndef __APPLE__
|
||||
printf("Using GNUStep Backend\n");
|
||||
|
|
|
|||
|
|
@ -8,6 +8,14 @@ typedef struct userdata {
|
|||
int max_set;
|
||||
} userdata_t;
|
||||
|
||||
static struct symtbl {
|
||||
void* lib_dwmapi;
|
||||
|
||||
HRESULT (WINAPI *DwmSetWindowAttribute)(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute);
|
||||
} wsymtbl;
|
||||
|
||||
#define DwmSetWindowAttribute wsymtbl.DwmSetWindowAttribute
|
||||
|
||||
static void detect_darktheme(MwLL handle) {
|
||||
DWORD dw;
|
||||
DWORD sz = sizeof(dw);
|
||||
|
|
@ -26,6 +34,11 @@ static void detect_darktheme(MwLL handle) {
|
|||
|
||||
t = dw ? 0 : 1;
|
||||
|
||||
if(t && DwmSetWindowAttribute != NULL){
|
||||
LPARAM style = GetWindowLongPtr(handle->gdi.hWnd, GWL_STYLE);
|
||||
if(!(style & WS_CHILD)) MwLLSetDarkTheme(handle, 1);
|
||||
}
|
||||
|
||||
MwLLDispatch(handle, dark_theme, &t);
|
||||
}
|
||||
|
||||
|
|
@ -265,7 +278,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
|||
r->common.copy_buffer = 1;
|
||||
r->common.type = MwLLBackendGDI;
|
||||
|
||||
r->gdi.get_clipboard = 1;
|
||||
r->gdi.get_clipboard = 0;
|
||||
if(parent == NULL) r->gdi.get_darktheme = 1;
|
||||
r->gdi.force_render = 0;
|
||||
r->gdi.grabbed = 0;
|
||||
|
|
@ -806,7 +819,20 @@ static void MwLLEndStateChangeImpl(MwLL handle) {
|
|||
(void)handle;
|
||||
}
|
||||
|
||||
static void MwLLSetDarkThemeImpl(MwLL handle, int toggle){
|
||||
BOOL v = toggle ? TRUE : FALSE;
|
||||
|
||||
DwmSetWindowAttribute(handle->gdi.hWnd, 20, &v, sizeof(v));
|
||||
|
||||
}
|
||||
|
||||
static int MwLLGDICallInitImpl(void) {
|
||||
memset(&wsymtbl, 0, sizeof(wsymtbl));
|
||||
|
||||
wsymtbl.lib_dwmapi = MwDynamicOpen("dwmapi.dll");
|
||||
|
||||
if(wsymtbl.lib_dwmapi != NULL) DwmSetWindowAttribute = MwDynamicSymbol(wsymtbl.lib_dwmapi, "DwmSetWindowAttribute");
|
||||
|
||||
/* TODO: check properly */
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1817,102 +1817,16 @@ static void widget_setup(MwLL r, MwLL parent, int x, int y, int width, int heigh
|
|||
}
|
||||
}
|
||||
|
||||
static void dbus_setup(MwLL handle) {
|
||||
MwU32 value = 0;
|
||||
int translated_value = 0;
|
||||
|
||||
if(!wl_call_tbl.dbus_lib) {
|
||||
return;
|
||||
}
|
||||
|
||||
time(&handle->wayland.dbus_timer);
|
||||
|
||||
wl_call_tbl.dbus_error_init(&handle->wayland.dbus_err);
|
||||
|
||||
handle->wayland.dbus_conn = wl_call_tbl.dbus_bus_get(0 /* DBUS_BUS_SESSION */, &handle->wayland.dbus_err);
|
||||
if(wl_call_tbl.dbus_error_is_set(&handle->wayland.dbus_err)) {
|
||||
fprintf(stderr, "[WARNING] Could not detect dark theme: Connection error: %s\n", handle->wayland.dbus_err.message);
|
||||
wl_call_tbl.dbus_error_free(&handle->wayland.dbus_err);
|
||||
return;
|
||||
}
|
||||
if(!handle->wayland.dbus_conn) {
|
||||
fprintf(stderr, "[WARNING] Could not detect dark theme: Failed to connect to session bus\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void dbus_get(MwLL handle, const char* portal, const char* namespace, const char* key, void* out) {
|
||||
if(!handle->wayland.dbus_conn) {
|
||||
return;
|
||||
}
|
||||
|
||||
handle->wayland.dbus_msg = wl_call_tbl.dbus_message_new_method_call(
|
||||
"org.freedesktop.portal.Desktop",
|
||||
"/org/freedesktop/portal/desktop",
|
||||
portal,
|
||||
"Read");
|
||||
if(!handle->wayland.dbus_msg) {
|
||||
fprintf(stderr, "[WARNING] Couldn't get %s::%s: Failed to create message\n", namespace, key);
|
||||
return;
|
||||
}
|
||||
|
||||
wl_call_tbl.dbus_message_iter_init_append(handle->wayland.dbus_msg, &handle->wayland.dbus_args);
|
||||
wl_call_tbl.dbus_message_iter_append_basic(&handle->wayland.dbus_args, 's', &namespace);
|
||||
wl_call_tbl.dbus_message_iter_append_basic(&handle->wayland.dbus_args, 's', &key);
|
||||
|
||||
handle->wayland.dbus_reply = wl_call_tbl.dbus_connection_send_with_reply_and_block(handle->wayland.dbus_conn, handle->wayland.dbus_msg, 100, &handle->wayland.dbus_err);
|
||||
|
||||
if(wl_call_tbl.dbus_error_is_set(&handle->wayland.dbus_err)) {
|
||||
fprintf(stderr, "[WARNING] Couldn't get %s::%s: Send error: %s\n", namespace, key, handle->wayland.dbus_err.message);
|
||||
wl_call_tbl.dbus_error_free(&handle->wayland.dbus_err);
|
||||
return;
|
||||
}
|
||||
if(!handle->wayland.dbus_reply) {
|
||||
fprintf(stderr, "[WARNING] Couldn't get %s::%s: No reply received\n", namespace, key);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!wl_call_tbl.dbus_message_iter_init(handle->wayland.dbus_reply, &handle->wayland.dbus_args)) {
|
||||
fprintf(stderr, "[WARNING] Couldn't get %s::%s: Reply has no arguments\n", namespace, key);
|
||||
wl_call_tbl.dbus_message_unref(handle->wayland.dbus_reply);
|
||||
return;
|
||||
}
|
||||
|
||||
if(wl_call_tbl.dbus_message_iter_get_arg_type(&handle->wayland.dbus_args) != 'v') {
|
||||
fprintf(stderr, "[WARNING] Couldn't get %s::%s: Expected outer variant\n", namespace, key);
|
||||
wl_call_tbl.dbus_message_unref(handle->wayland.dbus_reply);
|
||||
return;
|
||||
}
|
||||
wl_call_tbl.dbus_message_iter_recurse(&handle->wayland.dbus_args, &handle->wayland.dbus_variant);
|
||||
|
||||
/* Some portals wrap the value in a second variant */
|
||||
if(wl_call_tbl.dbus_message_iter_get_arg_type(&handle->wayland.dbus_variant) == 'v') {
|
||||
wl_call_tbl.dbus_message_iter_recurse(&handle->wayland.dbus_variant, &handle->wayland.dbus_inner_variant);
|
||||
wl_call_tbl.dbus_message_iter_get_basic(&handle->wayland.dbus_inner_variant, out);
|
||||
} else {
|
||||
wl_call_tbl.dbus_message_iter_get_basic(&handle->wayland.dbus_variant, out);
|
||||
}
|
||||
wl_call_tbl.dbus_message_unref(handle->wayland.dbus_msg);
|
||||
}
|
||||
|
||||
static void detect_dark_theme(MwLL handle) {
|
||||
MwU32 value = 0;
|
||||
MwU32 dark_theme = 0;
|
||||
dbus_get(handle, "org.freedesktop.portal.Settings", "org.freedesktop.appearance", "color-scheme", &value);
|
||||
MwLLDBusPortalGet(&wl_call_tbl.dbus, &handle->wayland.dbus, "org.freedesktop.portal.Settings", "org.freedesktop.appearance", "color-scheme", &value);
|
||||
|
||||
dark_theme = (value == 1) ? 1 : 0;
|
||||
|
||||
MwLLDispatch(handle, dark_theme, &dark_theme);
|
||||
}
|
||||
|
||||
static void dbus_destroy(MwLL handle) {
|
||||
if(!wl_call_tbl.dbus_lib) {
|
||||
return;
|
||||
}
|
||||
if(handle->wayland.dbus_reply) wl_call_tbl.dbus_message_unref(handle->wayland.dbus_reply);
|
||||
if(handle->wayland.dbus_conn) wl_call_tbl.dbus_connection_unref(handle->wayland.dbus_conn);
|
||||
}
|
||||
|
||||
static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
||||
MwLL r;
|
||||
r = malloc(sizeof(*r));
|
||||
|
|
@ -1921,10 +1835,12 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
|||
|
||||
widget_setup(r, parent, x, y, width, height, MWLL_WAYLAND_UNKNOWN);
|
||||
|
||||
if(!parent) {
|
||||
dbus_setup(r);
|
||||
#ifdef USE_DBUS
|
||||
if(!parent && wl_call_tbl.has_dbus) {
|
||||
wl_call_tbl.has_dbus = MwLLDBusNewContext(&wl_call_tbl.dbus, &r->wayland.dbus);
|
||||
r->wayland.dark_theme_detection = MwTRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
return r;
|
||||
}
|
||||
|
|
@ -1960,8 +1876,8 @@ static void MwLLDestroyImpl(MwLL handle) {
|
|||
pthread_mutex_unlock(&handle->wayland.eventsMutex);
|
||||
pthread_mutex_destroy(&handle->wayland.eventsMutex);
|
||||
|
||||
if(!handle->wayland.dbus_conn) {
|
||||
dbus_destroy(handle);
|
||||
if(!wl_call_tbl.has_dbus) {
|
||||
MwLLDBusFreeContext(&wl_call_tbl.dbus, &handle->wayland.dbus);
|
||||
}
|
||||
|
||||
buffer_destroy(&handle->wayland.cursor);
|
||||
|
|
@ -2245,7 +2161,7 @@ static int MwLLPendingImpl(MwLL handle) {
|
|||
int pending = 0;
|
||||
|
||||
if(handle->wayland.dark_theme_detection) {
|
||||
if(handle->wayland.dbus_conn) {
|
||||
if(wl_call_tbl.has_dbus) {
|
||||
detect_dark_theme(handle);
|
||||
handle->wayland.dark_theme_detection = MwFALSE;
|
||||
MwLLDispatch(handle, draw, NULL);
|
||||
|
|
@ -2706,6 +2622,11 @@ static void MwLLEndStateChangeImpl(MwLL handle) {
|
|||
}
|
||||
}
|
||||
|
||||
static void MwLLSetDarkThemeImpl(MwLL handle, int toggle){
|
||||
(void)handle;
|
||||
(void)toggle;
|
||||
}
|
||||
|
||||
static int MwLLWaylandCallInitImpl(void) {
|
||||
#ifdef __linux__
|
||||
MwBool loadWayland = MwFALSE;
|
||||
|
|
|
|||
|
|
@ -4,11 +4,14 @@
|
|||
|
||||
#define ClipboardTimeout 100
|
||||
|
||||
static struct {
|
||||
static struct symtbl {
|
||||
void* lib_xlib;
|
||||
void* lib_xrender;
|
||||
MwBool has_xrender;
|
||||
|
||||
MwLLDBusFuncTable dbus;
|
||||
MwBool has_dbus;
|
||||
|
||||
int (*XClearWindow)(Display* display, Window w);
|
||||
XImage* (*XCreateImage)(Display*, Visual*, unsigned int, int, int, char*, unsigned int, unsigned int, int, int);
|
||||
Display* (*XOpenDisplay)(_Xconst char*);
|
||||
|
|
@ -308,6 +311,16 @@ static XVisualInfo* get_visual_info(Display* display) {
|
|||
return XGetVisualInfo(display, VisualIDMask, &xvi, &n);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
MwLLDispatch(handle, dark_theme, &dark_theme);
|
||||
}
|
||||
|
||||
static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
||||
MwLL r;
|
||||
Window p;
|
||||
|
|
@ -429,6 +442,14 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef USE_DBUS
|
||||
memset(&r->x11.dbus, 0, sizeof(r->x11.dbus));
|
||||
if(!parent && xsymtbl.has_dbus) {
|
||||
xsymtbl.has_dbus = MwLLDBusNewContext(&xsymtbl.dbus, &r->x11.dbus);
|
||||
r->x11.dark_theme_detection = MwTRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
@ -449,6 +470,10 @@ static void MwLLDestroyImpl(MwLL handle) {
|
|||
|
||||
if(handle->x11.toplevel) XCloseDisplay(handle->x11.display);
|
||||
|
||||
if(!xsymtbl.has_dbus) {
|
||||
MwLLDBusFreeContext(&xsymtbl.dbus, &handle->x11.dbus);
|
||||
}
|
||||
|
||||
free(handle);
|
||||
}
|
||||
|
||||
|
|
@ -607,6 +632,14 @@ static void MwLLFreeColorImpl(MwLLColor color) {
|
|||
static int MwLLPendingImpl(MwLL handle) {
|
||||
XEvent ev;
|
||||
|
||||
if(handle->x11.dark_theme_detection) {
|
||||
if(xsymtbl.has_dbus) {
|
||||
detect_dark_theme(handle);
|
||||
handle->x11.dark_theme_detection = MwFALSE;
|
||||
MwLLDispatch(handle, draw, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if(handle->x11.clipboard_pending && (MwTimeGetTick() - handle->x11.clipboard_time) >= ClipboardTimeout) {
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -1275,6 +1308,11 @@ static void MwLLEndStateChangeImpl(MwLL handle) {
|
|||
MwLLShow(handle, 1);
|
||||
}
|
||||
|
||||
static void MwLLSetDarkThemeImpl(MwLL handle, int toggle){
|
||||
(void)handle;
|
||||
(void)toggle;
|
||||
}
|
||||
|
||||
static int MwLLX11CallInitImpl(void) {
|
||||
MwBool loadX11 = MwFALSE;
|
||||
if(getenv("MILSKO_BACKEND")) {
|
||||
|
|
@ -1388,6 +1426,8 @@ static int MwLLX11CallInitImpl(void) {
|
|||
XRENDER_FUNC_LOAD(XRenderSetPictureTransform)
|
||||
XRENDER_FUNC_LOAD(XRenderComposite)
|
||||
#endif
|
||||
|
||||
xsymtbl.has_dbus = MwLLDBusFuncSetup(&xsymtbl.dbus);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue