Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add vncviewer option to use large cursor instead of dot #1491

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
52 changes: 43 additions & 9 deletions java/com/tigervnc/vncviewer/OptionsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ protected void processFocusEvent(final FocusEvent e) {

/* Misc. */
JCheckBox sharedCheckbox;
JCheckBox dotWhenNoCursorCheckbox;
JCheckBox alwaysCursorCheckbox;
JCheckBox acceptBellCheckbox;

JComboBox cursorTypeChoice;

/* SSH */
JCheckBox tunnelCheckbox;
JCheckBox viaCheckbox;
Expand Down Expand Up @@ -311,6 +313,7 @@ private void loadOptions()
handleAutoselect();
handleCompression();
handleJpeg();
handleAlwaysCursor();

/* Security */
Security security = new Security(SecurityClient.secTypes);
Expand Down Expand Up @@ -458,7 +461,9 @@ private void loadOptions()

/* Misc. */
sharedCheckbox.setSelected(shared.getValue());
dotWhenNoCursorCheckbox.setSelected(dotWhenNoCursor.getValue());
alwaysCursorCheckbox.setSelected(alwaysCursor.getValue());
String cursorTypeStr = cursorType.getValueStr();
cursorTypeChoice.setSelectedItem(cursorTypeStr);
acceptBellCheckbox.setSelected(acceptBell.getValue());

/* SSH */
Expand Down Expand Up @@ -613,8 +618,9 @@ else if (mediumcolorButton.isSelected())

/* Misc. */
shared.setParam(sharedCheckbox.isSelected());
dotWhenNoCursor.setParam(dotWhenNoCursorCheckbox.isSelected());
alwaysCursor.setParam(alwaysCursorCheckbox.isSelected());
acceptBell.setParam(acceptBellCheckbox.isSelected());
cursorType.setParam((String)cursorTypeChoice.getSelectedItem());

/* SSH */
tunnel.setParam(tunnelCheckbox.isSelected());
Expand Down Expand Up @@ -1173,31 +1179,54 @@ private JPanel createMiscPanel() {
MiscPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
sharedCheckbox =
new JCheckBox("Shared (don't disconnect other viewers)");
dotWhenNoCursorCheckbox = new JCheckBox("Show dot when no cursor");
alwaysCursorCheckbox = new JCheckBox("Show local cursor when not provided by server");
alwaysCursorCheckbox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
handleAlwaysCursor();
}
});
JLabel cursorTypeLabel = new JLabel("Cursor type:");
String[] cursorTypes = {"Dot", "System"};
cursorTypeChoice = new MyJComboBox(cursorTypes);
cursorTypeChoice.setPrototypeDisplayValue("System.");
acceptBellCheckbox = new JCheckBox("Beep when requested by the server");
MiscPanel.add(sharedCheckbox,
new GridBagConstraints(0, 0,
1, 1,
REMAINDER, 1,
LIGHT, LIGHT,
LINE_START, NONE,
new Insets(0, 0, 4, 0),
NONE, NONE));
MiscPanel.add(dotWhenNoCursorCheckbox,
MiscPanel.add(alwaysCursorCheckbox,
new GridBagConstraints(0, 1,
1, 1,
REMAINDER, 1,
LIGHT, LIGHT,
LINE_START, NONE,
new Insets(0, 0, 4, 0),
NONE, NONE));
MiscPanel.add(acceptBellCheckbox,
MiscPanel.add(cursorTypeLabel,
new GridBagConstraints(0, 2,
1, 1,
LIGHT, LIGHT,
LINE_START, NONE,
new Insets(0, 0, 4, 0),
NONE, NONE));
MiscPanel.add(Box.createRigidArea(new Dimension(5, 0)),
MiscPanel.add(cursorTypeChoice,
new GridBagConstraints(1, 2,
1, 1,
LIGHT, LIGHT,
LINE_START, NONE,
new Insets(0, 5, 4, 0),
NONE, NONE));
MiscPanel.add(acceptBellCheckbox,
new GridBagConstraints(0, 3,
REMAINDER, 1,
LIGHT, LIGHT,
LINE_START, NONE,
new Insets(0, 0, 4, 0),
NONE, NONE));
MiscPanel.add(Box.createRigidArea(new Dimension(5, 0)),
new GridBagConstraints(0, 4,
REMAINDER, REMAINDER,
HEAVY, HEAVY,
LINE_START, BOTH,
Expand Down Expand Up @@ -1633,5 +1662,10 @@ private void handleRfbState()
}
}

private void handleAlwaysCursor()
{
cursorTypeChoice.setEnabled(alwaysCursorCheckbox.isSelected());
}

static LogWriter vlog = new LogWriter("OptionsDialog");
}
83 changes: 57 additions & 26 deletions java/com/tigervnc/vncviewer/Parameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,19 @@ public class Parameters {

public static BoolParameter dotWhenNoCursor
= new BoolParameter("DotWhenNoCursor",
"Show the dot cursor when the server sends an invisible cursor",
"[DEPRECATED] Show the dot cursor when the server sends an invisible cursor",
false);

public static BoolParameter alwaysCursor
= new BoolParameter("AlwaysCursor",
"Show the local cursor when the server sends an invisible cursor",
false);

public static StringParameter cursorType
= new StringParameter("CursorType",
"Specify which cursor type the local cursor should be. Should be either Dot or System",
"Dot");

public static BoolParameter sendLocalUsername
= new BoolParameter("SendLocalUsername",
"Send the local username for SecurityTypes "+
Expand Down Expand Up @@ -282,7 +292,8 @@ public class Parameters {
CSecurityTLS.X509CA,
CSecurityTLS.X509CRL,
SecurityClient.secTypes,
dotWhenNoCursor,
alwaysCursor,
cursorType,
autoSelect,
fullColor,
lowColorLevel,
Expand Down Expand Up @@ -315,6 +326,10 @@ public class Parameters {
sshKeyFile,
};

static VoidParameter[] readOnlyParameterArray = {
dotWhenNoCursor
};


static LogWriter vlog = new LogWriter("Parameters");

Expand Down Expand Up @@ -447,29 +462,35 @@ public static String loadViewerParameters(String filename) throws Exception {
invalidParameterName = false;
} else {
for (int i = 0; i < parameterArray.length; i++) {
if (parameterArray[i] instanceof StringParameter) {
if (line.substring(0,idx).trim().equalsIgnoreCase(parameterArray[i].getName())) {
VoidParameter parameter;
if (i < parameterArray.length) {
parameter = parameterArray[i];
} else {
parameter = readOnlyParameterArray[i - parameterArray.length];
}
if (parameter instanceof StringParameter) {
if (line.substring(0,idx).trim().equalsIgnoreCase(parameter.getName())) {
if (value.length() > 256) {
vlog.error(String.format("Failed to read line %d in file %s: %s",
lineNr, filepath, "Invalid format or too large value"));
continue;
}
((StringParameter)parameterArray[i]).setParam(value);
((StringParameter)parameter).setParam(value);
invalidParameterName = false;
}
} else if (parameterArray[i] instanceof IntParameter) {
if (line.substring(0,idx).trim().equalsIgnoreCase(parameterArray[i].getName())) {
((IntParameter)parameterArray[i]).setParam(value);
} else if (parameter instanceof IntParameter) {
if (line.substring(0,idx).trim().equalsIgnoreCase(parameter.getName())) {
((IntParameter)parameter).setParam(value);
invalidParameterName = false;
}
} else if (parameterArray[i] instanceof BoolParameter) {
if (line.substring(0,idx).trim().equalsIgnoreCase(parameterArray[i].getName())) {
((BoolParameter)parameterArray[i]).setParam(value);
} else if (parameter instanceof BoolParameter) {
if (line.substring(0,idx).trim().equalsIgnoreCase(parameter.getName())) {
((BoolParameter)parameter).setParam(value);
invalidParameterName = false;
}
} else {
vlog.error(String.format("Unknown parameter type for parameter %s",
parameterArray[i].getName()));
parameter.getName()));

}
}
Expand Down Expand Up @@ -517,6 +538,10 @@ public static void saveToReg(String servername) {
}
}

for (int i = 0; i < readOnlyParameterArray.length; i++) {
UserPreferences.delete(hKey, readOnlyParameterArray[i].getName());
}

UserPreferences.save(hKey);
}

Expand All @@ -528,28 +553,34 @@ public static String loadFromReg() {
if (servername == null)
servername = "";

for (int i = 0; i < parameterArray.length; i++) {
if (parameterArray[i] instanceof StringParameter) {
if (UserPreferences.get(hKey, parameterArray[i].getName()) != null) {
for (int i = 0; i < parameterArray.length + readOnlyParameterArray.length; i++) {
VoidParameter parameter;
if (i < parameterArray.length) {
parameter = parameterArray[i];
} else {
parameter = readOnlyParameterArray[i - parameterArray.length];
}
if (parameter instanceof StringParameter) {
if (UserPreferences.get(hKey, parameter.getName()) != null) {
String stringValue =
UserPreferences.get(hKey, parameterArray[i].getName());
((StringParameter)parameterArray[i]).setParam(stringValue);
UserPreferences.get(hKey, parameter.getName());
((StringParameter)parameter).setParam(stringValue);
}
} else if (parameterArray[i] instanceof IntParameter) {
if (UserPreferences.get(hKey, parameterArray[i].getName()) != null) {
} else if (parameter instanceof IntParameter) {
if (UserPreferences.get(hKey, parameter.getName()) != null) {
int intValue =
UserPreferences.getInt(hKey, parameterArray[i].getName());
((IntParameter)parameterArray[i]).setParam(intValue);
UserPreferences.getInt(hKey, parameter.getName());
((IntParameter)parameter).setParam(intValue);
}
} else if (parameterArray[i] instanceof BoolParameter) {
if (UserPreferences.get(hKey, parameterArray[i].getName()) != null) {
} else if (parameter instanceof BoolParameter) {
if (UserPreferences.get(hKey, parameter.getName()) != null) {
boolean booleanValue =
UserPreferences.getBool(hKey, parameterArray[i].getName());
((BoolParameter)parameterArray[i]).setParam(booleanValue);
UserPreferences.getBool(hKey, parameter.getName());
((BoolParameter)parameter).setParam(booleanValue);
}
} else {
vlog.error(String.format("Unknown parameter type for parameter %s",
parameterArray[i].getName()));
parameter.getName()));
}
}

Expand Down
5 changes: 5 additions & 0 deletions java/com/tigervnc/vncviewer/UserPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ public static void load(String nName) {
}
}

public static void delete(String nName, String key) {
Preferences node = root.node(nName);
node.remove(key);
}

static LogWriter vlog = new LogWriter("UserPreferences");
}

17 changes: 14 additions & 3 deletions java/com/tigervnc/vncviewer/Viewport.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,15 @@ public void setCursor(int width, int height, Point hotspot,
for (i = 0; i < width*height; i++)
if (data[i*4 + 3] != 0) break;

if ((i == width*height) && dotWhenNoCursor.getValue()) {
vlog.debug("cursor is empty - using dot");
useSystemCursor = false;
if ((i == width*height) && alwaysCursor.getValue()) {
String cursorTypeStr = cursorType.getValueStr();
if (cursorTypeStr.matches("^System$")) {
useSystemCursor = true;
} else {
vlog.debug("cursor is empty - using dot");
}
// Do this anyway to prevent cursor being null
cursor = new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB_PRE);
cursor.setRGB(0, 0, 5, 5, dotcursor_xpm, 0, 5);
cursorHotspot.x = cursorHotspot.y = 3;
Expand Down Expand Up @@ -216,7 +223,10 @@ private void setCursor(Image img, int x, int y)

hotspot = new java.awt.Point(x, y);
softCursor = tk.createCustomCursor(img, hotspot, name);
setCursor(softCursor);
if (useSystemCursor)
setCursor(java.awt.Cursor.getDefaultCursor());
else
setCursor(softCursor);
}

public void resize(int x, int y, int w, int h) {
Expand Down Expand Up @@ -830,6 +840,7 @@ public DownMap(int capacity) {
float scaleRatioX, scaleRatioY;

static BufferedImage cursor;
static boolean useSystemCursor = false;
Point cursorHotspot = new Point();

}
11 changes: 11 additions & 0 deletions java/com/tigervnc/vncviewer/VncViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ public VncViewer(String[] argv) {

// Check if the server name in reality is a configuration file
potentiallyLoadConfigurationFile(vncServerName);

migrateDeprecatedOptions();
}

public static void usage() {
Expand Down Expand Up @@ -449,6 +451,15 @@ public void run() {
}
}

static void migrateDeprecatedOptions() {
if (dotWhenNoCursor.getValue()) {
vlog.info("DotWhenNoCursor is deprecated, set AlwaysCursor to 1 and CursorType to 'Dot' instead");

alwaysCursor.setParam(true);
cursorType.setParam("Dot");
}
}

public static CConn cc;
public static StringParameter config
= new StringParameter("Config",
Expand Down
Loading
Loading