diff options
author | Mike Crute <mike@crute.us> | 2019-02-03 15:03:51 -0800 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2019-02-03 15:03:51 -0800 |
commit | 052e50f8c232e284fc6b9d194d0673b28ed5387c (patch) | |
tree | 7059856e07f837a6b9aa8a2eebdbb81018aeb788 /.config | |
parent | 6065e2d2bef6424c23f41b28ec22029dfed1c841 (diff) | |
download | dotfiles-052e50f8c232e284fc6b9d194d0673b28ed5387c.tar.bz2 dotfiles-052e50f8c232e284fc6b9d194d0673b28ed5387c.tar.xz dotfiles-052e50f8c232e284fc6b9d194d0673b28ed5387c.zip |
Move zooming and display mgmt to awesome
Diffstat (limited to '.config')
-rw-r--r-- | .config/awesome/mcrute.lua | 173 |
1 files changed, 161 insertions, 12 deletions
diff --git a/.config/awesome/mcrute.lua b/.config/awesome/mcrute.lua index 2cf2071..62b83ae 100644 --- a/.config/awesome/mcrute.lua +++ b/.config/awesome/mcrute.lua | |||
@@ -10,6 +10,32 @@ local wibox = require("wibox") | |||
10 | 10 | ||
11 | local timezone = "America/Los_Angeles" | 11 | local timezone = "America/Los_Angeles" |
12 | 12 | ||
13 | -- Good clear zoom stops for the Dell XPS 13 93{7,8}0 | ||
14 | local edp_zoom_modes = { | ||
15 | -- "2560x1440", | ||
16 | "2048x1152", | ||
17 | "1920x1080", | ||
18 | "1600x900", | ||
19 | "1368x768", | ||
20 | "1280x720", | ||
21 | "1024x576", | ||
22 | "960x540", | ||
23 | "864x486", | ||
24 | "720x405", | ||
25 | "640x360", | ||
26 | } | ||
27 | |||
28 | -- Good clear daily driver modes for the Dell XPS 13 93{7,8}0 | ||
29 | local edp_display_modes = { | ||
30 | "1600x900", | ||
31 | "1920x1080", | ||
32 | "2048x1152", | ||
33 | "2880x1620", | ||
34 | } | ||
35 | |||
36 | -- Preferred daily driver mode for the Dell XPS 13 93{7,8}0 | ||
37 | local default_edp_mode = edp_display_modes[3] | ||
38 | |||
13 | function dump(o) | 39 | function dump(o) |
14 | if type(o) == 'table' then | 40 | if type(o) == 'table' then |
15 | local s = '{ ' | 41 | local s = '{ ' |
@@ -23,6 +49,17 @@ function dump(o) | |||
23 | end | 49 | end |
24 | end | 50 | end |
25 | 51 | ||
52 | function string_split(s, delimiter) | ||
53 | if s == nil then | ||
54 | return nil | ||
55 | end | ||
56 | local result = {} | ||
57 | for match in (s..delimiter):gmatch("(.-)"..delimiter) do | ||
58 | table.insert(result, match) | ||
59 | end | ||
60 | return result | ||
61 | end | ||
62 | |||
26 | -- TODO: figure out how to notify when below 5% | 63 | -- TODO: figure out how to notify when below 5% |
27 | function battery_low_warning() | 64 | function battery_low_warning() |
28 | naughty.notify({ preset = naughty.config.presets.critical, | 65 | naughty.notify({ preset = naughty.config.presets.critical, |
@@ -125,9 +162,10 @@ end | |||
125 | 162 | ||
126 | function setup_device_handling() | 163 | function setup_device_handling() |
127 | -- Refresh screen config when monitors are plugged and unplugged | 164 | -- Refresh screen config when monitors are plugged and unplugged |
128 | awesome.connect_signal("screen::change", function() | 165 | awesome.connect_signal("screen::change", configure_displays) |
129 | awful.spawn.with_shell("$HOME/bin/setup-desktop.sh") | 166 | end |
130 | end) | 167 | |
168 | function setup_screens() | ||
131 | end | 169 | end |
132 | 170 | ||
133 | function set_solid_wallpaper(s) | 171 | function set_solid_wallpaper(s) |
@@ -203,6 +241,52 @@ function move_mouse_top_right() | |||
203 | }) | 241 | }) |
204 | end | 242 | end |
205 | 243 | ||
244 | function zoom_screen(zoom_stop) | ||
245 | local mode = default_edp_mode | ||
246 | local panning = "0x0" | ||
247 | |||
248 | zoom_stop = tonumber(zoom_stop) or 0 | ||
249 | if zoom_stop > #edp_zoom_modes then | ||
250 | zoom_stop = #edp_zoom_modes | ||
251 | end | ||
252 | |||
253 | print(zoom_stop) | ||
254 | print(mode) | ||
255 | |||
256 | if zoom_stop ~= 0 then | ||
257 | mode = edp_zoom_modes[zoom_stop] | ||
258 | panning = default_edp_mode | ||
259 | end | ||
260 | |||
261 | awful.util.spawn("xrandr --output eDP-1 --mode " .. mode .. " --panning " .. panning) | ||
262 | end | ||
263 | |||
264 | local current_zoom_stop = 0 | ||
265 | |||
266 | function zoom_screen_up() | ||
267 | if current_zoom_stop == #edp_zoom_modes then | ||
268 | current_zoom_stop = #edp_zoom_modes | ||
269 | else | ||
270 | current_zoom_stop = current_zoom_stop + 1 | ||
271 | end | ||
272 | |||
273 | zoom_screen(current_zoom_stop) | ||
274 | end | ||
275 | |||
276 | function zoom_screen_down() | ||
277 | if current_zoom_stop == 0 then | ||
278 | zoom_screen(0) | ||
279 | else | ||
280 | current_zoom_stop = current_zoom_stop - 1 | ||
281 | zoom_screen(current_zoom_stop) | ||
282 | end | ||
283 | end | ||
284 | |||
285 | function zoom_screen_reset() | ||
286 | current_zoom_stop = 0 | ||
287 | zoom_screen(current_zoom_stop) | ||
288 | end | ||
289 | |||
206 | function add_global_keys(globalkeys) | 290 | function add_global_keys(globalkeys) |
207 | light = os.getenv("HOME") .. "/.local/bin/light" | 291 | light = os.getenv("HOME") .. "/.local/bin/light" |
208 | if not gears.filesystem.file_readable(light) then | 292 | if not gears.filesystem.file_readable(light) then |
@@ -245,7 +329,10 @@ function add_global_keys(globalkeys) | |||
245 | 329 | ||
246 | -- Other useful commands | 330 | -- Other useful commands |
247 | awful.key({ "Control", "Shift" }, "`", make_spawn("xscreensaver-command -lock")), | 331 | awful.key({ "Control", "Shift" }, "`", make_spawn("xscreensaver-command -lock")), |
248 | awful.key({ modkey, "Shift" }, "p", move_mouse_top_right) | 332 | awful.key({ modkey, "Shift" }, "p", move_mouse_top_right), |
333 | awful.key({ modkey }, "z", zoom_screen_up), | ||
334 | awful.key({ modkey }, "-", zoom_screen_down), | ||
335 | awful.key({ modkey }, "=", zoom_screen_reset) | ||
249 | ) | 336 | ) |
250 | end | 337 | end |
251 | 338 | ||
@@ -296,17 +383,79 @@ function pomodoro() | |||
296 | } | 383 | } |
297 | end | 384 | end |
298 | 385 | ||
386 | function default_display_handler(card, edp_mode) | ||
387 | awful.util.spawn("xrandr --output eDP-1 --mode ".. edp_mode .. " --output " .. card .. " --auto --right-of eDP-1") | ||
388 | end | ||
389 | |||
390 | function get_displays() | ||
391 | local result = {} | ||
392 | local parts = nil | ||
393 | local outputs = nil | ||
394 | |||
395 | -- Do this first to ensure /sys is up-to-date | ||
396 | io.popen("xrandr -q"):close() | ||
397 | outputs = io.popen(os.getenv("HOME") .. "/bin/enumerate-displays") | ||
398 | |||
399 | while true do | ||
400 | parts = string_split(outputs:read("*l"), ":") | ||
401 | if parts == nil then | ||
402 | break | ||
403 | end | ||
404 | table.insert(result, { card = parts[1], edid = parts[2] }) | ||
405 | end | ||
406 | |||
407 | outputs:close() | ||
408 | return result | ||
409 | end | ||
410 | |||
411 | function configure_displays() | ||
412 | local displays = get_displays() | ||
413 | |||
414 | -- Only built-in display is connected | ||
415 | if #displays == 1 and displays[1].edid == "DELL_XPS_13" then | ||
416 | awful.util.spawn("xrandr " .. | ||
417 | "--output eDP-1 --mode " .. default_edp_mode .. " " .. | ||
418 | "--output DP-1 --off " .. | ||
419 | "--output DP-2 --off " .. | ||
420 | "--panning 0x0") | ||
421 | return | ||
422 | end | ||
423 | |||
424 | -- TODO: This should be a lot more intelliegent and a lot less hard coded | ||
425 | -- but it works for what I do so *shrug* | ||
426 | for _, s in pairs(displays) do | ||
427 | if s.edid == "DELL U2715H" then -- 27" Dell monitors | ||
428 | awful.util.spawn("xrandr " .. | ||
429 | "--output DP-1 --auto " .. | ||
430 | "--output DP-2 --auto --right-of DP-1 " .. | ||
431 | "--output eDP-1 --off") | ||
432 | return | ||
433 | elseif s.edid == "DELL U3415W" then -- 34" widescreen Dell monitors | ||
434 | awful.util.spawn("xrandr --output " .. s.card .. " --auto --output eDP-1 --off") | ||
435 | return | ||
436 | elseif s.edid == "DELL_XPS_13" then -- Built-in display | ||
437 | -- continue | ||
438 | else | ||
439 | default_display_handler(s.card, default_edp_mode) | ||
440 | return | ||
441 | end | ||
442 | end | ||
443 | end | ||
444 | |||
299 | return { | 445 | return { |
300 | dump = dump, | ||
301 | setup_device_handling = setup_device_handling, | ||
302 | set_solid_wallpaper = set_solid_wallpaper, | ||
303 | customize_theme = customize_theme, | ||
304 | start_desktop_target = start_desktop_target, | ||
305 | add_window_rules = add_window_rules, | ||
306 | add_global_keys = add_global_keys, | 446 | add_global_keys = add_global_keys, |
307 | get_layouts = get_layouts, | 447 | add_window_rules = add_window_rules, |
308 | battery_low_warning = battery_low_warning, | 448 | battery_low_warning = battery_low_warning, |
309 | split_screen = split_screen, | 449 | configure_displays = configure_displays, |
450 | customize_theme = customize_theme, | ||
451 | dump = dump, | ||
310 | get_clock = get_clock, | 452 | get_clock = get_clock, |
453 | get_displays = get_displays, | ||
454 | get_layouts = get_layouts, | ||
311 | pomodoro = pomodoro, | 455 | pomodoro = pomodoro, |
456 | set_solid_wallpaper = set_solid_wallpaper, | ||
457 | setup_device_handling = setup_device_handling, | ||
458 | split_screen = split_screen, | ||
459 | start_desktop_target = start_desktop_target, | ||
460 | zoom_screen = zoom_screen, | ||
312 | } | 461 | } |