トップレベルのウィンドウがいつ作成されるかを知る必要がある状況です。私は、Xlib/Xtレベルと、EWMH仕様をサポートしていないウィンドウマネージャで作業しています。私の考えは、ルートウィンドウのSubstructureNotifyイベントにフックすることです。しかし、物事はそれほど単純ではありません。Xlib/Xtの "新しいトップレベルウィンドウ"イベントを処理する
すべてのCreateNotifyイベントが[b]トップレベル[/ b]ウィンドウの作成に対応するわけではありません。だから、私がする必要があると思うのは、それがトップレベルのウィンドウであることを何らかの形で確認するイベントから取得したウィンドウをテストすることです。私は近づいてきましたが、いくつかの偽の窓はまだ私のネットを通してそれを行います。たとえば、GTKアプリケーションでドロップダウンボックスをクリックしてクリックすると、キャッチして無視する方法がわからない新しいウィンドウが作成されます。このようなウィンドウは、典型的なトップレベルのアプリケーションウィンドウとは区別がつかない。ここで
は、私がこれまで持っているものです。
// I am omiting (tons of) cleanup code and where I set the display and toplevel variables.
Display* display;
Widget toplevel;
bool has_name(Window window)
{
XTextProperty data = XTextProperty();
return (!XGetWMName (display, window, &data));
}
bool has_client_leader(Window window)
{
unsigned long nitems = 0;
unsigned char* data = 0;
Atom actual_type;
int actual_format;
unsigned long bytes;
// WM_CLIENT_LEADER is an interned Atom for the WM_CLIENT_LEADER property
int status = XGetWindowProperty (display, window, WM_CLIENT_LEADER, 0L, (~0L), False,
AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes, &data);
if (status != Success || acutal_type == None) return false;
Window* leader = reinterpret_cast<Window*> (data);
return (*leader != 0);
}
bool has_class(Window window)
{
XClassHint data = XClassHint();
return (!GetClassHint (display, window, &data));
}
void handle_event(Widget widget, XtPointer, XEvent* event, Boolean*)
{
if (event->type != CreateNotify) return;
Window w = event->xcreatewindow.window;
// confirm window has a name
if (!has_name (w)) return;
// confirm window is a client window
Window client = XmuClientWindow (display, w);
if (!client || client != w) return;
// confirm window has a client leader that is not 0x0
if (!has_client_leader (client)) return;
// confirm window has a class
if (!has_class (client)) return;
// The window has passed all our checks!
// Go on to do stuff with the window ...
}
int main(int argc, char* argv[])
{
// ...
// Setting up the event handler for SubstructureNotify on root window
Window root_window = XDefaultRootWindow (display);
Widget dummy = XtCreateWidget ("dummy", coreWidgetClass, toplevel, 0, 0);
XtRegisterDrawable (display, root_window, dummy);
XSelectInput (display, root_window, SubstructureNotifyMask);
XtAddRawEventHandler (dummy, SubstructureNotifyMask, False, handle_event, 0);
// ...
}
ロングショットを、誰でも、私は試みることができる任意のアイデアを持っているのですか?私はここで本当にできることは他にはないと思います。
あなたはどのウィンドウマネージャを使用していますか? EWMHを実装してみませんか?関連リンクとヒントについては – Zifre