LoginSignup
2
0

More than 5 years have passed since last update.

[Xlib]ウィンドウの装飾を取り除く

Posted at

私が最初に勉強した本では、ウィンドウの装飾を取り除くのに
ウィンドウマネージャの設定リクエストをリダイレクトするものでした。

main.c
XSetWindowAttributes att;
att.override_redirect = True;
XChangeWindowAttributes(dpy, win, CWOverrideRedirect, &att);

しかし、これではウィンドウの前後関係を変えるのが難しくなってしまいますし、
そのままだとEvent関連もスルーしていまいます。
スクリーンセーバや、"oneko"のようなアプリケーションであれば問題ないですが、
他のウィンドウと同様に扱える、装飾なしのウィンドウも欲しいところです。

少し調べてみたら、別の方法を用いて装飾を外せることがわかりました。
Motif のウィンドウマネージャあたりをいじるようです。
(Motif はGUI規格のひとつですが、以下の参考資料には「Motifを使っていなくても大丈夫」と、書いてあります)

(参考資料)
http://tonyobryan.com/index.php?article=9

main.c
/*************************************
サンプルプログラムは、
http://homepage3.nifty.com/rio_i/lab/xlib/001window.htm
のところを参考に書かせていただきました。
**************************************/
#include <X11/Xlib.h>

typedef struct{
    unsigned long flags;
    unsigned long functions;
    unsigned long decorations;
    long inputMode;
    unsigned long status;
} Hints;

int main(){
    Display *dpy;
    Window root;
    Window win;
    int screen;
    unsigned long black, white;
    XEvent e;

    dpy = XOpenDisplay("");

    root = DefaultRootWindow(dpy);
    screen = DefaultScreen(dpy);

    white = WhitePixel(dpy, screen);
    black = BlackPixel(dpy, screen);

    win = XCreateSimpleWindow(dpy, root, 32, 32, 64, 64, 2, black, white);

    XSelectInput(dpy, win, KeyPressMask);

    {
        Hints hints;
        Atom property;
        hints.flags = 2;
        hints.decorations = 0;
        property = XInternAtom(dpy, "_MOTIF_WM_HINTS", True);
        XChangeProperty(dpy, win, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5);
    }
    /*
    {
        XSetWindowAttributes att;
        att.override_redirect = True;
        XChangeWindowAttributes(dpy, win, CWOverrideRedirect, &att);
    }
    */    

    XMapWindow(dpy, win);
    XMoveWindow(dpy, win, 32, 32);  /* 一回マップするまで座標はWMによって決定するみたいです */

    XFlush(dpy);            /* 念のためのFlush */

    while(1){
        XNextEvent(dpy, &e);

        switch(e.type){
            case KeyPress:
                XDestroyWindow(dpy, win);
                XCloseDisplay(dpy);
                return 0;
        }
    }
}

いかがでしょうか。
もしかしたらオープンソースのGUI内部を覗けば書いてあるかもしれませんね。

お役に立つかどうか分かりませんが、
以上 Tips でした。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0