Skip to content

Commit

Permalink
Viewer: Add view-only mode menu entries + hotkeys
Browse files Browse the repository at this point in the history
(ported from the Windows TurboVNC Viewer)

Refer to #135
  • Loading branch information
dcommander committed Oct 11, 2021
1 parent 2e68dad commit 62d59e4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ specified in the "Security" tab.
- Settings under the "Security" tab are now automatically disabled when
they are rendered irrelevant by other settings.

28. Added an F8 menu option, a Mac menu option, and corresponding hotkeys
(CTRL-ALT-SHIFT-V and Command-V) to the TurboVNC Viewer that allow view-only
mode to be toggled more quickly. This functionality previously only existed in
the Windows TurboVNC Viewer.


2.2.7
=====
Expand Down
10 changes: 10 additions & 0 deletions java/com/turbovnc/vncviewer/CConn.java
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,8 @@ else if (reconfigure)
viewport.showToolbar(opts.showToolbar);
menu.showToolbar.setSelected(opts.showToolbar);
}
if (opts.viewOnly != oldOpts.viewOnly)
menu.viewOnly.setSelected(opts.viewOnly);
if (deleteRestore) {
savedState = -1;
savedRect = new Rectangle(-1, -1, 0, 0);
Expand Down Expand Up @@ -1683,6 +1685,14 @@ public void toggleFullScreen() {
recreateViewport(true);
}

// EDT
public void toggleViewOnly() {
opts.viewOnly = !opts.viewOnly;
menu.viewOnly.setSelected(opts.viewOnly);
if (viewport != null && opts.showToolbar && !opts.fullScreen)
recreateViewport(true);
}

// EDT
public void resize(int x, int y, int w, int h) {
if (viewport != null) {
Expand Down
3 changes: 3 additions & 0 deletions java/com/turbovnc/vncviewer/DesktopWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,9 @@ public void keyPressed(KeyEvent e) {
case KeyEvent.VK_T:
cc.toggleToolbar();
return;
case KeyEvent.VK_V:
cc.toggleViewOnly();
return;
case KeyEvent.VK_X:
VncViewer.tileWindows();
return;
Expand Down
11 changes: 9 additions & 2 deletions java/com/turbovnc/vncviewer/F8Menu.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
* Copyright (C) 2011, 2013 Brian P. Hinz
* Copyright (C) 2012-2015, 2017-2018, 2020-2021 D. R. Commander.
* All Rights Reserved.
* All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -76,6 +76,11 @@ public F8Menu(CConn cc_) {
tileWindows = addMenuItem("Tile All Viewer Windows (Ctrl-Alt-Shift-X)",
KeyEvent.VK_X);
addSeparator();
viewOnly = new JCheckBoxMenuItem("View Only (Ctrl-Alt-Shift-V)");
viewOnly.setMnemonic(KeyEvent.VK_V);
viewOnly.setSelected(cc.opts.viewOnly);
viewOnly.addActionListener(this);
add(viewOnly);
if (Utils.osGrab() && Helper.isAvailable()) {
grabKeyboard =
new JCheckBoxMenuItem("Grab Keyboard (Ctrl-Alt-Shift-G)");
Expand Down Expand Up @@ -156,6 +161,8 @@ public void actionPerformed(ActionEvent ev) {
VncViewer.tileWindows();
} else if (actionMatch(ev, clipboard)) {
cc.clipboardDialog.showDialog(cc.viewport);
} else if (actionMatch(ev, viewOnly)) {
cc.toggleViewOnly();
} else if (actionMatch(ev, grabKeyboard)) {
if (cc.viewport != null)
cc.viewport.grabKeyboardHelper(grabKeyboard.isSelected());
Expand Down Expand Up @@ -209,7 +216,7 @@ public void actionPerformed(ActionEvent ev) {
JMenuItem exit, clipboard, ctrlAltDel, ctrlEsc, refresh, losslessRefresh;
JMenuItem newConn, options, info, profile, screenshot, about, dismiss;
static JMenuItem f8;
JCheckBoxMenuItem fullScreen, showToolbar, grabKeyboard;
JCheckBoxMenuItem fullScreen, showToolbar, viewOnly, grabKeyboard;

static LogWriter vlog = new LogWriter("F8Menu");
}
11 changes: 10 additions & 1 deletion java/com/turbovnc/vncviewer/MacMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ public MacMenuBar(CConn cc_) {
showToolbar.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T,
acceleratorMask));
connMenu.addSeparator();
viewOnly = new JCheckBoxMenuItem("View Only");
viewOnly.setSelected(cc.opts.viewOnly);
viewOnly.addActionListener(this);
connMenu.add(viewOnly);
viewOnly.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,
acceleratorMask));
if (!Params.restricted.getValue()) {
ctrlAltDel = addMenuItem(connMenu, "Send Ctrl-Alt-Del");
ctrlEsc = addMenuItem(connMenu, "Send Ctrl-Esc");
Expand Down Expand Up @@ -187,6 +193,9 @@ public void actionPerformed(ActionEvent ev) {
} else if (actionMatch(ev, showToolbar)) {
cc.toggleToolbar();
showToolbar.setSelected(cc.opts.showToolbar);
} else if (actionMatch(ev, viewOnly)) {
cc.toggleViewOnly();
viewOnly.setSelected(cc.opts.viewOnly);
} else if (actionMatch(ev, clipboard)) {
cc.clipboardDialog.showDialog(cc.viewport);
} else if (actionMatch(ev, ctrlAltDel) && !cc.opts.viewOnly) {
Expand Down Expand Up @@ -234,6 +243,6 @@ void updateProfile() {
JMenuItem defaultSize, tileWindows;
JMenuItem clipboard, ctrlAltDel, ctrlEsc, refresh, losslessRefresh;
JMenuItem newConn, closeConn, info, screenshot;
JCheckBoxMenuItem profile, fullScreen, showToolbar;
JCheckBoxMenuItem profile, fullScreen, showToolbar, viewOnly;
static LogWriter vlog = new LogWriter("MacMenuBar");
}

0 comments on commit 62d59e4

Please sign in to comment.