Improved the display detection and fixed a widget bug