{"id":101,"date":"2013-05-26T03:30:00","date_gmt":"2013-05-26T02:30:00","guid":{"rendered":"http:\/\/www.celesteh.com\/blog\/2013\/05\/26\/a-better-script-for-wacom-with-screen\/"},"modified":"2015-06-19T00:23:08","modified_gmt":"2015-06-18T23:23:08","slug":"a-better-script-for-wacom-with-screen","status":"publish","type":"post","link":"https:\/\/www.celesteh.com\/blog\/2013\/05\/26\/a-better-script-for-wacom-with-screen\/","title":{"rendered":"A better script for Wacom with screen geometry changes"},"content":{"rendered":"<h3>Why and how<\/h3>\n<p>This is a better script to set your stylus setting to match a changed resolution, like if you plugged in to a projector.  If you are mirroring screens, the geometry may change, so that instead of using your whole 16\/9 ratio screen, you&#8217;re only using a 4\/3 box in the middle. The problem you may run into is that your stylus does not adjust and so where you&#8217;re pointing the stylus may differ significantly from where the pointer appears on the screen. This script fixes that.<br \/>\nThere are some dependencies: xsetwacom xrandr, and wcalc. Make sure you have xsetwacom by typing:<\/p>\n<pre>which xsetwacom<\/pre>\n<p>If it doesn&#8217;t give you a path, you need to:<\/p>\n<pre>sudo apt-get install xsetwacom<\/pre>\n<p>Do the same for xrandr. Finally, you need wcalc, which is not installed by default. Type:<\/p>\n<pre>sudo apt-get install wcalc<\/pre>\n<p>The script is below. To save it, copy it to the clipboard starting from just below the &#8216;Script&#8217; subheader and ending just above the &#8216;Commentary&#8217; subheader. Then type the following in the terminal:<\/p>\n<pre>\ncd\nmkdir bin\ncd bin\ntouch stylus_script.sh\nchmod +x stylus_script.sh\ngedit stylus_script.sh\n<\/pre>\n<p>Don&#8217;t worry if you get an error saying bin already exists. Just carry on.<\/p>\n<p>Gedit should open with a blank file. Paste the script into that file. Then save and quit. You may not need to make any changes. (See commentary.)<br \/>\nYou&#8217;ll want to run this script when you plug into a projector (after you set the resolution you&#8217;re going to use) and then again when you unplug from it. Do this in the terminal by typing:<\/p>\n<pre>~\/bin\/stylus_script.sh<\/pre>\n<p>You can run these from any terminal window, at any time and it should work.  If you get errors or it just doesn&#8217;t do anything, see the commentary below.<\/p>\n<h3>Script<\/h3>\n<pre>\n#!\/bin\/bash\n\n\nfunction touch_ratio {\n #get pen geometry\n LINE=`xsetwacom get \"Wacom ISDv4 E6 Pen stylus\" area`\n echo ${LINE}\n TabTx=`echo ${LINE} | awk '{ print $1 }'`\n TabTy=`echo ${LINE} | awk '{ print $2 }'`\n TabBx=`echo ${LINE} | awk '{ print $3 }'`\n TabBy=`echo ${LINE} | awk '{ print $4 }'`\n\n TouchHeight=$((${TabBy} -${TabTy}))\n TouchWidth=$((${TabBx} -${TabTx}))\n\n TouchRatio=`wcalc -q ${TouchWidth}\/${TouchHeight}`\n\n}\n\n\n\n# get screen geometry\nLINE=`xrandr -q | grep Screen`\nWIDTH=`echo ${LINE} | awk '{ print $8 }'`\nHEIGHT=`echo ${LINE} | awk '{ print $10 }' | awk -F\",\" '{ print $1 }'`\nRATIO=`wcalc -q ${WIDTH}\/${HEIGHT}`\n\n\n\ntouch_ratio\n\n# is the touch ratio different from the screen ratio?\nchange=`wcalc -q abs(${TouchRatio}-${RATIO})&gt;0.01`\nwcalc -q abs(${TouchRatio}-${RATIO})\nif [[ ${change} != 0 ]] \n  then\n\n #they differ\n\n # first try resetting\n xsetwacom set \"Wacom ISDv4 E6 Pen stylus\" ResetArea\n xsetwacom set \"Wacom ISDv4 E6 Pen eraser\" ResetArea \n xsetwacom set \"Wacom ISDv4 E6 Finger touch\" ResetArea\n\n # how about now?\n touch_ratio\n \n if [[ `wcalc -q abs(${TouchRatio}-${RATIO})&gt;0.01` != 0 ]] #they differ\n   then\n\n  if [[ ${TouchRatio} &gt; ${RATIO} ]] # width has shrunk\n    then\n   # use existing height values\n   TYOFFSET=${TabTy};\n   BYOFFSET=${TabBy};\n\n   # calculate new width values\n   # width = ratio * height\n   \n   NewTabWidth=`wcalc -q -P0 ${RATIO}*${TouchHeight}`\n   TabDiff=$(( (${TouchWidth} - ${NewTabWidth}) \/ 2));\n\n   TXOFFSET=$((${TabTx} + ${TabDiff}));\n   BXOFFSET=$((${TabBx}- ${TabDiff}));\n\n    else # height has shrunk\n\n   # use existing width values\n   TXOFFSET=${TabTx};\n   BXOFFSET=${TabBx};\n\n   # calculate new height values\n   # height = width \/ ratio\n\n   NewTabHeight=`wcalc -q -P0 ${TouchWidth}\/${RATIO}`\n   TabDiff=`wcalc -q (${TouchHeight}-${NewTabHeight})\/2`\n   \n   TYOFFSET=`wcalc -q ${TabTy}+${TabDiff}`\n   BYOFFSET=`wcalc -q ${TabBy}-${TabDiff}`\n\n    fi\n\n\n  echo ${TXOFFSET} ${TYOFFSET} ${BXOFFSET} ${BYOFFSET}\n  xsetwacom set \"Wacom ISDv4 E6 Pen stylus\" Area ${TXOFFSET} ${TYOFFSET} ${BXOFFSET} ${BYOFFSET}\n  xsetwacom set \"Wacom ISDv4 E6 Pen eraser\" Area ${TXOFFSET} ${TYOFFSET} ${BXOFFSET} ${BYOFFSET}\n  xsetwacom set \"Wacom ISDv4 E6 Finger touch\" Area ${TXOFFSET} ${TYOFFSET} ${BXOFFSET} ${BYOFFSET}\n\n   fi\n #gnome-control-center wacom\n  else\n echo normal resolution\nfi\n<\/pre>\n<h3>Commentary<\/h3>\n<p>If this script doesn&#8217;t work, it may be because the name of your wacom devices differs from mine.  To find the names of your devices, type: <\/p>\n<pre>xsetwacom --list<\/pre>\n<p>You will get a list of your wacom devices. Mine looks like this:<\/p>\n<pre>\nWacom ISDv4 E6 Pen stylus        id: 10 type: STYLUS    \nWacom ISDv4 E6 Finger touch      id: 11 type: TOUCH     \nWacom ISDv4 E6 Pen eraser        id: 15 type: ERASER    \n<\/pre>\n<p>In this script, I use the information at the far left: &#8216;Wacom ISDv4 E6 Pen stylus&#8217; and the two identifiers below that.  If your device list has different names, then replace the names in the script with the names of your devices.  So if you have, &#8216;Wacom ISDv7 E13 Pen Stylus&#8217;, you would use that instead.  These lines show up multiple places in the script, so if you need to change it, make sure you get it every time, down to the bottom of the file.<\/p>\n<h4>How it works<\/h4>\n<p>This script gets the geometry of your screen and the geometry of your stylus and calculates the width\/height ratio for each.  If this differs by more than a fractional amount, it calculates a new width or height for your stylus.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Why and how This is a better script to set your stylus setting to match a changed resolution, like if you plugged in to a projector. If you are mirroring screens, the geometry may change, so that instead of using your whole 16\/9 ratio screen, you&#8217;re only using a 4\/3 box in the middle. The &hellip; <a href=\"https:\/\/www.celesteh.com\/blog\/2013\/05\/26\/a-better-script-for-wacom-with-screen\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">A better script for Wacom with screen geometry changes<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[1],"tags":[48,39,87,88],"class_list":["post-101","post","type-post","status-publish","format-standard","hentry","category-uncategorised","tag-howto","tag-linux","tag-tablet","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/posts\/101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/comments?post=101"}],"version-history":[{"count":1,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/posts\/101\/revisions"}],"predecessor-version":[{"id":2296,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/posts\/101\/revisions\/2296"}],"wp:attachment":[{"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/media?parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/categories?post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.celesteh.com\/blog\/wp-json\/wp\/v2\/tags?post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}