diff options
Diffstat (limited to 'logout-menu-widget')
| -rw-r--r-- | logout-menu-widget/README.md | 45 | ||||
| -rw-r--r-- | logout-menu-widget/icons/lock.svg | 1 | ||||
| -rw-r--r-- | logout-menu-widget/icons/log-out.svg | 1 | ||||
| -rw-r--r-- | logout-menu-widget/icons/moon.svg | 1 | ||||
| -rw-r--r-- | logout-menu-widget/icons/power.svg | 1 | ||||
| -rw-r--r-- | logout-menu-widget/icons/power_w.svg | 1 | ||||
| -rw-r--r-- | logout-menu-widget/icons/refresh-cw.svg | 1 | ||||
| -rw-r--r-- | logout-menu-widget/logout-menu.gif | bin | 0 -> 47220 bytes | |||
| -rw-r--r-- | logout-menu-widget/logout-menu.lua | 129 | 
9 files changed, 180 insertions, 0 deletions
| diff --git a/logout-menu-widget/README.md b/logout-menu-widget/README.md new file mode 100644 index 0000000..d47dcb2 --- /dev/null +++ b/logout-menu-widget/README.md @@ -0,0 +1,45 @@ +# Logout Menu Widget + +This widget shows a menu with options to log out from the current session, lock, reboot, suspend and power off the computer, similar to [logout-popup-widget](https://github.com/streetturtle/awesome-wm-widgets/tree/master/logout-popup-widget): + + + +## Installation + +Clone this repo (if not cloned yet) **./.config/awesome/** + +```bash +cd ./.config/awesome/ +git clone https://github.com/streetturtle/awesome-wm-widgets +``` +Then add the widget to the wibar: + +```lua +local logout_menu_widget = require("awesome-wm-widgets.logout-menu-widget.logout-menu") + +s.mytasklist, -- Middle widget +    { -- Right widgets +        layout = wibox.layout.fixed.horizontal, +        ... +        -- default +        logout_menu_widget(), +        -- custom +        logout_menu_widget{ +            font = 'Play 14', +            onlock = function() awful.spawn.with_shell('i3lock-fancy') end +        } +        ... +``` + +## Customization + +It is possible to customize the widget by providing a table with all or some of the following config parameters: + +| Name | Default | Description | +|---|---|---| +| `font` | `beautiful.font` | Font of the menu items | +| `onlogout` | `function() awesome.quit() end` | Function which is called when the logout item is clicked | +| `onlock` | `function() awful.spawn.with_shell("i3lock") end` | Function which is called when the lock item is clicked | +| `onreboot` | `function() awful.spawn.with_shell("reboot") end` | Function which is called when the reboot item is clicked | +| `onsuspend` | `function() awful.spawn.with_shell("systemctl suspend") end` | Function which is called when the suspend item is clicked | +| `onpoweroff` | `function() awful.spawn.with_shell("shutdown now") end` | Function which is called when the poweroff item is clicked | diff --git a/logout-menu-widget/icons/lock.svg b/logout-menu-widget/icons/lock.svg new file mode 100644 index 0000000..3cfa528 --- /dev/null +++ b/logout-menu-widget/icons/lock.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" 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/logout-menu-widget/icons/log-out.svg b/logout-menu-widget/icons/log-out.svg new file mode 100644 index 0000000..77afebb --- /dev/null +++ b/logout-menu-widget/icons/log-out.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" 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/logout-menu-widget/icons/moon.svg b/logout-menu-widget/icons/moon.svg new file mode 100644 index 0000000..60e6ce8 --- /dev/null +++ b/logout-menu-widget/icons/moon.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#ECEFF4" 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/logout-menu-widget/icons/power.svg b/logout-menu-widget/icons/power.svg new file mode 100644 index 0000000..68b1be8 --- /dev/null +++ b/logout-menu-widget/icons/power.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#BF616A" 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/logout-menu-widget/icons/power_w.svg b/logout-menu-widget/icons/power_w.svg new file mode 100644 index 0000000..1f9c4e3 --- /dev/null +++ b/logout-menu-widget/icons/power_w.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/logout-menu-widget/icons/refresh-cw.svg b/logout-menu-widget/icons/refresh-cw.svg new file mode 100644 index 0000000..39f52a5 --- /dev/null +++ b/logout-menu-widget/icons/refresh-cw.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" 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/logout-menu-widget/logout-menu.gif b/logout-menu-widget/logout-menu.gifBinary files differ new file mode 100644 index 0000000..9f17b51 --- /dev/null +++ b/logout-menu-widget/logout-menu.gif diff --git a/logout-menu-widget/logout-menu.lua b/logout-menu-widget/logout-menu.lua new file mode 100644 index 0000000..5dc2a8e --- /dev/null +++ b/logout-menu-widget/logout-menu.lua @@ -0,0 +1,129 @@ +------------------------------------------------- +-- Logout Menu Widget for Awesome Window Manager +-- More details could be found here: +-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/logout-menu-widget + +-- @author Pavel Makhov +-- @copyright 2020 Pavel Makhov +------------------------------------------------- + +local awful = require("awful") +local wibox = require("wibox") +local spawn = require("awful.spawn") +local gears = require("gears") +local beautiful = require("beautiful") + +local HOME = os.getenv('HOME') +local ICON_DIR = HOME .. '/.config/awesome/awesome-wm-widgets/logout-menu-widget/icons/' + +local logout_menu_widget = wibox.widget { +    { +        image = ICON_DIR .. 'power_w.svg', +        resize = true, +        widget = wibox.widget.imagebox, +    }, +    margins = 4, +    layout = wibox.container.margin +} + +local popup = awful.popup { +    ontop = true, +    visible = false, +    shape = function(cr, width, height) +        gears.shape.rounded_rect(cr, width, height, 4) +    end, +    border_width = 1, +    border_color = beautiful.bg_focus, +    maximum_width = 400, +    offset = { y = 5 }, +    widget = {} +} +local rows = { layout = wibox.layout.fixed.vertical } + +local function worker(user_args) + +    local args = user_args or {} + +    local font = args.font or beautiful.font + +    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 + +    local menu_items = { +        { name = 'Log out', icon_name = 'log-out.svg', command = onlogout }, +        { name = 'Lock', icon_name = 'lock.svg', command = onlock }, +        { name = 'Reboot', icon_name = 'refresh-cw.svg', command = onreboot }, +        { name = 'Suspend', icon_name = 'moon.svg', command = onsuspend }, +        { name = 'Power off', icon_name = 'power.svg', command = onpoweroff }, +    } + +    for _, item in ipairs(menu_items) do + +        local row = wibox.widget { +            { +                { +                    { +                        image = ICON_DIR .. item.icon_name, +                        resize = false, +                        widget = wibox.widget.imagebox +                    }, +                    { +                        text = item.name, +                        font = font, +                        widget = wibox.widget.textbox +                    }, +                    spacing = 12, +                    layout = wibox.layout.fixed.horizontal +                }, +                margins = 8, +                layout = wibox.container.margin +            }, +            bg = beautiful.bg_normal, +            widget = wibox.container.background +        } + +        row:connect_signal("mouse::enter", function(c) c:set_bg(beautiful.bg_focus) end) +        row:connect_signal("mouse::leave", function(c) c:set_bg(beautiful.bg_normal) end) + +        local old_cursor, old_wibox +        row:connect_signal("mouse::enter", function() +            local wb = mouse.current_wibox +            old_cursor, old_wibox = wb.cursor, wb +            wb.cursor = "hand1" +        end) +        row:connect_signal("mouse::leave", function() +            if old_wibox then +                old_wibox.cursor = old_cursor +                old_wibox = nil +            end +        end) + +        row:buttons(awful.util.table.join(awful.button({}, 1, function() +            popup.visible = not popup.visible +            item.command() +        end))) + +        table.insert(rows, row) +    end +    popup:setup(rows) + +    logout_menu_widget:buttons( +            awful.util.table.join( +                    awful.button({}, 1, function() +                        if popup.visible then +                            popup.visible = not popup.visible +                        else +                            popup:move_next_to(mouse.current_widget_geometry) +                        end +                    end) +            ) +    ) + +    return logout_menu_widget + +end + +return setmetatable(logout_menu_widget, { __call = function(_, ...) return worker(...) end }) | 
