diff options
| -rw-r--r-- | experiments/logout-widget/README.md | 15 | ||||
| -rw-r--r-- | experiments/logout-widget/icons/lock.svg | 1 | ||||
| -rw-r--r-- | experiments/logout-widget/icons/log-out.svg | 1 | ||||
| -rw-r--r-- | experiments/logout-widget/icons/moon.svg | 1 | ||||
| -rw-r--r-- | experiments/logout-widget/icons/power.svg | 1 | ||||
| -rw-r--r-- | experiments/logout-widget/icons/refresh-cw.svg | 1 | ||||
| -rw-r--r-- | experiments/logout-widget/logout.lua | 128 | 
7 files changed, 96 insertions, 52 deletions
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 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#ECEFF4" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-lock"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>
\ 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 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#ECEFF4" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-log-out"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"></path><polyline points="16 17 21 12 16 7"></polyline><line x1="21" y1="12" x2="9" y2="12"></line></svg>
\ 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 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-moon"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path></svg>
\ 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 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#ECEFF4" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-power"><path d="M18.36 6.64a9 9 0 1 1-12.73 0"></path><line x1="12" y1="2" x2="12" y2="12"></line></svg>
\ 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 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#ECEFF4" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-refresh-cw"><polyline points="23 4 23 10 17 10"></polyline><polyline points="1 20 1 14 7 14"></polyline><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"></path></svg>
\ 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 = '<span color="'.. text_color .. '" size="20000">' .. phrases[ math.random( #phrases ) ] .. '</span>', +                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 = "<b>Spotify Shell</b>: ", -        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 {  | 
