Skip to content

Commit

Permalink
fix fcitx wrong position of hidpi scaling problem
Browse files Browse the repository at this point in the history
  • Loading branch information
tangruize committed Oct 28, 2022
1 parent b527989 commit 2639e96
Showing 1 changed file with 39 additions and 21 deletions.
60 changes: 39 additions & 21 deletions idea.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/src/java.desktop/share/classes/java/awt/Container.java b/src/java.desktop/share/classes/java/awt/Container.java
index ec6913057d8..c9ca9cbf11e 100644
index 1327b2fded9..c2ebc03fcc1 100644
--- a/src/java.desktop/share/classes/java/awt/Container.java
+++ b/src/java.desktop/share/classes/java/awt/Container.java
@@ -25,6 +25,7 @@
Expand All @@ -26,7 +26,7 @@ index ec6913057d8..c9ca9cbf11e 100644
* Detects whether or not remove from current parent and adding to new parent requires call of
* removeNotify on the component. Since removeNotify destroys native window this might (not)
diff --git a/src/java.desktop/share/classes/javax/swing/JTextArea.java b/src/java.desktop/share/classes/javax/swing/JTextArea.java
index 03b3bc7e9bd..7bd43f5829b 100644
index ecc9342f05a..eea39c9e03a 100644
--- a/src/java.desktop/share/classes/javax/swing/JTextArea.java
+++ b/src/java.desktop/share/classes/javax/swing/JTextArea.java
@@ -562,6 +562,14 @@ public class JTextArea extends JTextComponent {
Expand All @@ -45,7 +45,7 @@ index 03b3bc7e9bd..7bd43f5829b 100644
* Returns the number of columns in the TextArea.
*
diff --git a/src/java.desktop/share/classes/javax/swing/JTextField.java b/src/java.desktop/share/classes/javax/swing/JTextField.java
index 0d66209d8af..363ac03514b 100644
index 3abe09d0565..50dc549bdba 100644
--- a/src/java.desktop/share/classes/javax/swing/JTextField.java
+++ b/src/java.desktop/share/classes/javax/swing/JTextField.java
@@ -427,6 +427,14 @@ public class JTextField extends JTextComponent implements SwingConstants {
Expand All @@ -64,7 +64,7 @@ index 0d66209d8af..363ac03514b 100644
* Returns the preferred size <code>Dimensions</code> needed for this
* <code>TextField</code>. If a non-zero number of columns has been
diff --git a/src/java.desktop/share/classes/sun/awt/im/InputContext.java b/src/java.desktop/share/classes/sun/awt/im/InputContext.java
index 237164a9d42..9a16e75ff46 100644
index bb955dc5089..7c42e2aa685 100644
--- a/src/java.desktop/share/classes/sun/awt/im/InputContext.java
+++ b/src/java.desktop/share/classes/sun/awt/im/InputContext.java
@@ -28,6 +28,7 @@ package sun.awt.im;
Expand Down Expand Up @@ -164,10 +164,10 @@ index 237164a9d42..9a16e75ff46 100644
* Activates the current input method of this input context, and grabs
* the composition area for use by this input context.
diff --git a/src/java.desktop/unix/classes/sun/awt/X11/XInputMethod.java b/src/java.desktop/unix/classes/sun/awt/X11/XInputMethod.java
index 2afd7bbefdb..2be981523ed 100644
index 4244812ceb0..f2fa4a0684c 100644
--- a/src/java.desktop/unix/classes/sun/awt/X11/XInputMethod.java
+++ b/src/java.desktop/unix/classes/sun/awt/X11/XInputMethod.java
@@ -28,10 +28,21 @@ package sun.awt.X11;
@@ -28,12 +28,25 @@ package sun.awt.X11;
import java.awt.AWTException;
import java.awt.Component;
import java.awt.Container;
Expand All @@ -177,21 +177,34 @@ index 2afd7bbefdb..2be981523ed 100644
import java.awt.Rectangle;
import java.awt.im.spi.InputMethodContext;
import java.awt.peer.ComponentPeer;

+import java.awt.GraphicsEnvironment;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.text.JTextComponent;
+
import sun.awt.AWTAccessor;
import sun.awt.X11InputMethod;
+import sun.awt.X11GraphicsDevice;

@@ -86,15 +97,29 @@ public class XInputMethod extends X11InputMethod {
import sun.util.logging.PlatformLogger;

private static volatile long xicFocus;
@@ -45,6 +58,8 @@ import sun.util.logging.PlatformLogger;
public class XInputMethod extends X11InputMethod {
private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XInputMethod");

+ private int scale = ((X11GraphicsDevice)GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()).getScaleFactor();
+
public XInputMethod() throws AWTException {
super();
}
@@ -86,15 +101,29 @@ public class XInputMethod extends X11InputMethod {

private static volatile long xicFocus = 0;

+ /**
+ * fix fcitx position
Expand Down Expand Up @@ -220,8 +233,8 @@ index 2afd7bbefdb..2be981523ed 100644
}

public static long getXICFocus() {
@@ -156,6 +181,69 @@ public class XInputMethod extends X11InputMethod {
return peer.getContentWindow();
@@ -133,6 +162,74 @@ public class XInputMethod extends X11InputMethod {
return null;
}

+ protected int[] getOffXYRelateToFrame(ComponentPeer peer, boolean value) {
Expand Down Expand Up @@ -276,8 +289,13 @@ index 2afd7bbefdb..2be981523ed 100644
+ Method method_getNativeContainer = Component.class.getDeclaredMethod("getNativeContainer");
+ method_getNativeContainer.setAccessible(true);
+ Container c = (Container)method_getNativeContainer.invoke(awtFocussedComponent);
+ if(c != null)
+ if(c != null) {
+ result = new int[]{point.x - c.getPeerLocationOnScreen().x + caret_x, point.y - c.getPeerLocationOnScreen().y + font_height + caret_y};
+ if (scale > 1) {
+ result[0] *= scale;
+ result[1] *= scale;
+ }
+ }
+
+ return result;
+ } catch (Exception e) {
Expand All @@ -288,9 +306,9 @@ index 2afd7bbefdb..2be981523ed 100644
+ }
+
/*
* Native methods
*/
@@ -164,6 +252,6 @@ public class XInputMethod extends X11InputMethod {
* Subclasses should override disposeImpl() instead of dispose(). Client
* code should always invoke dispose(), never disposeImpl().
@@ -253,6 +350,6 @@ public class XInputMethod extends X11InputMethod {
private native boolean recreateXICNative(long window, long px11data, int ctxid);
private native int releaseXICNative(long px11data);
private native void setXICFocusNative(long window,
Expand All @@ -299,7 +317,7 @@ index 2afd7bbefdb..2be981523ed 100644
private native void adjustStatusWindow(long window);
}
diff --git a/src/java.desktop/unix/classes/sun/awt/X11InputMethod.java b/src/java.desktop/unix/classes/sun/awt/X11InputMethod.java
index 18e0ba1e7e4..34112b11db5 100644
index d9bed439688..623af69478e 100644
--- a/src/java.desktop/unix/classes/sun/awt/X11InputMethod.java
+++ b/src/java.desktop/unix/classes/sun/awt/X11InputMethod.java
@@ -33,6 +33,7 @@ import java.awt.AWTException;
Expand Down Expand Up @@ -351,10 +369,10 @@ index 18e0ba1e7e4..34112b11db5 100644
protected abstract int releaseXIC();
private static native boolean recreateX11InputMethod();
diff --git a/src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c b/src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c
index aafb1af3d81..ff3978dd043 100644
index e63741f583e..55d847b98ac 100644
--- a/src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c
+++ b/src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c
@@ -427,13 +427,17 @@ setXICFocus(XIC ic, unsigned short req)
@@ -434,13 +434,17 @@ setXICFocus(XIC ic, unsigned short req)
* Sets the focus window to the given XIC.
*/
static void
Expand All @@ -374,7 +392,7 @@ index aafb1af3d81..ff3978dd043 100644
}

/*
@@ -1469,7 +1473,8 @@ Java_sun_awt_X11_XInputMethod_setXICFocusNative(JNIEnv *env,
@@ -1519,7 +1523,8 @@ Java_sun_awt_X11_XInputMethod_setXICFocusNative(JNIEnv *env,
jobject this,
jlong w,
jboolean req,
Expand All @@ -384,7 +402,7 @@ index aafb1af3d81..ff3978dd043 100644
{
X11InputMethodData *pX11IMData;
AWT_LOCK();
@@ -1490,7 +1495,17 @@ Java_sun_awt_X11_XInputMethod_setXICFocusNative(JNIEnv *env,
@@ -1540,7 +1545,17 @@ Java_sun_awt_X11_XInputMethod_setXICFocusNative(JNIEnv *env,
* On Solaris2.6, setXICWindowFocus() has to be invoked
* before setting focus.
*/
Expand Down

0 comments on commit 2639e96

Please sign in to comment.