Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(gui): horizontal scrolling in linux #2229

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/ui/JadxEventQueue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package jadx.gui.ui;

import java.awt.AWTEvent;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;

import jadx.gui.utils.UiUtils;

public class JadxEventQueue extends EventQueue {

private static final boolean IS_X_TOOLKIT = UiUtils.isXToolkit();

public static void register() {
if (IS_X_TOOLKIT) {
Toolkit.getDefaultToolkit().getSystemEventQueue().push(new JadxEventQueue());
}
}

private JadxEventQueue() {
}

@Override
protected void dispatchEvent(AWTEvent event) {
AWTEvent mappedEvent = mapEvent(event);
super.dispatchEvent(mappedEvent);
}

private static AWTEvent mapEvent(AWTEvent event) {
if (IS_X_TOOLKIT && event instanceof MouseEvent && ((MouseEvent) event).getButton() > 3) {
return mapXWindowMouseEvent((MouseEvent) event);
}
return event;
}

@SuppressWarnings({ "deprecation", "MagicConstant" })
private static AWTEvent mapXWindowMouseEvent(MouseEvent src) {
if (src.getButton() < 6) {
// buttons 4-5 come from touchpad, they must be converted to horizontal scrolling events
int modifiers = src.getModifiers() | InputEvent.SHIFT_DOWN_MASK;
return new MouseWheelEvent(src.getComponent(), MouseEvent.MOUSE_WHEEL, src.getWhen(), modifiers,
src.getX(), src.getY(), 0, false, MouseWheelEvent.WHEEL_UNIT_SCROLL,
src.getClickCount(), src.getButton() == 4 ? -1 : 1);
} else {
// Here we "shift" events with buttons `6` and `7` to similar events with buttons 4 and 5
// See `java.awt.InputEvent#BUTTON_DOWN_MASK`, 1<<14 is the 4th physical button, 1<<15 is the 5th.
int modifiers = src.getModifiers() | (1 << (8 + src.getButton()));
return new MouseEvent(src.getComponent(), src.getID(), src.getWhen(), modifiers,
src.getX(), src.getY(), 1, src.isPopupTrigger(), src.getButton() - 2);
}
}
}
1 change: 1 addition & 0 deletions jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public MainWindow(JadxSettings settings) {
this.cacheManager = new CacheManager(settings);
this.shortcutsController = new ShortcutsController(settings);

JadxEventQueue.register();
resetCache();
FontUtils.registerBundledFonts();
setEditorTheme(settings.getEditorThemePath());
Expand Down
1 change: 1 addition & 0 deletions jadx-gui/src/main/java/jadx/gui/utils/SystemInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class SystemInfo {
public static final boolean IS_WINDOWS = LOWER_OS_NAME.startsWith("windows");
public static final boolean IS_MAC = LOWER_OS_NAME.startsWith("mac");
public static final boolean IS_LINUX = LOWER_OS_NAME.startsWith("linux");
public static final boolean IS_UNIX = !IS_WINDOWS;

private SystemInfo() {
}
Expand Down
6 changes: 6 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/utils/UiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,12 @@ public static void notUiThreadGuard() {
}
}

public static boolean isXToolkit() {
return SystemInfo.IS_UNIX
&& !SystemInfo.IS_MAC
&& "sun.awt.X11.XToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName());
}

@TestOnly
public static void debugTimer(int periodInSeconds, Runnable action) {
if (!LOG.isDebugEnabled()) {
Expand Down