Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def handler(self, reply):
""" This function is called when a xlib event is fired """
data = reply.data
while len(data):
event, data = rq.EventField(None).parse_binary_value(
data, self.disp.display, None, None)
if event.type == X.KeyPress:
pass
elif event.type == X.KeyRelease:
keycode = event.detail
keysym = self.disp.keycode_to_keysym(keycode, 0)
if hex(keysym) == MediaKey.media_next.value:
ControllerApi.player.play_next()
elif hex(keysym) == MediaKey.media_previous.value:
ControllerApi.player.play_last()
elif hex(keysym) == MediaKey.media_stop.value:
ControllerApi.player.stop()
elif hex(keysym) == MediaKey.media_play_pause.value:
ControllerApi.player.play_or_pause()
return event
try:
key_event = NSEvent.eventWithCGEvent_(event)
except:
LOG.info("mac event cast error")
return event
if key_event.subtype() == 8:
key_code = (key_event.data1() & 0xFFFF0000) >> 16
key_state = (key_event.data1() & 0xFF00) >> 8
if key_code in (16, 19, 20):
# 16 for play-pause, 19 for next, 20 for previous
if key_state == NSKeyUp:
if key_code is 19:
ControllerApi.player.play_next()
elif key_code is 20:
ControllerApi.player.play_last()
elif key_code is 16:
ControllerApi.player.play_or_pause()
return None
return event
def Previous(self):
LOG.info('dbus: call play last')
ControllerApi.player.play_last()