45 import java.util.logging.Logger; |
45 import java.util.logging.Logger; |
46 |
46 |
47 import sun.awt.AWTAccessor; |
47 import sun.awt.AWTAccessor; |
48 import sun.awt.ComponentAccessor; |
48 import sun.awt.ComponentAccessor; |
49 import sun.awt.WindowAccessor; |
49 import sun.awt.WindowAccessor; |
|
50 import sun.awt.AWTAccessor; |
50 import sun.awt.DisplayChangedListener; |
51 import sun.awt.DisplayChangedListener; |
51 import sun.awt.SunToolkit; |
52 import sun.awt.SunToolkit; |
52 import sun.awt.X11GraphicsDevice; |
53 import sun.awt.X11GraphicsDevice; |
53 import sun.awt.X11GraphicsEnvironment; |
54 import sun.awt.X11GraphicsEnvironment; |
54 |
55 |
709 int intAmt, vertAmt, horizAmt; |
710 int intAmt, vertAmt, horizAmt; |
710 int largestAmt = 0; |
711 int largestAmt = 0; |
711 int curScreenNum = ((X11GraphicsDevice)getGraphicsConfiguration().getDevice()).getScreen(); |
712 int curScreenNum = ((X11GraphicsDevice)getGraphicsConfiguration().getDevice()).getScreen(); |
712 int newScreenNum = 0; |
713 int newScreenNum = 0; |
713 GraphicsDevice gds[] = XToolkit.localEnv.getScreenDevices(); |
714 GraphicsDevice gds[] = XToolkit.localEnv.getScreenDevices(); |
|
715 GraphicsConfiguration newGC = null; |
714 Rectangle screenBounds; |
716 Rectangle screenBounds; |
715 |
717 |
716 for (int i = 0; i < gds.length; i++) { |
718 for (int i = 0; i < gds.length; i++) { |
717 screenBounds = gds[i].getDefaultConfiguration().getBounds(); |
719 screenBounds = gds[i].getDefaultConfiguration().getBounds(); |
718 if (newBounds.intersects(screenBounds)) { |
720 if (newBounds.intersects(screenBounds)) { |
724 Math.max(newBounds.y, screenBounds.y); |
726 Math.max(newBounds.y, screenBounds.y); |
725 intAmt = horizAmt * vertAmt; |
727 intAmt = horizAmt * vertAmt; |
726 if (intAmt == area) { |
728 if (intAmt == area) { |
727 // Completely on this screen - done! |
729 // Completely on this screen - done! |
728 newScreenNum = i; |
730 newScreenNum = i; |
|
731 newGC = gds[i].getDefaultConfiguration(); |
729 break; |
732 break; |
730 } |
733 } |
731 if (intAmt > largestAmt) { |
734 if (intAmt > largestAmt) { |
732 largestAmt = intAmt; |
735 largestAmt = intAmt; |
733 newScreenNum = i; |
736 newScreenNum = i; |
|
737 newGC = gds[i].getDefaultConfiguration(); |
734 } |
738 } |
735 } |
739 } |
736 } |
740 } |
737 if (newScreenNum != curScreenNum) { |
741 if (newScreenNum != curScreenNum) { |
738 if (log.isLoggable(Level.FINEST)) { |
742 if (log.isLoggable(Level.FINEST)) { |
739 log.finest("XWindowPeer: Moved to a new screen"); |
743 log.finest("XWindowPeer: Moved to a new screen"); |
740 } |
744 } |
741 draggedToNewScreen(newScreenNum); |
745 executeDisplayChangedOnEDT(newGC); |
742 } |
746 } |
743 } |
|
744 |
|
745 /* Xinerama |
|
746 * called to update our GC when dragged onto another screen |
|
747 */ |
|
748 public void draggedToNewScreen(int screenNum) { |
|
749 executeDisplayChangedOnEDT(screenNum); |
|
750 } |
747 } |
751 |
748 |
752 /** |
749 /** |
753 * Helper method that executes the displayChanged(screen) method on |
750 * Helper method that executes the displayChanged(screen) method on |
754 * the event dispatch thread. This method is used in the Xinerama case |
751 * the event dispatch thread. This method is used in the Xinerama case |
755 * and after display mode change events. |
752 * and after display mode change events. |
756 */ |
753 */ |
757 private void executeDisplayChangedOnEDT(final int screenNum) { |
754 private void executeDisplayChangedOnEDT(final GraphicsConfiguration gc) { |
758 Runnable dc = new Runnable() { |
755 Runnable dc = new Runnable() { |
759 public void run() { |
756 public void run() { |
760 // Updates this window's GC and notifies all the children. |
757 AWTAccessor.getComponentAccessor(). |
761 // See XPanelPeer/XCanvasPeer.displayChanged(int) for details. |
758 setGraphicsConfiguration((Component)target, gc); |
762 displayChanged(screenNum); |
|
763 } |
759 } |
764 }; |
760 }; |
765 SunToolkit.executeOnEventHandlerThread((Component)target, dc); |
761 SunToolkit.executeOnEventHandlerThread((Component)target, dc); |
766 } |
762 } |
767 |
763 |
768 /** |
764 /** |
769 * From the DisplayChangedListener interface; called from |
765 * From the DisplayChangedListener interface; called from |
770 * X11GraphicsDevice when the display mode has been changed. |
766 * X11GraphicsDevice when the display mode has been changed. |
771 */ |
767 */ |
772 public void displayChanged() { |
768 public void displayChanged() { |
773 GraphicsConfiguration gc = getGraphicsConfiguration(); |
769 executeDisplayChangedOnEDT(getGraphicsConfiguration()); |
774 int curScreenNum = ((X11GraphicsDevice)gc.getDevice()).getScreen(); |
|
775 executeDisplayChangedOnEDT(curScreenNum); |
|
776 } |
770 } |
777 |
771 |
778 /** |
772 /** |
779 * From the DisplayChangedListener interface; top-levels do not need |
773 * From the DisplayChangedListener interface; top-levels do not need |
780 * to react to this event. |
774 * to react to this event. |