In my current configuration, I have a dock (which shows application icons) on the left of the screen. I was wondering whether it is possible to move the dock to the top when the monitor is rotated 90 degrees (so to avoid narrowing down the width of the screen). Also, I want the dock to be back in the original position when I go back to the horizontal monitor orientation. Could someone help me do this?
Environment
I am running Ubuntu 18.04 and using the default gnome desktop environment. My computer is a 2-in-1 laptop which automatically rotates screen based on device orientation.
Current Attempt
I looked into possible gnome extensions that would do this, but Dash to Dock did not have such options.
Best Answer
We have to change approaches based on whether your computer comes with an accelerometer or not. If your computer comes with an accelerometer (usually a 2-in-1 laptop or a tablet), this can be completely automated by detecting screen orientation changes. Otherwise, creating a bash script to change the orientation and dock location at the same time would give you enough convenience.
Laptop with an Accelerometer
I wrote a python3 code that gets run on boot. The script listens to the screen rotation changes and changes the dock position accordingly.
chmod +x <filename>
command. If you saved your file in a directory owned by root in Step 2, you need to runsudo chmod +x <filename>
instead.Name:
<any>
Command:
<path to the file>
Comment:
<any>
Computer without an Accelerometer
This approach creates a bash script which needs to be executed when you want to change your display orientation.
Download Dash to Dock gnome extension. In my case, it did not need to be enabled, but it might be required.
With your favorite text editor, create a bash file called "drotate" (for dash rotate), put the following code, and save it.
Make the code executable by
chmod +x drotate
command. If you saved your file in a directory owned by root in Step 2, you need to runsudo chmod +x drotate
instead.Open
~/.bash
. Create a new line in the end of the file and paste the following line.export PATH="<path/to/the/directory/with/your/script>:$PATH
. For example, if you saved your file in/usr/local/drotate
, the command becomesexport PATH="/usr/local:$PATH
. Noticedrotate
being omitted.Save the file.
Either restart your terminal or run
source .bashrc
. They do the same thing. Now your script should be able to run.Usage
Open your terminal (Ctrl-Alt-t) and type
Examplesdrotate <rotation> [<display number>]
.drotate left
drotate normal
drotate left 2