omegaui / app_fleet

A brilliant workspace manager & launch automation tool specially designed for GNOME.
https://omegaui.github.io/app_fleet_webpage
BSD 3-Clause "New" or "Revised" License
107 stars 3 forks source link

Ability to Set Custom App Window Sizes #1

Open omegaui opened 11 months ago

omegaui commented 11 months ago
omegaui commented 11 months ago

I need to implement a feature in the next major release of App Fleet, which is to provide the users with the ability to set the size of their apps which they want to launch, moreover it should also provide an alternative tiling option.

To achieve it,

this can easily be achieved by

app-binary &
echo "$!"

looks easy, but there are some complications to make this actually implementable for App Fleet.

As we know, App Fleet is written in a high level language i.e, dart, thus, it cannot directly launch an application, instead it uses the unix-process-executor.sh script that it writes during startup.

Now, that script's sole purpose is to create a new bash environment, start the app in that environment.

#!/bin/bash

executable=$1
shift;
args=$@

bash -lic "$executable $args"

now, using even the & and $! in this case, will not give the process id of the app but of the bash environment itself, also, reading this through streams isn't a good way to do it and is highly experimental.

Well, supposing that this could be figured out.

There seems to be a solution for this on Stack Overflow,

#!/bin/sh

findpid=$1

known_windows=$(xwininfo -root -children|sed -e 's/^ *//'|grep -E "^0x"|awk '{ print $1 }')

for id in ${known_windows}
do
    xp=$(xprop -id $id _NET_WM_PID)
    if test $? -eq 0; then
        pid=$(xprop -id $id _NET_WM_PID|cut -d'=' -f2|tr -d ' ')

        if test "x${pid}" = x${findpid}
        then
            echo "Windows Id: $id"
        fi
    fi
done

the above script list all the window ids associated with the process id.

an example usage:

find-windows.sh 17183

Now, it list all the window ids associated with the process, but a process doesn't actually shows all of its windows that we get in this list.

Now, the next step is to figure out which window ids are actually visible on desktop, this can be done by matching these ids with the output of wmctrl -l, seems beautiful, but this solution is very compositor specific.

So, wmctrl is actually designed to be used in an X11 session, whereas most of the linux distributions have accepted Wayland as their default window compositor. Thus, wmctrl doesn't actually detects all the visible windows like window created by the process nautilus.

but there exists a Wayland specific tool that seems to be an alternative for wmctrl called wlrctl by brocellous.

again, supposing that we are able to find the exact window then, we are good to implement this feature.

This comment is to give a brief summary for anyone wanting to contribute.