|
| 1 | +# This file is part of Xpra. |
| 2 | +# Copyright (C) 2008, 2009 Nathaniel Smith <njs@pobox.com> |
| 3 | +# Copyright (C) 2012-2023 Antoine Martin <antoine@xpra.org> |
| 4 | +# Xpra is released under the terms of the GNU GPL v2, or, at your option, any |
| 5 | +# later version. See the file COPYING for details. |
| 6 | + |
| 7 | +from xpra.x11.bindings.window_bindings import constants, X11WindowBindings #@UnresolvedImport |
| 8 | +from xpra.log import Logger |
| 9 | + |
| 10 | +log = Logger("x11", "focus") |
| 11 | + |
| 12 | +X11Window = X11WindowBindings() |
| 13 | + |
| 14 | +CurrentTime = constants["CurrentTime"] |
| 15 | +SubstructureNotifyMask = constants["SubstructureNotifyMask"] |
| 16 | +SubstructureRedirectMask = constants["SubstructureRedirectMask"] |
| 17 | + |
| 18 | + |
| 19 | +def send_wm_take_focus(xid:int, timestamp : int=CurrentTime): |
| 20 | + log("sending WM_TAKE_FOCUS: %#x, X11 timestamp=%r", xid, int(timestamp or 0)) |
| 21 | + if timestamp<0: |
| 22 | + timestamp = 0 |
| 23 | + elif timestamp>0xFFFFFFFF: |
| 24 | + raise OverflowError(f"invalid time: {timestamp:x}") |
| 25 | + elif timestamp>0x7FFFFFFF: |
| 26 | + timestamp = int(0x100000000-timestamp) |
| 27 | + if timestamp>=0x80000000: |
| 28 | + timestamp -= 0x80000000 |
| 29 | + X11Window.sendClientMessage(xid, xid, False, 0, |
| 30 | + "WM_PROTOCOLS", |
| 31 | + "WM_TAKE_FOCUS", timestamp) |
| 32 | + |
| 33 | +def send_wm_delete_window(xid:int, timestamp : int=CurrentTime): |
| 34 | + log("sending WM_DELETE_WINDOW to %#x", xid) |
| 35 | + X11Window.sendClientMessage(xid, xid, False, 0, |
| 36 | + "WM_PROTOCOLS", |
| 37 | + "WM_DELETE_WINDOW", |
| 38 | + timestamp) |
| 39 | + |
| 40 | +def send_wm_workspace(root_xid:int, xid:int, workspace:int=0, timestamp : int=CurrentTime): |
| 41 | + event_mask = SubstructureNotifyMask | SubstructureRedirectMask |
| 42 | + X11Window.sendClientMessage(root_xid, xid, False, event_mask, |
| 43 | + "_NET_WM_DESKTOP", |
| 44 | + workspace, |
| 45 | + timestamp) |
| 46 | + |
| 47 | +def send_wm_request_frame_extents(root_xid:int, xid:int, timestamp : int=CurrentTime): |
| 48 | + event_mask = SubstructureNotifyMask | SubstructureRedirectMask |
| 49 | + X11Window.sendClientMessage(root_xid, xid, False, event_mask, |
| 50 | + "_NET_REQUEST_FRAME_EXTENTS", |
| 51 | + 0, |
| 52 | + timestamp) |
0 commit comments