diff options
author | Mike Crute <mike@crute.us> | 2019-02-03 17:48:14 -0800 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2019-02-03 17:48:14 -0800 |
commit | ca4b3a1daec801dcbd03150ba40d93f753718150 (patch) | |
tree | 97f1a8ec85b6da8862c55aa34277b1c248f0134e /.config | |
parent | 03471fed1493ce16adc46f58c32fad3aa0e6b661 (diff) | |
download | dotfiles-ca4b3a1daec801dcbd03150ba40d93f753718150.tar.bz2 dotfiles-ca4b3a1daec801dcbd03150ba40d93f753718150.tar.xz dotfiles-ca4b3a1daec801dcbd03150ba40d93f753718150.zip |
Add documentation to mcrute.lua
Diffstat (limited to '.config')
-rw-r--r-- | .config/awesome/mcrute.lua | 201 | ||||
-rw-r--r-- | .config/awesome/rc.lua | 4 |
2 files changed, 146 insertions, 59 deletions
diff --git a/.config/awesome/mcrute.lua b/.config/awesome/mcrute.lua index f0a9bcd..b922b39 100644 --- a/.config/awesome/mcrute.lua +++ b/.config/awesome/mcrute.lua | |||
@@ -1,6 +1,19 @@ | |||
1 | local ipairs = ipairs | 1 | -- AwesomeWM Customizations |
2 | local math = math | 2 | -- by Mike Crute <mike@crute.us> |
3 | 3 | -- | |
4 | -- This file contains the customizations that I run for AwesomeWM. I prefer to | ||
5 | -- stick as close to the stock rc.lua file as possible so it's easier to | ||
6 | -- upgrade. Over time awesome has had a habit of making drastic | ||
7 | -- non-backwards-compatible changes to that file. | ||
8 | -- | ||
9 | -- To understand some parts of this file it's useful to understand my runtime | ||
10 | -- environment; I run both Fedora and Ubuntu depending on the context but | ||
11 | -- always on a Dell XPS 13 (9370 and 9380). I don't run a traditional desktop | ||
12 | -- environment nor do I run a settings daemon as they tend to be overly bloated | ||
13 | -- and do much more than I care for so Awesome tends to subsume the important | ||
14 | -- tasks (like display configuration) instead. I do depend heavily on systemd | ||
15 | -- for user session task management. | ||
16 | -- | ||
4 | local awful = require("awful") | 17 | local awful = require("awful") |
5 | local beautiful = require("beautiful") | 18 | local beautiful = require("beautiful") |
6 | local dpi = require("beautiful.xresources").apply_dpi | 19 | local dpi = require("beautiful.xresources").apply_dpi |
@@ -8,11 +21,17 @@ local gears = require("gears") | |||
8 | local naughty = require("naughty") | 21 | local naughty = require("naughty") |
9 | local wibox = require("wibox") | 22 | local wibox = require("wibox") |
10 | 23 | ||
24 | -- Require this here because we customize it here but also so rc.lua can use it | ||
25 | -- transitively through this module. It makes our local customizations to | ||
26 | -- rc.lua just a little easier to grep for. | ||
27 | local battery = require("battery") | ||
28 | |||
11 | local timezone = "America/Los_Angeles" | 29 | local timezone = "America/Los_Angeles" |
12 | 30 | ||
13 | -- Good clear zoom stops for the Dell XPS 13 93{7,8}0 | 31 | -- Good clear zoom stops for the Dell XPS 13 93{7,8}0 |
14 | local edp_zoom_modes = { | 32 | local edp_zoom_modes = { |
15 | -- "2560x1440", | 33 | -- "2880x1620", |
34 | -- "2560x1440", | ||
16 | "2048x1152", | 35 | "2048x1152", |
17 | "1920x1080", | 36 | "1920x1080", |
18 | "1600x900", | 37 | "1600x900", |
@@ -30,12 +49,14 @@ local edp_display_modes = { | |||
30 | "1600x900", | 49 | "1600x900", |
31 | "1920x1080", | 50 | "1920x1080", |
32 | "2048x1152", | 51 | "2048x1152", |
52 | "2560x1440", | ||
33 | "2880x1620", | 53 | "2880x1620", |
34 | } | 54 | } |
35 | 55 | ||
36 | -- Preferred daily driver mode for the Dell XPS 13 93{7,8}0 | 56 | -- Preferred daily driver mode for the Dell XPS 13 93{7,8}0 |
37 | local default_edp_mode = edp_display_modes[3] | 57 | local default_edp_mode = edp_display_modes[3] |
38 | 58 | ||
59 | -- dumps is a debugging tool that prints text representations of lua objects | ||
39 | function dump(o) | 60 | function dump(o) |
40 | if type(o) == 'table' then | 61 | if type(o) == 'table' then |
41 | local s = '{ ' | 62 | local s = '{ ' |
@@ -49,6 +70,7 @@ function dump(o) | |||
49 | end | 70 | end |
50 | end | 71 | end |
51 | 72 | ||
73 | -- string_split splits strings on a delimiter and returns a table of the parts | ||
52 | function string_split(s, delimiter) | 74 | function string_split(s, delimiter) |
53 | if s == nil then | 75 | if s == nil then |
54 | return nil | 76 | return nil |
@@ -60,9 +82,23 @@ function string_split(s, delimiter) | |||
60 | return result | 82 | return result |
61 | end | 83 | end |
62 | 84 | ||
85 | -- | ||
86 | -- Low Battery Warning | ||
87 | -- | ||
63 | local battery_warning_delivered = false | 88 | local battery_warning_delivered = false |
64 | 89 | ||
65 | require("battery").status_callback = function(bat) | 90 | -- Connects a battery status callback to the custom battery widget code. This |
91 | -- gets called each time the status bar polls for battery status and is | ||
92 | -- responsible for displaying a very prominent notification when the battery is | ||
93 | -- running too low. It will display the warning once at 10% and then every | ||
94 | -- polling interval at 5% and below. Below 5% the Dell battery drains much more | ||
95 | -- rapidly than above that level and there's a chance it will either suspend or | ||
96 | -- shut down (losing work in the case of the later). | ||
97 | -- | ||
98 | -- This exists because I prefer to run my battery nearly to empty and then | ||
99 | -- charge it to avoid excess wear on the battery. But I'd prefer to not lose | ||
100 | -- work or be inconvenienced by a poorly timed suspend. | ||
101 | battery.status_callback = function(bat) | ||
66 | local should_warn = bat.charge <= 10 and (bat.status == 'discharging' or bat.status == 'not connected') | 102 | local should_warn = bat.charge <= 10 and (bat.status == 'discharging' or bat.status == 'not connected') |
67 | local be_persistent = bat.charge <= 5 and (bat.status == 'discharging' or bat.status == 'not connected') | 103 | local be_persistent = bat.charge <= 5 and (bat.status == 'discharging' or bat.status == 'not connected') |
68 | 104 | ||
@@ -89,7 +125,8 @@ require("battery").status_callback = function(bat) | |||
89 | end | 125 | end |
90 | end | 126 | end |
91 | 127 | ||
92 | -- TODO: | 128 | -- TODO: Migrate tags from removed screen to free tags on remaining screens |
129 | -- | ||
93 | -- https://www.reddit.com/r/awesomewm/comments/5r9mgu | 130 | -- https://www.reddit.com/r/awesomewm/comments/5r9mgu |
94 | -- https://stackoverflow.com/questions/42056795 | 131 | -- https://stackoverflow.com/questions/42056795 |
95 | function handle_tag_removal(tag) | 132 | function handle_tag_removal(tag) |
@@ -113,7 +150,7 @@ function handle_tag_removal(tag) | |||
113 | end | 150 | end |
114 | 151 | ||
115 | -- TODO: Allow mouse resizing | 152 | -- TODO: Allow mouse resizing |
116 | -- Copy of suit.fair that forces rows to 1 | 153 | -- Copy of suit.fair that forces rows or columns to one |
117 | local function do_equal(p, orientation) | 154 | local function do_equal(p, orientation) |
118 | local wa = p.workarea | 155 | local wa = p.workarea |
119 | local cls = p.clients | 156 | local cls = p.clients |
@@ -181,37 +218,38 @@ local function do_equal(p, orientation) | |||
181 | end | 218 | end |
182 | end | 219 | end |
183 | 220 | ||
221 | -- setup_device_handling configures callbacks that need to be run when | ||
222 | -- something changes about the system. This used to connect some dbus events to | ||
223 | -- configure keyboards and mice but just does display management now. | ||
184 | function setup_device_handling() | 224 | function setup_device_handling() |
185 | -- Refresh screen config when monitors are plugged and unplugged | ||
186 | awesome.connect_signal("screen::change", configure_displays) | 225 | awesome.connect_signal("screen::change", configure_displays) |
187 | end | 226 | end |
188 | 227 | ||
189 | function setup_screens() | 228 | -- set_solid_wallpaper sets the gears wallpaper to a solid color as defined in |
190 | end | 229 | -- beautiful.bg_normal |
191 | |||
192 | function set_solid_wallpaper(s) | 230 | function set_solid_wallpaper(s) |
193 | wallpaper = gears.color.create_solid_pattern(beautiful.bg_normal) | 231 | wallpaper = gears.color.create_solid_pattern(beautiful.bg_normal) |
194 | gears.wallpaper.set(wallpaper) | 232 | gears.wallpaper.set(wallpaper) |
195 | end | 233 | end |
196 | 234 | ||
235 | -- customize_theme applies additional customizations on the beautiful theme | ||
236 | -- after it has been setup by rc.lua | ||
197 | function customize_theme() | 237 | function customize_theme() |
198 | beautiful.bg_urgent = "#222222" | 238 | beautiful.bg_urgent = "#222222" |
199 | beautiful.border_width = dpi(0) | 239 | beautiful.border_width = dpi(0) |
200 | 240 | ||
201 | wallpaper_path_1 = gears.filesystem.get_dir("config") .. "tux-minimal-bg.png" | 241 | -- Setup the wallpaper if it exists |
202 | wallpaper_path_2 = os.getenv("HOME") .. "/Documents/personal/tux-minimal-bg.png" | 242 | wallpaper_path = gears.filesystem.get_dir("config") .. "tux-minimal-bg.png" |
203 | 243 | if gears.filesystem.file_readable(wallpaper_path) then | |
204 | if gears.filesystem.file_readable(wallpaper_path_1) then | 244 | beautiful.wallpaper = wallpaper_path |
205 | beautiful.wallpaper = wallpaper_path_1 | ||
206 | elseif gears.filesystem.file_readable(wallpaper_path_1) then | ||
207 | beautiful.wallpaper = wallpaper_path_2 | ||
208 | end | 245 | end |
209 | 246 | ||
247 | -- Setup custom icons for the custom equal layout in this file | ||
210 | beautiful.layout_equalv = gears.filesystem.get_dir("config") .. "icons/equalvw.png" | 248 | beautiful.layout_equalv = gears.filesystem.get_dir("config") .. "icons/equalvw.png" |
211 | beautiful.layout_equalh = gears.filesystem.get_dir("config") .. "icons/equalhw.png" | 249 | beautiful.layout_equalh = gears.filesystem.get_dir("config") .. "icons/equalhw.png" |
212 | 250 | ||
251 | -- Use a prettier icon theme if possible | ||
213 | icon_theme_dir = "/usr/share/icons/Adwaita/" | 252 | icon_theme_dir = "/usr/share/icons/Adwaita/" |
214 | |||
215 | if gears.filesystem.dir_readable(icon_theme_dir) then | 253 | if gears.filesystem.dir_readable(icon_theme_dir) then |
216 | naughty.config.icon_dirs = gears.table.join(naughty.config.icon_dirs, { | 254 | naughty.config.icon_dirs = gears.table.join(naughty.config.icon_dirs, { |
217 | icon_theme_dir | 255 | icon_theme_dir |
@@ -219,17 +257,27 @@ function customize_theme() | |||
219 | end | 257 | end |
220 | end | 258 | end |
221 | 259 | ||
260 | -- start_desktop_target calls systemd to startup all the processes in the user | ||
261 | -- session and hooks the quit function to properly shutdown systemd when | ||
262 | -- awesome quits. This starts a desktop.target in the user mode systemd which | ||
263 | -- can pull in widgets and anything else that enhances the desktop environment. | ||
222 | function start_desktop_target() | 264 | function start_desktop_target() |
223 | awful.spawn.spawn("systemctl --user start desktop.target") | 265 | awful.spawn.spawn("systemctl --user start desktop.target") |
224 | 266 | ||
225 | awesome._awesome_quit = awesome.quit | 267 | -- Only do this once in case awesome gets reloaded |
226 | awesome.quit = function() | 268 | if not awesome._awesome_quit then |
227 | awful.spawn.spawn("systemctl --user --wait stop desktop.target") | 269 | awesome._awesome_quit = awesome.quit |
228 | awesome._awesome_quit() | 270 | awesome.quit = function() |
271 | -- The use of io.popen here is intentional because it will block until | ||
272 | -- systemd has finished stopping the target | ||
273 | io.popen("systemctl --user --wait stop desktop.target") | ||
274 | awesome._awesome_quit() | ||
275 | end | ||
229 | end | 276 | end |
230 | end | 277 | end |
231 | 278 | ||
232 | -- mcrute: use xprop to get this info | 279 | -- add_window_rules mixes additional window rules into awful.rules.rules. To |
280 | -- gather the information needed here use the xprop tool. | ||
233 | function add_window_rules() | 281 | function add_window_rules() |
234 | awful.rules.rules = gears.table.join(awful.rules.rules, { | 282 | awful.rules.rules = gears.table.join(awful.rules.rules, { |
235 | { rule_any = { | 283 | { rule_any = { |
@@ -248,10 +296,9 @@ function add_window_rules() | |||
248 | }) | 296 | }) |
249 | end | 297 | end |
250 | 298 | ||
251 | function make_spawn(cmd) | 299 | -- move_mouse_top_right moves the mouse out of the way to the top right corner |
252 | return function() awful.util.spawn(cmd) end | 300 | -- of the screen but avoids overlapping the layout picker because that displays |
253 | end | 301 | -- a tooltip. |
254 | |||
255 | function move_mouse_top_right() | 302 | function move_mouse_top_right() |
256 | local mg = screen[mouse.screen].geometry | 303 | local mg = screen[mouse.screen].geometry |
257 | 304 | ||
@@ -262,6 +309,12 @@ function move_mouse_top_right() | |||
262 | }) | 309 | }) |
263 | end | 310 | end |
264 | 311 | ||
312 | -- zoom_screen uses xrandr to enable a lower resolution display mode and | ||
313 | -- panning, mimicking at some level, the control scroll-wheel zooming that Mac | ||
314 | -- OS is capable of. | ||
315 | -- | ||
316 | -- This only works with the built-in display and not at all with external | ||
317 | -- displays. | ||
265 | function zoom_screen(zoom_stop) | 318 | function zoom_screen(zoom_stop) |
266 | local mode = default_edp_mode | 319 | local mode = default_edp_mode |
267 | local panning = "0x0" | 320 | local panning = "0x0" |
@@ -282,8 +335,13 @@ function zoom_screen(zoom_stop) | |||
282 | awful.util.spawn("xrandr --output eDP-1 --mode " .. mode .. " --panning " .. panning) | 335 | awful.util.spawn("xrandr --output eDP-1 --mode " .. mode .. " --panning " .. panning) |
283 | end | 336 | end |
284 | 337 | ||
338 | -- | ||
339 | -- Session-persistent Zooming Support | ||
340 | -- | ||
285 | local current_zoom_stop = 0 | 341 | local current_zoom_stop = 0 |
286 | 342 | ||
343 | -- zoom_screen_up is a shortcut for zooming up using zoom stops that work | ||
344 | -- correctly with the display | ||
287 | function zoom_screen_up() | 345 | function zoom_screen_up() |
288 | if current_zoom_stop == #edp_zoom_modes then | 346 | if current_zoom_stop == #edp_zoom_modes then |
289 | current_zoom_stop = #edp_zoom_modes | 347 | current_zoom_stop = #edp_zoom_modes |
@@ -294,6 +352,8 @@ function zoom_screen_up() | |||
294 | zoom_screen(current_zoom_stop) | 352 | zoom_screen(current_zoom_stop) |
295 | end | 353 | end |
296 | 354 | ||
355 | -- zoom_screen_down is a shortcut for zooming down the screen using zoom stops | ||
356 | -- that work correctly with the display | ||
297 | function zoom_screen_down() | 357 | function zoom_screen_down() |
298 | if current_zoom_stop == 0 then | 358 | if current_zoom_stop == 0 then |
299 | zoom_screen(0) | 359 | zoom_screen(0) |
@@ -303,12 +363,23 @@ function zoom_screen_down() | |||
303 | end | 363 | end |
304 | end | 364 | end |
305 | 365 | ||
366 | -- zoom_screen_reset resets the zooming of the screen and disables panning | ||
306 | function zoom_screen_reset() | 367 | function zoom_screen_reset() |
307 | current_zoom_stop = 0 | 368 | current_zoom_stop = 0 |
308 | zoom_screen(current_zoom_stop) | 369 | zoom_screen(current_zoom_stop) |
309 | end | 370 | end |
310 | 371 | ||
372 | -- make_spawn is a shortcut for generating awful.util.spawn closures and allows | ||
373 | -- using this shorthand in other places in this file. | ||
374 | function make_spawn(cmd) | ||
375 | return function() awful.util.spawn(cmd) end | ||
376 | end | ||
377 | |||
378 | -- add_global_keys adds additional key bindings to the root key map. More | ||
379 | -- specific documentation is inline with the function. | ||
311 | function add_global_keys(globalkeys) | 380 | function add_global_keys(globalkeys) |
381 | -- On Fedora this is installed with dnf; Ubuntu as of 18.04 doesn't package | ||
382 | -- light so it's built locally there. | ||
312 | light = os.getenv("HOME") .. "/.local/bin/light" | 383 | light = os.getenv("HOME") .. "/.local/bin/light" |
313 | if not gears.filesystem.file_readable(light) then | 384 | if not gears.filesystem.file_readable(light) then |
314 | light = "light" | 385 | light = "light" |
@@ -322,6 +393,8 @@ function add_global_keys(globalkeys) | |||
322 | awful.key({ }, "XF86AudioMicMute", make_spawn("/usr/bin/pactl set-source-mute @DEFAULT_SOURCE@ toggle")), | 393 | awful.key({ }, "XF86AudioMicMute", make_spawn("/usr/bin/pactl set-source-mute @DEFAULT_SOURCE@ toggle")), |
323 | 394 | ||
324 | -- Audio Controls for Spotify | 395 | -- Audio Controls for Spotify |
396 | -- TODO: Make this work with rhythmbox and other stuff. Maybe not | ||
397 | -- needed at all if we can use some generic dbus functionality? | ||
325 | awful.key({ }, "XF86AudioPrev", make_spawn("dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous")), | 398 | awful.key({ }, "XF86AudioPrev", make_spawn("dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous")), |
326 | awful.key({ }, "XF86AudioPlay", make_spawn("dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause")), | 399 | awful.key({ }, "XF86AudioPlay", make_spawn("dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause")), |
327 | awful.key({ }, "XF86AudioNext", make_spawn("dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next")), | 400 | awful.key({ }, "XF86AudioNext", make_spawn("dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next")), |
@@ -332,31 +405,18 @@ function add_global_keys(globalkeys) | |||
332 | awful.key({ }, "XF86MonBrightnessUp", make_spawn(light .. " -A 5")), | 405 | awful.key({ }, "XF86MonBrightnessUp", make_spawn(light .. " -A 5")), |
333 | awful.key({ }, "XF86MonBrightnessDown", make_spawn(light .. " -U 5")), | 406 | awful.key({ }, "XF86MonBrightnessDown", make_spawn(light .. " -U 5")), |
334 | 407 | ||
335 | -- Suspend and Hibernate for Mac Keyboard | 408 | -- Screen Zooming Commands |
336 | awful.key({ modkey, "Control" }, "XF86Eject", make_spawn("/usr/bin/sudo /bin/systemctl hibernate")), | 409 | awful.key({ modkey }, "z", zoom_screen_up), |
337 | awful.key({ modkey, "Shift" }, "XF86Eject", make_spawn("/usr/bin/sudo /bin/systemctl hybrid-sleep")), | 410 | awful.key({ modkey }, "-", zoom_screen_down), |
338 | 411 | awful.key({ modkey }, "=", zoom_screen_reset), | |
339 | -- Suspend and Hibernate for unpatched Mac Keyboard | ||
340 | awful.key({ modkey, "Control" }, "F12", make_spawn("/usr/bin/sudo /bin/systemctl hibernate")), | ||
341 | awful.key({ modkey, "Shift" }, "F12", make_spawn("/usr/bin/sudo /bin/systemctl hybrid-sleep")), | ||
342 | |||
343 | -- Hack for unpatched Mac Keyboard | ||
344 | -- awful.key({ modkey, }, "F7", make_spawn("dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous")), | ||
345 | -- awful.key({ modkey, }, "F8", make_spawn("dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause")), | ||
346 | -- awful.key({ modkey, }, "F9", make_spawn("dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next")), | ||
347 | -- awful.key({ modkey, }, "F10", make_spawn("/usr/bin/pactl set-sink-mute @DEFAULT_SINK@ toggle")), | ||
348 | -- awful.key({ modkey, }, "F11", make_spawn("/usr/bin/pactl set-sink-volume @DEFAULT_SINK@ '-5%'")), | ||
349 | -- awful.key({ modkey, }, "F12", make_spawn("/usr/bin/pactl set-sink-volume @DEFAULT_SINK@ '+5%'")), | ||
350 | 412 | ||
351 | -- Other useful commands | 413 | -- Other useful commands |
352 | awful.key({ "Control", "Shift" }, "`", make_spawn("xscreensaver-command -lock")), | ||
353 | awful.key({ modkey, "Shift" }, "p", move_mouse_top_right), | 414 | awful.key({ modkey, "Shift" }, "p", move_mouse_top_right), |
354 | awful.key({ modkey }, "z", zoom_screen_up), | 415 | awful.key({ "Control", "Shift" }, "`", make_spawn("xscreensaver-command -lock")) |
355 | awful.key({ modkey }, "-", zoom_screen_down), | ||
356 | awful.key({ modkey }, "=", zoom_screen_reset) | ||
357 | ) | 416 | ) |
358 | end | 417 | end |
359 | 418 | ||
419 | -- get_layouts returns layouts to be used for awful.layout.layouts | ||
360 | function get_layouts() | 420 | function get_layouts() |
361 | return { | 421 | return { |
362 | awful.layout.suit.tile, | 422 | awful.layout.suit.tile, |
@@ -370,6 +430,10 @@ function get_layouts() | |||
370 | } | 430 | } |
371 | end | 431 | end |
372 | 432 | ||
433 | -- split_screen creates a virtual screen and splits the main screen in half. | ||
434 | -- This is mostly useful for the ultra-widescreen curved monitors. It makes | ||
435 | -- Awesome treat the monitor as containing two totally independent screens as | ||
436 | -- if it were two different monitors. | ||
373 | function split_screen(s) | 437 | function split_screen(s) |
374 | local geo = screen[s].geometry | 438 | local geo = screen[s].geometry |
375 | local new_width = math.ceil(geo.width/2) | 439 | local new_width = math.ceil(geo.width/2) |
@@ -379,10 +443,16 @@ function split_screen(s) | |||
379 | screen.fake_add(geo.x + new_width, geo.y, new_width2, geo.height) | 443 | screen.fake_add(geo.x + new_width, geo.y, new_width2, geo.height) |
380 | end | 444 | end |
381 | 445 | ||
446 | -- get_clock creates a textclock widget for the wibox. It's basically the | ||
447 | -- defaults but overrides the timezone to account for some oddities that I was | ||
448 | -- experiencing with Ubuntu when changing timezones. | ||
382 | function get_clock() | 449 | function get_clock() |
383 | return wibox.widget.textclock(" %a %b %d, %H:%M ", 60, timezone) | 450 | return wibox.widget.textclock(" %a %b %d, %H:%M ", 60, timezone) |
384 | end | 451 | end |
385 | 452 | ||
453 | -- pomodoro is a little pomodoro timer "app" that will show a notification on | ||
454 | -- all screens with a picture of a tomato after 25 minutes. It facilitates | ||
455 | -- using the pomodoro technique with nothing more than awesome. | ||
386 | function pomodoro() | 456 | function pomodoro() |
387 | local positions = {"bottom_right", "bottom_left", "bottom_right"} | 457 | local positions = {"bottom_right", "bottom_left", "bottom_right"} |
388 | 458 | ||
@@ -404,15 +474,26 @@ function pomodoro() | |||
404 | } | 474 | } |
405 | end | 475 | end |
406 | 476 | ||
477 | -- default_display_handler configures an output to use it's default xrandr mode | ||
478 | -- and position it to the right of the laptop built-in display. This should be | ||
479 | -- good enough for most screens. | ||
407 | function default_display_handler(card, edp_mode) | 480 | function default_display_handler(card, edp_mode) |
408 | awful.util.spawn("xrandr --output eDP-1 --mode ".. edp_mode .. " --output " .. card .. " --auto --right-of eDP-1") | 481 | awful.util.spawn("xrandr --output eDP-1 --mode ".. edp_mode .. " --output " .. card .. " --auto --right-of eDP-1") |
409 | end | 482 | end |
410 | 483 | ||
484 | -- get_displays uses a shell script helper (~/bin/enumerate-displays) to | ||
485 | -- retrieve a list of connected displays and their EDIDs. It will convert this | ||
486 | -- into a table and return it. | ||
487 | -- | ||
488 | -- The shell script exists mainly because Lua doesn't have any built-in ability | ||
489 | -- to list directories unless you compile a C extension (won't work with | ||
490 | -- awesome), use Glib (eww), or parse ls/find (error-prone). | ||
411 | function get_displays() | 491 | function get_displays() |
412 | local result = {} | 492 | local result = {} |
413 | local parts = nil | 493 | local parts = nil |
414 | local outputs = nil | 494 | local outputs = nil |
415 | 495 | ||
496 | -- TODO: Use the awful.spawn async functions | ||
416 | -- Do this first to ensure /sys is up-to-date | 497 | -- Do this first to ensure /sys is up-to-date |
417 | io.popen("xrandr -q"):close() | 498 | io.popen("xrandr -q"):close() |
418 | outputs = io.popen(os.getenv("HOME") .. "/bin/enumerate-displays") | 499 | outputs = io.popen(os.getenv("HOME") .. "/bin/enumerate-displays") |
@@ -429,6 +510,15 @@ function get_displays() | |||
429 | return result | 510 | return result |
430 | end | 511 | end |
431 | 512 | ||
513 | -- configure_displays uses xrandr to configure the displays connected to the | ||
514 | -- system when they are connected for removed. | ||
515 | -- | ||
516 | -- This would normally be done by a settings daemon but since I don't run one | ||
517 | -- we have to do it manually here. This function gets called as part of a | ||
518 | -- screen::change signal. | ||
519 | -- | ||
520 | -- TODO: This should be a lot more intelligent and a lot less hard coded but it | ||
521 | -- works for what I do so *shrug* | ||
432 | function configure_displays() | 522 | function configure_displays() |
433 | local displays = get_displays() | 523 | local displays = get_displays() |
434 | 524 | ||
@@ -442,8 +532,6 @@ function configure_displays() | |||
442 | return | 532 | return |
443 | end | 533 | end |
444 | 534 | ||
445 | -- TODO: This should be a lot more intelliegent and a lot less hard coded | ||
446 | -- but it works for what I do so *shrug* | ||
447 | for _, s in pairs(displays) do | 535 | for _, s in pairs(displays) do |
448 | if s.edid == "DELL U2715H" then -- 27" Dell monitors | 536 | if s.edid == "DELL U2715H" then -- 27" Dell monitors |
449 | awful.util.spawn("xrandr " .. | 537 | awful.util.spawn("xrandr " .. |
@@ -464,19 +552,18 @@ function configure_displays() | |||
464 | end | 552 | end |
465 | 553 | ||
466 | return { | 554 | return { |
555 | -- Public "API" used by rc.lua | ||
467 | add_global_keys = add_global_keys, | 556 | add_global_keys = add_global_keys, |
468 | add_window_rules = add_window_rules, | 557 | add_window_rules = add_window_rules, |
469 | battery_low_warning = battery_low_warning, | ||
470 | configure_displays = configure_displays, | ||
471 | customize_theme = customize_theme, | 558 | customize_theme = customize_theme, |
472 | dump = dump, | ||
473 | get_clock = get_clock, | 559 | get_clock = get_clock, |
474 | get_displays = get_displays, | ||
475 | get_layouts = get_layouts, | 560 | get_layouts = get_layouts, |
476 | pomodoro = pomodoro, | ||
477 | set_solid_wallpaper = set_solid_wallpaper, | ||
478 | setup_device_handling = setup_device_handling, | 561 | setup_device_handling = setup_device_handling, |
479 | split_screen = split_screen, | ||
480 | start_desktop_target = start_desktop_target, | 562 | start_desktop_target = start_desktop_target, |
481 | zoom_screen = zoom_screen, | 563 | battery = battery, |
564 | |||
565 | -- Public functions that are useful on import | ||
566 | configure_displays = configure_displays, | ||
567 | dump = dump, | ||
568 | pomodoro = pomodoro, | ||
482 | } | 569 | } |
diff --git a/.config/awesome/rc.lua b/.config/awesome/rc.lua index 18676e9..3577384 100644 --- a/.config/awesome/rc.lua +++ b/.config/awesome/rc.lua | |||
@@ -17,7 +17,7 @@ local hotkeys_popup = require("awful.hotkeys_popup").widget | |||
17 | -- Enable hotkeys help widget for VIM and other apps | 17 | -- Enable hotkeys help widget for VIM and other apps |
18 | -- when client with a matching name is opened: | 18 | -- when client with a matching name is opened: |
19 | require("awful.hotkeys_popup.keys") | 19 | require("awful.hotkeys_popup.keys") |
20 | local battery = require("battery") | 20 | -- See this file for more details about local customizations |
21 | local mcrute = require("mcrute") | 21 | local mcrute = require("mcrute") |
22 | 22 | ||
23 | mcrute.setup_device_handling() | 23 | mcrute.setup_device_handling() |
@@ -171,7 +171,7 @@ awful.screen.connect_for_each_screen(function(s) | |||
171 | { -- Right widgets | 171 | { -- Right widgets |
172 | layout = wibox.layout.fixed.horizontal, | 172 | layout = wibox.layout.fixed.horizontal, |
173 | wibox.widget.systray(), | 173 | wibox.widget.systray(), |
174 | battery(), | 174 | mcrute.battery(), |
175 | mytextclock, | 175 | mytextclock, |
176 | s.mylayoutbox, | 176 | s.mylayoutbox, |
177 | }, | 177 | }, |