My configuration files for Debian/Ubuntu applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Utilities.md 12 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. Quake
  2. -----
  3. A Quake-like dropdown container for your favourite application.
  4. **Usage**
  5. Define it globally to have a single instance for all screens:
  6. ```lua
  7. local quake = lain.util.quake()
  8. ```
  9. or define it in `connect_for_each_screen` to have one instance for each screen:
  10. ```lua
  11. awful.screen.connect_for_each_screen(function(s)
  12. -- Quake application
  13. s.quake = lain.util.quake()
  14. -- [...]
  15. ```
  16. **Keybinding example**
  17. If using a global instance:
  18. ```lua
  19. awful.key({ modkey, }, "z", function () quake:toggle() end),
  20. ```
  21. If using a per-screen instance:
  22. ```lua
  23. awful.key({ modkey, }, "z", function () awful.screen.focused().quake:toggle() end),
  24. ```
  25. **Input table**
  26. Variable | Meaning | Type | Default
  27. --- | --- | --- | ---
  28. `app` | client to spawn | string | "xterm"
  29. `name` | client name | string | "QuakeDD"
  30. `argname` | how to specify client name | string | "-name %s"
  31. `extra` | extra `app` arguments | string | empty string
  32. `border` | border width | integer | 1
  33. `visible` | initially visible | boolean | false
  34. `followtag` | always spawn on currently focused screen | boolean | false
  35. `overlap` | Overlap the wibox or not | boolean | false
  36. `settings` | Additional settings to make on the client | function | `nil`
  37. `screen` | screen where to spawn the client | integer | `awful.screen.focused()`
  38. `height` | dropdown client height | float in [0,1] or exact pixels number | 0.25
  39. `width` | dropdown client width | float in [0,1] or exact pixels number | 1
  40. `vert` | vertical position | string, possible values: "top", "bottom", "center" | "top"
  41. `horiz` | horizontal position | string, possible values: "left", "right", "center" | "left"
  42. `height` and `width` express a fraction of the workspace.
  43. `settings` is a function which takes the client as input, and can be used to customize its properties. For instance:
  44. ```lua
  45. -- set the client sticky
  46. s.quake = lain.util.quake { settings = function(c) c.sticky = true end }
  47. ```
  48. Read [here](https://awesomewm.org/doc/api/classes/client.html#Object_properties) for the complete list of properties.
  49. **Notes**
  50. * [Does not work](https://github.com/lcpz/lain/issues/358) with `gnome-terminal`, `konsole`, or any other terminal which is strictly designed for a Desktop Environment. Just pick a better terminal, [there's plenty](https://wiki.archlinux.org/index.php/List_of_applications#Terminal_emulators).
  51. * Set `followtag = true` if [experiencing issues with multiple screens](https://github.com/lcpz/lain/issues/346).
  52. * If you have a `awful.client.setslave` rule for your application, ensure you use an exception for `QuakeDD` (or your defined `name`). Otherwise, you may run into problems with focus.
  53. * If you are using a VTE-based terminal like `termite`, be sure to set [`argname = "--name %s"`](https://github.com/lcpz/lain/issues/211).
  54. Separators
  55. ----------
  56. Adds Cairo separators.
  57. ```lua
  58. local separators = lain.util.separators
  59. ```
  60. A separator function `separators.separator` takes two color arguments, defined as strings. `"alpha"` argument is allowed. Example:
  61. ```lua
  62. arrl_dl = separators.arrow_left(beautiful.bg_focus, "alpha")
  63. arrl_ld = separators.arrow_left("alpha", beautiful.bg_focus)
  64. ```
  65. You can customize height and width by setting `separators_height` and `separators_width` in your `theme.lua`. Default values are 0 and 9, respectively.
  66. List of functions:
  67. +-- separators
  68. |
  69. |`-- arrow_right() Draw a right arrow.
  70. `-- arrow_left() Draw a left arrow.
  71. markup
  72. ------
  73. Mades markup easier.
  74. ```lua
  75. local markup = lain.util.markup
  76. ```
  77. List of functions:
  78. +-- markup
  79. |
  80. |`-- bold() Set bold.
  81. |`-- italic() Set italicized text.
  82. |`-- strike() Set strikethrough text.
  83. |`-- underline() Set underlined text.
  84. |`-- monospace() Set monospaced text.
  85. |`-- big() Set bigger text.
  86. |`-- small() Set smaller text.
  87. |`-- font() Set the font of the text.
  88. |`-- font() Set the font of the text.
  89. |`-- color() Set background and foreground color.
  90. |`-- fontfg() Set font and foreground color.
  91. |`-- fontbg() Set font and background color.
  92. `-- fontcolor() Set font, plus background and foreground colors.
  93. |
  94. |`--+ bg
  95. | |
  96. | `-- color() Set background color.
  97. |
  98. `--+ fg
  99. |
  100. `-- color() Set foreground color.
  101. they all take one argument, which is the text to markup, except the following:
  102. ```lua
  103. markup.font(font, text)
  104. markup.color(fg, bg, text)
  105. markup.fontfg(font, fg, text)
  106. markup.fontbg(font, bg, text)
  107. markup.fontcolor(font, fg, bg, text)
  108. markup.fg.color(color, text)
  109. markup.bg.color(color, text)
  110. ```
  111. Dynamic tagging
  112. ---------------
  113. That is:
  114. - add a new tag;
  115. - rename current tag;
  116. - move current tag;
  117. - delete current tag.
  118. If you delete a tag, any rule set on it shall be broken, so be careful.
  119. Use it with key bindings like these:
  120. ```lua
  121. awful.key({ modkey, "Shift" }, "n", function () lain.util.add_tag(mylayout) end),
  122. awful.key({ modkey, "Shift" }, "r", function () lain.util.rename_tag() end),
  123. awful.key({ modkey, "Shift" }, "Left", function () lain.util.move_tag(1) end), -- move to next tag
  124. awful.key({ modkey, "Shift" }, "Right", function () lain.util.move_tag(-1) end), -- move to previous tag
  125. awful.key({ modkey, "Shift" }, "d", function () lain.util.delete_tag() end),
  126. ```
  127. The argument in `lain.util.add_tag` represents the tag layout, and is optional: if not present, it will be defaulted to `awful.layout.suit.tile`.
  128. Useless gaps resize
  129. ---------------------
  130. Changes `beautiful.useless_gaps` on the fly.
  131. ```lua
  132. lain.util.useless_gap_resize(thatmuch, s, t)
  133. ```
  134. The argument `thatmuch` is the number of pixel to add to/substract from gaps (integer).
  135. The arguments `s` and `t` are the `awful.screen` and `awful.tag` in which you want to change the gap. They are optional.
  136. Following are example keybindings for changing client gaps on current screen and tag.
  137. Example 1:
  138. ```lua
  139. -- On the fly useless gaps change
  140. awful.key({ altkey, "Control" }, "+", function () lain.util.useless_gaps_resize(1) end),
  141. awful.key({ altkey, "Control" }, "-", function () lain.util.useless_gaps_resize(-1) end),
  142. ```
  143. where `altkey = Mod1`. Example 2:
  144. ```lua
  145. mywidget:buttons(awful.util.table.join (
  146. awful.button({}, 4, function() lain.util.useless_gaps_resize(-1) end),
  147. awful.button({}, 5, function() lain.util.useless_gaps_resize(1) end)
  148. end)
  149. ))
  150. ```
  151. so when hovering the mouse over `mywidget`, you can adjust useless gaps size by scrolling with the mouse wheel.
  152. tag\_view\_nonempty
  153. -------------------
  154. This function lets you jump to the next/previous non-empty tag.
  155. It takes two arguments:
  156. * `direction`: `1` for next non-empty tag, `-1` for previous.
  157. * `sc`: Screen which the taglist is in. Default is `mouse.screen` or `1`. This
  158. argument is optional.
  159. You can use it with key bindings like these:
  160. ```lua
  161. -- Non-empty tag browsing
  162. awful.key({ altkey }, "Left", function () lain.util.tag_view_nonempty(-1) end),
  163. awful.key({ altkey }, "Right", function () lain.util.tag_view_nonempty(1) end),
  164. ```
  165. where `altkey = "Mod1"`.
  166. magnify\_client
  167. ---------------
  168. Set a client to floating and resize it in the same way the "magnifier"
  169. layout does it. Place it on the "current" screen (derived from the mouse
  170. position). This allows you to magnify any client you wish, regardless of
  171. the currently used layout. Use it with a client keybinding like this:
  172. ```lua
  173. clientkeys = awful.util.table.join(
  174. -- [...]
  175. awful.key({ modkey, "Control" }, "m", lain.util.magnify_client),
  176. -- [...]
  177. )
  178. ```
  179. If you want to "de-magnify" it, just retype the keybinding.
  180. If you want magnified client to respond to `incmwfact`, read [here](https://github.com/lcpz/lain/issues/195).
  181. menu\_clients\_current\_tags
  182. ----------------------------
  183. Similar to `awful.menu.clients`, but this menu only shows the clients
  184. of currently visible tags. Use it with a key binding like this:
  185. ```lua
  186. awful.key({ "Mod1" }, "Tab", function()
  187. lain.util.menu_clients_current_tags({ width = 350 }, { keygrabber = true })
  188. end),
  189. ```
  190. menu\_iterator
  191. --------------
  192. A generic menu utility which enables iteration over lists of possible
  193. actions to execute. The perfect example is a menu for choosing what
  194. configuration to apply to X with `xrandr`, as suggested on the [Awesome wiki page](https://awesomewm.org/recipes/xrandr).
  195. <p align="center">
  196. <img src="https://user-images.githubusercontent.com/4147254/36317474-3027f8b6-130b-11e8-9b6b-9a2cf55ae841.gif"/>
  197. <br>An example Synergy menu, courtesy of <a href="https://github.com/sim590/dotfiles/blob/master/awesome/rc/xrandr.lua">sim590</a>
  198. </p>
  199. You can either manually create a menu by defining a table in this format:
  200. ```lua
  201. { { "choice description 1", callbackFuction1 }, { "choice description 2", callbackFunction2 }, ... }
  202. ```
  203. or use `lain.util.menu_iterator.menu`. Once you have your menu, use it with `lain.menu_iterator.iterate`.
  204. ### Input tables
  205. **lain.menu_iterator.iterate**
  206. | Argument | Description | Type
  207. |---|---| ---
  208. | `menu` | the menu to iterate on | table
  209. | `timeout` | time (in seconds) to wait on a choice before the choice is accepted | integer (default: 4)
  210. | `icon` | path to the icon to display in `naughty.notify` window | string
  211. **lain.menu_iterator.menu**
  212. | Argument | Description | Type
  213. |---|---| ---
  214. `choices` | list of choices (e.g., `{ "choice1", "choice2", ... }`) | array of strings
  215. `name` | name of the program related to this menu | string
  216. `selected_cb` | callback to execute for each selected choice, it takes one choice (string) as argument; can be `nil` (no action to execute) | function
  217. `rejected_cb` | callback to execute for all rejected choices (the remaining choices, once one is selected), it takes one choice (string) as argument; can be `nil` (no action to execute) | function
  218. `extra_choices` | more choices to be added to the menu; unlike `choices`, these ones won't trigger `rejected_cb` | array of `{ choice, callback }` pairs, where `choice` is a string and `callback` is a function
  219. `combination` | how choices have to be combined in the menu; possible values are: "single" (default), the set of possible choices will simply be the input set ; "powerset", the set of possible choices will be the [power set](https://en.wikipedia.org/wiki/Power_set) of the input set | string
  220. ### Examples
  221. A simple example is:
  222. ```lua
  223. local mymenu_iterable = lain.util.menu_iterator.menu {
  224. choices = {"My first choice", "My second choice"},
  225. name = "My awesome program",
  226. selected_cb = function(choice)
  227. -- do something with selected choice
  228. end,
  229. rejected_cb = function(choice)
  230. -- do something with every rejected choice
  231. end
  232. }
  233. ```
  234. The variable `mymenu_iterable` is a menu compatible with the function `lain.util.menu_iterator.iterate`, which will iterate over it and displays notification with `naughty.notify` every time it is called. You can use it like this:
  235. ```lua
  236. local confirm_timeout = 5 -- time to wait before confirming the menu selection
  237. local my_notify_icon = "/path/to/icon" -- the icon to display in the notification
  238. lain.util.menu_iterator.iterate(mymenu_iterable, confirm_timeout, my_notify_icon)
  239. ```
  240. Once `confirm_timeout` has passed without anymore calls to `iterate`, the choice is made and the associated callbacks (both for selected and rejected choices) are spawned.
  241. A useful practice is to add a `Cancel` option as an extra choice for canceling a menu selection. Extending the above example:
  242. ```lua
  243. local mymenu_iterable = lain.util.menu_iterator.menu {
  244. choices = {"My first choice", "My second choice"},
  245. name = "My awesome program",
  246. selected_cb = function(choice)
  247. -- do something with selected choice
  248. end,
  249. rejected_cb = function(choice)
  250. -- do something with every rejected choice
  251. end
  252. -- nil means no action to do
  253. extra_choices = { {"Cancel"}, nil }
  254. }
  255. ```