1 /* 2 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @key headful 27 * @bug 8022810 28 * @summary Cannot list all the available display modes on Ubuntu linux in case 29 * of two screen devices 30 * @run main CompareToXrandrTest 31 */ 32 33 import java.awt.GraphicsEnvironment; 34 import java.awt.GraphicsDevice; 35 import java.io.BufferedReader; 36 import java.io.File; 37 import java.io.InputStreamReader; 38 import java.util.Arrays; 39 import java.util.Set; 40 import java.util.regex.Matcher; 41 import java.util.regex.Pattern; 42 import java.util.stream.Collectors; 43 44 public class CompareToXrandrTest { 45 46 public static void main(String[] args) throws Exception { 47 if (!new File("/usr/bin/xrandr").exists()) { 48 System.out.println("No xrandr tool to compare"); 49 return; 50 } 51 52 BufferedReader reader = new BufferedReader(new InputStreamReader( 53 Runtime.getRuntime().exec("/usr/bin/xrandr").getInputStream())); 54 reader.readLine(); 55 reader.readLine(); 56 Pattern pattern = Pattern.compile("^\\s*(\\d+x\\d+)"); 57 58 for (GraphicsDevice d : GraphicsEnvironment 59 .getLocalGraphicsEnvironment().getScreenDevices()) { 60 61 Set<String> xrandrModes = reader.lines().map(pattern::matcher) 62 .takeWhile(Matcher::find).map(m -> m.group(1)) 63 .collect(Collectors.toSet()); 64 65 Set<String> javaModes = Arrays.stream(d.getDisplayModes()) 66 .map(m -> m.getWidth() + "x" + m.getHeight()) 67 .collect(Collectors.toSet()); 68 69 if (!xrandrModes.equals(javaModes)) { 70 throw new RuntimeException("Failed"); 71 } else { 72 System.out.println("Device " + d + ": " + javaModes.size() + 73 " modes found."); 74 } 75 } 76 } 77 }