libui icon indicating copy to clipboard operation
libui copied to clipboard

Add way to set and get windows position

Open jhert0 opened this issue 6 years ago • 10 comments

It would be nice to be able to set and get the coordinates of the window.

jhert0 avatar Apr 27 '18 22:04 jhert0

This was present at one point, but I removed it, because on X11 there is no way to do either of these things except asynchronously (unless it is and GTK+ simply doesn't provide the API), and on Wayland it isn't really possible at all (intentionally). That's an oversimplification, of course, but alas. The uiArea function to begin a window move event by the user is the closest I can make, and that is already there.

If you have better ideas I will be glad to hear them, though you will want to scour the issue tracker for the past discussions first.

andlabs avatar Apr 27 '18 23:04 andlabs

Some past discussions: https://github.com/andlabs/libui/issues/154, https://github.com/andlabs/libui/issues/183, https://github.com/andlabs/libui/issues/127#issuecomment-231090316

mischnic avatar Apr 29 '18 10:04 mischnic

Would it be an option to readd this functionality (including centering) for the platforms where it works in a way it does not lead people to expect it to work where it doesn't? Window positioning is a pretty big deal for user experience and conformity with user expectations – sacrificing it for all platforms because a single one makes trouble is a bit of a loss. (disregard that realistically, 90% of end-users will be on Windows anyway) Specifically, windows popping up at (0, 0) in the top-left corner gives off strong vibes of a makeshift solution.

MMulthaupt avatar Jan 10 '19 10:01 MMulthaupt

That sounds like you're asking about the position a window is in when it first appears on screen. What algorithm were you planning on using for that? Both Windows and GTK+ provide the algorithm for you, and on OS X I just need to make sure the window is centered when created...

andlabs avatar Jan 10 '19 13:01 andlabs

In my specific case, I'd like to be able to have them centered (regardless of platform, where possible). Other configurations can make sense, however; e.g. remembering position and size from the last time the application ran. I am aware Windows and GTK have their own ideals/defaults here. Just saying that that is not necessarily the desired behavior at all times. In case of effort vs. use of course, there are certainly more pressing needs regarding windows, e.g. being able to restrict resizing and maximizing and setting the titlebar icon.

MMulthaupt avatar Jan 10 '19 16:01 MMulthaupt

restrict resizing

-> #316

mischnic avatar Jan 10 '19 17:01 mischnic

image

It would be nice for my windows to not all open in this fashion. (Every single window I open is like that.)

Please at least click the merge button on #271, though centering might be better imho

LoganDark avatar Aug 23 '20 15:08 LoganDark

This was present at one point, but I removed it, because on X11 there is no way to do either of these things except asynchronously (unless it is and GTK+ simply doesn't provide the API), and on Wayland it isn't really possible at all (intentionally).

unless i'm misunderstanding something, gtk provides the gtk_window_move function which does this natively. setting window positions seems to be perfectly do-able in x11 provided that the window manager supports it, and from what i've read wayland the wayland protocol supports it via an extension, so all wayland compositors that implement the extension would support window movement

i don't currently have a dev machine set up, but i'll try and get a proof of concept going when i have the time

ghost avatar Sep 28 '20 01:09 ghost

i can confirm that the following function works fine in x, but does absolutely nothing in GNOME's wayland compositor

void uiWindowMove(uiWindow *w, int x, int y) {
    gtk_window_move(w->window, x, y); 
}

i still think it would be nice to have, for the places that support it. i've got a usecase that's going to need some ugly hacks without that function

ghost avatar Sep 28 '20 03:09 ghost

gtk_window_move() operates asynchronously, as I mentioned. I'm not even sure it can be used in Wayland either, but it's been a while since I last brought it up.

andlabs avatar Sep 29 '20 22:09 andlabs