2

I am using Ubuntu 18.10.

I am trying to create two aliases in my .bashrc for commands to "resdown" and "resup" (i.e. decrease and increase my screen resolution respectively).

The resdown command is as follows, and works just fine:

xrandr --output DP-2 --mode 3840x2160

The issue I have is with resup. When I run the following:

xrandr --output DP-2 --mode 3840x2160

The UI scaling is set back to 100%. I need to change the scaling to 200%, or everything on my 4K display is incredibly small.

I have been experimenting with the "--scale" option for xrandr, but it entirely screws up my display. As such, I am not sure that it is doing what I think it is doing:

xrandr --output DP-2 --mode 3840x2160 --scale 2x2

If I used my second monitor to go back into gnome-control-center, I can set the screen resolution and scaling just fine, and everything goes back to normal. I want, however, to do this from the command line.

Basically - I want to know how to set the "Scale" setting that you see in gnome-control-center (see below) from the command line. How can I do this?:

enter image description here

  • RESUP and RESDOWN both use --mode 3840x2160 ? – Richard Cooke Nov 9 '18 at 20:49
  • You're right. I have made an error. The resdown resolution should be lower. I will edit this when I am next at my computer. My main question though is about adjusting the scaling from the command line. Thanks. – Lewis Nov 10 '18 at 10:12
  • I'm having my own struggles with 18.10: askubuntu.com/questions/1090518/… In my case, I cannot use xrandr at all, any attempt to SET anything kills both monitors! I have since switched that machine to a different desktop (gear icon at login) and that seems to have worked around my problem. Doing some digging, it seemed for the setup we have, Xrandr might be the wrong method. It seems PGM3 is in charge. – Richard Cooke Nov 12 '18 at 15:17
  • One idea I have: Run xrandr by itself to see what displays and modes it detects, and what the current mode is. Especially before and after you change it from the GUI panel. See if (a) the device name is not what you thought, or (b) the mode setting is not what your using. – Richard Cooke Nov 12 '18 at 15:22
  • Change Scale from 100% to 300% with a shortcut? The modern scale interface seems to have no gsettings equivalent :/ how can I change Scale configuration with a terminal script so that I can do it with a shortcut and change from desktop monitor mode to lean back couch mode :) – Ray Foss May 11 at 14:39
1

Tl;Dr:
sed -i -e '/<scale>/ s/1/2/' ~/.config/monitors.xml && sudo systemctl restart gdm

Mutter does listen to some settings in Gsettings, and after looking at the code, there is some legacy gsettings support for deprecated settings like gsettings ui-scaling-factor. For other things, it supports using XML for configuration. You'll probably need to Alt+F2, r to restart gnome-shell for settings to apply... or figure out the dbus details from the code.

Here is my config for an old monitor... notice the line... easy to sed

~/.config/monitors.xml
<monitors version="2">
  <configuration>
    <logicalmonitor>
      <x>0</x>
      <y>0</y>
      <scale>1</scale>
      <primary>yes</primary>
      <transform>
        <rotation>upside_down</rotation>
        <flipped>no</flipped>
      </transform>
      <monitor>
        <monitorspec>
          <connector>HDMI-1</connector>
          <vendor>ACR</vendor>
          <product>V226HQL</product>
          <serial>T0WAA0072442</serial>
        </monitorspec>
        <mode>
          <width>1920</width>
          <height>1080</height>
          <rate>60</rate>
        </mode>
      </monitor>
    </logicalmonitor>
  </configuration>

I put together the codes above to do 200x. It works on wayland and X, but will log you out. If you can do ALt+F2,r, that would obviously be better... I tried doing it with a terminal command and just kept crashing gnome. Might use Robot.js or xdotool to send a restart command... like this

xdotool keydown alt && sleep 1 && xdotool key F2 keyup alt && sleep 1 && xdotool key r && sleep 1 && xdotool key KP_Enter

My full version for X11 swap-res.sh... this works on an ubuntu keyboard shortcut too

#!/bin/bash
File=~/.config/monitors.xml
if grep -q "<scale>1" "$File"; then
  sed -i -e '/<scale>1/ s/1/3/' "$File"
else
  sed -i -e '/<scale>3/ s/3/1/' "$File"
fi

# Unix Utils
xdotool keydown alt && sleep 1 && xdotool key F2 keyup alt \
  && sleep 1 && xdotool key r key KP_Enter

Source: https://gitlab.gnome.org/GNOME/mutter/ (quite literally, leave a star!)

SEO / Similar Questions:
Scaling Gnome login screen on HiDPI display
How do I use Mutter with GNOME Shell?
Changing UI scaling from command line

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.