unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [C source] What is gravity and the change_gravity argument?
@ 2022-07-08 12:40 Akib Azmain Turja
  2022-07-08 12:52 ` Eli Zaretskii
  2022-07-08 13:05 ` Po Lu
  0 siblings, 2 replies; 7+ messages in thread
From: Akib Azmain Turja @ 2022-07-08 12:40 UTC (permalink / raw)
  To: emacs-devel

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


In src/termhooks.h, I found the following two members of struct
terminal:

--8<---------------cut here---------------start------------->8---
  /* This hook is called to change the size of frame F's native
   (underlying) window.  If CHANGE_GRAVITY, change to top-left-corner
   window gravity for this size change and subsequent size changes.
   Otherwise we leave the window gravity unchanged.  */
  void (*set_window_size_hook) (struct frame *f, bool change_gravity,
                                int width, int height);

  /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
   to really change the position, and 0 when calling from
   *_make_frame_visible (in that case, XOFF and YOFF are the current
   position values).  It is -1 when calling from gui_set_frame_parameters,
   which means, do adjust for borders but don't change the gravity.  */

  void (*set_frame_offset_hook) (struct frame *f, register int xoff,
                                 register int yoff, int change_gravity);
--8<---------------cut here---------------end--------------->8---

X and PGTK uses that 'change_gravity' argument, I can't understand what
they are doing with them.  I searched the internet and found several
answers[1], but couldn't make any sense.


Footnotes:
[1]  https://stackoverflow.com/q/3482742/11819469

-- 
Akib Azmain Turja

This message is signed by me with my GnuPG key.  It's fingerprint is:

    7001 8CE5 819F 17A3 BBA6  66AF E74F 0EFA 922A E7F5

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* Re: [C source] What is gravity and the change_gravity argument?
  2022-07-08 12:40 [C source] What is gravity and the change_gravity argument? Akib Azmain Turja
@ 2022-07-08 12:52 ` Eli Zaretskii
  2022-07-08 13:06   ` Po Lu
  2022-07-08 13:14   ` Akib Azmain Turja
  2022-07-08 13:05 ` Po Lu
  1 sibling, 2 replies; 7+ messages in thread
From: Eli Zaretskii @ 2022-07-08 12:52 UTC (permalink / raw)
  To: Akib Azmain Turja; +Cc: emacs-devel

> From: Akib Azmain Turja <akib@disroot.org>
> Date: Fri, 08 Jul 2022 18:40:16 +0600
> 
> In src/termhooks.h, I found the following two members of struct
> terminal:
> 
> --8<---------------cut here---------------start------------->8---
>   /* This hook is called to change the size of frame F's native
>    (underlying) window.  If CHANGE_GRAVITY, change to top-left-corner
>    window gravity for this size change and subsequent size changes.
>    Otherwise we leave the window gravity unchanged.  */
>   void (*set_window_size_hook) (struct frame *f, bool change_gravity,
>                                 int width, int height);
> 
>   /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
>    to really change the position, and 0 when calling from
>    *_make_frame_visible (in that case, XOFF and YOFF are the current
>    position values).  It is -1 when calling from gui_set_frame_parameters,
>    which means, do adjust for borders but don't change the gravity.  */
> 
>   void (*set_frame_offset_hook) (struct frame *f, register int xoff,
>                                  register int yoff, int change_gravity);
> --8<---------------cut here---------------end--------------->8---
> 
> X and PGTK uses that 'change_gravity' argument, I can't understand what
> they are doing with them.  I searched the internet and found several
> answers[1], but couldn't make any sense.

Try this:

  https://tronche.com/gui/x/xlib/window/attributes/gravity.html



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

* Re: [C source] What is gravity and the change_gravity argument?
  2022-07-08 12:40 [C source] What is gravity and the change_gravity argument? Akib Azmain Turja
  2022-07-08 12:52 ` Eli Zaretskii
@ 2022-07-08 13:05 ` Po Lu
  2022-07-08 13:52   ` Akib Azmain Turja
  1 sibling, 1 reply; 7+ messages in thread
From: Po Lu @ 2022-07-08 13:05 UTC (permalink / raw)
  To: Akib Azmain Turja; +Cc: emacs-devel

Akib Azmain Turja <akib@disroot.org> writes:

> X and PGTK uses that 'change_gravity' argument, I can't understand what
> they are doing with them.  I searched the internet and found several
> answers[1], but couldn't make any sense.

`change_gravity' means to actually change the position of the frame's
outer window, and to reset the window gravity to NorthWestGravity.  If
it is 0, then we ignore the value of xoff and yoff, preserve the current
window gravity, and simply restore the previously set frame position.

X has two gravities: the window gravity and bit gravity.  The window
gravity defines how a window is repositioned when its parent is resized.
The bit gravity describes how the contents of the window are moved or
obscured when it is resized.

I think the values are quite self explanatory.



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

* Re: [C source] What is gravity and the change_gravity argument?
  2022-07-08 12:52 ` Eli Zaretskii
@ 2022-07-08 13:06   ` Po Lu
  2022-07-08 13:14   ` Akib Azmain Turja
  1 sibling, 0 replies; 7+ messages in thread
From: Po Lu @ 2022-07-08 13:06 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Akib Azmain Turja, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> Try this:
>
>   https://tronche.com/gui/x/xlib/window/attributes/gravity.html

Keep in mind that resetting the gravity is only one side effect of
`change_gravity', which is some kind of misnomer.

I explained further in my reply to Akib.



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

* Re: [C source] What is gravity and the change_gravity argument?
  2022-07-08 12:52 ` Eli Zaretskii
  2022-07-08 13:06   ` Po Lu
@ 2022-07-08 13:14   ` Akib Azmain Turja
  2022-07-08 13:21     ` Po Lu
  1 sibling, 1 reply; 7+ messages in thread
From: Akib Azmain Turja @ 2022-07-08 13:14 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

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

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Akib Azmain Turja <akib@disroot.org>
>> Date: Fri, 08 Jul 2022 18:40:16 +0600
>> 
>> In src/termhooks.h, I found the following two members of struct
>> terminal:
>> 
>> --8<---------------cut here---------------start------------->8---
>>   /* This hook is called to change the size of frame F's native
>>    (underlying) window.  If CHANGE_GRAVITY, change to top-left-corner
>>    window gravity for this size change and subsequent size changes.
>>    Otherwise we leave the window gravity unchanged.  */
>>   void (*set_window_size_hook) (struct frame *f, bool change_gravity,
>>                                 int width, int height);
>> 
>>   /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
>>    to really change the position, and 0 when calling from
>>    *_make_frame_visible (in that case, XOFF and YOFF are the current
>>    position values).  It is -1 when calling from gui_set_frame_parameters,
>>    which means, do adjust for borders but don't change the gravity.  */
>> 
>>   void (*set_frame_offset_hook) (struct frame *f, register int xoff,
>>                                  register int yoff, int change_gravity);
>> --8<---------------cut here---------------end--------------->8---
>> 
>> X and PGTK uses that 'change_gravity' argument, I can't understand what
>> they are doing with them.  I searched the internet and found several
>> answers[1], but couldn't make any sense.
>
> Try this:
>
>   https://tronche.com/gui/x/xlib/window/attributes/gravity.html
>

This seems like to answer I found, except the terms are different.

If I understand correctly, the following happen when gravity is
CenterGravity:

--8<---------------cut here---------------start------------->8---
+----------+              +--------+
|   some   |              |  some  |              +------+
| contents | -> resize -> |contents| -> resize -> |ontent|
|   here   |              |  here  |              +------+
+----------+              +--------+
--8<---------------cut here---------------end--------------->8---

Am I correct?

But I can't still understand why Emacs needs this.  Emacs handles frame
resizing, so setting gravity seems useless.

-- 
Akib Azmain Turja

This message is signed by me with my GnuPG key.  It's fingerprint is:

    7001 8CE5 819F 17A3 BBA6  66AF E74F 0EFA 922A E7F5

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* Re: [C source] What is gravity and the change_gravity argument?
  2022-07-08 13:14   ` Akib Azmain Turja
@ 2022-07-08 13:21     ` Po Lu
  0 siblings, 0 replies; 7+ messages in thread
From: Po Lu @ 2022-07-08 13:21 UTC (permalink / raw)
  To: Akib Azmain Turja; +Cc: Eli Zaretskii, emacs-devel

Akib Azmain Turja <akib@disroot.org> writes:

> If I understand correctly, the following happen when gravity is
> CenterGravity:
>
> +----------+              +--------+
> |   some   |              |  some  |              +------+
> | contents | -> resize -> |contents| -> resize -> |ontent|
> |   here   |              |  here  |              +------+
> +----------+              +--------+

You're thinking of bit gravity.  Emacs sets the window gravity and
leaves the bit gravity alone.

> But I can't still understand why Emacs needs this.  Emacs handles
> frame resizing, so setting gravity seems useless.

I explained more in my other reply to you.



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

* Re: [C source] What is gravity and the change_gravity argument?
  2022-07-08 13:05 ` Po Lu
@ 2022-07-08 13:52   ` Akib Azmain Turja
  0 siblings, 0 replies; 7+ messages in thread
From: Akib Azmain Turja @ 2022-07-08 13:52 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel

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

Po Lu <luangruo@yahoo.com> writes:

> Akib Azmain Turja <akib@disroot.org> writes:
>
>> X and PGTK uses that 'change_gravity' argument, I can't understand what
>> they are doing with them.  I searched the internet and found several
>> answers[1], but couldn't make any sense.
>
> `change_gravity' means to actually change the position of the frame's
> outer window, and to reset the window gravity to NorthWestGravity.  If
> it is 0, then we ignore the value of xoff and yoff, preserve the current
> window gravity, and simply restore the previously set frame position.
>
> X has two gravities: the window gravity and bit gravity.  The window
> gravity defines how a window is repositioned when its parent is resized.
> The bit gravity describes how the contents of the window are moved or
> obscured when it is resized.

Thanks.

>
> I think the values are quite self explanatory.

Yes, just like directions in a map (of somewhere).

-- 
Akib Azmain Turja

This message is signed by me with my GnuPG key.  It's fingerprint is:

    7001 8CE5 819F 17A3 BBA6  66AF E74F 0EFA 922A E7F5

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

end of thread, other threads:[~2022-07-08 13:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-08 12:40 [C source] What is gravity and the change_gravity argument? Akib Azmain Turja
2022-07-08 12:52 ` Eli Zaretskii
2022-07-08 13:06   ` Po Lu
2022-07-08 13:14   ` Akib Azmain Turja
2022-07-08 13:21     ` Po Lu
2022-07-08 13:05 ` Po Lu
2022-07-08 13:52   ` Akib Azmain Turja

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).