Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
Fix mapper to port for Override Resolutions #74
Browse files Browse the repository at this point in the history
  • Loading branch information
srevinsaju committed Mar 26, 2020
1 parent cbd36e3 commit 2583d1f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 48 deletions.
3 changes: 2 additions & 1 deletion guiscrcpy/lib/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def get_dimensions(path):
return dimValues
else:
logging.error(
"AndroidDeviceError: adb shell wm size did not return 'Physical Size' or 'Override Size'")
"AndroidDeviceError: adb shell wm size did not return 'Physical Size' or 'Override Size'"
)
return False

@staticmethod
Expand Down
59 changes: 12 additions & 47 deletions guiscrcpy/lib/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""


from guiscrcpy.lib.config import InterfaceConfig
from guiscrcpy.lib.check import adb
import argparse
from subprocess import PIPE, Popen
from pynput import keyboard
Expand All @@ -37,16 +38,11 @@
fixedpos = [0, 0]
finalpos = [0, 0]

cfgmgr = InterfaceConfig()
config = cfgmgr.get_config()
adb.path = config['adb']

jsong = 'guiscrcpy.mapper.json'
if platform.system() == "Windows":
if os.path.isfile("./scrcpy.exe"):
increment = ".\\"
# print(bcolors.BOLD + "LOG: Found scrcpy.exe in current directory.")
else:
increment = ""
else:
increment = ""

print("+++++++++++++++++++++++++++++++++++++++")
print("guiscrcpy ~ mapper by srevinsaju")
Expand All @@ -55,19 +51,10 @@
print('With USB debugging turned on.')
print("+++++++++++++++++++++++++++++++++++++++")
print("Waiting for device")
po(increment + "adb wait-for-any-device", shell=True)
adb.command(adb.path, 'wait-for-any-device')
print("Device : OK!")


# Declare key_a. path position
if (platform.system() == 'Windows'):
cfgpath = os.path.expanduser("~/AppData/Local/guiscrcpy/")
else:
if (os.getenv('XDG_CONFIG_HOME') is None):
cfgpath = os.path.expanduser("~/.config/guiscrcpy/")
else:
cfgpath = os.getenv('XDG_CONFIG_HOME').split(":")[0] + "/guiscrcpy/"

cfgpath = cfgmgr.cfgpath

parser = argparse.ArgumentParser()
parser.add_argument('-t', '--delay', default=10,
Expand All @@ -76,20 +63,7 @@
help="Remove prefernces")
args = parser.parse_args()

adb_dim = po(
"adb shell wm size", shell=True, stdout=PIPE, stderr=PIPE
)

out = adb_dim.stdout.read()
out_decoded = out.decode("utf-8")
out_decoded = out_decoded[:-1]
dimVal = out_decoded.split(": ")
try:
dimensions_ = dimVal[1]
dimValues = dimensions_.split("x")
print(dimValues, " DIMENSIONS ")
except:
print("Error Device not connected")
dimensions = adb.get_dimensions(adb.path)


class MapperUI(QtWidgets.QWidget):
Expand Down Expand Up @@ -181,8 +155,8 @@ def keyreg(self):
#print("REL POS :: ", fixedpos)
relx = fixedpos[0]/self.label.width()
rely = fixedpos[1]/self.label.height()
fixx = relx * int(dimValues[0])
fixy = rely * int(dimValues[1])
fixx = relx * int(dimensions[0])
fixy = rely * int(dimensions[1])
print("FINALIZED POS :: ", fixx, fixy)

finalpos[0] = fixx
Expand Down Expand Up @@ -255,7 +229,6 @@ def on_press0(key):

try:
if key.char in key_a.keys():

print(key.char)
print("running cmd")
finalpos0 = key_a[key.char]
Expand All @@ -278,17 +251,11 @@ def on_press0(key):

def sth():
import sys

app = QtWidgets.QApplication(sys.argv)
window = MapperUI()

sys.exit(app.exec_())


def sth_w0():
pass


def file_check():
jsong = 'guiscrcpy.mapper.json'

Expand Down Expand Up @@ -373,15 +340,13 @@ def file_checkm():
)

if not fileExist:

# Init json file for first time use
key_a = {"key": [], "pos": []}
with open(cfgpath + jsong, 'w') as f:
with open(os.path.join(cfgpath, jsong), 'w') as f:
json.dump(key_a, f)
sth_w0()

elif fileExist:
with open(cfgpath + jsong, 'r') as f:
with open(os.path.join(cfgpath, jsong), 'r') as f:
key_a = json.load(f)
listen_keypress(key_a)

Expand Down

0 comments on commit 2583d1f

Please sign in to comment.