Skip to content

Commit

Permalink
Prevent stuck keys (by sending keyup on blur)
Browse files Browse the repository at this point in the history
This fixes a bug where, if the user defocused Xpra shortly after pressing a key (sending a keydown), that key could get stuck (the matching keyup would never be sent).
  • Loading branch information
Dan Isla committed Dec 30, 2021
1 parent 112d31b commit 4176697
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions html5/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,18 @@ <h2>Xpra Bug Report</h2>
client._poll_clipboard(e);
}
});

// Prevent stuck keys.
$(window).on("blur", (e) => {
if (client.last_key_packet.length > 2 && client.last_keycode_pressed > 0) {
console.log("clearing keycode: " + client.last_keycode_pressed);
key_packet = client.last_key_packet;
// Set pressed = false to indicate key up.
key_packet[3] = false;
client.send(key_packet);
client.last_key_packet = [];
}
});
}

$(document).ready(function() {
Expand Down
5 changes: 4 additions & 1 deletion html5/js/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ XpraClient.prototype.init_state = function(container) {
this.browser_language_change_embargo_time = 0;
this.key_layout = null;
this.last_keycode_pressed = 0;
this.last_key_packet = [];
// mouse
this.last_button_event = [-1, false, -1, -1];
this.mousedown_event = null;
Expand Down Expand Up @@ -933,7 +934,9 @@ XpraClient.prototype.do_keyb_process = function(pressed, event) {
const me = this;
setTimeout(function () {
while (me.key_packets.length>0) {
me.send(me.key_packets.shift());
var key_packet = me.key_packets.shift();
me.last_key_packet = key_packet;
me.send(key_packet);
}
}, delay);
}
Expand Down

0 comments on commit 4176697

Please sign in to comment.