I'm making a program where I need to lock the position of a window on the screen, one would think the easy way to do this is using _NET_WM_ALLOWED_ACTIONS but apparently didn't work or I don't know how it work xD... I tried to send an event, something like this:
def getatom (atom):
return self.display.intern_atom(atom)
data = [getatom("_NET_WM_ACTION_ABOVE"),getatom("_NET_WM_ACTION_CLOSE"),
getatom("_NET_WM_ACTION_BELOW"),getatom("_NET_WM_ACTION_CHANGE_DESKTOP"),
getatom("_NET_WM_ACTION_SHADE")]
state = getatom("_NET_WM_ALLOWED_ACTIONS")
event = Xlib.protocol.event.ClientMessage(window = window, client_type = state, data = (32, data))
root.send_event(event, X.SubstructureRedirectMask)
self.display.sync()
That did nothing, if I use xprop the allowed actions are _NET_WM_ACTION_ABOVE, _NET_WM_ACTION_CLOSE, _NET_WM_ACTION_BELOW, _NET_WM_ACTION_CHANGE_DESKTOP and _NET_WM_ACTION_SHADE but I can still move the window, I really don't know how to do this/how it work, if someone can clarify me this and give me an example would be much apreciated.
_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.
来源:https://stackoverflow.com/questions/14442081/disable-actions-move-resize-minimize-etc-using-python-xlib