diff --git a/boxes/phone/out-of-tree/Makefile b/boxes/phone/out-of-tree/Makefile index 66f2adc..f7ba990 100644 --- a/boxes/phone/out-of-tree/Makefile +++ b/boxes/phone/out-of-tree/Makefile @@ -1,4 +1,4 @@ -termux: termux-pkgs termux-dots utils-sh rebuild-sh st pip-pkgs git-annex.linux sssg +termux: termux-pkgs termux-dots utils-sh rebuild-sh st pip-pkgs git-annex.linux sssg statusbar-polyfill list: options # alias options: @@ -87,3 +87,6 @@ git-annex.linux: sssg: -cp ~/git/sssg/sssg.sh ~/.local/bin/sssg -chmod +x ~/.local/bin/sssg + +statusbar-polyfill: + cp ~/dot_testing/builds/statusbar/termux-statusbar-polyfill ~/.local/bin diff --git a/builds/statusbar/statusbar/statusbar.py b/builds/statusbar/statusbar/statusbar.py index bbb7c69..cd2e61c 100644 --- a/builds/statusbar/statusbar/statusbar.py +++ b/builds/statusbar/statusbar/statusbar.py @@ -1,8 +1,8 @@ from multiprocessing import Process, Queue from collections import defaultdict -from sys import argv -from sys import stdout +from sys import argv, stdout from math import floor +from socket import gethostname import datetime import signal import subprocess @@ -56,7 +56,10 @@ def filemodfactory(filename: str, modname: str): def new_mail(queue, _): while True: - dir_output = os.listdir("/home/usr/Mail/main/INBOX/new") + try: + dir_output = os.listdir("/home/usr/Mail/main/INBOX/new") + except FileNotFoundError: # we're on the phone, no mail here + return dir_output = len(dir_output) queue.put({ "module": "newmail", @@ -69,7 +72,10 @@ def bspwm(queue, monitor): socket.AF_UNIX, socket.SOCK_STREAM ) - client.connect("/tmp/bspwm_1_0-socket") + try: + client.connect("/tmp/bspwm_1_0-socket") + except: # perhaps we're on the phone? + client.connect("/data/data/com.termux/files/usr/tmp/bspwm_1_0-socket") message = "subscribe\0".encode() client.send(message) @@ -143,37 +149,57 @@ def render(modules) -> str: print(output, end='') stdout.flush() +def start_statusbars(): + # is there an actually good xrandr library? + xrandr = subprocess.Popen(['xrandr'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + output = list(xrandr.stdout) + output = [i.decode("utf-8") for i in output if " connected" in i.decode("utf-8")] + serialized = [] + for i in output: + splitted = i.split(' ') + print(splitted) + displayname = splitted[0] + geometry = splitted[2] + if geometry == "primary": + geometry = splitted[3] + + try: + geometry_splitted = [int(i) for i in geometry.replace('x', '+').split('+')] + except ValueError: + continue + geometry_splitted[1] = 20 + print(displayname, geometry_splitted) + os.system("st -c statusbar -p -g {}x{}+{}+{} -e statusbar {} & disown".format( + *map(str, geometry_splitted), + displayname + )) + def main(): try: os.mkdir("/home/usr/.cache/statusbar") except FileExistsError: pass + except FileNotFoundError: + # we're on the phone + try: + os.mkdir("/data/data/com.termux/files/home/.cache/statusbar") + except FileExistsError: + pass if argv[1] == "start_statusbars": - # get the monitors - xrandr = subprocess.Popen(['xrandr'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - output = list(xrandr.stdout) - output = [i.decode("utf-8") for i in output if " connected" in i.decode("utf-8")] - serialized = [] - for i in output: - splitted = i.split(' ') - print(splitted) - displayname = splitted[0] - geometry = splitted[2] - if geometry == "primary": - geometry = splitted[3] + hostname = gethostname() - try: - geometry_splitted = [int(i) for i in geometry.replace('x', '+').split('+')] - except ValueError: - continue - geometry_splitted[1] = 20 - print(displayname, geometry_splitted) - os.system("st -c statusbar -p -g {}x{}+{}+{} -e statusbar {} & disown".format( - *map(str, geometry_splitted), - displayname + if not hostname == "localhost": # if we're not the phone + start_statusbars() + else: + # we are the phone + os.system("/data/data/com.termux/files/usr/bin/bash -c 'st -c statusbar -p -g {}x{}+{}+{} -e termux-statusbar-polyfill {} & disown'".format( + 1920, 50, 0, 980, + "VNC-0" )) + return + queue = Queue() modules = [bspwm, clock, battery, batterystatus, sxhkdmode, new_mail] [Process(target=module, args=(queue, argv[1])).start() for module in modules] diff --git a/builds/statusbar/termux-statusbar-polyfill b/builds/statusbar/termux-statusbar-polyfill new file mode 100755 index 0000000..ae8f3f1 --- /dev/null +++ b/builds/statusbar/termux-statusbar-polyfill @@ -0,0 +1,3 @@ +#!/bin/sh + +python3 ~/dot_testing/builds/statusbar/statusbar/statusbar.py $@ diff --git a/builds/utils/disp b/builds/utils/disp index 894ba8a..7b3a8a3 100755 --- a/builds/utils/disp +++ b/builds/utils/disp @@ -183,6 +183,7 @@ case "$(hostname)" in bspc config top_padding 0 bspc config bottom_padding 100 mkdir -p ~/.cache/statusbar + termux-statusbar-polyfill start_statusbars ;; esac