/lua-xlib

Lua bindings for XLib and XRandR

Primary LanguageCGNU General Public License v3.0GPL-3.0

lua-xlib

License Build Status (GitHub Actions) LuaRocks Package

Lua bindings for XLib and libxrandr.

Archived just 3 weeks after the first commit? What’s going on?

When I started this project, I knew that XCB existed as a newer option to XLib. What I didn’t know was the extend of what XCB replaces in XLib’s ecosystem.

The initial trigger for lua-xlib was the need for XRandR bindings, with only adding as many XLib functions as was needed to make the XRandR function usable. The fact that all of libxrandr's calls are blocking didn’t feel right, but I figured that this might just be necessary for this protocol specifically.

Only when I casually browsed the XCB docs did I realize that it seems to be intended as a replacement for all of the XLib ecosystem, including RandR, Render and other protocol additions. So, after learning that and the non-blocking nature of XCB, and reading the XLib vs XCB rational, I now consider XCB bindings to be a better fit for my use case.

Nonetheless, the things implemented in lua-xlib so far should still work.

Quick Start

Install lua-xlib via LuaRocks:

luarocks install lua-xlib
local xlib = require("xlib")
local xrandr = require("xlib.xrandr")

local function find_by_size(list, w, h)
  for _, v in ipairs(list) do
    if v.width == w and v.height == h then
      return v
    end
  end
end

local display = xlib.XOpenDisplay()
local screen = xlib.DefaultScreen(display)
local root = xlib.RootWindow(display, screen)
local res = xrandr.XRRGetScreenResources(display, root)
local info = xrandr.XRRGetCrtcInfo(display, res, res.crtcs[1])
local mode = find_by_size(res.mode, 1600, 900)

xrandr.XRRSetCrtcConfig(
  display,
  res,
  res.ctcs[1]
  info.timestamp,
  info.x,
  info.y,
  mode.id,
  info.rotation,
  info.outputs
)