News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
basic wacom mapper (linux/osx-i-assume)
Author Message
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #1
RE: basic wacom mapper (linux/osx-i-assume)

did some more work on it....now it should automatically create a list of monitors (assuming monitor names are all one or more uppercase letters followed by zero or one digits), and if a monitor is connected but not active its button will be disabled (again, assuming xrandr keeps its format pretty much the same)

I think it's in a state now where i'll probably leave it at least for a while. I could have made the tables more tidy (put everything under one "monitor" table), but i'm not terribly comfortable with nested arrays yet.

Code:
#!/usr/bin/env murgaLua

-- mikshaw, dec 2013
-- simple GUI for picking a monitor on which to map a wacom stylus
-- requires xsetwacom and xrandr

-- Whatever device you want to map
wacom = "Wacom Intuos PT M Pen stylus"

-- Check for Wacom tablet
xsetwacom = io.popen("xsetwacom --list")
xsetwacom_string = xsetwacom:read("*a")
xsetwacom:close()
have_wacom    = string.find(xsetwacom_string, wacom)
if not have_wacom then fltk.fl_message("Wacom is not connected"); os.exit(1) end

function set_wacom(self)
os.execute("xsetwacom --set \""..wacom.."\" MapToOutput "..self:tooltip())
os.exit(0)
end

w = fltk:Fl_Double_Window(360, 180, "screen control")
pack = fltk:Fl_Pack(10, 10, w:w()-20, w:h()-20)
wacom_status = fltk:Fl_Box(0, 0, 20, 20, "Map "..wacom.." to:")

-- Check for monitors
xrandr = io.popen("xrandr -q")
xrandr_string = xrandr:read("*a")
xrandr:close()

monitor_line = {}; monitor = {}; m_connected = {}; m_avail = {}; m_label = {}
n = 0
for line in xrandr_string:gmatch("(%u+%d?%s.-)\n") do
    n = n + 1
    monitor_line[n] = line
    monitor[n] = line:gsub("%s.*", "") -- Grab the actual monitor name
    m_label[n] = fltk:Fl_Radio_Round_Button(0, 0, w:w()-20, 30, monitor[n].." (disconnected)")
    m_label[n]:deactivate()
    if string.find(monitor_line[n], " connected ") then
        m_label[n]:label(monitor[n].." (connected but not active)")
    end
    -- Monitor must be both connected and mapped to the screen
    if string.find(monitor_line[n], "%d+x%d+") then
        m_label[n]:callback(set_wacom)
        m_label[n]:label(monitor[n].." (connected)")
        m_label[n]:tooltip(monitor[n])
        m_label[n]:activate()
    end
end

fltk:Fl_End(pack)
w:show()
Fl:run()

01-01-2014 07:26 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
RE: basic wacom mapper (linux/osx-i-assume) - mikshaw - 01-01-2014 07:26 AM

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: