Subject: [bug#53648] [PATCH] gnu: fcitx5-gtk: Add GTK 4 support.

From: Zhu Zihao <[email-masked]>
Date: Mon, 07 Feb 2022 13:58:28 +0800

>From 0c23e8cbbfe8f0548b29176831a4358d41820159 Mon Sep 17 00:00:00 2001
From: Zhu Zihao <[email-masked]>
Date: Mon, 31 Jan 2022 14:51:30 +0800
Subject: [PATCH 1/2] gnu: fcitx5-gtk: Add GTK 4 support.

* gnu/packages/fcitx5.scm (fcitx5-gtk)[arguments]:
<configure-flags>: Enable GTK 4 IM module.
<phases>: In 'patch-install-prefix', patch the install prefix of GTK 4 IM
module.
[inputs]: Add GTK 4.
[outputs]: Add 'gtk4'.
---
 gnu/packages/fcitx5.scm | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/gnu/packages/fcitx5.scm b/gnu/packages/fcitx5.scm
index 92fc0ea171..123418cd4f 100644
--- a/gnu/packages/fcitx5.scm
+++ b/gnu/packages/fcitx5.scm
@@ -201,19 +201,23 @@ (define-public fcitx5-gtk
        (list (string-append "-DGOBJECT_INTROSPECTION_GIRDIR="
                             %output "/share/gir-1.0")
              (string-append "-DGOBJECT_INTROSPECTION_TYPELIBDIR="
-                            %output "/lib/girepository-1.0")
-             ;; TODO: Enable it when Guix has GTK4.
-             "-DENABLE_GTK4_IM_MODULE=Off")
+                            %output "/lib/girepository-1.0"))
        #:phases
        (modify-phases %standard-phases
          (add-before 'configure 'patch-install-prefix
            (lambda* (#:key outputs #:allow-other-keys)
              (let ((out (assoc-ref outputs "out"))
-                   (gtk2 (assoc-ref outputs "gtk2")))
+                   (gtk2 (assoc-ref outputs "gtk2"))
+                   (gtk4 (assoc-ref outputs "gtk4")))
                ;; Install GTK+ 2 input method module to its own output.
                (substitute* "gtk2/CMakeLists.txt"
                  (("\\$\\{CMAKE_INSTALL_LIBDIR\\}")
-                  (string-append gtk2 "/lib")))))))))
+                  (string-append gtk2 "/lib")))
+
+               ;; Install for GTK 4.
+               (substitute* "gtk4/CMakeLists.txt"
+                 (("\\$\\{CMAKE_INSTALL_LIBDIR\\}")
+                  (string-append gtk4 "/lib")))))))))
     (inputs
      `(("fcitx5" ,fcitx5)
        ("fmt" ,fmt)
@@ -221,6 +225,7 @@ (define-public fcitx5-gtk
        ("gobject-introspection" ,gobject-introspection)
        ("gtk2" ,gtk+-2)
        ("gtk3" ,gtk+)
+       ("gtk4" ,gtk)
        ("glib" ,glib)
        ("libx11" ,libx11)
        ("gettext" ,gettext-minimal)))
@@ -228,7 +233,7 @@ (define-public fcitx5-gtk
      (list extra-cmake-modules pkg-config
            `(,glib "bin")))           ;for glib-genmarshal
     ;; TODO: Add "lib" output to reduce the closure size of "gtk2".
-    (outputs '("out" "gtk2"))
+    (outputs '("out" "gtk2" "gtk4"))
     (home-page "https://github.com/fcitx/fcitx5-gtk")
     (synopsis "Glib based D-Bus client and GTK IM module for Fcitx 5")
     (description "Fcitx5-gtk provides a Glib based D-Bus client and IM module
-- 
2.34.0

>From ef83eb7614d8888fa538d16870a960cc84717147 Mon Sep 17 00:00:00 2001
From: Zhu Zihao <[email-masked]>
Date: Mon, 7 Feb 2022 13:55:26 +0800
Subject: [PATCH 2/2] gnu: fcitx5-gtk: Split IM module output for different
 version of GTK.

* gnu/packages/fcitx5.scm (fcitx5-gtk)[arguments] <phases>: Split input method
module into different outputs for GTK2, GTK3 and GTK4.

Now default output only provides GLib client of Fcitx5.

[outputs]: Add new "gtk3" output.
---
 gnu/packages/fcitx5.scm | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/gnu/packages/fcitx5.scm b/gnu/packages/fcitx5.scm
index 123418cd4f..e9884d8f0a 100644
--- a/gnu/packages/fcitx5.scm
+++ b/gnu/packages/fcitx5.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2020 Zhu Zihao <[email-masked]>
+;;; Copyright © 2020, 2022 Zhu Zihao <[email-masked]>
 ;;; Copyright © 2021 Tobias Geerinckx-Rice <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -206,18 +206,12 @@ (define-public fcitx5-gtk
        (modify-phases %standard-phases
          (add-before 'configure 'patch-install-prefix
            (lambda* (#:key outputs #:allow-other-keys)
-             (let ((out (assoc-ref outputs "out"))
-                   (gtk2 (assoc-ref outputs "gtk2"))
-                   (gtk4 (assoc-ref outputs "gtk4")))
-               ;; Install GTK+ 2 input method module to its own output.
-               (substitute* "gtk2/CMakeLists.txt"
+             (define (split-immodule gtk-version)
+               (substitute* (string-append gtk-version "/CMakeLists.txt")
                  (("\\$\\{CMAKE_INSTALL_LIBDIR\\}")
-                  (string-append gtk2 "/lib")))
+                  (string-append (assoc-ref outputs gtk-version) "/lib"))))
 
-               ;; Install for GTK 4.
-               (substitute* "gtk4/CMakeLists.txt"
-                 (("\\$\\{CMAKE_INSTALL_LIBDIR\\}")
-                  (string-append gtk4 "/lib")))))))))
+             (for-each split-immodule '("gtk2" "gtk3" "gtk4")))))))
     (inputs
      `(("fcitx5" ,fcitx5)
        ("fmt" ,fmt)
@@ -233,7 +227,7 @@ (define-public fcitx5-gtk
      (list extra-cmake-modules pkg-config
            `(,glib "bin")))           ;for glib-genmarshal
     ;; TODO: Add "lib" output to reduce the closure size of "gtk2".
-    (outputs '("out" "gtk2" "gtk4"))
+    (outputs '("out" "gtk2" "gtk3" "gtk4"))
     (home-page "https://github.com/fcitx/fcitx5-gtk")
     (synopsis "Glib based D-Bus client and GTK IM module for Fcitx 5")
     (description "Fcitx5-gtk provides a Glib based D-Bus client and IM module
-- 
2.34.0

-- 
Retrieve my PGP public key:

  gpg --recv-keys D47A9C8B2AE3905B563D9135BE42B352A9F6821F

Zihao