1

Active window isn't returning true from IsActive() under wxGTK.

My software has a main window and a set of tool windows, all derived from wxFrame. When the main window is moved it captures the move event and calls a position method in all the tool windows so that they all move together.

Each of the tool windows can be moved independently, and when the user moves them I need to catch the move event and update their position relative to the main window. To check whether they're being moved by the user or the main window I use IsActive(). This works fine under wxMSW and wxOSX but not wxGTK.

void ToolBox::OnMove(wxMoveEvent& event)
{
    wxPoint shift;

    if(IsActive()) {
        wxPoint newpos = GetPosition();
        (calculate new postion)
    }   
}

ToolBox is derived from wxFrame

Is this a bug in wxGTK? Better way to do this?

1 Answers1

0

Under GTK a frame becomes active when it gets focus, so depending on the focus policy of your WM it's possible that it's not considered as being active if you just drag it by its title bar, if this doesn't actually give it focus.

I am not sure if this can be corrected at wxGTK level, but you definitely can work around this by having a movedByProgram flag which would be set each time you call Move() in your code and reset in wxEVT_MOVE handler. Then you'd be able to detect user moves by just checking if this flag is unset.

VZ.
  • 21,740
  • 3
  • 39
  • 42
  • Thanks for the info. That's a neat workaround, but doesn't quite work unfortunately. It can detect user moves ok, but moving the windows under the control of the main window only works when going very slowly. Faster movements seem to trigger additional move events which occur after the flag has been reset. Currently testing with Unity in Ubuntu. Best workaround so far is to allow explicitly setting the window active, by detecting a mouse click in its panel, but it's not ideal. Even using the controls in the window still gets a false response to IsActive(). – doctorafternoon Jan 31 '14 at 13:51
  • Try resetting the flag in the next `wxEVT_IDLE`, this is hackish but should take care of the problem. – VZ. Jan 31 '14 at 14:09