JDK-4654713 : Toolkit.getScreenInsets() not recalculates insets on secondary monitor
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.1
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-03-19
  • Updated: 2002-10-04
  • Resolved: 2002-10-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2 mantisFixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description

Name: azR10139			Date: 03/19/2002


Run testcase below. Drag window to secondary monitor. Put taskbar on the bottom of the secondary monitor. Turn autohide option of taskbar off. Press button. Move taskbar to the left. Press button again. Note, that in the debug output insets not changed. On primary monitor everything works fine.
--- Bug.java ---
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Bug extends JFrame{
   public Bug(){
       JButton jButton = new JButton();
       jButton.setText("click me");
       jButton.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent e) {
               Toolkit tk = Toolkit.getDefaultToolkit();
               GraphicsConfiguration gc = getGraphicsConfiguration();
               System.out.println("Insets is: " +
                   tk.getScreenInsets(gc));
               System.out.println("");
           }
       });
       this.getContentPane().add(jButton, BorderLayout.SOUTH);
       this.setSize(new Dimension(200, 200));
       this.setVisible(true);
   }

   public static void main(String[] args) throws Exception    {
       Bug bug = new Bug();
   }
}
----------------
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis FIXED IN: mantis INTEGRATED IN: mantis mantis-b03
14-06-2004

WORK AROUND Name: azR10139 Date: 03/19/2002 ======================================================================
11-06-2004

SUGGESTED FIX ------- awt_Toolkit.cpp ------- *** /tmp/sccs.dCaaQS Wed Sep 11 17:14:19 2002 --- awt_Toolkit.cpp Wed Sep 11 16:51:21 2002 *************** *** 623,628 **** --- 623,630 ---- } case WM_SETTINGCHANGE: { + AwtWin32GraphicsDevice::ResetAllMonitorInfo(); + /* Upcall to WToolkit when user changes configuration. * * NOTE: there is a bug in Windows 98 and some older versions of *************** *** 1769,1776 **** AwtToolkit::insetsMID, miInfo->rWork.top - miInfo->rMonitor.top, miInfo->rWork.left - miInfo->rMonitor.left, ! miInfo->rWork.bottom - miInfo->rMonitor.bottom, ! miInfo->rWork.right - miInfo->rMonitor.right); } } --- 1771,1778 ---- AwtToolkit::insetsMID, miInfo->rWork.top - miInfo->rMonitor.top, miInfo->rWork.left - miInfo->rMonitor.left, ! miInfo->rMonitor.bottom - miInfo->rWork.bottom, ! miInfo->rMonitor.right - miInfo->rWork.right); } } ------- awt_Win32GraphicsDevice.cpp ------- *** /tmp/sccs.eCaaQS Wed Sep 11 17:14:20 2002 --- awt_Win32GraphicsDevice.cpp Wed Sep 11 17:13:05 2002 *************** *** 582,587 **** --- 582,604 ---- return mi; } + /** + * This function updates the data in the MONITOR_INFO structure pointed to by + * pMonitorInfo for all monitors on the system. Added for 4654713. + */ + void AwtWin32GraphicsDevice::ResetAllMonitorInfo() + { + AwtWin32GraphicsDevice **devArray = + (AwtWin32GraphicsDevice**)devices->Lock(); + + for (int deviceIndex = 0; deviceIndex < awt_numScreens; deviceIndex++) { + MHND monitor = getMHNDFromScreen(deviceIndex); + ::GetMonitorInfo(monitor, devArray[deviceIndex]->pMonitorInfo); + } + + devices->Unlock(); + } + void AwtWin32GraphicsDevice::DisableOffscreenAccelerationForDevice( MHND hMonitor) { ------- awt_Win32GraphicsDevice.h ------- *** /tmp/sccs.fCaaQS Wed Sep 11 17:14:20 2002 --- awt_Win32GraphicsDevice.h Wed Sep 11 16:26:38 2002 *************** *** 58,63 **** --- 58,64 ---- static HPALETTE GetPalette(int deviceIndex); static MHND GetMonitor(int deviceIndex); static MONITOR_INFO *GetMonitorInfo(int deviceIndex); + static void ResetAllMonitorInfo(); static BOOL IsPrimaryPalettized() { return primaryPalettized; } static int GetDefaultDeviceIndex() { return primaryIndex; } static void DisableOffscreenAccelerationForDevice(MHND hMonitor);
11-06-2004

EVALUATION The bug is easily reproducible on Windows 2000. The problem is that the native device array (from which the inset information is retrieved) is not updated when the taskbar is relocated on the secondary monitor. Taskbar relocations on the primary display work correctly, as a SPI_GETWORKAREA call is made every time. If the taskbar is located on the secondary display when the test case is started up, the insets for the secondary monitor are correct - almost. There is an additional problem with insets on secondary monitors - bottom and right insets are always reported to be negative, which is wrong. So, there are two problems: 1) Insets for secondary monitors need to be obtained from a "live" source, or the native device array needs to be updated when the taskbar is located 2) Bottom and right insets are always negative. ###@###.### 2002-03-19 The suggested fix updates the MONITORINFO structures on a WM_SETTINGCHANGE, and fixes an arithemtic error in Java_sun_awt_windows_WToolkit_getScreenInsets(). ###@###.### 2002-09-11
11-09-2002