graphics icon indicating copy to clipboard operation
graphics copied to clipboard

resize_window() not working properly

Open klartext opened this issue 6 months ago • 8 comments

Some first experiments allowed using resize_window to set sizes. But in my current code (even though I now commented out nearly anything) the function has no effect anymore. The window size, as reported by xprop, is 1024 x 768.

It's on Arch Linux, insallation is done via opam.

<><> graphics: information on all versions ><><><><><><><><><><><><><><><><><><>
name                   graphics
all-installed-versions 5.2.0 [default]
all-versions           4.08.1  5.0.0  5.1.2  5.2.0

<><> Version-specific details <><><><><><><><><><><><><><><><><><><><><><><><><>
version      5.2.0
repository   default
url.src      "https://github.com/ocaml/graphics/archive/refs/tags/5.2.0.tar.gz"
url.checksum "sha256=baa99f5316c26df0844ee68921f531e554aab7ea2a1c881f30bd8365309077b0"
             "sha512=3a9a534b438aff86fd7ac83b394ae118e79538dcce7787e587039310b6e8fd9b352cadd54392c6190bbf8127e227bcefec1902c714ed2dc987a6e5694170b6b4"
homepage     "https://github.com/ocaml/graphics"
bug-reports  "https://github.com/ocaml/graphics/issues"
dev-repo     "git+https://github.com/ocaml/graphics.git"
authors      "Xavier Leroy" "Jun Furuse" "J-M Geffroy" "Jacob Navia" "Pierre Weis"
maintainer   "[email protected]" "[email protected]"
license      "LGPL-2.1-only WITH OCaml-LGPL-linking-exception"
depends      "dune" {>= "2.7"}
             "dune-configurator"
             "conf-libX11" {os != "win32"}
             "conf-libXft" {os != "win32"}
             "conf-pkg-config" {os != "win32"}
             "ocaml" {>= "4.09.0~~"}
synopsis     The OCaml graphics library
description  The graphics library provides a set of portable drawing
             primitives. Drawing takes place in a separate window that is created
             when Graphics.open_graph is called.
             This library used to be distributed with OCaml up to OCaml 4.08.

Are there limits to the window-size, maybe dependent on certain environmental / X11 settings? I got no warning that would indicate a problem of some kind.

klartext avatar Aug 26 '25 02:08 klartext

It seems not to work if used directly after open_graph.

Using a wait_next_event [ Key_pressed ] before the resize_window and then the resizing works.

klartext avatar Aug 26 '25 02:08 klartext

What does not work:

  open_graph "";
  resize_window width height;
  set_window_title "mytitle";

...but what does work:

  open_graph "";                                               
  set_window_title "mytitle";                                                
  resize_window width height;

klartext avatar Aug 26 '25 20:08 klartext

Even when the size is changed with resize_window, xprop still reports program specified size: 1024 by 768 as part of WM_NORMAL_HINTS.

klartext avatar Aug 26 '25 20:08 klartext

I cannot reproduce. A simple open_graph ""; resize_window 200 300;; seems to work in the 5.3.0 toplevel (the window is resized).

nojb avatar Aug 26 '25 21:08 nojb

Using geometry settings as argument to open_graph sets the WM_NORMAL_HINTS so that two values show the new size: user specified size: 1200 by 1000 and program specified size: 1200 by 1000. So the resize_window function seems not to update these Window-Hints, what may cause the problems.

If these values are not set to the new value, as is happening as mentioned above, when using only the resize-function, then the window manager will make the window small again. after going from floating to tiling to floating again. I'm using i3 window manager, but have set the graphics-window to floating mode to exclude influence via tiling.

My impression is, that the missing size hints create the problems. Setting floating mode is done via the window title. If it is not known when the resizing-operation is asked for, the window might be created in tiling mode, when the name is set, the window will go into floating mode, and I guess the window size-hint is then evaluated to set the size of the window.

If the name is set before the resizing-function is called, the window is then in floating mode and the request for a different size is passed through, but otherwise maybe blocked?

If there is no reason to setting the window-hints by open_graph, but not updating them by resize_window, then adapting this here (so that resize_window updates these Window-Hints) might fix the issue.

... but I wonder why the waiting for an event has a similar effect. (timing issues also involved?)

klartext avatar Aug 26 '25 23:08 klartext

BTW: I compile to native code. At least for another issue (I hope to have time for opening it during the next days), this makes a difference.

klartext avatar Aug 26 '25 23:08 klartext

When using the following combination:

open_graph " 1600x800+50-0";                                                    
set_window_title "easy-graph";                                                  
resize_window 60 60;

the window will be set to a size of 60x60 (floating window), but after integrating it into tiling and moving it back to the floating, the size then is 1600x800. (Using i3.)

I think the same should happen with other window managers, when minimizing the window and then making it appearing again in it's "natural" size.

I guess the reason again is the WM-Window-Hint-Setting:

WM_NORMAL_HINTS(WM_SIZE_HINTS):
                user specified location: 50, 1356
                program specified location: 50, 1356
                user specified size: 1600 by 800
                program specified size: 1600 by 800

The 60x60 is not there.

klartext avatar Aug 27 '25 23:08 klartext

You're very likely right that resize_window should update WM hints. Would you like to give it a try? You seem to know a thing or two about X11 programming. A pull request would be very welcome.

xavierleroy avatar Sep 09 '25 09:09 xavierleroy