2929import javax .management .*;
3030import javax .swing .JComboBox ;
3131import java .lang .management .*;
32+ import java .util .*;
3233
3334public class AtkWrapper {
3435 static boolean accessibilityEnabled = false ;
@@ -37,9 +38,29 @@ static void initAtk() {
3738 if (AtkWrapper .initNativeLibrary ())
3839 accessibilityEnabled = true ;
3940 }
41+
42+ private static String findXPropPath () {
43+ String pathEnv = System .getenv ().get ("PATH" );
44+ if (pathEnv != null ) {
45+ String pathSeparator = File .pathSeparator ;
46+ java .util .List <String > paths = Arrays .asList (pathEnv .split (File .pathSeparator ));
47+ for (String path : paths ) {
48+ File xpropFile = new File (path , "xprop" );
49+ if (xpropFile .exists ()) {
50+ return xpropFile .getAbsolutePath ();
51+ }
52+ }
53+ }
54+ return null ;
55+ }
56+
4057 static {
4158 try {
42- ProcessBuilder builder = new ProcessBuilder("@XPROP@", "-root");
59+ String xpropPath = findXPropPath ();
60+ if (xpropPath == null ) {
61+ throw new RuntimeException ("No xprop found" );
62+ }
63+ ProcessBuilder builder = new ProcessBuilder (xpropPath , "-root" );
4364 Process p = builder .start ();
4465 BufferedReader b = new BufferedReader (new InputStreamReader (p .getInputStream ()));
4566 String result ;
@@ -690,7 +711,7 @@ public AtkWrapper() {
690711 AWTEvent .WINDOW_EVENT_MASK |
691712 AWTEvent .FOCUS_EVENT_MASK |
692713 AWTEvent .CONTAINER_EVENT_MASK );
693-
714+ if ( toolkit . getSystemEventQueue () != null ) {
694715 toolkit .getSystemEventQueue ().push (new EventQueue () {
695716 boolean previousPressConsumed = false ;
696717
@@ -719,6 +740,7 @@ public void dispatchEvent(AWTEvent e) {
719740 super .dispatchEvent (e );
720741 }
721742 });
743+ }
722744 }
723745
724746 public static long getInstanceFromSwing (AccessibleContext ac ) {
@@ -728,4 +750,4 @@ public static long getInstanceFromSwing(AccessibleContext ac) {
728750 public static void main (String args []) {
729751 new AtkWrapper ();
730752 }
731- }
753+ }
0 commit comments