X11相关参数设置

X11

环境变量DISPLAY用来设置将图形显示到何处。

直接登陆图形界面或者登陆命令行界面后使用startx启动图形, DISPLAY环境变量将自动设置为:0:0

变量格式

DISPLAY 环境变量格式如下host:NumA.NumB,

  • host指Xserver所在的主机主机名或者ip地址, 图形将显示在这一机器上, 可以是启动了图形界面的Linux/Unix机器, 也可以是安装了Exceed, X-Deep/32等Windows平台运行的Xserver的Windows机器. 如果Host为空, 则表示Xserver运行于本机, 并且图形程序(Xclient)使用unix socket方式连接到Xserver, 而不是TCP方式. 使用TCP方式连接时, NumA为连接的端口减去6000的值, 如果NumA为0, 则表示连接到6000端口; 使用unix socket方式连接时则表示连接的unix socket的路径, 如果为0, 则表示连接到/tmp/.X11-unix/X0 . NumB则几乎总是0

Xlib: connection to “:0.0” refused by server

Xlib: No protocol specifiedr
Error: Can’t open display: :0.0

这是因为Xserver默认情况下不允许别的用户的图形程序的图形显示在当前屏幕上. 如果需要别的用户的图形显示在当前屏幕上, 则应以当前登陆的用户, 也就是切换身份前的用户执行如下命令

xhost +

实例

#切换用户前是root用户在使用图形程序
su - root

xhost +

su - oracle

root与oracle用户的DISPLAY都为:0.0

xhost 是用来控制X server访问权限的。
通常当你从hostA登陆到hostB上运行hostB上的应用程序时,做为登录与被登录来说,hostA是client,但是对图形来说,是在hostA上显示的,需要使用hostA的Xserver,所以hostA是server

因此在登陆到hostB前,需要在hostA上运行xhost +来使其它用户能够访问hostA的Xserver。

开关闭屏幕显示

#ubuntu16.04关掉图形界面启动,命令:
systemctl disable lightdm.service

#开启图形界面命令:
ln -s /lib/systemd/system/lightdm.service /etc/systemd/system/display-manager.service

重置

sudo dpkg-reconfigure lightdm

其他

关闭图形界面:
1.不可恢复:
sudo systemctl disable lightdm.service
2.可恢复:
sudo systemctl set-default multi-user.target

打开图形界面,分别针对上述1和2
1
sudo apt-get install --reinstall lightdm
2
sudo systemctl set-default graphical.target

连接实际屏幕

确认实际屏幕的name of display 也就是DISPLAY的值是多少

要求在实际显示屏幕上运行

xdpyinfo |grep name

在这里插入图片描述
不同的登录会造成不同结果,切记!一定要登录在实际屏幕上运行

xhost +
#运行结果:access control disabled, clients can connect from any host

那么实际屏幕可以被其他登录端使用,比如ssh端登录
运行xdpyinfo |grep name结果为:
在这里插入图片描述
那么运行打开带ui的界面程序,不会显示到实际屏幕,如需映射到实际屏幕需执行以下指令:

#实际屏幕端,允许任意连接 或者加号后面带ip地址指定ip可以连接
xhost +
#ssh端设置DISPLAY,指定图形连接到localhost:0.0这里也就是我们在实际屏幕端查到的信息
export DISPLAY=:0.0
#以上没有错误,再ssh端,运行需要的程序即可显示到实际屏幕端
xxx

设置旋转

xrandr -o left 向左旋转90度
xrandr -o right 向右旋转90度
xrandr -o inverted 上下翻转
xrandr -o normal 回到正常角度
#通过xrandr读取显示屏id 为DSI-1,指定他旋转
xrandr --output DSI-1 --rotate left

触摸屏重定向

ubuntu多显示器单触摸屏校准

0、触摸屏重定向

sudo xinput map-to-output 13 DP1  #将触摸屏映射到指定的显示器
  • 13为触摸屏设备id,可通过xinput命令查看ILITEK ILITEK-TP id=13 [slave pointer (2)]

  • DP1为指定的显示设备名,可通过xrandr命令查看

1、安装屏幕校准器

sudo apt-get install xinput-calibrator

2、查看屏幕分辨率

在System settings --> Display 查看屏幕分辨率

3、手动设置校准窗口的大小(有多个显示器而只有一个触摸屏时用的,用于设置只指定窗口)

我的电脑有两个显示器,一个1920x1080, 一个1024x768,我只校准左边的显示器,如

Usage:xinput_calibrator --geometry x
–geometry: manually provide the geometry (width and height) for the calibration window

sudo xinput_calibrator --geometry 1920x1080
#注意:1920x1080 此处是字母x 

Warning: multiple calibratable devices found, calibrating last one (ILITEK ILITEK-TP)
use --device to select another one.
Setting calibration data: 0, 16384, 0, 9600
Calibrating EVDEV driver for “ILITEK ILITEK-TP” id=14
current calibration values (from XInput): min_x=0, max_x=16384 and min_y=0, max_y=9600

Doing dynamic recalibration:
Setting calibration data: 82, 32942, 155, 9796
–> Making the calibration permanent <–
copy the snippet below into ‘/etc/X11/xorg.conf.d/99-calibration.conf’ (/usr/share/X11/xorg.conf.d/ in some distro’s)
Section “InputClass”
Identifier “calibration”
MatchProduct “ILITEK ILITEK-TP”
Option “Calibration” “82 32942 155 9796”
Option “SwapAxes” “0”
EndSection

我的电脑是在/usr/share/X11/xorg.conf.d/目录下

4、按提示说明 拷贝校正信息到下面的文件中

sudo gedit /usr/share/X11/xorg.conf.d/99-calibration.conf

将下面的内容拷贝进去

Section “InputClass”
Identifier “calibration”
MatchProduct “ILITEK ILITEK-TP”
Option “Calibration” “82 32942 155 9796”
Option “SwapAxes” “0”
EndSection

5、完成。

1、查看 xinput_calibrator 使用方法

xinput_calibrator -h

xinput_calibrator, v0.7.5

Usage: xinput_calibrator [-h|–help] [-v|–verbose] [–list] [–device ] [–precalib ] [–misclick ] [–output-type <auto|xorg.conf.d|hal|xinput>] [–fake] [–geometry x] [–no-timeout]
-h, --help: print this help message
-v, --verbose: print debug messages during the process
–list: list calibratable input devices and quit
–device <device name or XID or sysfs event name (e.g event5)>: select a specific device to calibrate
–precalib: manually provide the current calibration setting (eg. the values in xorg.conf)
–misclick: set the misclick threshold (0=off, default: 15 pixels)
–output-type <auto|xorg.conf.d|hal|xinput>: type of config to output (auto=automatically detect, default: auto)
–fake: emulate a fake device (for testing purposes)
–geometry: manually provide the geometry (width and height) for the calibration window
–no-timeout: turns off the timeout
–output-filename: write calibration data to file (USB: override default /etc/modprobe.conf.local

2、查看输入设备

xinput

⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ Logitech USB Receiver id=11 [slave pointer (2)]
⎜ ↳ ILITEK ILITEK-TP id=13 [slave pointer (2)]
⎜ ↳ ILITEK ILITEK-TP id=14 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Power Button id=8 [slave keyboard (3)]
↳ Sleep Button id=9 [slave keyboard (3)]
↳ Logitech USB Receiver id=10 [slave keyboard (3)]
↳ USB2.0 Camera
id=12 [slave keyboard (3)]

3、查看输出设备

xrandr

Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 32767 x 32767
DP1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 521mm x 293mm
1920x1080 60.0*+
1680x1050 60.0
1280x1024 75.0 60.0
1440x900 59.9
1280x960 60.0
1280x720 60.0
1024x768 75.1 70.1 60.0
832x624 74.6
800x600 72.2 75.0 60.3 56.2
640x480 75.0 72.8 66.7 60.0
720x400 70.1
HDMI1 disconnected (normal left inverted right x axis y axis)
HDMI2 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)
实例参考

猜你喜欢

转载自blog.csdn.net/weixin_42892101/article/details/107807361