From 8d51780d13576241644ece73afa8e167b3c310f7 Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Sat, 9 Sep 2017 09:00:22 +0000 Subject: [PATCH] randr: Register monitors' output names as additional i3 output names In addition to the name of the monitor itself (which is still used as the i3 output's primary name), register RandR output names associated with the RandR monitor as alternative i3 output names. --- src/randr.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/randr.c b/src/randr.c index df63826d..92d652b7 100644 --- a/src/randr.c +++ b/src/randr.c @@ -599,9 +599,39 @@ static bool randr_query_outputs_15(void) { if (new == NULL) { new = scalloc(1, sizeof(Output)); + SLIST_INIT(&new->names_head); + + /* Register associated output names in addition to the monitor name */ + xcb_randr_output_t *randr_outputs = xcb_randr_monitor_info_outputs(monitor_info); + int randr_output_len = xcb_randr_monitor_info_outputs_length(monitor_info); + for (int i = 0; i < randr_output_len; i++) { + xcb_randr_output_t randr_output = randr_outputs[i]; + + xcb_randr_get_output_info_reply_t *info = + xcb_randr_get_output_info_reply(conn, + xcb_randr_get_output_info(conn, randr_output, monitors->timestamp), + NULL); + + if (info != NULL && info->crtc != XCB_NONE) { + char *oname; + sasprintf(&oname, "%.*s", + xcb_randr_get_output_info_name_length(info), + xcb_randr_get_output_info_name(info)); + + if (strcmp(name, oname) != 0) { + struct output_name *output_name = scalloc(1, sizeof(struct output_name)); + output_name->name = sstrdup(oname); + SLIST_INSERT_HEAD(&new->names_head, output_name, names); + } else { + free(oname); + } + } + FREE(info); + } + + /* Insert the monitor name last, so that it's used as the primary name */ struct output_name *output_name = scalloc(1, sizeof(struct output_name)); output_name->name = sstrdup(name); - SLIST_INIT(&new->names_head); SLIST_INSERT_HEAD(&new->names_head, output_name, names); if (monitor_info->primary) { -- 2.39.5