awesome icon indicating copy to clipboard operation
awesome copied to clipboard

Add client move global by direction

Open darrenswhite opened this issue 7 years ago • 10 comments

Similar to how awful.client.focus.global_bydirection and awful.client.swap.global_bydirection work except for moving a client in a given direction. This would be nice to have if possible! Thanks.

darrenswhite avatar Oct 15 '18 17:10 darrenswhite

Here you go https://github.com/elv13/collision

  • Select clients by direction
  • Move clients by direction
  • Move floating clients by relative offset
  • Select screens by direction
  • Select tag by direction
  • Move tag by direction

Elv13 avatar Oct 15 '18 17:10 Elv13

i think it could be done as client:move_to_screen_bydirection as a counterpart to existing client:move_to_screen but i am running single-screen setup now so can't play with it

actionless avatar Oct 16 '18 03:10 actionless

In that case it would be swap_by_direction, but it has some issues and isn't such a good idea because of floating vs. tiled clients.

If you implement a trivial swap by direction and the next client is floating and the origin isn't, you only have bad choice. Either you blindly swap them and it doesn't work. Either you make the target tiled and the origin floating, in which case you probably made your calculator or popup tiled by accident or you do nothing and it's confusing.

It's better to keep separate logic for floating and tiled clients when it comes to swapping. So a global method on the client isn't gonna work.

Elv13 avatar Oct 16 '18 03:10 Elv13

but move_to_screen is not swap, move means what the client just goes away from this screen to some other

actionless avatar Oct 16 '18 04:10 actionless

Ah, yeah, we could have that one. I always wanted to add move iterators and navigation methods to the screens to handle geometric navigation and iteration (from left to right, right to left, top to bottom, bottom to top) but I never did.

Elv13 avatar Oct 16 '18 04:10 Elv13

but such kind of code should already reside in *_global_bydirection helpers, so mb it could be extracted and re-used?

actionless avatar Oct 16 '18 04:10 actionless

It is in gears.geometry.rectangle.get_in_direction. However given the rarely changing screen layouts, it may be worth it to cache the result and daisy-chain the screens (internally, in Lua). Then add myscreen.left/right/up/down properties. However, as I said, it's only safe to do this for screens. Client and tags have many corner case that makes such accessors useless in practice.

Elv13 avatar Oct 16 '18 04:10 Elv13

I think client:move_to_screen_bydirection which @actionless suggested would work for me.

darrenswhite avatar Oct 20 '18 11:10 darrenswhite

Any updates on this? Just spent half an hour to implement this behaviour in my crappy lua:-

awful.key({ modkey, "Shift"   }, "u",
          function (c)
              local geo = c.screen.geometry
              if geo.x > 0 then
                  c:move_to_screen(c.screen.index-1)
              end
          end,
          {description = "move to screen on left", group = "screen"}),
awful.key({ modkey, "Shift"   }, "i",
          function (c)
              local geo = c.screen.geometry
              local width = root:size(1)
              if geo.x + geo.width < width then
                  c:move_to_screen()
              end
          end,
          {description = "move to screen on right", group = "screen"}),

ngoonee avatar Jun 24 '20 09:06 ngoonee

Can be done like this:

    awful.key({ modkeyWin,   "Shift", }, "j", 
              function (c)
                  local nScreen = c.screen:get_next_in_direction("left");
                  c:move_to_screen(nScreen.index)
              end, {description = "move to next screen", group = "client"}),
    awful.key({ modkeyWin,   "Shift", }, "k",        
              function (c)
                  local nScreen = c.screen:get_next_in_direction("right");
                  c:move_to_screen(nScreen.index) 
              end,
              {description = "move to prev screen", group = "client"}),

kandrelczyk avatar Sep 05 '25 06:09 kandrelczyk