Handling a full range of keys for the menu key is not as trivial in FLTK as
with raw X11, so do what the Windows client did and restrict the available
keys to just the function keys.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4444 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/vncviewer/OptionsDialog.cxx b/vncviewer/OptionsDialog.cxx
index 8fe7eec..7a2cf2e 100644
--- a/vncviewer/OptionsDialog.cxx
+++ b/vncviewer/OptionsDialog.cxx
@@ -253,11 +253,22 @@
#endif
/* Input */
+ const char *menuKeyBuf;
+
viewOnlyCheckbox->value(viewOnly);
acceptClipboardCheckbox->value(acceptClipboard);
sendClipboardCheckbox->value(sendClipboard);
sendPrimaryCheckbox->value(sendPrimary);
+ menuKeyChoice->value(0);
+
+ menuKeyBuf = menuKey;
+ if (menuKeyBuf[0] == 'F') {
+ int num = atoi(menuKeyBuf+1);
+ if ((num >= 1) && (num <= 12))
+ menuKeyChoice->value(num);
+ }
+
/* Misc. */
sharedCheckbox->value(shared);
fullScreenCheckbox->value(fullScreen);
@@ -342,6 +353,14 @@
sendClipboard.setParam(sendClipboardCheckbox->value());
sendPrimary.setParam(sendPrimaryCheckbox->value());
+ if (menuKeyChoice->value() == 0)
+ menuKey.setParam("");
+ else {
+ char buf[16];
+ sprintf(buf, "F%d", menuKeyChoice->value());
+ menuKey.setParam(buf);
+ }
+
/* Misc. */
shared.setParam(sharedCheckbox->value());
fullScreen.setParam(fullScreenCheckbox->value());
@@ -664,6 +683,17 @@
_("Send primary selection and cut buffer as clipboard")));
ty += CHECK_HEIGHT + TIGHT_MARGIN;
+ menuKeyChoice = new Fl_Choice(LBLLEFT(tx, ty, 150, CHOICE_HEIGHT, _("Menu key")));
+
+ menuKeyChoice->add(_("None"), 0, NULL, (void*)0, FL_MENU_DIVIDER);
+ for (int i = 1;i <= 12;i++) {
+ char buf[16];
+ sprintf(buf, "F%d", i);
+ menuKeyChoice->add(buf, 0, NULL, (void*)i, 0);
+ }
+
+ ty += CHOICE_HEIGHT + TIGHT_MARGIN;
+
group->end();
}
diff --git a/vncviewer/OptionsDialog.h b/vncviewer/OptionsDialog.h
index ea95859..d499469 100644
--- a/vncviewer/OptionsDialog.h
+++ b/vncviewer/OptionsDialog.h
@@ -26,6 +26,7 @@
#include <FL/Fl_Check_Button.H>
#include <FL/Fl_Round_Button.H>
#include <FL/Fl_Int_Input.H>
+#include <FL/Fl_Choice.H>
typedef void (OptionsCallback)(void*);
@@ -104,6 +105,7 @@
Fl_Check_Button *acceptClipboardCheckbox;
Fl_Check_Button *sendClipboardCheckbox;
Fl_Check_Button *sendPrimaryCheckbox;
+ Fl_Choice *menuKeyChoice;
/* Misc. */
Fl_Check_Button *sharedCheckbox;
diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx
index 1d90f06..4470a31 100644
--- a/vncviewer/Viewport.cxx
+++ b/vncviewer/Viewport.cxx
@@ -79,6 +79,10 @@
contextMenu = new Fl_Menu_Button(0, 0, 0, 0);
initContextMenu();
+
+ setMenuKey();
+
+ OptionsDialog::addCallback(handleOptions, this);
}
@@ -94,6 +98,8 @@
Fl::remove_clipboard_notify(handleClipboardChange);
#endif
+ OptionsDialog::removeCallback(handleOptions);
+
delete frameBuffer;
if (pixelTrans)
@@ -249,7 +255,7 @@
return 1;
case FL_KEYDOWN:
- if (Fl::event_key() == (FL_F + 8)) {
+ if (menuKeyCode && (Fl::event_key() == menuKeyCode)) {
popupContextMenu();
return 1;
}
@@ -259,6 +265,9 @@
return 1;
case FL_KEYUP:
+ if (menuKeyCode && (Fl::event_key() == menuKeyCode))
+ return 1;
+
handleKeyEvent(Fl::event_key(), Fl::event_original_key(),
Fl::event_text(), false);
return 1;
@@ -557,15 +566,20 @@
void Viewport::initContextMenu()
{
+ contextMenu->clear();
+
contextMenu->add(_("Exit viewer"), 0, NULL, (void*)ID_EXIT, FL_MENU_DIVIDER);
contextMenu->add(_("Ctrl"), 0, NULL, (void*)ID_CTRL, FL_MENU_TOGGLE);
contextMenu->add(_("Alt"), 0, NULL, (void*)ID_ALT, FL_MENU_TOGGLE);
- CharArray menuKeyStr(menuKey.getData());
- CharArray sendMenuKey(64);
- snprintf(sendMenuKey.buf, 64, _("Send %s"), "F8"); // FIXME
- contextMenu->add(sendMenuKey.buf, 0, NULL, (void*)ID_MENUKEY, 0);
- contextMenu->add("Secret shortcut menu key", FL_F + 8, NULL, (void*)ID_MENUKEY, FL_MENU_INVISIBLE);
+
+ if (menuKeyCode) {
+ char sendMenuKey[64];
+ snprintf(sendMenuKey, 64, _("Send %s"), (const char *)menuKey);
+ contextMenu->add(sendMenuKey, 0, NULL, (void*)ID_MENUKEY, 0);
+ contextMenu->add("Secret shortcut menu key", menuKeyCode, NULL, (void*)ID_MENUKEY, FL_MENU_INVISIBLE);
+ }
+
contextMenu->add(_("Send Ctrl-Alt-Del"), 0, NULL, (void*)ID_CTRLALTDEL, FL_MENU_DIVIDER);
contextMenu->add(_("Refresh screen"), 0, NULL, (void*)ID_REFRESH, FL_MENU_DIVIDER);
@@ -603,9 +617,8 @@
break;
case ID_MENUKEY:
if (!viewOnly) {
- // FIXME
- cc->writer()->keyEvent(XK_F8, true);
- cc->writer()->keyEvent(XK_F8, false);
+ handleKeyEvent(menuKeyCode, menuKeyCode, "", true);
+ handleKeyEvent(menuKeyCode, menuKeyCode, "", false);
}
break;
case ID_CTRLALTDEL:
@@ -638,3 +651,30 @@
break;
}
}
+
+
+void Viewport::setMenuKey()
+{
+ const char *menuKeyStr;
+
+ menuKeyCode = 0;
+
+ menuKeyStr = menuKey;
+ if (menuKeyStr[0] == 'F') {
+ int num = atoi(menuKeyStr + 1);
+ if ((num >= 1) && (num <= 12))
+ menuKeyCode = FL_F + num;
+ }
+
+ // Need to repopulate the context menu as it contains references to
+ // the menu key
+ initContextMenu();
+}
+
+
+void Viewport::handleOptions(void *data)
+{
+ Viewport *self = (Viewport*)data;
+
+ self->setMenuKey();
+}
diff --git a/vncviewer/Viewport.h b/vncviewer/Viewport.h
index 24d0f3c..f3f60be 100644
--- a/vncviewer/Viewport.h
+++ b/vncviewer/Viewport.h
@@ -104,6 +104,10 @@
void initContextMenu();
void popupContextMenu();
+ void setMenuKey();
+
+ static void handleOptions(void *data);
+
private:
CConn* cc;
@@ -120,6 +124,7 @@
typedef std::map<int, rdr::U32> DownMap;
DownMap downKeySym;
+ int menuKeyCode;
Fl_Menu_Button *contextMenu;
};
diff --git a/vncviewer/fltk_layout.h b/vncviewer/fltk_layout.h
index 61dea21..c16a359 100644
--- a/vncviewer/fltk_layout.h
+++ b/vncviewer/fltk_layout.h
@@ -99,6 +99,10 @@
#define CHECK_MIN_WIDTH RADIO_MIN_WIDTH
#define CHECK_HEIGHT RADIO_HEIGHT
+/* Fl_Choice */
+
+#define CHOICE_HEIGHT INPUT_HEIGHT
+
/* Fl_Group */
#define GROUP_LABEL_OFFSET FL_NORMAL_SIZE
#define GROUP_MARGIN 12