From 9a3a38cabab9c1bbed34641690899ec69e6b43c1 Mon Sep 17 00:00:00 2001 From: streetturtle Date: Fri, 18 Dec 2020 21:10:29 -0500 Subject: rename logout widget to logout-popup --- logout-popup-widget/README.md | 83 ++++++++++++++++ logout-popup-widget/logout-dark.png | Bin 0 -> 27757 bytes logout-popup-widget/logout-dracula.png | Bin 0 -> 44660 bytes logout-popup-widget/logout-nord.png | Bin 0 -> 26289 bytes logout-popup-widget/logout-outrun.png | Bin 0 -> 49973 bytes logout-popup-widget/logout-popup.lua | 176 +++++++++++++++++++++++++++++++++ logout-popup-widget/power.svg | 1 + logout-popup-widget/screenshot.gif | Bin 0 -> 446468 bytes logout-popup-widget/screenshot.png | Bin 0 -> 129588 bytes 9 files changed, 260 insertions(+) create mode 100644 logout-popup-widget/README.md create mode 100644 logout-popup-widget/logout-dark.png create mode 100644 logout-popup-widget/logout-dracula.png create mode 100644 logout-popup-widget/logout-nord.png create mode 100644 logout-popup-widget/logout-outrun.png create mode 100644 logout-popup-widget/logout-popup.lua create mode 100644 logout-popup-widget/power.svg create mode 100644 logout-popup-widget/screenshot.gif create mode 100644 logout-popup-widget/screenshot.png (limited to 'logout-popup-widget') diff --git a/logout-popup-widget/README.md b/logout-popup-widget/README.md new file mode 100644 index 0000000..cdbbb6e --- /dev/null +++ b/logout-popup-widget/README.md @@ -0,0 +1,83 @@ +# Logout Popup Widget + +Widget which allows to perform lock, reboot, log out, power off and sleep actions. It can be called either by a shortcut, or by clicking on a widget in wibar. + +

+ screenshot +

+ +When the widget is shown, following shortcuts can be used: + - Escape - hide widget + - s - shutdown + - r - reboot + - u - suspend + - k - lock + - l - log out + +# Installation + +Clone this (if not cloned yet) and the [awesome-buttons](https://github.com/streetturtle/awesome-buttons) repos under **./.config/awesome/** + +```bash +cd ./.config/awesome/ +git clone https://github.com/streetturtle/awesome-wm-widgets +git clone https://github.com/streetturtle/awesome-buttons +``` +Then + +- to show by a shortcut - define a shortcut in `globalkeys`: + + ```lua + local logout = require("awesome-wm-widgets.experiments.logout-widget.logout") + ... + globalkeys = gears.table.join( + ... + awful.key({ modkey }, "l", function() logout.launch() end, {description = "Show logout screen", group = "custom"}), + ``` + +- to show by clicking on a widget in wibar - add widget to the wibar: + + ```lua + local logout_popup = require("awesome-wm-widgets.logout-popup-widget.logout-popup") + + s.mytasklist, -- Middle widget + { -- Right widgets + layout = wibox.layout.fixed.horizontal, + ... + logout_popup.widget{}, + ... + ``` + +# Customisation + +| Name | Default | Description | +|---|---|---| +| `icon` | `power.svg` | If used as widget - the path to the widget's icon | +| `icon_size` | `40` | Size of the icon | +| `icon_margin` | `16` | Margin around the icon | +| `bg_color` | `beautiful.bg_normal` | The color the background of the | +| `accent_color` | `beautiful.bg_focus` | The color of the buttons | +| `text_color` | `beautiful.fg_normal` | The color of text | +| `phrases` | `{'Goodbye!'}` | The table with phrase(s) to show, if more than one provided, the phrase is chosen randomly. Leave empty (`{}`) to hide the phrase | +| `onlogout` | `function() awesome.quit() end` | Function which is called when the logout button is pressed | +| `onlock` | `function() awful.spawn.with_shell("systemctl suspend") end` | Function which is called when the lock button is pressed | +| `onreboot` | `function() awful.spawn.with_shell("reboot") end` | Function which is called when the reboot button is pressed | +| `onsuspend` | `function() awful.spawn.with_shell("systemctl suspend") end` | Function which is called when the suspend button is pressed | +| `onpoweroff` | `function() awful.spawn.with_shell("shutdown now") end` | Function which is called when the poweroff button is pressed | + +Some color themes for inspiration: + +![nord](./logout-nord.png) +![outrun](./logout-outrun.png) +![dark](./logout-dark.png) +![dracula](./logout-dracula.png) + +```lua +logout.launch{ + bg_color = "#261447", accent_color = "#ff4365", text_color = '#f706cf', icon_size = 40, icon_margin = 16, -- outrun + -- bg_color = "#0b0c10", accent_color = "#1f2833", text_color = '#66fce1', -- dark + -- bg_color = "#3B4252", accent_color = "#88C0D0", text_color = '#D8DEE9', -- nord + -- bg_color = "#282a36", accent_color = "#ff79c6", phrases = {}, -- dracula, no phrase + phrases = {"exit(0)", "Don't forget to be awesome.", "Yippee ki yay!"}, +} +``` diff --git a/logout-popup-widget/logout-dark.png b/logout-popup-widget/logout-dark.png new file mode 100644 index 0000000..06e7c9c Binary files /dev/null and b/logout-popup-widget/logout-dark.png differ diff --git a/logout-popup-widget/logout-dracula.png b/logout-popup-widget/logout-dracula.png new file mode 100644 index 0000000..3c61c46 Binary files /dev/null and b/logout-popup-widget/logout-dracula.png differ diff --git a/logout-popup-widget/logout-nord.png b/logout-popup-widget/logout-nord.png new file mode 100644 index 0000000..9ab4b55 Binary files /dev/null and b/logout-popup-widget/logout-nord.png differ diff --git a/logout-popup-widget/logout-outrun.png b/logout-popup-widget/logout-outrun.png new file mode 100644 index 0000000..9be68b5 Binary files /dev/null and b/logout-popup-widget/logout-outrun.png differ diff --git a/logout-popup-widget/logout-popup.lua b/logout-popup-widget/logout-popup.lua new file mode 100644 index 0000000..ce6699a --- /dev/null +++ b/logout-popup-widget/logout-popup.lua @@ -0,0 +1,176 @@ +------------------------------------------------- +-- Logout widget for Awesome Window Manager +-- More details could be found here: +-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/logout-widget + +-- @author Pavel Makhov +-- @copyright 2020 Pavel Makhov +------------------------------------------------- + +local awful = require("awful") +local capi = {keygrabber = keygrabber } +local wibox = require("wibox") +local gears = require("gears") +local beautiful = require("beautiful") +local awesomebuttons = require("awesome-buttons.awesome-buttons") + + +local HOME_DIR = os.getenv("HOME") +local WIDGET_DIR = HOME_DIR .. '/.config/awesome/awesome-wm-widgets/logout-popup-widget' + + +local w = wibox { + bg = beautiful.fg_normal, + max_widget_size = 500, + ontop = true, + height = 200, + width = 400, + shape = function(cr, width, height) + gears.shape.rounded_rect(cr, width, height, 8) + end +} + +local action = wibox.widget { + text = ' ', + widget = wibox.widget.textbox +} + +local phrase_widget = wibox.widget{ + align = 'center', + widget = wibox.widget.textbox +} + +local function create_button(icon_name, action_name, color, onclick, icon_size, icon_margin) + + local button = awesomebuttons.with_icon { + type = 'basic', + icon = icon_name, + color = color, + icon_size = icon_size, + icon_margin = icon_margin, + onclick = function() + onclick() + w.visible = false + capi.keygrabber.stop() + end + } + button:connect_signal("mouse::enter", function() action:set_text(action_name) end) + button:connect_signal("mouse::leave", function() action:set_text(' ') end) + return button +end + +local function launch(args) + + local bg_color = args.bg_color or beautiful.bg_normal + local accent_color = args.accent_color or beautiful.bg_focus + local text_color = args.text_color or beautiful.fg_normal + local phrases = args.phrases or {'Goodbye!'} + local icon_size = args.icon_size or 40 + local icon_margin = args.icon_margin or 16 + + local onlogout = args.onlogout or function () awesome.quit() end + local onlock = args.onlock or function() awful.spawn.with_shell("i3lock") end + local onreboot = args.onreboot or function() awful.spawn.with_shell("reboot") end + 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) + if #phrases > 0 then + phrase_widget:set_markup( + '' .. phrases[ math.random( #phrases ) ] .. '') + end + + w:setup { + { + phrase_widget, + { + { + create_button('log-out', 'Log Out (l)', accent_color, onlogout, icon_size, icon_margin), + create_button('lock', 'Lock (k)', accent_color, onlock, icon_size, icon_margin), + create_button('refresh-cw', 'Reboot (r)', accent_color, onreboot, icon_size, icon_margin), + create_button('moon', 'Suspend (u)', accent_color, onsuspend, icon_size, icon_margin), + create_button('power', 'Power Off (s)', accent_color, onpoweroff, icon_size, icon_margin), + id = 'buttons', + spacing = 8, + layout = wibox.layout.fixed.horizontal + }, + valigh = 'center', + layout = wibox.container.place + }, + { + action, + haligh = 'center', + layout = wibox.container.place + }, + spacing = 32, + layout = wibox.layout.fixed.vertical + }, + id = 'a', + shape_border_width = 1, + valigh = 'center', + layout = wibox.container.place + } + + w.screen = mouse.screen + w.visible = true + + awful.placement.centered(w) + capi.keygrabber.run(function(_, key, event) + if event == "release" then return end + if key then + if key == 'Escape' then + phrase_widget:set_text('') + capi.keygrabber.stop() + w.visible = false + elseif key == 's' then onpoweroff() + elseif key == 'r' then onreboot() + elseif key == 'u' then onsuspend() + elseif key == 'k' then onlock() + elseif key == 'l' then onlogout() + end + + if key == 'Escape' or string.match("srukl", key) then + phrase_widget:set_text('') + capi.keygrabber.stop() + w.visible = false + end + end + end) +end + +local function widget(args) + local icon = args.icon or WIDGET_DIR .. '/power.svg' + + local res = wibox.widget { + { + { + image = icon, + 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() + if w.visible then + phrase_widget:set_text('') + capi.keygrabber.stop() + w.visible = false + else + launch(args) + end + end) + )) + + return res + +end + +return { + launch = launch, + widget = widget +} diff --git a/logout-popup-widget/power.svg b/logout-popup-widget/power.svg new file mode 100644 index 0000000..1f9c4e3 --- /dev/null +++ b/logout-popup-widget/power.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/logout-popup-widget/screenshot.gif b/logout-popup-widget/screenshot.gif new file mode 100644 index 0000000..4975c19 Binary files /dev/null and b/logout-popup-widget/screenshot.gif differ diff --git a/logout-popup-widget/screenshot.png b/logout-popup-widget/screenshot.png new file mode 100644 index 0000000..74ed7f0 Binary files /dev/null and b/logout-popup-widget/screenshot.png differ -- cgit v1.2.3