From c613821410b0c3a49508c9f771e83eafe1a52ea2 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Fri, 14 Jun 2019 16:09:32 +0000 Subject: [PATCH] [awesome] add tearstop widget (and remove zsh alias for that) --- home/.config/awesome/icons/tearstop-off.png | Bin 0 -> 128 bytes home/.config/awesome/icons/tearstop-on.png | Bin 0 -> 128 bytes home/.config/awesome/rc.lua | 1 + home/.config/awesome/theme.lua | 5 ++-- home/.config/awesome/utils.lua | 12 +++++---- home/.config/awesome/widgets.lua | 27 +++++++++++++++++++- home/.zshrc.local | 1 - 7 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 home/.config/awesome/icons/tearstop-off.png create mode 100644 home/.config/awesome/icons/tearstop-on.png diff --git a/home/.config/awesome/icons/tearstop-off.png b/home/.config/awesome/icons/tearstop-off.png new file mode 100644 index 0000000000000000000000000000000000000000..2ca36eadc4786da2834c60f8b73d7edf4e252256 GIT binary patch literal 128 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh@3?y?HWJG`zTYyi9E0Dfpq@Nxtvl+-@ED7=p zW^j0RBMrn!@^*J&=wOxg0CJ=~T^vI=t|uoPV0!Z3(7bP0l+XkKB+4F) literal 0 HcmV?d00001 diff --git a/home/.config/awesome/icons/tearstop-on.png b/home/.config/awesome/icons/tearstop-on.png new file mode 100644 index 0000000000000000000000000000000000000000..709da04c795173334910ed78d9ee3ae38ceb62cd GIT binary patch literal 128 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh@3?y?HWJG`zTYyi9E0AuT$?!-j@H>#jSQ6wH z%;50sMjD8dgTe~DWM4fR3jfI literal 0 HcmV?d00001 diff --git a/home/.config/awesome/rc.lua b/home/.config/awesome/rc.lua index d0badcc..c2f2510 100644 --- a/home/.config/awesome/rc.lua +++ b/home/.config/awesome/rc.lua @@ -203,6 +203,7 @@ awful.screen.connect_for_each_screen(function(s) { -- Right widgets layout = wibox.layout.fixed.horizontal, wibox.widget.systray(), + widgets.tearstop, widgets.redshift, widgets.bluetooth, widgets.netdown_icon, diff --git a/home/.config/awesome/theme.lua b/home/.config/awesome/theme.lua index 06eef8c..3a65ed6 100644 --- a/home/.config/awesome/theme.lua +++ b/home/.config/awesome/theme.lua @@ -6,7 +6,8 @@ local gfs = require("gears.filesystem") local layout_icons_path = gfs.get_configuration_dir() .. "icons/layouts/" local spawn = require("awful.spawn") -local utils = require("../utils") +local utils = require("utils") +local helpers = require("lain.helpers") local theme = {} @@ -57,7 +58,7 @@ theme.hotkeys_description_font = "Iosevka sbruder 10" theme.hotkeys_modifiers_fg = theme.fg_normal theme.wallpaper = function(s) - if utils.file_exists(utils.home() .. ".fehbg") then + if helpers.file_exists(utils.home() .. ".fehbg") then spawn({utils.home() .. ".fehbg"}) end end diff --git a/home/.config/awesome/utils.lua b/home/.config/awesome/utils.lua index 7ed4ff3..dbd9989 100644 --- a/home/.config/awesome/utils.lua +++ b/home/.config/awesome/utils.lua @@ -1,12 +1,14 @@ -local utils = {} +local helpers = require("lain.helpers") -function utils.file_exists(name) - local f=io.open(name,"r") - if f~=nil then io.close(f) return true else return false end -end +local utils = {} function utils.home() return os.getenv("HOME") .. "/" end +function utils.handle_pid(command, callback) + helpers.async_with_shell(string.format("ps x -o pid=,command=|grep -E '^\\s*[0-9]* %s$'|sed 's/\\s*\\([0-9]*\\) .*/\\1/'", command), callback) +end + + return utils diff --git a/home/.config/awesome/widgets.lua b/home/.config/awesome/widgets.lua index 7e88f90..766c64c 100644 --- a/home/.config/awesome/widgets.lua +++ b/home/.config/awesome/widgets.lua @@ -7,6 +7,7 @@ local helpers = require("lain.helpers") local markup = lain.util.markup local theme = require("theme") +local utils = require("utils") local gfs = require("gears.filesystem") local iconsdir = gfs.get_configuration_dir() .. "icons/" @@ -112,7 +113,7 @@ helpers.newtimer("bluetooth", 10, widgets.bluetooth.update) widgets.redshift = wibox.widget.imagebox(iconsdir .. "redshift-on.png") widgets.redshift.pid = nil -helpers.async_with_shell("ps x -o pid=,command=|grep -E '^[0-9]* redshift$' |cut -d' ' -f 1", function(pid) +utils.handle_pid("redshift", function(pid) if pid and #pid > 0 then widgets.redshift.pid = tonumber(pid) else @@ -138,4 +139,28 @@ widgets.redshift:buttons( ) ) +widgets.tearstop = wibox.widget.imagebox(iconsdir .. "tearstop-off.png") +utils.handle_pid("compton --backend=glx", function(pid) + if pid and #pid > 0 then + widgets.tearstop.pid = tonumber(pid) + widgets.tearstop:set_image(iconsdir .. "tearstop-on.png") + end +end) +widgets.tearstop.pid = nil + +widgets.tearstop:buttons( + table.join( + awful.button({ }, 1, function() + if widgets.tearstop.pid == nil then + widgets.tearstop.pid = awful.spawn.spawn({ "compton", "--backend=glx" }) + widgets.tearstop:set_image(iconsdir .. "tearstop-on.png") + else + awful.spawn.spawn({ "kill", tostring(widgets.tearstop.pid) }) + widgets.tearstop.pid = nil + widgets.tearstop:set_image(iconsdir .. "tearstop-off.png") + end + end) + ) +) + return widgets diff --git a/home/.zshrc.local b/home/.zshrc.local index 94e7001..3b25e99 100644 --- a/home/.zshrc.local +++ b/home/.zshrc.local @@ -123,7 +123,6 @@ if which exa 2>&1 >> /dev/null;then fi alias ipy="ipython3" alias rls="/bin/ls --color=auto" -alias tearstop="compton --backend=glx" alias line="chromium --user-data-dir=$HOME/.line --app=chrome-extension://ophjlpahpchlmihnnnihgmmeilfjmjjc/index.html" ## Environment variables