I'm running 64-bit ubuntu 14.04. I'm experiencing a problem that started just a few days ago: every now and then, on reboot, my screen resolution is too narrow, with black unused screen space to the left and right. The pointer tends to flicker when this happens. I'm able to fix it by rebooting, which works more or less randomly (it might take several reboots).
When the problem occurs, the resolutions listed under Settings > Displays are 800x600 (4:3) and 1024x768 (4:3). The correct resolution of 1366x768 (16:9) does not appear.
Strangely, the login screen is displayed correctly (i.e. full-width resolution, taking up the entire screen) -- the problem only appears after I log in.
Why does this happen? Why did it only start a few days ago, when I've had 14.04 on this laptop for years? What can I do to make it go away?
Edit: here is the output from xrandr in the good state (i.e. when there is no resolution problem):
Screen 0: minimum 320 x 200, current 1366 x 768, maximum 32767 x 32767
LVDS1 connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 293mm x 164mm
1366x768 60.0*+
1360x768 59.8 60.0
1024x768 60.0
800x600 60.3 56.2
640x480 59.9
VGA1 disconnected (normal left inverted right x axis y axis)
HDMI1 disconnected (normal left inverted right x axis y axis)
DP1 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)
VGA-1-2 connected
1024x768 60.0
800x600 60.3 56.2
848x480 60.0
640x480 59.9
1024x768 (0x43) 65.0MHz
h: width 1024 start 1048 end 1184 total 1344 skew 0 clock 48.4KHz
v: height 768 start 771 end 777 total 806 clock 60.0Hz
800x600 (0x44) 40.0MHz
h: width 800 start 840 end 968 total 1056 skew 0 clock 37.9KHz
v: height 600 start 601 end 605 total 628 clock 60.3Hz
800x600 (0x45) 36.0MHz
h: width 800 start 824 end 896 total 1024 skew 0 clock 35.2KHz
v: height 600 start 601 end 603 total 625 clock 56.2Hz
Edit: I just rebooted into the bad state (narrow screen with black on each edge). Here's xrandr:
Screen 0: minimum 320 x 200, current 1024 x 768, maximum 32767 x 32767
LVDS1 connected primary 1024x768+0+0 (normal left inverted right x axis y axis) 293mm x 164mm
1366x768 60.0 +
1360x768 59.8 60.0
1024x768 60.0*
800x600 60.3 56.2
640x480 59.9
VGA2 disconnected (normal left inverted right x axis y axis)
HDMI1 disconnected (normal left inverted right x axis y axis)
DP1 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)
VGA-1-1 connected 1024x768+0+0 0mm x 0mm
1024x768 60.0*
800x600 60.3 56.2
848x480 60.0
640x480 59.9
1024x768 (0x43) 65.0MHz
h: width 1024 start 1048 end 1184 total 1344 skew 0 clock 48.4KHz
v: height 768 start 771 end 777 total 806 clock 60.0Hz
800x600 (0x44) 40.0MHz
h: width 800 start 840 end 968 total 1056 skew 0 clock 37.9KHz
v: height 600 start 601 end 605 total 628 clock 60.3Hz
800x600 (0x45) 36.0MHz
h: width 800 start 824 end 896 total 1024 skew 0 clock 35.2KHz
v: height 600 start 601 end 603 total 625 clock 56.2Hz
Edit: rebooted again and I'm back in the good state, no idea why...
Edit: the fix in the answer below worked for a while, but the issue occurred again today (for the first time in several weeks). I think it's related to accidentally hitting windowskey+P -- see How to stop Mod4-P from switching the display?.
Here's a screenshot showing the second, "bad" display: