Register
Final Platform Layer»Forums»Window closing being weird
Jai
5 posts
Window closing being weird
4 months ago Edited by Jai on Oct. 28, 2020, 3:54 p.m. Reason: Initial post
Hey! this is my code for window closing:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
    while (fplPollEvent(currentEvent)) {
		
        switch (currentEvent->type) {
			
            case fplEventType_Window: {
                // A window event, like resize, lost/got focus, etc.
                switch (currentEvent->window.type) {
					
                    case fplWindowEventType_Closed: {
                        global_running = false;
                    } break;
             ...


And for pressing Alt + F4:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
fplKey mappedKey = currentEvent->keyboard.mappedKey;
                        if (state == fplButtonState_Release) {
							
							// F4 key pressed
                            if (mappedKey == fplKey_F4) {
								            
								fplKeyboardModifierFlags keyModifier = currentEvent->keyboard.modifiers;
                                if (keyModifier == fplKeyboardModifierFlags_LAlt
									|| keyModifier == fplKeyboardModifierFlags_RAlt) {
									
                                    global_running = false;
                                }
                            }
                        }


However, none of these cases are being hit, windows is handling these events before I can - the window just closes, but the game is running in the background. What am I doing wrong here?
144 posts / 1 project

I am finalspace and do programming since more than 25 years, started on C64 and got serious with borland delphi. Nowadays i use C/C++ only.

Window closing being weird
6 days, 5 hours ago
Hi there,

sorry for the late answer, but now after i released fpl 0.9.5 i want to solve your issue now.
But first i need to explain why this happens:

The key combination F4 and alt-key are handled directly inside FPL in the win32 event for detecting the key-presses:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
...
fpl__HandleKeyboardButtonEvent(&appState->window, GetTickCount(), keyCode, modifiers, keyState, false);
if (wasDown != isDown) {
	if (isDown) {
		if (keyCode == VK_F4 && altKeyIsDown) {
			appState->window.isRunning = false;
		}
	}
}
...


I have no idea why i did it, i think i will remove this code so the window manager (Win32, X11) can handle this automatically.
Meaning in windows pressing Alt+F4 will send a WM_CLOSE message to your window and then FPL will stop the event handling.

Please post pack if that solves your problem (the develop branch contains the fix!)