1 /* |
1 /* |
2 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
47 if (!new File("/usr/bin/xrandr").exists()) { |
47 if (!new File("/usr/bin/xrandr").exists()) { |
48 System.out.println("No xrandr tool to compare"); |
48 System.out.println("No xrandr tool to compare"); |
49 return; |
49 return; |
50 } |
50 } |
51 |
51 |
52 BufferedReader reader = new BufferedReader(new InputStreamReader( |
52 try (BufferedReader reader = new BufferedReader(new InputStreamReader( |
53 Runtime.getRuntime().exec("/usr/bin/xrandr").getInputStream())); |
53 Runtime.getRuntime().exec("/usr/bin/xrandr").getInputStream()))) { |
54 reader.readLine(); |
54 Pattern pattern = Pattern.compile("^\\s*(\\d+x\\d+)"); |
55 reader.readLine(); |
|
56 Pattern pattern = Pattern.compile("^\\s*(\\d+x\\d+)"); |
|
57 |
55 |
58 for (GraphicsDevice d : GraphicsEnvironment |
56 for (GraphicsDevice d : GraphicsEnvironment |
59 .getLocalGraphicsEnvironment().getScreenDevices()) { |
57 .getLocalGraphicsEnvironment().getScreenDevices()) { |
60 |
58 |
61 Set<String> xrandrModes = reader.lines().map(pattern::matcher) |
59 Set<String> xrandrModes = reader.lines().map(pattern::matcher) |
62 .takeWhile(Matcher::find).map(m -> m.group(1)) |
60 .filter(Matcher::find).map(m -> m.group(1)) |
63 .collect(Collectors.toSet()); |
61 .collect(Collectors.toSet()); |
64 |
62 |
65 Set<String> javaModes = Arrays.stream(d.getDisplayModes()) |
63 Set<String> javaModes = Arrays.stream(d.getDisplayModes()) |
66 .map(m -> m.getWidth() + "x" + m.getHeight()) |
64 .map(m -> m.getWidth() + "x" + m.getHeight()) |
67 .collect(Collectors.toSet()); |
65 .collect(Collectors.toSet()); |
68 |
66 |
69 if (!xrandrModes.equals(javaModes)) { |
67 if (!xrandrModes.equals(javaModes)) { |
70 throw new RuntimeException("Failed"); |
68 throw new RuntimeException("Failed"); |
71 } else { |
69 } else { |
72 System.out.println("Device " + d + ": " + javaModes.size() + |
70 System.out.println("Device " + d + ": " + javaModes.size() + |
73 " modes found."); |
71 " modes found."); |
|
72 } |
74 } |
73 } |
75 } |
74 } |
76 } |
75 } |
77 } |
76 } |