#include <SFML/Graphics.hpp>
int main()
{
struct WindowDetails
{
sf::VideoMode videoMode;
sf::String name;
sf::Uint32 style;
};
// store the details so we can switch between them
WindowDetails
fullscreenWindowDetails { sf::VideoMode(800, 600), "Alt Tab Fullscreen", sf::Style::Fullscreen },
altTabbedWindowDetails { sf::VideoMode(200, 100), "Alt Tab Fullscreen - alt-tabbed", sf::Style::Default };
bool altTabbed{ false }; // keep track of which state the application is in: altTabbed is true when in window mode and false when fullscreen
sf::RenderWindow window(fullscreenWindowDetails.videoMode, fullscreenWindowDetails.name, fullscreenWindowDetails.style); // start fullscreen
window.setFramerateLimit(60);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed || event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
window.close();
}
// this is the main alt-tab switching code
if (altTabbed)
{
if (window.hasFocus())
{
// window is still in window mode but has focus so switch is back to fullscreen. returns to fullscreen if window is activated any way (not just alt-tabbing)
window.create(fullscreenWindowDetails.videoMode, fullscreenWindowDetails.name, fullscreenWindowDetails.style);
altTabbed = false;
}
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt) && sf::Keyboard::isKeyPressed(sf::Keyboard::Tab))
{
// recreate window (not fullscreen)
window.create(altTabbedWindowDetails.videoMode, altTabbedWindowDetails.name, altTabbedWindowDetails.style);
altTabbed = true;
}
window.clear();
//window.draw();
window.display();
}
return EXIT_SUCCESS;
}