Skip to content

Commit

Permalink
Merge pull request #712 from benoit-pierre/cherry_picks_for_3.1.1
Browse files Browse the repository at this point in the history
Cherry picks for 3.1.1
  • Loading branch information
morinted authored Mar 6, 2017
2 parents cbbf9c5 + 338ca0b commit 73fdbb8
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 36 deletions.
8 changes: 5 additions & 3 deletions plover/gui/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@


if sys.platform.startswith('win32'):
import win32gui
GetForegroundWindow = win32gui.GetForegroundWindow
SetForegroundWindow = win32gui.SetForegroundWindow

from ctypes import windll

GetForegroundWindow = windll.user32.GetForegroundWindow
SetForegroundWindow = windll.user32.SetForegroundWindow

def SetTopApp(w):
# Nothing else is necessary for windows.
Expand Down
19 changes: 10 additions & 9 deletions plover/oslayer/osxkeyboardcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
'dead_tilde': '~',
}


def down(seq):
return [(x, True) for x in seq]

Expand All @@ -127,16 +128,15 @@ def down_up(seq):
MODIFIER_KEYS_TO_MASKS = {
58: kCGEventFlagMaskAlternate,
61: kCGEventFlagMaskAlternate,
59: kCGEventFlagMaskControl,
62: kCGEventFlagMaskControl,
# As of Sierra we *require* secondary fn to get control to work properly.
59: kCGEventFlagMaskControl | kCGEventFlagMaskSecondaryFn,
62: kCGEventFlagMaskControl | kCGEventFlagMaskSecondaryFn,
56: kCGEventFlagMaskShift,
60: kCGEventFlagMaskShift,
55: kCGEventFlagMaskCommand,
63: kCGEventFlagMaskSecondaryFn,
}

OUTPUT_SOURCE = CGEventSourceCreate(kCGEventSourceStateHIDSystemState)

# For the purposes of this class, we're only watching these keys.
# We could calculate the keys, but our default layout would be misleading:
#
Expand Down Expand Up @@ -313,9 +313,9 @@ def __init__(self):
def send_backspaces(number_of_backspaces):
for _ in range(number_of_backspaces):
backspace_down = CGEventCreateKeyboardEvent(
OUTPUT_SOURCE, BACK_SPACE, True)
None, BACK_SPACE, True)
backspace_up = CGEventCreateKeyboardEvent(
OUTPUT_SOURCE, BACK_SPACE, False)
None, BACK_SPACE, False)
CGEventPost(kCGSessionEventTap, backspace_down)
CGEventPost(kCGSessionEventTap, backspace_up)

Expand Down Expand Up @@ -368,6 +368,7 @@ def apply_raw():
apply_raw.sequence.extend(down_up([keycode]))
else:
# Flush on type change.
last_modifier = None
apply_raw()
key_plan.append((self.STRING_PRESS, c))
# Flush after string is complete.
Expand All @@ -382,10 +383,10 @@ def apply_raw():

@staticmethod
def _send_string_press(c):
event = CGEventCreateKeyboardEvent(OUTPUT_SOURCE, 0, True)
event = CGEventCreateKeyboardEvent(None, 0, True)
KeyboardEmulation._set_event_string(event, c)
CGEventPost(kCGSessionEventTap, event)
event = CGEventCreateKeyboardEvent(OUTPUT_SOURCE, 0, False)
event = CGEventCreateKeyboardEvent(None, 0, False)
KeyboardEmulation._set_event_string(event, c)
CGEventPost(kCGSessionEventTap, event)

Expand Down Expand Up @@ -485,7 +486,7 @@ def _send_sequence(sequence):
mods_flags &= ~MODIFIER_KEYS_TO_MASKS[keycode]

event = CGEventCreateKeyboardEvent(
OUTPUT_SOURCE, keycode, key_down)
None, keycode, key_down)

if key_down and keycode not in MODIFIER_KEYS_TO_MASKS:
event_flags = CGEventGetFlags(event)
Expand Down
16 changes: 9 additions & 7 deletions plover/oslayer/processlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@


class LockNotAcquiredException(Exception):

pass


if sys.platform.startswith('win32'):
import win32event
import win32api
import winerror

from ctypes import windll


class PloverLock(object):

# A GUID from http://createguid.com/
guid = 'plover_{F8C06652-2C51-410B-8D15-C94DF96FC1F9}'

def __init__(self):
pass

def acquire(self):
self.mutex = win32event.CreateMutex(None, False, self.guid)
if win32api.GetLastError() == winerror.ERROR_ALREADY_EXISTS:
self.mutex = windll.kernel32.CreateMutexA(None, False, self.guid)
if windll.kernel32.GetLastError() == 0xB7: # ERROR_ALREADY_EXISTS
raise LockNotAcquiredException()

def release(self):
if hasattr(self, 'mutex'):
win32api.CloseHandle(self.mutex)
windll.kernel32.CloseHandle(self.mutex)
del self.mutex

def __del__(self):
Expand All @@ -45,11 +45,13 @@ def __exit__(self, type, value, traceback):
self.release()

else:

import fcntl
import os


class PloverLock(object):

def __init__(self):
# Check the environment for items to make the lockfile unique
# fallback if not found
Expand Down
4 changes: 1 addition & 3 deletions plover/oslayer/winkeyboardcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# Python 2/3 compatibility.
from six.moves import winreg

import win32api

from plover.key_combo import parse_key_combo
from plover.oslayer.winkeyboardlayout import KeyboardLayout
from plover import log
Expand Down Expand Up @@ -249,7 +247,7 @@ class KBDLLHOOKSTRUCT(ctypes.Structure):
# Ignore KeyboardInterrupt when attached to a console...
signal.signal(signal.SIGINT, signal.SIG_IGN)

self._tid = win32api.GetCurrentThreadId()
self._tid = windll.kernel32.GetCurrentThreadId()
self._queue.put(self._tid)

down_keys = set()
Expand Down
5 changes: 2 additions & 3 deletions plover/oslayer/winkeyboardlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
from ctypes import windll, wintypes
from collections import defaultdict, namedtuple

import win32gui

from plover.key_combo import CHAR_TO_KEYNAME, add_modifiers_aliases
from plover.misc import popcount_8


GetKeyboardLayout = windll.user32.GetKeyboardLayout
GetWindowThreadProcessId = windll.user32.GetWindowThreadProcessId
MapVirtualKeyEx = windll.user32.MapVirtualKeyExW
Expand Down Expand Up @@ -444,7 +443,7 @@ def sort_vk_ss_list(vk_ss_list):

@staticmethod
def current_layout_id():
pid = GetWindowThreadProcessId(win32gui.GetForegroundWindow(), 0)
pid = GetWindowThreadProcessId(windll.user32.GetForegroundWindow(), 0)
return GetKeyboardLayout(pid)

# }}}
Expand Down
13 changes: 10 additions & 3 deletions plover/oslayer/xkeyboardcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,23 @@ def _update_devices(self):
# Find all keyboard devices.
keyboard_devices = []
for devinfo in self.display.xinput_query_device(xinput.AllDevices).devices:
# Only keep slave keyboard devices.
if devinfo.use != xinput.SlaveKeyboard:
# Only keep slave devices.
# Note: we look at pointer devices too, as some keyboards (like the
# VicTop mechanical gaming keyboard) register 2 devices, including
# a pointer device with a key class (to fully support NKRO).
if devinfo.use not in (xinput.SlaveKeyboard, xinput.SlavePointer):
continue
# Ignore XTest keyboard device.
if 'Virtual core XTEST keyboard' == devinfo.name:
continue
# Ignore disabled devices.
if not devinfo.enabled:
continue
keyboard_devices.append(devinfo.deviceid)
# Check for the presence of a key class.
for c in devinfo.classes:
if c.type == xinput.KeyClass:
keyboard_devices.append(devinfo.deviceid)
break
if XINPUT_DEVICE_ID == xinput.AllDevices:
self.devices = keyboard_devices
else:
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,14 @@ def run(self):

extras_require = {
':"win32" in sys_platform': [
'pywin32>=219',
],
':"linux" in sys_platform': [
'python-xlib>=0.16',
],
':"darwin" in sys_platform': [
'pyobjc-core==3.1.1+plover2',
'pyobjc-framework-Cocoa==3.1.1+plover2',
'pyobjc-framework-Quartz>=3.0.3',
'pyobjc-framework-Quartz==3.1.1',
'appnope>=0.1.0',
],
}
Expand Down
1 change: 0 additions & 1 deletion windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ It is best to develop using 32 bit tools for Plover.

- [Cython](http://cython.org/)
- [Microsoft Visual C++ Compiler for Python 2.7](https://www.microsoft.com/en-us/download/details.aspx?id=44266)
- [Python for Windows Extensions](http://sourceforge.net/projects/pywin32/)
- [wxPython](http://www.wxpython.org/)

### Other dependencies
Expand Down
6 changes: 1 addition & 5 deletions windows/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,20 +248,16 @@ def add_to_path(self, directory):
class Helper(object):

if PY3:
# Note: update pip so hidapi install from wheel works.
DEPENDENCIES = (
# Note: update pip so hidapi install from wheel works.
('pip', 'pip:pip',
None, None, (), None),
('pywin32', 'https://downloads.sourceforge.net/project/pywin32/pywin32/Build 220/pywin32-220.win32-py3.5.exe',
'5c9bd9643982dbfea4aba500503227dd997931df', 'easy_install', (), None),
)
else:
DEPENDENCIES = (
# Note: we force the installation directory, otherwise the installer gets confused when run under AppVeyor, and installs in the wrong directory...
('wxPython', 'https://downloads.sourceforge.net/wxpython/wxPython3.0-win32-3.0.2.0-py27.exe',
'864d44e418a0859cabff71614a495bea57738c5d', None, ('/SP-', '/VERYSILENT', r'/DIR=C:\Python27\Lib\site-packages'), None),
('pywin32', 'https://downloads.sourceforge.net/project/pywin32/pywin32/Build 219/pywin32-219.win32-py2.7.exe',
'8bc39008383c646bed01942584117113ddaefe6b', 'easy_install', (), None),
('Cython', 'https://pypi.python.org/packages/2.7/C/Cython/Cython-0.23.4-cp27-none-win32.whl',
'd7c1978fe2037674b151622158881c700ac2f06a', None, (), None),
('VC for Python', 'https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi',
Expand Down

0 comments on commit 73fdbb8

Please sign in to comment.