如何知道哪个窗口具有焦点以及如何更改它? [英] How to know which window has focus and how to change it?

查看:28
本文介绍了如何知道哪个窗口具有焦点以及如何更改它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何询问 X11 哪些窗口具有焦点.如果出于任何原因我自己的应用程序(可能可见或不可见)获得焦点,我希望能够让以前的窗口再次获得焦点.

I would like to know how can I ask X11 which windows has focus. And if for any reason my own application (that may be visible or not) got the focus I want be able to let the former windows to get focus again.

例如,我的应用程序正在与许多其他应用程序(例如 firefox、gvim、nautilus 等)一起运行

For instance, my application is running with many others (e.g. firefox, gvim, nautilus,...)

假设最初 firefox 具有焦点并且用户单击了现在具有焦点的我的应用程序.我希望我的应用程序再次将焦点放在 Firefox 上.

Suppose that at first firefox has focus and that the user clicked on my app which now has the focus. I want that my application put focus on firefox again.

有谁知道如何实现这一目标?书籍推荐会非常好.

Does anyone knows how to achieve this? Books recommendations would be very nice.

非常感谢.

推荐答案

使用此 XQueryTree 来查找当前活动的或最顶部的窗口.

Use this XQueryTree to find the currently active, or top-most window.

这是一个函数,当给定一个显示时,它会找到当前焦点:

Here is a function, when given a display, it will find the current window in focus:

static Window
GetCurrWindow(d)
Display *d;
{
Window foo;
Window win;
int bar;

    do{
    (void) XQueryPointer(d, DefaultRootWindow(d), &foo, &win,
        &bar, &bar, &bar, &bar, &bar);
    } while(win <= 0);


#ifdef VROOT
    {
    int n;
    Window *wins;
    XWindowAttributes xwa;

    (void) fputs("=xwa=", stdout);

    /* do{  */
        XQueryTree(d, win, &foo, &foo, &wins, &n);
    /* } while(wins <= 0); */
    bar=0;
    while(--n >= 0) {
        XGetWindowAttributes(d, wins[n], &xwa);
        if( (xwa.width * xwa.height) > bar) {
        win = wins[n];
        bar = xwa.width * xwa.height;
        }
        n--;
    }
    XFree(wins);
    }
#endif
    return(win);
}

http://tronche.com/gui/x/xlib/窗口信息/XQueryTree.html

我找到了来源:

http://examples.oreilly.com/networksa/tools/xsnoop.c

祝你好运

这篇关于如何知道哪个窗口具有焦点以及如何更改它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆