summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan <stefan-guix@vodafonemail.de>2020-05-17 23:53:50 +0200
committerMathieu Othacehe <othacehe@gnu.org>2020-05-19 09:09:21 +0200
commit9cdb10d52e34f7e8fa3b6238fe268646a4bbb877 (patch)
tree2b994ed53f81b4a9948fd0b52398194dbe418b68
parent2e59ae238426df3f886c6a1aeca08ddc96b61143 (diff)
gnu: grub: Allow a PNG image and replace "aspect-ratio" with "resolution".
* gnu/bootloaders/grub.scm (<grub-image>): Remove this record and replace it by ... (<grub-theme>)[image]: ... this field with the default from %background-image, (<grub-theme>)[resolution]: ... this field with the defaults from 'width' and 'height' of 'grub-background-image'. (<grub-theme>)[images]: Remove this field. (svg->png): Rename to ... (image->png): ... and use 'copy-file' instead of 'svg->png', if the suffix of the image file is not ".svg". (grub-background-image): Remove the arguments 'width' and 'height'. (grub-theme-image): Add function. (grub-theme-resolution): Add function. (grub-theme-gfxmode): Add function. (grub-image): Remove function. (grub-image?): Remove function. (grub-image-aspect-ratio): Remove function. (grub-image-file): Remove function. (grub-theme-images): Remove function. (%default-theme): Remove variable. (%background-image): Remove variable. Using image formats different to SVG was not possible. For a <grub-image> to be chosen, the 'aspect-ratio' of it had to be 4/3, as the resolution of any image was defaulting to 1024 x 768. There was no code to determine the proper boot-resolution to make any use of a list of images with different aspect-ratios. It seems to be a better solution to only define a single image with any format, and use a given resolution only for the conversion from a SVG file. This also makes the use of a special <grub-image> record unnecessary. Moving the default values from '%background-image' and '%default-theme' into <grub-theme> makes a customisation easier without (inherit) and allows to remove the undocumented variables %background-image' and '%default-theme'. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
-rw-r--r--gnu/bootloader/grub.scm93
1 files changed, 37 insertions, 56 deletions
diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 8c5b5eac0c8..fb871c6e965 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -37,19 +37,13 @@
37 #:use-module (ice-9 regex) 37 #:use-module (ice-9 regex)
38 #:use-module (srfi srfi-1) 38 #:use-module (srfi srfi-1)
39 #:use-module (srfi srfi-2) 39 #:use-module (srfi srfi-2)
40 #:export (grub-image 40 #:export (grub-theme
41 grub-image?
42 grub-image-aspect-ratio
43 grub-image-file
44
45 grub-theme
46 grub-theme? 41 grub-theme?
47 grub-theme-images 42 grub-theme-image
43 grub-theme-resolution
48 grub-theme-color-normal 44 grub-theme-color-normal
49 grub-theme-color-highlight 45 grub-theme-color-highlight
50 46 grub-theme-gfxmode
51 %background-image
52 %default-theme
53 47
54 grub-bootloader 48 grub-bootloader
55 grub-efi-bootloader 49 grub-efi-bootloader
@@ -77,70 +71,57 @@ denoting a file name."
77 file)))) 71 file))))
78 (#f file))) 72 (#f file)))
79 73
80(define-record-type* <grub-image>
81 grub-image make-grub-image
82 grub-image?
83 (aspect-ratio grub-image-aspect-ratio ;rational number
84 (default 4/3))
85 (file grub-image-file)) ;file-valued gexp (SVG)
86
87(define-record-type* <grub-theme> 74(define-record-type* <grub-theme>
75 ;; Default theme contributed by Felipe López.
88 grub-theme make-grub-theme 76 grub-theme make-grub-theme
89 grub-theme? 77 grub-theme?
90 (images grub-theme-images 78 (image grub-theme-image
91 (default '())) ;list of <grub-image> 79 (default (file-append %artwork-repository
80 "/grub/GuixSD-fully-black-4-3.svg")))
81 (resolution grub-theme-resolution
82 (default '(1024 . 768)))
92 (color-normal grub-theme-color-normal 83 (color-normal grub-theme-color-normal
93 (default '((fg . cyan) (bg . blue)))) 84 (default '((fg . light-gray) (bg . black))))
94 (color-highlight grub-theme-color-highlight 85 (color-highlight grub-theme-color-highlight
95 (default '((fg . white) (bg . blue)))) 86 (default '((fg . yellow) (bg . black))))
96 (gfxmode grub-gfxmode 87 (gfxmode grub-theme-gfxmode
97 (default '("auto")))) ;list of string 88 (default '("auto")))) ;list of string
98 89
99(define %background-image
100 (grub-image
101 (aspect-ratio 4/3)
102 (file (file-append %artwork-repository
103 "/grub/GuixSD-fully-black-4-3.svg"))))
104
105(define %default-theme
106 ;; Default theme contributed by Felipe López.
107 (grub-theme
108 (images (list %background-image))
109 (color-highlight '((fg . yellow) (bg . black)))
110 (color-normal '((fg . light-gray) (bg . black))))) ;XXX: #x303030
111
112 90
113;;; 91;;;
114;;; Background image & themes. 92;;; Background image & themes.
115;;; 93;;;
116 94
117(define (bootloader-theme config) 95(define (bootloader-theme config)
118 "Return user defined theme in CONFIG if defined or %default-theme 96 "Return user defined theme in CONFIG if defined or a default theme
119otherwise." 97otherwise."
120 (or (bootloader-configuration-theme config) %default-theme)) 98 (or (bootloader-configuration-theme config) (grub-theme)))
121 99
122(define* (svg->png svg #:key width height) 100(define* (image->png image #:key width height)
123 "Build a PNG of HEIGHT x WIDTH from SVG." 101 "Build a PNG of HEIGHT x WIDTH from IMAGE if its file suffix is \".svg\".
102Otherwise the picture in IMAGE is just copied."
124 (computed-file "grub-image.png" 103 (computed-file "grub-image.png"
125 (with-imported-modules '((gnu build svg)) 104 (with-imported-modules '((gnu build svg))
126 (with-extensions (list guile-rsvg guile-cairo) 105 (with-extensions (list guile-rsvg guile-cairo)
127 #~(begin 106 #~(if (string-suffix? ".svg" #+image)
128 (use-modules (gnu build svg)) 107 (begin
129 (svg->png #+svg #$output 108 (use-modules (gnu build svg))
130 #:width #$width 109 (svg->png #+image #$output
131 #:height #$height)))))) 110 #:width #$width
132 111 #:height #$height))
133(define* (grub-background-image config #:key (width 1024) (height 768)) 112 (copy-file #+image #$output))))))
134 "Return the GRUB background image defined in CONFIG with a ratio of 113
135WIDTH/HEIGHT, or #f if none was found." 114(define* (grub-background-image config)
136 (let* ((ratio (/ width height)) 115 "Return the GRUB background image defined in CONFIG or #f if none was found.
137 (image (find (lambda (image) 116If the suffix of the image file is \".svg\", then it is converted into a PNG
138 (= (grub-image-aspect-ratio image) ratio)) 117file with the resolution provided in CONFIG."
139 (grub-theme-images 118 (let* ((theme (bootloader-theme config))
140 (bootloader-theme config))))) 119 (image (grub-theme-image theme)))
141 (and image 120 (and image
142 (svg->png (grub-image-file image) 121 (match (grub-theme-resolution theme)
143 #:width width #:height height)))) 122 (((? number? width) . (? number? height))
123 (image->png image #:width width #:height height))
124 (_ #f)))))
144 125
145(define* (eye-candy config store-device store-mount-point 126(define* (eye-candy config store-device store-mount-point
146 #:key system port) 127 #:key system port)
@@ -153,7 +134,7 @@ system string---e.g., \"x86_64-linux\"."
153 (define setup-gfxterm-body 134 (define setup-gfxterm-body
154 (let ((gfxmode 135 (let ((gfxmode
155 (or (and-let* ((theme (bootloader-configuration-theme config)) 136 (or (and-let* ((theme (bootloader-configuration-theme config))
156 (gfxmode (grub-gfxmode theme))) 137 (gfxmode (grub-theme-gfxmode theme)))
157 (string-join gfxmode ";")) 138 (string-join gfxmode ";"))
158 "auto"))) 139 "auto")))
159 140