Skip to contentSkip to conversation

Adding --set to videoinfo to retrieve current video resolution

PATCH In review Markus Scholz 3 participants 13 messages Oct 12, 2022 – Dec 14, 2022

lore
Share & tools
lore
#0 lore raw

Dear Grub Developers,

recently we faced the problem the author in this old thread faced:
- https://lists.gnu.org/archive/html/grub-devel/2012-10/msg00009.html

Ie. our theme wouldn't display properly due to different screen resolutions. Hence, I wanted to change specifically the font size of our theme given the current resolution.
While the videoinfo module provides info about the current resolution I wasn't able to
discover any way to get the info from the booted grub.

Following the aforementioned thread, I therefore patched the videoinfo mod to add the ability
of a -set switch just like commands like "smbinfo" or "search" have.

Ie. the documentation of the videoinfo call could change as follows:

Command: videoinfo [--set var | [WxH]xD]

Retrieve available video modes. If --set is given, assign the currently
active resolution to var.
If --set is not provided the available video modes are listed. If resolution is given, show only matching modes.

Attached is my patch proposal for the module; I probably made a lot mistakes wrt.
coding style and guidelines - please bear with me.

I would be grateful regarding feedback what I could do / how I could improve the patch to make it part of grub? If it possible at all with this approach?

Thank you for your reply & best,
Markus

---

--- grub-mod/grub-core/commands/videoinfo.c 2022-10-12
13:30:54.992451000 +0000
+++ grub/grub-core/commands/videoinfo.c 2022-10-12 13:31:37.715512000 +0000
@@ -30,7 +30,6 @@ GRUB_MOD_LICENSE ("GPLv3+");
struct hook_ctx
{
unsigned height, width, depth;
- unsigned char set_variable;
struct grub_video_mode_info *current_mode;
};

@@ -39,9 +38,6 @@ hook (const struct grub_video_mode_info
{
struct hook_ctx *ctx = hook_arg;

- if (ctx->set_variable) /* if variable should be set don't print all modes */
- return 0;
-
if (ctx->height && ctx->width && (info->width != ctx->width ||
info->height != ctx->height))

     return 0;

@@ -136,40 +132,31 @@ grub_cmd_videoinfo (grub_command_t cmd _
grub_video_adapter_t adapter; grub_video_driver_id_t id;
struct hook_ctx ctx;
-
- ctx.height = ctx.width = ctx.depth = ctx.set_variable = 0; -
+
+ ctx.height = ctx.width = ctx.depth = 0;
if (argc)

     {

- if (argc == 2 && grub_memcmp(args[0], "--set", sizeof ("--set") - 1)
== 0 )
- ctx.set_variable = 1;
- else

-        {
       const char *ptr;
       ptr = args[0];
       ctx.width = grub_strtoul (ptr, &ptr, 0);
       if (grub_errno)
-  return grub_errno;
+	return grub_errno;
       if (*ptr != 'x')

- return grub_error (GRUB_ERR_BAD_ARGUMENT,
- N_("invalid video mode specification `%s'"),
- args[0]);
+ return grub_error (GRUB_ERR_BAD_ARGUMENT,
+ N_("invalid video mode specification `%s'"),

+			   args[0]);
       ptr++;
       ctx.height = grub_strtoul (ptr, &ptr, 0);
       if (grub_errno)
-  return grub_errno;
+	return grub_errno;
       if (*ptr == 'x')
-  {
-    ptr++;
-    ctx.depth = grub_strtoul (ptr, &ptr, 0);
-    if (grub_errno)

- return grub_errno;
- }
- }
-
+ {

+	  ptr++;
+	  ctx.depth = grub_strtoul (ptr, &ptr, 0);
+	  if (grub_errno)
+	    return grub_errno;
+	}
     }

-
-

#ifdef GRUB_MACHINE_PCBIOS
if (grub_strcmp (cmd->name, "vbeinfo") == 0)
@@ -177,23 +164,20 @@ grub_cmd_videoinfo (grub_command_t cmd _
#endif

id = grub_video_get_driver_id ();
- if (!ctx.set_variable)
- {
-grub_puts_ (N_("List of supported video modes:")); -grub_puts_ (N_("Legend: mask/position=red/green/blue/reserved"));
- }
-
+
+ grub_puts_ (N_("List of supported video modes:"));
+ grub_puts_ (N_("Legend: mask/position=red/green/blue/reserved")); +
FOR_VIDEO_ADAPTERS (adapter)

   {
     struct grub_video_mode_info info;
     struct grub_video_edid_info edid_info;

- if (!ctx.set_variable)
- grub_printf_ (N_("Adapter `%s':\n"), adapter->name); +
+ grub_printf_ (N_("Adapter `%s':\n"), adapter->name);

     if (!adapter->iterate)
       {
-        if (!ctx.set_variable)
-    grub_puts_ (N_("  No info available"));
+	grub_puts_ (N_("  No info available"));
 	continue;
       }

@@ -202,18 +186,7 @@ grub_puts_ (N_("Legend: mask/position=re

     if (adapter->id == id)
       {

if (grub_video_get_info (&info) == GRUB_ERR_NONE)
- {
- ctx.current_mode = &info;
- if (ctx.set_variable)
- {

-    /* set grub env var to current mode */
-    char screen_wxh[20];
-    unsigned int width = info.width;
-    unsigned int height = info.height;
-    grub_snprintf (screen_wxh, 20, "%ux%u", width, height);
-    grub_env_set (args[1], screen_wxh);

- }
- }
+ ctx.current_mode = &info;
else
/* Don't worry about errors. */
grub_errno = GRUB_ERR_NONE;
@@ -263,26 +236,19 @@ GRUB_MOD_INIT(videoinfo)
/* TRANSLATORS: "x" has to be entered in,
like an identifier, so please don't use better Unicode codepoints. */
- N_("[--set var | [WxH]xD]"),
- N_("Retrieve available video modes. "

-             "--set is given, assign the currently"
-             "active resolution to var. If --set "
-             "is not provided the available video "
-             "modes are listed. If resolution is "
-             "given, show only matching modes."));

-
+ N_("[WxH[xD]]"),
+ N_("List available video modes. If "
+ "resolution is given show only modes"
+ " matching it."));
#ifdef GRUB_MACHINE_PCBIOS
cmd_vbe = grub_register_command ("vbeinfo", grub_cmd_videoinfo,
/* TRANSLATORS: "x" has to be entered in,
like an identifier, so please don't use better Unicode codepoints. */
- N_("[--set var | [WxH]xD]"),

-           N_("Retrieve available video modes. "
-           "--set is given, assign the currently"
-           "active resolution to var. If --set "
-           "is not provided the available video "
-           "modes are listed. If resolution is "
-           "given, show only matching modes."));

+ N_("[WxH[xD]]"),
+ N_("List available video modes. If "
+ "resolution is given show only modes"
+ " matching it."));
#endif
}

#1 lore raw

Adding Paul, Vladimir, and Zhang...

Quoted 25 lines · Markus Scholz

Dear Grub Developers,

recently we faced the problem the author in this old thread faced:
- https://lists.gnu.org/archive/html/grub-devel/2012-10/msg00009.html

Ie. our theme wouldn't display properly due to different screen resolutions. Hence, I wanted to change specifically the font size of our theme given the current resolution.
While the videoinfo module provides info about the current resolution I wasn't able to
discover any way to get the info from the booted grub.

Following the aforementioned thread, I therefore patched the videoinfo mod to add the ability
of a -set switch just like commands like "smbinfo" or "search" have.

Ie. the documentation of the videoinfo call could change as follows:

Command: videoinfo [--set var | [WxH]xD]

Retrieve available video modes. If --set is given, assign the currently
active resolution to var.
If --set is not provided the available video modes are listed. If resolution is given, show only matching modes.

Quoted 6 lines

Attached is my patch proposal for the module; I probably made a lot mistakes wrt.
coding style and guidelines - please bear with me.

I would be grateful regarding feedback what I could do / how I could improve the patch to make it part of grub? If it possible at all with this approach?

I think fix for similar problem has been proposed here [1] and I commented it here [2]. Sadly it ended in limbo. Could you work with Zhang on this issue?

Daniel

[1] https://lists.gnu.org/archive/html/grub-devel/2022-06/msg00143.html
[2] https://lists.gnu.org/archive/html/grub-devel/2022-07/msg00027.html

Quoted 168 lines

Thank you for your reply & best,
Markus

---

--- grub-mod/grub-core/commands/videoinfo.c 2022-10-12
13:30:54.992451000 +0000
+++ grub/grub-core/commands/videoinfo.c 2022-10-12 13:31:37.715512000 +0000

(quoted diff) +0 -4
@@ -30,7 +30,6 @@ GRUB_MOD_LICENSE ("GPLv3+");
 struct hook_ctx
 {
   unsigned height, width, depth;
-  unsigned char set_variable;
   struct grub_video_mode_info *current_mode;
 };
 
@@ -39,9 +38,6 @@ hook (const struct grub_video_mode_info
 {
   struct hook_ctx *ctx = hook_arg;
 
-  if (ctx->set_variable) /* if variable should be set don't print all modes
 */
-    return 0;
-
   if (ctx->height && ctx->width && (info->width != ctx->width ||
 info->height != ctx->height))
     return 0;
(quoted diff) +13 -22
@@ -136,40 +132,31 @@ grub_cmd_videoinfo (grub_command_t cmd _
   grub_video_adapter_t adapter;
   grub_video_driver_id_t id;
   struct hook_ctx ctx;
-
-  ctx.height = ctx.width = ctx.depth = ctx.set_variable = 0;
-
+
+  ctx.height = ctx.width = ctx.depth = 0;
   if (argc)
     {
-      if (argc == 2 && grub_memcmp(args[0], "--set", sizeof ("--set") - 1)
 == 0 )
-  ctx.set_variable = 1;
-      else
-        {
       const char *ptr;
       ptr = args[0];
       ctx.width = grub_strtoul (ptr, &ptr, 0);
       if (grub_errno)
-  return grub_errno;
+	return grub_errno;
       if (*ptr != 'x')
-  return grub_error (GRUB_ERR_BAD_ARGUMENT,
-        N_("invalid video mode specification `%s'"),
-        args[0]);
+	return grub_error (GRUB_ERR_BAD_ARGUMENT,
+			   N_("invalid video mode specification `%s'"),
+			   args[0]);
       ptr++;
       ctx.height = grub_strtoul (ptr, &ptr, 0);
       if (grub_errno)
-  return grub_errno;
+	return grub_errno;
       if (*ptr == 'x')
-  {
-    ptr++;
-    ctx.depth = grub_strtoul (ptr, &ptr, 0);
-    if (grub_errno)
-      return grub_errno;
-  }
-        }
-
+	{
+	  ptr++;
+	  ctx.depth = grub_strtoul (ptr, &ptr, 0);
+	  if (grub_errno)
+	    return grub_errno;
+	}
     }
-
-
 
 #ifdef GRUB_MACHINE_PCBIOS
   if (grub_strcmp (cmd->name, "vbeinfo") == 0)
(quoted diff) +16 -37
@@ -177,23 +164,20 @@ grub_cmd_videoinfo (grub_command_t cmd _
 #endif
 
   id = grub_video_get_driver_id ();
-  if (!ctx.set_variable)
-    {
-grub_puts_ (N_("List of supported video modes:"));
-grub_puts_ (N_("Legend: mask/position=red/green/blue/reserved"));
-    }
-
+
+  grub_puts_ (N_("List of supported video modes:"));
+  grub_puts_ (N_("Legend: mask/position=red/green/blue/reserved"));
+
   FOR_VIDEO_ADAPTERS (adapter)
   {
     struct grub_video_mode_info info;
     struct grub_video_edid_info edid_info;
-    if (!ctx.set_variable)
-  grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
+
+    grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
 
     if (!adapter->iterate)
       {
-        if (!ctx.set_variable)
-    grub_puts_ (N_("  No info available"));
+	grub_puts_ (N_("  No info available"));
 	continue;
       }
 
@@ -202,18 +186,7 @@ grub_puts_ (N_("Legend: mask/position=re
     if (adapter->id == id)
       {
 	if (grub_video_get_info (&info) == GRUB_ERR_NONE)
-    {
-      ctx.current_mode = &info;
-      if (ctx.set_variable)
-        {
-    /* set grub env var to current mode */
-    char screen_wxh[20];
-    unsigned int width = info.width;
-    unsigned int height = info.height;
-    grub_snprintf (screen_wxh, 20, "%ux%u", width, height);
-    grub_env_set (args[1], screen_wxh);
-        }
-    }
+	  ctx.current_mode = &info;
 	else
 	  /* Don't worry about errors.  */
 	  grub_errno = GRUB_ERR_NONE;
@@ -263,26 +236,19 @@ GRUB_MOD_INIT(videoinfo)
 			       /* TRANSLATORS: "x" has to be entered in,
 				  like an identifier, so please don't
 				  use better Unicode codepoints.  */
-			       N_("[--set var | [WxH]xD]"),
-			       N_("Retrieve available video modes. "
-             "--set is given, assign the currently"
-             "active resolution to var. If --set "
-             "is not provided the available video "
-             "modes are listed. If resolution is "
-             "given, show only matching modes."));
-
+			       N_("[WxH[xD]]"),
+			       N_("List available video modes. If "
+				     "resolution is given show only modes"
+				     " matching it."));
 #ifdef GRUB_MACHINE_PCBIOS
   cmd_vbe = grub_register_command ("vbeinfo", grub_cmd_videoinfo,
 				   /* TRANSLATORS: "x" has to be entered in,
 				      like an identifier, so please don't
 				      use better Unicode codepoints.  */
-				   N_("[--set var | [WxH]xD]"),
-           N_("Retrieve available video modes. "
-           "--set is given, assign the currently"
-           "active resolution to var. If --set "
-           "is not provided the available video "
-           "modes are listed. If resolution is "
-           "given, show only matching modes."));
+				   N_("[WxH[xD]]"),
+				   N_("List available video modes. If "
+				      "resolution is given show only modes"
+				      " matching it."));
 #endif
 }
#2 lore raw

Hi all,

* I checked the links by Daniel (thanks for providing).
* As I understand it Zhangs patches aim to add a high dpi scaling feature for the fonts
* In contrast, the patch I submitted (albeit having a similar use-case) adds the possibility
for grub "scripts" / config files to access & act upon the currently used display resolution
* for me both things would have their merit and independent use-cases

What is your opinion on having both features?

Besides, I am willing to help progress both features - if someone can guide me /give a hint
how to proceed best?

Thank you
Markus

-----Ursprüngliche Nachricht-----
Von: Daniel Kiper <[email protected]>
Gesendet: Donnerstag, 20. Oktober 2022 19:36
An: Markus Scholz <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Betreff: Re: Adding --set to videoinfo to retrieve current video resolution

Adding Paul, Vladimir, and Zhang...

Quoted 6 lines · Markus Scholz

Dear Grub Developers,

recently we faced the problem the author in this old thread faced:
- https://lists.gnu.org/archive/html/grub-devel/2012-10/msg00009.html

Ie. our theme wouldn't display properly due to different screen

resolutions.

Quoted 19 lines

Hence, I wanted to change specifically the font size of our theme given the current resolution.
While the videoinfo module provides info about the current resolution I wasn't able to discover any way to get the info from the booted grub.

Following the aforementioned thread, I therefore patched the videoinfo mod to add the ability of a -set switch just like commands like "smbinfo" or "search" have.

Ie. the documentation of the videoinfo call could change as follows:

Command: videoinfo [--set var | [WxH]xD]

Retrieve available video modes. If --set is given, assign the
currently active resolution to var.
If --set is not provided the available video modes are listed. If resolution is given, show only matching modes.

Quoted 6 lines

Attached is my patch proposal for the module; I probably made a lot mistakes wrt.
coding style and guidelines - please bear with me.

I would be grateful regarding feedback what I could do / how I could improve the patch to make it part of grub? If it possible at all with this

approach?

I think fix for similar problem has been proposed here [1] and I commented it here [2]. Sadly it ended in limbo. Could you work with Zhang on this issue?

Daniel

[1] https://lists.gnu.org/archive/html/grub-devel/2022-06/msg00143.html
[2] https://lists.gnu.org/archive/html/grub-devel/2022-07/msg00027.html

Quoted 8 lines

Thank you for your reply & best,
Markus

---

--- grub-mod/grub-core/commands/videoinfo.c 2022-10-12
13:30:54.992451000 +0000
+++ grub/grub-core/commands/videoinfo.c 2022-10-12

13:31:37.715512000 +0000

Quoted 18 lines
(quoted diff) +0 -2
@@ -30,7 +30,6 @@ GRUB_MOD_LICENSE ("GPLv3+");  struct hook_ctx  {
   unsigned height, width, depth;
-  unsigned char set_variable;
   struct grub_video_mode_info *current_mode;  };
 
@@ -39,9 +38,6 @@ hook (const struct grub_video_mode_info  {
   struct hook_ctx *ctx = hook_arg;
 
-  if (ctx->set_variable) /* if variable should be set don't print all 

modes */

(quoted diff) +0 -2
-    return 0;
-
   if (ctx->height && ctx->width && (info->width != ctx->width ||

info->height != ctx->height))

     return 0;
(quoted diff) +0 -0
@@ -136,40 +132,31 @@ grub_cmd_videoinfo (grub_command_t cmd _
   grub_video_adapter_t adapter;

Review grub_cmd_videoinfo (grub_command_t cmd _ · line 144

Quoted 10 lines
(quoted diff) +2 -4
   grub_video_driver_id_t id;
   struct hook_ctx ctx;
-
-  ctx.height = ctx.width = ctx.depth = ctx.set_variable = 0;
-
+
+  ctx.height = ctx.width = ctx.depth = 0;
   if (argc)
     {
-      if (argc == 2 && grub_memcmp(args[0], "--set", sizeof ("--set") -

1)

Quoted 127 lines
(quoted diff) +11 -18
 == 0 )
-  ctx.set_variable = 1;
-      else
-        {
       const char *ptr;
       ptr = args[0];
       ctx.width = grub_strtoul (ptr, &ptr, 0);
       if (grub_errno)
-  return grub_errno;
+	return grub_errno;
       if (*ptr != 'x')
-  return grub_error (GRUB_ERR_BAD_ARGUMENT,
-        N_("invalid video mode specification `%s'"),
-        args[0]);
+	return grub_error (GRUB_ERR_BAD_ARGUMENT,
+			   N_("invalid video mode specification `%s'"),
+			   args[0]);
       ptr++;
       ctx.height = grub_strtoul (ptr, &ptr, 0);
       if (grub_errno)
-  return grub_errno;
+	return grub_errno;
       if (*ptr == 'x')
-  {
-    ptr++;
-    ctx.depth = grub_strtoul (ptr, &ptr, 0);
-    if (grub_errno)
-      return grub_errno;
-  }
-        }
-
+	{
+	  ptr++;
+	  ctx.depth = grub_strtoul (ptr, &ptr, 0);
+	  if (grub_errno)
+	    return grub_errno;
+	}
     }
-
-
 
 #ifdef GRUB_MACHINE_PCBIOS
   if (grub_strcmp (cmd->name, "vbeinfo") == 0) @@ -177,23 +164,20 @@ 

grub_cmd_videoinfo (grub_command_t cmd _ #endif

   id = grub_video_get_driver_id ();
(quoted diff) +0 -3
-  if (!ctx.set_variable)
-    {
-grub_puts_ (N_("List of supported video modes:")); -grub_puts_ 

(N_("Legend: mask/position=red/green/blue/reserved"));

(quoted diff) +16 -33
-    }
-
+
+  grub_puts_ (N_("List of supported video modes:"));  grub_puts_ 
+ (N_("Legend: mask/position=red/green/blue/reserved"));
+
   FOR_VIDEO_ADAPTERS (adapter)
   {
     struct grub_video_mode_info info;
     struct grub_video_edid_info edid_info;
-    if (!ctx.set_variable)
-  grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
+
+    grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
 
     if (!adapter->iterate)
       {
-        if (!ctx.set_variable)
-    grub_puts_ (N_("  No info available"));
+	grub_puts_ (N_("  No info available"));
 	continue;
       }
@@ -202,18 +186,7 @@ grub_puts_ (N_("Legend: mask/position=re
     if (adapter->id == id)
       {
 	if (grub_video_get_info (&info) == GRUB_ERR_NONE)
-    {
-      ctx.current_mode = &info;
-      if (ctx.set_variable)
-        {
-    /* set grub env var to current mode */
-    char screen_wxh[20];
-    unsigned int width = info.width;
-    unsigned int height = info.height;
-    grub_snprintf (screen_wxh, 20, "%ux%u", width, height);
-    grub_env_set (args[1], screen_wxh);
-        }
-    }
+	  ctx.current_mode = &info;
 	else
 	  /* Don't worry about errors.  */
 	  grub_errno = GRUB_ERR_NONE;
@@ -263,26 +236,19 @@ GRUB_MOD_INIT(videoinfo)
 			       /* TRANSLATORS: "x" has to be entered in,
 				  like an identifier, so please don't
 				  use better Unicode codepoints.  */
-			       N_("[--set var | [WxH]xD]"),
-			       N_("Retrieve available video modes. "
-             "--set is given, assign the currently"
-             "active resolution to var. If --set "
-             "is not provided the available video "
-             "modes are listed. If resolution is "
-             "given, show only matching modes."));
-
+			       N_("[WxH[xD]]"),
+			       N_("List available video modes. If "
+				     "resolution is given show only modes"
+				     " matching it."));
 #ifdef GRUB_MACHINE_PCBIOS
   cmd_vbe = grub_register_command ("vbeinfo", grub_cmd_videoinfo,
 				   /* TRANSLATORS: "x" has to be entered in,
 				      like an identifier, so please don't
 				      use better Unicode codepoints.  */
-				   N_("[--set var | [WxH]xD]"),
-           N_("Retrieve available video modes. "
-           "--set is given, assign the currently"
-           "active resolution to var. If --set "
-           "is not provided the available video "
-           "modes are listed. If resolution is "
-           "given, show only matching modes."));
+				   N_("[WxH[xD]]"),
+				   N_("List available video modes. If "
+				      "resolution is given show only modes"
+				      " matching it."));
 #endif
 }
#3 lore raw

Hi,

Sorry for late reply... I think my patch is almost independent of Markus's, and it would be good to have both. However, I think there are some point we can share opinions. I'd like to ask your opinions of the mechanism of choosing font size automatically. In my patch (preliminary), it scales Unifont(16x16) M times on a N x 1080p screen, with M = pow(2,ceil(log2(N))), e.g. 2x when (1080p, 2160p], 4x when (2160p, 4320p], 8x when (4320p, 8640p]. This approach seems not good enough, and it might not suitable for custom themes. What's your opinion on this from your perspective? I will probably go back to work on my HiDPI patch after few weeks.

By the way, if I understand correctly, you patch seems reversed, and your mail client seems corrupted your patch. You might find "git format-patch" and "git send-email" useful :)

Best Regards,
Zhang Boyang

Quoted 241 lines · Markus Scholz

Hi all,

* I checked the links by Daniel (thanks for providing).
* As I understand it Zhangs patches aim to add a high dpi scaling feature for the fonts
* In contrast, the patch I submitted (albeit having a similar use-case) adds the possibility
for grub "scripts" / config files to access & act upon the currently used display resolution
* for me both things would have their merit and independent use-cases

What is your opinion on having both features?

Besides, I am willing to help progress both features - if someone can guide me /give a hint
how to proceed best?

Thank you
Markus

-----Ursprüngliche Nachricht-----
Von: Daniel Kiper <[email protected]>
Gesendet: Donnerstag, 20. Oktober 2022 19:36
An: Markus Scholz <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Betreff: Re: Adding --set to videoinfo to retrieve current video resolution

Adding Paul, Vladimir, and Zhang...

Quoted 6 lines · Markus Scholz

Dear Grub Developers,

recently we faced the problem the author in this old thread faced:
- https://lists.gnu.org/archive/html/grub-devel/2012-10/msg00009.html

Ie. our theme wouldn't display properly due to different screen

resolutions.

Quoted 19 lines

Hence, I wanted to change specifically the font size of our theme given the current resolution.
While the videoinfo module provides info about the current resolution I wasn't able to discover any way to get the info from the booted grub.

Following the aforementioned thread, I therefore patched the videoinfo mod to add the ability of a -set switch just like commands like "smbinfo" or "search" have.

Ie. the documentation of the videoinfo call could change as follows:

Command: videoinfo [--set var | [WxH]xD]

Retrieve available video modes. If --set is given, assign the
currently active resolution to var.
If --set is not provided the available video modes are listed. If resolution is given, show only matching modes.

Quoted 6 lines

Attached is my patch proposal for the module; I probably made a lot mistakes wrt.
coding style and guidelines - please bear with me.

I would be grateful regarding feedback what I could do / how I could improve the patch to make it part of grub? If it possible at all with this

approach?

I think fix for similar problem has been proposed here [1] and I commented it here [2]. Sadly it ended in limbo. Could you work with Zhang on this issue?

Daniel

[1] https://lists.gnu.org/archive/html/grub-devel/2022-06/msg00143.html
[2] https://lists.gnu.org/archive/html/grub-devel/2022-07/msg00027.html

Quoted 8 lines

Thank you for your reply & best,
Markus

---

--- grub-mod/grub-core/commands/videoinfo.c 2022-10-12
13:30:54.992451000 +0000
+++ grub/grub-core/commands/videoinfo.c 2022-10-12

13:31:37.715512000 +0000

Quoted 18 lines
(quoted diff) +0 -2
@@ -30,7 +30,6 @@ GRUB_MOD_LICENSE ("GPLv3+");  struct hook_ctx  {
    unsigned height, width, depth;
-  unsigned char set_variable;
    struct grub_video_mode_info *current_mode;  };
 
@@ -39,9 +38,6 @@ hook (const struct grub_video_mode_info  {
    struct hook_ctx *ctx = hook_arg;
 
-  if (ctx->set_variable) /* if variable should be set don't print all

modes */

(quoted diff) +0 -2
-    return 0;
-
    if (ctx->height && ctx->width && (info->width != ctx->width ||

info->height != ctx->height))

      return 0;
(quoted diff) +0 -0
@@ -136,40 +132,31 @@ grub_cmd_videoinfo (grub_command_t cmd _
    grub_video_adapter_t adapter;

Review grub_cmd_videoinfo (grub_command_t cmd _ · line 144

Quoted 10 lines
(quoted diff) +2 -4
    grub_video_driver_id_t id;
    struct hook_ctx ctx;
-
-  ctx.height = ctx.width = ctx.depth = ctx.set_variable = 0;
-
+
+  ctx.height = ctx.width = ctx.depth = 0;
    if (argc)
      {
-      if (argc == 2 && grub_memcmp(args[0], "--set", sizeof ("--set") -

1)

Quoted 127 lines
(quoted diff) +11 -18
 == 0 )
-  ctx.set_variable = 1;
-      else
-        {
        const char *ptr;
        ptr = args[0];
        ctx.width = grub_strtoul (ptr, &ptr, 0);
        if (grub_errno)
-  return grub_errno;
+	return grub_errno;
        if (*ptr != 'x')
-  return grub_error (GRUB_ERR_BAD_ARGUMENT,
-        N_("invalid video mode specification `%s'"),
-        args[0]);
+	return grub_error (GRUB_ERR_BAD_ARGUMENT,
+			   N_("invalid video mode specification `%s'"),
+			   args[0]);
        ptr++;
        ctx.height = grub_strtoul (ptr, &ptr, 0);
        if (grub_errno)
-  return grub_errno;
+	return grub_errno;
        if (*ptr == 'x')
-  {
-    ptr++;
-    ctx.depth = grub_strtoul (ptr, &ptr, 0);
-    if (grub_errno)
-      return grub_errno;
-  }
-        }
-
+	{
+	  ptr++;
+	  ctx.depth = grub_strtoul (ptr, &ptr, 0);
+	  if (grub_errno)
+	    return grub_errno;
+	}
      }
-
-
 
  #ifdef GRUB_MACHINE_PCBIOS
    if (grub_strcmp (cmd->name, "vbeinfo") == 0) @@ -177,23 +164,20 @@

grub_cmd_videoinfo (grub_command_t cmd _ #endif

    id = grub_video_get_driver_id ();
(quoted diff) +0 -3
-  if (!ctx.set_variable)
-    {
-grub_puts_ (N_("List of supported video modes:")); -grub_puts_

(N_("Legend: mask/position=red/green/blue/reserved"));

(quoted diff) +16 -33
-    }
-
+
+  grub_puts_ (N_("List of supported video modes:"));  grub_puts_
+ (N_("Legend: mask/position=red/green/blue/reserved"));
+
    FOR_VIDEO_ADAPTERS (adapter)
    {
      struct grub_video_mode_info info;
      struct grub_video_edid_info edid_info;
-    if (!ctx.set_variable)
-  grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
+
+    grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
 
      if (!adapter->iterate)
        {
-        if (!ctx.set_variable)
-    grub_puts_ (N_("  No info available"));
+	grub_puts_ (N_("  No info available"));
  	continue;
        }
@@ -202,18 +186,7 @@ grub_puts_ (N_("Legend: mask/position=re
      if (adapter->id == id)
        {
  	if (grub_video_get_info (&info) == GRUB_ERR_NONE)
-    {
-      ctx.current_mode = &info;
-      if (ctx.set_variable)
-        {
-    /* set grub env var to current mode */
-    char screen_wxh[20];
-    unsigned int width = info.width;
-    unsigned int height = info.height;
-    grub_snprintf (screen_wxh, 20, "%ux%u", width, height);
-    grub_env_set (args[1], screen_wxh);
-        }
-    }
+	  ctx.current_mode = &info;
  	else
  	  /* Don't worry about errors.  */
  	  grub_errno = GRUB_ERR_NONE;
@@ -263,26 +236,19 @@ GRUB_MOD_INIT(videoinfo)
  			       /* TRANSLATORS: "x" has to be entered in,
  				  like an identifier, so please don't
  				  use better Unicode codepoints.  */
-			       N_("[--set var | [WxH]xD]"),
-			       N_("Retrieve available video modes. "
-             "--set is given, assign the currently"
-             "active resolution to var. If --set "
-             "is not provided the available video "
-             "modes are listed. If resolution is "
-             "given, show only matching modes."));
-
+			       N_("[WxH[xD]]"),
+			       N_("List available video modes. If "
+				     "resolution is given show only modes"
+				     " matching it."));
  #ifdef GRUB_MACHINE_PCBIOS
    cmd_vbe = grub_register_command ("vbeinfo", grub_cmd_videoinfo,
  				   /* TRANSLATORS: "x" has to be entered in,
  				      like an identifier, so please don't
  				      use better Unicode codepoints.  */
-				   N_("[--set var | [WxH]xD]"),
-           N_("Retrieve available video modes. "
-           "--set is given, assign the currently"
-           "active resolution to var. If --set "
-           "is not provided the available video "
-           "modes are listed. If resolution is "
-           "given, show only matching modes."));
+				   N_("[WxH[xD]]"),
+				   N_("List available video modes. If "
+				      "resolution is given show only modes"
+				      " matching it."));
  #endif
  }
#4 lore raw

Hi Zhang,

now I need to apologize for my very late reply.. sorry!
I saw that you also went ahead as you said with committing the highdpi patches.

Anyways, regarding the high DPI question:
until now we have mostly focused on different screen resolutions in our customer offerings and simply chose the font size based on visual testing. So we did not attempt to solve this "mathematically".

E.g. right now use:
- x_res >= 1024; bootmenu font ubuntu regular 20 (large theme)
- x_res == 1204; bootmenu font ubuntu regular 17 (medium theme)
- x_res < 1024 & unknown ; bootmenu font ubuntu regular 15 (small theme)

I don’t know if this helpful for you but that’s the current state we are using to keep the text readable given different resolutions. Of course, for the different fonts/themes (small, medium, large) the screens still look different i.e. the user experience is not consistent. Maybe using your highDPI patch it will become much easier to
make the appearance consistent and more appealing across different screen resolutions.

Note that we exclusively use gfxmode for our application, avoiding text mode. We believe that, for our application, this gives a much more polished and mature look&feel.

Also thank you for your recommendation for the patch submission.
I will attempt to send another reply to this thread with the help of git patch asap.

Best
Markus

-----Ursprüngliche Nachricht-----
Von: [email protected] <[email protected]> Im Auftrag von Zhang Boyang
Gesendet: Montag, 7. November 2022 08:56
An: Markus Scholz <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; 'Daniel Kiper' <[email protected]>
Betreff: Re: AW: Adding --set to videoinfo to retrieve current video resolution

Hi,

Sorry for late reply... I think my patch is almost independent of Markus's, and it would be good to have both. However, I think there are some point we can share opinions. I'd like to ask your opinions of the mechanism of choosing font size automatically. In my patch (preliminary), it scales Unifont(16x16) M times on a N x 1080p screen, with M = pow(2,ceil(log2(N))), e.g. 2x when (1080p, 2160p], 4x when (2160p, 4320p], 8x when (4320p, 8640p]. This approach seems not good enough, and it might not suitable for custom themes. What's your opinion on this from your perspective? I will probably go back to work on my HiDPI patch after few weeks.

By the way, if I understand correctly, you patch seems reversed, and your mail client seems corrupted your patch. You might find "git format-patch" and "git send-email" useful :)

Best Regards,
Zhang Boyang

Quoted 234 lines · Markus Scholz

Hi all,

* I checked the links by Daniel (thanks for providing).
* As I understand it Zhangs patches aim to add a high dpi scaling feature for the fonts
* In contrast, the patch I submitted (albeit having a similar use-case) adds the possibility for grub "scripts" / config files to access & act upon the currently used display resolution
* for me both things would have their merit and independent use-cases

What is your opinion on having both features?

Besides, I am willing to help progress both features - if someone can guide me /give a hint how to proceed best?

Thank you
Markus

-----Ursprüngliche Nachricht-----
Von: Daniel Kiper <[email protected]>
Gesendet: Donnerstag, 20. Oktober 2022 19:36
An: Markus Scholz <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Betreff: Re: Adding --set to videoinfo to retrieve current video resolution

Adding Paul, Vladimir, and Zhang...

Quoted 6 lines · Markus Scholz

Dear Grub Developers,

recently we faced the problem the author in this old thread faced:
- https://lists.gnu.org/archive/html/grub-devel/2012-10/msg00009.html

Ie. our theme wouldn't display properly due to different screen

resolutions.

Quoted 19 lines

Hence, I wanted to change specifically the font size of our theme given the current resolution.
While the videoinfo module provides info about the current resolution I wasn't able to discover any way to get the info from the booted grub.

Following the aforementioned thread, I therefore patched the videoinfo mod to add the ability of a -set switch just like commands like "smbinfo" or "search" have.

Ie. the documentation of the videoinfo call could change as follows:

Command: videoinfo [--set var | [WxH]xD]

Retrieve available video modes. If --set is given, assign the
currently active resolution to var.
If --set is not provided the available video modes are listed. If resolution is given, show only matching modes.

Quoted 7 lines

Attached is my patch proposal for the module; I probably made a lot mistakes wrt.
coding style and guidelines - please bear with me.

I would be grateful regarding feedback what I could do / how I could improve the patch to make it part of grub? If it possible at all with this

approach?

I think fix for similar problem has been proposed here [1] and I commented it here [2]. Sadly it ended in limbo. Could you work with Zhang on this issue?

Daniel

[1]
https://lists.gnu.org/archive/html/grub-devel/2022-06/msg00143.html
[2]
https://lists.gnu.org/archive/html/grub-devel/2022-07/msg00027.html

Quoted 8 lines

Thank you for your reply & best,
Markus

---

--- grub-mod/grub-core/commands/videoinfo.c 2022-10-12
13:30:54.992451000 +0000
+++ grub/grub-core/commands/videoinfo.c 2022-10-12

13:31:37.715512000 +0000

Quoted 18 lines
(quoted diff) +0 -2
@@ -30,7 +30,6 @@ GRUB_MOD_LICENSE ("GPLv3+");  struct hook_ctx  {
    unsigned height, width, depth;
-  unsigned char set_variable;
    struct grub_video_mode_info *current_mode;  };
 
@@ -39,9 +38,6 @@ hook (const struct grub_video_mode_info  {
    struct hook_ctx *ctx = hook_arg;
 
-  if (ctx->set_variable) /* if variable should be set don't print 

all modes */

(quoted diff) +0 -2
-    return 0;
-
    if (ctx->height && ctx->width && (info->width != ctx->width ||

info->height != ctx->height))

      return 0;
(quoted diff) +0 -0
@@ -136,40 +132,31 @@ grub_cmd_videoinfo (grub_command_t cmd _
    grub_video_adapter_t adapter;

Review grub_cmd_videoinfo (grub_command_t cmd _ · line 144

Quoted 10 lines
(quoted diff) +2 -4
    grub_video_driver_id_t id;
    struct hook_ctx ctx;
-
-  ctx.height = ctx.width = ctx.depth = ctx.set_variable = 0;
-
+
+  ctx.height = ctx.width = ctx.depth = 0;
    if (argc)
      {
-      if (argc == 2 && grub_memcmp(args[0], "--set", sizeof ("--set") -

1)

Quoted 119 lines
(quoted diff) +11 -18
 == 0 )
-  ctx.set_variable = 1;
-      else
-        {
        const char *ptr;
        ptr = args[0];
        ctx.width = grub_strtoul (ptr, &ptr, 0);
        if (grub_errno)
-  return grub_errno;
+	return grub_errno;
        if (*ptr != 'x')
-  return grub_error (GRUB_ERR_BAD_ARGUMENT,
-        N_("invalid video mode specification `%s'"),
-        args[0]);
+	return grub_error (GRUB_ERR_BAD_ARGUMENT,
+			   N_("invalid video mode specification `%s'"),
+			   args[0]);
        ptr++;
        ctx.height = grub_strtoul (ptr, &ptr, 0);
        if (grub_errno)
-  return grub_errno;
+	return grub_errno;
        if (*ptr == 'x')
-  {
-    ptr++;
-    ctx.depth = grub_strtoul (ptr, &ptr, 0);
-    if (grub_errno)
-      return grub_errno;
-  }
-        }
-
+	{
+	  ptr++;
+	  ctx.depth = grub_strtoul (ptr, &ptr, 0);
+	  if (grub_errno)
+	    return grub_errno;
+	}
      }
-
-
 
  #ifdef GRUB_MACHINE_PCBIOS
    if (grub_strcmp (cmd->name, "vbeinfo") == 0) @@ -177,23 +164,20 

@@ grub_cmd_videoinfo (grub_command_t cmd _ #endif

    id = grub_video_get_driver_id ();
(quoted diff) +0 -3
-  if (!ctx.set_variable)
-    {
-grub_puts_ (N_("List of supported video modes:")); -grub_puts_

(N_("Legend: mask/position=red/green/blue/reserved"));

(quoted diff) +12 -31
-    }
-
+
+  grub_puts_ (N_("List of supported video modes:"));  grub_puts_
+ (N_("Legend: mask/position=red/green/blue/reserved"));
+
    FOR_VIDEO_ADAPTERS (adapter)
    {
      struct grub_video_mode_info info;
      struct grub_video_edid_info edid_info;
-    if (!ctx.set_variable)
-  grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
+
+    grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
 
      if (!adapter->iterate)
        {
-        if (!ctx.set_variable)
-    grub_puts_ (N_("  No info available"));
+	grub_puts_ (N_("  No info available"));
  	continue;
        }
@@ -202,18 +186,7 @@ grub_puts_ (N_("Legend: mask/position=re
      if (adapter->id == id)
        {
  	if (grub_video_get_info (&info) == GRUB_ERR_NONE)
-    {
-      ctx.current_mode = &info;
-      if (ctx.set_variable)
-        {
-    /* set grub env var to current mode */
-    char screen_wxh[20];
-    unsigned int width = info.width;
-    unsigned int height = info.height;
-    grub_snprintf (screen_wxh, 20, "%ux%u", width, height);
-    grub_env_set (args[1], screen_wxh);
-        }
-    }
+	  ctx.current_mode = &info;
  	else
  	  /* Don't worry about errors.  */
  	  grub_errno = GRUB_ERR_NONE;
@@ -263,26 +236,19 @@ GRUB_MOD_INIT(videoinfo)
  			       /* TRANSLATORS: "x" has to be entered in,
  				  like an identifier, so please don't
  				  use better Unicode codepoints.  */
-			       N_("[--set var | [WxH]xD]"),
-			       N_("Retrieve available video modes. "
-             "--set is given, assign the currently"
-             "active resolution to var. If --set "
-             "is not provided the available video "
-             "modes are listed. If resolution is "
-             "given, show only matching modes."));
-
+			       N_("[WxH[xD]]"),
+			       N_("List available video modes. If "
+				     "resolution is given show only modes"
+				     " matching it."));
  #ifdef GRUB_MACHINE_PCBIOS
    cmd_vbe = grub_register_command ("vbeinfo", grub_cmd_videoinfo,
  				   /* TRANSLATORS: "x" has to be entered in,
  				      like an identifier, so please don't
  				      use better Unicode codepoints.  */
-				   N_("[--set var | [WxH]xD]"),
-           N_("Retrieve available video modes. "
-           "--set is given, assign the currently"
-           "active resolution to var. If --set "
-           "is not provided the available video "
Quoted 9 lines

Review GRUB_MOD_INIT(videoinfo) · line 253

Quoted 8 lines
(quoted diff) +4 -2
-           "modes are listed. If resolution is "
-           "given, show only matching modes."));
+				   N_("[WxH[xD]]"),
+				   N_("List available video modes. If "
+				      "resolution is given show only modes"
+				      " matching it."));
  #endif
  }

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#5 lore raw

cover feat: add --set argument to videoinfo to write current resolution to grub env var

Hi, here is my attempt to provide the patch using git format-patch and git send-mail.

This extends the videoinfo module to provide a --set argument which contains the currently active video resolution.

Documentation could be extended as follows:

Command: videoinfo [--set var | [WxH]xD]

Retrieve available video modes. If --set is given, assign the currently active resolution to var.
If --set is not provided the available video modes are listed. If resolution is given, show only matching modes.

scholz (1):
feat: add --set argument to videoinfo to write current resolution to
grub env var

 grub-core/commands/videoinfo.c | 92 +++++++++++++++++++++++-----------
 1 file changed, 63 insertions(+), 29 deletions(-)
Signature · 1 line
2.34.1
#6 lore raw

PATCH 1/1 feat: add --set argument to videoinfo to write current resolution to grub env var

---
 grub-core/commands/videoinfo.c | 92 +++++++++++++++++++++++-----------
 1 file changed, 63 insertions(+), 29 deletions(-)
grub-core/commands/videoinfo.c +63 -29
index 5eb969748..75e3b4e9f 100644
@@ -30,6 +30,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
 struct hook_ctx
 {
   unsigned height, width, depth;
+  unsigned char set_variable; 
   struct grub_video_mode_info *current_mode;
 };
 
@@ -38,6 +39,9 @@ hook (const struct grub_video_mode_info *info, void *hook_arg)
 {
   struct hook_ctx *ctx = hook_arg;
 
+  if (ctx->set_variable) /* if variable should be set don't print all modes */
+    return 0;
+
   if (ctx->height && ctx->width && (info->width != ctx->width || info->height != ctx->height))
     return 0;
 
@@ -132,31 +136,40 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
   grub_video_adapter_t adapter;
   grub_video_driver_id_t id;
   struct hook_ctx ctx;
-
-  ctx.height = ctx.width = ctx.depth = 0;
+  
+  ctx.height = ctx.width = ctx.depth = ctx.set_variable = 0;
+  
   if (argc)
     {
+      if (argc == 2 && grub_memcmp(args[0], "--set", sizeof ("--set") - 1) == 0 )
+  ctx.set_variable = 1;
+      else
+        {
       const char *ptr;
       ptr = args[0];
       ctx.width = grub_strtoul (ptr, &ptr, 0);
       if (grub_errno)
-	return grub_errno;
+  return grub_errno;
       if (*ptr != 'x')
-	return grub_error (GRUB_ERR_BAD_ARGUMENT,
-			   N_("invalid video mode specification `%s'"),
-			   args[0]);
+  return grub_error (GRUB_ERR_BAD_ARGUMENT,
+        N_("invalid video mode specification `%s'"),
+        args[0]);
       ptr++;
       ctx.height = grub_strtoul (ptr, &ptr, 0);
       if (grub_errno)
-	return grub_errno;
+  return grub_errno;
       if (*ptr == 'x')
-	{
-	  ptr++;
-	  ctx.depth = grub_strtoul (ptr, &ptr, 0);
-	  if (grub_errno)
-	    return grub_errno;
-	}
+  {
+    ptr++;
+    ctx.depth = grub_strtoul (ptr, &ptr, 0);
+    if (grub_errno)
+      return grub_errno;
+  }
+        }
+
     }
+  
+
 
 #ifdef GRUB_MACHINE_PCBIOS
   if (grub_strcmp (cmd->name, "vbeinfo") == 0)
@@ -164,20 +177,23 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
 #endif
 
   id = grub_video_get_driver_id ();
-
-  grub_puts_ (N_("List of supported video modes:"));
-  grub_puts_ (N_("Legend: mask/position=red/green/blue/reserved"));
-
+  if (!ctx.set_variable)
+    {
+grub_puts_ (N_("List of supported video modes:"));
+grub_puts_ (N_("Legend: mask/position=red/green/blue/reserved"));
+    }
+  
   FOR_VIDEO_ADAPTERS (adapter)
   {
     struct grub_video_mode_info info;
     struct grub_video_edid_info edid_info;
-
-    grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
+    if (!ctx.set_variable)
+  grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
 
     if (!adapter->iterate)
       {
-	grub_puts_ (N_("  No info available"));
+        if (!ctx.set_variable)
+    grub_puts_ (N_("  No info available"));
 	continue;
       }
 
@@ -186,7 +202,18 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
     if (adapter->id == id)
       {
 	if (grub_video_get_info (&info) == GRUB_ERR_NONE)
-	  ctx.current_mode = &info;
+    {
+      ctx.current_mode = &info;
+      if (ctx.set_variable)
+        {
+    /* set grub env var to current mode */
+    char screen_wxh[20];
+    unsigned int width = info.width;
+    unsigned int height = info.height;
+    grub_snprintf (screen_wxh, 20, "%ux%u", width, height);
+    grub_env_set (args[1], screen_wxh);
+        }
+    }
 	else
 	  /* Don't worry about errors.  */
 	  grub_errno = GRUB_ERR_NONE;
@@ -236,19 +263,26 @@ GRUB_MOD_INIT(videoinfo)
 			       /* TRANSLATORS: "x" has to be entered in,
 				  like an identifier, so please don't
 				  use better Unicode codepoints.  */
-			       N_("[WxH[xD]]"),
-			       N_("List available video modes. If "
-				     "resolution is given show only modes"
-				     " matching it."));
+			       N_("[--set var | [WxH]xD]"),
+			       N_("Retrieve available video modes. "
+             "--set is given, assign the currently"
+             "active resolution to var. If --set "
+             "is not provided the available video "
+             "modes are listed. If resolution is "
+             "given, show only matching modes."));
+
 #ifdef GRUB_MACHINE_PCBIOS
   cmd_vbe = grub_register_command ("vbeinfo", grub_cmd_videoinfo,
 				   /* TRANSLATORS: "x" has to be entered in,
 				      like an identifier, so please don't
 				      use better Unicode codepoints.  */
-				   N_("[WxH[xD]]"),
-				   N_("List available video modes. If "
-				      "resolution is given show only modes"
-				      " matching it."));
+				   N_("[--set var | [WxH]xD]"),
+           N_("Retrieve available video modes. "
+           "--set is given, assign the currently"
+           "active resolution to var. If --set "
+           "is not provided the available video "
+           "modes are listed. If resolution is "
+           "given, show only matching modes."));
 #endif
 }
 
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH 1/1] feat: add --set argument to videoinfo to write current resolution to grub env var

Hi,

Quoted 4 lines · Markus Scholz
---
  grub-core/commands/videoinfo.c | 92 +++++++++++++++++++++++-----------
  1 file changed, 63 insertions(+), 29 deletions(-)

Commit message shouldn't be empty. You need to write something about your changes. You also need to add your Signed-off-by tags.

grub-core/commands/videoinfo.c GRUB_MOD_LICENSE ("GPLv3+"); · line 33

Quoted 9 lines
grub-core/commands/videoinfo.c +1 -0
index 5eb969748..75e3b4e9f 100644
@@ -30,6 +30,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
  struct hook_ctx
  {
    unsigned height, width, depth;
+  unsigned char set_variable;

bool can be used instead of unsigned char here.

Quoted 15 lines
grub-core/commands/videoinfo.c +3 -0
    struct grub_video_mode_info *current_mode;
  };
 
@@ -38,6 +39,9 @@ hook (const struct grub_video_mode_info *info, void *hook_arg)
  {
    struct hook_ctx *ctx = hook_arg;
 
+  if (ctx->set_variable) /* if variable should be set don't print all modes */
+    return 0;
+
    if (ctx->height && ctx->width && (info->width != ctx->width || info->height != ctx->height))
      return 0;
 
@@ -132,31 +136,40 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
    grub_video_adapter_t adapter;

grub-core/commands/videoinfo.c grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), · line 144

Quoted 10 lines
grub-core/commands/videoinfo.c +4 -2
    grub_video_driver_id_t id;
    struct hook_ctx ctx;
-
-  ctx.height = ctx.width = ctx.depth = 0;
+
+  ctx.height = ctx.width = ctx.depth = ctx.set_variable = 0;
+
    if (argc)
      {
+      if (argc == 2 && grub_memcmp(args[0], "--set", sizeof ("--set") - 1) == 0 )

grub_strcmp() is more appropriate here?

grub-core/commands/videoinfo.c grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), · line 152

Quoted 9 lines
grub-core/commands/videoinfo.c +4 -1
+  ctx.set_variable = 1;
+      else
+        {
        const char *ptr;
        ptr = args[0];
        ctx.width = grub_strtoul (ptr, &ptr, 0);
        if (grub_errno)
-	return grub_errno;
+  return grub_errno;

There are white space issues in your patch. Please use GNU coding style.

Quoted 65 lines
grub-core/commands/videoinfo.c +24 -17
        if (*ptr != 'x')
-	return grub_error (GRUB_ERR_BAD_ARGUMENT,
-			   N_("invalid video mode specification `%s'"),
-			   args[0]);
+  return grub_error (GRUB_ERR_BAD_ARGUMENT,
+        N_("invalid video mode specification `%s'"),
+        args[0]);
        ptr++;
        ctx.height = grub_strtoul (ptr, &ptr, 0);
        if (grub_errno)
-	return grub_errno;
+  return grub_errno;
        if (*ptr == 'x')
-	{
-	  ptr++;
-	  ctx.depth = grub_strtoul (ptr, &ptr, 0);
-	  if (grub_errno)
-	    return grub_errno;
-	}
+  {
+    ptr++;
+    ctx.depth = grub_strtoul (ptr, &ptr, 0);
+    if (grub_errno)
+      return grub_errno;
+  }
+        }
+
      }
+
+
 
  #ifdef GRUB_MACHINE_PCBIOS
    if (grub_strcmp (cmd->name, "vbeinfo") == 0)
@@ -164,20 +177,23 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
  #endif
 
    id = grub_video_get_driver_id ();
-
-  grub_puts_ (N_("List of supported video modes:"));
-  grub_puts_ (N_("Legend: mask/position=red/green/blue/reserved"));
-
+  if (!ctx.set_variable)
+    {
+grub_puts_ (N_("List of supported video modes:"));
+grub_puts_ (N_("Legend: mask/position=red/green/blue/reserved"));
+    }
+
    FOR_VIDEO_ADAPTERS (adapter)
    {
      struct grub_video_mode_info info;
      struct grub_video_edid_info edid_info;
-
-    grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
+    if (!ctx.set_variable)
+  grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
 
      if (!adapter->iterate)
        {
-	grub_puts_ (N_("  No info available"));
+        if (!ctx.set_variable)
+    grub_puts_ (N_("  No info available"));
  	continue;
        }
 

grub-core/commands/videoinfo.c grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)), · line 210

Quoted 10 lines
grub-core/commands/videoinfo.c +6 -1
@@ -186,7 +202,18 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
      if (adapter->id == id)
        {
  	if (grub_video_get_info (&info) == GRUB_ERR_NONE)
-	  ctx.current_mode = &info;
+    {
+      ctx.current_mode = &info;
+      if (ctx.set_variable)
+        {
+    /* set grub env var to current mode */
+    char screen_wxh[20];

20 is not sufficient (theoretically) because 32 bit unsigned integer can be as large as 4294967296 (10 digits). You might find grub_xasprintf() useful.

Quoted 15 lines
grub-core/commands/videoinfo.c +6 -2
+    unsigned int width = info.width;
+    unsigned int height = info.height;
+    grub_snprintf (screen_wxh, 20, "%ux%u", width, height);
+    grub_env_set (args[1], screen_wxh);
+        }
+    }
  	else
  	  /* Don't worry about errors.  */
  	  grub_errno = GRUB_ERR_NONE;
@@ -236,19 +263,26 @@ GRUB_MOD_INIT(videoinfo)
  			       /* TRANSLATORS: "x" has to be entered in,
  				  like an identifier, so please don't
  				  use better Unicode codepoints.  */
-			       N_("[WxH[xD]]"),
-			       N_("List available video modes. If "

grub-core/commands/videoinfo.c GRUB_MOD_INIT(videoinfo) · line 273

Quoted 10 lines
grub-core/commands/videoinfo.c +8 -2
-				     "resolution is given show only modes"
-				     " matching it."));
+			       N_("[--set var | [WxH]xD]"),
+			       N_("Retrieve available video modes. "
+             "--set is given, assign the currently"
+             "active resolution to var. If --set "
+             "is not provided the available video "
+             "modes are listed. If resolution is "
+             "given, show only matching modes."));
+

The docs in docs/grub.texi also needs updates.

Quoted 9 lines
grub-core/commands/videoinfo.c +0 -4
  #ifdef GRUB_MACHINE_PCBIOS
    cmd_vbe = grub_register_command ("vbeinfo", grub_cmd_videoinfo,
  				   /* TRANSLATORS: "x" has to be entered in,
  				      like an identifier, so please don't
  				      use better Unicode codepoints.  */
-				   N_("[WxH[xD]]"),
-				   N_("List available video modes. If "
-				      "resolution is given show only modes"
-				      " matching it."));

grub-core/commands/videoinfo.c GRUB_MOD_INIT(videoinfo) · line 288

Quoted 10 lines
grub-core/commands/videoinfo.c +7 -0
+				   N_("[--set var | [WxH]xD]"),
+           N_("Retrieve available video modes. "
+           "--set is given, assign the currently"
+           "active resolution to var. If --set "
+           "is not provided the available video "
+           "modes are listed. If resolution is "
+           "given, show only matching modes."));
  #endif
  }
 

Best Regards,
Zhang Boyang

#8 lore raw
In reply to Markus Scholz

Hi,

Quoted 14 lines · Markus Scholz

Hi Zhang,

now I need to apologize for my very late reply.. sorry!
I saw that you also went ahead as you said with committing the highdpi patches.

Anyways, regarding the high DPI question:
until now we have mostly focused on different screen resolutions in our customer offerings and simply chose the font size based on visual testing. So we did not attempt to solve this "mathematically".

E.g. right now use:
- x_res >= 1024; bootmenu font ubuntu regular 20 (large theme)
- x_res == 1204; bootmenu font ubuntu regular 17 (medium theme)
- x_res < 1024 & unknown ; bootmenu font ubuntu regular 15 (small theme)

Quoted 6 lines

I don’t know if this helpful for you but that’s the current state we are using to keep the text readable given different resolutions. Of course, for the different fonts/themes (small, medium, large) the screens still look different i.e. the user experience is not consistent. Maybe using your highDPI patch it will become much easier to
make the appearance consistent and more appealing across different screen resolutions.

Thanks for explaining your solution. My font scaling patches can't give user consistent experience, because it only accept integer scaling factors.

By the way, Debian CDs use a fixed 800x600 resolution as far as I know, and the user experience is consistent. However, its appearance is blurry and this doesn't work on buggy firmwares which do not allow to switch to 800x600 resolution.

Quoted 3 lines

Note that we exclusively use gfxmode for our application, avoiding text mode. We believe that, for our application, this gives a much more polished and mature look&feel.

Unfortunately my patches only work on gfxterm and there is no support for gfxmenu yet (at least for now).

Nevertheless, I think it's good to have both my patches and your patches, because I think we are focusing on different things.

Best Regards,
Zhang Boyang

Quoted 274 lines

Also thank you for your recommendation for the patch submission.
I will attempt to send another reply to this thread with the help of git patch asap.

Best
Markus

-----Ursprüngliche Nachricht-----
Von: [email protected] <[email protected]> Im Auftrag von Zhang Boyang
Gesendet: Montag, 7. November 2022 08:56
An: Markus Scholz <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; 'Daniel Kiper' <[email protected]>
Betreff: Re: AW: Adding --set to videoinfo to retrieve current video resolution

Hi,

Sorry for late reply... I think my patch is almost independent of Markus's, and it would be good to have both. However, I think there are some point we can share opinions. I'd like to ask your opinions of the mechanism of choosing font size automatically. In my patch (preliminary), it scales Unifont(16x16) M times on a N x 1080p screen, with M = pow(2,ceil(log2(N))), e.g. 2x when (1080p, 2160p], 4x when (2160p, 4320p], 8x when (4320p, 8640p]. This approach seems not good enough, and it might not suitable for custom themes. What's your opinion on this from your perspective? I will probably go back to work on my HiDPI patch after few weeks.

By the way, if I understand correctly, you patch seems reversed, and your mail client seems corrupted your patch. You might find "git format-patch" and "git send-email" useful :)

Best Regards,
Zhang Boyang

Quoted 234 lines · Markus Scholz

Hi all,

* I checked the links by Daniel (thanks for providing).
* As I understand it Zhangs patches aim to add a high dpi scaling feature for the fonts
* In contrast, the patch I submitted (albeit having a similar use-case) adds the possibility for grub "scripts" / config files to access & act upon the currently used display resolution
* for me both things would have their merit and independent use-cases

What is your opinion on having both features?

Besides, I am willing to help progress both features - if someone can guide me /give a hint how to proceed best?

Thank you
Markus

-----Ursprüngliche Nachricht-----
Von: Daniel Kiper <[email protected]>
Gesendet: Donnerstag, 20. Oktober 2022 19:36
An: Markus Scholz <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Betreff: Re: Adding --set to videoinfo to retrieve current video resolution

Adding Paul, Vladimir, and Zhang...

Quoted 6 lines · Markus Scholz

Dear Grub Developers,

recently we faced the problem the author in this old thread faced:
- https://lists.gnu.org/archive/html/grub-devel/2012-10/msg00009.html

Ie. our theme wouldn't display properly due to different screen

resolutions.

Quoted 19 lines

Hence, I wanted to change specifically the font size of our theme given the current resolution.
While the videoinfo module provides info about the current resolution I wasn't able to discover any way to get the info from the booted grub.

Following the aforementioned thread, I therefore patched the videoinfo mod to add the ability of a -set switch just like commands like "smbinfo" or "search" have.

Ie. the documentation of the videoinfo call could change as follows:

Command: videoinfo [--set var | [WxH]xD]

Retrieve available video modes. If --set is given, assign the
currently active resolution to var.
If --set is not provided the available video modes are listed. If resolution is given, show only matching modes.

Quoted 7 lines

Attached is my patch proposal for the module; I probably made a lot mistakes wrt.
coding style and guidelines - please bear with me.

I would be grateful regarding feedback what I could do / how I could improve the patch to make it part of grub? If it possible at all with this

approach?

I think fix for similar problem has been proposed here [1] and I commented it here [2]. Sadly it ended in limbo. Could you work with Zhang on this issue?

Daniel

[1]
https://lists.gnu.org/archive/html/grub-devel/2022-06/msg00143.html
[2]
https://lists.gnu.org/archive/html/grub-devel/2022-07/msg00027.html

Quoted 8 lines

Thank you for your reply & best,
Markus

---

--- grub-mod/grub-core/commands/videoinfo.c 2022-10-12
13:30:54.992451000 +0000
+++ grub/grub-core/commands/videoinfo.c 2022-10-12

13:31:37.715512000 +0000

Quoted 18 lines
(quoted diff) +0 -2
@@ -30,7 +30,6 @@ GRUB_MOD_LICENSE ("GPLv3+");  struct hook_ctx  {
     unsigned height, width, depth;
-  unsigned char set_variable;
     struct grub_video_mode_info *current_mode;  };
 
@@ -39,9 +38,6 @@ hook (const struct grub_video_mode_info  {
     struct hook_ctx *ctx = hook_arg;
 
-  if (ctx->set_variable) /* if variable should be set don't print

all modes */

(quoted diff) +0 -2
-    return 0;
-
     if (ctx->height && ctx->width && (info->width != ctx->width ||

info->height != ctx->height))

       return 0;
(quoted diff) +0 -0
@@ -136,40 +132,31 @@ grub_cmd_videoinfo (grub_command_t cmd _
     grub_video_adapter_t adapter;

Review grub_cmd_videoinfo (grub_command_t cmd _ · line 144

Quoted 10 lines
(quoted diff) +2 -4
     grub_video_driver_id_t id;
     struct hook_ctx ctx;
-
-  ctx.height = ctx.width = ctx.depth = ctx.set_variable = 0;
-
+
+  ctx.height = ctx.width = ctx.depth = 0;
     if (argc)
       {
-      if (argc == 2 && grub_memcmp(args[0], "--set", sizeof ("--set") -

1)

Quoted 119 lines
(quoted diff) +11 -18
 == 0 )
-  ctx.set_variable = 1;
-      else
-        {
         const char *ptr;
         ptr = args[0];
         ctx.width = grub_strtoul (ptr, &ptr, 0);
         if (grub_errno)
-  return grub_errno;
+	return grub_errno;
         if (*ptr != 'x')
-  return grub_error (GRUB_ERR_BAD_ARGUMENT,
-        N_("invalid video mode specification `%s'"),
-        args[0]);
+	return grub_error (GRUB_ERR_BAD_ARGUMENT,
+			   N_("invalid video mode specification `%s'"),
+			   args[0]);
         ptr++;
         ctx.height = grub_strtoul (ptr, &ptr, 0);
         if (grub_errno)
-  return grub_errno;
+	return grub_errno;
         if (*ptr == 'x')
-  {
-    ptr++;
-    ctx.depth = grub_strtoul (ptr, &ptr, 0);
-    if (grub_errno)
-      return grub_errno;
-  }
-        }
-
+	{
+	  ptr++;
+	  ctx.depth = grub_strtoul (ptr, &ptr, 0);
+	  if (grub_errno)
+	    return grub_errno;
+	}
       }
-
-
 
   #ifdef GRUB_MACHINE_PCBIOS
     if (grub_strcmp (cmd->name, "vbeinfo") == 0) @@ -177,23 +164,20

@@ grub_cmd_videoinfo (grub_command_t cmd _ #endif

     id = grub_video_get_driver_id ();
(quoted diff) +0 -3
-  if (!ctx.set_variable)
-    {
-grub_puts_ (N_("List of supported video modes:")); -grub_puts_

(N_("Legend: mask/position=red/green/blue/reserved"));

(quoted diff) +12 -31
-    }
-
+
+  grub_puts_ (N_("List of supported video modes:"));  grub_puts_
+ (N_("Legend: mask/position=red/green/blue/reserved"));
+
     FOR_VIDEO_ADAPTERS (adapter)
     {
       struct grub_video_mode_info info;
       struct grub_video_edid_info edid_info;
-    if (!ctx.set_variable)
-  grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
+
+    grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
 
       if (!adapter->iterate)
         {
-        if (!ctx.set_variable)
-    grub_puts_ (N_("  No info available"));
+	grub_puts_ (N_("  No info available"));
   	continue;
         }
@@ -202,18 +186,7 @@ grub_puts_ (N_("Legend: mask/position=re
       if (adapter->id == id)
         {
   	if (grub_video_get_info (&info) == GRUB_ERR_NONE)
-    {
-      ctx.current_mode = &info;
-      if (ctx.set_variable)
-        {
-    /* set grub env var to current mode */
-    char screen_wxh[20];
-    unsigned int width = info.width;
-    unsigned int height = info.height;
-    grub_snprintf (screen_wxh, 20, "%ux%u", width, height);
-    grub_env_set (args[1], screen_wxh);
-        }
-    }
+	  ctx.current_mode = &info;
   	else
   	  /* Don't worry about errors.  */
   	  grub_errno = GRUB_ERR_NONE;
@@ -263,26 +236,19 @@ GRUB_MOD_INIT(videoinfo)
   			       /* TRANSLATORS: "x" has to be entered in,
   				  like an identifier, so please don't
   				  use better Unicode codepoints.  */
-			       N_("[--set var | [WxH]xD]"),
-			       N_("Retrieve available video modes. "
-             "--set is given, assign the currently"
-             "active resolution to var. If --set "
-             "is not provided the available video "
-             "modes are listed. If resolution is "
-             "given, show only matching modes."));
-
+			       N_("[WxH[xD]]"),
+			       N_("List available video modes. If "
+				     "resolution is given show only modes"
+				     " matching it."));
   #ifdef GRUB_MACHINE_PCBIOS
     cmd_vbe = grub_register_command ("vbeinfo", grub_cmd_videoinfo,
   				   /* TRANSLATORS: "x" has to be entered in,
   				      like an identifier, so please don't
   				      use better Unicode codepoints.  */
-				   N_("[--set var | [WxH]xD]"),
-           N_("Retrieve available video modes. "
-           "--set is given, assign the currently"
-           "active resolution to var. If --set "
-           "is not provided the available video "
Quoted 9 lines

Review GRUB_MOD_INIT(videoinfo) · line 253

Quoted 8 lines
(quoted diff) +4 -2
-           "modes are listed. If resolution is "
-           "given, show only matching modes."));
+				   N_("[WxH[xD]]"),
+				   N_("List available video modes. If "
+				      "resolution is given show only modes"
+				      " matching it."));
   #endif
   }

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#9 lore raw

Hi,

thank you again for your reply and explanation. Despite the different focus, I am still looking forward to try out your additions.

Regarding my videoinfo patch I submitted them using git to the mailing list. What is the best way forward here?

Since its just a single file and no deep changes maybe the effort is no too much... Would you be so kind/able to review them or should I reach out to Daniel for this?
Since I am new to the grub process I am not sure how to get the changes in.

Thank you and best
Markus

Zhang Boyang <[email protected]> schrieb am Sa., 10. Dez. 2022, 12:32:

Quoted 348 lines

Hi,

Quoted 4 lines · Markus Scholz

Hi Zhang,

now I need to apologize for my very late reply.. sorry!
I saw that you also went ahead as you said with committing the highdpi

patches.

Quoted 3 lines

Anyways, regarding the high DPI question:
until now we have mostly focused on different screen resolutions in our

customer offerings and simply chose the font

Quoted 1 line

size based on visual testing. So we did not attempt to solve this

"mathematically".

Quoted 7 lines

E.g. right now use:
- x_res >= 1024; bootmenu font ubuntu regular 20 (large theme)
- x_res == 1204; bootmenu font ubuntu regular 17 (medium theme)
- x_res < 1024 & unknown ; bootmenu font ubuntu regular 15 (small theme)

I don’t know if this helpful for you but that’s the current state we are

using to keep

Quoted 1 line

the text readable given different resolutions. Of course, for the

different fonts/themes

Quoted 1 line

(small, medium, large) the screens still look different i.e. the user

experience is not consistent.

Quoted 2 lines

Maybe using your highDPI patch it will become much easier to make the appearance consistent and more appealing across different

screen resolutions.

Quoted 1 line

Thanks for explaining your solution. My font scaling patches can't give user consistent experience, because it only accept integer scaling factors.

By the way, Debian CDs use a fixed 800x600 resolution as far as I know, and the user experience is consistent. However, its appearance is blurry and this doesn't work on buggy firmwares which do not allow to switch to 800x600 resolution.

Quoted 1 line

Note that we exclusively use gfxmode for our application, avoiding text

mode.

Quoted 1 line

We believe that, for our application, this gives a much more polished

and mature look&feel.

Quoted 1 line

Unfortunately my patches only work on gfxterm and there is no support for gfxmenu yet (at least for now).

Nevertheless, I think it's good to have both my patches and your patches, because I think we are focusing on different things.

Best Regards,
Zhang Boyang

Quoted 2 lines

Also thank you for your recommendation for the patch submission. I will attempt to send another reply to this thread with the help of git

patch asap.

Quoted 7 lines

Best
Markus

-----Ursprüngliche Nachricht-----
Von: [email protected]

<[email protected]> Im Auftrag von Zhang Boyang

Quoted 3 lines

Gesendet: Montag, 7. November 2022 08:56
An: Markus Scholz <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; 'Daniel Kiper' <

[email protected]>

Quoted 1 line

Betreff: Re: AW: Adding --set to videoinfo to retrieve current video

resolution

Quoted 4 lines

Hi,

Sorry for late reply... I think my patch is almost independent of

Markus's, and it would be good to have both. However, I think there are some point we can share opinions. I'd like to ask your opinions of the mechanism of choosing font size automatically. In my patch (preliminary), it scales Unifont(16x16) M times on a N x 1080p screen, with M = pow(2,ceil(log2(N))), e.g. 2x when (1080p, 2160p], 4x when (2160p, 4320p], 8x when (4320p, 8640p]. This approach seems not good enough, and it might not suitable for custom themes. What's your opinion on this from your perspective? I will probably go back to work on my HiDPI patch after few weeks.

Quoted 2 lines

By the way, if I understand correctly, you patch seems reversed, and

your mail client seems corrupted your patch. You might find "git format-patch" and "git send-email" useful :)

Quoted 108 lines

Best Regards,
Zhang Boyang

Quoted 102 lines · Markus Scholz

Hi all,

* I checked the links by Daniel (thanks for providing).
* As I understand it Zhangs patches aim to add a high dpi scaling feature for the fonts
* In contrast, the patch I submitted (albeit having a similar use-case) adds the possibility for grub "scripts" / config files to access & act upon the currently used display resolution
* for me both things would have their merit and independent use-cases

What is your opinion on having both features?

Besides, I am willing to help progress both features - if someone can guide me /give a hint how to proceed best?

Thank you
Markus

-----Ursprüngliche Nachricht-----
Von: Daniel Kiper <[email protected]>
Gesendet: Donnerstag, 20. Oktober 2022 19:36
An: Markus Scholz <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Betreff: Re: Adding --set to videoinfo to retrieve current video resolution

Adding Paul, Vladimir, and Zhang...

Quoted 6 lines · Markus Scholz

Dear Grub Developers,

recently we faced the problem the author in this old thread faced:
- https://lists.gnu.org/archive/html/grub-devel/2012-10/msg00009.html

Ie. our theme wouldn't display properly due to different screen

resolutions.

Quoted 19 lines

Hence, I wanted to change specifically the font size of our theme given the current resolution.
While the videoinfo module provides info about the current resolution I wasn't able to discover any way to get the info from the booted grub.

Following the aforementioned thread, I therefore patched the videoinfo mod to add the ability of a -set switch just like commands like "smbinfo" or "search" have.

Ie. the documentation of the videoinfo call could change as follows:

Command: videoinfo [--set var | [WxH]xD]

Retrieve available video modes. If --set is given, assign the
currently active resolution to var.
If --set is not provided the available video modes are listed. If resolution is given, show only matching modes.

Quoted 7 lines

Attached is my patch proposal for the module; I probably made a lot mistakes wrt.
coding style and guidelines - please bear with me.

I would be grateful regarding feedback what I could do / how I could improve the patch to make it part of grub? If it possible at all with this

approach?

I think fix for similar problem has been proposed here [1] and I commented it here [2]. Sadly it ended in limbo. Could you work with Zhang on this issue?

Daniel

[1]
https://lists.gnu.org/archive/html/grub-devel/2022-06/msg00143.html
[2]
https://lists.gnu.org/archive/html/grub-devel/2022-07/msg00027.html

Quoted 8 lines

Thank you for your reply & best,
Markus

---

--- grub-mod/grub-core/commands/videoinfo.c 2022-10-12 13:30:54.992451000 +0000
+++ grub/grub-core/commands/videoinfo.c 2022-10-12

13:31:37.715512000 +0000

Quoted 16 lines
(quoted diff) +0 -2
@@ -30,7 +30,6 @@ GRUB_MOD_LICENSE ("GPLv3+");  struct hook_ctx  {
     unsigned height, width, depth;
-  unsigned char set_variable;
     struct grub_video_mode_info *current_mode;  };
 
@@ -39,9 +38,6 @@ hook (const struct grub_video_mode_info  {
     struct hook_ctx *ctx = hook_arg;
 
-  if (ctx->set_variable) /* if variable should be set don't print

all modes */

(quoted diff) +0 -2
-    return 0;
-
     if (ctx->height && ctx->width && (info->width != ctx->width ||

info->height != ctx->height))

       return 0;
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -136,40 +132,31 @@ grub_cmd_videoinfo (grub_command_t cmd _
     grub_video_adapter_t adapter;
     grub_video_driver_id_t id;
     struct hook_ctx ctx;
Quoted 8 lines

Review grub_cmd_videoinfo (grub_command_t cmd _ · line 144

Quoted 8 lines
(quoted diff) +2 -4
-
-  ctx.height = ctx.width = ctx.depth = ctx.set_variable = 0;
-
+
+  ctx.height = ctx.width = ctx.depth = 0;
     if (argc)
       {
-      if (argc == 2 && grub_memcmp(args[0], "--set", sizeof ("--set")

-

Quoted 105 lines
Quoted 105 lines

1)

Quoted 104 lines
(quoted diff) +11 -18
 == 0 )
-  ctx.set_variable = 1;
-      else
-        {
         const char *ptr;
         ptr = args[0];
         ctx.width = grub_strtoul (ptr, &ptr, 0);
         if (grub_errno)
-  return grub_errno;
+   return grub_errno;
         if (*ptr != 'x')
-  return grub_error (GRUB_ERR_BAD_ARGUMENT,
-        N_("invalid video mode specification `%s'"),
-        args[0]);
+   return grub_error (GRUB_ERR_BAD_ARGUMENT,
+                      N_("invalid video mode specification `%s'"),
+                      args[0]);
         ptr++;
         ctx.height = grub_strtoul (ptr, &ptr, 0);
         if (grub_errno)
-  return grub_errno;
+   return grub_errno;
         if (*ptr == 'x')
-  {
-    ptr++;
-    ctx.depth = grub_strtoul (ptr, &ptr, 0);
-    if (grub_errno)
-      return grub_errno;
-  }
-        }
-
+   {
+     ptr++;
+     ctx.depth = grub_strtoul (ptr, &ptr, 0);
+     if (grub_errno)
+       return grub_errno;
+   }
       }
-
-
 
   #ifdef GRUB_MACHINE_PCBIOS
     if (grub_strcmp (cmd->name, "vbeinfo") == 0) @@ -177,23 +164,20

@@ grub_cmd_videoinfo (grub_command_t cmd _ #endif

     id = grub_video_get_driver_id ();
(quoted diff) +0 -3
-  if (!ctx.set_variable)
-    {
-grub_puts_ (N_("List of supported video modes:")); -grub_puts_

(N_("Legend: mask/position=red/green/blue/reserved"));

(quoted diff) +8 -25
-    }
-
+
+  grub_puts_ (N_("List of supported video modes:"));  grub_puts_
+ (N_("Legend: mask/position=red/green/blue/reserved"));
+
     FOR_VIDEO_ADAPTERS (adapter)
     {
       struct grub_video_mode_info info;
       struct grub_video_edid_info edid_info;
-    if (!ctx.set_variable)
-  grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
+
+    grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
 
       if (!adapter->iterate)
         {
-        if (!ctx.set_variable)
-    grub_puts_ (N_("  No info available"));
+   grub_puts_ (N_("  No info available"));
    continue;
         }
@@ -202,18 +186,7 @@ grub_puts_ (N_("Legend: mask/position=re
       if (adapter->id == id)
         {
    if (grub_video_get_info (&info) == GRUB_ERR_NONE)
-    {
-      ctx.current_mode = &info;
-      if (ctx.set_variable)
-        {
-    /* set grub env var to current mode */
-    char screen_wxh[20];
-    unsigned int width = info.width;
-    unsigned int height = info.height;
-    grub_snprintf (screen_wxh, 20, "%ux%u", width, height);
-    grub_env_set (args[1], screen_wxh);
-        }
-    }
+     ctx.current_mode = &info;
    else
      /* Don't worry about errors.  */
      grub_errno = GRUB_ERR_NONE;
@@ -263,26 +236,19 @@ GRUB_MOD_INIT(videoinfo)
                           /* TRANSLATORS: "x" has to be entered in,
                              like an identifier, so please don't
                              use better Unicode codepoints.  */
-                          N_("[--set var | [WxH]xD]"),
-                          N_("Retrieve available video modes. "
-             "--set is given, assign the currently"
-             "active resolution to var. If --set "
-             "is not provided the available video "
-             "modes are listed. If resolution is "
-             "given, show only matching modes."));
Quoted 8 lines
Quoted 8 lines

Review GRUB_MOD_INIT(videoinfo) · line 245

Quoted 8 lines
(quoted diff) +4 -1
-
+                          N_("[WxH[xD]]"),
+                          N_("List available video modes. If "
+                                "resolution is given show only modes"
+                                " matching it."));
   #ifdef GRUB_MACHINE_PCBIOS
     cmd_vbe = grub_register_command ("vbeinfo", grub_cmd_videoinfo,
                               /* TRANSLATORS: "x" has to be entered

in,

Quoted 22 lines
Quoted 7 lines
Quoted 7 lines
(quoted diff) +0 -5
                                  like an identifier, so please don't
                                  use better Unicode codepoints.  */
-                              N_("[--set var | [WxH]xD]"),
-           N_("Retrieve available video modes. "
-           "--set is given, assign the currently"
-           "active resolution to var. If --set "
-           "is not provided the available video "
Quoted 9 lines

Review GRUB_MOD_INIT(videoinfo) · line 253

Quoted 8 lines
(quoted diff) +4 -2
-           "modes are listed. If resolution is "
-           "given, show only matching modes."));
+                              N_("[WxH[xD]]"),
+                              N_("List available video modes. If "
+                                 "resolution is given show only modes"
+                                 " matching it."));
   #endif
   }

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#10 lore raw

Hi,

Quoted 8 lines · Markus Scholz

Hi,

thank you again for your reply and explanation. Despite the different focus, I am still looking forward to try out your additions.

Regarding my videoinfo patch I submitted them using git to the mailing list. What is the best way forward here?

Maybe the only thing what can do now is wait... If you think the maintainers forget you patches, you can resend them like [PATCH RESEND 1/1] after few days/weeks.

Quoted 3 lines

Since its just a single file and no deep changes maybe the effort is no too much... Would you be so kind/able to review them or should I reach out to Daniel for this?

I'm not a maintainer of GRUB, so I'm not sure whether I have rights to send Reviewed-By tags. Although I think I can give some advice for these patches.

I think you can reach out to Daniel if you think these patches are forgotten.

Quoted 1 line

Since I am new to the grub process I am not sure how to get the changes in.

I'm also new to GRUB (and other open source projects).... So please forgive me if I said something misleading.

Best Regards,
Zhang Boyang

Quoted 357 lines

Thank you and best
Markus

Zhang Boyang <[email protected]> schrieb am Sa., 10. Dez. 2022, 12:32:

Quoted 348 lines

Hi,

Quoted 4 lines · Markus Scholz

Hi Zhang,

now I need to apologize for my very late reply.. sorry!
I saw that you also went ahead as you said with committing the highdpi

patches.

Quoted 3 lines

Anyways, regarding the high DPI question:
until now we have mostly focused on different screen resolutions in our

customer offerings and simply chose the font

Quoted 1 line

size based on visual testing. So we did not attempt to solve this

"mathematically".

Quoted 7 lines

E.g. right now use:
- x_res >= 1024; bootmenu font ubuntu regular 20 (large theme)
- x_res == 1204; bootmenu font ubuntu regular 17 (medium theme)
- x_res < 1024 & unknown ; bootmenu font ubuntu regular 15 (small theme)

I don’t know if this helpful for you but that’s the current state we are

using to keep

Quoted 1 line

the text readable given different resolutions. Of course, for the

different fonts/themes

Quoted 1 line

(small, medium, large) the screens still look different i.e. the user

experience is not consistent.

Quoted 2 lines

Maybe using your highDPI patch it will become much easier to make the appearance consistent and more appealing across different

screen resolutions.

Quoted 1 line

Thanks for explaining your solution. My font scaling patches can't give user consistent experience, because it only accept integer scaling factors.

By the way, Debian CDs use a fixed 800x600 resolution as far as I know, and the user experience is consistent. However, its appearance is blurry and this doesn't work on buggy firmwares which do not allow to switch to 800x600 resolution.

Quoted 1 line

Note that we exclusively use gfxmode for our application, avoiding text

mode.

Quoted 1 line

We believe that, for our application, this gives a much more polished

and mature look&feel.

Quoted 1 line

Unfortunately my patches only work on gfxterm and there is no support for gfxmenu yet (at least for now).

Nevertheless, I think it's good to have both my patches and your patches, because I think we are focusing on different things.

Best Regards,
Zhang Boyang

Quoted 2 lines

Also thank you for your recommendation for the patch submission. I will attempt to send another reply to this thread with the help of git

patch asap.

Quoted 7 lines

Best
Markus

-----Ursprüngliche Nachricht-----
Von: [email protected]

<[email protected]> Im Auftrag von Zhang Boyang

Quoted 3 lines

Gesendet: Montag, 7. November 2022 08:56
An: Markus Scholz <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; 'Daniel Kiper' <

[email protected]>

Quoted 1 line

Betreff: Re: AW: Adding --set to videoinfo to retrieve current video

resolution

Quoted 4 lines

Hi,

Sorry for late reply... I think my patch is almost independent of

Markus's, and it would be good to have both. However, I think there are some point we can share opinions. I'd like to ask your opinions of the mechanism of choosing font size automatically. In my patch (preliminary), it scales Unifont(16x16) M times on a N x 1080p screen, with M = pow(2,ceil(log2(N))), e.g. 2x when (1080p, 2160p], 4x when (2160p, 4320p], 8x when (4320p, 8640p]. This approach seems not good enough, and it might not suitable for custom themes. What's your opinion on this from your perspective? I will probably go back to work on my HiDPI patch after few weeks.

Quoted 2 lines

By the way, if I understand correctly, you patch seems reversed, and

your mail client seems corrupted your patch. You might find "git format-patch" and "git send-email" useful :)

Quoted 108 lines

Best Regards,
Zhang Boyang

Quoted 102 lines · Markus Scholz

Hi all,

* I checked the links by Daniel (thanks for providing).
* As I understand it Zhangs patches aim to add a high dpi scaling feature for the fonts
* In contrast, the patch I submitted (albeit having a similar use-case) adds the possibility for grub "scripts" / config files to access & act upon the currently used display resolution
* for me both things would have their merit and independent use-cases

What is your opinion on having both features?

Besides, I am willing to help progress both features - if someone can guide me /give a hint how to proceed best?

Thank you
Markus

-----Ursprüngliche Nachricht-----
Von: Daniel Kiper <[email protected]>
Gesendet: Donnerstag, 20. Oktober 2022 19:36
An: Markus Scholz <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Betreff: Re: Adding --set to videoinfo to retrieve current video resolution

Adding Paul, Vladimir, and Zhang...

Quoted 6 lines · Markus Scholz

Dear Grub Developers,

recently we faced the problem the author in this old thread faced:
- https://lists.gnu.org/archive/html/grub-devel/2012-10/msg00009.html

Ie. our theme wouldn't display properly due to different screen

resolutions.

Quoted 19 lines

Hence, I wanted to change specifically the font size of our theme given the current resolution.
While the videoinfo module provides info about the current resolution I wasn't able to discover any way to get the info from the booted grub.

Following the aforementioned thread, I therefore patched the videoinfo mod to add the ability of a -set switch just like commands like "smbinfo" or "search" have.

Ie. the documentation of the videoinfo call could change as follows:

Command: videoinfo [--set var | [WxH]xD]

Retrieve available video modes. If --set is given, assign the
currently active resolution to var.
If --set is not provided the available video modes are listed. If resolution is given, show only matching modes.

Quoted 7 lines

Attached is my patch proposal for the module; I probably made a lot mistakes wrt.
coding style and guidelines - please bear with me.

I would be grateful regarding feedback what I could do / how I could improve the patch to make it part of grub? If it possible at all with this

approach?

I think fix for similar problem has been proposed here [1] and I commented it here [2]. Sadly it ended in limbo. Could you work with Zhang on this issue?

Daniel

[1]
https://lists.gnu.org/archive/html/grub-devel/2022-06/msg00143.html
[2]
https://lists.gnu.org/archive/html/grub-devel/2022-07/msg00027.html

Quoted 8 lines

Thank you for your reply & best,
Markus

---

--- grub-mod/grub-core/commands/videoinfo.c 2022-10-12 13:30:54.992451000 +0000
+++ grub/grub-core/commands/videoinfo.c 2022-10-12

13:31:37.715512000 +0000

Quoted 16 lines
(quoted diff) +0 -2
@@ -30,7 +30,6 @@ GRUB_MOD_LICENSE ("GPLv3+");  struct hook_ctx  {
      unsigned height, width, depth;
-  unsigned char set_variable;
      struct grub_video_mode_info *current_mode;  };
 
@@ -39,9 +38,6 @@ hook (const struct grub_video_mode_info  {
      struct hook_ctx *ctx = hook_arg;
 
-  if (ctx->set_variable) /* if variable should be set don't print

all modes */

(quoted diff) +0 -2
-    return 0;
-
      if (ctx->height && ctx->width && (info->width != ctx->width ||

info->height != ctx->height))

        return 0;
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -136,40 +132,31 @@ grub_cmd_videoinfo (grub_command_t cmd _
      grub_video_adapter_t adapter;
      grub_video_driver_id_t id;
      struct hook_ctx ctx;
Quoted 8 lines

Review grub_cmd_videoinfo (grub_command_t cmd _ · line 144

Quoted 8 lines
(quoted diff) +2 -4
-
-  ctx.height = ctx.width = ctx.depth = ctx.set_variable = 0;
-
+
+  ctx.height = ctx.width = ctx.depth = 0;
      if (argc)
        {
-      if (argc == 2 && grub_memcmp(args[0], "--set", sizeof ("--set")

-

Quoted 105 lines
Quoted 105 lines

1)

Quoted 104 lines
(quoted diff) +11 -18
 == 0 )
-  ctx.set_variable = 1;
-      else
-        {
          const char *ptr;
          ptr = args[0];
          ctx.width = grub_strtoul (ptr, &ptr, 0);
          if (grub_errno)
-  return grub_errno;
+   return grub_errno;
          if (*ptr != 'x')
-  return grub_error (GRUB_ERR_BAD_ARGUMENT,
-        N_("invalid video mode specification `%s'"),
-        args[0]);
+   return grub_error (GRUB_ERR_BAD_ARGUMENT,
+                      N_("invalid video mode specification `%s'"),
+                      args[0]);
          ptr++;
          ctx.height = grub_strtoul (ptr, &ptr, 0);
          if (grub_errno)
-  return grub_errno;
+   return grub_errno;
          if (*ptr == 'x')
-  {
-    ptr++;
-    ctx.depth = grub_strtoul (ptr, &ptr, 0);
-    if (grub_errno)
-      return grub_errno;
-  }
-        }
-
+   {
+     ptr++;
+     ctx.depth = grub_strtoul (ptr, &ptr, 0);
+     if (grub_errno)
+       return grub_errno;
+   }
        }
-
-
 
    #ifdef GRUB_MACHINE_PCBIOS
      if (grub_strcmp (cmd->name, "vbeinfo") == 0) @@ -177,23 +164,20

@@ grub_cmd_videoinfo (grub_command_t cmd _ #endif

      id = grub_video_get_driver_id ();
(quoted diff) +0 -3
-  if (!ctx.set_variable)
-    {
-grub_puts_ (N_("List of supported video modes:")); -grub_puts_

(N_("Legend: mask/position=red/green/blue/reserved"));

(quoted diff) +8 -25
-    }
-
+
+  grub_puts_ (N_("List of supported video modes:"));  grub_puts_
+ (N_("Legend: mask/position=red/green/blue/reserved"));
+
      FOR_VIDEO_ADAPTERS (adapter)
      {
        struct grub_video_mode_info info;
        struct grub_video_edid_info edid_info;
-    if (!ctx.set_variable)
-  grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
+
+    grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
 
        if (!adapter->iterate)
          {
-        if (!ctx.set_variable)
-    grub_puts_ (N_("  No info available"));
+   grub_puts_ (N_("  No info available"));
     continue;
          }
@@ -202,18 +186,7 @@ grub_puts_ (N_("Legend: mask/position=re
        if (adapter->id == id)
          {
     if (grub_video_get_info (&info) == GRUB_ERR_NONE)
-    {
-      ctx.current_mode = &info;
-      if (ctx.set_variable)
-        {
-    /* set grub env var to current mode */
-    char screen_wxh[20];
-    unsigned int width = info.width;
-    unsigned int height = info.height;
-    grub_snprintf (screen_wxh, 20, "%ux%u", width, height);
-    grub_env_set (args[1], screen_wxh);
-        }
-    }
+     ctx.current_mode = &info;
     else
       /* Don't worry about errors.  */
       grub_errno = GRUB_ERR_NONE;
@@ -263,26 +236,19 @@ GRUB_MOD_INIT(videoinfo)
                            /* TRANSLATORS: "x" has to be entered in,
                               like an identifier, so please don't
                               use better Unicode codepoints.  */
-                          N_("[--set var | [WxH]xD]"),
-                          N_("Retrieve available video modes. "
-             "--set is given, assign the currently"
-             "active resolution to var. If --set "
-             "is not provided the available video "
-             "modes are listed. If resolution is "
-             "given, show only matching modes."));
Quoted 8 lines
Quoted 8 lines

Review GRUB_MOD_INIT(videoinfo) · line 245

Quoted 8 lines
(quoted diff) +4 -1
-
+                          N_("[WxH[xD]]"),
+                          N_("List available video modes. If "
+                                "resolution is given show only modes"
+                                " matching it."));
    #ifdef GRUB_MACHINE_PCBIOS
      cmd_vbe = grub_register_command ("vbeinfo", grub_cmd_videoinfo,
                                /* TRANSLATORS: "x" has to be entered

in,

Quoted 22 lines
Quoted 7 lines
Quoted 7 lines
(quoted diff) +0 -5
                                   like an identifier, so please don't
                                   use better Unicode codepoints.  */
-                              N_("[--set var | [WxH]xD]"),
-           N_("Retrieve available video modes. "
-           "--set is given, assign the currently"
-           "active resolution to var. If --set "
-           "is not provided the available video "
Quoted 9 lines

Review GRUB_MOD_INIT(videoinfo) · line 253

Quoted 8 lines
(quoted diff) +4 -2
-           "modes are listed. If resolution is "
-           "given, show only matching modes."));
+                              N_("[WxH[xD]]"),
+                              N_("List available video modes. If "
+                                 "resolution is given show only modes"
+                                 " matching it."));
    #endif
    }

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#11 lore raw
Quoted 16 lines · Zhang Boyang

Hi,

Quoted 8 lines · Markus Scholz

Hi,

thank you again for your reply and explanation. Despite the different focus, I am still looking forward to try out your additions.

Regarding my videoinfo patch I submitted them using git to the mailing list. What is the best way forward here?

Maybe the only thing what can do now is wait... If you think the maintainers forget you patches, you can resend them like [PATCH RESEND 1/1] after few days/weeks.

Quoted 6 lines
Quoted 3 lines

Since its just a single file and no deep changes maybe the effort is no too much... Would you be so kind/able to review them or should I reach out to Daniel for this?

I'm not a maintainer of GRUB, so I'm not sure whether I have rights to send Reviewed-By tags. Although I think I can give some advice for these patches.

I am OK with everybody giving RB if them reviewed patches and they seem OK with the code. Though I reserve right to add some more comments and final decision to include or not the patch in the upstream.

Quoted 2 lines

I think you can reach out to Daniel if you think these patches are forgotten.

I try to follow this (and other) threads but I count on you to work out final solution. If I see anything which does not work for me I will jump in and comment. When the patch set is ready for my review drop me a line and I will take a look at it.

Quoted 4 lines
Quoted 1 line

Since I am new to the grub process I am not sure how to get the changes in.

I'm also new to GRUB (and other open source projects).... So please forgive me if I said something misleading.

You are doing good guys. Thank you!

Daniel

#12 lore raw
In reply to Zhang Boyang

Dear Zhang,

thank you a lot for your advice and review!
I will address the pointed out improvements and then ask Daniel (as he suggested) to take a look.

Thanks again & best
Markus

-----Ursprüngliche Nachricht-----
Von: Zhang Boyang <[email protected]>
Gesendet: Dienstag, 13. Dezember 2022 12:07
An: Markus Scholz <[email protected]>
Cc: The development of GNU GRUB <[email protected]>
Betreff: Re: AW: AW: Adding --set to videoinfo to retrieve current video resolution

Hi,

Quoted 8 lines · Markus Scholz

Hi,

thank you again for your reply and explanation. Despite the different focus, I am still looking forward to try out your additions.

Regarding my videoinfo patch I submitted them using git to the mailing list. What is the best way forward here?

Maybe the only thing what can do now is wait... If you think the maintainers forget you patches, you can resend them like [PATCH RESEND 1/1] after few days/weeks.

Quoted 3 lines

Since its just a single file and no deep changes maybe the effort is no too much... Would you be so kind/able to review them or should I reach out to Daniel for this?

I'm not a maintainer of GRUB, so I'm not sure whether I have rights to send Reviewed-By tags. Although I think I can give some advice for these patches.

I think you can reach out to Daniel if you think these patches are forgotten.

Quoted 1 line

Since I am new to the grub process I am not sure how to get the changes in.

I'm also new to GRUB (and other open source projects).... So please forgive me if I said something misleading.

Best Regards,
Zhang Boyang

Quoted 371 lines

Thank you and best
Markus

Zhang Boyang <[email protected]> schrieb am Sa., 10. Dez. 2022, 12:32:

Quoted 362 lines

Hi,

Quoted 5 lines · Markus Scholz

Hi Zhang,

now I need to apologize for my very late reply.. sorry! I saw that you also went ahead as you said with committing the highdpi

patches.

Quoted 4 lines

Anyways, regarding the high DPI question:
until now we have mostly focused on different screen resolutions in our

customer offerings and simply chose the font

Quoted 1 line

size based on visual testing. So we did not attempt to solve this

"mathematically".

Quoted 9 lines

E.g. right now use:
- x_res >= 1024; bootmenu font ubuntu regular 20 (large theme)
- x_res == 1204; bootmenu font ubuntu regular 17 (medium theme)
- x_res < 1024 & unknown ; bootmenu font ubuntu regular 15 (small theme)

I don’t know if this helpful for you but that’s the current state we are

using to keep

Quoted 1 line

the text readable given different resolutions. Of course, for the

different fonts/themes

Quoted 2 lines

(small, medium, large) the screens still look different i.e. the user

experience is not consistent.

Quoted 2 lines

Maybe using your highDPI patch it will become much easier to make the appearance consistent and more appealing across different

screen resolutions.

Quoted 1 line

Thanks for explaining your solution. My font scaling patches can't give user consistent experience, because it only accept integer scaling factors.

By the way, Debian CDs use a fixed 800x600 resolution as far as I know, and the user experience is consistent. However, its appearance is blurry and this doesn't work on buggy firmwares which do not allow to switch to
800x600 resolution.

Quoted 2 lines

Note that we exclusively use gfxmode for our application, avoiding text

mode.

Quoted 2 lines

We believe that, for our application, this gives a much more polished

and mature look&feel.

Quoted 1 line

Unfortunately my patches only work on gfxterm and there is no support for gfxmenu yet (at least for now).

Nevertheless, I think it's good to have both my patches and your patches, because I think we are focusing on different things.

Best Regards,
Zhang Boyang

Quoted 3 lines

Also thank you for your recommendation for the patch submission. I will attempt to send another reply to this thread with the help of git

patch asap.

Quoted 7 lines

Best
Markus

-----Ursprüngliche Nachricht-----
Von: [email protected]

<[email protected]> Im Auftrag von Zhang Boyang

Quoted 3 lines

Gesendet: Montag, 7. November 2022 08:56
An: Markus Scholz <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; 'Daniel Kiper' <

[email protected]>

Quoted 1 line

Betreff: Re: AW: Adding --set to videoinfo to retrieve current video

resolution

Quoted 4 lines

Hi,

Sorry for late reply... I think my patch is almost independent of

Markus's, and it would be good to have both. However, I think there are some point we can share opinions. I'd like to ask your opinions of the mechanism of choosing font size automatically. In my patch (preliminary), it scales Unifont(16x16) M times on a N x 1080p screen, with M = pow(2,ceil(log2(N))), e.g. 2x when (1080p, 2160p], 4x when (2160p, 4320p], 8x when (4320p, 8640p]. This approach seems not good enough, and it might not suitable for custom themes. What's your opinion on this from your perspective? I will probably go back to work on my HiDPI patch after few weeks.

Quoted 2 lines

By the way, if I understand correctly, you patch seems reversed, and

your mail client seems corrupted your patch. You might find "git format-patch" and "git send-email" useful :)

Quoted 112 lines

Best Regards,
Zhang Boyang

Quoted 106 lines · Markus Scholz

Hi all,

* I checked the links by Daniel (thanks for providing).
* As I understand it Zhangs patches aim to add a high dpi scaling feature for the fonts
* In contrast, the patch I submitted (albeit having a similar use-case) adds the possibility for grub "scripts" / config files to access & act upon the currently used display resolution
* for me both things would have their merit and independent use-cases

What is your opinion on having both features?

Besides, I am willing to help progress both features - if someone can guide me /give a hint how to proceed best?

Thank you
Markus

-----Ursprüngliche Nachricht-----
Von: Daniel Kiper <[email protected]>
Gesendet: Donnerstag, 20. Oktober 2022 19:36
An: Markus Scholz <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Betreff: Re: Adding --set to videoinfo to retrieve current video resolution

Adding Paul, Vladimir, and Zhang...

Quoted 8 lines · Markus Scholz

Dear Grub Developers,

recently we faced the problem the author in this old thread faced:
-
https://lists.gnu.org/archive/html/grub-devel/2012-10/msg00009.htm
l

Ie. our theme wouldn't display properly due to different screen

resolutions.

Quoted 19 lines

Hence, I wanted to change specifically the font size of our theme given the current resolution.
While the videoinfo module provides info about the current resolution I wasn't able to discover any way to get the info from the booted grub.

Following the aforementioned thread, I therefore patched the videoinfo mod to add the ability of a -set switch just like commands like "smbinfo" or "search" have.

Ie. the documentation of the videoinfo call could change as follows:

Command: videoinfo [--set var | [WxH]xD]

Retrieve available video modes. If --set is given, assign
the currently active resolution to var.
If --set is not provided the available video modes are listed. If resolution is given, show only matching modes.

Quoted 7 lines

Attached is my patch proposal for the module; I probably made a lot mistakes wrt.
coding style and guidelines - please bear with me.

I would be grateful regarding feedback what I could do / how I could improve the patch to make it part of grub? If it possible at all with this

approach?

I think fix for similar problem has been proposed here [1] and I commented it here [2]. Sadly it ended in limbo. Could you work with Zhang on this issue?

Daniel

[1]
https://lists.gnu.org/archive/html/grub-devel/2022-06/msg00143.html
[2]
https://lists.gnu.org/archive/html/grub-devel/2022-07/msg00027.html

Quoted 8 lines

Thank you for your reply & best,
Markus

---

--- grub-mod/grub-core/commands/videoinfo.c 2022-10-12 13:30:54.992451000 +0000
+++ grub/grub-core/commands/videoinfo.c 2022-10-12

13:31:37.715512000 +0000

Quoted 17 lines
(quoted diff) +0 -2
@@ -30,7 +30,6 @@ GRUB_MOD_LICENSE ("GPLv3+");  struct hook_ctx  {
      unsigned height, width, depth;
-  unsigned char set_variable;
      struct grub_video_mode_info *current_mode;  };
 
@@ -39,9 +38,6 @@ hook (const struct grub_video_mode_info  {
      struct hook_ctx *ctx = hook_arg;
 
-  if (ctx->set_variable) /* if variable should be set don't print 

all modes */

(quoted diff) +0 -2
-    return 0;
-
      if (ctx->height && ctx->width && (info->width != ctx->width 

||
info->height != ctx->height))

        return 0;
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -136,40 +132,31 @@ grub_cmd_videoinfo (grub_command_t cmd _
      grub_video_adapter_t adapter;
      grub_video_driver_id_t id;
      struct hook_ctx ctx;
Quoted 8 lines

Review grub_cmd_videoinfo (grub_command_t cmd _ · line 144

Quoted 8 lines
(quoted diff) +2 -4
-
-  ctx.height = ctx.width = ctx.depth = ctx.set_variable = 0;
-
+
+  ctx.height = ctx.width = ctx.depth = 0;
      if (argc)
        {
-      if (argc == 2 && grub_memcmp(args[0], "--set", sizeof ("--set")

-

Quoted 106 lines
Quoted 106 lines

1)

Quoted 105 lines
(quoted diff) +11 -18
 == 0 )
-  ctx.set_variable = 1;
-      else
-        {
          const char *ptr;
          ptr = args[0];
          ctx.width = grub_strtoul (ptr, &ptr, 0);
          if (grub_errno)
-  return grub_errno;
+   return grub_errno;
          if (*ptr != 'x')
-  return grub_error (GRUB_ERR_BAD_ARGUMENT,
-        N_("invalid video mode specification `%s'"),
-        args[0]);
+   return grub_error (GRUB_ERR_BAD_ARGUMENT,
+                      N_("invalid video mode specification `%s'"),
+                      args[0]);
          ptr++;
          ctx.height = grub_strtoul (ptr, &ptr, 0);
          if (grub_errno)
-  return grub_errno;
+   return grub_errno;
          if (*ptr == 'x')
-  {
-    ptr++;
-    ctx.depth = grub_strtoul (ptr, &ptr, 0);
-    if (grub_errno)
-      return grub_errno;
-  }
-        }
-
+   {
+     ptr++;
+     ctx.depth = grub_strtoul (ptr, &ptr, 0);
+     if (grub_errno)
+       return grub_errno;
+   }
        }
-
-
 
    #ifdef GRUB_MACHINE_PCBIOS
      if (grub_strcmp (cmd->name, "vbeinfo") == 0) @@ -177,23 

+164,20 @@ grub_cmd_videoinfo (grub_command_t cmd _ #endif

      id = grub_video_get_driver_id ();
(quoted diff) +0 -3
-  if (!ctx.set_variable)
-    {
-grub_puts_ (N_("List of supported video modes:")); -grub_puts_

(N_("Legend: mask/position=red/green/blue/reserved"));

(quoted diff) +8 -18
-    }
-
+
+  grub_puts_ (N_("List of supported video modes:"));  grub_puts_
+ (N_("Legend: mask/position=red/green/blue/reserved"));
+
      FOR_VIDEO_ADAPTERS (adapter)
      {
        struct grub_video_mode_info info;
        struct grub_video_edid_info edid_info;
-    if (!ctx.set_variable)
-  grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
+
+    grub_printf_ (N_("Adapter `%s':\n"), adapter->name);
 
        if (!adapter->iterate)
          {
-        if (!ctx.set_variable)
-    grub_puts_ (N_("  No info available"));
+   grub_puts_ (N_("  No info available"));
     continue;
          }
@@ -202,18 +186,7 @@ grub_puts_ (N_("Legend: mask/position=re
        if (adapter->id == id)
          {
     if (grub_video_get_info (&info) == GRUB_ERR_NONE)
-    {
-      ctx.current_mode = &info;
-      if (ctx.set_variable)
-        {
-    /* set grub env var to current mode */
-    char screen_wxh[20];
-    unsigned int width = info.width;
-    unsigned int height = info.height;
-    grub_snprintf (screen_wxh, 20, "%ux%u", width, height);
-    grub_env_set (args[1], screen_wxh);
-        }
-    }
+     ctx.current_mode = &info;
     else
       /* Don't worry about errors.  */
       grub_errno = GRUB_ERR_NONE; @@ -263,26 +236,19 @@ 

GRUB_MOD_INIT(videoinfo)
/* TRANSLATORS: "x" has to be entered in,
like an identifier, so please don't use better Unicode codepoints. */

(quoted diff) +0 -8
-                          N_("[--set var | [WxH]xD]"),
-                          N_("Retrieve available video modes. "
-             "--set is given, assign the currently"
-             "active resolution to var. If --set "
-             "is not provided the available video "
-             "modes are listed. If resolution is "
-             "given, show only matching modes."));
-
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
(quoted diff) +4 -0
+                          N_("[WxH[xD]]"),
+                          N_("List available video modes. If "
+                                "resolution is given show only modes"
+                                " matching it."));
    #ifdef GRUB_MACHINE_PCBIOS
      cmd_vbe = grub_register_command ("vbeinfo", grub_cmd_videoinfo,
                                /* TRANSLATORS: "x" has to be 

entered

in,

Quoted 22 lines
Quoted 7 lines
Quoted 7 lines

like an identifier, so please don't use better Unicode codepoints. */

(quoted diff) +0 -5
-                              N_("[--set var | [WxH]xD]"),
-           N_("Retrieve available video modes. "
-           "--set is given, assign the currently"
-           "active resolution to var. If --set "
-           "is not provided the available video "
Quoted 9 lines

Review

Quoted 8 lines
(quoted diff) +4 -2
-           "modes are listed. If resolution is "
-           "given, show only matching modes."));
+                              N_("[WxH[xD]]"),
+                              N_("List available video modes. If "
+                                 "resolution is given show only modes"
+                                 " matching it."));
    #endif
    }

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel