Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Calculate the modifiers
mods = Qt.NoModifier
qtmods = Qt.NoModifier
modifiers = 0
if (ks & Qt.ShiftModifier == Qt.ShiftModifier):
mods |= ModsTbl.index(Qt.ShiftModifier)
qtmods |= Qt.ShiftModifier.real
modifiers |= getattr(xproto.KeyButMask, "Shift", 0)
if (ks & Qt.AltModifier == Qt.AltModifier):
mods |= ModsTbl.index(Qt.AltModifier)
qtmods |= Qt.AltModifier.real
modifiers |= getattr(xproto.KeyButMask, "Mod1", 0)
if (ks & Qt.ControlModifier == Qt.ControlModifier):
mods |= ModsTbl.index(Qt.ControlModifier)
qtmods |= Qt.ControlModifier.real
modifiers |= getattr(xproto.KeyButMask, "Control", 0)
# Calculate the keys
qtkeys = ks ^ qtmods
key = QKeySequence(Qt.Key(qtkeys)).toString().lower()
keycode = lookup_string(conn, key)
return modifiers, keycode
# Fallback logic
modifiers = 0
keycode = None
key_string = "Shift+Control+A"
for part in key_string.split('+'):
if hasattr(xproto.KeyButMask, part):
modifiers |= getattr(xproto.KeyButMask, part)
else:
def __init__(self, conn, persist=True):
self.conn = conn
self.screen = conn.get_setup().roots[0]
self.root = self.screen.root
self.width = self.screen.width_in_pixels
self.height = self.screen.height_in_pixels
self.depth = self.screen.root_depth
if persist:
self.conn.core.SetCloseDownMode(xcffib.xproto.CloseDown.RetainPermanent)
def handle_ConfigureRequest(self, e): # noqa: N802
cw = xcffib.xproto.ConfigWindow
if self.conf_x is None and e.value_mask & cw.X:
self.x = e.x
if self.conf_y is None and e.value_mask & cw.Y:
self.y = e.y
if self.conf_width is None and e.value_mask & cw.Width:
self.width = e.width
if self.conf_height is None and e.value_mask & cw.Height:
self.height = e.height
self.place(
self.screen.x + self.x,
self.screen.y + self.y,
self.width,
self.height,
self.borderwidth,
self.bordercolor
def unmap_window(self, window_id) -> None:
c = self.windows_map.get(window_id)
if c and getattr(c, "group", None):
try:
c.window.unmap()
c.state = window.WithdrawnState
except xcffib.xproto.WindowError:
# This means that the window has probably been destroyed,
# but we haven't yet seen the DestroyNotify (it is likely
# next in the queue). So, we just let these errors pass
# since the window is dead.
pass
self.unmanage(window_id)
def get_modifiers(state):
"""
Takes a ``state`` (typically found in key press or button press events)
and returns a string list representation of the modifiers that were pressed
when generating the event.
:param state: Typically from ``some_event.state``.
:return: List of modifier string representations.
:rtype: [str]
"""
ret = []
if state & xproto.ModMask.Shift:
ret.append('Shift')
if state & xproto.ModMask.Lock:
ret.append('Lock')
if state & xproto.ModMask.Control:
ret.append('Control')
if state & xproto.ModMask._1:
ret.append('Mod1')
if state & xproto.ModMask._2:
ret.append('Mod2')
if state & xproto.ModMask._3:
ret.append('Mod3')
if state & xproto.ModMask._4:
ret.append('Mod4')
if state & xproto.ModMask._5:
ret.append('Mod5')
if state & xproto.KeyButMask.Button1:
ret.append('Button1')
if state & xproto.KeyButMask.Button2:
def update_hints(self):
"""Update the local copy of the window's WM_HINTS
See http://tronche.com/gui/x/icccm/sec-4.html#WM_HINTS
"""
try:
h = self.window.get_wm_hints()
normh = self.window.get_wm_normal_hints()
except (xcffib.xproto.WindowError, xcffib.xproto.AccessError):
return
# FIXME
# h values
# {
# 'icon_pixmap': 4194337,
# 'icon_window': 0,
# 'icon_mask': 4194340,
# 'icon_y': 0,
# 'input': 1,
# 'icon_x': 0,
# 'window_group': 4194305
# 'initial_state': 1,
# 'flags': set(['StateHint',
# 'IconMaskHint',
# 'WindowGroupHint',