Skip to content

Commit

Permalink
Bug 1156: LinuxKeyEventTracker, LinuxMouseTracker: Robostness (+NEWT …
Browse files Browse the repository at this point in the history
…fix)

commit 453f80e added disabling the tracker,
however the NEWT usage didn't cover all mouse tracker null pointer.

Further, let's initialize and spawn off the threads only at first getSingleton() call
not at class initialization earlier.
  • Loading branch information
sgothel committed Nov 30, 2019
1 parent 453f80e commit 94dbf9b
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 41 deletions.
3 changes: 3 additions & 0 deletions make/scripts/tests.sh
Expand Up @@ -117,6 +117,9 @@ function jrun() {
#D_ARGS="-Djogl.debug=all"
#D_ARGS="-Djogl.debug=all -Dnewt.debug=all -Djogl.debug.DebugGL"
#D_ARGS="-Dnewt.debug=all"
D_ARGS="-Dnativewindow.debug=all -Djogl.debug=all -Dnewt.debug=all -Dnewt.disable.LinuxKeyEventTracker -Dnewt.disable.LinuxMouseTracker"
#D_ARGS="-Dnativewindow.debug=all -Djogl.debug=all -Dnewt.debug=all -Dnewt.disable.LinuxKeyEventTracker"
#D_ARGS="-Dnativewindow.debug=all -Djogl.debug=all -Dnewt.debug=all -Dnewt.disable.LinuxMouseTracker"
#D_ARGS="-Djogl.debug=all -Dnewt.debug=all"
#D_ARGS="-Djogl.debug=all -Dnativewindow.debug=all"
#D_ARGS="-Dnativewindow.debug=all -Djogl.debug=all -Dnewt.debug=all"
Expand Down
Expand Up @@ -108,7 +108,11 @@ protected void createNativeImpl() {
}
if( null != defaultPointerIcon ) {
final LinuxMouseTracker lmt = LinuxMouseTracker.getSingleton();
setPointerIconActive(defaultPointerIcon.getHandle(), lmt.getLastX(), lmt.getLastY());
if( null != lmt ) {
setPointerIconActive(defaultPointerIcon.getHandle(), lmt.getLastX(), lmt.getLastY());
} else {
setPointerIconActive(defaultPointerIcon.getHandle(), 0, 0);
}
}
}
private PointerIconImpl defaultPointerIcon = null;
Expand Down
30 changes: 22 additions & 8 deletions src/newt/classes/jogamp/newt/driver/bcm/vc/iv/WindowDriver.java
Expand Up @@ -210,9 +210,12 @@ protected void createNativeImpl() {
}
windowHandleClose = nativeWindowHandle;

addWindowListener(keyTracker);
addWindowListener(mouseTracker);

if( null != keyTracker ) {
addWindowListener(keyTracker);
}
if( null != mouseTracker ) {
addWindowListener(mouseTracker);
}

focusChanged(false, true);
}
Expand All @@ -222,9 +225,12 @@ protected void closeNativeImpl() {
final DisplayDriver display = (DisplayDriver) getScreen().getDisplay();
final EGLGraphicsDevice eglDevice = (EGLGraphicsDevice) getGraphicsConfiguration().getScreen().getDevice();

removeWindowListener(mouseTracker);
removeWindowListener(keyTracker);

if( null != mouseTracker ) {
removeWindowListener(mouseTracker);
}
if( null != keyTracker ) {
removeWindowListener(keyTracker);
}
if(0!=windowHandleClose) {
CloseWindow0(display.getBCMHandle(), windowHandleClose);
}
Expand Down Expand Up @@ -285,13 +291,21 @@ protected final void doMouseEvent(final boolean enqueue, final boolean wait, fin
@Override
protected void setPointerIconImpl(final PointerIconImpl pi) {
final DisplayDriver display = (DisplayDriver) getScreen().getDisplay();
display.setPointerIconActive(null != pi ? pi.validatedHandle() : 0, mouseTracker.getLastX(), mouseTracker.getLastY());
if( null != mouseTracker ) {
display.setPointerIconActive(null != pi ? pi.validatedHandle() : 0, mouseTracker.getLastX(), mouseTracker.getLastY());
} else {
display.setPointerIconActive(null != pi ? pi.validatedHandle() : 0, 0, 0);
}
}

@Override
protected boolean setPointerVisibleImpl(final boolean pointerVisible) {
final DisplayDriver display = (DisplayDriver) getScreen().getDisplay();
display.setActivePointerIconVisible(pointerVisible, mouseTracker.getLastX(), mouseTracker.getLastY());
if( null != mouseTracker ) {
display.setActivePointerIconVisible(pointerVisible, mouseTracker.getLastX(), mouseTracker.getLastY());
} else {
display.setActivePointerIconVisible(pointerVisible, 0, 0);
}
return true;
}

Expand Down
Expand Up @@ -120,7 +120,11 @@ protected void collectNativeMonitorModesAndDevicesImpl(final MonitorModeProps.Ca
crtc_ids = new int[] { encoder[scridx].getCrtc_id() };
if( null != defaultPointerIcon ) {
final LinuxMouseTracker lmt = LinuxMouseTracker.getSingleton();
setPointerIconActive(defaultPointerIcon.getHandle(), lmt.getLastX(), lmt.getLastY());
if( null != lmt ) {
setPointerIconActive(defaultPointerIcon.getHandle(), lmt.getLastX(), lmt.getLastY());
} else {
setPointerIconActive(defaultPointerIcon.getHandle(), 0, 0);
}
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/newt/classes/jogamp/newt/driver/egl/gbm/WindowDriver.java
Expand Up @@ -347,13 +347,21 @@ protected final void doMouseEvent(final boolean enqueue, final boolean wait, fin
@Override
protected void setPointerIconImpl(final PointerIconImpl pi) {
final ScreenDriver screen = (ScreenDriver) getScreen();
screen.setPointerIconActive(null != pi ? pi.validatedHandle() : 0, mouseTracker.getLastX(), mouseTracker.getLastY());
if( null != mouseTracker ) {
screen.setPointerIconActive(null != pi ? pi.validatedHandle() : 0, mouseTracker.getLastX(), mouseTracker.getLastY());
} else {
screen.setPointerIconActive(null != pi ? pi.validatedHandle() : 0, 0, 0);
}
}

@Override
protected boolean setPointerVisibleImpl(final boolean pointerVisible) {
final ScreenDriver screen = (ScreenDriver) getScreen();
screen.setActivePointerIconVisible(pointerVisible, mouseTracker.getLastX(), mouseTracker.getLastY());
if( null != mouseTracker ) {
screen.setActivePointerIconVisible(pointerVisible, mouseTracker.getLastX(), mouseTracker.getLastY());
} else {
screen.setActivePointerIconVisible(pointerVisible, 0, 0);
}
return true;
}

Expand Down
28 changes: 12 additions & 16 deletions src/newt/classes/jogamp/newt/driver/linux/LinuxKeyEventTracker.java
Expand Up @@ -82,30 +82,24 @@
*/
public class LinuxKeyEventTracker implements WindowListener, KeyTracker {

private static final boolean DISABLE;
private static final boolean ENABLE_PLAIN_EVENTX;
private static final boolean DISABLE = PropertyAccess.isPropertyDefined("newt.disable.LinuxKeyEventTracker", true);
private static final boolean ENABLE_PLAIN_EVENTX = PropertyAccess.isPropertyDefined("newt.enable.LinuxKeyEventTracker.eventx", true);

private static final String linuxDevInputByEventXRoot = "/dev/input/";
private static final String linuxDevInputByIDRoot = "/dev/input/by-id/";
private static final String linuxDevInputByPathRoot = "/dev/input/by-path/";

private static final LinuxKeyEventTracker ledt;

static {
DISABLE = PropertyAccess.isPropertyDefined("newt.disable.LinuxKeyEventTracker", true);
ENABLE_PLAIN_EVENTX = PropertyAccess.isPropertyDefined("newt.enable.LinuxKeyEventTracker.eventx", true);
private static LinuxKeyEventTracker ledt = null;

public static synchronized LinuxKeyEventTracker getSingleton() {
if( !DISABLE ) {
ledt = new LinuxKeyEventTracker();
final Thread t = new InterruptSource.Thread(null, ledt.eventDeviceManager, "NEWT-LinuxEventDeviceManager");
t.setDaemon(true);
t.start();
} else {
ledt = null;
if( null == ledt ) {
ledt = new LinuxKeyEventTracker();
final Thread t = new InterruptSource.Thread(null, ledt.eventDeviceManager, "NEWT-LinuxEventDeviceManager");
t.setDaemon(true);
t.start();
}
}
}

public static LinuxKeyEventTracker getSingleton() {
return ledt;
}

Expand All @@ -124,6 +118,8 @@ public static LinuxKeyEventTracker getSingleton() {
*/
private final Map<String, EventDevicePoller> edpMap = new HashMap<String, EventDevicePoller>();

private LinuxKeyEventTracker() {}

@Override
public void windowResized(final WindowEvent e) { }

Expand Down
24 changes: 11 additions & 13 deletions src/newt/classes/jogamp/newt/driver/linux/LinuxMouseTracker.java
Expand Up @@ -57,22 +57,18 @@
*/
public class LinuxMouseTracker implements WindowListener, MouseTracker {

private static final boolean DISABLE;
private static final LinuxMouseTracker lmt;
private static final boolean DISABLE = PropertyAccess.isPropertyDefined("newt.disable.LinuxMouseTracker", true);
private static LinuxMouseTracker lmt = null;

static {
DISABLE = PropertyAccess.isPropertyDefined("newt.disable.LinuxMouseTracker", true);
public static synchronized LinuxMouseTracker getSingleton() {
if(!DISABLE) {
lmt = new LinuxMouseTracker();
final Thread t = new InterruptSource.Thread(null, lmt.mouseDevicePoller, "NEWT-MouseTracker");
t.setDaemon(true);
t.start();
} else {
lmt = null;
if( null == lmt ) {
lmt = new LinuxMouseTracker();
final Thread t = new InterruptSource.Thread(null, lmt.mouseDevicePoller, "NEWT-MouseTracker");
t.setDaemon(true);
t.start();
}
}
}

public static LinuxMouseTracker getSingleton() {
return lmt;
}

Expand All @@ -88,6 +84,8 @@ public static LinuxMouseTracker getSingleton() {
private WindowImpl focusedWindow = null;
private final MouseDevicePoller mouseDevicePoller = new MouseDevicePoller();

private LinuxMouseTracker() {}

public final int getLastX() { return lastFocusedX; }
public final int getLastY() { return lastFocusedY; }

Expand Down

0 comments on commit 94dbf9b

Please sign in to comment.