From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <s.ivanov@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 79A3467D88
 for <pve-devel@lists.proxmox.com>; Tue, 10 Nov 2020 15:16:12 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 6FECA22CBD
 for <pve-devel@lists.proxmox.com>; Tue, 10 Nov 2020 15:15:42 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 6A13622C9C
 for <pve-devel@lists.proxmox.com>; Tue, 10 Nov 2020 15:15:41 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 3D7C246034
 for <pve-devel@lists.proxmox.com>; Tue, 10 Nov 2020 15:15:41 +0100 (CET)
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Tue, 10 Nov 2020 15:15:28 +0100
Message-Id: <20201110141530.30904-2-s.ivanov@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20201110141530.30904-1-s.ivanov@proxmox.com>
References: <20201110141530.30904-1-s.ivanov@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.096 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH installer 1/3] memorize keyboard layout selection
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 10 Nov 2020 14:16:12 -0000

currently when using the previous/next buttons the keyboard layout gets
defined based on the detected/selected country, even if it was set to a
different value explicitly.

This patch changes the behaviour to only update the layout and set it in
the installer if it got actively changed, or if a different country was
selected

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
 proxinstall | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/proxinstall b/proxinstall
index 9879df4..9977f44 100755
--- a/proxinstall
+++ b/proxinstall
@@ -2549,6 +2549,8 @@ sub get_device_desc {
     }
 }
 
+my $last_layout;
+my $country_layout;
 sub update_layout {
     my ($cb, $kmap) = @_;
 
@@ -2562,7 +2564,14 @@ sub update_layout {
 	$i++;
     }
 
-    $cb->set_active($ind || $def || 0);
+    my $val = $ind || $def || 0;
+
+    if (!defined($kmap)) {
+	$last_layout //= $val;
+    } elsif (!defined($country_layout) || $country_layout != $val) {
+	$last_layout = $country_layout = $val;
+    }
+    $cb->set_active($last_layout);
 }
 
 my $lastzonecb;
@@ -2699,6 +2708,7 @@ sub create_password_view {
 
 }
 
+my $installer_kmap;
 sub create_country_view {
 
     cleanup_view();
@@ -2744,11 +2754,16 @@ sub create_country_view {
 
     $kmapcb->signal_connect ('changed' => sub {
 	my $sel = $kmapcb->get_active_text();
+	$last_layout = $kmapcb->get_active();
 	if (my $kmap = $cmap->{kmaphash}->{$sel}) {
 	    my $xkmap = $cmap->{kmap}->{$kmap}->{x11};
 	    my $xvar = $cmap->{kmap}->{$kmap}->{x11var};
 	    $keymap = $kmap;
 
+	    return if (defined($installer_kmap) && $installer_kmap eq $kmap);
+
+	    $installer_kmap = $keymap;
+
 	    if (! $opt_testmode) {
 		syscmd ("setxkbmap $xkmap $xvar");
 	    }
-- 
2.20.1