jdk/src/solaris/classes/sun/awt/X11/XToolkit.java
changeset 24538 25bf8153fbfe
parent 24520 e8afd90fcb69
child 26004 7507a1b93f67
equal deleted inserted replaced
24537:ecad2d59bc19 24538:25bf8153fbfe
    34 import java.awt.dnd.DragGestureEvent;
    34 import java.awt.dnd.DragGestureEvent;
    35 import java.awt.dnd.DragGestureRecognizer;
    35 import java.awt.dnd.DragGestureRecognizer;
    36 import java.awt.dnd.MouseDragGestureRecognizer;
    36 import java.awt.dnd.MouseDragGestureRecognizer;
    37 import java.awt.dnd.InvalidDnDOperationException;
    37 import java.awt.dnd.InvalidDnDOperationException;
    38 import java.awt.dnd.peer.DragSourceContextPeer;
    38 import java.awt.dnd.peer.DragSourceContextPeer;
       
    39 import java.awt.font.TextAttribute;
    39 import java.awt.im.InputMethodHighlight;
    40 import java.awt.im.InputMethodHighlight;
    40 import java.awt.im.spi.InputMethodDescriptor;
    41 import java.awt.im.spi.InputMethodDescriptor;
    41 import java.awt.image.ColorModel;
    42 import java.awt.image.ColorModel;
    42 import java.awt.peer.*;
    43 import java.awt.peer.*;
    43 import java.beans.PropertyChangeListener;
    44 import java.beans.PropertyChangeListener;
    97     private XSettings xs;
    98     private XSettings xs;
    98 
    99 
    99     private FontConfigManager fcManager = new FontConfigManager();
   100     private FontConfigManager fcManager = new FontConfigManager();
   100 
   101 
   101     static int arrowCursor;
   102     static int arrowCursor;
   102     static TreeMap winMap = new TreeMap();
   103     static TreeMap<Long, XBaseWindow> winMap = new TreeMap<>();
   103     static HashMap specialPeerMap = new HashMap();
   104     static HashMap<Object, Object> specialPeerMap = new HashMap<>();
   104     static HashMap winToDispatcher = new HashMap();
   105     static HashMap<Long, Collection<XEventDispatcher>> winToDispatcher = new HashMap<>();
   105     private static long _display;
   106     private static long _display;
   106     static UIDefaults uidefaults;
   107     static UIDefaults uidefaults;
   107     static X11GraphicsEnvironment localEnv;
   108     static X11GraphicsEnvironment localEnv;
   108     static X11GraphicsDevice device;
   109     static X11GraphicsDevice device;
   109     static final X11GraphicsConfig config;
   110     static final X11GraphicsConfig config;
   356             winMap.remove(Long.valueOf(window));
   357             winMap.remove(Long.valueOf(window));
   357         }
   358         }
   358     }
   359     }
   359     static XBaseWindow windowToXWindow(long window) {
   360     static XBaseWindow windowToXWindow(long window) {
   360         synchronized(winMap) {
   361         synchronized(winMap) {
   361             return (XBaseWindow) winMap.get(Long.valueOf(window));
   362             return winMap.get(Long.valueOf(window));
   362         }
   363         }
   363     }
   364     }
   364 
   365 
   365     static void addEventDispatcher(long window, XEventDispatcher dispatcher) {
   366     static void addEventDispatcher(long window, XEventDispatcher dispatcher) {
   366         synchronized(winToDispatcher) {
   367         synchronized(winToDispatcher) {
   367             Long key = Long.valueOf(window);
   368             Long key = Long.valueOf(window);
   368             Collection dispatchers = (Collection)winToDispatcher.get(key);
   369             Collection<XEventDispatcher> dispatchers = winToDispatcher.get(key);
   369             if (dispatchers == null) {
   370             if (dispatchers == null) {
   370                 dispatchers = new Vector();
   371                 dispatchers = new Vector<>();
   371                 winToDispatcher.put(key, dispatchers);
   372                 winToDispatcher.put(key, dispatchers);
   372             }
   373             }
   373             dispatchers.add(dispatcher);
   374             dispatchers.add(dispatcher);
   374         }
   375         }
   375     }
   376     }
   376     static void removeEventDispatcher(long window, XEventDispatcher dispatcher) {
   377     static void removeEventDispatcher(long window, XEventDispatcher dispatcher) {
   377         synchronized(winToDispatcher) {
   378         synchronized(winToDispatcher) {
   378             Long key = Long.valueOf(window);
   379             Long key = Long.valueOf(window);
   379             Collection dispatchers = (Collection)winToDispatcher.get(key);
   380             Collection<XEventDispatcher> dispatchers = winToDispatcher.get(key);
   380             if (dispatchers != null) {
   381             if (dispatchers != null) {
   381                 dispatchers.remove(dispatcher);
   382                 dispatchers.remove(dispatcher);
   382             }
   383             }
   383         }
   384         }
   384     }
   385     }
   491             resetKeyboardSniffer();
   492             resetKeyboardSniffer();
   492             setupModifierMap();
   493             setupModifierMap();
   493         }
   494         }
   494         XBaseWindow.dispatchToWindow(ev);
   495         XBaseWindow.dispatchToWindow(ev);
   495 
   496 
   496         Collection dispatchers = null;
   497         Collection<XEventDispatcher> dispatchers = null;
   497         synchronized(winToDispatcher) {
   498         synchronized(winToDispatcher) {
   498             Long key = Long.valueOf(xany.get_window());
   499             Long key = Long.valueOf(xany.get_window());
   499             dispatchers = (Collection)winToDispatcher.get(key);
   500             dispatchers = winToDispatcher.get(key);
   500             if (dispatchers != null) { // Clone it to avoid synchronization during dispatching
   501             if (dispatchers != null) { // Clone it to avoid synchronization during dispatching
   501                 dispatchers = new Vector(dispatchers);
   502                 dispatchers = new Vector<>(dispatchers);
   502             }
   503             }
   503         }
   504         }
   504         if (dispatchers != null) {
   505         if (dispatchers != null) {
   505             Iterator iter = dispatchers.iterator();
   506             Iterator<XEventDispatcher> iter = dispatchers.iterator();
   506             while (iter.hasNext()) {
   507             while (iter.hasNext()) {
   507                 XEventDispatcher disp = (XEventDispatcher)iter.next();
   508                 XEventDispatcher disp = iter.next();
   508                 disp.dispatchEvent(ev);
   509                 disp.dispatchEvent(ev);
   509             }
   510             }
   510         }
   511         }
   511         notifyListeners(ev);
   512         notifyListeners(ev);
   512     }
   513     }
   762         XAtom XA_NET_WM_STRUT = XAtom.get("_NET_WM_STRUT");
   763         XAtom XA_NET_WM_STRUT = XAtom.get("_NET_WM_STRUT");
   763         XAtom XA_NET_WM_STRUT_PARTIAL = XAtom.get("_NET_WM_STRUT_PARTIAL");
   764         XAtom XA_NET_WM_STRUT_PARTIAL = XAtom.get("_NET_WM_STRUT_PARTIAL");
   764 
   765 
   765         Insets insets = new Insets(0, 0, 0, 0);
   766         Insets insets = new Insets(0, 0, 0, 0);
   766 
   767 
   767         java.util.List search = new LinkedList();
   768         java.util.List<Object> search = new LinkedList<>();
   768         search.add(root);
   769         search.add(root);
   769         search.add(0);
   770         search.add(0);
   770         while (!search.isEmpty())
   771         while (!search.isEmpty())
   771         {
   772         {
   772             long window = (Long)search.remove(0);
   773             long window = (Long)search.remove(0);
   927 
   928 
   928     public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
   929     public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
   929         return XDragSourceContextPeer.createDragSourceContextPeer(dge);
   930         return XDragSourceContextPeer.createDragSourceContextPeer(dge);
   930     }
   931     }
   931 
   932 
       
   933     @SuppressWarnings("unchecked")
   932     public <T extends DragGestureRecognizer> T
   934     public <T extends DragGestureRecognizer> T
   933     createDragGestureRecognizer(Class<T> recognizerClass,
   935     createDragGestureRecognizer(Class<T> recognizerClass,
   934                     DragSource ds,
   936                     DragSource ds,
   935                     Component c,
   937                     Component c,
   936                     int srcActions,
   938                     int srcActions,
  1145 
  1147 
  1146     public int getMaximumCursorColors() {
  1148     public int getMaximumCursorColors() {
  1147         return 2;  // Black and white.
  1149         return 2;  // Black and white.
  1148     }
  1150     }
  1149 
  1151 
  1150     public Map mapInputMethodHighlight(InputMethodHighlight highlight)     {
  1152     public Map<TextAttribute, ?> mapInputMethodHighlight( InputMethodHighlight highlight) {
  1151         return XInputMethod.mapInputMethodHighlight(highlight);
  1153         return XInputMethod.mapInputMethodHighlight(highlight);
  1152     }
  1154     }
  1153     @Override
  1155     @Override
  1154     public boolean getLockingKeyState(int key) {
  1156     public boolean getLockingKeyState(int key) {
  1155         if (! (key == KeyEvent.VK_CAPS_LOCK || key == KeyEvent.VK_NUM_LOCK ||
  1157         if (! (key == KeyEvent.VK_CAPS_LOCK || key == KeyEvent.VK_NUM_LOCK ||
  1336     }
  1338     }
  1337 
  1339 
  1338     static void dumpPeers() {
  1340     static void dumpPeers() {
  1339         if (log.isLoggable(PlatformLogger.Level.FINE)) {
  1341         if (log.isLoggable(PlatformLogger.Level.FINE)) {
  1340             log.fine("Mapped windows:");
  1342             log.fine("Mapped windows:");
  1341             Iterator iter = winMap.entrySet().iterator();
  1343             winMap.forEach((k, v) -> {
  1342             while (iter.hasNext()) {
  1344                 log.fine(k + "->" + v);
  1343                 Map.Entry entry = (Map.Entry)iter.next();
  1345                 if (v instanceof XComponentPeer) {
  1344                 log.fine(entry.getKey() + "->" + entry.getValue());
  1346                     Component target = (Component)((XComponentPeer)v).getTarget();
  1345                 if (entry.getValue() instanceof XComponentPeer) {
       
  1346                     Component target = (Component)((XComponentPeer)entry.getValue()).getTarget();
       
  1347                     log.fine("\ttarget: " + target);
  1347                     log.fine("\ttarget: " + target);
  1348                 }
  1348                 }
  1349             }
  1349             });
  1350 
  1350 
  1351             SunToolkit.dumpPeers(log);
  1351             SunToolkit.dumpPeers(log);
  1352 
  1352 
  1353             log.fine("Mapped special peers:");
  1353             log.fine("Mapped special peers:");
  1354             iter = specialPeerMap.entrySet().iterator();
  1354             specialPeerMap.forEach((k, v) -> {
  1355             while (iter.hasNext()) {
  1355                 log.fine(k + "->" + v);
  1356                 Map.Entry entry = (Map.Entry)iter.next();
  1356             });
  1357                 log.fine(entry.getKey() + "->" + entry.getValue());
       
  1358             }
       
  1359 
  1357 
  1360             log.fine("Mapped dispatchers:");
  1358             log.fine("Mapped dispatchers:");
  1361             iter = winToDispatcher.entrySet().iterator();
  1359             winToDispatcher.forEach((k, v) -> {
  1362             while (iter.hasNext()) {
  1360                 log.fine(k + "->" + v);
  1363                 Map.Entry entry = (Map.Entry)iter.next();
  1361             });
  1364                 log.fine(entry.getKey() + "->" + entry.getValue());
       
  1365             }
       
  1366         }
  1362         }
  1367     }
  1363     }
  1368 
  1364 
  1369     /* Protected with awt_lock. */
  1365     /* Protected with awt_lock. */
  1370     private static boolean initialized;
  1366     private static boolean initialized;
  1584      * <p>
  1580      * <p>
  1585      * NB: This could be called from any thread if triggered by
  1581      * NB: This could be called from any thread if triggered by
  1586      * <code>loadXSettings</code>.  It is called from the System EDT
  1582      * <code>loadXSettings</code>.  It is called from the System EDT
  1587      * if triggered by an XSETTINGS change.
  1583      * if triggered by an XSETTINGS change.
  1588      */
  1584      */
  1589     void parseXSettings(int screen_XXX_ignored,Map updatedSettings) {
  1585     void parseXSettings(int screen_XXX_ignored,Map<String, Object> updatedSettings) {
  1590 
  1586 
  1591         if (updatedSettings == null || updatedSettings.isEmpty()) {
  1587         if (updatedSettings == null || updatedSettings.isEmpty()) {
  1592             return;
  1588             return;
  1593         }
  1589         }
  1594 
  1590 
  1595         Iterator i = updatedSettings.entrySet().iterator();
  1591         Iterator<Map.Entry<String, Object>> i = updatedSettings.entrySet().iterator();
  1596         while (i.hasNext()) {
  1592         while (i.hasNext()) {
  1597             Map.Entry e = (Map.Entry)i.next();
  1593             Map.Entry<String, Object> e = i.next();
  1598             String name = (String)e.getKey();
  1594             String name = e.getKey();
  1599 
  1595 
  1600             name = "gnome." + name;
  1596             name = "gnome." + name;
  1601             setDesktopProperty(name, e.getValue());
  1597             setDesktopProperty(name, e.getValue());
  1602             if (log.isLoggable(PlatformLogger.Level.FINE)) {
  1598             if (log.isLoggable(PlatformLogger.Level.FINE)) {
  1603                 log.fine("name = " + name + " value = " + e.getValue());
  1599                 log.fine("name = " + name + " value = " + e.getValue());
  1690             // keycode. We are going to check a state of this modifier.
  1686             // keycode. We are going to check a state of this modifier.
  1691             // If a modifier is a weird one, we cannot help it.
  1687             // If a modifier is a weird one, we cannot help it.
  1692             long window = 0;
  1688             long window = 0;
  1693             try{
  1689             try{
  1694                 // get any application window
  1690                 // get any application window
  1695                 window = ((Long)(winMap.firstKey())).longValue();
  1691                 window = winMap.firstKey().longValue();
  1696             }catch(NoSuchElementException nex) {
  1692             }catch(NoSuchElementException nex) {
  1697                 // get root window
  1693                 // get root window
  1698                 window = getDefaultRootWindow();
  1694                 window = getDefaultRootWindow();
  1699             }
  1695             }
  1700             boolean res = XlibWrapper.XQueryPointer(getDisplay(), window,
  1696             boolean res = XlibWrapper.XQueryPointer(getDisplay(), window,
  1796             log.fine("modLockIsShiftLock = " + modLockIsShiftLock);
  1792             log.fine("modLockIsShiftLock = " + modLockIsShiftLock);
  1797         }
  1793         }
  1798     }
  1794     }
  1799 
  1795 
  1800 
  1796 
  1801     private static SortedMap timeoutTasks;
  1797     private static SortedMap<Long, java.util.List<Runnable>> timeoutTasks;
  1802 
  1798 
  1803     /**
  1799     /**
  1804      * Removed the task from the list of waiting-to-be called tasks.
  1800      * Removed the task from the list of waiting-to-be called tasks.
  1805      * If the task has been scheduled several times removes only first one.
  1801      * If the task has been scheduled several times removes only first one.
  1806      */
  1802      */
  1817                 if (timeoutTaskLog.isLoggable(PlatformLogger.Level.FINER)) {
  1813                 if (timeoutTaskLog.isLoggable(PlatformLogger.Level.FINER)) {
  1818                     timeoutTaskLog.finer("Task is not scheduled");
  1814                     timeoutTaskLog.finer("Task is not scheduled");
  1819                 }
  1815                 }
  1820                 return;
  1816                 return;
  1821             }
  1817             }
  1822             Collection values = timeoutTasks.values();
  1818             Collection<java.util.List<Runnable>> values = timeoutTasks.values();
  1823             Iterator iter = values.iterator();
  1819             Iterator<java.util.List<Runnable>> iter = values.iterator();
  1824             while (iter.hasNext()) {
  1820             while (iter.hasNext()) {
  1825                 java.util.List list = (java.util.List)iter.next();
  1821                 java.util.List<Runnable> list = iter.next();
  1826                 boolean removed = false;
  1822                 boolean removed = false;
  1827                 if (list.contains(task)) {
  1823                 if (list.contains(task)) {
  1828                     list.remove(task);
  1824                     list.remove(task);
  1829                     if (list.isEmpty()) {
  1825                     if (list.isEmpty()) {
  1830                         iter.remove();
  1826                         iter.remove();
  1867                                      ";  task being added={2}" + ";  tasks before addition={3}",
  1863                                      ";  task being added={2}" + ";  tasks before addition={3}",
  1868                                      Long.valueOf(System.currentTimeMillis()), Long.valueOf(interval), task, timeoutTasks);
  1864                                      Long.valueOf(System.currentTimeMillis()), Long.valueOf(interval), task, timeoutTasks);
  1869             }
  1865             }
  1870 
  1866 
  1871             if (timeoutTasks == null) {
  1867             if (timeoutTasks == null) {
  1872                 timeoutTasks = new TreeMap();
  1868                 timeoutTasks = new TreeMap<>();
  1873             }
  1869             }
  1874 
  1870 
  1875             Long time = Long.valueOf(System.currentTimeMillis() + interval);
  1871             Long time = Long.valueOf(System.currentTimeMillis() + interval);
  1876             java.util.List tasks = (java.util.List)timeoutTasks.get(time);
  1872             java.util.List<Runnable> tasks = timeoutTasks.get(time);
  1877             if (tasks == null) {
  1873             if (tasks == null) {
  1878                 tasks = new ArrayList(1);
  1874                 tasks = new ArrayList<>(1);
  1879                 timeoutTasks.put(time, tasks);
  1875                 timeoutTasks.put(time, tasks);
  1880             }
  1876             }
  1881             tasks.add(task);
  1877             tasks.add(task);
  1882 
  1878 
  1883 
  1879 
  1895         awtLock();
  1891         awtLock();
  1896         try {
  1892         try {
  1897             if (timeoutTasks == null || timeoutTasks.isEmpty()) {
  1893             if (timeoutTasks == null || timeoutTasks.isEmpty()) {
  1898                 return -1L;
  1894                 return -1L;
  1899             }
  1895             }
  1900             return (Long)timeoutTasks.firstKey();
  1896             return timeoutTasks.firstKey();
  1901         } finally {
  1897         } finally {
  1902             awtUnlock();
  1898             awtUnlock();
  1903         }
  1899         }
  1904     }
  1900     }
  1905 
  1901 
  1916         if (timeoutTasks == null || timeoutTasks.isEmpty()) {
  1912         if (timeoutTasks == null || timeoutTasks.isEmpty()) {
  1917             return;
  1913             return;
  1918         }
  1914         }
  1919 
  1915 
  1920         Long currentTime = Long.valueOf(System.currentTimeMillis());
  1916         Long currentTime = Long.valueOf(System.currentTimeMillis());
  1921         Long time = (Long)timeoutTasks.firstKey();
  1917         Long time = timeoutTasks.firstKey();
  1922 
  1918 
  1923         while (time.compareTo(currentTime) <= 0) {
  1919         while (time.compareTo(currentTime) <= 0) {
  1924             java.util.List tasks = (java.util.List)timeoutTasks.remove(time);
  1920             java.util.List<Runnable> tasks = timeoutTasks.remove(time);
  1925 
  1921 
  1926             for (Iterator iter = tasks.iterator(); iter.hasNext();) {
  1922             for (Iterator<Runnable> iter = tasks.iterator(); iter.hasNext();) {
  1927                 Runnable task = (Runnable)iter.next();
  1923                 Runnable task = iter.next();
  1928 
  1924 
  1929                 if (timeoutTaskLog.isLoggable(PlatformLogger.Level.FINER)) {
  1925                 if (timeoutTaskLog.isLoggable(PlatformLogger.Level.FINER)) {
  1930                     timeoutTaskLog.finer("XToolkit.callTimeoutTasks(): current time={0}" +
  1926                     timeoutTaskLog.finer("XToolkit.callTimeoutTasks(): current time={0}" +
  1931                                          ";  about to run task={1}", Long.valueOf(currentTime), task);
  1927                                          ";  about to run task={1}", Long.valueOf(currentTime), task);
  1932                 }
  1928                 }
  1941             }
  1937             }
  1942 
  1938 
  1943             if (timeoutTasks.isEmpty()) {
  1939             if (timeoutTasks.isEmpty()) {
  1944                 break;
  1940                 break;
  1945             }
  1941             }
  1946             time = (Long)timeoutTasks.firstKey();
  1942             time = timeoutTasks.firstKey();
  1947         }
  1943         }
  1948     }
  1944     }
  1949 
  1945 
  1950     static long getAwtDefaultFg() {
  1946     static long getAwtDefaultFg() {
  1951         return awt_defaultFg;
  1947         return awt_defaultFg;