From 06b92cf08123dbd94f7be06ca79938d42a7a86fc Mon Sep 17 00:00:00 2001 From: Brian Hinz Date: Mon, 24 Oct 2011 02:11:53 +0000 Subject: [PATCH] set dialog locations relative to parent window, otherwise dialogs appear on wrong screen in multi-monitor configurations. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4732 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- java/com/tigervnc/vncviewer/Dialog.java | 20 +++++++++++++------ java/com/tigervnc/vncviewer/F8Menu.java | 4 ++-- java/com/tigervnc/vncviewer/ServerDialog.java | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/java/com/tigervnc/vncviewer/Dialog.java b/java/com/tigervnc/vncviewer/Dialog.java index d6fdd1bf..563a471d 100644 --- a/java/com/tigervnc/vncviewer/Dialog.java +++ b/java/com/tigervnc/vncviewer/Dialog.java @@ -41,15 +41,19 @@ class Dialog extends JFrame { //addWindowListener(this); } - public boolean showDialog() { + public boolean showDialog(Component c) { ok = false; done = false; initDialog(); - Dimension dpySize = getToolkit().getScreenSize(); - Dimension mySize = getSize(); - int x = (dpySize.width - mySize.width) / 2; - int y = (dpySize.height - mySize.height) / 2; - setLocation(x, y); + if (c != null) { + setLocationRelativeTo(c); + } else { + Dimension dpySize = getToolkit().getScreenSize(); + Dimension mySize = getSize(); + int x = (dpySize.width - mySize.width) / 2; + int y = (dpySize.height - mySize.height) / 2; + setLocation(x, y); + } ClassLoader cl = this.getClass().getClassLoader(); ImageIcon icon = new ImageIcon(cl.getResource("com/tigervnc/vncviewer/tigervnc.ico")); setIconImage(icon.getImage()); @@ -69,6 +73,10 @@ class Dialog extends JFrame { return ok; } + public boolean showDialog() { + return showDialog(null); + } + public void endDialog() { done = true; setVisible(false); diff --git a/java/com/tigervnc/vncviewer/F8Menu.java b/java/com/tigervnc/vncviewer/F8Menu.java index 375849c1..15717617 100644 --- a/java/com/tigervnc/vncviewer/F8Menu.java +++ b/java/com/tigervnc/vncviewer/F8Menu.java @@ -96,7 +96,7 @@ public class F8Menu extends JPopupMenu implements ActionListener { if (cc.fullScreen) cc.toggleFullScreen(); cc.viewport.setExtendedState(JFrame.MAXIMIZED_BOTH); } else if (actionMatch(ev, clipboard)) { - cc.clipboardDialog.showDialog(); + cc.clipboardDialog.showDialog(cc.viewport); } else if (actionMatch(ev, f8)) { cc.writeKeyEvent(cc.menuKey, true); cc.writeKeyEvent(cc.menuKey, false); @@ -112,7 +112,7 @@ public class F8Menu extends JPopupMenu implements ActionListener { } else if (actionMatch(ev, newConn)) { VncViewer.newViewer(cc.viewer); } else if (actionMatch(ev, options)) { - cc.options.showDialog(); + cc.options.showDialog(cc.viewport); } else if (actionMatch(ev, info)) { cc.showInfo(); } else if (actionMatch(ev, about)) { diff --git a/java/com/tigervnc/vncviewer/ServerDialog.java b/java/com/tigervnc/vncviewer/ServerDialog.java index f5e56141..0f32a96c 100644 --- a/java/com/tigervnc/vncviewer/ServerDialog.java +++ b/java/com/tigervnc/vncviewer/ServerDialog.java @@ -119,7 +119,7 @@ class ServerDialog extends Dialog implements ok = false; endDialog(); } else if (s instanceof JButton && (JButton)s == optionsButton) { - options.showDialog(); + options.showDialog(this); } else if (s instanceof JButton && (JButton)s == aboutButton) { cc.showAbout(); } else if (s instanceof JComboBox && (JComboBox)s == server) { -- 2.39.5