From 840f084db8b9b55848f9732d0cccc019c308b5c2 Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 16 Jul 2022 14:13:03 -0700 Subject: [PATCH] Started migrating to module architecture --- bin/init.lua | 10 -- binds/init.lua | 2 - desktop/init.lua | 8 +- desktop/widgets/keymap.lua | 41 ------- modules/ibus/init.lua | 12 ++ .../input.lua => modules/ibus/keybinds.lua | 23 +++- .../language.lua => modules/ibus/popup.lua | 74 +++++------- modules/ibus/util.lua | 94 +++++++++++++++ modules/ibus/widget.lua | 72 ++++++++++++ modules/mpc/init.lua | 6 + .../mpd.lua => modules/mpc/keybinds.lua | 22 ++-- modules/mpc/util.lua | 19 +++ .../widgets/mpc.lua => modules/mpc/widget.lua | 109 +++++++++--------- rc.lua | 63 +++++++--- wrapper/ibus.lua | 102 ---------------- wrapper/init.lua | 1 - 16 files changed, 369 insertions(+), 289 deletions(-) delete mode 100755 desktop/widgets/keymap.lua create mode 100644 modules/ibus/init.lua rename binds/system/input.lua => modules/ibus/keybinds.lua (57%) rename desktop/popups/language.lua => modules/ibus/popup.lua (55%) create mode 100644 modules/ibus/util.lua create mode 100755 modules/ibus/widget.lua create mode 100644 modules/mpc/init.lua rename binds/system/mpd.lua => modules/mpc/keybinds.lua (67%) create mode 100644 modules/mpc/util.lua rename desktop/widgets/mpc.lua => modules/mpc/widget.lua (64%) delete mode 100644 wrapper/ibus.lua diff --git a/bin/init.lua b/bin/init.lua index 8eecb22..fb2c7dc 100755 --- a/bin/init.lua +++ b/bin/init.lua @@ -72,15 +72,5 @@ return { --awful.spawn("flameshot gui -p \"" .. conf.screenshot_dir .. "\"", false) awful.spawn("flameshot gui", false) end - }, - - mpc = { - watch = function(command, timeout, callback, widget) - awful.widget.watch("mpc --host " .. conf.mpd_host .. " " .. command, timeout, callback, widget) - end, - - command = function(command, callback) - awful.spawn.easy_async("mpc --host " .. conf.mpd_host .. " " .. command, callback) - end } } diff --git a/binds/init.lua b/binds/init.lua index 8a8c17b..50d6d79 100755 --- a/binds/init.lua +++ b/binds/init.lua @@ -1,10 +1,8 @@ return { keys = gears.table.join( require("binds.system.backlight"), - require("binds.system.mpd"), require("binds.system.volume"), require("binds.system.system"), - require("binds.system.input"), require("binds.window.client"), require("binds.window.layout"), diff --git a/desktop/init.lua b/desktop/init.lua index fbd00ff..c728de7 100755 --- a/desktop/init.lua +++ b/desktop/init.lua @@ -1,15 +1,11 @@ local desktop = { Tagger = require("desktop.tagger"), - popup = { - language = require("desktop.popups.language") - }, - widgets = { tasklist = require("desktop.widgets.tasklist"), textclock = require("desktop.widgets.textclock"), layoutbox = require("desktop.widgets.layoutbox"), - keymap = require("desktop.widgets.keymap"), + keymap = modules.ibus.widgets.ibus, volume = require("desktop.widgets.volume"), tagindicator = require("desktop.widgets.tagindicator"), launcher = require("desktop.widgets.launcher"), @@ -56,7 +52,7 @@ if conf.battery_enabled then desktop.widgets.battery = require("desktop.widgets.battery") end if conf.mpc_enabled then - desktop.widgets.mpc = require("desktop.widgets.mpc") + desktop.widgets.mpc = modules.mpc.widgets.mpc end diff --git a/desktop/widgets/keymap.lua b/desktop/widgets/keymap.lua deleted file mode 100755 index 848b6c9..0000000 --- a/desktop/widgets/keymap.lua +++ /dev/null @@ -1,41 +0,0 @@ -local keymap = {} - - -keymap.widget = wibox.widget { - { - { -- Right spacer - widget = wibox.widget.separator, - color = beautiful.color.transparent, - forced_width = beautiful.dpi(3) - }, - wibox.widget { - wrapper.ibus.ibus_indicator_text, - wrapper.ibus.xkb_indicator_text, - - forced_num_cols = 1, - forced_num_rows = 2, - homogeneous = true, - expand = true, - layout = wibox.layout.grid - }, - { -- Left spacer - widget = wibox.widget.separator, - color = beautiful.color.transparent, - forced_width = beautiful.dpi(3) - }, - - layout = wibox.layout.align.horizontal, - }, - layout = wibox.container.background, -} - - --- Change background when mouse is over widget -keymap.widget:connect_signal("mouse::enter", function(result) - keymap.widget.bg = beautiful.color.bar.hover_bg -end) - -keymap.widget:connect_signal("mouse::leave", function(result) - keymap.widget.bg = beautiful.color.transparent -end) -return keymap.widget diff --git a/modules/ibus/init.lua b/modules/ibus/init.lua new file mode 100644 index 0000000..3f108a4 --- /dev/null +++ b/modules/ibus/init.lua @@ -0,0 +1,12 @@ +local util = require("modules.ibus.util") + +return { + widgets = { + ibus = require("modules.ibus.widget").widget + }, + keybinds = require("modules.ibus.keybinds"), + + init = function() + util.set(1) + end +} diff --git a/binds/system/input.lua b/modules/ibus/keybinds.lua similarity index 57% rename from binds/system/input.lua rename to modules/ibus/keybinds.lua index 5bc4c56..2026c86 100644 --- a/binds/system/input.lua +++ b/modules/ibus/keybinds.lua @@ -1,25 +1,42 @@ +local util = req_rel(..., "util") +local popup = req_rel(..., "popup") +local widget = req_rel(..., "widget") + return gears.table.join( awful.key( {"Mod4"}, "space", function() - desktop.popup.language.next() + util.next(function() + popup.update() + widget.update() + end) end, { description = "Change input language", group = "System" } ), + + awful.key( {"Mod4", "Shift", "Control"}, "9", function() - desktop.popup.language.set(2) + util.set(2, function() + popup.update() + widget.update() + end) end, { description = "Set input language to RU", group = "System" } ), + + awful.key( {"Mod4", "Shift", "Control"}, "0", function() - desktop.popup.language.set(1) + util.set(1, function() + popup.update() + widget.update() + end) end, { description = "Set input language to EN", diff --git a/desktop/popups/language.lua b/modules/ibus/popup.lua similarity index 55% rename from desktop/popups/language.lua rename to modules/ibus/popup.lua index 9a9f7be..cdb6ed4 100644 --- a/desktop/popups/language.lua +++ b/modules/ibus/popup.lua @@ -1,10 +1,8 @@ -local language = {} +local popup = {} +local util = req_rel(..., "util") -language.language_list = conf.ibus_language_list - - -language.widget = wibox.widget { +popup.widget = wibox.widget { homogeneous = false, vertical_homogeneous = true, horizontal_homogeneous = false, @@ -16,7 +14,7 @@ language.widget = wibox.widget { } -for k, l in pairs(language.language_list) do +for k, l in pairs(conf.ibus_language_list) do l["widget_checkbox"] = wibox.widget { checked = false, @@ -44,52 +42,33 @@ for k, l in pairs(language.language_list) do l["widget_text"].bg = "#00000000" - language.widget:add_widget_at(l["widget_text"], k, 1, 1, 1) - --language.widget:add_widget_at(l["widget_checkbox"], k, 1, 1, 1) - --language.widget:add_widget_at(l["widget_text"], k, 2, 0, 1) + popup.widget:add_widget_at(l["widget_text"], k, 1, 1, 1) + --popup.widget:add_widget_at(l["widget_checkbox"], k, 1, 1, 1) + --popup.widget:add_widget_at(l["widget_text"], k, 2, 0, 1) end -language.next = function() - if (language.popup.visible) then - wrapper.ibus.next(function() - language.update_checks() - end) - else - language.update_checks() - end - - language.show_popup() -end - -language.set = function(idx) - wrapper.ibus.set(idx, function() - language.update_checks() - end) - language.show_popup() -end - -language.update_checks = function() - for _, l in pairs(language.language_list) do - if (wrapper.ibus.current_engine == l["ibus_engine"]) then +popup.update = function() + -- Update checkmarks + for _, l in pairs(conf.ibus_language_list) do + if (util.current_engine == l["ibus_engine"]) then l["widget_text"].bg = "#FF0000" else l["widget_text"].bg = "#00000000" end - l["widget_checkbox"].checked = (wrapper.ibus.current_engine == l["ibus_engine"]) + l["widget_checkbox"].checked = (util.current_engine == l["ibus_engine"]) end + + -- Show popup + popup.popup.screen = awful.screen.focused() + popup.popup.visible = true + popup.popup_timer:again() end -language.show_popup = function() - language.popup.screen = awful.screen.focused() - language.popup.visible = true - language.popup_timer:again() -end - -language.popup = awful.popup { +popup.popup = awful.popup { widget = { { - language.widget, + popup.widget, margins = 10, widget = wibox.container.margin }, @@ -108,22 +87,25 @@ language.popup = awful.popup { shape = gears.shape.rectangle, placement = function(d) - return awful.placement.bottom_right(d, { - honor_workarea = true - }) + return awful.placement.bottom_right( + d, + { + honor_workarea = true + } + ) end, } -language.popup_timer = gears.timer { +popup.popup_timer = gears.timer { timeout = 1, autostart = false, call_now = false, single_shot = true, callback = function() - language.popup.visible = false + popup.popup.visible = false end } -return language +return popup diff --git a/modules/ibus/util.lua b/modules/ibus/util.lua new file mode 100644 index 0000000..4f5705c --- /dev/null +++ b/modules/ibus/util.lua @@ -0,0 +1,94 @@ +local util = {} + +util.current_engine = "" +util.current_engine_index = nil +util.current_xkbmap = "" + + +-- Update current_engine and current_engine index, +-- call callback() when done. +util.get = function(callback) + -- Get current ibus engine + awful.spawn.easy_async( + "ibus engine", + function(stdout, stderr, exitreason, exitcode) + util.current_engine = string.gsub(stdout, "\n", "") + util.current_engine_index = nil + + -- Find the current engine's index in conf.ibus_language_list. + -- If it is not there, util.current_engine_index will be nil. + for k, v in pairs(conf.ibus_language_list) do + if (v["ibus_engine"] == util.current_engine) then + util.current_engine_index = k + end + end + + -- Get current xkbmap + awful.spawn.easy_async( + "setxkbmap -query", + function(stdout, stderr, exitreason, exitcode) + util.current_xkbmap = string.match(stdout, "layout:%s+(%w+)") + + -- When everything is done, run callback if it is given. + if callback then + callback() + end + end + ) + end + ) +end + + +-- Set engine to language_index. +-- calls util.get(callback) when done. +util.set = function(language_index, callback) + -- engine is an index of the language list above + + local engine = conf.ibus_language_list[language_index]["ibus_engine"] + + -- Get required engine, if one is given + local requires_engine + for k, v in pairs(conf.ibus_language_list) do + if (v["ibus_engine"] == engine) then + requires_engine = v["requires_engine"] + end + end + + -- If a required xkb engine is given, but it is not active, switch to it before switching to the target + if (requires_engine ~= util.current_engine) and (requires_engine ~= nil) then + awful.spawn.easy_async( + "ibus engine " .. requires_engine, + function(stdout, stderr, exitreason, exitcode) + awful.spawn.easy_async( + "ibus engine " .. engine, + function(stdout, stderr, exitreason, exitcode) + util.get(callback) + end + ) + end + ) + else + awful.spawn.easy_async( + "ibus engine " .. engine, + function(stdout, stderr, exitreason, exitcode) + util.get(callback) + end + ) + end +end + + +-- Calls util.set(callback) with next language in list. +util.next = function(callback) + if (util.current_engine_index == nil) or (util.current_engine_index == #conf.ibus_language_list) then + util.current_engine_index = 1 + else + util.current_engine_index = util.current_engine_index + 1 + end + util.set(util.current_engine_index, callback) +end + + + +return util diff --git a/modules/ibus/widget.lua b/modules/ibus/widget.lua new file mode 100755 index 0000000..796d7c4 --- /dev/null +++ b/modules/ibus/widget.lua @@ -0,0 +1,72 @@ +local util = req_rel(..., "util") +local widget = {} + +widget.ibus_indicator_text = wibox.widget.textbox("??") +widget.ibus_indicator_text.valign = "center" +widget.ibus_indicator_text.align = "center" +widget.ibus_indicator_text.font = "Hack NF 14" + +widget.xkb_indicator_text = wibox.widget.textbox("??") +widget.xkb_indicator_text.valign = "center" +widget.xkb_indicator_text.align = "center" +widget.xkb_indicator_text.font = "Hack NF 10" + + +widget.widget = wibox.widget { + { + { -- Right spacer + widget = wibox.widget.separator, + color = beautiful.color.transparent, + forced_width = beautiful.dpi(3) + }, + + wibox.widget { + widget.ibus_indicator_text, + widget.xkb_indicator_text, + + forced_num_cols = 1, + forced_num_rows = 2, + homogeneous = true, + expand = true, + layout = wibox.layout.grid + }, + + { -- Left spacer + widget = wibox.widget.separator, + color = beautiful.color.transparent, + forced_width = beautiful.dpi(3) + }, + + layout = wibox.layout.align.horizontal, + }, + layout = wibox.container.background, +} + + +-- Change background when mouse is over widget +widget.widget:connect_signal("mouse::enter", function(result) + widget.widget.bg = beautiful.color.bar.hover_bg +end) + +widget.widget:connect_signal("mouse::leave", function(result) + widget.widget.bg = beautiful.color.transparent +end) + +widget.update = function() + widget.ibus_indicator_text.markup = conf.ibus_language_list[util.current_engine_index]["indicator_code"] + widget.xkb_indicator_text.markup = util.current_xkbmap +end + + +-- Update every 2 seconds, just in case. +widget.update_timer = gears.timer { + timeout = 2, + call_now = false, + autostart = true, + single_shot = false, + callback = function () + util.get(widget.update) + end +} + +return widget diff --git a/modules/mpc/init.lua b/modules/mpc/init.lua new file mode 100644 index 0000000..94c0ef3 --- /dev/null +++ b/modules/mpc/init.lua @@ -0,0 +1,6 @@ +return { + widgets = { + mpc = require("modules.mpc.widget").widget + }, + keybinds = require("modules.mpc.keybinds") +} diff --git a/binds/system/mpd.lua b/modules/mpc/keybinds.lua similarity index 67% rename from binds/system/mpd.lua rename to modules/mpc/keybinds.lua index 476af5a..5307216 100755 --- a/binds/system/mpd.lua +++ b/modules/mpc/keybinds.lua @@ -1,51 +1,53 @@ +local mpc = req_rel(..., "util") + return gears.table.join( awful.key( {}, "XF86AudioPrev", function () - bin.mpc.command("prev") + mpc.mpc_command("prev") end, { description = "Previous track", - group = "MPD" + group = "MPC" } ), awful.key( {}, "XF86AudioPlay", function () - bin.mpc.command("toggle") + mpc.mpc_command("toggle") end, { description = "Play/Pause", - group = "MPD" + group = "MPC" } ), awful.key( {}, "XF86AudioNext", function () - bin.mpc.command("next") + mpc.mpc_command("next") end, { description = "Next track", - group = "MPD" + group = "MPC" } ), awful.key( {"Mod4"}, "XF86AudioRaiseVolume", function () - bin.mpc.command("vol +5") + mpc.mpc_command("vol +5") end, { description = "Volume up", - group = "MPD" + group = "MPC" } ), awful.key( {"Mod4"}, "XF86AudioLowerVolume", function () - bin.mpc.command("vol -5") + mpc.mpc_command("vol -5") end, { description = "Volume down", - group = "MPD" + group = "MPC" } ) ) diff --git a/modules/mpc/util.lua b/modules/mpc/util.lua new file mode 100644 index 0000000..edc07c3 --- /dev/null +++ b/modules/mpc/util.lua @@ -0,0 +1,19 @@ +local util = {} + +util.mpc_command = function(command, callback) + awful.spawn.easy_async( + "mpc --host " .. conf.mpd_host .. " " .. command, + callback + ) +end + +util.mpc_watch = function(command, timeout, callback, widget) + awful.widget.watch( + "mpc --host " .. conf.mpd_host .. " " .. command, + timeout, + callback, + widget + ) +end + +return util diff --git a/desktop/widgets/mpc.lua b/modules/mpc/widget.lua similarity index 64% rename from desktop/widgets/mpc.lua rename to modules/mpc/widget.lua index 4704ee1..d3fd787 100644 --- a/desktop/widgets/mpc.lua +++ b/modules/mpc/widget.lua @@ -1,3 +1,4 @@ +local mpc = req_rel(..., "util") local mpc_widget = {} mpc_widget.title = wibox.widget.textbox("MPD is not") @@ -64,7 +65,6 @@ mpc_widget.right = wibox.widget { layout = wibox.container.background, } - mpc_widget.widget = wibox.widget { { { -- Right spacer @@ -87,7 +87,7 @@ mpc_widget.widget = wibox.widget { } -mpc_widget.widget:connect_signal("mouse::enter", function(result) +mpc_widget.widget:connect_signal("mouse::enter",function(result) mpc_widget.widget.bg = beautiful.color.bar.hover_bg end) @@ -99,7 +99,7 @@ end) mpc_widget.widget:connect_signal("button::press", function(_, _, _, button, mods) if (button == 3) or (button == 1)then - bin.mpc.command("toggle") + mpc.mpc_command("toggle") end mpc_widget.readupdate() end @@ -109,9 +109,9 @@ mpc_widget.widget:connect_signal("button::press", mpc_widget.right:connect_signal("button::press", function(_, _, _, button, mods) if (button == 4) then -- Scroll up - bin.mpc.command("prev") + mpc.mpc_command("prev") elseif (button == 5) then -- Scroll down - bin.mpc.command("next") + mpc.mpc_command("next") end mpc_widget.readupdate() @@ -122,72 +122,77 @@ mpc_widget.right:connect_signal("button::press", mpc_widget.left:connect_signal("button::press", function(_, _, _, button, mods) if (button == 4) then -- Scroll up - bin.mpc.command("volume +5") + mpc.mpc_command("volume +5") elseif (button == 5) then -- Scroll down - bin.mpc.command("volume -5") + mpc.mpc_command("volume -5") end mpc_widget.readupdate() end ) - -mpc_widget.update = function(stdout) - if (stdout == "") then - return - end - - mpc_widget.title.markup = string.match(stdout, "title=(.*)artist=") - mpc_widget.artist.markup = string.match(stdout, "artist=(.*)") - - -end - - -mpc_widget.update_status = function(stdout) - play = string.match(stdout, "(%[playing)") or false - pause = string.match(stdout, "(%[paused)") or false - stop = not (play or pause) - - if (play) then - mpc_widget.icon_play.image = beautiful.icons.music.blue.playing - elseif (pause) then - mpc_widget.icon_play.image = beautiful.icons.music.blue.paused - elseif (stop) then - mpc_widget.icon_play.image = beautiful.icons.music.blue.stopped - end - - volume = string.match(stdout, "volume: (%d?%d?%d)%%") - if (volume) then - mpc_widget.volume.markup = volume .. "%" - else - mpc_widget.volume.markup = "" - end -end - mpc_widget.readupdate = function() - bin.mpc.command("current --format \"title=%title% artist=%artist%\"", + -- Update title and artist + mpc.mpc_command("current --format \"title=%title% artist=%artist%\"", function(stdout, stderr, exitreason, exitcode) - mpc_widget.update(stdout) + if (stdout == "") then + return + end + + mpc_widget.title.markup = string.match(stdout, "title=(.*)artist=") + mpc_widget.artist.markup = string.match(stdout, "artist=(.*)") end ) - bin.mpc.command("status", + -- Update status + mpc.mpc_command("status", function(stdout, stderr, exitreason, exitcode) - mpc_widget.update_status(stdout) + local play = string.match(stdout, "(%[playing)") or false + local pause = string.match(stdout, "(%[paused)") or false + local stop = not (play or pause) + + if (play) then + mpc_widget.icon_play.image = beautiful.icons.music.blue.playing + elseif (pause) then + mpc_widget.icon_play.image = beautiful.icons.music.blue.paused + elseif (stop) then + mpc_widget.icon_play.image = beautiful.icons.music.blue.stopped + end + + local volume = string.match(stdout, "volume: (%d?%d?%d)%%") + if (volume) then + mpc_widget.volume.markup = volume .. "%" + else + mpc_widget.volume.markup = "" + end end ) end --- The time here is super short because the --wait option is used in mpc. --- It will not return a response until changes are seen. -bin.mpc.watch("current --wait", 0.01, function(_, stdout) mpc_widget.readupdate() end, mpc_widget.widget) -bin.mpc.watch("current", 1, function(_, stdout) mpc_widget.readupdate() end, mpc_widget.widget) +-- Short delay here, the --wait option makes mpc block until +-- a change is detected. +mpc.mpc_watch( + "current --wait", + 0.01, + function(_, stdout) + mpc_widget.readupdate() + end, + mpc_widget.widget +) + +mpc.mpc_watch( + "current", + 1, + function(_, stdout) + mpc_widget.readupdate() + end, + mpc_widget.widget +) --- Make sure you do an initial read, though, otherwise the widget will --- not update until a change occurs. +-- Make sure you do an initial read, otherwise the widget will +-- not update until a change occurs. mpc_widget.readupdate() -return mpc_widget.widget +return mpc_widget diff --git a/rc.lua b/rc.lua index c2321cc..cd45531 100755 --- a/rc.lua +++ b/rc.lua @@ -1,6 +1,4 @@ --- Load libaries. --- We only need to load these once. --- These are global variables, all scripts can access them +-- AwesomeWM core gears = require("gears") awful = require("awful") naughty = require("naughty") @@ -11,31 +9,73 @@ configuration_dir = gears.filesystem.get_configuration_dir() require("awful.autofocus") +-- A "relative require" hack. Does the same thing as `require,` +-- But takes a relative path. +-- Called with req_rel(..., "module") +function req_rel(ddd, modname) + local parent_folder = (ddd):match("(.-)[^%.]+$") + return require(parent_folder .. modname) +end -- Quick debug function debug_message = function(msg) naughty.notify({title = "Debug message:", text = tostring(msg)}) end - -- These must be loaded in order. -- Make sure you've created conf.lua! conf = require("conf") -conf.sound_dir = configuration_dir .. "theme/resources/sounds/" -conf.icon_dir = configuration_dir .. "theme/resources/icons/" + layoutmanager = require("desktop.layoutmanager") layoutmanager.layouts = conf.layouts bin = require("bin") wrapper = require("wrapper") -wrapper.ibus.set(1) + beautiful.init(require("theme")) + + +-- Load key bindings +local binds = require("binds") +local keys = binds.keys +local buttons = binds.buttons + +-- Load modules +modules = {} +for k, v in ipairs({ + "mpc", + "ibus" +}) do + modules[v] = require("modules." .. v) + + -- If module defines keybinds, load keybinds. + if (modules[v]["keybinds"] ~= nil) then + keys = gears.table.join( + keys, + modules[v]["keybinds"] + ) + end +end + +-- Run all module init methods +for _, mod in ipairs(modules) do + if (mod["init"] ~= nil) then + mod["init"]() + end +end + + +-- Finalize keys +root.keys(keys) +root.buttons(buttons) + desktop = require("desktop") + -- Autostart for i, v in ipairs(conf.startup_commands) do awful.spawn(v) @@ -55,15 +95,6 @@ terminal = conf.terminal menubar.utils.terminal = terminal ------------------- --- Load Modules -- ------------------- --- Load key bindings -local binds = require("binds") -root.keys(binds.keys) -root.buttons(binds.buttons) - - -- Load client methods awful.rules.rules = require("clients.rules") dofile(configuration_dir .. "clients/signals.lua") diff --git a/wrapper/ibus.lua b/wrapper/ibus.lua deleted file mode 100644 index b0c3051..0000000 --- a/wrapper/ibus.lua +++ /dev/null @@ -1,102 +0,0 @@ -local ibus = {} - - -ibus.current_engine = "" -ibus.current_engine_index = nil - -ibus.ibus_indicator_text = wibox.widget.textbox("??") -ibus.ibus_indicator_text.valign = "center" -ibus.ibus_indicator_text.align = "center" -ibus.ibus_indicator_text.font = "Hack NF 14" - -ibus.xkb_indicator_text = wibox.widget.textbox("??") -ibus.xkb_indicator_text.valign = "center" -ibus.xkb_indicator_text.align = "center" -ibus.xkb_indicator_text.font = "Hack NF 10" - - -ibus.get = function(callback) - awful.spawn.easy_async("ibus engine", function(stdout, stderr, exitreason, exitcode) - -- Get current ibus engine, remove newlines from output. - ibus.current_engine = string.gsub(stdout, "\n", "") - ibus.current_engine_index = nil - - -- Find the current engine's index in conf.ibus_language_list. - -- If it is not there, ibus.current_engine_index will be nil. - for k, v in pairs(conf.ibus_language_list) do - if (v["ibus_engine"] == ibus.current_engine) then - ibus.current_engine_index = k - end - end - - if callback then - callback() - end - end) -end - - -ibus.update_indicator = function() - -- Update indicators - awful.spawn.easy_async("setxkbmap -query" , function(stdout, stderr, exitreason, exitcode) - ibus.ibus_indicator_text.markup = conf.ibus_language_list[ibus.current_engine_index]["indicator_code"] - ibus.xkb_indicator_text.markup = string.match(stdout, "layout:%s+(%w+)") - end) -end - -ibus.set = function(language_index, callback) - -- engine is an index of the language list above - - engine = conf.ibus_language_list[language_index]["ibus_engine"] - - -- Get required engine, if one is given - local requires_engine - for k, v in pairs(conf.ibus_language_list) do - if (v["ibus_engine"] == engine) then - requires_engine = v["requires_engine"] - end - end - - -- If a required xkb engine is given, but it is not active, switch to it before switching to the target - if (requires_engine ~= ibus.current_engine) and (requires_engine ~= nil) then - awful.spawn.easy_async("ibus engine " .. requires_engine, function(stdout, stderr, exitreason, exitcode) - awful.spawn.easy_async("ibus engine " .. engine, function(stdout, stderr, exitreason, exitcode) - ibus.update_indicator() - ibus.get(callback) - end) - end) - else - awful.spawn.easy_async("ibus engine " .. engine, function(stdout, stderr, exitreason, exitcode) - ibus.update_indicator() - ibus.get(callback) - end) - end -end - - -ibus.next = function(callback) - if (ibus.current_engine_index == nil) or (ibus.current_engine_index == #conf.ibus_language_list) then - ibus.current_engine_index = 1 - else - ibus.current_engine_index = ibus.current_engine_index + 1 - end - ibus.set(ibus.current_engine_index, callback) -end - --- Update the language indicator -ibus.update_timer = gears.timer { - timeout = 2, - call_now = false, - autostart = true, - single_shot = false, - - callback = function() - ibus.get( - function() - ibus.update_indicator() - end - ) - end -} - -return ibus diff --git a/wrapper/init.lua b/wrapper/init.lua index f1b56ef..0b85be8 100755 --- a/wrapper/init.lua +++ b/wrapper/init.lua @@ -2,6 +2,5 @@ return { backlight = require("wrapper.backlight"), volume = require("wrapper.volume"), sound = require("wrapper.sound"), - ibus = require("wrapper.ibus"), mdadm = require("wrapper.mdadm") }