awesomeWM / awesome

awesome window manager
https://awesomewm.org/
GNU General Public License v2.0
6.37k stars 598 forks source link

Should awesome-client require awful/wibox/naughty/gears/... by default? #1166

Open Elv13 opened 8 years ago

Elv13 commented 8 years ago

All is in the title. I checked the logs and many common use case need extra require("awful").do_somehting. Given awesome-client is limited when it comes to variables definition and that all "globals" such as client are defined. I was wondering if we should require all common libraries by default (same ones as rc.lua)? Also, an awesome-clientrc.lua could be a good idea? This file could define some functions/variables available when using the tool. This also confuse the users a lot when they see the error popup.

 grep -C5 awesome-client logs/*awe* | grep -iE -C999 "(error|undefined|attempt to index)" --color

Show 5 this year alone (I am connected ~30% of the time)

It can be hacked into remote.lua to avoid setting "real" globals.

psychon commented 8 years ago

Importing useful things by default sounds good. Dunno about awesome-clientrc.lua. Such a file would further complicate our build system and be hard to find / learn about. How about awful.remote exporting its "global env table" as awful.remote.env or something like that and people can add entries to it by modifying this tbale?

Implementation-wise, this sounds like "Yay, fun with differences between Lua versions". Also, this brings fun with cyclic dependencies (awful.remote depending on awful).

Just to think about what the differences are, Lua 5.2 and 5.3 need something like this:

load(code, nil, ni, setmetatable({ awful = require("awful"), etc }, { __index = _G, __newindex = _G }))

Lua 5.1 (and thus likely also LuaJIT) need:

local f = load(code)
setfenv(f, setmetatable({ awful = require("awful"), etc }, { __index = _G, __newindex = _G }))