From 7cff52a24546a6cc67701f2bb481d76c60949b54 Mon Sep 17 00:00:00 2001 From: "Zhiyong (Justin) He" Date: Tue, 17 Sep 2024 19:08:35 +0300 Subject: [PATCH 1/8] Update flake.nix to allow customised resolution for NixOS --- flake.nix | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/flake.nix b/flake.nix index 0481487..520a36d 100644 --- a/flake.nix +++ b/flake.nix @@ -26,7 +26,7 @@ "2k" = "2560x1440"; "4k" = "3840x2160"; "ultrawide2k" = "3440x1440"; - }; + } // (if cfg.customResolution != null then { "custom" = cfg.customResolution; } else {}); grub2-theme = pkgs.stdenv.mkDerivation { name = "grub2-theme"; src = "${self}"; @@ -61,7 +61,9 @@ fi; ''; }; - resolution = resolutions."${cfg.screen}"; + resolution = if cfg.customResolution != null + then cfg.customResolution + else resolutions."${cfg.screen}"; in rec { options = { @@ -93,9 +95,17 @@ screen = mkOption { default = "1080p"; example = "1080p"; - type = types.enum [ "1080p" "2k" "4k" "ultrawide" "ultrawide2k" ]; + type = types.enum ([ "1080p" "2k" "4k" "ultrawide" "ultrawide2k" ] ++ (if cfg.customResolution != null then [ "custom" ] else [])); description = '' - The screen resolution to use for grub2. + The screen resolution to use for grub2. Use "custom" if you've set a customResolution. + ''; + }; + customResolution = mkOption { + default = null; + example = "1600x900"; + type = types.nullOr (types.strMatching "[0-9]+x[0-9]+"); + description = '' + Custom resolution for grub2 theme. Should be in the format "WIDTHxHEIGHT". ''; }; splashImage = mkOption { @@ -138,19 +148,17 @@ environment.systemPackages = [ grub2-theme ]; - boot.loader.grub = - { - theme = "${grub2-theme}/grub/themes/${cfg.theme}"; - splashImage = - "${grub2-theme}/grub/themes/${cfg.theme}/background.jpg"; - gfxmodeEfi = "${resolution},auto"; - gfxmodeBios = "${resolution},auto"; - extraConfig = '' - insmod gfxterm - insmod png - set icondir=($root)/theme/icons - ''; - }; + boot.loader.grub = { + theme = "${grub2-theme}/grub/themes/${cfg.theme}"; + splashImage = "${grub2-theme}/grub/themes/${cfg.theme}/background.jpg"; + gfxmodeEfi = "${resolution},auto"; + gfxmodeBios = "${resolution},auto"; + extraConfig = '' + insmod gfxterm + insmod png + set icondir=($root)/theme/icons + ''; + }; }]); }; }; From 9aa7e35d71f97cf60ebd80da83a74811246ecf66 Mon Sep 17 00:00:00 2001 From: "Zhiyong (Justin) He" Date: Tue, 17 Sep 2024 19:25:41 +0300 Subject: [PATCH 2/8] Update flake.nix to fix a bug ERROR: Unrecognized screen variant 'custom'. --- flake.nix | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 520a36d..a8779c6 100644 --- a/flake.nix +++ b/flake.nix @@ -26,7 +26,7 @@ "2k" = "2560x1440"; "4k" = "3840x2160"; "ultrawide2k" = "3440x1440"; - } // (if cfg.customResolution != null then { "custom" = cfg.customResolution; } else {}); + }; grub2-theme = pkgs.stdenv.mkDerivation { name = "grub2-theme"; src = "${self}"; @@ -36,7 +36,8 @@ --generate $out/grub/themes \ --screen ${cfg.screen} \ --theme ${cfg.theme} \ - --icon ${cfg.icon}; + --icon ${cfg.icon} \ + ${if cfg.customResolution != null then "--custom-resolution ${cfg.customResolution}" else ""} if [ -n "${splashImage}" ]; then rm $out/grub/themes/${cfg.theme}/background.jpg; @@ -95,9 +96,9 @@ screen = mkOption { default = "1080p"; example = "1080p"; - type = types.enum ([ "1080p" "2k" "4k" "ultrawide" "ultrawide2k" ] ++ (if cfg.customResolution != null then [ "custom" ] else [])); + type = types.enum [ "1080p" "2k" "4k" "ultrawide" "ultrawide2k" ]; description = '' - The screen resolution to use for grub2. Use "custom" if you've set a customResolution. + The screen resolution to use for grub2. ''; }; customResolution = mkOption { @@ -106,6 +107,7 @@ type = types.nullOr (types.strMatching "[0-9]+x[0-9]+"); description = '' Custom resolution for grub2 theme. Should be in the format "WIDTHxHEIGHT". + If set, this will override the 'screen' option. ''; }; splashImage = mkOption { From daa8aef95f6f12caafc4ad12be3ea0833274ae9e Mon Sep 17 00:00:00 2001 From: "Zhiyong (Justin) He" Date: Tue, 17 Sep 2024 20:02:25 +0300 Subject: [PATCH 3/8] Update install.sh to make it work for customised resolution --- install.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 7e1eba8..e1d9c86 100755 --- a/install.sh +++ b/install.sh @@ -14,6 +14,7 @@ REO_DIR="$(cd $(dirname $0) && pwd)" THEME_VARIANTS=('tela' 'vimix' 'stylish' 'whitesur') ICON_VARIANTS=('color' 'white' 'whitesur') SCREEN_VARIANTS=('1080p' '2k' '4k' 'ultrawide' 'ultrawide2k') +custom_resolution="" ################################# # :::::: C O L O R S :::::: # @@ -65,6 +66,7 @@ OPTIONS: -t, --theme theme variant(s) [tela|vimix|stylish|whitesur] (default is tela) -i, --icon icon variant(s) [color|white|whitesur] (default is color) -s, --screen screen display variant(s) [1080p|2k|4k|ultrawide|ultrawide2k] (default is 1080p) + -c, --custom-resolution set custom resolution (e.g., 1600x900) -r, --remove Remove theme [tela|vimix|stylish|whitesur] (must add theme name option, default is tela) -b, --boot install theme into '/boot/grub' or '/boot/grub2' @@ -99,6 +101,33 @@ generate() { cp -a --no-preserve=ownership "${REO_DIR}/config/theme-${screen}.txt" "${THEME_DIR}/${theme}/theme.txt" cp -a --no-preserve=ownership "${REO_DIR}/backgrounds/${screen}/background-${theme}.jpg" "${THEME_DIR}/${theme}/background.jpg" + # Function to determine which assets to use based on resolution + get_asset_type() { + local width=$(echo $1 | cut -d'x' -f1) + local height=$(echo $1 | cut -d'x' -f2) + if [ $width -le 1920 ] && [ $height -le 1080 ]; then + echo "1080p" + elif [ $width -le 2560 ] && [ $height -le 1440 ]; then + echo "2k" + else + echo "4k" + fi + } + + # Determine which configuration file and assets to use + if [[ -n "$custom_resolution" ]]; then + asset_type=$(get_asset_type "$custom_resolution") + cp -a --no-preserve=ownership "${REO_DIR}/config/theme-${asset_type}.txt" "${THEME_DIR}/${theme}/theme.txt" + # Replace resolution in theme.txt + sed -i "s/[0-9]\+x[0-9]\+/${custom_resolution}/" "${THEME_DIR}/${theme}/theme.txt" + # Use appropriate background as base and resize it + cp -a --no-preserve=ownership "${REO_DIR}/backgrounds/${asset_type}/background-${theme}.jpg" "${THEME_DIR}/${theme}/background.jpg" + convert "${THEME_DIR}/${theme}/background.jpg" -resize ${custom_resolution}^ -gravity center -extent ${custom_resolution} "${THEME_DIR}/${theme}/background.jpg" + else + cp -a --no-preserve=ownership "${REO_DIR}/config/theme-${screen}.txt" "${THEME_DIR}/${theme}/theme.txt" + cp -a --no-preserve=ownership "${REO_DIR}/backgrounds/${screen}/background-${theme}.jpg" "${THEME_DIR}/${theme}/background.jpg" + fi + # Use custom background.jpg as grub background image if [[ -f "${REO_DIR}/background.jpg" ]]; then prompt -w "\n Using custom background.jpg as grub background image..." @@ -106,7 +135,13 @@ generate() { convert -auto-orient "${THEME_DIR}/${theme}/background.jpg" "${THEME_DIR}/${theme}/background.jpg" fi - if [[ ${screen} == 'ultrawide' ]]; then + # Determine which assets to use based on custom resolution or screen + if [[ -n "$custom_resolution" ]]; then + asset_type=$(get_asset_type "$custom_resolution") + cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-${icon}/icons-${asset_type}" "${THEME_DIR}/${theme}/icons" + cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-select/select-${asset_type}/"*.png "${THEME_DIR}/${theme}" + cp -a --no-preserve=ownership "${REO_DIR}/assets/info-${asset_type}.png" "${THEME_DIR}/${theme}/info.png" + elif [[ ${screen} == 'ultrawide' ]]; then cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-${icon}/icons-1080p" "${THEME_DIR}/${theme}/icons" cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-select/select-1080p/"*.png "${THEME_DIR}/${theme}" cp -a --no-preserve=ownership "${REO_DIR}/assets/info-1080p.png" "${THEME_DIR}/${theme}/info.png" @@ -186,7 +221,9 @@ install() { fi # Make sure the right resolution for grub is set - if [[ ${screen} == '1080p' ]]; then + if [[ -n "$custom_resolution" ]]; then + gfxmode="GRUB_GFXMODE=${custom_resolution},auto" + elif [[ ${screen} == '1080p' ]]; then gfxmode="GRUB_GFXMODE=1920x1080,auto" elif [[ ${screen} == 'ultrawide' ]]; then gfxmode="GRUB_GFXMODE=2560x1080,auto" @@ -645,6 +682,11 @@ while [[ $# -gt 0 ]]; do esac done ;; + -c|--custom-resolution) + shift + custom_resolution="$1" + shift + ;; -h|--help) usage exit 0 From d73179c4ea89e71901f1f1f62260a94b08a7edf3 Mon Sep 17 00:00:00 2001 From: "Zhiyong (Justin) He" Date: Tue, 17 Sep 2024 20:08:46 +0300 Subject: [PATCH 4/8] Update flake.nix add imagemagick --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index a8779c6..97f9962 100644 --- a/flake.nix +++ b/flake.nix @@ -30,6 +30,7 @@ grub2-theme = pkgs.stdenv.mkDerivation { name = "grub2-theme"; src = "${self}"; + buildInputs = [ pkgs.imagemagick ]; installPhase = '' mkdir -p $out/grub/themes; bash ./install.sh \ From 326a27a6f2b7bffc064fc25c1d40f7153ff3b6f9 Mon Sep 17 00:00:00 2001 From: "Zhiyong (Justin) He" Date: Tue, 17 Sep 2024 20:14:55 +0300 Subject: [PATCH 5/8] Update install.sh --- install.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index e1d9c86..dd72edf 100755 --- a/install.sh +++ b/install.sh @@ -63,11 +63,11 @@ cat << EOF Usage: $0 [OPTION]... OPTIONS: - -t, --theme theme variant(s) [tela|vimix|stylish|whitesur] (default is tela) - -i, --icon icon variant(s) [color|white|whitesur] (default is color) - -s, --screen screen display variant(s) [1080p|2k|4k|ultrawide|ultrawide2k] (default is 1080p) - -c, --custom-resolution set custom resolution (e.g., 1600x900) - -r, --remove Remove theme [tela|vimix|stylish|whitesur] (must add theme name option, default is tela) + -t, --theme theme variant(s) [tela|vimix|stylish|whitesur] (default is tela) + -i, --icon icon variant(s) [color|white|whitesur] (default is color) + -s, --screen screen display variant(s) [1080p|2k|4k|ultrawide|ultrawide2k] (default is 1080p) + -c, --custom-resolution set custom resolution (e.g., 1600x900) (disabled in default) + -r, --remove remove theme [tela|vimix|stylish|whitesur] (must add theme name option, default is tela) -b, --boot install theme into '/boot/grub' or '/boot/grub2' -g, --generate do not install but generate theme into chosen directory (must add your directory) From 18ea3defc55da3d3a9ad4edd9e6a332d5b4a5d0d Mon Sep 17 00:00:00 2001 From: "Zhiyong (Justin) He" Date: Tue, 17 Sep 2024 20:20:35 +0300 Subject: [PATCH 6/8] Update README.md --- README.md | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 974c421..c8d98a8 100644 --- a/README.md +++ b/README.md @@ -1,51 +1,46 @@ ![banner](banner.png?raw=true) ## Installation: - Usage: `sudo ./install.sh [OPTIONS...]` - ``` - -t, --theme theme variant(s) [tela|vimix|stylish|whitesur] (default is tela) - -i, --icon icon variant(s) [color|white|whitesur] (default is color) - -s, --screen screen display variant(s) [1080p|2k|4k|ultrawide|ultrawide2k] (default is 1080p) - -r, --remove Remove theme [tela|vimix|stylish|whitesur] (must add theme name option, default is tela) + -t, --theme theme variant(s) [tela|vimix|stylish|whitesur] (default is tela) + -i, --icon icon variant(s) [color|white|whitesur] (default is color) + -s, --screen screen display variant(s) [1080p|2k|4k|ultrawide|ultrawide2k] (default is 1080p) + -c, --custom-resolution set custom resolution (e.g., 1600x900) (disabled in default) + -r, --remove remove theme [tela|vimix|stylish|whitesur] (must add theme name option, default is tela) - -b, --boot install theme into '/boot/grub' or '/boot/grub2' - -g, --generate do not install but generate theme into chosen directory (must add your directory) + -b, --boot install theme into '/boot/grub' or '/boot/grub2' + -g, --generate do not install but generate theme into chosen directory (must add your directory) - -h, --help Show this help + -h, --help Show this help ``` - -_If no options are used, a user interface `dialog` will show up instead_ +*If no options are used, a user interface *`dialog`* will show up instead* ### Examples: - Install Tela theme on 2k display device: - ```sh sudo ./install.sh -t tela -s 2k ``` - + - Install Tela theme with custom resolution: +```sh +sudo ./install.sh -t tela -c 1600x900 +``` - Install Tela theme into /boot/grub/themes: - ```sh sudo ./install.sh -b -t tela ``` - - Uninstall Tela theme: - ```sh sudo ./install.sh -r -t tela ``` ## Installation with NixOS: To use this theme with NixOS you will have to enable [flakes](https://wiki.nixos.org/wiki/flakes). Before you do this, please inform yourself if you really want to, because flakes are still an unstable feature. - First you will have to add grub2 to your `flake.nix` file as a new input. ```nix # flake.nix { description = "NixOS configuration"; - inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; # Add grub2 themes to your inputs ... @@ -53,13 +48,11 @@ First you will have to add grub2 to your `flake.nix` file as a new input. url = "github:vinceliuice/grub2-themes"; }; }; - outputs = inputs@{ nixpkgs, grub2-themes, ... }: { nixosConfigurations = { my_host = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; specialArgs = { inherit inputs; }; - # ... and then to your modules modules = [ ./configuration.nix @@ -70,7 +63,6 @@ First you will have to add grub2 to your `flake.nix` file as a new input. }; } ``` - After that, you can configure the theme as shown below. In this example it is inside the `configuration.nix` file but it can be any file you choose. ```nix # configuration.nix @@ -81,21 +73,19 @@ After that, you can configure the theme as shown below. In this example it is in enable = true; theme = "stylish"; footer = true; + customResolution = "1600x900"; # Optional: Set a custom resolution }; } ``` ## Issues / tweaks: - ### Correcting display resolution: - - On the grub screen, press `c` to enter the command line - Enter `vbeinfo` or `videoinfo` to check available resolutions - Open `/etc/default/grub`, and edit `GRUB_GFXMODE=[height]x[width]x32` to match your resolution - Finally, run `grub-mkconfig -o /boot/grub/grub.cfg` to update your grub config ### Setting a custom background: - - Make sure you have `imagemagick` installed, or at least something that provides `convert` - Find the resolution of your display, and make sure your background matches the resolution - 1920x1080 >> 1080p @@ -106,6 +96,7 @@ After that, you can configure the theme as shown below. In this example it is in - Place your custom background inside the root of the project, and name it `background.jpg` - Run the installer like normal, but with -s `[YOUR_RESOLUTION]` and -t `[THEME]` and -i `[ICON]` - Make sure to replace `[YOUR_RESOLUTION]` with your resolution and `[THEME]` with the theme + - Alternatively, use the `-c` option to set a custom resolution ## Contributing: - If you made changes to icons, or added a new one: @@ -118,7 +109,5 @@ After that, you can configure the theme as shown below. In this example it is in ![preview](preview.png?raw=true) ## Documents - -[Grub2 theme reference](https://wiki.rosalab.ru/en/index.php/Grub2_theme_/_reference) - +[Grub2 theme reference](https://wiki.rosalab.ru/en/index.php/Grub2_theme_/_reference) [Grub2 theme tutorial](https://wiki.rosalab.ru/en/index.php/Grub2_theme_tutorial) From a2b3fa071be34671a2c6e0b564012a70a63e6d13 Mon Sep 17 00:00:00 2001 From: "Zhiyong (Justin) He" Date: Tue, 17 Sep 2024 20:21:13 +0300 Subject: [PATCH 7/8] Update install.sh --- install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index dd72edf..60f3752 100755 --- a/install.sh +++ b/install.sh @@ -69,10 +69,10 @@ OPTIONS: -c, --custom-resolution set custom resolution (e.g., 1600x900) (disabled in default) -r, --remove remove theme [tela|vimix|stylish|whitesur] (must add theme name option, default is tela) - -b, --boot install theme into '/boot/grub' or '/boot/grub2' - -g, --generate do not install but generate theme into chosen directory (must add your directory) + -b, --boot install theme into '/boot/grub' or '/boot/grub2' + -g, --generate do not install but generate theme into chosen directory (must add your directory) - -h, --help Show this help + -h, --help show this help EOF } From 610bc230120f8c9ef006f9fcbe88950d85e97e6d Mon Sep 17 00:00:00 2001 From: "Zhiyong (Justin) He" Date: Tue, 17 Sep 2024 20:22:28 +0300 Subject: [PATCH 8/8] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c8d98a8..55411db 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Usage: `sudo ./install.sh [OPTIONS...]` -b, --boot install theme into '/boot/grub' or '/boot/grub2' -g, --generate do not install but generate theme into chosen directory (must add your directory) - -h, --help Show this help + -h, --help show this help ``` *If no options are used, a user interface *`dialog`* will show up instead* @@ -109,5 +109,7 @@ After that, you can configure the theme as shown below. In this example it is in ![preview](preview.png?raw=true) ## Documents + [Grub2 theme reference](https://wiki.rosalab.ru/en/index.php/Grub2_theme_/_reference) + [Grub2 theme tutorial](https://wiki.rosalab.ru/en/index.php/Grub2_theme_tutorial)