Advertisement
yulya3102

lock widgets

Nov 20th, 2012
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. -- Create a keylock widget
  2. capslock = widget({ type = "textbox", align = "center" })
  3. capslock.width = 40
  4. scrolllock = widget({ type = "textbox", align = "center" })
  5. scrolllock.width = 44
  6. numlock = widget({ type = "textbox", align = "center" })
  7. numlock.width = 36
  8.  
  9. do
  10.         local update = function()
  11.                 local str = io.popen("xset q | grep Caps"):read()
  12.                 local caps = string.sub(str, string.find(str, "Caps"), string.find(str, "01") - 5):find("off") == nil
  13.                 local num = string.sub(str, string.find(str, "Num"), string.find(str, "02") - 5):find("off") == nil
  14.                 local scroll = string.sub(str, string.find(str, "Scroll"), -1):find("off") == nil
  15.                 local capsstr = "<span " .. (caps and "font_desc='Sans Bold'" or "color='" .. theme.fg_focus .. "'") .. ">Caps</span>"
  16.                 local numstr = "<span " .. (num and "font_desc='Sans Bold'" or "color='" .. theme.fg_focus .. "'") .. ">Num</span>"
  17.                 local scrollstr = "<span " .. (scroll and "font_desc='Sans Bold'" or "color='" .. theme.fg_focus .. "'") .. ">Scroll</span>"
  18.                 capslock.text = " " .. capsstr .. " "
  19.         --      capslock.bg = caps and theme.bg_focus or theme.bg_normal
  20.                 scrolllock.text = " " .. scrollstr .. " "
  21.         --      scrolllock.bg = scroll and theme.bg_focus or theme.bg_normal
  22.                 numlock.text = " " .. numstr .. " "
  23.         --      numlock.bg = num and theme.bg_focus or theme.bg_normal
  24.         end
  25.         timer = timer { timeout = 0.001 }
  26.         timer:add_signal( "timeout", function() update() end)
  27.         timer:start()
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement