Skip to content

Win32: EVENT_APPRESUME, EVENT_APPSUSPEND (and so AppSuspended) broken #372

@GWRon

Description

@GWRon

The current revisions of brl.system contain a non working AppResume/Suspend handling (recognition of application is send into the background / alt-tabbed)

Sample:

SuperStrict
Framework Brl.D3D9Max2D

Graphics 800, 600 ', 32
SetBlend AlphaBlend

Function GraphicsHook:Object( id:Int,data:Object,context:Object )
    Local ev:TEvent=TEvent(data)
    If Not ev Return data
    
    Select ev.id
        Case EVENT_APPRESUME
            Print "GAINED"
        Case EVENT_APPSUSPEND
            Print "LOST"
    End Select

    Return data
End Function

AddHook EmitEventHook,GraphicsHook,Null,0


Repeat
    Cls
    
    Global informed:Int = False
    If AppSuspended() 
        If Not informed
            Print "suspended"
            informed = True
        EndIf
    Else
        informed = False
    EndIf
    Flip
Until AppTerminate() Or KeyHit(KEY_ESCAPE)

system.win32.c contains this:

	case WM_ACTIVATE:
		if( LOWORD(wp)==WA_INACTIVE || !IsIconic(hwnd) ){
			DWORD proc;
			GetWindowThreadProcessId( hwnd,&proc );
			if( proc!=GetCurrentProcessId() ){
				id = (LOWORD(wp) == WA_INACTIVE) ? BBEVENT_APPSUSPEND : BBEVENT_APPRESUME;
				break;
			}
		}
		return;

-> so either "if suspended or not minimized"
-> and the event must be initiated by some other process

The second condition is not met (other process should initiate it).

To fix it we could simply change:

			if( proc!=GetCurrentProcessId() ){
//to
			if( proc==GetCurrentProcessId() ){

if we want to only resume and suspend if the application should be the reason for the change.
But this would break if your application had multiple windows - because now it suspends/resums if you switch "inner" windows.

I guess this more likely has to be removed at all - and we suspend/resume simply by being loosing focus or gaining focus (ignoring multi-window) OR ... identify if GetCurrentProcessId() does incorrectly return the calling process or so.

then there is the already commented out code:

	case WM_ACTIVATEAPP:
		//
		// WM_ACTIVATEAPP appears to be broken.
		//
		// Clicking on taskbar button to minimize an app appears to confuse poor old windows.
		//
		// So, we'll use the WM_ACTIVATE code above courtesy of Seb...
		//
		id=wp ? BBEVENT_APPRESUME : BBEVENT_APPSUSPEND;
		break;
		*/

which is the one we should use when we only want to resume/suspend when not switching "inner" Windows (so "Alt-Tab" in a single window application). It would not suspend/resume if inner windows focus changes between each other.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions