forked from ashpie/simple-awesome
Update keyboard layout widget and small improvements
This commit is contained in:
parent
3aa412a73f
commit
12668472f8
@ -23,6 +23,7 @@ By default, Simple Awesome uses
|
||||
- Improve "leave menu"'s design
|
||||
- Modify "start menu", make everything work
|
||||
- Make "start menu" and "leave menu" not sticky (they currently stay open and focus even when clicking outside)
|
||||
- Replace the os menu with a custom widget
|
||||
|
||||
## Arisu personal todo
|
||||
|
||||
|
@ -73,10 +73,7 @@ config.keys = {
|
||||
-- Hotkeys globally available (through the entire OS, regardless of what's focused)
|
||||
config.keys.global_keys = {
|
||||
-- Application launcher
|
||||
launcher = {
|
||||
{ config.keys.modkey },
|
||||
"space",
|
||||
},
|
||||
launcher = { { config.keys.modkey }, "space", },
|
||||
|
||||
--
|
||||
-- Media and volume controls
|
||||
@ -84,23 +81,32 @@ config.keys.global_keys = {
|
||||
--
|
||||
media_control = {
|
||||
-- Raise volume
|
||||
raiseVolume = "XF86AudioRaiseVolume",
|
||||
raiseVolume = { {}, "XF86AudioRaiseVolume" },
|
||||
|
||||
-- Lower volume
|
||||
lowerVolume = "XF86AudioLowerVolume",
|
||||
lowerVolume = { {}, "XF86AudioLowerVolume" },
|
||||
|
||||
-- Toggle mute
|
||||
toggleMute = "XF86AudioMute",
|
||||
toggleMute = { {}, "XF86AudioMute" },
|
||||
|
||||
-- Toggle Play / Pause
|
||||
playPause = "XF86AudioPlay",
|
||||
playPause = { {}, "XF86AudioPlay" },
|
||||
|
||||
-- Next track
|
||||
nextTrack = "XF86AudioNext",
|
||||
nextTrack = { {}, "XF86AudioNext" },
|
||||
|
||||
-- Previous track
|
||||
previousTrack = "XF86AudioPrev",
|
||||
previousTrack = { {}, "XF86AudioPrev" },
|
||||
},
|
||||
|
||||
-- Keyboard layout
|
||||
keyboard_layout = {
|
||||
-- Switch between layouts
|
||||
switch = { { "Mod1" }, "Shift_L" },
|
||||
|
||||
-- Switch between layouts (alternative)
|
||||
switch_alt = { { "Shift" }, "Alt_L" },
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -108,8 +114,17 @@ config.keys.global_keys = {
|
||||
-- Widgets
|
||||
--
|
||||
config.widgets = {
|
||||
-- Keyboard layout widget
|
||||
keyboard_layout = {
|
||||
enabled = true,
|
||||
layouts = { "fr", "us" },
|
||||
layout_switch_command = "setxkbmap",
|
||||
},
|
||||
|
||||
-- Enable/disable the system resources monitoring widget
|
||||
system_resources = true,
|
||||
system_resources = {
|
||||
enabled = true,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -135,10 +150,6 @@ config.theme = awful.util.getdir("config") .. "/theme.lua"
|
||||
-- Screenshot utility
|
||||
config.screenshot_utility_command = "flameshot gui"
|
||||
|
||||
-- Keyboard layout
|
||||
config.kbSwitchCmd = "setxkbmap"
|
||||
config.kbLayouts = { "fr", "us" }
|
||||
|
||||
-- Run menu
|
||||
config.windowSwitcher = "rofi -show window -config " .. awful.util.getdir("config") .. "/assets/rofi/themes/paper-float.rasi"
|
||||
|
||||
|
@ -4,6 +4,10 @@ local gears = require("gears")
|
||||
local global_keys = {}
|
||||
|
||||
function make(hotkey, action, identity)
|
||||
if hotkey == nil then
|
||||
return nil
|
||||
end
|
||||
|
||||
local modifiers = hotkey[1]
|
||||
local key = hotkey[2]
|
||||
return awful.key(modifiers, key, action, identity)
|
||||
|
@ -111,10 +111,18 @@ hotkey.registerKeys(media_control.getKeys(config.keys.global_keys.media_control)
|
||||
|
||||
-- System resources
|
||||
local system_resources_widget
|
||||
if config.widgets.system_resources then
|
||||
if config.widgets.system_resources.enabled then
|
||||
system_resources_widget = require("simple/widgets/system_resources")
|
||||
end
|
||||
|
||||
-- Keyboard map indicator and switcher
|
||||
local keyboard_layout = require("simple/widgets/keyboard_layout")
|
||||
local keyboard_layout_widget
|
||||
if config.widgets.keyboard_layout.enabled then
|
||||
keyboard_layout_widget = keyboard_layout.widget
|
||||
end
|
||||
hotkey.registerKeys(keyboard_layout.getKeys(config.keys.global_keys.keyboard_layout))
|
||||
|
||||
|
||||
--
|
||||
-- Auto start
|
||||
@ -133,68 +141,31 @@ end
|
||||
--
|
||||
-- Launcher (start menu)
|
||||
--
|
||||
local launcher = awful.widget.launcher({
|
||||
local launcher = awful.widget.button({
|
||||
image = beautiful.awesome_icon,
|
||||
menu = awful.menu({
|
||||
items = {
|
||||
{ "Hotkeys", function() hotkeys_popup.show_help(nil, awful.screen.focused()) end },
|
||||
{ "Manual", config.awesome.terminal .. " -e man awesome" },
|
||||
{ "Edit config", config.awesome.editor_cmd .. " " .. awesome.conffile },
|
||||
{ "Open terminal", config.awesome.terminal }
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
|
||||
-- Keyboard map indicator and switcher
|
||||
mykeyboardlayout = awful.widget.keyboardlayout()
|
||||
|
||||
kbdlayout = {}
|
||||
kbdlayout.cur = 1
|
||||
kbdlayout.switch = function()
|
||||
kbdlayout.cur = (kbdlayout.cur % #(config.kbLayouts)) + 1
|
||||
local t = config.kbLayouts[kbdlayout.cur]
|
||||
os.execute(config.kbSwitchCmd .. " " .. t)
|
||||
end
|
||||
launcher:buttons(gears.table.join(launcher:buttons(),
|
||||
awful.button({}, 1, nil, showAppLauncher)))
|
||||
|
||||
shutdown_icon = awesome.load_image(awful.util.getdir("config") .. "/assets/icons/power.svg")
|
||||
restart_icon = awesome.load_image(awful.util.getdir("config") .. "/assets/icons/refresh-cw.svg")
|
||||
logout_icon = awesome.load_image(awful.util.getdir("config") .. "/assets/icons/log-out.svg")
|
||||
lock_icon = awesome.load_image(awful.util.getdir("config") .. "/assets/icons/lock.svg")
|
||||
|
||||
shutdownMenu_items = {
|
||||
{
|
||||
"Shutdown",
|
||||
function()
|
||||
os.execute('shutdown now')
|
||||
end,
|
||||
shutdown_icon
|
||||
},
|
||||
{
|
||||
"Restart",
|
||||
function()
|
||||
os.execute('shutdown -r now')
|
||||
end,
|
||||
restart_icon
|
||||
},
|
||||
{
|
||||
"Logout",
|
||||
function()
|
||||
awesome.quit()
|
||||
end,
|
||||
logout_icon
|
||||
},
|
||||
{
|
||||
"Lock",
|
||||
function()
|
||||
awful.spawn("xscreensaver-command -lock")
|
||||
end,
|
||||
lock_icon
|
||||
}
|
||||
}
|
||||
shutdownMenu_launcher = awful.widget.launcher({
|
||||
os_menu = awful.widget.launcher({
|
||||
image = beautiful.awesome_icon,
|
||||
menu = awful.menu({ items = shutdownMenu_items })
|
||||
menu = awful.menu({
|
||||
items = {
|
||||
{ "Hotkeys", function() hotkeys_popup.show_help(nil, awful.screen.focused()) end },
|
||||
{ "Manual", config.awesome.terminal .. " -e man awesome" },
|
||||
{ "Edit config", config.awesome.editor_cmd .. " " .. awesome.conffile },
|
||||
{ "Open terminal", config.awesome.terminal },
|
||||
{ "Lock", function() awful.spawn("xscreensaver-command -lock") end, lock_icon },
|
||||
{ "Logout", function() awesome.quit() end, logout_icon },
|
||||
{ "Restart", function() os.execute('shutdown -r now') end, restart_icon },
|
||||
{ "Shutdown", function() os.execute('shutdown now') end, shutdown_icon },
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -332,20 +303,20 @@ awful.screen.connect_for_each_screen(function(s)
|
||||
{
|
||||
-- Left widgets
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
mylauncher,
|
||||
launcher,
|
||||
s.mytaglist,
|
||||
s.mypromptbox,
|
||||
},
|
||||
s.mytasklist, -- Middle widget
|
||||
{
|
||||
-- Right widgets
|
||||
matchesScreen(config.system_resources_widget_screens) and system_resources_widget.widget or nil,
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
mykeyboardlayout,
|
||||
matchesScreen(config.system_resources_widget_screens) and system_resources_widget.widget or nil,
|
||||
keyboard_layout_widget,
|
||||
wibox.widget.systray(),
|
||||
mytextclock,
|
||||
s.mylayoutbox,
|
||||
shutdownMenu_launcher,
|
||||
os_menu,
|
||||
},
|
||||
}
|
||||
end)
|
||||
@ -453,11 +424,6 @@ hotkey.registerKeys(awful.key({ config.keys.modkey, }, "s", hotkeys_popup.show_h
|
||||
-- Menubar
|
||||
awful.key({ config.keys.modkey }, "space", function() os.execute(config.runMenu) end,
|
||||
{ description = "show the run menu", group = "launcher" }),
|
||||
-- Keyboard layout switch
|
||||
awful.key({ "Mod1" }, "Shift_L", function() kbdlayout.switch() end,
|
||||
{ description = "switch keyboard layout" }),
|
||||
awful.key({ "Shift" }, "Alt_L", function() kbdlayout.switch() end,
|
||||
{ description = "switch keyboard layout" }),
|
||||
-- Flameshot
|
||||
awful.key({}, "Print", function() os.execute(config.screenshot_utility_command) end,
|
||||
{ description = "Take a screenshot using the screenshot utility", group = "utilities" }))
|
||||
|
@ -16,6 +16,8 @@ local gears = require("gears")
|
||||
local naughty = require("naughty")
|
||||
local wibox = require("wibox")
|
||||
|
||||
local hotkey = require("simple/core/hotkey")
|
||||
|
||||
local config = require("config")
|
||||
|
||||
local hasPlayerctl = os.execute("playerctl -v") == true
|
||||
@ -183,20 +185,20 @@ end
|
||||
function getKeys(config)
|
||||
return
|
||||
-- Volume control
|
||||
config.raiseVolume ~= nil and awful.key({}, config.raiseVolume, raiseVolume,
|
||||
{ description = "Raise volume", group = "media control" }) or nil,
|
||||
config.lowerVolume ~= nil and awful.key({}, config.lowerVolume, lowerVolume,
|
||||
{ description = "Lower volume", group = "media control" }) or nil,
|
||||
config.toggleMute ~= nil and awful.key({}, config.toggleMute, toggleMute,
|
||||
{ description = "Toggle mute audio", group = "media control" }) or nil,
|
||||
hotkey.make(config.raiseVolume, raiseVolume,
|
||||
{ description = "Raise volume", group = "media control" }),
|
||||
hotkey.make(config.lowerVolume, lowerVolume,
|
||||
{ description = "Lower volume", group = "media control" }),
|
||||
hotkey.make(config.toggleMute, toggleMute,
|
||||
{ description = "Toggle mute audio", group = "media control" }),
|
||||
|
||||
-- Media control
|
||||
config.playPause ~= nil and awful.key({}, config.playPause, playPause,
|
||||
{ description = "Toggle Play / Pause", group = "media control" }) or nil,
|
||||
config.nextTrack ~= nil and awful.key({}, config.nextTrack, nextTrack,
|
||||
{ description = "Next track", group = "media control" }) or nil,
|
||||
config.previousTrack ~= nil and awful.key({}, config.previousTrack, previousTrack,
|
||||
{ description = "Previous track", group = "media control" }) or nil
|
||||
-- Media control
|
||||
hotkey.make(config.playPause, playPause,
|
||||
{ description = "Toggle Play / Pause", group = "media control" }),
|
||||
hotkey.make(config.nextTrack, nextTrack,
|
||||
{ description = "Next track", group = "media control" }),
|
||||
hotkey.make(config.previousTrack, previousTrack,
|
||||
{ description = "Previous track", group = "media control" })
|
||||
end
|
||||
|
||||
return {
|
||||
|
26
simple/widgets/keyboard_layout.lua
Normal file
26
simple/widgets/keyboard_layout.lua
Normal file
@ -0,0 +1,26 @@
|
||||
local awful = require("awful")
|
||||
|
||||
local hotkey = require("simple/core/hotkey")
|
||||
|
||||
local config = require("config")
|
||||
|
||||
|
||||
local widget = awful.widget.keyboardlayout()
|
||||
local layouts = config.widgets.keyboard_layout.layouts
|
||||
|
||||
local current_layout_index = 1
|
||||
function switchLayout()
|
||||
current_layout_index = (current_layout_index % #(layouts)) + 1
|
||||
os.execute(config.widgets.keyboard_layout.layout_switch_command .. " " .. layouts[current_layout_index])
|
||||
end
|
||||
|
||||
return {
|
||||
widget = widget,
|
||||
switch = switchLayout,
|
||||
getKeys = function(config)
|
||||
return hotkey.make(config.switch, switchLayout,
|
||||
{ description = "switch keyboard layout" }),
|
||||
hotkey.make(config.switch_alt, switchLayout,
|
||||
{ description = "switch keyboard layout (alternative)" })
|
||||
end
|
||||
}
|
Loading…
Reference in New Issue
Block a user