Re: Formally request *X* focus?



Neil Bird <neil fnxweb com> writes:
>   What's the proper way to ask the WM to give input focus to a newly
> popped-up dialogue box?
> 
>   I can't see any obvious or non-obvious GTK/GDK calls/hints/etc.
> 

GDK 2 has this function, which you'll have to do yourself in GDK
1.2. Can leave out the net_wm_supports() part, that is "ask politely
for focus using new window manager spec", just use the fallback case.

void
gdk_window_focus (GdkWindow *window,
                  guint32    timestamp)
{
  g_return_if_fail (GDK_IS_WINDOW (window));

  if (GDK_WINDOW_DESTROYED (window))
    return;
  
  if (gdk_net_wm_supports (gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
    {
      XEvent xev;

      xev.xclient.type = ClientMessage;
      xev.xclient.serial = 0;
      xev.xclient.send_event = True;
      xev.xclient.window = GDK_WINDOW_XWINDOW (window);
      xev.xclient.display = gdk_display;
      xev.xclient.message_type = gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE);
      xev.xclient.format = 32;
      xev.xclient.data.l[0] = 0;
      
      XSendEvent (gdk_display, gdk_root_window, False,
                  SubstructureRedirectMask | SubstructureNotifyMask,
                  &xev);
    }
  else
    {
      XSetInputFocus (GDK_DISPLAY (),
                      GDK_WINDOW_XWINDOW (window),
                      RevertToNone,
                      timestamp);
    }
}

Havoc




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]