Ubuntu Terminal Default Positions

As many of you know, whenever you open a new terminal window on Ubuntu it gets located in the upper left part of the screen. The next one is located right below it. The third one is in the upper right, the fourth one in the bottom right part of the screen. I want to add that functionality to another Linux distribution which I'm using now. I just want to know how this is handled in Ubuntu.

Also that doesn't only work with gnome-terminal. It works with any terminal emulator that I've downloaded so far. So I highly think it's not an issue specific to the terminal emulator. Does anyone know how this is handled?


RECOMMENDATION

I would recommend that you learn the tool you will be moving to. Almost all terminals have some sort of config file such as alacritty. That said, here are a few "tricks" which I've happened upon along the way."

HOW I DO IT

When you launch a terminal, there is an option which lets you set both it's size and it's X and Y offsets.

The option is --geometry, and it is available on many (most?) linux terminal emulators. Gnome terminal is no exception. As for an always solution, some developers just don't take the time to build in extra programmer/ superuser automation hooks..

The syntax to use the geometry option with our terminal is as follows:

$ gnome-terminal --geometry WxH+X+Y

Note that in the argument string, everything but the capitals is to be interpreted literally. The caps represent width measured in columns, Height measured in rows, and X & Y offsets from screen position (0,0).

I used to write out an command to save it to $HOME,the save to ~/.bashrc, which persists it. This is an idea I believe I got from this same site a long time ago, but now I use a method of my own devising when I need to script a script the functionality.

As a quick side-note: If i am changing myself in Ubuntu, I just create (or change to) another terminal profile. Each new l profile you make in the terminal gui "preferences" settings lets you specify the terminal's b-g color, transparency, etc. along with the previously mentioned settings.

I will also open vim and print the above command to a single line. Next, I will copy it vertically as many times as needed and configure each to a convenient size / position.

Finally I open a split with ~/.bash-aliases loaded to it's buffer and set an alias for each instance of the command.

Then I can just put a 3-4 letter name, like maybe midl in each time I need a guit terminal new process to launch in the middle of the screen.


Thank you Nate. I used the idea you gave me and came up with that script that solves my problem. It's a python script that's specifically designed for my resolution which is 1920x1080. It also depends on a tool called wmctrl. Here is the script:

#!/usr/bin/python3

import os


def eliminate(iter):
    res = []
    for i in iter:
        if i:
            res.append(i)
    return res


workspace = "wmctrl -d | grep '*' | cut -d ' ' -f1 > /tmp/curr_ws"

os.system(workspace)
out_workspace = ""
with open("/tmp/curr_ws","r") as f:
    out_workspace =  f.read()
out_workspace = int(out_workspace)
print("DEBUG: Current workspace:", out_workspace)

positions = 'wmctrl -lG | grep "kali:" | grep "^........... {0}" | tr -s " " | cut -d " " -f 3,4 > /tmp/positions'.format(out_workspace)
sizes = 'wmctrl -lG | grep "kali:" | grep "^........... {0}" | tr -s " " | cut -d " " -f 5,6 > /tmp/sizes'.format(out_workspace)

os.system(positions)
out_positions = ""
with open("/tmp/positions","r") as f:
    out_positions =  f.read()
out_positions = eliminate(out_positions.split("\n"))

os.system(sizes)
out_sizes = ""
with open("/tmp/sizes","r") as f:
    out_sizes = f.read()
out_sizes = eliminate(out_sizes.split("\n"))

terminal_positions = [[110, 101, 854, 479], [973, 101, 854, 479], [110, 611, 854, 479], [973, 611, 854, 479]]
terminal_strings = ["gnome-terminal --geometry 105x25+100+45", "gnome-terminal --geometry 105x25+963+45",
                    "gnome-terminal --geometry 105x25+100+555", "gnome-terminal --geometry 105x25+963+555"]

parsed_positions = []
for i in range(0,len(out_positions)):
    parsed_positions.append([ int(out_positions[i].split(" ")[0]),int(out_positions[i].split(" ")[1]),int(out_sizes[i].split(" ")[0]),int(out_sizes[i].split(" ")[1]) ])
print("DEBUG: Positions:", parsed_positions)

def check(term_pos, parsed_pos):
    index = 0
    overlap = False
    for i in terminal_positions:
        overlap = False
        for j in parsed_positions:
            ax0 = term_left_start = i[0]
            ay0 = term_up_start = i[1]
            ax1 = term_left_end = i[0] + i[2]
            ay1 = term_up_end = i[1] + i[3]
            
            bx0 = pars_left_start = j[0]
            by0 = pars_up_start = j[1]
            bx1 = pars_left_end = j[0] + j[2]
            by1 = pars_up_end = j[1] + j[3]

            # if term_left_start >= pars_left_end or term_left_end <= pars_left_start or term_up_end <= pars_up_start or term_up_start >= pars_up_end:
            #     overlap = True

            if ((bx0 <= ax0) and (ax1 <= bx1)) or ((ax0 <= bx0 <= ax1) and (ax1 <= bx1)) or ((ax0 >= bx0) and (ax1 >= bx1 >= ax0)) or ((ax0 <= bx0 <= ax1) and (ax1 >= bx1 >= ax0)):
                if ((by0 <= ay0) and (ay1 <= by1)) or ((ay0 <= by0 <= ay1) and (ay1 <= by1)) or ((ay0 >= by0) and (ay1 >= by1 >= ay0)) or ((ay0 <= by0 <= ay1) and (ay1 >= by1 >= ay0)):
                    overlap = True

        if overlap:
            index += 1
        else:
            return index


    return -1


place = check(terminal_positions, parsed_positions)

if place == -1:
    os.system("gnome-terminal")
else:
    os.system(terminal_strings[place])

You have to include the location of the script in your PATH variable then assign a shortcut to a command that executes the script