From 7a52f31e4e7e64e9830aa51cb1fd36862f42a57a Mon Sep 17 00:00:00 2001 From: Stefano Mazzucco Date: Thu, 27 Jul 2017 22:42:07 +0100 Subject: [PATCH] Change widget from checkbox to textbox Now we show an uppercase "A" when capslock is active and a lowercase "a" when it's inactive. this can be customized too. Also added a tooltip. --- README.md | 27 +++++++++++++-- capslock.lua | 41 ++++++++++++----------- screenshots/active_capslock_widget.png | Bin 0 -> 589 bytes screenshots/capslock_widget.png | Bin 962 -> 0 bytes screenshots/inactive_capslock_widget.png | Bin 0 -> 550 bytes 5 files changed, 47 insertions(+), 21 deletions(-) create mode 100644 screenshots/active_capslock_widget.png delete mode 100644 screenshots/capslock_widget.png create mode 100644 screenshots/inactive_capslock_widget.png diff --git a/README.md b/README.md index b2c4690..7b9fd0a 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,31 @@ local globalkeys = awful.util.table.join( -- more config follows ``` -Now, when you activate CAPS LOCK, a chevron sign will be -displayed: ![capslock screenshot](/screenshots/capslock_widget.png?raw=true) +Now, when CAPS LOCK is active, an uppercase letter **A** will be displayed + +![active_capslock screenshot](/screenshots/active_capslock_widget.png?raw=true) + +when CAPS LOCK is inactive, a lowecase letter **a** will be displayed: + +![inactive_capslock screenshot](/screenshots/inactive_capslock_widget.png?raw=true) + +These can be changed by changing the `activated` and `deactivated` +attributes of the widget +as +[Pango markup](https://developer.gnome.org/pango/stable/PangoMarkupFormat.html) +strings. You will probably need to adjust the `forced_width` attribute too. + +For example: + +``` lua +local capslock = require("capslock") +capslock.forced_width = 35 +capslock.activated = "CAPS" +capslock.deactivated = "caps" +``` + +When the mouse is over the widget, a tooltip that says `Caps Lock on`/`Caps +Lock off` is also shown. # Contributing diff --git a/capslock.lua b/capslock.lua index 296ae63..3a72a51 100644 --- a/capslock.lua +++ b/capslock.lua @@ -39,34 +39,35 @@ ]] -local math = math local awful = require("awful") -local gears = require("gears") local wibox = require("wibox") -local checkbox = wibox.widget { - checked = false, - border_width = 0, - paddings = 2, - check_shape = function (cr, w, h) - gears.shape.transform(gears.shape.powerline) - :rotate(-math.pi/2) - :translate(-h, 0)(cr, w, h) - end, - widget = wibox.widget.checkbox +local capslock = wibox.widget { + widget = wibox.widget.textbox, + align = "center", + valign = "center", + forced_width = 15, } -local function check_caps_lock() +capslock.activated = "A" +capslock.deactivated = "a" + +local tooltip = awful.tooltip({}) + +tooltip:add_to_object(capslock) + +function capslock:check() awful.spawn.with_line_callback( "bash -c 'sleep 0.2 && xset q'", { stdout = function (line) if line:match("Caps Lock") then local status = line:gsub(".*(Caps Lock:%s+)(%a+).*", "%2") + tooltip.text = "Caps Lock " .. status if status == "on" then - checkbox.checked = true + self.markup = self.activated else - checkbox.checked = false + self.markup = self.deactivated end end end @@ -74,9 +75,11 @@ local function check_caps_lock() ) end -local capslock = awful.key({}, "Caps_Lock", check_caps_lock) -checkbox.key = capslock +capslock.key = awful.key( + {}, + "Caps_Lock", + function () capslock:check() end) -check_caps_lock() +capslock:check() -return checkbox +return capslock diff --git a/screenshots/active_capslock_widget.png b/screenshots/active_capslock_widget.png new file mode 100644 index 0000000000000000000000000000000000000000..aeff3972d49c384b53f38eeb4ad98246d53ccb21 GIT binary patch literal 589 zcmV-T0_k+m))Y?z(hlSK6cWUi=GQ zybJy!!9U@>C@QuTta!177C~(5!IQAF^Ij4U*?kV?l*voJ5%ZqIkR7-te|e<7q@(;$xGDh~j!#ZaBI6 z^!{vtw$)z2`6Ymgx7ZNpbYykEe74>h*f&i3m~F ze>58vusA<>b9~)I7P$HN>Hc_YXLs=V<8PFeQMY6PN(DCa!Jm)5CQ-cMG<4Ph^jVC6Jw-winfm1BiIuFw3SIQ zMvF4DNz8aA9a$?&NGheKX-sS}Mw5c7GP4D(%p4P!AyT*7O>52b+$LdWJB%q00009a7bBm000XU z000XU0RWnu7ytkRbV)=(R5;6hQ%!GMMHIbvW}auPC`yyYjm&}|NbNXI$%mst%Rc~A zKDI!G)HW?@)kUjrP)XvXQISBbT3Dn(D3r}pMG_~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