Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [BUG] [Linux] Calling Window.setSize() while resizing makes the window grow  (Read 9609 times)

0 Members and 1 Guest are viewing this topic.

Chnossos

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Deep Space Battle - MMOAG spatial
Hi,

Using SFML 2.5.1 on Fedora 32 (GCC 10). I want to restrict the size of the window so it doesn't shrink more than a certain size.
Using the following code, when I start to resize horizontally (mouse button pressed then mouse move) the window will grow in height until it reaches the top of the screen or until I release the resize handle (mouse button released).

#include <SFML/Window.hpp>

int main()
{
    sf::Window window(sf::VideoMode(1280, 720, sf::VideoMode::getDesktopMode().bitsPerPixel), "W");

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            /**/ if (event.type == sf::Event::Closed)
                window.close();
            else if (event.type == sf::Event::Resized)
            {
                if (event.size.width < 1280 || event.size.height < 720)
                    window.setSize({ 1280, 720 });
            }
        }
    }
}
 

The window end up not resizing to the values I want as a minimum. So I told myself "let's try to wait the release of the handle" but there is no such event. I tried this:

    sf::Vector2u newSize;
    while (window.isOpen())
    {
        bool resizing = false;

        sf::Event event;
        while (window.pollEvent(event))
        {
            /**/ if (event.type == sf::Event::Closed)
                window.close();
            else if (event.type == sf::Event::Resized)
            {
                newSize.x = event.size.width  < 1280 ? 1280 : event.size.width;
                newSize.y = event.size.height < 720  ? 720  : event.size.height;
                resizing = true;
            }
        }

        if (!resizing && newSize != sf::Vector2u())
        {
            window.setSize(newSize);
            newSize = sf::Vector2u();
        }
    }

But it doesn't work either because the moment I stop moving but still holding the resize handle the next frame will update the window size since no event is generated (Resized is only generated when there's actually a change in size).

I see 3 paths of resolution:
  • Send new ResizeStart/ResizeStop events ;
  • Send Resized event until the handle is released ;
  • Find a way to actually specify a min/max width/height on the window so even if the user tries to, the window size doesn't go beyond what's been intended (sadly I supposed it is up to the Window Manager to decide about this).

PS: I can talk in French if that's easier to discuss.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Not sure I fully understood the issue you're running into.

So with the given code, if you start changing the size, then the window starts "moving" around,  thus making your window resize "on its own" until it's reaches the full horizontal or vertical size?

Can you take a short video/gif of the issue, just so we properly understand it?
Also feel free to open an issue on GitHub about this.

On Windows the code looks like this:
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ShardTheBroken

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Sorry for bringing up an old topic, but I am having this exact same issue with Ubuntu 24.04, g++14. Here is a link to a video showing the issue: https://drive.google.com/file/d/12NNll-IviG9l_DNPJ6k5ZhanWEakC7MS/view?usp=sharing.

My resize handling code is equivalent to:

if( event.type == sf::Event::Resized )
{
        Vector2u size { std::max( event.size.width, MinWindowWidth ), std::max( event.size.height, MinWindowHeight ) };

        if( size.x != event.size.width || size.y != event.size.height )
        {
                m_window->setSize( size );
                continue;
        }

        sf::View view = m_window->getView();
        Vector2f tl = view.getCenter() - ( view.getSize() * 0.5f );

        view.setSize( Vector2f( static_cast<float>( event.size.width ), static_cast<float>( event.size.height ) ) );
        view.setCenter( tl + Vector2f( view.getSize() * 0.5f ) );
        view.setViewport( { { 0.f, 0.f }, { 1.f, 1.f } } );

        m_window->setView( view );
}
 

Edit: Using SFML 2.6.1