Skip to content

Commit

Permalink
Add local cursor selection for C++ version
Browse files Browse the repository at this point in the history
This adds the option to select which cursor should be used in the event the server sends an invisible cursor. It also renames the DotWhenNoCursor config option to LocalCursor.
  • Loading branch information
krystof1119 committed Jun 30, 2024
1 parent 60962a9 commit fcdb8d9
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 17 deletions.
70 changes: 64 additions & 6 deletions vncviewer/OptionsDialog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,13 @@ void OptionsDialog::loadOptions(void)
/* Misc. */
sharedCheckbox->value(shared);
reconnectCheckbox->value(reconnectOnError);
dotCursorCheckbox->value(dotWhenNoCursor);
localCursorCheckbox->value(localCursor);
if (!strcasecmp(cursorType, "dot")) {
dotCursorButton->setonly();
} else {
systemCursorButton->setonly();
}
handleLocalCursor(localCursorCheckbox, this);
}


Expand Down Expand Up @@ -486,7 +492,13 @@ void OptionsDialog::storeOptions(void)
/* Misc. */
shared.setParam(sharedCheckbox->value());
reconnectOnError.setParam(reconnectCheckbox->value());
dotWhenNoCursor.setParam(dotCursorCheckbox->value());
localCursor.setParam(localCursorCheckbox->value());

if (dotCursorButton->value()) {
cursorType.setParam("Dot");
} else {
cursorType.setParam("System");
}

std::map<OptionsCallback*, void*>::const_iterator iter;

Expand Down Expand Up @@ -835,11 +847,46 @@ void OptionsDialog::createInputPage(int tx, int ty, int tw, int th)
_("Emulate middle mouse button")));
ty += CHECK_HEIGHT + TIGHT_MARGIN;

dotCursorCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
CHECK_MIN_WIDTH,
CHECK_HEIGHT,
_("Show dot when no cursor")));
localCursorCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
CHECK_MIN_WIDTH,
CHECK_HEIGHT,
_("Show local cursor when not provided by server")));
localCursorCheckbox->callback(handleLocalCursor, this);
ty += CHECK_HEIGHT + TIGHT_MARGIN;

/* Cursor type box */
ty += GROUP_LABEL_OFFSET;
cursorGroup = new Fl_Group(tx, ty, width, 0, _("Cursor type"));
cursorGroup->box(FL_FLAT_BOX);
cursorGroup->labelfont(FL_BOLD);
cursorGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);

{
tx += INDENT;
ty += TIGHT_MARGIN;

dotCursorButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
RADIO_MIN_WIDTH,
RADIO_HEIGHT,
"Dot cursor"));
dotCursorButton->type(FL_RADIO_BUTTON);
ty += RADIO_HEIGHT + TIGHT_MARGIN;

systemCursorButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
RADIO_MIN_WIDTH,
RADIO_HEIGHT,
"System cursor"));
systemCursorButton->type(FL_RADIO_BUTTON);
ty += RADIO_HEIGHT + TIGHT_MARGIN;
}

ty -= TIGHT_MARGIN;

cursorGroup->end();
/* Needed for resize to work sanely */
cursorGroup->resizable(nullptr);
cursorGroup->size(cursorGroup->w(), ty - cursorGroup->y());

}
ty -= TIGHT_MARGIN;

Expand Down Expand Up @@ -1181,3 +1228,14 @@ void OptionsDialog::handleScreenConfigTimeout(void *data)

self->monitorArrangement->value(fullScreenSelectedMonitors.getParam());
}

void OptionsDialog::handleLocalCursor(Fl_Widget* /*widget*/, void *data)
{
OptionsDialog *dialog = (OptionsDialog*)data;

if (dialog->localCursorCheckbox->value()) {
dialog->cursorGroup->activate();
} else {
dialog->cursorGroup->deactivate();
}
}
6 changes: 5 additions & 1 deletion vncviewer/OptionsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class OptionsDialog : public Fl_Window {
static void handleAutoselect(Fl_Widget *widget, void *data);
static void handleCompression(Fl_Widget *widget, void *data);
static void handleJpeg(Fl_Widget *widget, void *data);
static void handleLocalCursor(Fl_Widget *widget, void *data);

static void handleX509(Fl_Widget *widget, void *data);
static void handleRSAAES(Fl_Widget *widget, void *data);
Expand Down Expand Up @@ -115,7 +116,10 @@ class OptionsDialog : public Fl_Window {
Fl_Check_Button *viewOnlyCheckbox;
Fl_Group *mouseGroup;
Fl_Check_Button *emulateMBCheckbox;
Fl_Check_Button *dotCursorCheckbox;
Fl_Check_Button *localCursorCheckbox;
Fl_Group *cursorGroup;
Fl_Round_Button *dotCursorButton;
Fl_Round_Button *systemCursorButton;
Fl_Group *keyboardGroup;
Fl_Check_Button *systemKeysCheckbox;
Fl_Choice *menuKeyChoice;
Expand Down
11 changes: 8 additions & 3 deletions vncviewer/Viewport.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void Viewport::setCursor(int width, int height, const Point& hotspot,
for (i = 0; i < width*height; i++)
if (data[i*4 + 3] != 0) break;

if ((i == width*height) && dotWhenNoCursor) {
if ((i == width*height) && localCursor && !strcasecmp("dot", cursorType)) {
vlog.debug("cursor is empty - using dot");

Fl_Pixmap pxm(dotcursor_xpm);
Expand All @@ -279,8 +279,13 @@ void Viewport::setCursor(int width, int height, const Point& hotspot,
}
}

if (Fl::belowmouse() == this)
window()->cursor(cursor, cursorHotspot.x, cursorHotspot.y);
if (Fl::belowmouse() == this) {
if ((i == width*height) && localCursor && !strcasecmp("system", cursorType)) {
window()->cursor(FL_CURSOR_DEFAULT);
} else {
window()->cursor(cursor, cursorHotspot.x, cursorHotspot.y);
}
}
}

void Viewport::handleClipboardRequest()
Expand Down
12 changes: 8 additions & 4 deletions vncviewer/parameters.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ BoolParameter emulateMiddleButton("EmulateMiddleButton",
"Emulate middle mouse button by pressing "
"left and right mouse buttons simultaneously",
false);
BoolParameter dotWhenNoCursor("DotWhenNoCursor",
"Show the dot cursor when the server sends an "
"invisible cursor", false);
BoolParameter localCursor("LocalCursor",
"Show the local cursor when the server sends an "
"invisible cursor", false);
StringParameter cursorType("CursorType", "Specify which cursor type the local cursor should be. "
"Should be either Dot or System",
"Dot");

BoolParameter alertOnFatalError("AlertOnFatalError",
"Give a dialog on connection problems rather "
Expand Down Expand Up @@ -198,7 +201,8 @@ static VoidParameter* parameterArray[] = {
/* Input */
&viewOnly,
&emulateMiddleButton,
&dotWhenNoCursor,
&localCursor,
&cursorType,
&acceptClipboard,
&sendClipboard,
#if !defined(WIN32) && !defined(__APPLE__)
Expand Down
3 changes: 2 additions & 1 deletion vncviewer/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@

extern rfb::IntParameter pointerEventInterval;
extern rfb::BoolParameter emulateMiddleButton;
extern rfb::BoolParameter dotWhenNoCursor;
extern rfb::BoolParameter localCursor;
extern rfb::StringParameter cursorType;

extern rfb::StringParameter passwordFile;

Expand Down
10 changes: 8 additions & 2 deletions vncviewer/vncviewer.man
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,14 @@ Use specified lossless compression level. 0 = Low, 9 = High. Default is 2.
Use custom compression level. Default if \fBCompressLevel\fP is specified.
.
.TP
.B \-DotWhenNoCursor
Show the dot cursor when the server sends an invisible cursor. Default is off.
.B \-LocalCursor
Show a local cursor when the server sends an invisible cursor. Default is off.
.
.TP
.B \-CursorType \fItype\fP
Specify which cursor type to use when a local cursor is shown. It should be
either "Dot", or "System". Ignored if LocalCursor is off.
The default is "Dot".
.
.TP
.B \-PointerEventInterval \fItime\fP
Expand Down

0 comments on commit fcdb8d9

Please sign in to comment.