awqterm.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. -- {{{ License
  2. -- Awesome dropdown Quake like console
  3. -- 2012, Emmanuel Bouthenot <kolter@openics.org>
  4. --
  5. -- (very) partially inspired from http://awesome.naquadah.org/wiki/Drop-down_terminal
  6. --
  7. -- This file is distributed in the hope that it will be useful,
  8. -- but WITHOUT ANY WARRANTY
  9. --
  10. -- }}}
  11. -- {{{ Libraries
  12. require('utils')
  13. -- }}}
  14. -- {{{ Variables
  15. awq = {}
  16. awq_tag = nil
  17. awq_name = ''
  18. awq_scr = nil
  19. awq_idx = 0
  20. awqterm_prog = 'xterm'
  21. -- }}}
  22. -- {{{ Keys
  23. awqkeys = awful.util.table.join(
  24. awful.key({ "Control" }, "Prior", function(c) awq_client_show_next() end),
  25. awful.key({ "Control" }, "Next" , function(c) awq_client_show_prev() end),
  26. awful.key({ "Mod1" } , "Up" , function(c) awq_client_new() end)
  27. )
  28. -- }}}
  29. -- {{{ Functions (“private”)
  30. function awq_client_show_pos(reverse)
  31. local keys = awful.util.table.keys(awq)
  32. if reverse then
  33. keys = awful.util.table.reverse(keys)
  34. end
  35. local pos = table.pos(keys, awq_name)
  36. if not (pos == nil) then
  37. local pos = pos+1
  38. local newname = table.keypos(keys, pos)
  39. if newname == nil then
  40. newname = table.keyfirst(keys)
  41. end
  42. if not (awq_name == newname) then
  43. awq_client_hide(awq_name)
  44. awq_name = newname
  45. awq_client_show(awq_name)
  46. end
  47. end
  48. end
  49. function awq_client_show_next()
  50. awq_client_show_pos(true)
  51. end
  52. function awq_client_show_prev()
  53. awq_client_show_pos(false)
  54. end
  55. function awq_client_new()
  56. awq_idx = awq_idx+1
  57. awq_name = 'awq_' .. awq_idx
  58. local name = awq_name
  59. if not awq[name] then
  60. -- Create table
  61. awq[name] = {}
  62. -- Add unmanage hook for awq programs
  63. client.add_signal("unmanage", function (c, startup)
  64. awq_client_show_prev()
  65. for name,data in pairs(awq) do
  66. for s, cl in pairs(data) do
  67. if cl == c then
  68. awq[name] = nil
  69. end
  70. end
  71. end
  72. end)
  73. end
  74. -- Get workarea
  75. local workarea = screen[awq_scr].workarea
  76. spawnw = function (c)
  77. -- Store client
  78. awq[name][awq_scr] = c
  79. -- Float client
  80. awful.client.floating.set(c, true)
  81. -- Resize client
  82. c:geometry({
  83. x = workarea.x,
  84. y = workarea.y-19,
  85. width = workarea.width,
  86. height = workarea.height+20
  87. })
  88. -- Set keys
  89. c:keys(awful.util.table.join(
  90. c:keys(),
  91. awqkeys
  92. ))
  93. -- Focus and raise client
  94. c:raise()
  95. client.focus = c
  96. -- Remove hook
  97. client.remove_signal("manage", spawnw)
  98. end
  99. -- Add hook
  100. client.add_signal("manage", spawnw)
  101. -- Spawn program
  102. awful.util.spawn(awqterm_prog)
  103. awq_tag = awful.tag.selected(awq_scr)
  104. end
  105. function awq_client_show(name)
  106. -- Get client
  107. local c = awq[name][awq_scr]
  108. awful.client.movetotag(awful.tag.selected(awq_scr), c)
  109. c.hidden = false
  110. c:raise()
  111. client.focus = c
  112. end
  113. function awq_client_hide(name)
  114. -- Get client
  115. local c = awq[name][awq_scr]
  116. if awful.tag.selected(awq_scr) == awq_tag then
  117. c.hidden = true
  118. local ctags = c:tags()
  119. for i, t in pairs(ctags) do
  120. ctags[i] = nil
  121. end
  122. c:tags(ctags)
  123. else
  124. awful.client.movetotag(awful.tag.selected(awq_scr), c)
  125. c:raise()
  126. client.focus = c
  127. end
  128. end
  129. function awq_client_toggle()
  130. -- Get client
  131. if awq[awq_name] then
  132. c = awq[awq_name][awq_scr]
  133. end
  134. if c == nil then
  135. awq_client_new()
  136. else
  137. if c.hidden then
  138. awq_client_show(awq_name)
  139. else
  140. awq_client_hide(awq_name)
  141. end
  142. awq_tag = awful.tag.selected(awq_scr)
  143. end
  144. end
  145. -- }}}
  146. -- {{{ Functions (“public”)
  147. function awqterm_toggle()
  148. awq_scr = mouse.screen
  149. if next(awq) == nil then
  150. awq_client_new()
  151. else
  152. awq_client_toggle()
  153. end
  154. end
  155. -- }}}
  156. -- vim: foldmethod=marker