From c27e72bcfac874372bc070d0d2cb4b0c149b2cdd Mon Sep 17 00:00:00 2001 From: Thomas Buckley-Houston Date: Sat, 23 Apr 2016 00:58:05 +0300 Subject: [PATCH] First draft This is just a scattering of notes and proofs of concepts. --- .gitignore | 2 ++ Dockerfile | 3 +++ do.bash | 41 +++++++++++++++++++++++++++++++++++++++++ forward_mouse.rb | 21 +++++++++++++++++++++ run.bash | 7 +++++++ 5 files changed, 74 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100755 do.bash create mode 100644 forward_mouse.rb create mode 100755 run.bash diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..073f461 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.log +*.out diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..03f1ca9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine +RUN apk add xvfb xdotool xfce4 ffmpeg chromium +RUN rm -rf /var/cache/apk/* diff --git a/do.bash b/do.bash new file mode 100755 index 0000000..81f89a2 --- /dev/null +++ b/do.bash @@ -0,0 +1,41 @@ +# +# This is AWESOME. +# +# Original code by: Chris F.A. Johnson +# +ESC="" ## A literal escape character +but_row=1 + +clear +mv=1000 ## mv=1000 for press and release reporting; mv=9 for press only + +_STTY=$(stty -g) ## Save current terminal setup +stty -echo -icanon ## Turn off line buffering +printf "${ESC}[?${mv}h " ## Turn on mouse reporting +printf "${ESC}[?25l" ## Turn off cursor + +while : +do + x=$(dd bs=1 count=6 2>/dev/null) ## Read six characters + + m1=${x#???} ## Remove the first 3 characters + m2=${x#????} ## Remove the first 4 characters + m3=${x#?????} ## Remove the first 5 characters + + ## Convert to characters to decimal values + eval "$(printf "mb=%d mx=%d my=%d" "'$m1" "'$m2" "'$m3")" + + ## Values > 127 are signed + [ $mx -lt 0 ] && MOUSEX=$(( 223 + $mx )) || MOUSEX=$(( $mx - 32 )) + [ $my -lt 0 ] && MOUSEY=$(( 223 + $my )) || MOUSEY=$(( $my - 32 )) + + ## Button pressed is in first 2 bits; use bitwise AND + BUTTON=$(( ($mb & 3) + 1 )) + echo $MOUSEX $MOUSEY $BUTTON > mouse.out + +done + +printf "${ESC}[?${mv}l" ## Turn off mouse reporting +stty "$_STTY" ## Restore terminal settings +printf "${ESC}[?12l${ESC}[?25h" ## Turn cursor back on +printf "\n${ESC}[0J\n" ## Clear from cursor to bottom of screen diff --git a/forward_mouse.rb b/forward_mouse.rb new file mode 100644 index 0000000..a8c3dd4 --- /dev/null +++ b/forward_mouse.rb @@ -0,0 +1,21 @@ +require 'curses' +include Curses + +# These 2 allow mouse input +noecho # Prevent input being echoed to the screen +stdscr.keypad(true) # Not sure what this does exactly, but mouse input doesn't work without it + +# Block whilst waiting for input +stdscr.timeout = -1 + +mousemask(ALL_MOUSE_EVENTS) + +loop do + case getch + when KEY_MOUSE + m = getmouse + File.open('/home/tombh/Workspace/lowbandwidth/mouse.out', 'w') do |file| + file.write("#{m.x}, #{m.y}, #{m.z}, #{m.bstate}") + end + end +end diff --git a/run.bash b/run.bash new file mode 100755 index 0000000..8078eba --- /dev/null +++ b/run.bash @@ -0,0 +1,7 @@ +#!/bin/bash +ffmpeg -f x11grab -s 3200x1600 -r 12 -i :0.0 -vcodec mpeg2video -f mpegts udp://127.0.0.1:1234 >> ffmpeg.log 2>&1 & +sleep 1 +# (/home/tombh/.rbenv/versions/2.3.0/bin/ruby ./forward_mouse.rb <&3 &) 3<&0 +(./do.bash <&3 &) 3<&0 +hiptext -width 95 -font /usr/share/fonts/TTF/DejaVuSansMono.ttf 'udp://127.0.0.1:1234' 2> hiptext.log +trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT