0

I have the application Franz on my autostart list and it works fine. The problem is that it opens full screen whenever I boot into kubuntu. I'd rather it open in a minimized state so I don't have to manually close/minimize it every time. Can anyone provide a descriptive solution to this so that I can apply the same for some other apps that I want to autostart?

  • 1
    This (unaccepted anwser with no upvotes) may apply to you, even in the general case of other apps: https://askubuntu.com/questions/1181813/how-to-get-franz-messaging-app-start-minimized-and-with-window-along-the-right-e – Jos Oct 26 '23 at 10:08
  • Could you explain in a little more detail how I could extend this to other apps. I am not very familiar with shell scripting. – Sagnik Taraphdar Oct 26 '23 at 10:16
  • KDE supports "window rules". Right-click on the applications title bar and select "More Actions -> Special Application Settings …". There should be a minimize option as a rule. – Rinzwind Oct 26 '23 at 10:40
  • This is a how to on "window rules": https://www.maketecheasier.com/better-manage-application-windows-kde/#:~:text=To%20create%20rules%20for%20any,how%20useful%20the%20options%20are. I don't use kde that much so if someone wants to answer go for it ;) – Rinzwind Oct 26 '23 at 10:41

1 Answers1

0

As I understand it, the linked answer suggests you write a separate startup script for every app, and place it in ~/.bin. Call it login-myapp.sh.

The script starts with the command to start the app normally. For Franz that would be /opt/Franz/franz followed by an & to let it execute in the background. Replace this command with the normal startup command for the app.

"/opt/Franz/franz" &

It gives the app 3 seconds to start up and create a window:

sleep 3

Then it takes the width and height of the current monitor from xrandr: you can simply copy that.

# Get the WIDTH of screen
SWIDTH="$(xrandr | grep " connected" | grep "[0-9]x[0-9]"| cut -d ' ' -f 4 | cut -d '+' -f 1 | cut -d 'x' -f 1)"
# Get the HEIGHT of screen
SHEIGHT="$(xrandr | grep " connected" | grep "[0-9]x[0-9]"| cut -d ' ' -f 4 | cut -d '+' -f 1 | cut -d 'x' -f 2)"

Then it finds the window ID of the application's main window. You will need to start up the app normally and execute wmctrl -l in a terminal. You may need to install wmctrl first: it is a small standalone tool.

$ wmctrl -l

Then it is a matter of identifying the proper line. However, not all application windows are managed by the window manager. I have currently Firefox, Thunderbird, Libreoffice and Slack running on my system, but only Slack is returned. We take the line containing the app's name at the end (using grep) and from that line, only the first field, delimited by a space (using cut). The window handle is then put into the variable FWINDOW:

# Get the WINDOW ID of Franz
FWINDOW="$(wmctrl -l | grep " Franz$" | cut -d ' ' -f 1)"

For your app, you will need to replace Franz by whatever wmctrl returns at the end of the relevant line.

In the following steps, the app is aligned against the right hand side of the screen. You may omit these steps if you don't need that.

# Calculate the window LEFT position for 750px width
FLEFT="$(echo $(( $SWIDTH-750 )))"
# Calculate the window HEIGHT below a 22px top panel
FHEIGHT="$(echo $(( $SHEIGHT-22 )))"
# Move and resize Franz window as above
wmctrl -i -r $FWINDOW -e 0,$FLEFT,22,750,$FHEIGHT

Finally, the app's window is minimized:

# Close Franz window to system tray
wmctrl -ic $FWINDOW
exit 0

In the case of Franz this works because closing the window means minimizing Franz to the system tray. If this actually closes your app completely, you may minimize the window using

xdotool windowminimize $FWINDOW
exit 0

instead.

If your script login-myapp.sh works, the linked answer suggests you modify the .desktop file for your app, so that login-myapp.sh is used instead of the normal executable.

I got much of the information in this answer from this question: How to close, minimize, and maximize a specified window from Terminal?

Jos
  • 29,224