The i3 FAQ has migrated to https://www.reddit.com/r/i3wm/. All content here is read-only.
Ask Your Question
0

Moving relative to bottom/right of screen

asked 2013-10-30 02:41:54 +0000

jonlorusso gravatar image

I can currently move a container relative to the top/left (0, 0) of the screen:

move absolute position 0 0

Is it possible to refer to the bottom and/or right of the screen. Ideally, when moving a container relative to the bottom or right, it would be relative to the bottom and/or right of the window being moved.

I am reasonably sure this is not possible via any combination of built-in commands/options. Can anyone think of a way this can be scripted? Just thinking through it, I would need some way to access the size of the screen, and the size of the container being moved.

Thanks!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-10-30 08:10:40 +0000

Adaephon gravatar image

xdotool could help you with that.

Retrieving the Window ID of the currently active window

$ xdotool getwindowfocus
62914570

Getting the geometry of that window

$ xdotool getwindowgeometry 62914570
Window 62914570
  Position: 3520,472 (screen: 0)
  Geometry: 164x164

Or both commands rolled in one

$ xdotool getwindowfocus getwindowgeometry
Window 62914570
  Position: 3520,472 (screen: 0)
  Geometry: 164x164

Moving a given window arround, for example to position x,y = 123,456:

$ xdotool windowmove 62914570 123 456

Moving the current window to the same position:

$ xdotool getwindowfocus windowmove 123 456

The position is the position of the upper left corner of the window content, so there is some scripting to be done to take into account the window size when moving to the bottom or to the right in order to keep everything on screen. Parsing the output of xdotool shouldn't be to hard. Keep in mind that xdotool does not care for borders and titlebars, so you'll have to try around a bit, to keep them on screen.

As for the screen size. If you have just one display xdotool getdisplaygeometry should do the trick. Unfortunatelly this seems not to work with multiple displays as it still returns just the size of one display (All my displays are the same size so I cannot check easily if it always the current display or just broken). With multiple displays (especially with differing resolutions) you may have to parse the output of xrandr. Of course, if you are not in the habbit of changing display setups regularly, you could just hard code it in your script.

Please note that moving around windows with xdotool works only for floating windows, but nothing (including nothing bad) seems to happen when trying it on tiled windows.

You also could try to parse the output of 'i3-msg -t get_tree' (it's formatted in JSON) and move the window around with the build-in command. But I myself am a bit confused about the values I get there, as there seem to be several fields pertaining to window size and position. Here the relevant parts from the same window as above:

{
  "current_border_width": -1,
  "geometry": {
    "height": 164,
    "width": 164,
    "x": 0,
    "y": 0
  },
  "rect": {
    "height": 168,
    "width": 170,
    "x": 3515,
    "y": 471
  },
  "window": 62914570,
  "window_rect": {
    "height": 164,
    "width": 164,
    "x": 2,
    "y": 0
  }
}

As you can see, some values match up, some differ slightly (enough for the borders but not the title bar).

edit flag offensive delete link more

Comments

Thanks! This worked great.

jonlorusso gravatar imagejonlorusso ( 2013-10-30 12:01:30 +0000 )edit

Glad to hear. Maybe you could post your script. A few days ago there was a similar qestion, so there may be others interested in the solution.

Adaephon gravatar imageAdaephon ( 2013-10-30 12:33:45 +0000 )edit

Question Tools

Stats

Asked: 2013-10-30 02:41:54 +0000

Seen: 545 times

Last updated: Oct 30 '13