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

Window placement in floating mode #73

Closed
bklaase opened this issue May 25, 2016 · 14 comments
Closed

Window placement in floating mode #73

bklaase opened this issue May 25, 2016 · 14 comments

Comments

@bklaase
Copy link

bklaase commented May 25, 2016

Current strategy seems to be to place windows in the top left of the current monitor. While it was the easiest thing in the world to create a hook, and subsequently a script that gets triggered on windows with certain conditions (i.e. no size hints for location), that centres the window, this has a disadvantage. When I do this there is an almost unnoticeable movement before the window moves to the centre of the monitor. With a compton fade effect not so much noticable, without it, it looks quite clunky. Would it be possible (maybe in next release) to implement placement strategy natively in the WM ?

Possible values could be:

  • Centre (or center, I never know.. [1])
  • Corner (all of them)
  • Smart (I never use this, and never will :) )
@blairdrummond
Copy link

I found that this centers the windows in floating mode, and they behave appropriately when dragged. I don't know this code very well though, so perhaps this will cause other issues. If someone implemented a way to specify "floating_mode (center|corner)" as you suggest, then I think that this might be a really simple fix.

// clientlist.cpp
void client_resize_floating(HSClient* client, HSMonitor* m) {
    // ...
    Rectangle rect = client->float_size;

    + rect.x += (m->rect.width - rect.width)/2;
    + rect.y += (m->rect.height - rect.height)/2;

    rect.x += m->rect.x;
    rect.x += m->rect.y;
    // ...

I have tested this only on a basic one monitor setup.

@t-wissmann
Copy link
Member

Right now, hlwm positions a new floating window the way the window itselfs suggests it. That's why terminal windows are placed in the top right corner and other windows in the monitor center.

But it's a todo for me to have this overwritable by rules.

@bklaase
Copy link
Author

bklaase commented Aug 22, 2016

Alright, thank you both for replying. :) I might have a go at this myself and make a pull request.

@bklaase
Copy link
Author

bklaase commented Jan 11, 2017

@blairdrummond, because of your post I was motivated to try this solution. It does work somewhat in a one monitor scenario, but resizing starts behaving very weirdly (resizing from window center, instead of upper left corner, etc). In a multi monitor setup, it only functions on the primary monitor.

I did however find what I think is the way to fix this. Perhaps @t-wissmann, can spot some suble mistake, but I run this now on a multi-monitor setup, without any problems

I place it here, so that people annoyed by this behaviour can patch the 7.0 release and move on with their lives, whilst waiting for WinterBreeze

--- a/src/clientlist.cpp
+++ b/src/clientlist.cpp
@@ -239,9 +239,27 @@ HSClient* manage_client(Window win) {
     int x, y;
     unsigned int w, h;
     XGetGeometry(g_display, win, &root_win, &x, &y, &w, &h, &border, &depth);
-    // treat wanted coordinates as floating coords
-    client->float_size.x = x;
-    client->float_size.y = y;
+    // treat wanted coordinates as floating coords but center otherwise
+
+       //monitor dims
+       int mw = m->rect.width;
+       int mh = m->rect.height;
+       //padding values
+       int pl = m->pad_left;
+       int pr = m->pad_right;
+       int pu = m->pad_up;
+       int pd = m->pad_down;
+
+       if(x == 0 && w <= mw)
+               client->float_size.x = (mw-(pl+pr)-w)/2;
+       else
+               client->float_size.x = x;
+
+       if(y == 0 && h <= mh)
+               client->float_size.y = (mh-(pu+pd)-h)/2;
+       else
+               client->float_size.y = y;
+
     client->float_size.width = w;
     client->float_size.height = h;
     client->last_size = client->float_size;

@imtbl
Copy link

imtbl commented Jul 10, 2020

But it's a todo for me to have this overwritable by rules.

This issue is quite old and I can't find anything in the docs. Are there any updates on this?

I open quite a few CLI programs via click actions in my Polybar:

I've set a rule: hc rule class='float' floating=on
And the Polybar click action: click-left = kitty --class float -e htop

Right now they all open in the top left corner (due to them being launched inside a terminal emulator, I assume).

So I also think being able to set rules for the placement (e.g., hc rule class='float' placement=center) would be great.

@t-wissmann
Copy link
Member

But it's a todo for me to have this overwritable by rules.

This issue is quite old and I can't find anything in the docs. Are there any updates on this?

No, sorry for letting you wait!

So I also think being able to set rules for the placement (e.g., hc rule class='float' placement=center) would be great.

Yes, placement=center is a perfect name for this. Please keep reminding me of this because this is really an issue/missing feature that should be fixed soon.

t-wissmann added a commit that referenced this issue Jul 13, 2020
This implements feature request #73 and adds a rule consequence
'placement' that updates the floating position of a client, possibly
overwriting the position requested by the client itself (which is not to
be trusted in most cases, or even is simply (0,0) for terminals).
mergify bot pushed a commit that referenced this issue Jul 22, 2020
This implements feature request #73 and adds a rule consequence
'floatplacement' that updates the floating position of a client, possibly
overwriting the position requested by the client itself (which is not to
be trusted in most cases, or even is simply (0,0) for terminals).
@blarz
Copy link
Contributor

blarz commented Jul 27, 2020

This can be closed with #957 being merged, right?

@bew
Copy link

bew commented Jul 27, 2020

#957 only implements none & center afaik, corners are not done yet (topleft, topright, bottomleft, bottomright), so I think this issue should be kept open until we're happy with the floatplacement values.

I think another useful one could be framecenter to place the window centered in the current frame.
(or even: frame:center, so we can have frame:topleft, etc...)

@t-wissmann
Copy link
Member

Do you really need the corners? I'm hesitating to implement (and to write tests for) something that only might be useful at some point in the future.

@bew
Copy link

bew commented Jul 30, 2020

Do you really need the corners?

I don't need the corners myself, it's just that it was mentionned by @bklaase in his first post of the issue, so I wanted to remind you about it!

However the framecenter option (or whatever the name) could be quite helpful in addition to center.

@bklaase
Copy link
Author

bklaase commented Jul 30, 2020

yeah, no to be honest I am very grateful for the feature as is, and the rest of my initial post is (in hindsight) just rambling ;)

I'll close this, for bookkeeping, sorry to have left it open :)

@bklaase bklaase closed this as completed Jul 30, 2020
@t-wissmann
Copy link
Member

yeah, no to be honest I am very grateful for the feature as is, and the rest of my initial post is (in hindsight) just rambling ;)

I'll close this, for bookkeeping, sorry to have left it open :)

I see! No Worries! :)
Btw I find that 'smart' is reasonable (and I wanted this feature for a very long time, now it's in #978), even though you didn't explicitly asked for this.

mergify bot pushed a commit that referenced this issue Aug 2, 2020
This adds a new option 'smart' for the rule consequence floatplacement.
It tries to place the floating window with as little overlap to other
floating windows as possible. Beside documentation, this also adds
test cases.

Smart window placement is quite hard to test, so I have two test cases
that actually verify the window positions, and one test case that only
adds a bunch of clients without verifying anything (not contributing to
code coverage).

This has been requested in #73.
@Piping
Copy link

Piping commented Oct 24, 2020

is this feature available in v0.8.3?

@t-wissmann
Copy link
Member

is this feature available in v0.8.3?

No, you need the current git-version for this feature, @Piping

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

7 participants