forked from pyrite-dev/milsko
auto detect dark theme change via dbus signals
This commit is contained in:
parent
bc942153fe
commit
138555f41d
3 changed files with 86 additions and 7 deletions
|
|
@ -176,6 +176,69 @@ MWDECL MwBool MwLLDBusPortalGet(MwLLDBusFuncTable* tbl, MwLLDBusContext* ctx, co
|
|||
return MwTRUE;
|
||||
}
|
||||
|
||||
MWDECL MwBool MwLLDBusPortalWatch(MwLLDBusFuncTable* tbl, MwLLDBusContext* ctx, const char* portal) {
|
||||
if(!ctx->dbus_conn) {
|
||||
return MwFALSE;
|
||||
}
|
||||
|
||||
char filter_string[2048];
|
||||
MwStringPrintIntoBuffer(filter_string, sizeof(filter_string), "type='%s',interface=%s", "signal", portal);
|
||||
|
||||
dbus_bus_add_match(ctx->dbus_conn, filter_string, &ctx->dbus_err);
|
||||
dbus_connection_flush(ctx->dbus_conn);
|
||||
|
||||
return MwTRUE;
|
||||
}
|
||||
|
||||
// Technically this will swallow all other results, so this is not usable multiple times.
|
||||
// TODO: Use a hashmap instead
|
||||
MWDECL MwBool MwLLDBusPortalPoll(MwLLDBusFuncTable* tbl, MwLLDBusContext* ctx, MwLL handle, const char* portal, const char* namespace, const char* key, MwLLDBusPortalPollListener listener) {
|
||||
DBusMessage* msg;
|
||||
DBusMessageIter args, msg_value;
|
||||
const char* msg_namespace;
|
||||
const char* msg_key;
|
||||
MwU32 msg_value_content;
|
||||
|
||||
if(!ctx->dbus_conn) {
|
||||
return MwFALSE;
|
||||
}
|
||||
|
||||
dbus_connection_read_write(ctx->dbus_conn, 0);
|
||||
msg = dbus_connection_pop_message(ctx->dbus_conn);
|
||||
|
||||
if (NULL == msg) {
|
||||
return MwFALSE;
|
||||
}
|
||||
|
||||
// check if the message is a signal from the correct interface and with the correct name
|
||||
if (dbus_message_is_signal(msg, portal, "SettingChanged")) {
|
||||
// read the parameters
|
||||
if (!dbus_message_iter_init(msg, &args))
|
||||
fprintf(stderr, "[WARNING] Message has no arguments\n");
|
||||
else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args))
|
||||
fprintf(stderr, "[WARNING] Argument is not string\n");
|
||||
else {
|
||||
dbus_message_iter_get_basic(&args, &msg_namespace);
|
||||
|
||||
dbus_message_iter_next(&args);
|
||||
dbus_message_iter_get_basic(&args, &msg_key);
|
||||
|
||||
// Check that key and namespace match
|
||||
if (strcmp(msg_namespace, namespace) == 0 && strcmp(msg_key, key) == 0) {
|
||||
// Assuming the value is a basic type
|
||||
dbus_message_iter_next(&args);
|
||||
dbus_message_iter_recurse(&args, &msg_value);
|
||||
dbus_message_iter_get_basic(&msg_value, &msg_value_content);
|
||||
|
||||
listener(handle, msg_value_content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// free the message
|
||||
dbus_message_unref(msg);
|
||||
}
|
||||
|
||||
void MwLLDBusFreeContext(MwLLDBusFuncTable* tbl, MwLLDBusContext* ctx) {
|
||||
if(!tbl->lib) {
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue