From 62fed6bfb4de09d643bf766fa74d9d23103f3abf Mon Sep 17 00:00:00 2001 From: streetturtle Date: Wed, 2 Sep 2020 21:30:00 -0400 Subject: [logout] improvements --- experiments/logout-widget/README.md | 36 ++++++++++++++++++++---- experiments/logout-widget/logout.lua | 54 +++++++++++++++++++++++++++--------- experiments/logout-widget/power.svg | 1 + 3 files changed, 73 insertions(+), 18 deletions(-) create mode 100644 experiments/logout-widget/power.svg diff --git a/experiments/logout-widget/README.md b/experiments/logout-widget/README.md index f848e5f..d9a3ea9 100644 --- a/experiments/logout-widget/README.md +++ b/experiments/logout-widget/README.md @@ -4,12 +4,38 @@ Clone repo (if not cloned yet) under ~/.config/awesome, then -```lua -local logout = require("awesome-wm-widgets.experiments.logout-widget.logout") - -- define a shorcut in globalkey - awful.key({ modkey }, "l", function() logout.launch() end, {description = "Show logout screen", group = "custom"}), -``` +- to show by shortcut: + + ```lua + local logout = require("awesome-wm-widgets.experiments.logout-widget.logout") + + -- define a shorcut in globalkey + awful.key({ modkey }, "l", function() logout.launch() end, {description = "Show logout screen", group = "custom"}), + ``` + +- to show by clicking on a widget in wibar: + + ```lua + local logout = require("awesome-wm-widgets.experiments.logout-widget.logout") + + s.mytasklist, -- Middle widget + { -- Right widgets + layout = wibox.layout.fixed.horizontal, + ... + logout.widget{ + bg_color = "#000000", + accent_color = "#888888", + text_color = '#ffffff', + phrases = {'Yippee ki yay!', 'Hasta la vista, baby', 'See you later, alligator!', 'After a while, crocodile.'}, + onlogout = function() naughty.notify{text = "Logged out!"} end + }, + ... + ``` # Customisation + +## Phrase + +You can provide a phrase which appears on the widget. diff --git a/experiments/logout-widget/logout.lua b/experiments/logout-widget/logout.lua index fb0e06e..3b15274 100644 --- a/experiments/logout-widget/logout.lua +++ b/experiments/logout-widget/logout.lua @@ -39,7 +39,7 @@ local action = wibox.widget { local function create_button(icon_name, action_name, color, onclick) - local button = fancybuttons.with_icon{ type = 'basic', shape = 'circle', icon = ICONS_DIR .. icon_name, color = color, onclick = onclick } + local button = fancybuttons.with_icon{ type = 'basic', shape = 'rectangle', icon = icon_name, color = color, onclick = onclick } button:connect_signal("mouse::enter", function(c) action:set_text(action_name) end) button:connect_signal("mouse::leave", function(c) action:set_text(' ') end) return button @@ -55,25 +55,27 @@ local function launch(args) local onlogout = args.onlogout or function () awesome.quit() end local onlock = args.onlock local onreboot = args.onreboot - local onsuspend = args.onsuspend + local onsuspend = args.onsuspend or function () awful.spawn.with_shell("systemctl suspend") end local onpoweroff = args.onpoweroff or function () awful.spawn.with_shell("shutdown now") end w:set_bg(bg_color) + local phrase_widget = wibox.widget{ + markup = '' .. phrases[ math.random( #phrases ) ] .. '', + align = 'center', + widget = wibox.widget.textbox + } + w:setup { { - { - markup = '' .. phrases[ math.random( #phrases ) ] .. '', - align = 'center', - widget = wibox.widget.textbox - }, + phrase_widget, { { - create_button('log-out.svg', 'Log Out', accent_color, onlogout), - create_button('lock.svg', 'Lock', accent_color, onlock), - create_button('refresh-cw.svg', 'Reboot', accent_color, onreboot), - create_button('moon.svg', 'Suspend', accent_color, onsuspend), - create_button('power.svg', 'Power Off', accent_color, onpoweroff), + create_button('log-out', 'Log Out', accent_color, onlogout), + create_button('lock', 'Lock', accent_color, onlock), + create_button('refresh-cw', 'Reboot', accent_color, onreboot), + create_button('moon', 'Suspend', accent_color, onsuspend), + create_button('power', 'Power Off', accent_color, onpoweroff), id = 'buttons', spacing = 8, layout = wibox.layout.fixed.horizontal @@ -101,12 +103,38 @@ local function launch(args) capi.keygrabber.run(function(_, key, event) if event == "release" then return end if key then + phrase_widget:set_text('') capi.keygrabber.stop() w.visible = false end end) end +local function widget(args) + local res = wibox.widget { + { + { + image = WIDGET_DIR .. '/power.svg', + widget = wibox.widget.imagebox + }, + margins = 4, + layout = wibox.container.margin + }, + layout = wibox.layout.fixed.horizontal, + } + + res:buttons( + awful.util.table.join( + awful.button({}, 1, function() + launch(args) + end) + )) + + return res + +end + return { - launch = launch + launch = launch, + widget = widget } diff --git a/experiments/logout-widget/power.svg b/experiments/logout-widget/power.svg new file mode 100644 index 0000000..1f9c4e3 --- /dev/null +++ b/experiments/logout-widget/power.svg @@ -0,0 +1 @@ + \ No newline at end of file -- cgit v1.2.3