A solid ALT-ENTER scheme

Discuss programming topics for the various GPL'd game engine sources.
Post Reply
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

A solid ALT-ENTER scheme

Post by Baker »

I like the idea of toggling between fullscreen and windowed at any time with ALT-ENTER.

But it has always sucked on exactly how to implement it right. Both ProQuake and Engine X do this pretty decently, but it isn't perfect.

And here is why ...

1) Not every windowed mode translates into fullscreen. (780 x 500 is fine for a window, there is no such fullscreen mode of course)
2) Even if a windowed mode did translate into fullscreen, you have bpp and other guys to consider.
3) So, let's say you are in fullscreen mode and press ALT-ENTER to windowed mode and then exit, what video mode writes to config :?: :?: :?:
4) Let's say I am in fullscreen mode at maximum resolution and want to switch to windowed mode. Well, that isn't going to work with the taskbar and the window borders. So it will have to be a different windowed video mode.

After thinking about it, here is what I did and it works nicely. The video mode you INTENTIONALLY set yourself is the real video mode --- whether from your config, the default Quake one or if you set it in video mode options.

If you press ALT-ENTER while in an intentionally set mode, the new mode is treated as a temporary mode. If you exit, it will save your "intentionally chosen" video mode to config.

The key code is always touchy ... I've done it before but can never remember how to get it perfect (initially) ... I implemented key combos in this way:

Code: Select all

/*
===================
Key_Event

Called by the system between frames for both key up and key down events
Should NOT be called during an interrupt!
===================
*/
#ifdef SUPPORTS_SPECIAL_KEY_COMBINES // Baker change
qboolean Keys_All_Up_But_Me (int key)
{
	qboolean anydown = false;
	int i;

	for (i = 0; i < 256; i ++)
	{
		if (key == i) // Don't check this key of course, it was just released but not updated.  But we can't do it here
			continue;
		else if (keydown[i])
			return false;
	}

	// Nothing down except the key being released
	return true;
}

#endif // Baker change +

void Key_Event (int key, qboolean down)
{
	char		*kb;
	char		cmd[1024];

#ifdef SUPPORTS_SPECIAL_KEY_COMBINES // Baker change

#define COMBO_NONE 		0
#define COMBO_ALT_ENTER 1
#define COMBO_ALT_M 	2

	static int	in_key_combo = COMBO_NONE; // Combo hit.  Wait for all keys up.
	static int  enact_combo  = COMBO_NONE; // Activate combo
	
	if (in_key_combo && !down && enact_combo == 0)
		if (Keys_All_Up_But_Me (key))
		{
			// Combo was in effect and all keys are now released
			// Except current key which was just released.
			// Enact this combo.
			enact_combo = in_key_combo;

			Key_Event (key, down); // Process like normal ...

			// Now perform the combo action ...
			if (enact_combo == COMBO_ALT_ENTER) VID_Alt_Enter_f ();
			if (enact_combo == COMBO_ALT_M)		Sound_Toggle_Mute_f ();

			enact_combo = in_key_combo = 0;  // Reset
			return; // Get out.  We are done.  
		}

#endif // Baker change +

	keydown[key] = down;

#ifdef SUPPORTS_SPECIAL_KEY_COMBINES // Baker change
	// Enter key released while ALT depressed
	if (key == K_ENTER  && !down && keydown[K_ALT] && in_key_combo == COMBO_NONE /* && vid_altenter_toggle.integer*/)
		in_key_combo = COMBO_ALT_ENTER; // Once all keys and buttons are released, vid change occurs.

	if (key == 109 /* M */ && !down && keydown[K_ALT] && in_key_combo == COMBO_NONE)
		in_key_combo = COMBO_ALT_M;
#endif // Baker change +

	if (!down)
		key_repeats[key] = 0;

	key_lastpress = key;
	key_count++;
	if (key_count <= 0)
	{
		return;		// just catching keys for Con_NotifyBox
	}
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
Post Reply