From nobody Tue May 7 01:34:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613671908; cv=none; d=zohomail.com; s=zohoarc; b=Vz6E7UftvOKUxJ3jrts9ixHgZuppJX/IvMX58z9l3PxRgXsztImHr1gZgQg2wFJrEylS9gxt0pRYC3cRG5SQKl5DmklylNQ+hq33znwtF6S5MYhbXTtAR+uCCs3/VX8aq9qYjEp5U9494OIJBM41Tno3W2hrGFngk2DXrKNcwHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613671908; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=EyNu0BbGNUwf7tFsk1QuyaLpT6bClgT+K61P5qclUNk=; b=eDzcvvdkVGsHud+VZDBVZ9L/bdLH+vwO3YJzS7UqDHJnpoizIqENsChBkGGXd9qFiDGdUSCH+ePnyZuijqZvdfqTHJWWMS1rqcKX8IyCi8kz7+9tViqQduf11EeP7JQDmeoryYTJk/8tqjOs5iFS4UP7cmEKABBCH5M9g5y7d6E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613671908064201.87992658151722; Thu, 18 Feb 2021 10:11:48 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-142-63l3zU8FPomSw0S-0ls49A-1; Thu, 18 Feb 2021 13:11:44 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 87A59C291; Thu, 18 Feb 2021 18:11:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DDEFE1002393; Thu, 18 Feb 2021 18:11:38 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id AA94918095CB; Thu, 18 Feb 2021 18:11:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11IIBZF1021964 for ; Thu, 18 Feb 2021 13:11:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 18F4B57; Thu, 18 Feb 2021 18:11:35 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.235]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66B305C5AE for ; Thu, 18 Feb 2021 18:11:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613671907; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=EyNu0BbGNUwf7tFsk1QuyaLpT6bClgT+K61P5qclUNk=; b=Ful/TIkE0emDiJNHaG7UP4zk2sy5EYDGcEfG0dFBtW1mzOxzigaiRCtWd/7EvxboGbbanV DoqUuCxq0FPiLIRpFXucAcGfXwXRlcV4Gnie/w9rkhglqxdLuGVV5qXKDLRgkDx9BiUkwX nUPb3vPrcx31MgYYWaYzyHi60OIApvs= X-MC-Unique: 63l3zU8FPomSw0S-0ls49A-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH] virsh: Add virshKeycodeNameCompleter Date: Thu, 18 Feb 2021 19:11:22 +0100 Message-Id: <20210218181122.17769-1-khanicov@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova Reviewed-by: J=C3=A1n Tomko --- tools/virsh-completer-domain.c | 72 ++++++++++++++++++++++++++++++++++ tools/virsh-completer-domain.h | 8 +++- tools/virsh-domain.c | 1 + 3 files changed, 79 insertions(+), 2 deletions(-) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index fc4d7b2e52..15993064fa 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -32,6 +32,9 @@ #include "virperf.h" #include "virbitmap.h" #include "virkeycode.h" +#include "virkeynametable_linux.h" +#include "virkeynametable_osx.h" +#include "virkeynametable_win32.h" =20 char ** virshDomainNameCompleter(vshControl *ctl, @@ -800,3 +803,72 @@ virshCodesetNameCompleter(vshControl *ctl G_GNUC_UNUSE= D, =20 return g_steal_pointer(&tmp); } + + +char ** +virshKeycodeNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + g_auto(GStrv) tmp =3D NULL; + size_t i =3D 0; + size_t j =3D 0; + const char *codeset_option; + int codeset; + const char **names =3D NULL; + size_t len; + + virCheckFlags(0, NULL); + + if (vshCommandOptStringQuiet(ctl, cmd, "codeset", &codeset_option) <= =3D 0) + codeset_option =3D "linux"; + + if (STREQ(codeset_option, "rfb")) + codeset_option =3D "qnum"; + + codeset =3D virKeycodeSetTypeFromString(codeset_option); + + if (codeset < 0) + return NULL; + + switch ((virKeycodeSet) codeset) { + case VIR_KEYCODE_SET_LINUX: + names =3D virKeyNameTable_linux; + len =3D virKeyNameTable_linux_len; + break; + case VIR_KEYCODE_SET_OSX: + names =3D virKeyNameTable_osx; + len =3D virKeyNameTable_osx_len; + break; + case VIR_KEYCODE_SET_WIN32: + names =3D virKeyNameTable_win32; + len =3D virKeyNameTable_win32_len; + break; + case VIR_KEYCODE_SET_XT: + case VIR_KEYCODE_SET_ATSET1: + case VIR_KEYCODE_SET_ATSET2: + case VIR_KEYCODE_SET_ATSET3: + case VIR_KEYCODE_SET_XT_KBD: + case VIR_KEYCODE_SET_USB: + case VIR_KEYCODE_SET_QNUM: + case VIR_KEYCODE_SET_LAST: + break; + } + + if (!names) + return NULL; + + tmp =3D g_new0(char *, len + 1); + + for (i =3D 0; i < len; i++) { + if (!names[i]) + continue; + + tmp[j] =3D g_strdup(names[i]); + j++; + } + + tmp =3D g_renew(char *, tmp, j + 1); + + return g_steal_pointer(&tmp); +} diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h index 4c01b0ca1f..04a3705ff9 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -112,5 +112,9 @@ char ** virshDomainLifecycleActionCompleter(vshControl = *ctl, unsigned int flags); =20 char ** virshCodesetNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); + const vshCmd *cmd, + unsigned int flags); + +char ** virshKeycodeNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index d40995f44d..df33467646 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -8802,6 +8802,7 @@ static const vshCmdOptDef opts_send_key[] =3D { {.name =3D "keycode", .type =3D VSH_OT_ARGV, .flags =3D VSH_OFLAG_REQ, + .completer =3D virshKeycodeNameCompleter, .help =3D N_("the key code") }, {.name =3D NULL} --=20 2.29.2