| 1 | <!-- START doctoc generated TOC please keep comment here to allow auto update --> |
| 2 | <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> |
| 3 | **Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)* |
| 4 | |
| 5 | - [awesome-cyclefocus](#awesome-cyclefocus) |
| 6 | - [Screenshot](#screenshot) |
| 7 | - [Installation](#installation) |
| 8 | - [Keybindings](#keybindings) |
| 9 | - [Example 1: cycle through all windows](#example-1-cycle-through-all-windows) |
| 10 | - [Example 2: cycle through windows on the same screen and tag](#example-2-cycle-through-windows-on-the-same-screen-and-tag) |
| 11 | - [`cycle_filters`](#cycle_filters) |
| 12 | - [Predefined filters](#predefined-filters) |
| 13 | - [Example 3: cycle through clients with the same class](#example-3-cycle-through-clients-with-the-same-class) |
| 14 | - [Reference](#reference) |
| 15 | - [Configuration](#configuration) |
| 16 | - [<a name="settings"></a>Settings](#a-namesettingsasettings) |
| 17 | - [Status](#status) |
| 18 | - [Bugs, Feedback and Support](#bugs-feedback-and-support) |
| 19 | - [Donate](#donate) |
| 20 | |
| 21 | <!-- END doctoc generated TOC please keep comment here to allow auto update --> |
| 22 | |
| 23 | # awesome-cyclefocus |
| 24 | |
| 25 | awesome-cyclefocus is a module/plugin for the [awesome window |
| 26 | manager][], which provides methods to cycle through |
| 27 | the most recently used clients (typically known as Alt-Tab). |
| 28 | |
| 29 | It allows to easily filter the list of windows to be cycled through, e.g. by |
| 30 | screen, tags, window class, name/title etc. |
| 31 | |
| 32 | ## Screenshot |
| 33 | |
| 34 |  |
| 35 | |
| 36 | Please note that the graphical aspect needs to be developed, but since people |
| 37 | like screenshots… |
| 38 | |
| 39 | ## Installation |
| 40 | |
| 41 | *Requirements:* awesome-cyclefocus requires Awesome 4+. |
| 42 | |
| 43 | Create a subdirectory `cyclefocus` in your awesome config directory, e.g. |
| 44 | |
| 45 | cd ~/.config/awesome |
| 46 | git clone https://github.com/blueyed/awesome-cyclefocus cyclefocus |
| 47 | |
| 48 | Then include it from your config file (`~/.config/awesome/rc.lua`), somewhere |
| 49 | at the beginning: |
| 50 | |
| 51 | ```lua |
| 52 | local cyclefocus = require('cyclefocus') |
| 53 | ``` |
| 54 | |
| 55 | ## Keybindings |
| 56 | |
| 57 | Then you can define the keybindings. |
| 58 | |
| 59 | While you can use it with the `globalkeys` configuration, you should use |
| 60 | the `clientkeys` table for any bindings which use `cycle_filters`. |
| 61 | |
| 62 | The default for `modkey+Tab` in awesome (3.5.2) is: |
| 63 | ```lua |
| 64 | awful.key({ modkey, }, "Tab", |
| 65 | function () |
| 66 | awful.client.focus.history.previous() |
| 67 | if client.focus then |
| 68 | client.focus:raise() |
| 69 | end |
| 70 | end), |
| 71 | ``` |
| 72 | You should disable it (e.g. by commenting it out), and add your method below. |
| 73 | |
| 74 | Here are three methods to setup the key mappings: |
| 75 | |
| 76 | ### Example 1: cycle through all windows |
| 77 | |
| 78 | Setup `modkey+Tab` to cycle through all windows (assuming `modkey` is |
| 79 | `Mod4`/`Super_L`, which is the default): |
| 80 | |
| 81 | ```lua |
| 82 | -- modkey+Tab: cycle through all clients. |
| 83 | awful.key({ modkey }, "Tab", function(c) |
| 84 | cyclefocus.cycle({modifier="Super_L"}) |
| 85 | end), |
| 86 | -- modkey+Shift+Tab: backwards |
| 87 | awful.key({ modkey, "Shift" }, "Tab", function(c) |
| 88 | cyclefocus.cycle({modifier="Super_L"}) |
| 89 | end), |
| 90 | ``` |
| 91 | |
| 92 | You can pass a table of optional arguments. |
| 93 | We need to pass the modifier (as seen by awesome's `keygrabber`) here. |
| 94 | Internally the direction gets set according to if the `Shift` modifier key |
| 95 | is present, so that the second definition is only necessary to trigger it in |
| 96 | the opposite direction from the beginning. |
| 97 | |
| 98 | See the `init.lua` file (or the [settings section below](#settings)) for a full |
| 99 | reference. |
| 100 | |
| 101 | ### Example 2: cycle through windows on the same screen and tag |
| 102 | |
| 103 | You can use `cyclefocus.key` (a wrapper around `awful.key`) like this: |
| 104 | |
| 105 | ```lua |
| 106 | -- Alt-Tab: cycle through clients on the same screen. |
| 107 | -- This must be a clientkeys mapping to have source_c available in the callback. |
| 108 | cyclefocus.key({ "Mod1", }, "Tab", { |
| 109 | -- cycle_filters as a function callback: |
| 110 | -- cycle_filters = { function (c, source_c) return c.screen == source_c.screen end }, |
| 111 | |
| 112 | -- cycle_filters from the default filters: |
| 113 | cycle_filters = { cyclefocus.filters.same_screen, cyclefocus.filters.common_tag }, |
| 114 | keys = {'Tab', 'ISO_Left_Tab'} -- default, could be left out |
| 115 | }), |
| 116 | ``` |
| 117 | |
| 118 | The first two arguments are the same as with `awful.key`: a list of modifiers |
| 119 | and the key. Then the table with optional arguments to `cyclefocus.cycle()` |
| 120 | follows. |
| 121 | (here the `modifier` argument is not required, because it gets used from |
| 122 | the first argument). |
| 123 | |
| 124 | NOTE: this needs to go into `clientkeys`. |
| 125 | |
| 126 | #### `cycle_filters` |
| 127 | |
| 128 | In this case the `cycle_filters` argument is used, which is a list of filters |
| 129 | to apply while cycling through the focus history: it gets passed a `client` |
| 130 | object, and optionally another `client` object for the source (where the |
| 131 | cycling started). |
| 132 | For the source client to be available, it needs to be an entry in the |
| 133 | `clientkeys` table. |
| 134 | |
| 135 | You can pass functions here, or use one of the predefined filters: |
| 136 | |
| 137 | #### Predefined filters |
| 138 | |
| 139 | The following filters are available by default: |
| 140 | |
| 141 | ```lua |
| 142 | -- A set of default filters, which can be used for cyclefocus.cycle_filters. |
| 143 | cyclefocus.filters = { |
| 144 | -- Filter clients on the same screen. |
| 145 | same_screen = function (c, source_c) return c.screen == source_c.screen end, |
| 146 | |
| 147 | same_class = function (c, source_c) |
| 148 | return c.class == source_c.class |
| 149 | end, |
| 150 | |
| 151 | -- Only marked clients (via awful.client.mark and .unmark). |
| 152 | marked = function (c, source_c) |
| 153 | return awful.client.ismarked(c) |
| 154 | end, |
| 155 | |
| 156 | common_tag = function (c, source_c) |
| 157 | for _, t in pairs(c:tags()) do |
| 158 | for _, t2 in pairs(source_c:tags()) do |
| 159 | if t == t2 then |
| 160 | cyclefocus.debug("Filter: client shares tag '" .. t.name .. " with " .. c.name) |
| 161 | return true |
| 162 | end |
| 163 | end |
| 164 | end |
| 165 | return false |
| 166 | end |
| 167 | } |
| 168 | ``` |
| 169 | |
| 170 | ### Example 3: cycle through clients with the same class |
| 171 | |
| 172 | The following will cycle through windows, which share the same window class |
| 173 | (e.g. only Firefox windows, when starting from a Firefox window): |
| 174 | |
| 175 | ```lua |
| 176 | -- Alt-^: cycle through clients with the same class name. |
| 177 | cyclefocus.key({ "Mod1", }, "#49", 1, { |
| 178 | cycle_filter = function (c, source_c) return c.class == source_c.class end, |
| 179 | keys = { "°", "^" }, -- the keys to be handled, wouldn't be required if the keycode was available in keygrabber. |
| 180 | }), |
| 181 | cyclefocus.key({ "Mod1", "Shift", }, "#49", -1, { -- keycode #49 => ^/° on german keyboard, upper left below Escape and next to 1. |
| 182 | cycle_filter = function (c, source_c) return c.class == source_c.class end, |
| 183 | keys = { "°", "^" }, -- the keys to be handled, wouldn't be required if the keycode was available in keygrabber. |
| 184 | }), |
| 185 | ``` |
| 186 | |
| 187 | The key argument uses the keycode notation (`#49`) and refers (probably) to the key |
| 188 | below Escape, above Tab and next to the first digit (1). |
| 189 | It should be the same shortcut, as what Ubuntu's Unity uses to cycle through |
| 190 | the windows of a single application. |
| 191 | |
| 192 | NOTE: You need to pass the keys this refers to via the `keys` argument, so that |
| 193 | the keygrabber considers those only. |
| 194 | In the example above, `^` and `°` refers to the key on the German keyboard |
| 195 | layout (un-shifted and shifted, i.e. with Shift pressed and released). |
| 196 | |
| 197 | NOTE: this needs to go into `clientkeys`. |
| 198 | |
| 199 | ## Reference |
| 200 | |
| 201 | ### Configuration |
| 202 | |
| 203 | awesome-cyclefocus can be configured by passing optional arguments to the |
| 204 | `cyclefocus.cycle` or `cyclefocus.key` functions, or by setting defaults, after |
| 205 | loading `cyclefocus`: |
| 206 | |
| 207 | #### <a name="settings"></a>Settings |
| 208 | |
| 209 | The default settings are: |
| 210 | |
| 211 | ```lua |
| 212 | cyclefocus = { |
| 213 | -- Should clients get shown during cycling? |
| 214 | -- This should be a function (or `false` to disable showing clients), which |
| 215 | -- receives a client object, and can make use of `cyclefocus.show_client` |
| 216 | -- (the default implementation). |
| 217 | show_clients = true, |
| 218 | -- Should clients get focused during cycling? |
| 219 | -- This is required for the tasklist to highlight the selected entry. |
| 220 | focus_clients = true, |
| 221 | -- Should the selected client get raised? |
| 222 | -- This calls `cyclefocus.raise_client_without_focus` by default, which you |
| 223 | -- can use when overriding this with a function (that gets the client as |
| 224 | -- argument). |
| 225 | raise_client = true, |
| 226 | -- Should the mouse pointer be moved away during cycling? |
| 227 | -- This is normally done to avoid interference from sloppy focus handling, |
| 228 | -- but can be disabled if you do not use sloppy focus. |
| 229 | move_mouse_pointer = true, |
| 230 | |
| 231 | -- How many entries should get displayed before and after the current one? |
| 232 | display_next_count = 3, |
| 233 | display_prev_count = 3, |
| 234 | |
| 235 | -- Default preset to use for entries. |
| 236 | -- `preset_for_offset` (below) gets added to it. |
| 237 | default_preset = {}, |
| 238 | |
| 239 | --- Templates for entries in the list. |
| 240 | -- The following arguments get passed to a callback: |
| 241 | -- - client: the current client object. |
| 242 | -- - idx: index number of current entry in clients list. |
| 243 | -- - displayed_list: the list of entries in the list, possibly filtered. |
| 244 | preset_for_offset = { |
| 245 | -- Default callback, which will gets applied for all offsets (first). |
| 246 | default = function (preset, args) |
| 247 | -- Default font and icon size (gets overwritten for current/0 index). |
| 248 | preset.font = 'sans 8' |
| 249 | preset.icon_size = dpi(24) |
| 250 | preset.text = escape_markup(cyclefocus.get_client_title(args.client, false)) |
| 251 | end, |
| 252 | |
| 253 | -- Preset for current entry. |
| 254 | ["0"] = function (preset, args) |
| 255 | preset.font = 'sans 14' |
| 256 | preset.icon_size = dpi(36) |
| 257 | preset.text = escape_markup(cyclefocus.get_client_title(args.client, true)) |
| 258 | -- Add screen number if there is more than one. |
| 259 | if screen.count() > 1 then |
| 260 | preset.text = preset.text .. " [screen " .. tostring(args.client.screen.index) .. "]" |
| 261 | end |
| 262 | preset.text = preset.text .. " [#" .. args.idx .. "] " |
| 263 | preset.text = '<b>' .. preset.text .. '</b>' |
| 264 | end, |
| 265 | |
| 266 | -- You can refer to entries by their offset. |
| 267 | -- ["-1"] = function (preset, args) |
| 268 | -- -- preset.icon_size = 32 |
| 269 | -- end, |
| 270 | -- ["1"] = function (preset, args) |
| 271 | -- -- preset.icon_size = 32 |
| 272 | -- end |
| 273 | }, |
| 274 | |
| 275 | -- Default builtin filters. |
| 276 | -- (meant to get applied always, but you could override them) |
| 277 | cycle_filters = { |
| 278 | function(c, source_c) return not c.minimized end, --luacheck: no unused args |
| 279 | }, |
| 280 | |
| 281 | -- Experimental: Width of icon column ("max_icon_size", used for margin). |
| 282 | -- This could be "margin" etc instead, but currently only the width for the |
| 283 | -- current entry is known. |
| 284 | icon_col_width = dpi(36), |
| 285 | |
| 286 | -- EXPERIMENTAL: only add clients to the history that have been focused by |
| 287 | -- cyclefocus. |
| 288 | -- This allows to switch clients using other methods, but those are then |
| 289 | -- not added to cyclefocus' internal history. |
| 290 | -- The get_next_client function will then first consider the most recent |
| 291 | -- entry in the history stack, if it's not focused currently. |
| 292 | -- |
| 293 | -- You can use cyclefocus.history.add to manually add an entry, or |
| 294 | -- cyclefocus.history.append if you want to add it to the end of the stack. |
| 295 | -- This might be useful in a request::activate signal handler. |
| 296 | -- only_add_internal_focus_changes_to_history = true, |
| 297 | |
| 298 | -- The filter to ignore clients altogether (get not added to the history stack). |
| 299 | -- This is different from the cycle_filters. |
| 300 | -- The function should return true / the client if it's ok, nil otherwise. |
| 301 | filter_focus_history = awful.client.focus.filter, |
| 302 | |
| 303 | -- Display notifications while cycling? |
| 304 | -- WARNING: without raise_clients this will not make sense probably! |
| 305 | display_notifications = true, |
| 306 | |
| 307 | -- Debugging: messages get printed, and should show up in ~/.xsession-errors etc. |
| 308 | -- 1: enable, 2: verbose, 3: very verbose, 4: much verbose. |
| 309 | debug_level = 0, |
| 310 | -- Use naughty notifications for debugging (additional to printing)? |
| 311 | debug_use_naughty_notify = false, |
| 312 | } |
| 313 | ``` |
| 314 | |
| 315 | You can change them like this: |
| 316 | ```lua |
| 317 | cyclefocus = require("cyclefocus") |
| 318 | cyclefocus.debug_level = 2 |
| 319 | ``` |
| 320 | |
| 321 | You can also use custom settings when calling `cyclefocus.cycle` or |
| 322 | `cyclefocus.key` via `args`, e.g. to not display notifications when switching |
| 323 | between clients on the same tag: |
| 324 | ```lua |
| 325 | cyclefocus.key({ modkey, }, "Tab", 1, { |
| 326 | cycle_filters = { cyclefocus.filters.common_tag }, |
| 327 | display_notifications = false, |
| 328 | modifier='Super_L', keys={'Tab', 'ISO_Left_Tab'} |
| 329 | }), |
| 330 | cyclefocus.key({ modkey, "Shift", }, "Tab", 1, { |
| 331 | cycle_filters = { cyclefocus.filters.common_tag }, |
| 332 | display_notifications = false, |
| 333 | modifier='Super_L', keys={'Tab', 'ISO_Left_Tab'} |
| 334 | }), |
| 335 | ``` |
| 336 | |
| 337 | ## Status |
| 338 | |
| 339 | Stable: it works well for me and others. |
| 340 | Internals, default settings and behavior might still change. |
| 341 | |
| 342 | I came up with this while dipping my toes in the waters of awesome. If you have |
| 343 | problems, please enable `cyclefocus.debug_level` (goes up to 3) and report your |
| 344 | findings on the [Github issue tracker][]. |
| 345 | |
| 346 | # Bugs, Feedback and Support |
| 347 | |
| 348 | You can report bugs and wishes at the [Github issue tracker][]. |
| 349 | |
| 350 | Pull requests would be awesome! :) |
| 351 | |
| 352 | ## Donate |
| 353 | |
| 354 | [](https://flattr.com/submit/auto?user_id=blueyed&url=https://github.com/blueyed/awesome-cyclefocus&title=awesome-cyclefocus&language=en&tags=github&category=software) |
| 355 | |
| 356 | Bitcoin: 16EVhEpXxfNiT93qT2uxo4DsZSHzNdysSp |
| 357 | |
| 358 | [awesome window manager]: http://awesome.naquadah.org/ |
| 359 | [Github issue tracker]: https://github.com/blueyed/awesome-cyclefocus/issues |