]> granicus.if.org Git - nethack/commitdiff
Qt: ^V on OSX
authorPatR <rankin@nethack.org>
Fri, 8 Jan 2021 09:37:38 +0000 (01:37 -0800)
committerPatR <rankin@nethack.org>
Fri, 8 Jan 2021 09:37:38 +0000 (01:37 -0800)
I can't take credit for this and still have no idea why it is
needed, but it fixes use of ^V as a command and as input to
to the regular version of yn_function().  In particular, '&'
command reports it as ^V.  Unfortunately when 'popup_dialog' is
set, no control characters seem to be accepted by the part of
NetHackQtYnDialog(Exec+KeyPressEvent) responsible for arbitrary
input.

It also causes getlin() to terminate but I can't think of any
situation where ^V would be considered to be valid input for
getlin() so won't worry about that.

I put it in as '#if MACOSX' because I don't know whether any
other Qt platforms need it.

doc/fixes37.0
win/Qt/Qt-issues.txt
win/Qt/qt_main.cpp
win/Qt/qt_main.h

index 471fe3c960529be7bbccd2e9beffef74e0b5620c..5f22a55025902ce07ac165e5edf869b7b0c8c018 100644 (file)
@@ -1,4 +1,4 @@
-NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.423 $ $NHDT-Date: 1609977590 2021/01/06 23:59:50 $
+NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.424 $ $NHDT-Date: 1610098651 2021/01/08 09:37:31 $
 
 General Fixes and Modified Features
 -----------------------------------
@@ -591,7 +591,7 @@ Qt: {maybe just Qt+OSX:} when viewing a text window ('V' to look at 'history'
        for instance), clicking on [Search], entering a search target in the
        resulting popup and clicking on [Okay] or typing <return>, the text
        window got pushed underneath the main window so seemed to go away
-Qt+OSX: fix control key
+Qt+OSX: fix control key (fixed all except for ^V); handle ^V as a shortcut key
 Qt+OSX: rename menu entry "nethack->Preferences..." for invoking nethack's
        'O' command to "Game->Run-time options" and entry "Game->Qt settings"
        for making persistent Qt customizations to "nethack->Preferences..."
index 01f5e6cc5b1356be3ae73c42d4b08e4d9922fc17..a7418f984e1b22e2343b092d0c0b4de140507af4 100644 (file)
@@ -40,10 +40,6 @@ On OSX, command+Q while a menu (which has its own key event handler)
 is popped up gets ignored.  It should at least close the popup like
 ESC and maybe also initiate quitting.
 
-On the map, ^V is a dead key (at least on OSX; all other ASCII control
-characters from ^A through ^U, ^W through ^Z, and ^[, ^\, ^], ^^, ^_
-work; no attempt to have ^@ generate NUL has been made).
-
 Map column #0, which the core reserves for its own purposes and isn't
 intended to be displayed, is displayed (as blank terrain).
 
index cb2eade3d1aa22ea19101225089183181bd6df2a..f3bca10a1d2af86ac1433be19e85c8c0a5d39864 100644 (file)
@@ -10,6 +10,8 @@ extern "C" {
 
 #include "qt_pre.h"
 #include <QtGui/QtGui>
+#include <QtWidgets/QShortcut>
+
 #if QT_VERSION >= 0x050000
 #include <QtWidgets/QtWidgets>
 #endif
@@ -548,6 +550,13 @@ NetHackQtMainWindow::NetHackQtMainWindow(NetHackQtKeyBuffer& ks) :
      *  setMenuRole() can be used to override this behavior.
      */
 #endif
+
+#ifdef CTRL_V_HACK
+    // NetHackQtBind::notify() sees all control characters except for ^V
+    QShortcut *c_V = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_V), this);
+    connect(c_V, &QShortcut::activated, this, &NetHackQtMainWindow::CtrlV);
+#endif
+
     QMenu* game=new QMenu;
     QMenu* apparel=new QMenu;
     QMenu* act1=new QMenu;
@@ -889,6 +898,20 @@ NetHackQtMainWindow::NetHackQtMainWindow(NetHackQtKeyBuffer& ks) :
     }
 }
 
+#ifdef CTRL_V_HACK
+#ifndef C
+#define C(c) (0x1f & (c))
+#endif
+
+// called when ^V is typed while the main window has keyboard focus;
+// all other control characters go through NetHackQtBind::notify()
+void NetHackQtMainWindow::CtrlV()
+{
+    static const char cV[] = { C('V'), '\0' };
+    doKeys(cV);
+}
+#endif
+
 // add a toolbar button to invoke command 'name' via function '(*func)()'
 void NetHackQtMainWindow::AddToolButton(QToolBar *toolbar, QSignalMapper *sm,
                                         const char *name, int NDECL((*func)),
index 1b4441ec9a3794a43b9c7750476c1fb214ec995b..3f8c9f400933abaae8333adf3f0dfdb668b8509d 100644 (file)
 // [Used in qt_bind.cpp and qt_main.cpp, but not referenced in qt_stat.cpp.]
 #define DYNAMIC_STATUSLINES
 
+// NetHackQtBind::notify() doesn't see ^V on OSX
+#ifdef MACOSX
+#define CTRL_V_HACK
+#endif
+
 namespace nethack_qt_ {
 
 class NetHackQtInvUsageWindow;
@@ -83,6 +88,9 @@ private slots:
        void zoomMap();
        void raiseMessages();
        void raiseStatus();
+#ifdef CTRL_V_HACK
+        void CtrlV();
+#endif
 
 private:
        void ShowIfReady();