Friday, December 22, 2017

Make Intellij IDEA on Linux with sharp fonts as Macbook Pro

IntelliJ IDEA supports HiDPI on Windows and MacOS. The fonts look so beautiful on a Macbook Pro Retina Display. Unfortunately IDEA doesn’t support HiDPI on Linux. Looks at the code UIUtil#isJreHiDPIEnabled. For Linux, it always return false.
You can get that sharpness through VNC by changing to the larger font size. I’m using 2017.3.1
  • Settings -> Editor -> Color Shcema -> Color Scheme Font
    • Check “Use color scheme font instead of the default`
    • Change “Size” to 22
  • Settings -> Appearance & Behavior -> Appearance -> UI Options
    • Themes: Darcular
    • Check “Override default fonts by (not recommended):”
    • Name: Dialog and size to 22
HiDPI-profiles plugin may make switching between HiDPI and lower resolution easier.

How to make VNC sharp on Retina display.

Most of time, I work on a Linux box running CentOS 7 through VNC. The largest VNC screen size is 1920x1080 (16:9). It is ok when you maximize the RealVNC viewer window on an external monitor with that resolution. On my Macbook Pro, there are two black areas on top and bottom because the Retina display is 2880x1800 (16:10), and the font looks small and blurry. I have to switch VNC screen side to 1680x1050 (16:10), the font size is proper, but still blurry. How can I make VNC sharp as a native MacOS app?
First, create a larger screen on VNC as below, then you will have the same size VNC screen as Macbook Pro.
  • Create a modeline using cvt
  • Create a new mode using the modeline
  • Add the new mode
  • Switch to the new mode
  • Set screen DPI to 220, which is the DPI of Macbook Pro’s Retina Display
[bwang@bwang ~]$ cvt 2880 1800
# 2880x1800 59.97 Hz (CVT 5.18MA) hsync: 111.84 kHz; pclk: 442.00 MHz
Modeline "2880x1800_60.00"  442.00  2880 3104 3416 3952  1800 1803 1809 1865 -hsync +vsync
[bwang@bwang ~]$ xrandr --newmode "2880x1800_60.00"  442.00  2880 3104 3416 3952  1800 1803 1809 1865 -hsync +vsync
[bwang@bwang ~]$ xrandr
Screen 0: minimum 32 x 32, current 1680 x 1050, maximum 32768 x 32768
VNC-0 connected primary 1680x1050+0+0 0mm x 0mm
   1920x1080     60.00 +
   1920x1200     60.00  
   1600x1200     60.00  
   1680x1050     60.00* 
   1400x1050     60.00  
   1360x768      60.00  
   1280x1024     60.00  
   1280x960      60.00  
   1280x800      60.00  
   1280x720      60.00  
   1024x768      60.00  
   800x600       60.00  
   640x480       60.00  
  2880x1800_60.00 (0x29f) 442.000MHz -HSync +VSync
        h: width  2880 start 3104 end 3416 total 3952 skew    0 clock 111.84KHz
        v: height 1800 start 1803 end 1809 total 1865           clock  59.97Hz
[bwang@bwang ~]$ xrandr --addmode 2880x1800_60.00
xrandr: --addmode requires two arguments
Try 'xrandr --help' for more information.
[bwang@bwang ~]$ xrandr --addmode VNC-0 2880x1800_60.00
[bwang@bwang ~]$ xrandr
Screen 0: minimum 32 x 32, current 1920 x 1080, maximum 32768 x 32768
VNC-0 connected primary 1920x1080+0+0 0mm x 0mm
   1920x1080     60.00*+
   1920x1200     60.00  
   1600x1200     60.00  
   1680x1050     60.00  
   1400x1050     60.00  
   1360x768      60.00  
   1280x1024     60.00  
   1280x960      60.00  
   1280x800      60.00  
   1280x720      60.00  
   1024x768      60.00  
   800x600       60.00  
   640x480       60.00  
   2880x1800_60.00  59.97  

[bwang@bwang ~]$ xrandr -s 2880x1800_60.00
[bwang@bwang ~]$ xrandr --dpi 220
[bwang@bwang ~]$ xdpyinfo
...
screen #0:
  dimensions:    2880x1800 pixels (332x207 millimeters)
  resolution:    220x221 dots per inch
  depths (7):    1, 4, 8, 16, 24, 32, 24
  root window id:    0x268
  depth of root window:    24 planes
  number of colormaps:    minimum 1, maximum 1
  default colormap:    0x20
  default number of colormap cells:    256
  preallocated pixels:    black 0, white 16777215
  options:    backing-store WHEN MAPPED, save-unders NO
  largest cursor:    2880x1800
  current input event mask:    0xda0003
    KeyPressMask             KeyReleaseMask           StructureNotifyMask      
    SubstructureNotifyMask   SubstructureRedirectMask PropertyChangeMask       
    ColormapChangeMask       
  number of visuals:    240
  default visual id:  0x21
...
The font size is too small to read. I tried several ways to make the fonts larger:
  • Tweak tool -> Windows -> HiDPI -> Window Scaling, change 1 to 2. This method make the font and window larger, but it is too large to me. Another issue is the font of menu is still small.
  • Run gsettings set org.gnome.desktop.interface.scaling-factor 2. Only integer is allowed, and make the font size larger on the menu bar, but not the font of terminal.
  • Scale X window xrandr --screen 0 --output VNC-0 --scale 2x2. This scaling bases on bitmap, it will cause blurry. And I ran multiple times into trouble when I set to 0.5x0.5 then 1x1, the screen zoom in with only big pixels, then I have to restart VNC server.
  • Set font scaling factor: Tweak Tool -> Fonts -> Scaling Factor. Changing to 1.5 works for me. This change makes the font larger everywhere: system menu and terminal, except Intellij IDEA. The font still look small, but it is super sharp. gsettings set org.gnome.desktop.interface text-scaling-factor 1.5
If the VNC server restarts, the new screen size will be lost. Need to find a better way to set it. Of course, I can put those commands in VNC xstartup or xinitrc.
Another thing is to make it easier to switch to lower resolution.

Monday, December 18, 2017

"No such a file or directory" when setting NETGEAR router

I got this error when I was setting up a new NETGEAR X6 router after setting up the new password. I restored the factory settings multiple times, but it either showed "No such a file or directory" for the link "http://www.routerlogin.net/genie_index.html" or pop up a dialog for user name and password, but the default "admin" and "password" didn't work.

I finally realized that it was my fault, not NETGEAR's. My laptop connected to NETGEAR X6 using a cable, but to my old NETGEAR router using WiFi. When the new router redirected the page to "http://www.routerlogin.net/genie_index.html", my laptop messed up with www.routerlogin.net because it tried to the old NETGEAR router. Turning off WiFi of my laptop solved the problem, and X6 home page showed up correctly.

Tuesday, December 12, 2017

Allow the outside world access your server in a container

I run docker containers of Nexus and httpd on a CentOS 7 host. I added a nexus.service to start the containers using docker-compose. I could access the nexus server from any machine after I started the service. But the next day, I could not access that server from other machines, running curl -k -X GET https://<host-ip> always got time out. The containers were still running and they were still bound to all interfaces because I could run curl -k -X GET https://<host-ip> on that host. The below shows those three ports 80,443,15001 of all interfaces are listened. NOTE: Proto=tcp6 doesn’t means “not listening on ipv4”.
# netstat -l -t
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp6       0      0 [::]:http               [::]:*                  LISTEN     
tcp6       0      0 [::]:15001              [::]:*                  LISTEN     
tcp6       0      0 [::]:https              [::]:*                  LISTEN
If I restart the service docker using systemctl restart docker, and service nexus systemctl start nexus, everything works again. If I reboot the server, docker starts and the containers are running, but I cannot access the Nexus server from any machine except the host.
It turns out that the host runs chef-client in the early morning and after rebooting, and set net.ipv4.ip_forward = 0. I can run sysctl net.ipv4.ip_forward=1 to make remote access to the Nexus server, and sysctl net.ipv4.ip_forward=0 to deny any access.
If I restarts the service docker, docker set net.ipv4.ip_forward=1 automatically. Check the docker document Communcating to the outside world
IP packet forwarding is governed by the ip_forward system parameter. Packets can only pass between containers if this parameter is 1. Usually you will simply leave the Docker server at its default setting —ip-forward=true and Docker will go set ip_forward to 1 for you when the server starts up. If you set —ip-forward=false and your system’s kernel has it enabled, the —ip-forward=false option has no effect. To check the setting on your kernel or to turn it on manually: