Compare commits
No commits in common. "6257376b1f4e1acbb4d277290082aba2c42775f8" and "f7eb9840def45894a416521cb5f0b555dad29ca6" have entirely different histories.
6257376b1f
...
f7eb9840de
4 changed files with 8 additions and 182 deletions
|
|
@ -35,11 +35,12 @@ int main() {
|
||||||
|
|
||||||
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT,
|
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT,
|
||||||
MwDEFAULT, 640, 480, MwNtitle, "color picker", NULL);
|
MwDEFAULT, 640, 480, MwNtitle, "color picker", NULL);
|
||||||
MwSetText(window, MwNbackground, MwGetInteger(window, MwNdarkTheme) ? MwDefaultBackground : MwDefaultDarkBackground);
|
MwSetText(window, MwNbackground, "#000000");
|
||||||
|
|
||||||
button = MwVaCreateWidget(MwButtonClass, "button", window, 160, 180, 320, 120,
|
button = MwVaCreateWidget(MwButtonClass, "button", window, 160, 180, 320, 120,
|
||||||
MwNtext, "change window background",
|
MwNtext, "change window background",
|
||||||
NULL);
|
NULL);
|
||||||
|
MwSetText(button, MwNbackground, MwGetInteger(button, MwNdarkTheme) ? MwDefaultDarkBackground : MwDefaultBackground);
|
||||||
|
|
||||||
MwAddUserHandler(button, MwNactivateHandler, color_picker, NULL);
|
MwAddUserHandler(button, MwNactivateHandler, color_picker, NULL);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@
|
||||||
#include <xkbcommon/xkbcommon.h>
|
#include <xkbcommon/xkbcommon.h>
|
||||||
#include <cairo/cairo.h>
|
#include <cairo/cairo.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <dbus/dbus.h>
|
|
||||||
|
|
||||||
MWDECL int MwLLWaylandCallInit(void);
|
MWDECL int MwLLWaylandCallInit(void);
|
||||||
|
|
||||||
|
|
@ -36,7 +35,8 @@ typedef struct wayland_call_table {
|
||||||
void* lib;
|
void* lib;
|
||||||
void* xkb_lib;
|
void* xkb_lib;
|
||||||
void* cairo_lib;
|
void* cairo_lib;
|
||||||
void* dbus_lib;
|
#if WAYLAND_LOAD_OPENGL
|
||||||
|
#endif
|
||||||
|
|
||||||
int (*wl_display_dispatch_pending)(struct wl_display* display);
|
int (*wl_display_dispatch_pending)(struct wl_display* display);
|
||||||
void (*wl_display_disconnect)(struct wl_display* display);
|
void (*wl_display_disconnect)(struct wl_display* display);
|
||||||
|
|
@ -125,21 +125,6 @@ typedef struct wayland_call_table {
|
||||||
void (*cairo_set_antialias)(cairo_t*, cairo_antialias_t);
|
void (*cairo_set_antialias)(cairo_t*, cairo_antialias_t);
|
||||||
void (*cairo_set_operator)(cairo_t* cr, cairo_operator_t op);
|
void (*cairo_set_operator)(cairo_t* cr, cairo_operator_t op);
|
||||||
|
|
||||||
void (*dbus_error_init)(DBusError* error);
|
|
||||||
DBusConnection* (*dbus_bus_get)(DBusBusType type, DBusError* error);
|
|
||||||
dbus_bool_t (*dbus_error_is_set)(const DBusError* error);
|
|
||||||
void (*dbus_error_free)(DBusError* error);
|
|
||||||
DBusMessage* (*dbus_message_new_method_call)(const char* bus_name, const char* path, const char* iface, const char* method);
|
|
||||||
void (*dbus_message_iter_init_append)(DBusMessage* message, DBusMessageIter* iter);
|
|
||||||
dbus_bool_t (*dbus_message_iter_append_basic)(DBusMessageIter* iter, int type, const void* value);
|
|
||||||
DBusMessage* (*dbus_connection_send_with_reply_and_block)(DBusConnection* connection, DBusMessage* message, int timeout_milliseconds, DBusError* error);
|
|
||||||
void (*dbus_message_unref)(DBusMessage* message);
|
|
||||||
dbus_bool_t (*dbus_message_iter_init)(DBusMessage* message, DBusMessageIter* iter);
|
|
||||||
int (*dbus_message_iter_get_arg_type)(DBusMessageIter* iter);
|
|
||||||
void (*dbus_message_iter_recurse)(DBusMessageIter* iter, DBusMessageIter* sub);
|
|
||||||
void (*dbus_connection_unref)(DBusConnection* connection);
|
|
||||||
void (*dbus_message_iter_get_basic)(DBusMessageIter* iter, void* value);
|
|
||||||
|
|
||||||
} wayland_call_table_t;
|
} wayland_call_table_t;
|
||||||
|
|
||||||
extern wayland_call_table_t wl_call_tbl;
|
extern wayland_call_table_t wl_call_tbl;
|
||||||
|
|
@ -240,34 +225,6 @@ MwInline int wayland_load_funcs() {
|
||||||
CAIRO_FUNC(cairo_pattern_set_filter);
|
CAIRO_FUNC(cairo_pattern_set_filter);
|
||||||
#undef CAIRO_FUNC
|
#undef CAIRO_FUNC
|
||||||
|
|
||||||
wl_call_tbl.dbus_lib = MwDynamicOpen("libdbus-1.so");
|
|
||||||
if(!wl_call_tbl.dbus_lib) {
|
|
||||||
fprintf(stderr, "[WARNING] Will not be able to detect dark theme: dbus library (libdbus-1.so) not found.\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DBUS_FUNC(x) \
|
|
||||||
wl_call_tbl.x = MwDynamicSymbol(wl_call_tbl.dbus_lib, #x); \
|
|
||||||
if(!x) { \
|
|
||||||
fprintf(stderr, "[WARNING] Will not be able to detect dark theme: dbus function %s (libdbus-1.so) not found.\n", #x); \
|
|
||||||
return 0; \
|
|
||||||
}
|
|
||||||
|
|
||||||
DBUS_FUNC(dbus_error_init);
|
|
||||||
DBUS_FUNC(dbus_bus_get);
|
|
||||||
DBUS_FUNC(dbus_error_is_set);
|
|
||||||
DBUS_FUNC(dbus_error_free);
|
|
||||||
DBUS_FUNC(dbus_message_new_method_call);
|
|
||||||
DBUS_FUNC(dbus_message_iter_init_append);
|
|
||||||
DBUS_FUNC(dbus_message_iter_append_basic);
|
|
||||||
DBUS_FUNC(dbus_connection_send_with_reply_and_block);
|
|
||||||
DBUS_FUNC(dbus_message_unref);
|
|
||||||
DBUS_FUNC(dbus_message_iter_init);
|
|
||||||
DBUS_FUNC(dbus_message_iter_get_arg_type);
|
|
||||||
DBUS_FUNC(dbus_message_iter_recurse);
|
|
||||||
DBUS_FUNC(dbus_connection_unref);
|
|
||||||
DBUS_FUNC(dbus_message_iter_get_basic);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -479,14 +436,6 @@ struct _MwLLWayland {
|
||||||
struct zwp_locked_pointer_v1* locked_pointer;
|
struct zwp_locked_pointer_v1* locked_pointer;
|
||||||
MwBool pointer_constrained;
|
MwBool pointer_constrained;
|
||||||
|
|
||||||
MwBool dark_theme_detection;
|
|
||||||
time_t dbus_timer;
|
|
||||||
DBusConnection* dbus_conn;
|
|
||||||
DBusError dbus_err;
|
|
||||||
DBusMessage* dbus_msg;
|
|
||||||
DBusMessage* dbus_reply;
|
|
||||||
DBusMessageIter dbus_args, dbus_variant, dbus_inner_variant;
|
|
||||||
|
|
||||||
/* clipboard related stuff.
|
/* clipboard related stuff.
|
||||||
* Note that unlike most interfaces, we don't keep zwp_primary_selection stuff in a wayland_protocol_t because we use wl_data_device as a fallback and want to have it share memory space.*/
|
* Note that unlike most interfaces, we don't keep zwp_primary_selection stuff in a wayland_protocol_t because we use wl_data_device as a fallback and want to have it share memory space.*/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,6 @@ if (grep(/^wayland$/, @backends)) {
|
||||||
scan_wayland_protocol("unstable", "pointer-constraints", "-unstable-v1");
|
scan_wayland_protocol("unstable", "pointer-constraints", "-unstable-v1");
|
||||||
scan_wayland_protocol("unstable", "relative-pointer", "-unstable-v1");
|
scan_wayland_protocol("unstable", "relative-pointer", "-unstable-v1");
|
||||||
|
|
||||||
add_cflags("-I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include");
|
|
||||||
|
|
||||||
$gl_libs = "-lGL -lGLU";
|
$gl_libs = "-lGL -lGLU";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1816,101 +1816,6 @@ static void widget_setup(MwLL r, MwLL parent, int x, int y, int width, int heigh
|
||||||
MwLLEndDraw(r);
|
MwLLEndDraw(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dark_theme_detection_setup(MwLL handle) {
|
|
||||||
const char* namespace = "org.freedesktop.appearance";
|
|
||||||
const char* key = "color-scheme"; /* 0=no preference, 1=dark, 2=light */
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
handle->wayland.dbus_msg = wl_call_tbl.dbus_message_new_method_call(
|
|
||||||
"org.freedesktop.portal.Desktop",
|
|
||||||
"/org/freedesktop/portal/desktop",
|
|
||||||
"org.freedesktop.portal.Settings",
|
|
||||||
"Read");
|
|
||||||
if(!handle->wayland.dbus_msg) {
|
|
||||||
fprintf(stderr, "[WARNING] Could not detect dark theme: Failed to create message\n");
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void detect_dark_theme(MwLL handle) {
|
|
||||||
const char* namespace = "org.freedesktop.appearance";
|
|
||||||
const char* key = "color-scheme"; /* 0=no preference, 1=dark, 2=light */
|
|
||||||
MwU32 value = 0;
|
|
||||||
|
|
||||||
if(!handle->wayland.dbus_conn) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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] Could not detect dark theme: Send error: %s\n", handle->wayland.dbus_err.message);
|
|
||||||
wl_call_tbl.dbus_error_free(&handle->wayland.dbus_err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!handle->wayland.dbus_reply) {
|
|
||||||
fprintf(stderr, "[WARNING] Could not detect dark theme: No reply received\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!wl_call_tbl.dbus_message_iter_init(handle->wayland.dbus_reply, &handle->wayland.dbus_args)) {
|
|
||||||
fprintf(stderr, "[WARNING] Could not detect dark theme: Reply has no arguments\n");
|
|
||||||
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] Could not detect dark theme: Expected outer variant\n");
|
|
||||||
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, &value);
|
|
||||||
} else {
|
|
||||||
wl_call_tbl.dbus_message_iter_get_basic(&handle->wayland.dbus_variant, &value);
|
|
||||||
}
|
|
||||||
|
|
||||||
MwLLDispatch(handle, dark_theme, &value);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dark_theme_detection_destroy(MwLL handle) {
|
|
||||||
if(!wl_call_tbl.dbus_lib) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(handle->wayland.dbus_msg) wl_call_tbl.dbus_message_unref(handle->wayland.dbus_msg);
|
|
||||||
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) {
|
static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
||||||
MwLL r;
|
MwLL r;
|
||||||
r = malloc(sizeof(*r));
|
r = malloc(sizeof(*r));
|
||||||
|
|
@ -1919,11 +1824,6 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
||||||
|
|
||||||
widget_setup(r, parent, x, y, width, height, MWLL_WAYLAND_UNKNOWN);
|
widget_setup(r, parent, x, y, width, height, MWLL_WAYLAND_UNKNOWN);
|
||||||
|
|
||||||
if(!parent) {
|
|
||||||
dark_theme_detection_setup(r);
|
|
||||||
r->wayland.dark_theme_detection = MwTRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1936,11 +1836,6 @@ static void MwLLDestroyImpl(MwLL handle) {
|
||||||
};
|
};
|
||||||
int select_ret;
|
int select_ret;
|
||||||
|
|
||||||
event_loop(handle);
|
|
||||||
// wl_display_cancel_read(handle->wayland.display);
|
|
||||||
|
|
||||||
wl_flush(handle);
|
|
||||||
|
|
||||||
if(pthread_mutex_timedlock(&handle->wayland.eventsMutex, &t) != 0) {
|
if(pthread_mutex_timedlock(&handle->wayland.eventsMutex, &t) != 0) {
|
||||||
printf("WARNING: Couldn't call MwLLDestroyImpl due to deadlock.\n");
|
printf("WARNING: Couldn't call MwLLDestroyImpl due to deadlock.\n");
|
||||||
return;
|
return;
|
||||||
|
|
@ -1948,6 +1843,8 @@ static void MwLLDestroyImpl(MwLL handle) {
|
||||||
|
|
||||||
MwLLDestroyCommon(handle);
|
MwLLDestroyCommon(handle);
|
||||||
|
|
||||||
|
event_loop(handle);
|
||||||
|
|
||||||
/* sleep long enough that any active attempts to wait for the mutex will have given up and we can safely unlock/destroy it */
|
/* sleep long enough that any active attempts to wait for the mutex will have given up and we can safely unlock/destroy it */
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
tv.tv_usec = 1000;
|
tv.tv_usec = 1000;
|
||||||
|
|
@ -1958,10 +1855,7 @@ static void MwLLDestroyImpl(MwLL handle) {
|
||||||
pthread_mutex_unlock(&handle->wayland.eventsMutex);
|
pthread_mutex_unlock(&handle->wayland.eventsMutex);
|
||||||
pthread_mutex_destroy(&handle->wayland.eventsMutex);
|
pthread_mutex_destroy(&handle->wayland.eventsMutex);
|
||||||
|
|
||||||
if(!handle->wayland.dbus_conn) {
|
// framebuffer_destroy(&handle->wayland);
|
||||||
dark_theme_detection_destroy(handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer_destroy(&handle->wayland.cursor);
|
buffer_destroy(&handle->wayland.cursor);
|
||||||
wl_region_destroy(handle->wayland.region);
|
wl_region_destroy(handle->wayland.region);
|
||||||
|
|
||||||
|
|
@ -1994,12 +1888,7 @@ static void MwLLDestroyImpl(MwLL handle) {
|
||||||
shfree(handle->wayland.wl_protocol_map);
|
shfree(handle->wayland.wl_protocol_map);
|
||||||
shfree(handle->wayland.wl_protocol_setup_map);
|
shfree(handle->wayland.wl_protocol_setup_map);
|
||||||
|
|
||||||
wl_keyboard_destroy(handle->wayland.keyboard);
|
free(handle);
|
||||||
wl_pointer_destroy(handle->wayland.pointer);
|
|
||||||
|
|
||||||
wl_flush(handle);
|
|
||||||
|
|
||||||
// free(handle);
|
|
||||||
|
|
||||||
if(currentlyHeldWidget == handle) {
|
if(currentlyHeldWidget == handle) {
|
||||||
currentlyHeldWidget = NULL;
|
currentlyHeldWidget = NULL;
|
||||||
|
|
@ -2242,14 +2131,6 @@ static int MwLLPendingImpl(MwLL handle) {
|
||||||
};
|
};
|
||||||
int pending = 0;
|
int pending = 0;
|
||||||
|
|
||||||
if(handle->wayland.dark_theme_detection) {
|
|
||||||
if(handle->wayland.dbus_conn) {
|
|
||||||
detect_dark_theme(handle);
|
|
||||||
handle->wayland.dark_theme_detection = MwFALSE;
|
|
||||||
MwLLDispatch(handle, draw, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!handle->wayland.did_initial_resize) {
|
if(!handle->wayland.did_initial_resize) {
|
||||||
recursive_dispatch_resize(handle);
|
recursive_dispatch_resize(handle);
|
||||||
handle->wayland.did_initial_resize = 1;
|
handle->wayland.did_initial_resize = 1;
|
||||||
|
|
@ -2668,9 +2549,6 @@ static void MwLLEndStateChangeImpl(MwLL handle) {
|
||||||
|
|
||||||
widget_setup(handle, handle->wayland.parent, handle->wayland.detach_point.x, handle->wayland.detach_point.y, handle->wayland.ww, handle->wayland.wh, handle->wayland.type_to_be);
|
widget_setup(handle, handle->wayland.parent, handle->wayland.detach_point.x, handle->wayland.detach_point.y, handle->wayland.ww, handle->wayland.wh, handle->wayland.type_to_be);
|
||||||
|
|
||||||
if(!handle->wayland.parent)
|
|
||||||
handle->wayland.dark_theme_detection = MwTRUE;
|
|
||||||
|
|
||||||
if(handle->common.user) {
|
if(handle->common.user) {
|
||||||
MwWidget w = handle->common.user;
|
MwWidget w = handle->common.user;
|
||||||
int i;
|
int i;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue