How to detect when a window's position is changed in GTKmm 3?

I want to receive a signal every time a window has been moved either physically by the user or programmatically (e.g. Gtk::window::move) in X11.
I tried doing it by calling add_events(Gdk::STRUCTURE_MASK) for the Gtk::Window object and then connecting to its signal_configure_event, but the callback is not being called. I also tried connecting to signal_configure_event on a widget inside the window, but that did not work either.

Hello @Snowdrop!

This sample is working here on GNOME 43 (X11):

#include <gtkmm.h>

class MyAppWindow
 : public Gtk::ApplicationWindow
  explicit MyAppWindow();

  bool on_configure_event(GdkEventConfigure *e);

    sigc::mem_fun(*this, &MyAppWindow::on_configure_event));

MyAppWindow::on_configure_event(GdkEventConfigure *e)
  g_print ("Configure event\n");

  return false; // propagate event

int main(int argc, char *argv[])
  auto app =
    Gtk::Application::create(argc, argv,

  MyAppWindow window;
  window.set_default_size(200, 200);

  return app->run(window);
1 Like

Note that Gtkmm defaults to a connect after behavior. I.e, by default connect() uses g_signal_connect_after. That’s quite surprising in general. To make it use g_signal_connect you can specify the second argument:

    sigc::mem_fun(*this, &MyAppWindow::on_configure_event),
    false /* do not connect after */);

That may help in case an handler blocks propagation

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.