#!/usr/bin/env lua local tA = {...} local direction = tA[1] local disp = tA[2] or "LVDS-0" local orientations = {"normal", "right", "inverted", "left"} local ctms = {["normal"]="1 0 0 0 1 0 0 0 1", ["inverted"]="-1 0 1 0 -1 1 0 0 1", ["left"]="0 -1 1 1 0 0 0 0 1", ["right"]="0 1 0 -1 0 1 0 0 1"} --[[ xrandr -q --verbose LVDS-0 connected 800x1280+0+0 (0x43) left (normal left inverted right x axis y axis) 0mm x 0mm NEW_ROT="normal" CTM="1 0 0 0 1 0 0 0 1" NEW_ROT="inverted" CTM="-1 0 1 0 -1 1 0 0 1" NEW_ROT="left" CTM="0 -1 1 1 0 0 0 0 1" NEW_ROT="right" CTM="0 1 0 -1 0 1 0 0 1" ]] local function nextRight(o) local current = 1 for k,v in pairs(orientations) do if o == v then current = k end end local ret = current + 1 if ret > #orientations then ret = 1 end return orientations[ret] end local function nextLeft(o) local current = 1 for k,v in pairs(orientations) do if o == v then current = k end end local ret = current - 1 if ret < 1 then ret = #orientations end return orientations[ret] end local f = io.popen("xrandr -q --verbose","r") c=f:read("*a") f:close() local line = (c:match("\n("..disp:gsub("%p","%%%1") .. ".-)\n")) print(line) local orientation = line:match(".-(left) %(") or line:match(".-(right) %(") or line:match(".-(normal) %(") or line:match(".-(inverted) %(") local f = io.popen("xinput --list","r") local xin=f:read("*a"):lower() f:close() --⎜ ↳ Elan Touchscreen id=6 [slave pointer (2)] local touchscreen = (xin:match("touch.*screen%s-id=(%d+)[^\n]-pointer")) print(orientation) print(nextLeft(orientation)) print(nextRight(orientation)) local newRot = nextRight(orientation) if direction == "left" then newRot = nextLeft(orientation) end print(string.format("xrandr --output %s --rotate %s",disp,newRot)) os.execute(string.format("xrandr --output %s --rotate %s",disp,newRot)) print(string.format("xinput set-prop %s 'Coordinate Transformation Matrix' %s",touchscreen,ctms[newRot])) os.execute(string.format("xinput set-prop %s 'Coordinate Transformation Matrix' %s",touchscreen,ctms[newRot]))