New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Event onClientMTAFocusChange #185

Closed
wants to merge 6 commits into
base: master
from

Conversation

Projects
None yet
6 participants
@CrosRoad95
Copy link
Collaborator

CrosRoad95 commented Jan 25, 2018

This is event similar to onClientMinimize but, insted of checking did mta windows was minimized, this events are triggered when you lost focus on mta window.
If someone play on rpg server in window mode, then he never minimize them. This event can help programmer handle when player is afk

Example script clientside

addEventHandler("onClientMTAFocusChange", root, function (focus)
  outputChatBox(inspect(focus))
end)

Print false when you lost focus on mta window, when you back to game, will print true

@Citizen01
Copy link

Citizen01 left a comment

Thanks for the work you put into MTA lately.
Here are my comments and also in JS the name of such events are Focus and Blur but the latest doesn't sound familiar for someone looking up into the wiki ... But there is also FocusIn and FocusOut.
You event names are perfectly fine to me, just throwing in some variants in case someone wants to debate over it. (Do not rename it until a decision is made).

@@ -740,6 +740,7 @@ class CClientGame
bool m_bBeingDeleted; // To enable speedy disconnect

bool m_bWasMinimized;
bool m_bWasFocus;

This comment has been minimized.

@Citizen01

Citizen01 Jan 25, 2018

m_bWasFocused would be better

@@ -3959,6 +3961,24 @@ void CClientGame::IdleHandler ( void )
m_pManager->GetSoundManager ()->SetMinimizeMuted ( true );
}
}
if ( g_pCore->IsFocused() )
{
if (!m_bWasMinimized)

This comment has been minimized.

@Citizen01

Citizen01 Jan 25, 2018

You probably wanted to use m_bWasFocus instead (or m_bWasFocused if you rename it)

{
if (!m_bWasMinimized)
{
m_bWasMinimized = true;

This comment has been minimized.

@Citizen01

Citizen01 Jan 25, 2018

Same: m_bWasFocus instead (or m_bWasFocused if you rename it)

}
else
{
if (m_bWasMinimized)

This comment has been minimized.

@Citizen01

Citizen01 Jan 25, 2018

Same: m_bWasFocus instead (or m_bWasFocused if you rename it)

{
if (m_bWasMinimized)
{
m_bWasMinimized = false;

This comment has been minimized.

@Citizen01

Citizen01 Jan 25, 2018

Same: m_bWasFocus instead (or m_bWasFocused if you rename it)

@Citizen01

This comment has been minimized.

Copy link

Citizen01 commented Jan 26, 2018

Also, I'm concerned about the performance of CCore::IsFocused:

 bool IsFocused ( void ) { return ( GetForegroundWindow ( ) == GetHookedWindow ( ) ); };

⚠️ I'm asking to whoever knows: Is calling that method every frame okay ?

I really feel like we need some sort of optimization like it has been done with IsWindowMinimized (updated once every 50 ms if I read the code correctly from Github).

CrosRoad95 added some commits Jun 22, 2018

@CrosRoad95 CrosRoad95 changed the title Event onClientMTAFocus and onClientMTALostFocus Event onClientMTAFocusChange Jul 2, 2018

@botder

This comment has been minimized.

Copy link
Member

botder commented Jul 9, 2018

I think it would be much better to wait for the WndProc events, then delegate the event from Core to Deathmatch and finally trigger the event.

@botder botder added review-required and removed enhancement labels Jul 9, 2018

@qaisjp qaisjp removed the review required label Jul 14, 2018

CrosRoad95 added some commits Jul 24, 2018

@botder

This comment has been minimized.

Copy link
Member

botder commented Sep 27, 2018

I assume you have to add code to these following lines, which handle the focus loss/gain of the GTA window:

if (uMsg == WM_ACTIVATE && LOWORD(wParam) == WA_ACTIVE)
{
GetVideoModeManager()->OnGainFocus();
}
if (uMsg == WM_ACTIVATE && LOWORD(wParam) == WA_INACTIVE)
{
GetVideoModeManager()->OnLoseFocus();
}

From there you can call into the deathmatch module to handle the focus change.

@botder botder self-assigned this Sep 30, 2018

@botder botder removed the question label Sep 30, 2018

@botder botder changed the title Event onClientMTAFocusChange WIP: Event onClientMTAFocusChange Sep 30, 2018

@botder

This comment has been minimized.

Copy link
Member

botder commented Jan 7, 2019

@qaisjp

This comment has been minimized.

Copy link
Member

qaisjp commented Feb 10, 2019

stale

@qaisjp qaisjp closed this Feb 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment