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).