awesome/my.lua
changeset 13 e9e2f624cd99
parent 12 ffc02bf394cb
child 14 6348b9f842b2
equal deleted inserted replaced
12:ffc02bf394cb 13:e9e2f624cd99
     1 local os = require("os")
     1 local os = require("os")
     2 local io = require("io")
     2 local io = require("io")
     3 local debug = require("debug")
     3 local debug = require("debug")
       
     4 local table = require("table")
     4 local awesome = require("awesome")
     5 local awesome = require("awesome")
     5 local naughty = require("naughty")
     6 local naughty = require("naughty")
     6 local awful = require("awful")
     7 local awful = require("awful")
     7 local vicious = require("vicious")
     8 local vicious = require("vicious")
     8 local wicked = require("wicked")
     9 local wicked = require("wicked")
    59    end
    60    end
    60 end
    61 end
    61    
    62    
    62 notify_error = mk_notify_error_dialog(3)
    63 notify_error = mk_notify_error_dialog(3)
    63 
    64 
    64 local function get_gradient_colors(c1, c2, c3)
    65 local function get_gradient_colors(c1, c2)
    65    return { type = "linear", from = { 0, 0 }, to = { 0, 20 }, stops = { { 0, c1 }, { 0.5, c2 }, { 1, c3 } }}
    66    return { type = "linear", from = { 0, 0 }, to = { 0, 20 }, stops = { { 0, c2 }, { 1, c1 } }}
    66 end
    67 end
    67 
    68 
    68 function mkspawn(p)
    69 function mkspawn(p)
    69    return function () awful.util.spawn(p) end
    70    return function () awful.util.spawn(p) end
    70 end
    71 end
   100 
   101 
   101 local function widgets_cpu()
   102 local function widgets_cpu()
   102    local w = awful.widget.graph()
   103    local w = awful.widget.graph()
   103    -- Graph properties
   104    -- Graph properties
   104    w:set_width(30)
   105    w:set_width(30)
   105    w:set_background_color("#729fcf")
   106    w:set_background_color(beautiful.bg_normal)
   106    w:set_color(get_gradient_colors("#729fcf", "LightBlue", "white"))
   107    w:set_color(get_gradient_colors(beautiful.bg_focus, beautiful.bg_urgent))
   107 -- Register widget
   108 -- Register widget
   108    vicious.register(w, vicious.widgets.cpu, "$1", 1)
   109    vicious.register(w, vicious.widgets.cpu, "$1", 1)
   109    return w
   110    return w
   110 end
   111 end
   111 
   112 
   128 -- Initialize widget
   129 -- Initialize widget
   129    local w = awful.widget.progressbar()
   130    local w = awful.widget.progressbar()
   130 -- Progressbar properties
   131 -- Progressbar properties
   131    w:set_width(10)
   132    w:set_width(10)
   132    w:set_vertical(true)
   133    w:set_vertical(true)
   133    w:set_background_color("#729fcf")
   134    w:set_background_color(beautiful.bg_normal)
   134    w:set_color(get_gradient_colors("#729fcf", "LightBlue", "white"))
   135    w:set_color(get_gradient_colors(beautiful.bg_focus, beautiful.bg_urgent))
   135 -- Register widget
   136 -- Register widget
   136    vicious.register(w, vicious.widgets.mem, "$1", 5)
   137    vicious.register(w, vicious.widgets.mem, "$1", 5)
   137    return w
   138    return w
   138 end
   139 end
   139 
   140 
   221 
   222 
   222 local function kt_handler(keytable, mod, key, event)
   223 local function kt_handler(keytable, mod, key, event)
   223    if event == "release" then 
   224    if event == "release" then 
   224       return true 
   225       return true 
   225    end
   226    end
   226    local theme = beautiful.get()
   227    widgets.mode_widget_bg:set_bg(beautiful.bg_focus)
   227    widgets.mode_widget_bg:set_bg(theme.bg_focus)
       
   228    if key == "Escape" then   
   228    if key == "Escape" then   
   229       return false
   229       return false
   230    end
   230    end
   231    local skey = capi.string.lower(translate_key(mod, key))
   231    local skey = capi.string.lower(translate_key(mod, key))
   232    if skey == "control+h" or skey == "shift+?" then
   232    if skey == "control+h" or skey == "shift+?" then
   237       if skey == capi.string.lower(k.key) then
   237       if skey == capi.string.lower(k.key) then
   238          return k.func(c)
   238          return k.func(c)
   239       end
   239       end
   240    end
   240    end
   241    -- notify_error("Nothing for " .. skey)
   241    -- notify_error("Nothing for " .. skey)
   242    widgets.mode_widget_bg:set_bg(theme.bg_urgent)
   242    widgets.mode_widget_bg:set_bg(beautiful.bg_urgent)
   243    return true
   243    return true
   244 end
   244 end
   245 
   245 
   246 local function stop_kt()
   246 local function stop_kt()
   247    capi.keygrabber.stop()
   247    capi.keygrabber.stop()
   258 
   258 
   259 -- local is_in_run_kt = false
   259 -- local is_in_run_kt = false
   260 function run_kt(c, keytable, title)
   260 function run_kt(c, keytable, title)
   261    widgets.mode_widget:set_text("Mode: " .. title)
   261    widgets.mode_widget:set_text("Mode: " .. title)
   262    -- widgets.mode_widget:show()
   262    -- widgets.mode_widget:show()
   263    widgets.mode_widget_bg:set_bg("LightBlue")
   263    widgets.mode_widget_bg:set_bg(beautiful.bg_focus)
   264    widgets.mode_widget:buttons(
   264    widgets.mode_widget:buttons(
   265       awful.util.table.join(
   265       awful.util.table.join(
   266          awful.button({}, 1, function () show_kt(keytable, "Binding") end),
   266          awful.button({}, 1, function () show_kt(keytable, "Binding") end),
   267          awful.button({}, 3, stop_kt)))
   267          awful.button({}, 3, stop_kt)))
   268    capi.keygrabber.run(function (mod, key, event)
   268    capi.keygrabber.run(function (mod, key, event)
   351                                  if sloppy_timer.started then
   351                                  if sloppy_timer.started then
   352                                     sloppy_timer:stop()
   352                                     sloppy_timer:stop()
   353                                  end
   353                                  end
   354    end)
   354    end)
   355 end
   355 end
       
   356 
       
   357 -- theme menu
       
   358 function theme_load(theme)
       
   359    local cfg_path = awful.util.getdir("config")
       
   360    awful.util.spawn("ln -sfn " .. cfg_path .. "/themes/" .. theme .. " " .. cfg_path .. "/current_theme")
       
   361    awesome.restart()
       
   362 end
       
   363 
       
   364 function theme_menu()
       
   365    -- List your theme files and feed the menu table
       
   366    local cmd = "ls -1 " .. awful.util.getdir("config") .. "/themes/"
       
   367    local f = io.popen(cmd)
       
   368 
       
   369    local themes = {}
       
   370    for l in f:lines() do
       
   371 	  local item = { l, function () theme_load(l) end }
       
   372 	  table.insert(themes, item)
       
   373    end
       
   374 
       
   375    f:close()
       
   376    return themes
       
   377 end
       
   378 
       
   379 function set_wallpaper(wallpaper)
       
   380    local cfg_path = awful.util.getdir("config")
       
   381    local source_path = cfg_path .. "/wallpapers/" .. wallpaper
       
   382    local default_path = cfg_path .. "/default"
       
   383    awful.util.spawn("ln -sfn " .. source_path .. " " .. default_path )
       
   384    awful.util.spawn("fbsetbg -a " .. default_path)
       
   385 end
       
   386 
       
   387 function wallpaper_menu()
       
   388    local cmd = "ls " .. awful.util.getdir("config") .. "/wallpapers/"
       
   389    local f = io.popen(cmd)
       
   390    local wallpapers = {}
       
   391    for l in f:lines() do
       
   392       local name, ext = capi.string.match(l, "(.-)(%.[^%.]+)$")
       
   393       local item = { name,  function () set_wallpaper(l) end }
       
   394       table.insert(wallpapers, item)
       
   395    end
       
   396 
       
   397    f:close()
       
   398    return wallpapers
       
   399 end
       
   400