diff --git a/include/ctl-commands.h b/include/ctl-commands.h index aa3a274..87f1eec 100644 --- a/include/ctl-commands.h +++ b/include/ctl-commands.h @@ -40,6 +40,8 @@ enum event_type { EVT_CLIENT_CONNECTED, EVT_CLIENT_DISCONNECTED, EVT_DETACHED, + EVT_OUTPUT_ADDED, + EVT_OUTPUT_REMOVED, EVT_UNKNOWN, }; #define EVT_LIST_LEN EVT_UNKNOWN diff --git a/include/ctl-server.h b/include/ctl-server.h index 6d3139c..48a6f48 100644 --- a/include/ctl-server.h +++ b/include/ctl-server.h @@ -89,3 +89,6 @@ void ctl_server_event_capture_changed(struct ctl*, const char* captured_output); void ctl_server_event_detached(struct ctl*); + +void ctl_server_event_output_added(struct ctl*, const char* name); +void ctl_server_event_output_removed(struct ctl*, const char* name); diff --git a/src/ctl-commands.c b/src/ctl-commands.c index afd4b22..42e7ff2 100644 --- a/src/ctl-commands.c +++ b/src/ctl-commands.c @@ -128,6 +128,20 @@ struct cmd_info ctl_event_list[] = { "Sent after detaching from compositor", {} }, + [EVT_OUTPUT_ADDED] = {"output-added", + "Sent when an output is added by the compositor", + { + { "name", "Output name", "" }, + {} + } + }, + [EVT_OUTPUT_REMOVED] = {"output-removed", + "Sent when an output is removed by the compositor", + { + { "name", "Output name", "" }, + {} + } + }, }; enum cmd_type ctl_command_parse_name(const char* name) diff --git a/src/ctl-server.c b/src/ctl-server.c index b1d81a6..dcb7ba9 100644 --- a/src/ctl-server.c +++ b/src/ctl-server.c @@ -1005,3 +1005,15 @@ void ctl_server_event_detached(struct ctl* self) { ctl_server_enqueue_event(self, EVT_DETACHED, json_object()); } + +void ctl_server_event_output_added(struct ctl* self, const char* name) +{ + ctl_server_enqueue_event(self, EVT_OUTPUT_ADDED, + json_pack("{s:s}", "name", name)); +} + +void ctl_server_event_output_removed(struct ctl* self, const char* name) +{ + ctl_server_enqueue_event(self, EVT_OUTPUT_REMOVED, + json_pack("{s:s}", "name", name)); +} diff --git a/src/main.c b/src/main.c index 187c5bf..b47d21b 100644 --- a/src/main.c +++ b/src/main.c @@ -240,7 +240,10 @@ static void registry_add(void* data, struct wl_registry* registry, if (!self->is_initializing) { wl_display_dispatch(self->display); wl_display_roundtrip(self->display); + + ctl_server_event_output_added(self->ctl, output->name); } + return; } @@ -322,6 +325,8 @@ static void registry_remove(void* data, struct wl_registry* registry, } else nvnc_log(NVNC_LOG_INFO, "Output %s went away", out->name); + ctl_server_event_output_removed(self->ctl, out->name); + wl_list_remove(&out->link); output_destroy(out);