Disable actions, move, resize, minimize, etc using python-xlib

不羁岁月 提交于 2019-12-06 16:31:33

_NET_WM_ALLOWED_ACTIONS don't seem to be about what you want at all:

The Window Manager MUST keep this property updated to reflect the actions which are currently "active" or "sensitive" for a window [...] Window Managers SHOULD ignore the value of _NET_WM_ALLOWED_ACTIONS when they initially manage a window. This value may be left over from a previous Window Manager with different policies.

Among freedesktop extensions, _NET_WM_WINDOW_TYPE comes closest to what you want: specify certain window type to recommend certain behavior. No chance, though, to get an exact thing you want (like, unmovable window with decorations), and no guarantee that WM would obey this hint at all.

You might want to use OverrideRedirect attribute: when it's set before a window is mapped, WM does not intervene into window mapping process. It means no decorations, no reparenting and no user-originating actions with that window: you promise to manage it by yourself. It will be unmovable (unless you provide a facility of dragging it around). It will also (perhaps unfortunately) be undecorated.

It's an old question, but I had a similar problem, so, here's what I ended up using: the Motif-compatible, unofficial, yet supported by most window managers _MOTIF_WM_HINTS. The definitions are from the old Motif code (should be in Xm/MwmUtil.h), but everybody is cloning them, so:

struct MwmHints {
    unsigned long flags;
    unsigned long functions;
    unsigned long decorations;
    long input_mode;
    unsigned long status;
};
enum {
    MWM_HINTS_FUNCTIONS = (1L << 0),
    MWM_HINTS_DECORATIONS =  (1L << 1),

    MWM_FUNC_ALL = (1L << 0),
    MWM_FUNC_RESIZE = (1L << 1),
    MWM_FUNC_MOVE = (1L << 2),
    MWM_FUNC_MINIMIZE = (1L << 3),
    MWM_FUNC_MAXIMIZE = (1L << 4),
    MWM_FUNC_CLOSE = (1L << 5)
};

And the code would be something like this:

struct MwmHints hints;
Atom wm = XInternAtom(display, "_MOTIF_WM_HINTS", False);
hints.functions = MWM_FUNC_RESIZE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE | MWM_FUNC_CLOSE;
hints.flags = MWM_HINTS_FUNCTIONS;
XChangeProperty(display, window, wm, XA_ATOM, 32, PropModeReplace, (unsigned char*)&hints, 5);

Since we left out MWM_FUNC_MOVE, the windows should be unmovable.

In my (limited) testing, these mostly work, except MWM_FUNC_RESIZE, which mostly doesn't.

Porting these to Python shouldn't be hard, but I didn't need this in Python and I prefer to share working code.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!