Skip to content

Commit

Permalink
ctl: Emit event when output is added/removed
Browse files Browse the repository at this point in the history
  • Loading branch information
any1 committed Feb 11, 2024
1 parent d819ca4 commit 5d55944
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/ctl-commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions include/ctl-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
14 changes: 14 additions & 0 deletions src/ctl-commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<string>" },
{}
}
},
[EVT_OUTPUT_REMOVED] = {"output-removed",
"Sent when an output is removed by the compositor",
{
{ "name", "Output name", "<string>" },
{}
}
},
};

enum cmd_type ctl_command_parse_name(const char* name)
Expand Down
12 changes: 12 additions & 0 deletions src/ctl-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
5 changes: 5 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 5d55944

Please sign in to comment.