unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* About the new frame title
@ 2020-09-14  8:27 Angelo Graziosi
  2020-09-14 15:17 ` Eli Zaretskii
  0 siblings, 1 reply; 19+ messages in thread
From: Angelo Graziosi @ 2020-09-14  8:27 UTC (permalink / raw)
  To: emacs-devel@gnu.org

I have just built Emacs master (on GNU/Linux) and see the new frame title. Anyway, I noticed a strange behavior. 

In my init file I have this code:

(setq default-frame-alist
      '(
        (width . 115) ; character
        (height . 51) ; lines
        ;;(left . (- 0)); pixel
        ;;(top  . (+ 0)); pixel
        (left . 850); pixel
        (top  .   0); pixel
        (font . "Monospace-11") ; font
        ))

When I start Emacs clicking the icon on the task bar, its frame for less than a second is squared (its default size?) then assume the size following the above code.

When it is squared, the frame title is still "emacs@myPC", only when it assume the final size it take the new frame title (buffer - GNU Emacs at ...)

I wonder if this is what you want with this change or if in its code, somewhere, there is still the old title coded.

BTW, I tried to start Emacs without the init file but it is too fast and I cannot establish the above things.

Thanks,
  Angelo.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-09-14  8:27 About the new frame title Angelo Graziosi
@ 2020-09-14 15:17 ` Eli Zaretskii
  2020-09-14 15:52   ` Angelo Graziosi
  0 siblings, 1 reply; 19+ messages in thread
From: Eli Zaretskii @ 2020-09-14 15:17 UTC (permalink / raw)
  To: Angelo Graziosi; +Cc: emacs-devel

> Date: Mon, 14 Sep 2020 10:27:49 +0200 (CEST)
> From: Angelo Graziosi <angelo.g0@libero.it>
> 
> When I start Emacs clicking the icon on the task bar, its frame for less than a second is squared (its default size?) then assume the size following the above code.
> 
> When it is squared, the frame title is still "emacs@myPC", only when it assume the final size it take the new frame title (buffer - GNU Emacs at ...)

Yes, because the GUI frame initialization code writes the old string
to the frame's title.  See the initialization routines in the
xterm.c/w32term.c etc. (for example, in xterm.c, look in x_term_init).

Is that bad? given that we also momentarily flash the "wrong"
dimensions of the frame?



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-09-14 15:17 ` Eli Zaretskii
@ 2020-09-14 15:52   ` Angelo Graziosi
  2020-09-19 13:21     ` Stefan Kangas
  0 siblings, 1 reply; 19+ messages in thread
From: Angelo Graziosi @ 2020-09-14 15:52 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel


> Il 14/09/2020 17:17 Eli Zaretskii ha scritto:
> 
>  
> > Date: Mon, 14 Sep 2020 10:27:49 +0200 (CEST)
> > From: Angelo Graziosi
> > 
> > When I start Emacs clicking the icon on the task bar, its frame for less than a second is squared (its default size?) then assume the size following the above code.
> > 
> > When it is squared, the frame title is still "emacs@myPC", only when it assume the final size it take the new frame title (buffer - GNU Emacs at ...)
> 
> Yes, because the GUI frame initialization code writes the old string
> to the frame's title.  See the initialization routines in the
> xterm.c/w32term.c etc. (for example, in xterm.c, look in x_term_init).
> 
> Is that bad? given that we also momentarily flash the "wrong"
> dimensions of the frame?

I don't know ... If the decision to change the frame title has been taken, one would expect that the old string goes away too, for coherence. After all, the old string just flashes.

Thanks



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-09-14 15:52   ` Angelo Graziosi
@ 2020-09-19 13:21     ` Stefan Kangas
  2020-09-19 14:39       ` Eli Zaretskii
  2020-09-19 21:22       ` Angelo Graziosi
  0 siblings, 2 replies; 19+ messages in thread
From: Stefan Kangas @ 2020-09-19 13:21 UTC (permalink / raw)
  To: Angelo Graziosi, Eli Zaretskii; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1017 bytes --]

Angelo Graziosi <angelo.g0@libero.it> writes:

>> > When I start Emacs clicking the icon on the task bar, its frame for less than a second is squared (its default size?) then assume the size following the above code.
>> >
>> > When it is squared, the frame title is still "emacs@myPC", only when it assume the final size it take the new frame title (buffer - GNU Emacs at ...)
>>
>> Yes, because the GUI frame initialization code writes the old string
>> to the frame's title.  See the initialization routines in the
>> xterm.c/w32term.c etc. (for example, in xterm.c, look in x_term_init).
>>
>> Is that bad? given that we also momentarily flash the "wrong"
>> dimensions of the frame?
>
> I don't know ... If the decision to change the frame title has been taken, one would expect that the old string goes away too, for coherence. After all, the old string just flashes.

We might as well try to fix it up a bit.  How does the attached patch
look?  Angelo, could you please help test it?

(Untested on MS Windows.)

[-- Attachment #2: 0001-Make-initial-frame-title-match-frame-title-format.patch --]
[-- Type: text/x-diff, Size: 2705 bytes --]

From 6a6179492c50f54dff0fe6d7d45d0318477ee86d Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefan@marxist.se>
Date: Sat, 19 Sep 2020 14:13:52 +0200
Subject: [PATCH] Make initial frame title match frame-title-format

* src/xterm.c (x_term_init):
* src/w32term.c (w32_initialize_display_info): Sync initial frame
title with new value of Vframe_title_format.
Problem reported by Angelo Graziosi <angelo.g0@libero.it>.
---
 src/w32term.c | 11 ++++++-----
 src/xterm.c   | 22 ++++++++++++----------
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/w32term.c b/src/w32term.c
index 2669f29b56..9fbc054688 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -7167,13 +7167,14 @@ w32_initialize_display_info (Lisp_Object display_name)
   dpyinfo->name_list_element = Fcons (display_name, Qnil);
   if (STRINGP (Vsystem_name))
     {
-      dpyinfo->w32_id_name = xmalloc (SCHARS (Vinvocation_name)
-                                      + SCHARS (Vsystem_name) + 2);
-      sprintf (dpyinfo->w32_id_name, "%s@%s",
-               SDATA (Vinvocation_name), SDATA (Vsystem_name));
+      dpyinfo->w32_id_name = xmalloc (14 + SCHARS (Vsystem_name));
+      sprintf (dpyinfo->w32_id_name, "GNU Emacs at %s", SDATA (Vsystem_name));
     }
   else
-    dpyinfo->w32_id_name = xlispstrdup (Vinvocation_name);
+    {
+      dpyinfo->w32_id_name = xmalloc (10);
+      sprintf (dpyinfo->w32_id_name, "GNU Emacs");
+    }
 
   /* Default Console mode values - overridden when running in GUI mode
      with values obtained from system metrics.  */
diff --git a/src/xterm.c b/src/xterm.c
index 2e0407aff4..c30de05a59 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -12927,19 +12927,21 @@ #define NUM_ARGV 10
 #endif
 
   Lisp_Object system_name = Fsystem_name ();
-
-  ptrdiff_t nbytes = SBYTES (Vinvocation_name) + 1;
-  if (STRINGP (system_name)
-      && INT_ADD_WRAPV (nbytes, SBYTES (system_name) + 1, &nbytes))
-    memory_full (SIZE_MAX);
-  dpyinfo->x_id = ++x_display_id;
-  dpyinfo->x_id_name = xmalloc (nbytes);
-  char *nametail = lispstpcpy (dpyinfo->x_id_name, Vinvocation_name);
   if (STRINGP (system_name))
     {
-      *nametail++ = '@';
-      lispstpcpy (nametail, system_name);
+      ptrdiff_t nbytes = 14;
+      if (INT_ADD_WRAPV (nbytes, SBYTES (system_name), &nbytes))
+	memory_full (SIZE_MAX);
+      dpyinfo->x_id_name = xmalloc (nbytes);
+      sprintf(dpyinfo->x_id_name, "GNU Emacs at %s", SDATA (system_name));
     }
+  else
+    {
+      dpyinfo->x_id_name = xmalloc (10);
+      sprintf (dpyinfo->x_id_name, "GNU Emacs");
+    }
+
+  dpyinfo->x_id = ++x_display_id;
 
   /* Figure out which modifier bits mean what.  */
   x_find_modifier_meanings (dpyinfo);
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-09-19 13:21     ` Stefan Kangas
@ 2020-09-19 14:39       ` Eli Zaretskii
  2020-09-24  8:57         ` Stefan Kangas
  2020-09-19 21:22       ` Angelo Graziosi
  1 sibling, 1 reply; 19+ messages in thread
From: Eli Zaretskii @ 2020-09-19 14:39 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: angelo.g0, emacs-devel

> From: Stefan Kangas <stefankangas@gmail.com>
> Date: Sat, 19 Sep 2020 13:21:25 +0000
> Cc: emacs-devel@gnu.org
> 
> We might as well try to fix it up a bit.  How does the attached patch
> look?

Thanks, a minor comment below.

>    dpyinfo->name_list_element = Fcons (display_name, Qnil);
>    if (STRINGP (Vsystem_name))
>      {
> -      dpyinfo->w32_id_name = xmalloc (SCHARS (Vinvocation_name)
> -                                      + SCHARS (Vsystem_name) + 2);
> -      sprintf (dpyinfo->w32_id_name, "%s@%s",
> -               SDATA (Vinvocation_name), SDATA (Vsystem_name));
> +      dpyinfo->w32_id_name = xmalloc (14 + SCHARS (Vsystem_name));
> +      sprintf (dpyinfo->w32_id_name, "GNU Emacs at %s", SDATA (Vsystem_name));

Please don't use hard-coded constants, like 14 above, in such cases.
Instead, use sizeof to compute the correct size at compile time from
the string used as format specifier.

(This pertains to xterm.c change as well.)



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-09-19 13:21     ` Stefan Kangas
  2020-09-19 14:39       ` Eli Zaretskii
@ 2020-09-19 21:22       ` Angelo Graziosi
  2020-09-24  8:37         ` Stefan Kangas
  1 sibling, 1 reply; 19+ messages in thread
From: Angelo Graziosi @ 2020-09-19 21:22 UTC (permalink / raw)
  To: Stefan Kangas, Eli Zaretskii; +Cc: emacs-devel


> Il 19/09/2020 15:21 Stefan Kangas ha scritto:
> 
> We might as well try to fix it up a bit.  How does the attached patch
> look?  Angelo, could you please help test it?

It seems to work. Now I just see 'GNUEmacs at ...'. Thanks.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-09-19 21:22       ` Angelo Graziosi
@ 2020-09-24  8:37         ` Stefan Kangas
  0 siblings, 0 replies; 19+ messages in thread
From: Stefan Kangas @ 2020-09-24  8:37 UTC (permalink / raw)
  To: Angelo Graziosi, Eli Zaretskii; +Cc: emacs-devel

Angelo Graziosi <angelo.g0@libero.it> writes:

>> We might as well try to fix it up a bit.  How does the attached patch
>> look?  Angelo, could you please help test it?
>
> It seems to work. Now I just see 'GNUEmacs at ...'. Thanks.

Thanks for testing!



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-09-19 14:39       ` Eli Zaretskii
@ 2020-09-24  8:57         ` Stefan Kangas
  2020-09-24 14:46           ` Eli Zaretskii
  0 siblings, 1 reply; 19+ messages in thread
From: Stefan Kangas @ 2020-09-24  8:57 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: angelo.g0, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 781 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

>>    dpyinfo->name_list_element = Fcons (display_name, Qnil);
>>    if (STRINGP (Vsystem_name))
>>      {
>> -      dpyinfo->w32_id_name = xmalloc (SCHARS (Vinvocation_name)
>> -                                      + SCHARS (Vsystem_name) + 2);
>> -      sprintf (dpyinfo->w32_id_name, "%s@%s",
>> -               SDATA (Vinvocation_name), SDATA (Vsystem_name));
>> +      dpyinfo->w32_id_name = xmalloc (14 + SCHARS (Vsystem_name));
>> +      sprintf (dpyinfo->w32_id_name, "GNU Emacs at %s", SDATA (Vsystem_name));
>
> Please don't use hard-coded constants, like 14 above, in such cases.
> Instead, use sizeof to compute the correct size at compile time from
> the string used as format specifier.

Thanks.  Does the attached look better?

[-- Attachment #2: 0001-Make-initial-frame-match-frame-title-format.patch --]
[-- Type: text/x-diff, Size: 2954 bytes --]

From 46214fcd6db55b2c71836d2d3054fabe2860c9a1 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefan@marxist.se>
Date: Sat, 19 Sep 2020 14:13:52 +0200
Subject: [PATCH] Make initial frame match frame-title-format

* src/xterm.c (x_term_init):
* src/w32term.c (w32_initialize_display_info): Sync initial frame
title with new value of Vframe_title_format.
Problem reported by Angelo Graziosi <angelo.g0@libero.it>.
---
 src/w32term.c | 14 +++++++++-----
 src/xterm.c   | 25 +++++++++++++++----------
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/src/w32term.c b/src/w32term.c
index 2669f29b56..206b5ecb82 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -7165,15 +7165,19 @@ w32_initialize_display_info (Lisp_Object display_name)
   memset (dpyinfo, 0, sizeof (*dpyinfo));
 
   dpyinfo->name_list_element = Fcons (display_name, Qnil);
+  const char *title;
   if (STRINGP (Vsystem_name))
     {
-      dpyinfo->w32_id_name = xmalloc (SCHARS (Vinvocation_name)
-                                      + SCHARS (Vsystem_name) + 2);
-      sprintf (dpyinfo->w32_id_name, "%s@%s",
-               SDATA (Vinvocation_name), SDATA (Vsystem_name));
+      title = "GNU Emacs at ";
+      dpyinfo->w32_id_name = xmalloc (sizeof (title) + SCHARS (Vsystem_name));
+      sprintf (dpyinfo->w32_id_name, "%s%s", title, SDATA (Vsystem_name));
     }
   else
-    dpyinfo->w32_id_name = xlispstrdup (Vinvocation_name);
+    {
+      title = "GNU Emacs";
+      dpyinfo->w32_id_name = xmalloc (sizeof (title));
+      sprintf (dpyinfo->w32_id_name, "%s", title);
+    }
 
   /* Default Console mode values - overridden when running in GUI mode
      with values obtained from system metrics.  */
diff --git a/src/xterm.c b/src/xterm.c
index 2e0407aff4..626f066bca 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -12927,19 +12927,24 @@ #define NUM_ARGV 10
 #endif
 
   Lisp_Object system_name = Fsystem_name ();
-
-  ptrdiff_t nbytes = SBYTES (Vinvocation_name) + 1;
-  if (STRINGP (system_name)
-      && INT_ADD_WRAPV (nbytes, SBYTES (system_name) + 1, &nbytes))
-    memory_full (SIZE_MAX);
-  dpyinfo->x_id = ++x_display_id;
-  dpyinfo->x_id_name = xmalloc (nbytes);
-  char *nametail = lispstpcpy (dpyinfo->x_id_name, Vinvocation_name);
+  const char *title;
   if (STRINGP (system_name))
     {
-      *nametail++ = '@';
-      lispstpcpy (nametail, system_name);
+      title = "GNU Emacs at ";
+      ptrdiff_t nbytes = sizeof (title);
+      if (INT_ADD_WRAPV (nbytes, SBYTES (system_name), &nbytes))
+	memory_full (SIZE_MAX);
+      dpyinfo->x_id_name = xmalloc (nbytes);
+      sprintf(dpyinfo->x_id_name, "%s%s", title, SDATA (system_name));
     }
+  else
+    {
+      title = "GNU Emacs";
+      dpyinfo->x_id_name = xmalloc (sizeof (title));
+      sprintf (dpyinfo->x_id_name, "%s", title);
+    }
+
+  dpyinfo->x_id = ++x_display_id;
 
   /* Figure out which modifier bits mean what.  */
   x_find_modifier_meanings (dpyinfo);
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-09-24  8:57         ` Stefan Kangas
@ 2020-09-24 14:46           ` Eli Zaretskii
  2020-09-25 12:38             ` Angelo Graziosi
  2020-11-13 23:10             ` Stefan Kangas
  0 siblings, 2 replies; 19+ messages in thread
From: Eli Zaretskii @ 2020-09-24 14:46 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: angelo.g0, emacs-devel

> From: Stefan Kangas <stefankangas@gmail.com>
> Date: Thu, 24 Sep 2020 01:57:38 -0700
> Cc: angelo.g0@libero.it, emacs-devel@gnu.org
> 
> +  const char *title;
>    if (STRINGP (system_name))
>      {
> -      *nametail++ = '@';
> -      lispstpcpy (nametail, system_name);
> +      title = "GNU Emacs at ";
> +      ptrdiff_t nbytes = sizeof (title);

Does this work?  AFAIK, 'sizeof (char *)' returns 8 on a 64-bit system
and 4 on a 32-bit system, regardless of the length of the text string
it points to.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-09-24 14:46           ` Eli Zaretskii
@ 2020-09-25 12:38             ` Angelo Graziosi
  2020-09-25 12:41               ` Eli Zaretskii
  2020-11-13 23:10             ` Stefan Kangas
  1 sibling, 1 reply; 19+ messages in thread
From: Angelo Graziosi @ 2020-09-25 12:38 UTC (permalink / raw)
  To: Eli Zaretskii, Stefan Kangas; +Cc: emacs-devel


> Il 24/09/2020 16:46 Eli Zaretskii ha scritto:
> 
>  
> > From: Stefan Kangas
> > Date: Thu, 24 Sep 2020 01:57:38 -0700
> > Cc: 
> > 
> > +  const char *title;
> >    if (STRINGP (system_name))
> >      {
> > -      *nametail++ = '@';
> > -      lispstpcpy (nametail, system_name);
> > +      title = "GNU Emacs at ";
> > +      ptrdiff_t nbytes = sizeof (title);
> 
> Does this work?  AFAIK, 'sizeof (char *)' returns 8 on a 64-bit system
> and 4 on a 32-bit system, regardless of the length of the text string
> it points to.

I wonder if this can fix it:

ptrdiff_t nbytes = strlen(title)*sizeof (title[0]);

or better, given 'title' is a const hard coded,

ptrdiff_t nbytes = 13*sizeof (title[0]);


Just a reminiscence of the ancient use of C ...



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-09-25 12:38             ` Angelo Graziosi
@ 2020-09-25 12:41               ` Eli Zaretskii
  2020-09-25 13:31                 ` Angelo Graziosi
  0 siblings, 1 reply; 19+ messages in thread
From: Eli Zaretskii @ 2020-09-25 12:41 UTC (permalink / raw)
  To: Angelo Graziosi; +Cc: stefankangas, emacs-devel

> Date: Fri, 25 Sep 2020 14:38:44 +0200 (CEST)
> From: Angelo Graziosi <angelo.g0@libero.it>
> Cc: emacs-devel@gnu.org
> 
> > Does this work?  AFAIK, 'sizeof (char *)' returns 8 on a 64-bit system
> > and 4 on a 32-bit system, regardless of the length of the text string
> > it points to.
> 
> I wonder if this can fix it:
> 
> ptrdiff_t nbytes = strlen(title)*sizeof (title[0]);

This will work, but the idea was to compute the value at compile time,
since sizeof is a compile-time operator.

> or better, given 'title' is a const hard coded,
> 
> ptrdiff_t nbytes = 13*sizeof (title[0]);

That's exactly what I wanted to avoid, since the constant needs to be
updated each time the text is modified.

Thanks.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-09-25 12:41               ` Eli Zaretskii
@ 2020-09-25 13:31                 ` Angelo Graziosi
  2020-09-25 13:42                   ` Eli Zaretskii
  0 siblings, 1 reply; 19+ messages in thread
From: Angelo Graziosi @ 2020-09-25 13:31 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: stefankangas, emacs-devel


> Il 25/09/2020 14:41 Eli Zaretskii ha scritto:
> 
> This will work, but the idea was to compute the value at compile time,

Not sure if this works as you want, just a STC,

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
  int n, m, nb;

  srand (time(NULL));

  if (rand() % 2 == 0)
  {
    const char title[] = "GNU Emacs at ";
     n = sizeof (title)-1;
     m = sizeof(title[0]);
  }
  else
  {
    const char title[] = "GNU Emacs";
     n = sizeof (title)-1;
     m = sizeof(title[0]);
  }

  nb = n/m;

  printf("%d\n",n);
  printf("%d\n",m);
  printf("%d\n",nb);

  return 0;
}



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-09-25 13:31                 ` Angelo Graziosi
@ 2020-09-25 13:42                   ` Eli Zaretskii
  0 siblings, 0 replies; 19+ messages in thread
From: Eli Zaretskii @ 2020-09-25 13:42 UTC (permalink / raw)
  To: Angelo Graziosi; +Cc: stefankangas, emacs-devel

> Date: Fri, 25 Sep 2020 15:31:49 +0200 (CEST)
> From: Angelo Graziosi <angelo.g0@libero.it>
> Cc: stefankangas@gmail.com, emacs-devel@gnu.org
> 
>   if (rand() % 2 == 0)
>   {
>     const char title[] = "GNU Emacs at ";
>      n = sizeof (title)-1;
>      m = sizeof(title[0]);

Yes, using 'char title[]' will work and compute the size at compile
time.

Thanks.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-09-24 14:46           ` Eli Zaretskii
  2020-09-25 12:38             ` Angelo Graziosi
@ 2020-11-13 23:10             ` Stefan Kangas
  2020-11-13 23:51               ` Andrea Corallo via Emacs development discussions.
  2020-11-14  7:26               ` Eli Zaretskii
  1 sibling, 2 replies; 19+ messages in thread
From: Stefan Kangas @ 2020-11-13 23:10 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: angelo.g0, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 601 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Stefan Kangas <stefankangas@gmail.com>
>> Date: Thu, 24 Sep 2020 01:57:38 -0700
>> Cc: angelo.g0@libero.it, emacs-devel@gnu.org
>>
>> +  const char *title;
>>    if (STRINGP (system_name))
>>      {
>> -      *nametail++ = '@';
>> -      lispstpcpy (nametail, system_name);
>> +      title = "GNU Emacs at ";
>> +      ptrdiff_t nbytes = sizeof (title);
>
> Does this work?  AFAIK, 'sizeof (char *)' returns 8 on a 64-bit system
> and 4 on a 32-bit system, regardless of the length of the text string
> it points to.

Please find attached a fixed patch.

[-- Attachment #2: 0001-Make-initial-frame-match-frame-title-format.patch --]
[-- Type: text/x-diff, Size: 2936 bytes --]

From b373d79630bc6b419c46d782f13c4c4bfb625f0c Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefan@marxist.se>
Date: Sat, 19 Sep 2020 14:13:52 +0200
Subject: [PATCH] Make initial frame match frame-title-format

* src/xterm.c (x_term_init):
* src/w32term.c (w32_initialize_display_info): Sync initial frame
title with new value of Vframe_title_format.
Problem reported by Angelo Graziosi <angelo.g0@libero.it>.
---
 src/w32term.c | 13 ++++++++-----
 src/xterm.c   | 24 ++++++++++++++----------
 2 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/src/w32term.c b/src/w32term.c
index e0618e4f52..89fa26ed9f 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -7167,13 +7167,16 @@ w32_initialize_display_info (Lisp_Object display_name)
   dpyinfo->name_list_element = Fcons (display_name, Qnil);
   if (STRINGP (Vsystem_name))
     {
-      dpyinfo->w32_id_name = xmalloc (SCHARS (Vinvocation_name)
-                                      + SCHARS (Vsystem_name) + 2);
-      sprintf (dpyinfo->w32_id_name, "%s@%s",
-               SDATA (Vinvocation_name), SDATA (Vsystem_name));
+      static char const title[] = "GNU Emacs at ";
+      dpyinfo->w32_id_name = xmalloc (sizeof title + SCHARS (Vsystem_name));
+      sprintf (dpyinfo->w32_id_name, "%s%s", title, SDATA (Vsystem_name));
     }
   else
-    dpyinfo->w32_id_name = xlispstrdup (Vinvocation_name);
+    {
+      static char const title[] = "GNU Emacs";
+      dpyinfo->w32_id_name = xmalloc (sizeof title);
+      sprintf (dpyinfo->w32_id_name, "%s", title);
+    }
 
   /* Default Console mode values - overridden when running in GUI mode
      with values obtained from system metrics.  */
diff --git a/src/xterm.c b/src/xterm.c
index 98bb0ea891..c65588cfda 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -12928,19 +12928,23 @@ #define NUM_ARGV 10
 #endif
 
   Lisp_Object system_name = Fsystem_name ();
-
-  ptrdiff_t nbytes = SBYTES (Vinvocation_name) + 1;
-  if (STRINGP (system_name)
-      && INT_ADD_WRAPV (nbytes, SBYTES (system_name) + 1, &nbytes))
-    memory_full (SIZE_MAX);
-  dpyinfo->x_id = ++x_display_id;
-  dpyinfo->x_id_name = xmalloc (nbytes);
-  char *nametail = lispstpcpy (dpyinfo->x_id_name, Vinvocation_name);
   if (STRINGP (system_name))
     {
-      *nametail++ = '@';
-      lispstpcpy (nametail, system_name);
+      static char const title[] = "GNU Emacs at ";
+      ptrdiff_t nbytes = sizeof title;
+      if (INT_ADD_WRAPV (nbytes, SBYTES (system_name), &nbytes))
+	memory_full (SIZE_MAX);
+      dpyinfo->x_id_name = xmalloc (nbytes);
+      sprintf (dpyinfo->x_id_name, "%s%s", title, SDATA (system_name));
     }
+  else
+    {
+      static char const title[] = "GNU Emacs";
+      dpyinfo->x_id_name = xmalloc (sizeof title);
+      sprintf (dpyinfo->x_id_name, "%s", title);
+    }
+
+  dpyinfo->x_id = ++x_display_id;
 
   /* Figure out which modifier bits mean what.  */
   x_find_modifier_meanings (dpyinfo);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-11-13 23:10             ` Stefan Kangas
@ 2020-11-13 23:51               ` Andrea Corallo via Emacs development discussions.
  2020-11-14  7:26               ` Eli Zaretskii
  1 sibling, 0 replies; 19+ messages in thread
From: Andrea Corallo via Emacs development discussions. @ 2020-11-13 23:51 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Eli Zaretskii, angelo.g0, emacs-devel

Stefan Kangas <stefankangas@gmail.com> writes:

[...]

Hi Stefan,

> From b373d79630bc6b419c46d782f13c4c4bfb625f0c Mon Sep 17 00:00:00 2001
> From: Stefan Kangas <stefan@marxist.se>
> Date: Sat, 19 Sep 2020 14:13:52 +0200
> Subject: [PATCH] Make initial frame match frame-title-format
>
> * src/xterm.c (x_term_init):
> * src/w32term.c (w32_initialize_display_info): Sync initial frame
> title with new value of Vframe_title_format.
> Problem reported by Angelo Graziosi <angelo.g0@libero.it>.
> ---
>  src/w32term.c | 13 ++++++++-----
>  src/xterm.c   | 24 ++++++++++++++----------
>  2 files changed, 22 insertions(+), 15 deletions(-)
>
> diff --git a/src/w32term.c b/src/w32term.c
> index e0618e4f52..89fa26ed9f 100644
> --- a/src/w32term.c
> +++ b/src/w32term.c
> @@ -7167,13 +7167,16 @@ w32_initialize_display_info (Lisp_Object display_name)
>    dpyinfo->name_list_element = Fcons (display_name, Qnil);
>    if (STRINGP (Vsystem_name))
>      {
> -      dpyinfo->w32_id_name = xmalloc (SCHARS (Vinvocation_name)
> -                                      + SCHARS (Vsystem_name) + 2);
> -      sprintf (dpyinfo->w32_id_name, "%s@%s",
> -               SDATA (Vinvocation_name), SDATA (Vsystem_name));
> +      static char const title[] = "GNU Emacs at ";
> +      dpyinfo->w32_id_name = xmalloc (sizeof title + SCHARS (Vsystem_name));

I believe `sizeof (title)` is more conventional nowdays as safer.

> +      sprintf (dpyinfo->w32_id_name, "%s%s", title, SDATA (Vsystem_name));
>      }
>    else
> -    dpyinfo->w32_id_name = xlispstrdup (Vinvocation_name);
> +    {
> +      static char const title[] = "GNU Emacs";
> +      dpyinfo->w32_id_name = xmalloc (sizeof title);

Same

> +      sprintf (dpyinfo->w32_id_name, "%s", title);

I think a strcpy here would be sufficent as the format string is only "%s".

> +    }
>  
>    /* Default Console mode values - overridden when running in GUI mode
>       with values obtained from system metrics.  */
> diff --git a/src/xterm.c b/src/xterm.c
> index 98bb0ea891..c65588cfda 100644
> --- a/src/xterm.c
> +++ b/src/xterm.c
> @@ -12928,19 +12928,23 @@ #define NUM_ARGV 10
>  #endif
>  
>    Lisp_Object system_name = Fsystem_name ();
> -
> -  ptrdiff_t nbytes = SBYTES (Vinvocation_name) + 1;
> -  if (STRINGP (system_name)
> -      && INT_ADD_WRAPV (nbytes, SBYTES (system_name) + 1, &nbytes))
> -    memory_full (SIZE_MAX);
> -  dpyinfo->x_id = ++x_display_id;
> -  dpyinfo->x_id_name = xmalloc (nbytes);
> -  char *nametail = lispstpcpy (dpyinfo->x_id_name, Vinvocation_name);
>    if (STRINGP (system_name))
>      {
> -      *nametail++ = '@';
> -      lispstpcpy (nametail, system_name);
> +      static char const title[] = "GNU Emacs at ";
> +      ptrdiff_t nbytes = sizeof title;

Same

> +      if (INT_ADD_WRAPV (nbytes, SBYTES (system_name), &nbytes))
> +	memory_full (SIZE_MAX);
> +      dpyinfo->x_id_name = xmalloc (nbytes);
> +      sprintf (dpyinfo->x_id_name, "%s%s", title, SDATA (system_name));
>      }
> +  else
> +    {
> +      static char const title[] = "GNU Emacs";
> +      dpyinfo->x_id_name = xmalloc (sizeof title);
> +      sprintf (dpyinfo->x_id_name, "%s", title);

Same

> +    }
> +
> +  dpyinfo->x_id = ++x_display_id;
>  
>    /* Figure out which modifier bits mean what.  */
>    x_find_modifier_meanings (dpyinfo);

Hope it helps

  Andrea



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-11-13 23:10             ` Stefan Kangas
  2020-11-13 23:51               ` Andrea Corallo via Emacs development discussions.
@ 2020-11-14  7:26               ` Eli Zaretskii
  2020-11-14 14:47                 ` Stefan Kangas
  1 sibling, 1 reply; 19+ messages in thread
From: Eli Zaretskii @ 2020-11-14  7:26 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: angelo.g0, emacs-devel

> From: Stefan Kangas <stefankangas@gmail.com>
> Date: Fri, 13 Nov 2020 15:10:27 -0800
> Cc: angelo.g0@libero.it, emacs-devel@gnu.org
> 
> Please find attached a fixed patch.

Thanks.  In addition to comments from Andrea, I have a few minor nits
below.

>    if (STRINGP (Vsystem_name))
>      {
> -      dpyinfo->w32_id_name = xmalloc (SCHARS (Vinvocation_name)
> -                                      + SCHARS (Vsystem_name) + 2);
> -      sprintf (dpyinfo->w32_id_name, "%s@%s",
> -               SDATA (Vinvocation_name), SDATA (Vsystem_name));
> +      static char const title[] = "GNU Emacs at ";
> +      dpyinfo->w32_id_name = xmalloc (sizeof title + SCHARS (Vsystem_name));
> +      sprintf (dpyinfo->w32_id_name, "%s%s", title, SDATA (Vsystem_name));
>      }
>    else
> -    dpyinfo->w32_id_name = xlispstrdup (Vinvocation_name);
> +    {
> +      static char const title[] = "GNU Emacs";
> +      dpyinfo->w32_id_name = xmalloc (sizeof title);
> +      sprintf (dpyinfo->w32_id_name, "%s", title);
> +    }

Can we have just one const char variable with "GNU Emacs" and another
with " at "?  I think this would be somewhat cleaner, and also save us
a tiny amount of memory.  And the same in xterm.c.

>    if (STRINGP (system_name))
>      {
> -      *nametail++ = '@';
> -      lispstpcpy (nametail, system_name);
> +      static char const title[] = "GNU Emacs at ";
> +      ptrdiff_t nbytes = sizeof title;
> +      if (INT_ADD_WRAPV (nbytes, SBYTES (system_name), &nbytes))
> +	memory_full (SIZE_MAX);

I see no reason to use INT_ADD_WRAPV in xterm.c, but not in w32term.c.
Let's do the same either in both places or in none of them.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-11-14  7:26               ` Eli Zaretskii
@ 2020-11-14 14:47                 ` Stefan Kangas
  2020-11-14 15:10                   ` Eli Zaretskii
  0 siblings, 1 reply; 19+ messages in thread
From: Stefan Kangas @ 2020-11-14 14:47 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Andrea Corallo, angelo.g0, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 473 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

> Thanks.  In addition to comments from Andrea, I have a few minor nits
> below.

Thank you Andrea and Eli for your comments.

I have attached an updated patch that fixes your comments.  I have only
tested it on GNU/Linux.

If someone wants to test this on Windows, make sure to test also using
"--no-build-details".  To be able to spot the title before it changes,
make sure to load a long-running init file, i.e. don't use emacs -Q.

[-- Attachment #2: 0001-Make-initial-frame-match-frame-title-format.patch --]
[-- Type: text/x-diff, Size: 3089 bytes --]

From b598f9c06b631949225a4e7c797ee17f75ca1ba2 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefan@marxist.se>
Date: Sat, 14 Nov 2020 00:08:17 +0100
Subject: [PATCH] Make initial frame match frame-title-format

* src/xterm.c (x_term_init):
* src/w32term.c (w32_initialize_display_info): Sync initial frame
title with new value of Vframe_title_format.
Problem reported by Angelo Graziosi <angelo.g0@libero.it>.
---
 src/w32term.c | 16 +++++++++++-----
 src/xterm.c   | 24 ++++++++++++++----------
 2 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/src/w32term.c b/src/w32term.c
index e0618e4f52..23cb380040 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -7165,15 +7165,21 @@ w32_initialize_display_info (Lisp_Object display_name)
   memset (dpyinfo, 0, sizeof (*dpyinfo));
 
   dpyinfo->name_list_element = Fcons (display_name, Qnil);
+  static char const title[] = "GNU Emacs";
   if (STRINGP (Vsystem_name))
     {
-      dpyinfo->w32_id_name = xmalloc (SCHARS (Vinvocation_name)
-                                      + SCHARS (Vsystem_name) + 2);
-      sprintf (dpyinfo->w32_id_name, "%s@%s",
-               SDATA (Vinvocation_name), SDATA (Vsystem_name));
+      static char const at[] = " at ";
+      ptrdiff_t nbytes = sizeof (title) + sizeof (at);
+      if (INT_ADD_WRAPV (nbytes, SCHARS (Vsystem_name), &nbytes))
+	memory_full (SIZE_MAX);
+      dpyinfo->w32_id_name = xmalloc (nbytes);
+      sprintf (dpyinfo->w32_id_name, "%s%s%s", title, at, SDATA (Vsystem_name));
     }
   else
-    dpyinfo->w32_id_name = xlispstrdup (Vinvocation_name);
+    {
+      dpyinfo->w32_id_name = xmalloc (sizeof (title));
+      strcpy (dpyinfo->w32_id_name, title);
+    }
 
   /* Default Console mode values - overridden when running in GUI mode
      with values obtained from system metrics.  */
diff --git a/src/xterm.c b/src/xterm.c
index 98bb0ea891..0d2452de92 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -12928,19 +12928,23 @@ #define NUM_ARGV 10
 #endif
 
   Lisp_Object system_name = Fsystem_name ();
-
-  ptrdiff_t nbytes = SBYTES (Vinvocation_name) + 1;
-  if (STRINGP (system_name)
-      && INT_ADD_WRAPV (nbytes, SBYTES (system_name) + 1, &nbytes))
-    memory_full (SIZE_MAX);
-  dpyinfo->x_id = ++x_display_id;
-  dpyinfo->x_id_name = xmalloc (nbytes);
-  char *nametail = lispstpcpy (dpyinfo->x_id_name, Vinvocation_name);
+  static char const title[] = "GNU Emacs";
   if (STRINGP (system_name))
     {
-      *nametail++ = '@';
-      lispstpcpy (nametail, system_name);
+      static char const at[] = " at ";
+      ptrdiff_t nbytes = sizeof (title) + sizeof (at);
+      if (INT_ADD_WRAPV (nbytes, SBYTES (system_name), &nbytes))
+	memory_full (SIZE_MAX);
+      dpyinfo->x_id_name = xmalloc (nbytes);
+      sprintf (dpyinfo->x_id_name, "%s%s%s", title, at, SDATA (system_name));
     }
+  else
+    {
+      dpyinfo->x_id_name = xmalloc (sizeof (title));
+      strcpy (dpyinfo->x_id_name, title);
+    }
+
+  dpyinfo->x_id = ++x_display_id;
 
   /* Figure out which modifier bits mean what.  */
   x_find_modifier_meanings (dpyinfo);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-11-14 14:47                 ` Stefan Kangas
@ 2020-11-14 15:10                   ` Eli Zaretskii
  2020-11-15  1:44                     ` Stefan Kangas
  0 siblings, 1 reply; 19+ messages in thread
From: Eli Zaretskii @ 2020-11-14 15:10 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: akrl, angelo.g0, emacs-devel

> From: Stefan Kangas <stefankangas@gmail.com>
> Date: Sat, 14 Nov 2020 06:47:30 -0800
> Cc: angelo.g0@libero.it, emacs-devel@gnu.org, Andrea Corallo <akrl@sdf.org>
> 
> Thank you Andrea and Eli for your comments.
> 
> I have attached an updated patch that fixes your comments.  I have only
> tested it on GNU/Linux.

LGTM, thanks.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: About the new frame title
  2020-11-14 15:10                   ` Eli Zaretskii
@ 2020-11-15  1:44                     ` Stefan Kangas
  0 siblings, 0 replies; 19+ messages in thread
From: Stefan Kangas @ 2020-11-15  1:44 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: akrl, angelo.g0, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> LGTM, thanks.

Thanks, pushed to master as commit 36431e1679.



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2020-11-15  1:44 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-14  8:27 About the new frame title Angelo Graziosi
2020-09-14 15:17 ` Eli Zaretskii
2020-09-14 15:52   ` Angelo Graziosi
2020-09-19 13:21     ` Stefan Kangas
2020-09-19 14:39       ` Eli Zaretskii
2020-09-24  8:57         ` Stefan Kangas
2020-09-24 14:46           ` Eli Zaretskii
2020-09-25 12:38             ` Angelo Graziosi
2020-09-25 12:41               ` Eli Zaretskii
2020-09-25 13:31                 ` Angelo Graziosi
2020-09-25 13:42                   ` Eli Zaretskii
2020-11-13 23:10             ` Stefan Kangas
2020-11-13 23:51               ` Andrea Corallo via Emacs development discussions.
2020-11-14  7:26               ` Eli Zaretskii
2020-11-14 14:47                 ` Stefan Kangas
2020-11-14 15:10                   ` Eli Zaretskii
2020-11-15  1:44                     ` Stefan Kangas
2020-09-19 21:22       ` Angelo Graziosi
2020-09-24  8:37         ` Stefan Kangas

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).