Skip to content

Commit 8e0fda0

Browse files
electricfacedeepin-bot[bot]
authored andcommitted
fix(grub-theme): Fix incomplete display of GRUB theme menu text on
arm64, loongarch64, and sw64 architectures - Add support for V25 GRUB theme adjustments - Migrate the original deepin theme resources to the deepin-v20 directory - Copy a theme from deepin-fallback to the deepin theme - Upgrade the theme adjustment tool version from 18 to 19 - Specifically increase the menu width when GFXMODE is set to 1024x768 --- fix(grub-theme): 修复arm64,loongarch64,sw64架构的 GRUB主题菜单文字显示不全 - 新增 V25 GRUB 主题调整支持 - 将原有的 deepin 主题资源迁移到 deepin-v20 目录 - 从 deepin-fallback 复制一份主题到 deepin 主题 - 主题调整工具版本号从 18 升级到 19 - 在GFXMODE为1024x7682,特别地增加启动菜单宽度 Log: 修复arm64,loongarch64,sw64架构的GRUB主题菜单文字显示不全 Influence: GRUB主题 PMS: BUG-277733, BUG-291909
1 parent a712e5d commit 8e0fda0

55 files changed

Lines changed: 317 additions & 106 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

adjust-grub-theme/adjust_grub_theme_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -135,9 +135,14 @@ func (s *su) TestGetFontSize() {
135135
}
136136

137137
func (s *su) TestGetScreenSizeFromGrubParams() {
138-
grubParamsFilePath := "testdata/grub"
139-
require.FileExists(s.T(), grubParamsFilePath)
140-
w, h, err := getScreenSizeFromGrubParams(grubParamsFilePath)
138+
require.FileExists(s.T(), "testdata/grub")
139+
require.FileExists(s.T(), "testdata/grub.d/00_test")
140+
require.FileExists(s.T(), "testdata/grub.d/99_local")
141+
w, h, err := getScreenSizeFromGrubParams([]string{
142+
"testdata/grub",
143+
"testdata/grub.d/00_test",
144+
"testdata/grub.d/99_local",
145+
})
141146
assert.NoError(s.T(), err)
142147
assert.Equal(s.T(), 1024, w)
143148
assert.Equal(s.T(), 768, h)
@@ -201,7 +206,7 @@ func (s *su) TestAdjustThemeNormal() {
201206
defer func() {
202207
_ = os.RemoveAll(optThemeOutputDir)
203208
}()
204-
err = adjustThemeNormal()
209+
err = adjustThemeNormalV20()
205210
assert.Equal(s.T(), nil, err)
206211

207212
}

adjust-grub-theme/main.go

Lines changed: 113 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -162,11 +162,8 @@ func getFontSize(screenWidth int, screenHeight int) int {
162162
return round(y)
163163
}
164164

165-
func getScreenSizeFromGrubParams(grubParamsFilePath string) (w, h int, err error) {
166-
params, err := loadGrubParams(grubParamsFilePath)
167-
if err != nil {
168-
return
169-
}
165+
func getScreenSizeFromGrubParams(grubParamsFilePaths []string) (w, h int, err error) {
166+
params := loadGrubParams(grubParamsFilePaths)
170167

171168
w, h, err = parseResolution(getGfxMode(params))
172169
if err != nil {
@@ -306,13 +303,13 @@ func adjustTheme() {
306303
if optFallbackOnly {
307304
return
308305
}
309-
err = adjustThemeNormal()
306+
err = adjustThemeNormalV25()
310307
if err != nil {
311308
logger.Fatal(err)
312309
}
313310
}
314311

315-
func adjustThemeNormal() error {
312+
func adjustThemeNormalV20() error {
316313
themeInputDir := filepath.Join(optThemeInputDir, themeNameNormal)
317314
themeOutputDir := filepath.Join(optThemeOutputDir, themeNameNormal)
318315

@@ -409,6 +406,100 @@ func adjustThemeNormal() error {
409406
return err
410407
}
411408

409+
func adjustThemeNormalV25() error {
410+
themeInputDir := filepath.Join(optThemeInputDir, themeNameNormal)
411+
themeOutputDir := filepath.Join(optThemeOutputDir, themeNameNormal)
412+
413+
cleanupThemeOutputDir(themeOutputDir)
414+
err := os.MkdirAll(themeOutputDir, 0755)
415+
if err != nil {
416+
return err
417+
}
418+
copyThemeFiles(themeInputDir, themeOutputDir)
419+
420+
bgImg, themeBgImg, err := loadV25BackgroundImage()
421+
if err != nil {
422+
return err
423+
}
424+
425+
err = saveJpeg(bgImg, filepath.Join(themeOutputDir, "background.jpg"))
426+
if err != nil {
427+
return err
428+
}
429+
if themeBgImg != nil {
430+
err = saveJpeg(themeBgImg, filepath.Join(themeOutputDir, "background_in_theme.jpg"))
431+
if err != nil {
432+
return err
433+
}
434+
} else {
435+
_, err = copyFile(filepath.Join(themeOutputDir, "background.jpg"),
436+
filepath.Join(themeOutputDir, "background_in_theme.jpg"))
437+
if err != nil {
438+
return err
439+
}
440+
}
441+
442+
themeFile := filepath.Join(themeInputDir, "theme.txt.tpl")
443+
theme, err := tt.ParseThemeFile(themeFile)
444+
if err != nil {
445+
return err
446+
}
447+
448+
bootMenu := theme.FindComponentByType(tt.ComponentTypeBootMenu)
449+
if bootMenu != nil {
450+
adjustBootMenuV25(bootMenu, optScreenWidth, optScreenHeight)
451+
}
452+
453+
for _, comp := range theme.Components {
454+
if comp.Type == tt.ComponentTypeLabel {
455+
adjustLabelText(comp)
456+
}
457+
}
458+
459+
themeOutput := filepath.Join(themeOutputDir, "theme.txt")
460+
themeOutputFh, err := os.Create(themeOutput)
461+
if err != nil {
462+
return err
463+
}
464+
defer func() {
465+
_ = themeOutputFh.Close()
466+
}()
467+
bw := bufio.NewWriter(themeOutputFh)
468+
// write head
469+
_, err = fmt.Fprintf(bw, "#version:%d\n", VERSION)
470+
if err != nil {
471+
return err
472+
}
473+
_, err = fmt.Fprintf(bw, "#lang:%s\n", optLang)
474+
if err != nil {
475+
return err
476+
}
477+
478+
var inputDir string
479+
inputDir, err = filepath.Abs(themeInputDir)
480+
if err != nil {
481+
logger.Warning(err)
482+
inputDir = themeInputDir
483+
}
484+
485+
_, err = fmt.Fprintf(bw, "#themeInputDir:%s\n", inputDir)
486+
if err != nil {
487+
return err
488+
}
489+
490+
_, err = fmt.Fprintln(bw, "#head end")
491+
if err != nil {
492+
return err
493+
}
494+
495+
_, err = theme.WriteTo(bw)
496+
if err != nil {
497+
return err
498+
}
499+
err = bw.Flush()
500+
return err
501+
}
502+
412503
func adjustThemeFallback() error {
413504
themeInputDir := filepath.Join(optThemeInputDir, themeNameFallback)
414505
themeOutputDir := filepath.Join(optThemeOutputDir, themeNameFallback)
@@ -585,7 +676,10 @@ func main() {
585676

586677
if optScreenWidth == 0 || optScreenHeight == 0 {
587678
var err error
588-
optScreenWidth, optScreenHeight, err = getScreenSizeFromGrubParams(grubParamsFile)
679+
optScreenWidth, optScreenHeight, err = getScreenSizeFromGrubParams([]string{
680+
grubParamsFile,
681+
ddeGrubParamsFile,
682+
})
589683
if err != nil {
590684
logger.Debug(err)
591685
optScreenWidth = 1024
@@ -984,6 +1078,16 @@ func adjustBootMenu(themeOutputDir string, comp *tt.Component, vars map[string]f
9841078
adjustScrollbarThumbPixmapStyle(scrollbarThumbR)
9851079
}
9861080

1081+
func adjustBootMenuV25(comp *tt.Component, width, height int) {
1082+
if width == 1024 && height == 768 {
1083+
// halfWidthPercent represents half of the boot menu width percentage.
1084+
// The boot menu is centered, so width = halfWidthPercent * 2, left = 50% - halfWidthPercent,
1085+
halfWidthPercent := 22
1086+
comp.SetProp("width", tt.RelNum(halfWidthPercent*2))
1087+
comp.SetProp("left", tt.RelNum(50-halfWidthPercent))
1088+
}
1089+
}
1090+
9871091
const (
9881092
orientationHorizontal = 0
9891093
orientationVertical = 1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Test config for GRUB_GFXMODE override
2+
GRUB_GFXMODE=1920x1080
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Local settings - highest priority
2+
GRUB_DEFAULT=saved
3+
GRUB_SAVEDEFAULT=true
4+
GRUB_GFXMODE=1024x768

adjust-grub-theme/util.go

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -153,6 +153,7 @@ func decodeShellValue(in string) string {
153153
const defaultGrubGfxMode = "auto"
154154
const grubGfxMode = "GRUB_GFXMODE"
155155
const grubParamsFile = "/etc/default/grub"
156+
const ddeGrubParamsFile = "/etc/default/grub.d/11_dde.cfg"
156157

157158
func getGfxMode(params map[string]string) (val string) {
158159
val = decodeShellValue(params[grubGfxMode])
@@ -162,31 +163,52 @@ func getGfxMode(params map[string]string) (val string) {
162163
return
163164
}
164165

165-
func loadGrubParams(grubParamsFilePath string) (map[string]string, error) {
166+
func loadGrubParams(grubParamsFilePaths []string) map[string]string {
166167
params := make(map[string]string)
167-
f, err := os.Open(grubParamsFilePath)
168+
169+
// First read the main configuration file
170+
for _, grubParamsFilePath := range grubParamsFilePaths {
171+
if err := readGrubParamsFile(grubParamsFilePath, params); err != nil {
172+
logger.Warningf("Failed to read grub params file %s: %v", grubParamsFilePath, err)
173+
}
174+
}
175+
176+
return params
177+
}
178+
179+
func readGrubParamsFile(filePath string, params map[string]string) error {
180+
f, err := os.Open(filePath)
168181
if err != nil {
169-
return params, err
182+
if os.IsNotExist(err) {
183+
return nil
184+
}
185+
return err
170186
}
171187
defer func() {
172188
_ = f.Close()
173189
}()
174190

175-
r := kv.NewReader(f)
176-
r.TrimSpace = kv.TrimLeadingTailingSpace
177-
r.Comment = '#'
178-
for {
179-
pair, err := r.Read()
180-
if err != nil {
181-
break
191+
scanner := bufio.NewScanner(f)
192+
for scanner.Scan() {
193+
line := strings.TrimSpace(scanner.Text())
194+
// Skip empty lines and comment lines
195+
if line == "" || strings.HasPrefix(line, "#") {
196+
continue
197+
}
198+
// Find the position of the first equal sign
199+
eqIdx := strings.Index(line, "=")
200+
if eqIdx == -1 {
201+
// Not in key=value format, skip
202+
continue
182203
}
183-
if pair.Key == "" {
204+
key := strings.TrimSpace(line[:eqIdx])
205+
value := strings.TrimSpace(line[eqIdx+1:])
206+
if key == "" {
184207
continue
185208
}
186-
params[pair.Key] = pair.Value
209+
params[key] = value
187210
}
188-
189-
return params, nil
211+
return scanner.Err()
190212
}
191213

192214
type InvalidResolutionError struct {

adjust-grub-theme/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

55
package main
66

7-
const VERSION int = 18
7+
const VERSION int = 19

grub_theme/themetxt/theme.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -264,6 +264,16 @@ func (t *Theme) Dump() {
264264
}
265265
}
266266

267+
// FindComponentByType finds the first component by component type
268+
func (t *Theme) FindComponentByType(compType string) *Component {
269+
for _, comp := range t.Components {
270+
if comp.Type == compType {
271+
return comp
272+
}
273+
}
274+
return nil
275+
}
276+
267277
func (t *Theme) WriteTo(w io.Writer) (n int64, err error) {
268278
for _, prop := range t.Props {
269279
var pn int

misc/data/grub-themes/deepin-fallback/theme.txt.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ terminal-border: "0"
2525
item_height = 18
2626
item_spacing = 25
2727
selected_item_pixmap_style = "selected_item_*.png"
28+
icon_width = 0
2829
}
2930

3031
# Show a countdown message using the label component
File renamed without changes.

misc/data/grub-themes/deepin/resources/os-logos/antergos.svg renamed to misc/data/grub-themes/deepin-v20/resources/os-logos/antergos.svg

File renamed without changes.

0 commit comments

Comments
 (0)