Skip to content

Commit 57a258c

Browse files
gkleenemersion
authored andcommitted
dbus: add Modes property
1 parent a7c5d46 commit 57a258c

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

dbus/mako.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,37 @@ static int handle_set_modes(sd_bus_message *msg, void *data,
433433
return sd_bus_reply_method_return(msg, "");
434434
}
435435

436+
static int get_modes(sd_bus *bus, const char *path,
437+
const char *interface, const char *property,
438+
sd_bus_message *reply, void *data,
439+
sd_bus_error *ret_error) {
440+
struct mako_state *state = data;
441+
442+
int ret = sd_bus_message_open_container(reply, 'a', "s");
443+
if (ret < 0) {
444+
return ret;
445+
}
446+
447+
const char **mode_ptr;
448+
wl_array_for_each(mode_ptr, &state->current_modes) {
449+
ret = sd_bus_message_append_basic(reply, 's', *mode_ptr);
450+
if (ret < 0) {
451+
return ret;
452+
}
453+
}
454+
455+
ret = sd_bus_message_close_container(reply);
456+
if (ret < 0) {
457+
return ret;
458+
}
459+
460+
return 0;
461+
}
462+
463+
void emit_modes_changed(struct mako_state *state) {
464+
sd_bus_emit_properties_changed(state->bus, service_path, service_interface, "Modes", NULL);
465+
}
466+
436467
static const sd_bus_vtable service_vtable[] = {
437468
SD_BUS_VTABLE_START(0),
438469
SD_BUS_METHOD("DismissAllNotifications", "", "", handle_dismiss_all_notifications, SD_BUS_VTABLE_UNPRIVILEGED),
@@ -447,6 +478,7 @@ static const sd_bus_vtable service_vtable[] = {
447478
SD_BUS_METHOD("SetMode", "s", "", handle_set_mode, SD_BUS_VTABLE_UNPRIVILEGED),
448479
SD_BUS_METHOD("ListModes", "", "as", handle_list_modes, SD_BUS_VTABLE_UNPRIVILEGED),
449480
SD_BUS_METHOD("SetModes", "as", "", handle_set_modes, SD_BUS_VTABLE_UNPRIVILEGED),
481+
SD_BUS_PROPERTY("Modes", "as", get_modes, 0, SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
450482
SD_BUS_VTABLE_END
451483
};
452484

include/dbus.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ void notify_action_invoked(struct mako_action *action,
2525

2626
int init_dbus_xdg(struct mako_state *state);
2727

28+
void emit_modes_changed(struct mako_state *state);
29+
2830
int init_dbus_mako(struct mako_state *state);
2931

3032
#endif

mode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "mako.h"
66
#include "mode.h"
7+
#include "dbus.h"
78

89
bool has_mode(struct mako_state *state, const char *mode) {
910
const char **mode_ptr;
@@ -38,4 +39,6 @@ void set_modes(struct mako_state *state, const char **modes, size_t modes_len) {
3839
char **dst = wl_array_add(&state->current_modes, sizeof(char *));
3940
*dst = strdup(modes[i]);
4041
}
42+
43+
emit_modes_changed(state);
4144
}

0 commit comments

Comments
 (0)