aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2020-01-02 16:27:23 +0100
committerGerd Hoffmann <kraxel@redhat.com>2020-01-02 16:27:23 +0100
commit3f2c2cc1189e8bc68c5098865d7c7a437688bf64 (patch)
treed229554716a34488cfd916baceca8dd48a467406
parentecfe19dd1bb589b6a3e832e2b2be82828b7d0a51 (diff)
downloaddrminfo-3f2c2cc1189e8bc68c5098865d7c7a437688bf64.tar.gz
output completion
-rw-r--r--complete.c18
-rw-r--r--drminfo.c31
2 files changed, 45 insertions, 4 deletions
diff --git a/complete.c b/complete.c
index 2e9d4a1..87b3332 100644
--- a/complete.c
+++ b/complete.c
@@ -23,11 +23,18 @@
" COMPREPLY=( $(compgen -W \"$words\" -- \"$cur\") )\n" \
" ;;\n"
+#define CASE_OUTPUT \
+ " --output)\n" \
+ " words=$(drminfo --complete-output)\n" \
+ " COMPREPLY=( $(compgen -W \"$words\" -- \"$cur\") )\n" \
+ " ;;\n"
+
void complete_bash(const char *command, struct option *opts)
{
bool have_image = false;
bool have_card = false;
bool have_fbdev = false;
+ bool have_output = false;
char opt_all[1024];
char opt_arg[1024];
int pos_all = 0;
@@ -46,6 +53,8 @@ void complete_bash(const char *command, struct option *opts)
have_card = true;
} else if (strcmp(opts[i].name, "fbdev") == 0) {
have_fbdev = true;
+ } else if (strcmp(opts[i].name, "output") == 0) {
+ have_output = true;
} else if (opts[i].has_arg) {
/* options without argument completion */
@@ -70,7 +79,7 @@ void complete_bash(const char *command, struct option *opts)
" cur=\"${COMP_WORDS[COMP_CWORD]}\"\n"
" prev=\"${COMP_WORDS[COMP_CWORD-1]}\"\n"
" case \"$prev\" in\n"
- "%s%s%s"
+ "%s%s%s%s"
" %s)\n"
" COMPREPLY=()\n"
" ;;\n"
@@ -83,9 +92,10 @@ void complete_bash(const char *command, struct option *opts)
"complete -F _%s_complete %s\n"
"\n",
command,
- have_image ? CASE_IMAGE : "",
- have_card ? CASE_CARD : "",
- have_fbdev ? CASE_FBDEV : "",
+ have_image ? CASE_IMAGE : "",
+ have_card ? CASE_CARD : "",
+ have_fbdev ? CASE_FBDEV : "",
+ have_output ? CASE_OUTPUT : "",
opt_arg, opt_all, command, command);
}
diff --git a/drminfo.c b/drminfo.c
index c211ea2..b6bb293 100644
--- a/drminfo.c
+++ b/drminfo.c
@@ -434,6 +434,29 @@ static void list_formats(FILE *fp)
/* ------------------------------------------------------------------ */
+static void complete_output(int card)
+{
+ drmModeConnector *conn;
+ drmModeRes *res;
+ char name[64];
+ int fd, i;
+
+ logind_init();
+ fd = drm_open(card);
+
+ res = drmModeGetResources(fd);
+ if (res == NULL)
+ return;
+
+ for (i = 0; i < res->count_connectors; i++) {
+ conn = drmModeGetConnector(fd, res->connectors[i]);
+ if (!conn)
+ continue;
+ drm_conn_name(conn, name, sizeof(name));
+ printf("%s\n", name);
+ }
+}
+
static void usage(FILE *fp)
{
fprintf(fp,
@@ -463,6 +486,7 @@ enum {
OPT_LONG_LEASE = 0x100,
OPT_LONG_COMP_BASH,
OPT_LONG_COMP_CARD,
+ OPT_LONG_COMP_OUTPUT,
};
static struct option long_opts[] = {
@@ -516,6 +540,10 @@ static struct option long_opts[] = {
.has_arg = false,
.val = OPT_LONG_COMP_CARD,
},{
+ .name = "complete-output",
+ .has_arg = false,
+ .val = OPT_LONG_COMP_OUTPUT,
+ },{
/* --- with argument --- */
.name = "card",
@@ -599,6 +627,9 @@ int main(int argc, char **argv)
case OPT_LONG_COMP_CARD:
complete_device_nr("/dev/dri/card");
exit(0);
+ case OPT_LONG_COMP_OUTPUT:
+ complete_output(card);
+ exit(0);
case 'h':
usage(stdout);
exit(0);