]> source.dussan.org Git - tigervnc.git/commitdiff
Initial support for context menu, based on Unix vncviewer code.
authorPierre Ossman <ossman@cendio.se>
Fri, 29 Apr 2011 11:08:11 +0000 (11:08 +0000)
committerPierre Ossman <ossman@cendio.se>
Fri, 29 Apr 2011 11:08:11 +0000 (11:08 +0000)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4390 3789f03b-4d11-0410-bbf8-ca57d06f2519

vncviewer/Viewport.cxx
vncviewer/Viewport.h

index 4d8bd2a5f9beebec834f80050e3d55124836c748..bb5c94e6766390eb5b0533aa49e0127f19d12911 100644 (file)
@@ -54,6 +54,10 @@ extern void exit_vncviewer();
 
 static rfb::LogWriter vlog("Viewport");
 
+// Menu constants
+
+enum { ID_EXIT, ID_CTRL, ID_ALT, ID_MENUKEY, ID_CTRLALTDEL, ID_DISMISS };
+
 Viewport::Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_)
   : Fl_Widget(0, 0, w, h), cc(cc_), frameBuffer(NULL), pixelTrans(NULL),
     lastPointerPos(0, 0), lastButtonMask(0)
@@ -62,6 +66,9 @@ Viewport::Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_)
   assert(frameBuffer);
 
   setServerPF(serverPF);
+
+  contextMenu = new Fl_Menu_Button(0, 0, 0, 0);
+  initContextMenu();
 }
 
 
@@ -77,6 +84,9 @@ Viewport::~Viewport()
 
   if (pixelTrans)
     delete pixelTrans;
+
+  // FLTK automatically deletes all child widgets, so we shouldn't touch
+  // them ourselves here
 }
 
 
@@ -206,6 +216,11 @@ int Viewport::handle(int event)
     return 1;
 
   case FL_KEYDOWN:
+    if (Fl::event_key() == (FL_F + 8)) {
+      popupContextMenu();
+      return 1;
+    }
+
     handleKeyEvent(Fl::event_key(), Fl::event_compose_symbol(), true);
     return 1;
 
@@ -487,3 +502,66 @@ void Viewport::handleKeyEvent(int keyCode, const char *keyText, bool down)
   downKeySym[keyCode] = keySym;
   cc->writer()->keyEvent(keySym, down);
 }
+
+
+void Viewport::initContextMenu()
+{
+  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); // Broken, see STR2613
+  contextMenu->add(_("Send Ctrl-Alt-Del"), 0, NULL, (void*)ID_CTRLALTDEL, FL_MENU_DIVIDER);
+
+  contextMenu->add(_("Dismiss menu"), 0, NULL, (void*)ID_DISMISS, 0);
+}
+
+
+void Viewport::popupContextMenu()
+{
+  const Fl_Menu_Item *m;
+
+  contextMenu->position(Fl::event_x(), Fl::event_y());
+
+  m = contextMenu->popup();
+  if (m == NULL)
+    return;
+
+  switch (m->argument()) {
+  case ID_EXIT:
+    exit_vncviewer();
+    break;
+  case ID_CTRL:
+    if (!viewOnly)
+      cc->writer()->keyEvent(XK_Control_L, m->value());
+    break;
+  case ID_ALT:
+    if (!viewOnly)
+      cc->writer()->keyEvent(XK_Alt_L, m->value());
+    break;
+  case ID_MENUKEY:
+    if (!viewOnly) {
+      // FIXME
+      cc->writer()->keyEvent(XK_F8, true);
+      cc->writer()->keyEvent(XK_F8, false);
+    }
+    break;
+  case ID_CTRLALTDEL:
+    if (!viewOnly) {
+      cc->writer()->keyEvent(XK_Control_L, true);
+      cc->writer()->keyEvent(XK_Alt_L, true);
+      cc->writer()->keyEvent(XK_Delete, true);
+      cc->writer()->keyEvent(XK_Delete, false);
+      cc->writer()->keyEvent(XK_Alt_L, false);
+      cc->writer()->keyEvent(XK_Control_L, false);
+    }
+    break;
+  case ID_DISMISS:
+    // Don't need to do anything
+    break;
+  }
+}
index d8a584ae2912df979ef64f446219cd9bde1d9730..58ac30ed7443a869b453fa36ed4136b3317b3ae3 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <FL/Fl.H>
 #include <FL/Fl_Widget.H>
+#include <FL/Fl_Menu_Button.H>
 
 #include <rfb/Rect.h>
 #include <rfb/Region.h>
@@ -98,6 +99,9 @@ private:
   rdr::U32 translateKeyEvent(int keyCode, const char *keyText);
   void handleKeyEvent(int keyCode, const char *keyText, bool down);
 
+  void initContextMenu();
+  void popupContextMenu();
+
 private:
   CConn* cc;
 
@@ -113,6 +117,8 @@ private:
 
   typedef std::map<int, rdr::U32> DownMap;
   DownMap downKeySym;
+
+  Fl_Menu_Button *contextMenu;
 };
 
 #endif