From d269ba7a19b203ab11f2e434b51b7eff741b195f Mon Sep 17 00:00:00 2001 From: Augusto Gunsch Date: Sun, 23 Jan 2022 19:38:19 -0300 Subject: [PATCH] Add cmus widget --- config/awesome/cmus-widget/README.md | 93 +++++++++++++ config/awesome/cmus-widget/br-wid-1.png | Bin 0 -> 4912 bytes config/awesome/cmus-widget/brightness.svg | 153 ++++++++++++++++++++++ config/awesome/cmus-widget/cmus.lua | 112 ++++++++++++++++ config/awesome/rc.lua | 76 +++++++---- 5 files changed, 407 insertions(+), 27 deletions(-) create mode 100644 config/awesome/cmus-widget/README.md create mode 100644 config/awesome/cmus-widget/br-wid-1.png create mode 100644 config/awesome/cmus-widget/brightness.svg create mode 100644 config/awesome/cmus-widget/cmus.lua diff --git a/config/awesome/cmus-widget/README.md b/config/awesome/cmus-widget/README.md new file mode 100644 index 0000000..cbf5b7e --- /dev/null +++ b/config/awesome/cmus-widget/README.md @@ -0,0 +1,93 @@ +# Brightness widget + +This widget represents current brightness level, depending on config parameters could be an arcchart or icon with text: ![Brightness widget](./br-wid-1.png) + +## Customization + +It is possible to customize widget by providing a table with all or some of the following config parameters: + +| Name | Default | Description | +|---|---|---| +| `type`| `arc` | The widget type. Could be `arc` or `icon_and_text` | +| `program` | `light` | The program used to control the brightness, either `light`, `xbacklight`, or `brightnessctl`. | +| `step` | 5 | Step | +| `base` | 20 | Base level to set brightness to on left click. | +| `path_to_icon` | `/usr/share/icons/Arc/status/symbolic/display-brightness-symbolic.svg` | Path to the icon | +| `font` | `Play 9` | Font | +| `timeout` | 1 | How often in seconds the widget refreshes. Check the note below | +| `tooltip` | false | Display brightness level in a tooltip when the mouse cursor hovers the widget | + +_Note:_ If brightness is controlled only by the widget (either by a mouse, or by a shortcut, then the `timeout` could be quite big, as there is no reason to synchronize the brightness level). + +## Installation + +To choose the right `program` argument, first you need to check which of them works better for you. + + - using `xbacklight`: + + Install (on Ubuntu it's available in the apt repository) it and check if it works by running: + + ```bash + xbacklight -get + ``` + + If there is no output it means that it doesn't work, you can either try to fix it, or try to use `light`. + + - using `light` command: + + Install (on Ubuntu it's available in the apt repository) from the repo: [github.com/haikarainen/light](https://github.com/haikarainen/light) and check if it works by running + + ```bash + light -G + 49.18 + light -A 5 + ``` + If you're on Ubuntu/debian and if the brightness level doesn't change, try to do this: https://github.com/haikarainen/light/issues/113#issuecomment-632638436. + + - using `brightnessctl`: + + On Ubuntu it is available in the apt repository. Install and check the ouptut of the following command. + ```bash + brightnessctl --list + ``` + +Then clone this repo under **~/.config/awesome/**: + +```bash +git clone https://github.com/streetturtle/awesome-wm-widgets.git ~/.config/awesome/awesome-wm-widgets +``` + +Require widget at the beginning of **rc.lua**: + +```lua +local brightness_widget = require("awesome-wm-widgets.brightness-widget.brightness") +``` + +Add the widget to the tasklist: + +```lua +s.mytasklist, -- Middle widget + { -- Right widgets + layout = wibox.layout.fixed.horizontal, + ... + -- default + brightness_widget(), + -- or customized + brightness_widget{ + type = 'icon_and_text', + program = 'xbacklight', + step = 2, + } + } + ... +``` + +## Controls + +In order to change brightness by shortcuts you can add them to the `globalkeys` table in the **rc.lua**: + +```lua +awful.key({ modkey }, ";", function () brightness_widget:inc() end, {description = "increase brightness", group = "custom"}), +awful.key({ modkey, "Shift"}, ";", function () brightness_widget:dec() end, {description = "decrease brightness", group = "custom"}), +``` +On a laptop you can use `XF86MonBrightnessUp` and `XF86MonBrightnessDown` keys. diff --git a/config/awesome/cmus-widget/br-wid-1.png b/config/awesome/cmus-widget/br-wid-1.png new file mode 100644 index 0000000000000000000000000000000000000000..b00b0e6091a08f4954e3a132648ddadb09163753 GIT binary patch literal 4912 zcmV-06VL34P)|+BiAmEOk<|DZ|VhX|QCOp{1as zk!k)&4S#@K(NYP+rIB9JD}o4@bKYnEc;D~W`Ef6hb=J9Sogd%*zVF@d-p_vav-cs| zyGSGHeH8!zl65b_Lx8}>VXxq1EyDp-BHZQJ7^&2dR%3MvL z0D^U=f`sI+w@7qbGF<^vlAs6*LU3=z*am?FP~5)(qX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xx%iWNUGnV4C4a2>Rw{L&gUiBw#QV?0k9e46r6I_jhYfpu-J9_~ zqD;q7<1($fMIZ3m(V4EQy@8J0@=0GF6%anq>KYtHY3UrUQ<-aqsCx{Tn{!H(;S$o zn=Yv8kfa*CK(A!ivPil0n_DF}D18)32Wa#(vuv*C7A)KHe_0SZ5IMW6kWRtS zM!<-Uo$D@H%2CB7iKTiyYfI*nCfQSIycBvi>9h~Mq>RQzY|YvqfgCi^zL*QzB|;h# zb=EJ*_FG$P*%G$;#_6Vb6hW9+=+W>zx zsZ_p%yi!FxS~%4lvNm1pc`(2+^1#ksw%BrKK|p-j}>3@|Zxn zd`{zCM)Go}w$VcBK(=)Wux^w1mQ5*@#6db=T1i z5`ZNUZGygBq|HnfnXL9lacVgohf&_E2%4;=(L*Wg-1-y;YmiUlngJ>h(N-Y5uc{UB zrA^yX)206gc++t|WAj0FfoL)&?psx=Abl3KM2ilnO~p*~EqfdR>yL|LiT ztgXrpO+#8q z9j1ONrH)!=V!>*Vb9KaDN$x2>@1PLNU;3h{|m?r@?xg){7{aJd`>~uF^R`pfo^g(h4fSy8_?)ez{ha7fQBp`hi7{$4gG=aK zI_DE*he%su2$yJJkg-{x80u!6SvSQHF`?j=RP(w^stbtt0}{f_B_iczF7fh^%p6N| zUHy#TwEB$;!>m)0C#f;GN-0j+q(&KnA}G2nnMv75jsZch@sgJ>*1@e991F&+FD}z@ z*FvS|i__W}&#?v~rn*n$tMUoxMAW + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/config/awesome/cmus-widget/cmus.lua b/config/awesome/cmus-widget/cmus.lua new file mode 100644 index 0000000..c0d4e00 --- /dev/null +++ b/config/awesome/cmus-widget/cmus.lua @@ -0,0 +1,112 @@ +------------------------------------------------- +-- Cmus Widget for Awesome Window Manager +-- Show what's playing, play/pause, etc + +-- @author Augusto Gunsch +-- @copyright 2022 Augusto Gunsch +------------------------------------------------- + +local awful = require("awful") +local wibox = require("wibox") +local watch = require("awful.widget.watch") +local spawn = require("awful.spawn") +local naughty = require("naughty") + +local cmus_widget = {} + +local function show_warning(message) + naughty.notify{ + preset = naughty.config.presets.critical, + title = "Cmus Widget", + text = message} +end + +local function worker(user_args) + + local args = user_args or {} + local font = args.font or "Play 9" + + local path_to_icons = args.path_to_icons or "/usr/share/icons/Arc/actions/symbolic/" + local timeout = args.timeout or 10 + + cmus_widget = wibox.widget { + { + { + id = "playback_icon", + resize = false, + widget = wibox.widget.imagebox, + }, + layout = wibox.container.place + }, + { + id = "text", + font = font, + widget = wibox.widget.textbox + }, + layout = wibox.layout.fixed.horizontal, + update_icon = function(self, name) + self:get_children_by_id("playback_icon")[1]:set_image(path_to_icons .. name) + end, + set_title = function(self, title) + self:get_children_by_id("text")[1]:set_text(title) + end + } + + watch("cmus-remote -Q", timeout, + function(widget, stdout, _, _, code) + if code == 0 then + local cmus_info = {} + + for s in stdout:gmatch("[^\r\n]+") do + local key, val = string.match(s, "^tag (%a+) (.+)$") + + if key and val then + cmus_info[key] = val + else + local key, val = string.match(s, "^set (%a+) (.+)$") + + if key and val then + cmus_info[key] = val + else + local key, val = string.match(s, "^(%a+) (.+)$") + if key and val then + cmus_info[key] = val + end + end + end + end + + local title = cmus_info.title + + if not title and cmus_info.file then + title = cmus_info.file:gsub("%..-$", "") + title = title:gsub("^.+/", "") + end + + if title then + if cmus_info["status"] == "playing" then + widget:update_icon("media-playback-start-symbolic.svg") + elseif cmus_info["status"] == "paused" then + widget:update_icon("media-playback-pause-symbolic.svg") + else + widget:update_icon("media-playback-stop-symbolic.svg") + end + + widget:set_title(title) + widget.visible = true + else + widget.visible = false + widget.width = 0 + end + else + widget.visible = false + end + end, + cmus_widget) + + return cmus_widget +end + +return setmetatable(cmus_widget, { __call = function(_, ...) + return worker(...) +end }) diff --git a/config/awesome/rc.lua b/config/awesome/rc.lua index d6af5da..3b6fdd1 100644 --- a/config/awesome/rc.lua +++ b/config/awesome/rc.lua @@ -23,6 +23,7 @@ local is_deb, debian = pcall(require, "debian.menu") local has_fdo, freedesktop = pcall(require, "freedesktop") -- awesome-wm-widgets +local cmus_widget = require("cmus-widget.cmus") local volume_widget = require("awesome-wm-widgets.volume-widget.volume") local battery_widget = require("awesome-wm-widgets.battery-widget.battery") local brightness_widget = require("awesome-wm-widgets.brightness-widget.brightness") @@ -247,36 +248,57 @@ awful.screen.connect_for_each_screen(function(s) s.mypromptbox, }, s.mytasklist, -- Middle widget - { -- Right widgets + { layout = wibox.layout.fixed.horizontal, - spacing = 10, - --mykeyboardlayout, - wibox.widget.separator{ - orientation = "vertical", - forced_width = 5, - visible = false + { + widget = wibox.container.margin, + right = 4, + { + layout = wibox.layout.fixed.horizontal, + spacing = 10, + wibox.widget.separator{ + orientation = "vertical", + forced_width = 5, + visible = false + }, + wibox.widget.systray(), + wibox.widget.separator{ + orientation = "vertical", + forced_width = 5 + } + } }, - wibox.widget.systray(), - wibox.widget.separator{ - orientation = "vertical", - forced_width = 5 + { + cmus_widget(), + widget = wibox.container.margin, + right = 5, + left = 5, + draw_empty = false }, - battery_widget{ - enable_battery_warning = true - }, - brightness_widget { - type = 'icon_and_text', - program = 'brightnessctl', - percentage = false - }, - volume_widget{ - widget_type = 'icon_and_text', - with_icon = true, - mute_color = beautiful.bg_urgent - }, - mytextclock, - s.mylayoutbox, - }, + { + widget = wibox.container.margin, + left = 6, + { + layout = wibox.layout.fixed.horizontal, + spacing = 10, + volume_widget{ + widget_type = 'icon_and_text', + with_icon = true, + mute_color = beautiful.bg_urgent + }, + --battery_widget{ + --enable_battery_warning = true + --}, + --brightness_widget { + --type = 'icon_and_text', + --program = 'brightnessctl', + --percentage = false + --}, + mytextclock, + s.mylayoutbox, + } + } + } } end) -- }}}