Created
September 13, 2021 02:22
-
-
Save LingDong-/7a75ac951e0dada08573144ac9fb0567 to your computer and use it in GitHub Desktop.
applet to create cursor "wormholes" connecting different displays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Wormhole.java | |
// Lingdong Huang 2021, Public domain | |
// Simple app to create "wormholes" connecting different displays: | |
// When cursor enters a black patch, it comes out from the other | |
// Idea inspired by this mac app "Wormhole by Tod LLC": https://macdownload.informer.com/wormhole1/ | |
// I implemented the idea in java to work on Windows | |
// | |
// Usage: | |
// javac Wormhole.java; java Wormhole <x0> <y0> <x1> <y1> | |
// (arguments being the positions of the two holes) | |
// Right-click on a hole to exit app. | |
// Drag hole (slowly) to move it across screen | |
import javax.swing.JFrame; | |
import java.awt.event.MouseListener; | |
import java.awt.event.MouseMotionListener; | |
import java.awt.event.MouseEvent; | |
import java.awt.Robot; | |
import java.awt.AWTException; | |
import java.awt.Color; | |
public class Wormhole { | |
Robot robot; | |
public class Hole extends JFrame implements MouseMotionListener, MouseListener{ | |
Hole other; | |
boolean active = true; | |
Hole (int x, int y){ | |
setType(Type.UTILITY); | |
setUndecorated(true); | |
setVisible(true); | |
setSize(50,50); | |
setLocation(x,y); | |
setAlwaysOnTop(true); | |
addMouseListener(this); | |
addMouseMotionListener(this); | |
getContentPane().setBackground(Color.black); | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
} | |
void setOther(Hole o){ | |
other = o; | |
} | |
public void mouseMoved(MouseEvent e){ | |
// System.out.println(e.getXOnScreen()+","+e.getYOnScreen()); | |
} | |
public void mouseDragged(MouseEvent e){ | |
setLocation(e.getXOnScreen()-getWidth()/2,e.getYOnScreen()-getHeight()/2); | |
} | |
public void mouseClicked(MouseEvent e){ | |
if (e.getButton() == MouseEvent.BUTTON3){ | |
System.exit(0); | |
} | |
} | |
public void mouseEntered(MouseEvent e){ | |
if (!active) return; | |
int x = other.getX() + other.getWidth()/2; | |
int y = other.getY() + other.getHeight()/2; | |
robot.mouseMove(x,y); | |
other.active = false; | |
} | |
public void mouseExited(MouseEvent e){ | |
active = true; | |
} | |
public void mousePressed(MouseEvent e){ | |
} | |
public void mouseReleased(MouseEvent e){ | |
} | |
} | |
Hole f1; | |
Hole f2; | |
Wormhole(int x0, int y0, int x1, int y1){ | |
try{ | |
robot = new Robot(); | |
}catch(AWTException e){} | |
f1 = new Hole(x0,y0); | |
f2 = new Hole(x1,y1); | |
f1.setOther(f2); | |
f2.setOther(f1); | |
} | |
public static void main(String[] args){ | |
int x0 = 1870; try{x0 = Integer.parseInt(args[0]);}catch(Exception e){} | |
int y0 = 800; try{y0 = Integer.parseInt(args[1]);}catch(Exception e){} | |
int x1 = 3200; try{x1 = Integer.parseInt(args[2]);}catch(Exception e){} | |
int y1 = 800; try{y1 = Integer.parseInt(args[3]);}catch(Exception e){} | |
new Wormhole(x0,y0,x1,y1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment