Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Child frame not resizing to fit candidates #2

Open
Koekelas opened this issue Jul 10, 2018 · 73 comments
Open

Child frame not resizing to fit candidates #2

Koekelas opened this issue Jul 10, 2018 · 73 comments

Comments

@Koekelas
Copy link

Koekelas commented Jul 10, 2018

When the child frame is shown, it fits the initial candidates. When you interact with the child frame (e.g. type or scroll), it doesn't resize, resulting in cut off candidates. Look at the two cut off autoload candidates.

company-posframe

This also happens on a clean Emacs.

@Koekelas
Copy link
Author

Koekelas commented Jul 15, 2018

I'm trying to debug this, but so far no luck.

Some additional observations:

  • I can reproduce this on my primary machine (Linux 4.17.5, GNOME 3.28.2, Emacs 26.1) but not on my secondary machine (Windows 8, Emacs 26.1)
  • When current loses/regains focus (by executing eval-expression), the child window resizes.

@tumashu
Copy link
Owner

tumashu commented Jul 15, 2018

Switch anothet WM, and try again, maybe gnome problem

@Koekelas
Copy link
Author

I tried your suggestion inside a VM. I can't reproduce this on KDE Neon (KDE/KWin). I also tried Fedora Workstation (GNOME/Mutter), both the Wayland and the X.Org session. I can reproduce it on Fedora. So, something GNOME specific.

@0x3UH4224D
Copy link

Same here on GNOME 3.28.2, Emacs 26.1.

@andreyorst
Copy link

Seems like I'm experiencing the same issue:
image

@nicber
Copy link

nicber commented Sep 30, 2019

@dgutov
Copy link
Contributor

dgutov commented Dec 14, 2019

I'm also seeing this problem.

@tumashu GNOME is the most popular Linux DE. Shouldn't we do something?

If it's the problem in how child frame is implemented, could you file an Emacs bug report with a reproduction scenario that our windowing subsystem devs can understand?

@dgutov
Copy link
Contributor

dgutov commented Jan 18, 2020

Some questions to help debug this problem with Emacs developers:

  1. Is everybody seeing this problem using GNOME?
  2. Is everybody using Mutter as the WM, or somebody with Metacity as well?
  3. Does anyone with this problem have a non-HiDPI (i.e. normal resolution) monitor?

@andreyorst
Copy link

andreyorst commented Jan 18, 2020 via email

@dgutov
Copy link
Contributor

dgutov commented Jan 18, 2020

Thanks. Martin asked whether this happens on GNOME + Metacity as well.

@Koekelas
Copy link
Author

GNOME with Mutter on a non HiDPI display.

@andreyorst
Copy link

andreyorst commented Jan 18, 2020 via email

@dgutov
Copy link
Contributor

dgutov commented Jan 20, 2020

Here's a workaround for y'all to try:

--- posframe.el	2019-12-16 00:37:59.392804886 +0300
+++ posframe.el	2020-01-20 15:59:50.981671559 +0300
@@ -627,13 +627,19 @@
   (if (and width height)
       (unless (equal posframe--last-posframe-size
                      (list height min-height width min-width))
-        (fit-frame-to-buffer
+        (posframe--fit-to-buffer
          posframe height min-height width min-width)
         (setq-local posframe--last-posframe-size
                     (list height min-height width min-width)))
-    (fit-frame-to-buffer
+    (posframe--fit-to-buffer
      posframe height min-height width min-width)))
 
+(defun posframe--fit-to-buffer (frame height min-height width min-width)
+  ;; GNOME Mutter workaround
+  (make-frame-invisible frame)
+  (fit-frame-to-buffer frame height min-height width min-width)
+  (make-frame-visible frame))
+
 (defun posframe--set-frame-position (posframe position
                                               parent-frame-width
                                               parent-frame-height)

I still get hellish flickering (particularly noticeable if you lean on M-n), but now much faster, and with correct resizing.

@dgutov
Copy link
Contributor

dgutov commented Jan 20, 2020

BTW, if there's someone here who can build and debug Mutter, please speak up.

@dgutov
Copy link
Contributor

dgutov commented Jan 20, 2020

And here's a better workaround: just build Emacs with a different toolkit.

./configure --with-x-toolkit=lucid gives me posframe that's much faster, resizes correctly even without the visibility hack above, and where flickering is basically non-existent (at least in company-posframe; ivy-posframe still has some).

@dgutov
Copy link
Contributor

dgutov commented Jan 20, 2020

And if you have tool-bar-mode turned off, you'll likely see no practical difference.

@tumashu
Copy link
Owner

tumashu commented Jan 21, 2020

I have tested lucid, frame show and hide or frame move seem to very slow.

@dgutov
Copy link
Contributor

dgutov commented Jan 21, 2020

Compared to... GTK?

@andreyorst
Copy link

can confirm that it is quite slow, but it certainly works with lucid. Except if slideshow experience can be described as works

@dgutov
Copy link
Contributor

dgutov commented Jan 21, 2020

That's surprising. The Lucid build is really very fast here (GNOME 3.32.1, GTK 3.24.8). You can also try Motif, I'm seeing similar experience.

As for the GTK build, @andreyorst have you tried the workaround I posted above?

@andreyorst
Copy link

As for the GTK build, @andreyorst have you tried the workaround I posted above?

No, sorry for that! I'm not using company-posframe, I'm here from the https://github.com/casouri/eldoc-box package, which has the same issue with resizing child frames but doesn't use posframe inside.

@dgutov
Copy link
Contributor

dgutov commented Jan 21, 2020

Then you can try the same approach by toggling visibility before and after the set-frame-size call in eldoc-box--update-childframe-geometry. It might actually work okay, if the eldoc box isn't shown persistently.

@dgutov
Copy link
Contributor

dgutov commented Jan 21, 2020

Speaking of performance under Lucid, etc, it would be helpful if you and/or others posted some measuremenets.

There is an example here: https://lists.gnu.org/archive/html/emacs-devel/2020-01/msg00343.html

If you add (benchmark 10 '(resize-test test-frame)) at the bottom, what's the result?

@tumashu
Copy link
Owner

tumashu commented Jan 22, 2020

@dgutov

Today, I test lucid again, and find the slow may posn-at-point

(benchmark 1000 '(posn-at-point (point)))

"Elapsed time: 0.684959s"

this let posframe slow when first show posframe

         (parent-window-height (window-pixel-height parent-window))
         (position-info
          (if (integerp position)
              (posn-at-point position parent-window)
            position))
         (parent-frame (window-frame parent-window))

@dgutov
Copy link
Contributor

dgutov commented Jan 22, 2020

@tumashu Why do you consider that slow? Do you call post-at-point more than once per action?

The same form returns 0.72s for me using a GTK build anyway.

@tumashu
Copy link
Owner

tumashu commented Jan 22, 2020

@dgutov I use pyim (an input method) to test posframe, and find that posn-at-point let posframe ~half second lag

@andreyorst
Copy link

What if you also set x-wait-for-event-timeout to 0 like the message suggests?

I've missed that part. It's much faster, but still noticeable, although I can live with it.

@dgutov
Copy link
Contributor

dgutov commented Mar 13, 2020

So, to sum up:

  • the patch is an improvement (with no noticeable regressions)
  • emacs-27 behaves better than master
  • setting x-wait-for-event-timeout to 0 eliminates a visual delay

Is that right?

If you still can make a video of the lag, that would be also great.

@andreyorst
Copy link

I'll try to record it in two hours or tomorrow. Everything else you've listed seems correct by me

@AlexLewandowski
Copy link

@dgutov I just tried the patch on emacs 27.0.90 and gtk3, it seems to work very well!

@andreyorst
Copy link

@dgutov After several days of using this patch I think that everything is very good. No issues so far. The lag also gone for some reason.

@dgutov
Copy link
Contributor

dgutov commented Apr 6, 2020

Good news everyone!

Emacs 27 will include a new variable called x-gtk-resize-child-frames: https://git.savannah.gnu.org/cgit/emacs.git/commit/?h=emacs-27&id=c49d379f17bcb0ce82604def2eaa04bda00bd5ec

It's sort of a stopgap, but apparently GNOME requires special handling that is not compatible with some other DEs/WMs.

So GNOME users with GTK3 builds should set this new variable to either resize-mode and restart (better behavior but not future-compatible) or hide (which is more future-proof but will blink the child frame every time it's resized).

In other news, the Lucid build should be at least as fast now (or faster) WRT to child frames. So using basically any other build than GTK3 is also a good workaround.

@dgutov
Copy link
Contributor

dgutov commented Apr 6, 2020

@tumashu Will you add that info to README? Here, and/or in the main posframe repo.

@andreyorst
Copy link

This is great news! I think @casouri will be interested in adding this info to README as well

IIUC @dgutov patch was merged and available on master right now?

@dgutov
Copy link
Contributor

dgutov commented Apr 6, 2020

It's in the release branch now. Should be merged to master in a few days or so.

@casouri
Copy link

casouri commented Apr 6, 2020

Good, I'll add it to eldoc-box's readme.

tumashu added a commit to tumashu/posframe that referenced this issue Apr 7, 2020
@tumashu
Copy link
Owner

tumashu commented Apr 7, 2020

@dgutov Info has been added, thanks very very very much for your and Martin Rudalics hard word, if no your long disscuss and coding, this problem can not be resolved.

@dgutov
Copy link
Contributor

dgutov commented Apr 7, 2020

@tumashu IIUC, Mate users don't need to do this. Otherwise, the instructions look good, thanks.

@dgutov
Copy link
Contributor

dgutov commented Apr 7, 2020

By the way, we could try to automate this.

@andreyorst Could you check the output of echo $XDG_CURRENT_DESKTOP when inside a Mate session? Does it also say GNOME?

@andreyorst
Copy link

By the way, we could try to automate this.

@andreyorst Could you check the output of echo $XDG_CURRENT_DESKTOP when inside a Mate session? Does it also say GNOME?

Unlikely. Unfortunately I don't use Mate, I'm on GNOME. I'll ask colleague to check, but IDK when he'll respond.

@tumashu
Copy link
Owner

tumashu commented Apr 7, 2020

@dgutov I have not test it by myself, but MATE is gnome2,its wm may very similar with gnome3's vm, so it may have similar problem too.

@dgutov
Copy link
Contributor

dgutov commented Apr 7, 2020

According to @andreyorst it's using Metacity, a different window manager, and it doesn't have this problem: #2 (comment)

@tumashu
Copy link
Owner

tumashu commented Apr 8, 2020

OK, I will remove MATE info

@tumashu
Copy link
Owner

tumashu commented Apr 8, 2020

@dgutov After x-gtk-resize-child-frames set, we must restart emacs ?

@dgutov
Copy link
Contributor

dgutov commented Apr 8, 2020

You actually need to just create a new child frame (the resize-mode value only affects new child frames).

Anyway, please wait a little for my PR. I think we really can automate this, to make it easier for a lot of users.

@tumashu
Copy link
Owner

tumashu commented Apr 8, 2020

ok

dgutov added a commit to dgutov/posframe that referenced this issue Apr 8, 2020
Allows us to bind x-gtk-resize-child-frames to an appropriate value
requiring no user intervention.

Discussion at tumashu/company-posframe#2.
Fixes tumashu#51.
@dgutov
Copy link
Contributor

dgutov commented Apr 8, 2020

@andreyorst

If possible, please also ask a colleague to try this:

(let ((id (x-window-property "_NET_SUPPORTING_WM_CHECK" nil "WINDOW" 0 nil t)))
  (x-window-property "_NET_WM_NAME" nil "UTF8_STRING" id nil))

Which is a method we might choose to switch to in the future.

@andreyorst
Copy link

@andreyorst

If possible, please also ask a colleague to try this:

(let ((id (x-window-property "_NET_SUPPORTING_WM_CHECK" nil "WINDOW" 0 nil t)))
  (x-window-property "_NET_WM_NAME" nil "UTF8_STRING" id nil))

Which is a method we might choose to switch to in the future.

unfortunately he's working from home right now using his Mac, so he can't access mate right now. He's not Emacs user, so I can't help with that test much.

@dgutov
Copy link
Contributor

dgutov commented Apr 8, 2020

That's ok, thanks.

@andreyorst
Copy link

andreyorst commented Apr 9, 2020 via email

@dgutov
Copy link
Contributor

dgutov commented Apr 9, 2020

Thank you. Then the current solution in posframe should work all right.

@andreyorst
Copy link

It seems that changes finally hit the master branch and I no longer need to patch my build! Gonna say that everything works great on GNOME now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants