GTK detecting window resize from the user

前端 未结 5 941
我在风中等你
我在风中等你 2020-12-10 11:58

In GTK (or pygtk or gtkmm...)

How can I detect that an application window has been manually resized by the user, as is typically done by dragging th

5条回答
  •  余生分开走
    2020-12-10 12:07

    I managed to pull this off by watching for size_allocate and size_request signals on the GtkWindow. If size_request ever got smaller, I called resize(1,1). If size_allocate was ever bigger than expected, I turned the system off.

    One thing I made sure to handle was size_request returning big, then small, and having size_allocate be big and then small. I don't know if this is possible, but I fixed it by making sure to only decrease the expected values for size_allocate when I got a smaller size_allocate, not when I got a smaller size_request.

    Make sure that your size_request handler comes after the base class' handler so that you get the right values. I did this by overriding the method and then calling the base class method first.

    I've tried this in both 1 and 2 dimensions and it seems to work either way.

提交回复
热议问题