From: Pierre Ossman Date: Tue, 24 May 2011 12:47:12 +0000 (+0000) Subject: Handling a full range of keys for the menu key is not as trivial in FLTK as X-Git-Tag: v1.1.90~334 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4e7271e060c2b0c9be9649692f0c608604ea545a;p=tigervnc.git 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 8fe7eecf..7a2cf2ed 100644 --- a/vncviewer/OptionsDialog.cxx +++ b/vncviewer/OptionsDialog.cxx @@ -253,11 +253,22 @@ void OptionsDialog::loadOptions(void) #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 @@ void OptionsDialog::storeOptions(void) 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 @@ void OptionsDialog::createInputPage(int tx, int ty, int tw, int th) _("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 ea958595..d4994699 100644 --- a/vncviewer/OptionsDialog.h +++ b/vncviewer/OptionsDialog.h @@ -26,6 +26,7 @@ #include #include #include +#include typedef void (OptionsCallback)(void*); @@ -104,6 +105,7 @@ protected: 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 1d90f066..4470a31e 100644 --- a/vncviewer/Viewport.cxx +++ b/vncviewer/Viewport.cxx @@ -79,6 +79,10 @@ Viewport::Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_) contextMenu = new Fl_Menu_Button(0, 0, 0, 0); initContextMenu(); + + setMenuKey(); + + OptionsDialog::addCallback(handleOptions, this); } @@ -94,6 +98,8 @@ Viewport::~Viewport() Fl::remove_clipboard_notify(handleClipboardChange); #endif + OptionsDialog::removeCallback(handleOptions); + delete frameBuffer; if (pixelTrans) @@ -249,7 +255,7 @@ int Viewport::handle(int event) 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 @@ int Viewport::handle(int event) 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::handleKeyEvent(int keyCode, int origKeyCode, const char *keyText, 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 @@ void Viewport::popupContextMenu() 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 @@ void Viewport::popupContextMenu() 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 24d0f3c0..f3f60be9 100644 --- a/vncviewer/Viewport.h +++ b/vncviewer/Viewport.h @@ -104,6 +104,10 @@ private: void initContextMenu(); void popupContextMenu(); + void setMenuKey(); + + static void handleOptions(void *data); + private: CConn* cc; @@ -120,6 +124,7 @@ private: typedef std::map DownMap; DownMap downKeySym; + int menuKeyCode; Fl_Menu_Button *contextMenu; }; diff --git a/vncviewer/fltk_layout.h b/vncviewer/fltk_layout.h index 61dea211..c16a359f 100644 --- a/vncviewer/fltk_layout.h +++ b/vncviewer/fltk_layout.h @@ -99,6 +99,10 @@ static inline int fltk_escape(const char *in, char *out, size_t maxlen) #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