From 402ebd04801a8dcf825cf2909f362c9f8e06e88c Mon Sep 17 00:00:00 2001 From: streetturtle Date: Tue, 1 Sep 2020 22:19:52 -0400 Subject: [logout] some improvements --- experiments/logout-widget/README.md | 15 +++ experiments/logout-widget/icons/lock.svg | 1 + experiments/logout-widget/icons/log-out.svg | 1 + experiments/logout-widget/icons/moon.svg | 1 + experiments/logout-widget/icons/power.svg | 1 + experiments/logout-widget/icons/refresh-cw.svg | 1 + experiments/logout-widget/logout.lua | 128 +++++++++++++++---------- 7 files changed, 96 insertions(+), 52 deletions(-) create mode 100644 experiments/logout-widget/README.md create mode 100644 experiments/logout-widget/icons/lock.svg create mode 100644 experiments/logout-widget/icons/log-out.svg create mode 100644 experiments/logout-widget/icons/moon.svg create mode 100644 experiments/logout-widget/icons/power.svg create mode 100644 experiments/logout-widget/icons/refresh-cw.svg (limited to 'experiments') diff --git a/experiments/logout-widget/README.md b/experiments/logout-widget/README.md new file mode 100644 index 0000000..f848e5f --- /dev/null +++ b/experiments/logout-widget/README.md @@ -0,0 +1,15 @@ +# Logout widget + +# Installation + +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"}), +``` + +# Customisation + diff --git a/experiments/logout-widget/icons/lock.svg b/experiments/logout-widget/icons/lock.svg new file mode 100644 index 0000000..5396f93 --- /dev/null +++ b/experiments/logout-widget/icons/lock.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/experiments/logout-widget/icons/log-out.svg b/experiments/logout-widget/icons/log-out.svg new file mode 100644 index 0000000..955e870 --- /dev/null +++ b/experiments/logout-widget/icons/log-out.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/experiments/logout-widget/icons/moon.svg b/experiments/logout-widget/icons/moon.svg new file mode 100644 index 0000000..7fb9607 --- /dev/null +++ b/experiments/logout-widget/icons/moon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/experiments/logout-widget/icons/power.svg b/experiments/logout-widget/icons/power.svg new file mode 100644 index 0000000..1f9c4e3 --- /dev/null +++ b/experiments/logout-widget/icons/power.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/experiments/logout-widget/icons/refresh-cw.svg b/experiments/logout-widget/icons/refresh-cw.svg new file mode 100644 index 0000000..9af0ef3 --- /dev/null +++ b/experiments/logout-widget/icons/refresh-cw.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/experiments/logout-widget/logout.lua b/experiments/logout-widget/logout.lua index c9c738e..fb0e06e 100644 --- a/experiments/logout-widget/logout.lua +++ b/experiments/logout-widget/logout.lua @@ -8,79 +8,103 @@ ------------------------------------------------- local awful = require("awful") -local gfs = require("gears.filesystem") +local capi = {keygrabber = keygrabber } local wibox = require("wibox") local gears = require("gears") +local beautiful = require("beautiful") +local fancybuttons = require("awesome-buttons.awesome-buttons") -local ICON = '/usr/share/icons/Papirus-Light/32x32/apps/spotify-linux-48x48.svg' -local spotify_shell = awful.widget.prompt() +local HOME_DIR = os.getenv("HOME") +local WIDGET_DIR = HOME_DIR .. '/.config/awesome/awesome-wm-widgets/experiments/logout-widget' +local ICONS_DIR = WIDGET_DIR .. '/icons/' + local w = wibox { - bg = '#1e252c', - border_width = 1, - border_color = '#84bd00', + bg = beautiful.fg_normal, max_widget_size = 500, ontop = true, - height = 400, - width = 250, + height = 200, + width = 400, shape = function(cr, width, height) - gears.shape.rounded_rect(cr, width, height, 3) + gears.shape.rounded_rect(cr, width, height, 8) end } -w:setup { - { +local action = wibox.widget { + text = ' ', + widget = wibox.widget.textbox +} + + +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 } + 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 +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 onlogout = args.onlogout or function () awesome.quit() end + local onlock = args.onlock + local onreboot = args.onreboot + local onsuspend = args.onsuspend + local onpoweroff = args.onpoweroff or function () awful.spawn.with_shell("shutdown now") end + + w:set_bg(bg_color) + + w:setup { { { - image = ICON, - widget = wibox.widget.imagebox, - resize = false + markup = '' .. phrases[ math.random( #phrases ) ] .. '', + align = 'center', + widget = wibox.widget.textbox }, - id = 'icon', - top = 9, - left = 10, - layout = wibox.container.margin - }, - { - layout = wibox.container.margin, - left = 10, - spotify_shell, + { + { + 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), + 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 = 'left', - layout = wibox.layout.fixed.horizontal - }, - { - image = '/usr/share/icons/Arc/actions/symbolic/system-shutdown-symbolic.svg', - widget = wibox.widget.imagebox, - resize = false, - opacity = 0.2, - set_hover = function(self, opacity) - self.opacity = opacity - self.image = '/usr/share/icons/Arc/actions/symbolic/system-shutdown-symbolic.svg' - end - - }, - layout = wibox.layout.fixed.vertical -} + id = 'a', + shape_border_width = 1, + valigh = 'center', + layout = wibox.container.place + } -local function launch() w.visible = true - awful.placement.top(w, { margins = {top = 40}, parent = awful.screen.focused()}) - awful.prompt.run{ - prompt = "Spotify Shell: ", - bg_cursor = '#84bd00', - textbox = spotify_shell.widget, - history_path = gfs.get_dir('cache') .. '/spotify_history', - exe_callback = function(input_text) - if not input_text or #input_text == 0 then return end - awful.spawn("sp " .. input_text) - end, - done_callback = function() + awful.placement.centered(w) + capi.keygrabber.run(function(_, key, event) + if event == "release" then return end + if key then + capi.keygrabber.stop() w.visible = false end - } + end) end return { -- cgit v1.2.3