Advertisement
bvn13

Untitled

Sep 13th, 2013
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. ----------------------------------------------------------------------------
  2. -- @author Damien Leone <damien.leone@gmail.com>
  3. -- @author Julien Danjou <julien@danjou.info>
  4. -- @copyright 2008-2009 Damien Leone, Julien Danjou
  5. -- @release v3.4.15
  6. ----------------------------------------------------------------------------
  7.  
  8. -- Grab environment
  9. local io = io
  10. local os = os
  11. local print = print
  12. local pcall = pcall
  13. local pairs = pairs
  14. local type = type
  15. local dofile = dofile
  16. local setmetatable = setmetatable
  17. local util = require("awful.util")
  18. local package = package
  19. local capi =
  20. {
  21. screen = screen,
  22. awesome = awesome,
  23. image = image
  24. }
  25.  
  26. --- Theme library.
  27. module("beautiful")
  28.  
  29. -- Local data
  30. local theme
  31.  
  32. -- Checks the entries in the wallpaper_cmd are valid.
  33. -- @param tw A table with wallpaper commands.
  34. -- @return False if there is no way that this can be a valid wallpaper cmd.
  35. local function wallpaper_is_valid(tw)
  36. if type(tw) ~= 'table' then return false end
  37. for _, v in pairs(tw) do
  38. if type(v) ~= 'string' then return false end
  39. end
  40. return (#tw > 0) and true
  41. end
  42.  
  43. --- Init function, should be runned at the beginning of configuration file.
  44. -- @param path The theme file path.
  45. function init(path)
  46. if path then
  47. local success
  48. success, theme = pcall(function() return dofile(path) end)
  49.  
  50. if not success then
  51. return print("E: beautiful: error loading theme file " .. theme)
  52. elseif theme then
  53. -- try and grab user's $HOME directory
  54. local homedir = os.getenv("HOME")
  55. -- expand '~'
  56. if homedir then
  57. for k, v in pairs(theme) do
  58. if type(v) == "string" then theme[k] = v:gsub("~", homedir) end
  59. end
  60. end
  61.  
  62. -- setup wallpaper
  63. if wallpaper_is_valid(theme.wallpaper_cmd) then
  64. for s = 1, capi.screen.count() do
  65. util.spawn(theme.wallpaper_cmd[util.cycle(#theme.wallpaper_cmd, s)], false, s)
  66. end
  67. else
  68. if theme.wallpaper_cmd then
  69. -- There is a wallpaper_cmd, but wallpaper_is_valid doesn't like it
  70. print("W: beautiful: invalid wallpaper_cmd in theme file " .. path)
  71. end
  72. end
  73. if theme.font then capi.awesome.font = theme.font end
  74. if theme.fg_normal then capi.awesome.fg = theme.fg_normal end
  75. if theme.bg_normal then capi.awesome.bg = theme.bg_normal end
  76. else
  77. return print("E: beautiful: error loading theme file " .. path)
  78. end
  79. else
  80. return print("E: beautiful: error loading theme: no path specified")
  81. end
  82. end
  83.  
  84. --- Get the current theme.
  85. -- @return The current theme table.
  86. function get()
  87. return theme
  88. end
  89.  
  90. setmetatable(_M, { __index = function(t, k) return theme[k] end })
  91.  
  92. -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement