Software & AppsOperating SystemLinux

How To Start an Application with a Pre-defined Window Size and Position in Ubuntu

Ubuntu 2

In this tutorial, we will cover how to start an application with a pre-defined window size and position in Ubuntu. This can be particularly useful if you have specific workspace layouts that you frequently use for different tasks.

Quick Answer

To start an application with a pre-defined window size and position in Ubuntu, you can use command-line options such as --geometry if the application supports it. Alternatively, you can use window management tools like wmctrl and xdotool to programmatically set the window size and position.

Prerequisites

Before we begin, ensure you have the following:

  • A working Ubuntu system
  • Basic knowledge of the command line
  • Access to a terminal

Method 1: Using Command-Line Options

Many applications in Ubuntu support the --geometry option. This allows you to specify the window size and position when launching the application.

The general syntax for the --geometry option is as follows:

application --geometry=WIDTHxHEIGHT+X+Y

In this command:

  • WIDTH and HEIGHT specify the window size
  • X and Y specify the window position

For example, to launch the Gnome Terminal with a window size of 800×600 pixels at the position (100, 100), you would use the following command:

gnome-terminal --geometry=800x600+100+100

Please note that not all applications support the --geometry option. You can check whether an application supports this option by running <application> --help in the terminal.

Method 2: Using Window Management Tools

If the application you want to launch does not support the --geometry option, you can use window management tools like wmctrl and xdotool. These tools allow you to manipulate windows programmatically.

Here is an example of how you can use wmctrl and xdotool to launch an application and set its window size and position:

  1. Install wmctrl and xdotool:
sudo apt install wmctrl xdotool
  1. Create a script that launches the application, waits for it to start, and then sets its window size and position:
#!/bin/bash
application &
sleep 1
wmctrl -r :ACTIVE: -e 0,100,100,800,600

In this script:

  • application & launches the application in the background
  • sleep 1 waits for one second to ensure the application has started
  • wmctrl -r :ACTIVE: -e 0,100,100,800,600 resizes and moves the active window

Replace application with the command to launch your desired application.

Conclusion

In this tutorial, we covered two methods to start an application with a pre-defined window size and position in Ubuntu. The first method uses the --geometry option that some applications support. The second method uses the wmctrl and xdotool window management tools.

Remember to adjust the commands and parameters according to your specific needs and desktop environment. With these tools and options at your disposal, you can create a more efficient and customized workspace in Ubuntu.

How do I check if an application supports the `–geometry` option?

To check if an application supports the --geometry option, you can run <application> --help in the terminal. This will display the available options for the application, including whether it supports --geometry.

Can I use the `–geometry` option to resize and position windows of any application?

No, not all applications support the --geometry option. It depends on how the application was developed. You can check if an application supports --geometry by running <application> --help in the terminal.

What if the application I want to launch does not support the `–geometry` option?

If the application you want to launch does not support the --geometry option, you can use window management tools like wmctrl and xdotool to programmatically resize and position the window. These tools allow you to manipulate windows even if the application itself does not have built-in support for it.

How do I install `wmctrl` and `xdotool`?

You can install wmctrl and xdotool by running the following command in the terminal: sudo apt install wmctrl xdotool. This will install both tools on your Ubuntu system.

How can I customize the script to launch and resize a specific application?

To customize the script to launch and resize a specific application, you need to replace the application placeholder with the command to launch your desired application. For example, if you want to launch Firefox, you would replace application with firefox in the script.

Can I use these methods to resize and position windows in other Linux distributions?

Yes, you can use these methods to resize and position windows in other Linux distributions as well. The --geometry option is supported by many applications across different distributions, and window management tools like wmctrl and xdotool are commonly available. However, the specific commands to install these tools may vary depending on the distribution.

Leave a Comment

Your email address will not be published. Required fields are marked *