2013-04-25 4 views
0

Я не уверен, что это нормально спросить об этом здесь, поэтому скажите мне, если это не так :). Я понятия не имею, где еще спросить.Awesome WM 3.5 отдельные конфигурационные файлы

У меня проблема с Awesome WM. Я пытаюсь отделить rc.lua в разные файлы (потому что они начинаются долго) и просто загружать их в rc.lua.

У меня есть функция для изменения раскладки xrandr. Этот код отлично работает, когда он вставлен непосредственно в rc.lua.

-- Xrandr settings switcher -- 
-- Get active outputs 
local function outputs() 
    local outputs = {} 
    local xrandr = io.popen("xrandr -q") 
    if xrandr then 
     for line in xrandr:lines() do 
    output = line:match("^([%w-]+) connected ") 
    if output then 
     outputs[#outputs + 1] = output 
    end 
     end 
     xrandr:close() 
    end 

    return outputs 
end 

local function arrange(out) 
    -- We need to enumerate all the way to combinate output. We assume 
    -- we want only an horizontal layout. 
    local choices = {} 
    local previous = { {} } 
    for i = 1, #out do 
     -- Find all permutation of length `i`: we take the permutation 
     -- of length `i-1` and for each of them, we create new 
     -- permutations by adding each output at the end of it if it is 
     -- not already present. 
     local new = {} 
     for _, p in pairs(previous) do 
    for _, o in pairs(out) do 
     if not awful.util.table.hasitem(p, o) then 
      new[#new + 1] = awful.util.table.join(p, {o}) 
     end 
    end 
     end 
     choices = awful.util.table.join(choices, new) 
     previous = new 
    end 

    return choices 
end 

-- Build available choices 
local function menu() 
    local menu = {} 
    local out = outputs() 
    local choices = arrange(out) 

    for _, choice in pairs(choices) do 
     local cmd = "xrandr" 
     -- Enabled outputs 
     for i, o in pairs(choice) do 
    cmd = cmd .. " --output " .. o .. " --auto" 
    if i > 1 then 
     cmd = cmd .. " --right-of " .. choice[i-1] 
    end 
     end 
     -- Disabled outputs 
     for _, o in pairs(out) do 
    if not awful.util.table.hasitem(choice, o) then 
     cmd = cmd .. " --output " .. o .. " --off" 
    end 
     end 

     local label = "" 
     if #choice == 1 then 
    label = 'Only <span weight="bold">' .. choice[1] .. '</span>' 
     else 
    for i, o in pairs(choice) do 
     if i > 1 then label = label .. " + " end 
     label = label .. '<span weight="bold">' .. o .. '</span>' 
    end 
     end 

     menu[#menu + 1] = { label, 
       cmd, 
          "/usr/share/icons/Tango/32x32/devices/display.png"} 
    end 
    return menu 
end 

-- Display xrandr notifications from choices 
local state = { iterator = nil, 
     timer = nil, 
     cid = nil } 
local function xrandr() 
    -- Stop any previous timer 
    if state.timer then 
     state.timer:stop() 
     state.timer = nil 
    end 

    -- Build the list of choices 
    if not state.iterator then 
     state.iterator = awful.util.table.iterate(menu(), 
        function() return true end) 
    end 

    -- Select one and display the appropriate notification 
    local next = state.iterator() 
    local label, action, icon 
    if not next then 
     label, icon = "Keep the current configuration", "/usr/share/icons/Tango/32x32/devices/display.png" 
     state.iterator = nil 
    else 
     label, action, icon = unpack(next) 
    end 
    state.cid = naughty.notify({ text = label, 
       icon = icon, 
       timeout = 4, 
       screen = mouse.screen, -- Important, not all screens may be visible 
       font = "Free Sans 18", 
       replaces_id = state.cid }).id 

    -- Setup the timer 
    state.timer = timer { timeout = 4 } 
    state.timer:connect_signal("timeout", 
       function() 
       state.timer:stop() 
       state.timer = nil 
       state.iterator = nil 
       if action then 
       awful.util.spawn(action, false) 
       end 
       end) 
    state.timer:start() 
end 

Я сохраняю его как xrandr.lua и вставляю его в папку awesome/rc.

Тогда у меня есть функция в rc.lua для загрузки файлов из папки "гс" (from here):

function loadrc(name, mod) 
    local success 
    local result 

    -- Which file? In rc/ or in lib/? 
    local path = awful.util.getdir("config") .. "/" .. 
     (mod and "lib" or "rc") .. 
     "/" .. name .. ".lua" 

    -- If the module is already loaded, don't load it again 
    if mod and package.loaded[mod] then return package.loaded[mod] end 

    -- Execute the RC/module file 
    success, result = pcall(function() return dofile(path) end) 
    if not success then 
     naughty.notify({ title = "Error while loading an RC file", 
       text = "When loading `" .. name .. 
       "`, got the following error:\n" .. result, 
       preset = naughty.config.presets.critical 
      }) 
     return print("E: error loading RC file '" .. name .. "': " .. result) 
    end 

    -- Is it a module? 
    if mod then 
     return package.loaded[mod] 
    end 

    return result 
end 

Тогда я наклеен 'loadrc ("XRandR")' в моем rc.lua, но ничего случается. Я пробовал разные файлы (например, простой виджет, а затем loadrc этот файл виджета), но все, что я получаю, это всего лишь пакет ошибок, и он не работает.

Я также пробовал просто: «require (« xrandr »)», но все тот же.

Я попытался Google, но все для awesome 3.4, и я не очень опытен в коде Lua. Спасибо за помощь

+0

Я думаю, что вы можете искать dofile() вместо require() (и loadrc() просто не существует). Может ли это быть правильно? –

+0

Да, но когда я пишу «dofile (« xrandr.lua »), где xrandr.lua является частью этого кода, я просто получаю ошибки. – kotrfa

+0

Ну, какие ошибки? –

ответ

3

В принципе, require("xrandr") в ~/.config/awesome/rc.lua говорит Lua, чтобы осмотреться файл с именем xrandr.lua в ~/.config/awesome/ в то время как вы храните его в ~/.config/awesome/rc/. Вот почему он ничего не может найти. Это должно сделать трюк:

require("rc.xrandr")

0

Вы можете вдохновить себя другими народами конфиги: rc.lua

В принципе, как envolyse сказал, требуют (что-то) будет смотреть на ROOTDIR/something.lua, в то время как require (somedir.something) рассмотрит rootdir/somedir/something.

Вы все еще нужно будет делать звонки от фильме something.rc хотя (включая библиотеки):

myrc.lua: 

local naughty = require("naughty"); 
naughty.somecall(); 

так Lua 5.2, вам нужно будет использовать локальную переменную для хранения указателей, включенных LIBS, на старых версии lua plain "требуют (" непослушный "); было бы достаточно.

Счастливый взлом.

 Смежные вопросы

  • Нет связанных вопросов^_^