Subject: qtile definitions to make it runs on wayland

From: Orahcio Felicio de Sousa <[email-masked]>
Date: Tue, 4 Feb 2025 02:17:00 +0000

When I run `qtile -b wayland` qtile gives an error, it does not find the
wlroots library. I could package some dependencies and then make some
changes on the official qtile recipe. I don't know how to send a patch, but
I will append my-qtile (based on the official one) and its additional
dependencies to run on wayland.

Additional dependencies for
qtile-wayland: python-pywlroots, python-pywayland, python-xkbcommon.
wlroots-0.17 needs to build qtile-wayland and python-pywlroots, the last
version on guix gives error.
qtile and pywlroots staff like to use "/usr/include" to find pixman and
libdrm headers, I use (substitute* to give the guix path after 'unpack
phase.

(define-module (python-qtile)
  #:use-module (gnu packages check)
  #:use-module (gnu packages freedesktop)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages libffi)
  #:use-module (gnu packages mpd)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages pulseaudio)
  #:use-module (gnu packages python-build)
  #:use-module (gnu packages python-crypto)
  #:use-module (gnu packages python-xyz)
  #:use-module (gnu packages time)
  #:use-module (gnu packages wm)
  #:use-module (gnu packages xdisorg)
  #:use-module (gnu packages xorg)
  #:use-module (guix download)
  #:use-module (guix gexp)
  #:use-module (guix packages)
  #:use-module (guix licenses)
  #:use-module (guix build-system python)
  #:use-module (guix build-system pyproject))

(define-public qtile-wayland
  (package
   (name "qtile-wayland")
   (version "0.30.0")
   (source
    (origin
     (method url-fetch)
     (uri (pypi-uri "qtile" version))
     (sha256
      (base32 "0zd2bh4mvgwjxkkwn3angkaqzm7ldcmzg3gdc098jzzlf90fmywm"))))
   (build-system pyproject-build-system)
   (arguments
    (list
     ;; A lot of tests fail despite Xvfb and writable temp/cache space.
     #:tests? #f
     #:test-flags
     #~(list "--ignore=test/widgets/test_widget_init_configure.py")
     #:phases
     #~(modify-phases %standard-phases
     (add-after 'unpack 'patch-paths
(lambda* (#:key inputs #:allow-other-keys)
  (substitute* "libqtile/pangocffi.py"
(("^(gobject = ffi.dlopen).*" all def)
(format #f "~a(~s)~%" def
(search-input-file inputs "/lib/libgobject-2.0.so.0")))
(("^(pango = ffi.dlopen).*" all def)
(format #f "~a(~s)~%" def
(search-input-file inputs "/lib/libpango-1.0.so.0")))
(("^(pangocairo = ffi.dlopen).*" all def)
(format #f "~a(~s)~%" def
(search-input-file
 inputs "/lib/libpangocairo-1.0.so.0"))))
  (substitute* "libqtile/backend/wayland/cffi/build.py"
(("/usr/include/pixman-1")
(string-append #$pixman
"/include/pixman-1"))
(("/usr/include/libdrm")
(string-append #$libdrm
"/include/libdrm")))))
     (add-after 'install 'install-xsessions
(lambda* (#:key outputs #:allow-other-keys)
  (let* ((out (assoc-ref outputs "out"))
 (xsessions (string-append out "/share/xsessions"))
 (qtile (string-append out "/bin/qtile start")))
    (mkdir-p xsessions)
    (copy-file "resources/qtile.desktop"
(string-append xsessions "/qtile.desktop"))
    (substitute* (string-append xsessions "/qtile.desktop")
 (("qtile start") qtile)))))
     (add-before 'check 'pre-check
 (lambda* (#:key tests? #:allow-other-keys)
   (when tests?
     (setenv "HOME" "/tmp")
     (system "Xvfb :1 &")
     (setenv "DISPLAY" ":1")
     (setenv "XDG_CACHE_HOME" "/tmp")))))))
   (inputs
    (list glib pango pulseaudio wlroots-0.17 pixman libdrm))
   (propagated-inputs
    (list python-cairocffi
          python-cffi
          python-dateutil
          python-dbus-fast
          python-iwlib
          python-keyring
          python-libcst
          python-mpd2
          python-pygobject
          python-pyxdg
          python-xcffib
 python-pywlroots
 python-pywayland
 python-xkbcommon))
   (native-inputs
    (list pkg-config
          python-flake8
          python-pep8-naming
          python-pytest
          python-pytest-cov
          python-psutil
          python-setuptools
          python-setuptools-scm
          python-wheel
          xorg-server-for-tests))
   (home-page "http://qtile.org")
   (synopsis "Hackable tiling window manager written and configured in
Python")
   (description "Qtile is simple, small, and extensible.  It's easy to write
your own layouts, widgets, and built-in commands.")
   (license expat)))

(define-public python-pywlroots
  (package
    (name "python-pywlroots")
    (version "0.17.0")
    (source
     (origin
       (method url-fetch)
       (uri "
https://github.com/flacjacket/pywlroots/archive/refs/tags/v0.17.0.tar.gz")
       (sha256
        (base32 "1ghbsdgmgpzhmfgr614bglmrlsgdl1bgdl1lg0y1i6cs9750qyv6"))))
    (build-system python-build-system)
    (arguments (list #:phases
    #~(modify-phases %standard-phases
     (add-before 'build 'set-pixman-path
 (lambda _
   (substitute* "wlroots/ffi_build.py"
(("/usr/include/pixman-1")
 (string-append #$pixman
"/include/pixman-1"))))))))
    (inputs (list wlroots-0.17 pixman))
    (propagated-inputs (list python-cffi python-pywayland python-xkbcommon))
    (native-inputs (list python-cffi python-pytest python-setuptools
                         python-wheel))
;;    (inputs (list wlroots-0.17))
    (home-page "https://github.com/flacjacket/pywlroots")
    (synopsis "Python binding to the wlroots library using cffi")
    (description "Python binding to the wlroots library using cffi.")
    (license ncsa)))

(define-public python-pywayland
  (package
    (name "python-pywayland")
    (version "0.4.18")
    (source
     (origin
       (method url-fetch)
       (uri (pypi-uri "pywayland" version))
       (sha256
        (base32 "0cv5aqn23id31mn95q6isn5vcnjcd4dvaqzn52ihbb9sg01dx2jr"))))
    (build-system pyproject-build-system)
    (arguments (list #:tests? #f))
    (propagated-inputs (list python-cffi))
    (native-inputs (list python-cffi python-pytest python-setuptools
                         python-wheel wayland wayland-protocols pkg-config))
    (home-page "https://github.com/flacjacket/pywayland")
    (synopsis
     "Python bindings for the libwayland library written in pure Python")
    (description
     "Python bindings for the libwayland library written in pure Python.")
    (license asl2.0)))

(define-public python-xkbcommon
  (package
    (name "python-xkbcommon")
    (version "1.5.1")
    (source
     (origin
       (method url-fetch)
       (uri (pypi-uri "xkbcommon" version))
       (sha256
        (base32 "0dnwbp8rriwkmsa8a40cpvrccjy7m8xz6jw0vbcka7gnvc44h5xc"))))
    (build-system pyproject-build-system)
    (propagated-inputs (list python-cffi))
    (native-inputs (list python-setuptools python-wheel libxkbcommon))
    (home-page "https://github.com/sde1000/python-xkbcommon")
    (synopsis "Bindings for libxkbcommon using cffi")
    (description "Bindings for libxkbcommon using cffi.")
    (license expat)))