1
2
3
4
5 package oshi.driver.unix;
6
7 import java.util.ArrayList;
8 import java.util.Collections;
9 import java.util.List;
10
11 import oshi.annotation.concurrent.ThreadSafe;
12 import oshi.util.ExecutingCommand;
13 import oshi.util.ParseUtil;
14
15
16
17
18 @ThreadSafe
19 public final class Xrandr {
20
21 private static final String[] XRANDR_VERBOSE = { "xrandr", "--verbose" };
22
23 private Xrandr() {
24 }
25
26 public static List<byte[]> getEdidArrays() {
27
28 List<String> xrandr = ExecutingCommand.runNative(XRANDR_VERBOSE, null);
29
30
31 if (xrandr.isEmpty()) {
32 return Collections.emptyList();
33 }
34 List<byte[]> displays = new ArrayList<>();
35 StringBuilder sb = null;
36 for (String s : xrandr) {
37 if (s.contains("EDID")) {
38 sb = new StringBuilder();
39 } else if (sb != null) {
40 sb.append(s.trim());
41 if (sb.length() < 256) {
42 continue;
43 }
44 String edidStr = sb.toString();
45 byte[] edid = ParseUtil.hexStringToByteArray(edidStr);
46 if (edid.length >= 128) {
47 displays.add(edid);
48 }
49 sb = null;
50 }
51 }
52 return displays;
53 }
54 }