See here for the wiki.ubuntu.com entry on xrandr and how to use it. Basically run xrandr from the terminal and copy the output to create a .xprofile file in your home directory - my .xprofile reads as follows (I have a 1680x1050 monitor connected on VGA1):
xrandr --output VGA-1 --mode 1680x1050
Make the .xprofile file executable then log out and back in again.
You can use the following python script to start your application at a given resolution:
#!/usr/bin/env python3
import argparse
import re
import subprocess
import sys
parser = argparse.ArgumentParser()
parser.add_argument('--output', required=True)
parser.add_argument('--resolution', required=True)
parser.add_argument('APP')
args = parser.parse_args()
device_context = '' # track what device's modes we are looking at
modes = [] # keep track of all the devices and modes discovered
current_modes = [] # remember the user's current settings
# Run xrandr and ask it what devices and modes are supported
xrandrinfo = subprocess.Popen('xrandr -q', shell=True, stdout=subprocess.PIPE)
output = xrandrinfo.communicate()[0].decode().split('\n')
for line in output:
# luckily the various data from xrandr are separated by whitespace...
foo = line.split()
# Check to see if the second word in the line indicates a new context
# -- if so, keep track of the context of the device we're seeing
if len(foo) >= 2: # throw out any weirdly formatted lines
if foo[1] == 'disconnected':
# we have a new context, but it should be ignored
device_context = ''
if foo[1] == 'connected':
# we have a new context that we want to test
device_context = foo[0]
elif device_context != '': # we've previously seen a 'connected' dev
# mode names seem to always be of the format [horiz]x[vert]
# (there can be non-mode information inside of a device context!)
if foo[0].find('x') != -1:
modes.append((device_context, foo[0]))
# we also want to remember what the current mode is, which xrandr
# marks with a '*' character, so we can set things back the way
# we found them at the end:
if line.find('*') != -1:
current_modes.append((device_context, foo[0]))
for mode in modes:
if args.output == mode[0] and args.resolution == mode[1]:
cmd = 'xrandr --output ' + mode[0] + ' --mode ' + mode[1]
subprocess.call(cmd, shell=True)
break
else:
print('Unable to set mode ' + args.resolution + ' for output ' + args.output)
sys.exit(1)
subprocess.call(args.APP, shell=True)
# Put things back the way we found them
for mode in current_modes:
cmd = 'xrandr --output ' + mode[0] + ' --mode ' + mode[1]
subprocess.call(cmd, shell=True)
Save the above script (e.g as my-script.py
) and make it executable:
chmod +x my-script.py
To set a resolution of 1280x1024
and start gedit
just type:
./my_script.py --output VGA1 --resolution 1280x1024 gedit
To avoid typing this command everytime, save the script in your home directory and add the following lines to your .bashrc
:
alias my_bracket='~/my_script.py --output VGA1 --resolution 1280x1024 gedit'
Or even better, modify the desktop file that the package installs in /usr/local/share/applications/brackets.desktop
.
sudo gedit /usr/local/share/applications/brackets.desktop
And replace the file content with the new lines below:
[Desktop Entry]
Name=Brackets
Type=Application
Categories=Development
Exec=/home/mushir/my_script.py --output VGA1 --resolution=1280x1024 /opt/brackets/brackets
Icon=brackets
MimeType=text/html;
Keywords=Text;Editor;Write;Web;Development;
Source: Checkbox xrandr_cycle script
Best Answer
OK, it looks like I solved this problem, somehow or other. Here's what I did:
cmd
prompt, I ran:C:\>cd "c:\Program Files\Oracle\VirtualBox"
C:\Program Files\Oracle\VirtualBox>VboxManage setextradata "<vmname>" "CustomVideoMode1" "1280x800x16"
(Of course, replace
<vmname>
with the actual name of your vm, and replace the resolution spec string with the appropriate one for your monitor. Also note that the last character in the argumentCustomVideoMode1
is the digit 1, and not the letter "l". With some fonts the two characters are practically indistinguishable. BTW, more custom models can be specified, using a similar command, with arguments of the formCustomVideoMode2
,CustomVideoMode3
, and so on up to, I believe,CustomVideoMode16
.)System Settings > Displays
);System Settings > Additional Drivers
, selected the optionOracle VM VirtualBox Guest Additions for Linux Module
, and clicked onActivate
;When the VM came back up, the resolution was the correct one; furthermore, now the resolution options available through System
Settings > Displays
include one additional option "1280 x 800 (16:10)" (it is, of course, the currently active one).I can't tell whether running
VBoxManage setextradata ...
(steps 1 & 2 above) made any difference. IOW, steps 4 & 5 may very well have done the trick.Also, note that the
Oracle VM VirtualBox Guest Additions for Linux Module
was not activated even though I had previously runDevices > Install Guest Additions...
at the VirtualBox control panel.