I'm glad you posed this problem. It was an interesting thing to solve. This can be run as-is:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "", sf::Style::None);
sf::Vector2i grabbedOffset;
bool grabbedWindow = false;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
else if (event.type == sf::Event::KeyPressed)
{
if (event.key.code == sf::Keyboard::Escape)
window.close();
}
else if (event.type == sf::Event::MouseButtonPressed)
{
if (event.mouseButton.button == sf::Mouse::Left)
{
grabbedOffset = window.getPosition() - sf::Mouse::getPosition();
grabbedWindow = true;
}
}
else if (event.type == sf::Event::MouseButtonReleased)
{
if (event.mouseButton.button == sf::Mouse::Left)
grabbedWindow = false;
}
else if (event.type == sf::Event::MouseMoved)
{
if (grabbedWindow)
window.setPosition(sf::Mouse::getPosition() + grabbedOffset);
}
}
window.clear(sf::Color::Red);
window.display();
}
}
It works on all window types, not just borderless.
You can press Escape to close or use another closing method (taskbar etc.)
EDIT: removed some code I was using for testing.
EDIT 2: just noticed that it also works in fullscreen mode