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 0000000..b00b0e6 Binary files /dev/null and b/config/awesome/cmus-widget/br-wid-1.png differ diff --git a/config/awesome/cmus-widget/brightness.svg b/config/awesome/cmus-widget/brightness.svg new file mode 100644 index 0000000..d334372 --- /dev/null +++ b/config/awesome/cmus-widget/brightness.svg @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + 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) -- }}}