awesome/my.lua
author Fabien Ninoles <fabien@tzone.org>
Sat, 03 Jan 2015 11:21:36 -0500
changeset 9 56e80afa3e1c
parent 8 0eae48be1d62
child 11 7226709dc4c4
permissions -rw-r--r--
Only start sloppy timer on a mouse_enter. This avoid a bug when the focus is stolen by another window.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     1
require("naughty")
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     2
require("awful")
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     3
require("debug")
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     4
require("vicious")
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     5
require("wicked")
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     6
require("beautiful")
8
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
     7
require("timer")
7
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     8
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
     9
local ipairs = ipairs
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    10
local pairs = pairs
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    11
local naughty = naughty
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    12
local awful = awful
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    13
local debug = debug
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    14
local vicious = vicious
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    15
local wicked = wicked
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    16
local beautiful = beautiful
8
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
    17
local timer = timer
7
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    18
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    19
local capi = {
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    20
   keygrabber = keygrabber,
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    21
   client = client,
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    22
   string = string,
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    23
   widget = widget,
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    24
}
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    25
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    26
module("my")
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    27
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    28
local in_error = false
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    29
function notify_error(err)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    30
   -- Make sure we don't go into an endless error loop
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    31
   if in_error then return end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    32
   in_error = true
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    33
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    34
   naughty.notify({ preset = naughty.config.presets.critical,
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    35
                    title = "Oops, an error happened!",
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    36
                    text = err })
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    37
   in_error = false
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    38
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    39
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    40
function mkspawn(p)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    41
   return function () awful.util.spawn(p) end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    42
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    43
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    44
function setxkbmap(kb)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    45
   XKBDIR="$HOME/.xkb"
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    46
   -- Strange bug on xkbcomp: pushing directly the output to the display
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    47
   -- lead to an error; We need to convert it first to .xkb and then feed
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    48
   -- xkbcomp again for setting the x display
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    49
   p = 'setxkbmap "' .. kb .. " -print | xkbcomp -xkb -a -I" .. XKBDIR .. " - - | kxbcomp - $DISPLAY"
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    50
   awful.util.spawn_with_shell(p)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    51
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    52
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    53
function kill_all(rule)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    54
   for c in awful.client.iterate(rule) do
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    55
      c:kill()
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    56
   end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    57
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    58
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    59
function quit()
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    60
   kill_all(awful.rules.any)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    61
   awesome.quit()
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    62
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    63
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    64
function show_clients()
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    65
   if instance then
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    66
      instance:hide()
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    67
      instance = nil
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    68
   else
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    69
      instance = awful.menu.clients({width=250})
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    70
   end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    71
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    72
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    73
local function widgets_cpu()
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    74
   local w = awful.widget.graph()
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    75
   -- Graph properties
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    76
   w:set_width(30)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    77
   w:set_background_color("#729fcf")
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    78
   w:set_gradient_colors({ "#729fcf", "LightBlue", "white" })
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    79
-- Register widget
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    80
   vicious.register(w, vicious.widgets.cpu, "$1", 1)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    81
   return w
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    82
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    83
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    84
local function widgets_mdp()
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    85
   -- Initialize widget
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    86
   local w = capi.widget({ type = "textbox" })
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    87
   -- Register widget
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    88
   vicious.register(w, vicious.widgets.mpd,
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    89
                    function (widget, args)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    90
                       if args["{state}"] == "Stop" then 
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    91
                          return " - "
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    92
                       else 
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    93
                          return args["{Artist}"]..' - '.. args["{Title}"]
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    94
                       end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    95
                    end, 10)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    96
   return w
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    97
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    98
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
    99
local function widgets_mem(monitor)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   100
-- Initialize widget
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   101
   local w = awful.widget.progressbar()
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   102
-- Progressbar properties
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   103
   w:set_width(10)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   104
   w:set_vertical(true)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   105
   w:set_background_color("#729fcf")
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   106
   w:set_gradient_colors({ "#729fcf", "LightBlue", "white" })
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   107
-- Register widget
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   108
   vicious.register(w, vicious.widgets.mem, "$1", 5)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   109
   return w
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   110
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   111
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   112
local function widgets_net(device)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   113
   local w = capi.widget({ type = "textbox"})
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   114
   -- w:set_vertical(true)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   115
   w.width = 150
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   116
   w.align = 'center'
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   117
   vicious.register(w, wicked.widgets.net,
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   118
                    '${' .. device .. ' up} / ${' .. device .. ' down}',
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   119
                   1)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   120
   return w
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   121
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   122
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   123
local function widgets_mode()
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   124
   local w = capi.widget({ type = "textbox"})
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   125
   widgets.mode_widget = w
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   126
   return w
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   127
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   128
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   129
local function widgets_keyboard()
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   130
   local w = capi.widget({ type = "textbox"})
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   131
   widgets.keyboard_widget = w
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   132
   return w
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   133
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   134
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   135
local function widgets_decorated(w, onclick)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   136
   local wg = w
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   137
   if w.widget then
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   138
      wg = w.widget
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   139
   end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   140
   wg:buttons(awful.util.table.join(
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   141
                awful.button({}, 1, onclick)))
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   142
   return w
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   143
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   144
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   145
widgets = {
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   146
   cpu = widgets_cpu,
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   147
   mem = widgets_mem,
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   148
   net = widgets_net,
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   149
   mdp = widgets_mdp,
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   150
   mode = widgets_mode,
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   151
   keyboard = widgets_keyboard,
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   152
   decorated = widgets_decorated,
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   153
}
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   154
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   155
function make_key(k, n, f)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   156
   return { key = k, name = n, func = f}
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   157
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   158
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   159
function show_kt(keytable, title)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   160
   -- todo: replace with a menu ?
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   161
   text = ""
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   162
   for _, k in ipairs(keytable) do
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   163
      text = text .. "\'" .. k.key .. "\'\t" .. k.name .. "\n"
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   164
   end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   165
   naughty.notify({text = text, 
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   166
                   title = title, 
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   167
                   position = "top_left",
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   168
   })
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   169
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   170
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   171
local keynames = {
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   172
   [" "] = "space",
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   173
   ["\t"] = "tab",
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   174
}
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   175
8
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   176
local ignored_mods = {
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   177
   ["Mod2"] = true,
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   178
}
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   179
7
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   180
local function translate_key(mod, key)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   181
   local skey = ""
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   182
   for m,v in pairs(mod) do
8
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   183
      if not ignored_mods[v] then 
7
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   184
         skey = skey .. v .. "+"
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   185
      end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   186
   end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   187
   skey = skey .. (keynames[key] or key)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   188
   return skey
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   189
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   190
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   191
local function kt_handler(keytable, mod, key, event)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   192
   if event == "release" then 
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   193
      return true 
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   194
   end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   195
   local theme = beautiful.get()
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   196
   widgets.mode_widget.bg = theme.bg_focus
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   197
   if key == "Escape" then   
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   198
      return false
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   199
   end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   200
   local skey = capi.string.lower(translate_key(mod, key))
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   201
   if skey == "control+h" or skey == "shift+?" then
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   202
      show_kt(keytable, "Current binding")
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   203
      return true
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   204
   end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   205
   for _,k in ipairs(keytable) do
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   206
      if skey == capi.string.lower(k.key) then
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   207
         return k.func(c)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   208
      end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   209
   end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   210
   -- notify_error("Nothing for " .. skey)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   211
   widgets.mode_widget.bg = theme.bg_urgent
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   212
   return true
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   213
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   214
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   215
local function stop_kt()
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   216
   capi.keygrabber.stop()
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   217
   widgets.mode_widget.visible = false
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   218
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   219
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   220
function mkinteractive(f)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   221
  return function (c)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   222
     stop_kt()
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   223
     return f(c)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   224
  end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   225
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   226
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   227
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   228
-- local is_in_run_kt = false
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   229
function run_kt(c, keytable, title)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   230
   widgets.mode_widget.text = "Mode: " .. title
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   231
   widgets.mode_widget.visible = true
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   232
   widgets.mode_widget.bg = "LightBlue"
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   233
   widgets.mode_widget:buttons(
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   234
      awful.util.table.join(
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   235
         awful.button({}, 1, function () show_kt(keytable, "Binding") end),
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   236
         awful.button({}, 3, stop_kt)))
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   237
   capi.keygrabber.run(function (mod, key, event)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   238
         if not kt_handler(keytable, mod, key, event) then
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   239
            stop_kt()
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   240
            return false
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   241
         end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   242
         return true
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   243
   end)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   244
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   245
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   246
function make_kt(keytable, title)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   247
   return function (c) 
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   248
      -- if is_in_run_kt then
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   249
      --    -- notify_error("Already in run_kt:\n" .. debug.traceback())
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   250
      --    is_in_run_kt = false -- reset
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   251
      --    return false
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   252
      -- end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   253
      return run_kt(c, keytable, title)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   254
   end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   255
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   256
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   257
function make_focus_bydirection(direction)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   258
   return function ()
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   259
      awful.client.focus.bydirection(direction)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   260
      if capi.client.focus then capi.client.focus:raise() end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   261
      return true
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   262
   end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   263
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   264
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   265
function make_globalkeys(modifiers, keytable)
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   266
   local t = {}
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   267
   for _,k in ipairs(keytable) do
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   268
      t = awful.util.table.join(t, awful.key(modifiers, k.key, k.func))
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   269
   end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   270
   return t
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   271
end
03125e413ae3 Add awesome configuration
Fabien Ninoles <fabien@tzone.org>
parents:
diff changeset
   272
8
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   273
-- Install a sloppy-like focus with a timeout.
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   274
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   275
function sloppy_toggle()
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   276
   sloppy = not sloppy
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   277
end
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   278
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   279
function sloppy_mouse_enter(c)
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   280
   if sloppy and
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   281
      c ~= sloppy_last_client and
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   282
      awful.client.focus.filter(c) and
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   283
      awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   284
   then
9
56e80afa3e1c Only start sloppy timer on a mouse_enter.
Fabien Ninoles <fabien@tzone.org>
parents: 8
diff changeset
   285
      if sloppy_timer.started
56e80afa3e1c Only start sloppy timer on a mouse_enter.
Fabien Ninoles <fabien@tzone.org>
parents: 8
diff changeset
   286
      then
56e80afa3e1c Only start sloppy timer on a mouse_enter.
Fabien Ninoles <fabien@tzone.org>
parents: 8
diff changeset
   287
         sloppy_timer:again()
56e80afa3e1c Only start sloppy timer on a mouse_enter.
Fabien Ninoles <fabien@tzone.org>
parents: 8
diff changeset
   288
      else
56e80afa3e1c Only start sloppy timer on a mouse_enter.
Fabien Ninoles <fabien@tzone.org>
parents: 8
diff changeset
   289
         sloppy_timer:start()
56e80afa3e1c Only start sloppy timer on a mouse_enter.
Fabien Ninoles <fabien@tzone.org>
parents: 8
diff changeset
   290
      end
8
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   291
      sloppy_last_client = c
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   292
   end
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   293
end
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   294
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   295
function sloppy_on_timeout()
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   296
   if sloppy
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   297
   then
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   298
      local c = awful.mouse.client_under_pointer()
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   299
      if c and
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   300
         c == sloppy_last_client
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   301
      then
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   302
         capi.client.focus = c
9
56e80afa3e1c Only start sloppy timer on a mouse_enter.
Fabien Ninoles <fabien@tzone.org>
parents: 8
diff changeset
   303
         sloppy_timer:stop()
8
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   304
      end
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   305
    end
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   306
end
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   307
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   308
sloppy = true
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   309
sloppy_last_client = nil
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   310
sloppy_timer = nil
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   311
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   312
function sloppy_install(delay)
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   313
   sloppy_timer = timer({ timeout = delay })
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   314
   sloppy_timer:add_signal("timeout", sloppy_on_timeout)
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   315
   sloppy_timer:start()
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   316
   capi.client.add_signal("manage", function (c)
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   317
                             c:add_signal("mouse::enter", sloppy_mouse_enter)
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   318
   end)
9
56e80afa3e1c Only start sloppy timer on a mouse_enter.
Fabien Ninoles <fabien@tzone.org>
parents: 8
diff changeset
   319
   capi.client.add_signal("focus", function () sloppy_timer:stop() end)
8
0eae48be1d62 Add my.sloppy
Fabien Ninoles <fabien@tzone.org>
parents: 7
diff changeset
   320
end