Opened 8 years ago

Last modified 15 months ago

#3870 closed defect

[PATCH] SDL 2.0.4 update broke hotkeys on windows (Opening team chat with key T automatically writes a t in input dialog) — at Version 38

Reported by: Imarok Owned by:
Priority: Must Have Milestone: Alpha 26
Component: Core engine Keywords: patch
Cc: Patch:

Description (last modified by elexis)

On windows, opening the team chat window with key T automatically writes a t in input dialog A Patch could be to open the team chat window not until the t key has been released.


Testing on Windows revealed that the SDL 2.0.4 update in r17658 introduced this behavior.

Change History (43)

comment:1 by Imarok, 8 years ago

Cc: jon12@… added
Description: modified (diff)

comment:2 by elexis, 8 years ago

I heard this from others too, but I can't reproduce it. According to sanderd17, it has been like that since some time, but only when the dialog is opened the first time. Maybe it is a platform-dependent bug?

Can someone check if adding chatInput.caption = ""; to the end of function toggleChatWindow() in menu.js is sufficient?

If it truly is a platform-dependent bug, it might appear in other places too though...

comment:3 by Imarok, 8 years ago

Cc: jon12@… removed

comment:4 by Imarok, 8 years ago

" but only when the dialog is opened the first time": When you mean the bug only appears the first time you open team chat via "t" and after sending a message and reopen team chat with "t" the bug doesnt occur: thats wrong. The bug always appears. I'm using windows.

comment:5 by Imarok, 8 years ago

I will try it after downloading visual c++ and the source. ;) Do you mean the menu.js in: ps/trunk/binaries/data/mods/public/gui/session/menu.js?

Last edited 8 years ago by Imarok (previous) (diff)

comment:6 by sanderd17, 8 years ago

There's no need to use visual C++. The changes should be done in the scripts (*.js files), so you don't have to compile those. And we offer a precompiled version of the game for windows.

So you should download the source, then modify that file in a good text editor (like notepad++), and then you can just run it from the precompiled binary (under binaries/system).

comment:7 by Imarok, 8 years ago

Seems logic :D

I changed the menu.js at binaries\data\mods\public\gui\session to

function toggleChatWindow(teamChat)
{
	if (g_Disconnected)
		return;

	let chatWindow = Engine.GetGUIObjectByName("chatDialogPanel");
	let chatInput = Engine.GetGUIObjectByName("chatInput");
	let hidden = chatWindow.hidden;

	closeOpenDialogs();

	if (hidden)
	{
		setTeamChat(teamChat);
		chatInput.focus();
	}
	else
	{
		if (chatInput.caption.length)
		{
			submitChatInput();
			return;
		}
		chatInput.caption = "";
	}

	chatWindow.hidden = !hidden;
	chatInput.caption = "";
}

started 0ad with binaries/system/pyrogenesis.exe and the bug still remains :(

Last edited 8 years ago by Imarok (previous) (diff)

comment:8 by elexis, 8 years ago

Do you still have alpha 19? It didn't happen there?

comment:9 by Imarok, 8 years ago

I installed the new alpha 20 3 hours ago :( I don't know if it happend in alpha 19

Last edited 8 years ago by Imarok (previous) (diff)

comment:10 by Imarok, 8 years ago

I reinstalled alpha 19 now. There the bug only occurs the first time in the running time of the program. In alpha 20 it occurs always.

comment:11 by sanderd17, 8 years ago

Imarok, can you add a line like

warn("it works");

to that file (next to the line you added), just to assure that the modifications were read (and the game isn't reading the scripts from some other installation. You should see a yellow "It works" line appearing then every time you open the chat window.

comment:12 by Imarok, 8 years ago

I added this line, the warning came when pressing t but the bug stayed. I noticed pressing Ctrl+T opens the team chat window without writing t into the input box

comment:13 by njm, 8 years ago

I think the function toggleChatWindow in menu.js should consume the key event to stop its propagation/bubbling. But I don't know how (yet).

comment:14 by Imarok, 8 years ago

Another way would be to let the function wait until the key is unpressed.

comment:15 by Dummer, 8 years ago

with AutoIt this with be easy

comment:16 by elexis, 8 years ago

To me this looks like CGUI.cpp sending the press event on SDL_HOTKEYDOWN, while it should be SDL_HOTKEYUP, as the latter one also waits for the button to be released. Changing this however closes the chatbox again when typing t.

comment:17 by njm, 8 years ago

I suggest to only open the chat window with the hotkey on SDL_HOTKEYUP (as suggested by elexis) and close the chat window when a message is submitted or the dialog is cancelled. The second part is already implemented. The first part would mean to rename toggleChatWindow to openChatWindow and only open the chat window, if it isn't open. Additionally submitChatInput in messages.js should call closeChat in menu.js instead of toggleChatWindow.

The "else"-part in toggleChatWindow seems to be obsolete anyway, because the chat dialog in session.xml uses the function submitChatInput directly.

Do you agree? If so, I can do it.

comment:18 by Imarok, 8 years ago

I'm just a "noob" to the 0ad code, but this sounds good.

by Imarok, 8 years ago

Attachment: keyfix.patch added

change SDL_HOTKEYDOWN to SDL_HOTKEYUP and move the text input part

comment:19 by Imarok, 8 years ago

Keywords: review patch added
Milestone: BacklogAlpha 21
Summary: Opening team chat with key T automatically writes a t in input dialog[PATCH]Opening team chat with key T automatically writes a t in input dialog

comment:20 by elexis, 8 years ago

Keywords: simple review removed

Doesn't work fully here (linux):

  • Escape doesn't close the chat dialog
  • Enter sends the chat and opens it again

Also when moving code, the code should be optimized:

  • operators like || should appear in the end of a line
  • those 2 ifs could be merged

Not sure if the comment would remain true after moving // else will return IN_PASS because we never used the button

But it seems that code path you moved is the one being triggered incorrectly.

by Imarok, 8 years ago

Attachment: keyfixv2.patch added

fixes #3870 but the inserted tchat text doesn't get sended anymore

comment:21 by Imarok, 8 years ago

This patch fixes the bug but the inserted text doesn't get sent. I can't figure out why...

by Imarok, 8 years ago

Attachment: keyfixv3.patch added

Now the chat message gets sent

comment:22 by Imarok, 8 years ago

Keywords: review added

comment:23 by elexis, 8 years ago

Description: modified (diff)
Priority: Should HaveMust Have

comment:24 by elexis, 8 years ago

Keywords: review removed

Closes the chat window when typing t (on a gnu/linux machine) :-L

Last edited 8 years ago by elexis (previous) (diff)

comment:25 by Imarok, 8 years ago

I'll give it up :(

comment:26 by Imarok, 8 years ago

Keywords: patch removed
Summary: [PATCH]Opening team chat with key T automatically writes a t in input dialogOpening team chat with key T automatically writes a t in input dialog

in reply to:  25 ; comment:27 by njm, 8 years ago

Replying to Imarok:

I'll give it up :(

Ok, I'll try tomorrow.

in reply to:  27 comment:28 by Imarok, 8 years ago

Replying to njm:

Replying to Imarok:

I'll give it up :(

Ok, I'll try tomorrow.

Good luck ;)

by njm, 8 years ago

Attachment: keyfixv4.patch added

Improvement to Imarok's patch: Typing t in chat does not close the chat anymore. More information below.

comment:29 by njm, 8 years ago

Information regarding above keyfixv4.patch: I used the last patch of Imarok (thanks!), that altered C++ files, and I altered JavaScript files.

  • Typing a t in chat now does not close the chat anymore.
  • Renamed toggleChatWindow to openChatWindow, because it is/was only used for that. Altered containing code.
  • Deleted openChat, that was called when opening the chat window via menu, and use openChatWindow instead. Like this, the chat input is not deleted and now focused, when clicking Chat in the menu.
  • Further improvement would be to set the cursor to the end of the chat input, when the Chat button in the menu is clicked.

comment:30 by njm, 8 years ago

Keywords: review patch added
Summary: Opening team chat with key T automatically writes a t in input dialog[PATCH] Opening team chat with key T automatically writes a t in input dialog

comment:31 by elexis, 8 years ago

Awesome, the patch works, great teamwork!

Can someone recapitulate what the c++ change does and which of these JS changes are crucial to fix the bug?

Now to the codestyle-nitpicking:

  • Why replace the call to closeOpenDialogs with closeMenu()? The former does the same and closes also other stuff, so should be saner.
  • if( should be if (
  • agreing that toggleChat should be replaced with openChat and closeChat
  • closeChat()` -> an early return would be better with regards to codestyle. But why add the check in the first place? If you don't want to clear chat in both cases (opening&closing), then completely remove the duplicate clears (and test that it doesnt introduce bugs).
  • Make a variable for the GUI object chatInput as well, the clear-chat comment is not needed
  • As mentioned by Imarok, funciton names should be consistent (either both or none of them should contain "Window")

comment:32 by sanderd17, 8 years ago

Just tested the patch on Linux, and it indeed got rid of the annoying "t" (which I only got on the first opening of the dialog). And I didn't notice any negative side effects.

So functionality-wise, this is fine IMO, and I'll leave it to elexis to do the code review.

comment:33 by elexis, 8 years ago

Keywords: review removed

(Most) hotkeys shouldn't work if chat is focused. For example whenever the user types the idle-worker-hotkey (dot), then an idle worker will be selected. The action was not intended though, as the user only wanted to add text. Another example is selecting a CC and then typing a queue hotkey, (Y/Z, X, C, V, ...)

in reply to:  10 comment:34 by elexis, 8 years ago

Replying to Imarok:

I reinstalled alpha 19 now. There the bug only occurs the first time in the running time of the program. In alpha 20 it occurs always.

So find the revision that introduced the platform-specific difference. It was somewhere between r17299 (alpha19) and r17965 (alpha 20).

As SDL is responsible for input, maybe it was r17658?

Boot windows, revert your stuff, do svn update -r <revision> and compile the code.

You only need a logarithmical amount of tries to find the commit. If the bug occurs on rev X but not rev Y, then check for the revision right between them. Thus you divide the number of commits to check by 2 everytime.

by Imarok, 8 years ago

Attachment: keyfixv5.patch added

Now hotkeys shouldn't work in chat

comment:35 by Imarok, 8 years ago

The new patch disables escape :(

comment:36 by elexis, 8 years ago

Priority: Must HaveRelease Blocker

Nominated for most annoying bugs of the last release. Doesn't need to stay, but should really be fixed.

comment:37 by Imarok, 8 years ago

r17658 is responsible for this bug. (I tested that)

Last edited 8 years ago by Imarok (previous) (diff)

comment:38 by elexis, 8 years ago

Description: modified (diff)
Summary: [PATCH] Opening team chat with key T automatically writes a t in input dialog[PATCH] SDL 2.0.4 update broke hotkeys on windows (Opening team chat with key T automatically writes a t in input dialog)
Note: See TracTickets for help on using tickets.