Skip to content

Commit

Permalink
Implement rpc interface for setting external GUI features
Browse files Browse the repository at this point in the history
Add handler for GUI option rpc notifications. Currently, only tabline is
handled.

Add signal for when nvim updates the value of ext_tabline and a matching
slot to control visibility of the gui tabline.

Add GuiTabline ex command to nvim_gui_shim.vim to enable and disable the GUI
tabline. Document in runtime/doc/nvim_gui_shim.txt and README.md.
  • Loading branch information
Joseph R. Nosie authored and equalsraf committed Jul 31, 2018
1 parent faef696 commit a250faf
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 19 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Commands for interacting with the GUI are regular commands, available in the doc

:Guifont DejaVu Sans Mono:h13

To disable the GUI tabline and use the nvim TUI tabline, call

:GuiTabline 0

You can set GUI options on startup, in the GUI configuration file (:help ginit.vim).

## Development
Expand Down
50 changes: 31 additions & 19 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,24 @@ void MainWindow::init(NeovimConnector *c)
m_nvim->deleteLater();
}

if (m_shell_options.enable_ext_tabline) {
m_tabline_bar = addToolBar("tabline");
m_tabline_bar->setObjectName("tabline");
m_tabline_bar->setAllowedAreas(Qt::TopToolBarArea);
m_tabline_bar->setMovable(false);
m_tabline_bar->setFloatable(false);
// Avoid margins around the tabbar
m_tabline_bar->layout()->setContentsMargins(0, 0, 0, 0);

m_tabline = new QTabBar(m_tabline_bar);
m_tabline->setDrawBase(false);
m_tabline->setExpanding(false);
m_tabline->setDocumentMode(true);
m_tabline->setFocusPolicy(Qt::NoFocus);
connect(m_tabline, &QTabBar::currentChanged,
this, &MainWindow::changeTab);

m_tabline_bar->addWidget(m_tabline);
}
m_tabline_bar = addToolBar("tabline");
m_tabline_bar->setObjectName("tabline");
m_tabline_bar->setAllowedAreas(Qt::TopToolBarArea);
m_tabline_bar->setMovable(false);
m_tabline_bar->setFloatable(false);
// Avoid margins around the tabbar
m_tabline_bar->layout()->setContentsMargins(0, 0, 0, 0);

m_tabline = new QTabBar(m_tabline_bar);
m_tabline->setDrawBase(false);
m_tabline->setExpanding(false);
m_tabline->setDocumentMode(true);
m_tabline->setFocusPolicy(Qt::NoFocus);
connect(m_tabline, &QTabBar::currentChanged,
this, &MainWindow::changeTab);

m_tabline_bar->addWidget(m_tabline);
m_tabline_bar->setVisible(m_shell_options.enable_ext_tabline);

m_nvim = c;
m_shell = new Shell(c, m_shell_options);
Expand All @@ -72,6 +71,8 @@ void MainWindow::init(NeovimConnector *c)
this, &MainWindow::neovimError);
connect(m_shell, &Shell::neovimIsUnsupported,
this, &MainWindow::neovimIsUnsupported);
connect(m_shell, &Shell::neovimExtTablineSet,
this, &MainWindow::extTablineSet);
connect(m_shell, &Shell::neovimTablineUpdate,
this, &MainWindow::neovimTablineUpdate);
connect(m_shell, &Shell::neovimShowtablineSet,
Expand Down Expand Up @@ -243,6 +244,17 @@ Shell* MainWindow::shell()
return m_shell;
}

void MainWindow::extTablineSet(bool val)
{
bool old = m_shell_options.enable_ext_tabline;
m_shell_options.enable_ext_tabline = val;
// redraw if state changed
if (old != m_shell_options.enable_ext_tabline) {
if (!val) m_tabline_bar->setVisible(false);
m_nvim->api0()->vim_command("silent! redraw!");
}
}

void MainWindow::neovimShowtablineSet(int val)
{
m_shell_options.nvim_show_tabline = val;
Expand Down
1 change: 1 addition & 0 deletions src/gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private slots:
void neovimIsUnsupported();
void neovimShowtablineSet(int);
void neovimTablineUpdate(int64_t curtab, QList<Tab> tabs);
void extTablineSet(bool);
void changeTab(int index);
private:
void init(NeovimConnector *);
Expand Down
3 changes: 3 additions & 0 deletions src/gui/runtime/doc/nvim_gui_shim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ GuiLinespace When called with no arguments this command displays the
linespace, the number of extra pixels each line will have.
A single argument is accepted as the new linespace height.

*GuiTabline*
GuiTabline Enable or disable the external GUI tabline


==============================================================================
2. GUI variables
Expand Down
5 changes: 5 additions & 0 deletions src/gui/runtime/plugin/nvim_gui_shim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ function s:GuiLinespaceCommand(height) abort
endfunction
command! -nargs=? GuiLinespace call s:GuiLinespaceCommand("<args>")

function! s:GuiTabline(enable) abort
call rpcnotify(0, 'Gui', 'Option', 'Tabline', a:enable)
endfunction
command! -nargs=1 GuiTabline call s:GuiTabline(<args>)

" GuiDrop('file1', 'file2', ...) is similar to :drop file1 file2 ...
" but it calls fnameescape() over all arguments
function GuiDrop(...)
Expand Down
18 changes: 18 additions & 0 deletions src/gui/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,9 @@ void Shell::handleNeovimNotification(const QByteArray &name, const QVariantList&
} else if (guiEvName == "Close" && args.size() == 1) {
qDebug() << "Neovim requested a GUI close";
emit neovimGuiCloseRequest();
} else if (guiEvName == "Option" && args.size() >= 3) {
QString option = m_nvim->decode(args.at(1).toByteArray());
handleExtGuiOption(option, args.at(2));
}
return;
} else if (name != "redraw") {
Expand Down Expand Up @@ -586,6 +589,19 @@ void Shell::handleNeovimNotification(const QByteArray &name, const QVariantList&
}
}

void Shell::handleExtGuiOption(const QString& name, const QVariant& value)
{
if (!m_nvim->api2()) return;
if (name == "Tabline") {
m_nvim->api2()->nvim_ui_set_option("ext_tabline", value.toBool());
} else if (name == "Popupmenu") {
} else if (name == "Cmdline") {
} else if (name == "Wildmenu") {
} else {
qDebug() << "Unknown GUI Option" << name << value;
}
}

void Shell::handleSetOption(const QString& name, const QVariant& value)
{
if (name == "guifont") {
Expand All @@ -598,6 +614,8 @@ void Shell::handleSetOption(const QString& name, const QVariant& value)
setLineSpace(value.toString().toInt());
} else if (name == "showtabline") {
emit neovimShowtablineSet(value.toString().toInt());
} else if (name == "ext_tabline") {
emit neovimExtTablineSet(value.toBool());
} else {
qDebug() << "Received unknown option" << name << value;
}
Expand Down
2 changes: 2 additions & 0 deletions src/gui/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Shell: public ShellWidget
void neovimGuiCloseRequest();
/// This signal is emmited if the running neovim version is unsupported by the GUI
void neovimIsUnsupported();
void neovimExtTablineSet(bool);
/// The tabline needs updating. curtab is the handle of the current tab (not its index)
/// as seen in Tab::tab.
void neovimTablineUpdate(int64_t curtab, QList<Tab> tabs);
Expand Down Expand Up @@ -116,6 +117,7 @@ protected slots:
virtual void handleSetScrollRegion(const QVariantList& opargs);
virtual void handleBusy(bool);
virtual void handleSetOption(const QString& name, const QVariant& value);
void handleExtGuiOption(const QString& name, const QVariant& value);

void neovimMouseEvent(QMouseEvent *ev);
virtual void mousePressEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
Expand Down
15 changes: 15 additions & 0 deletions test/tst_shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ private slots:
checkStartVars(c);
}

void guiExtTablineSet() {
QStringList args;
args << "-u" << "NONE";
NeovimConnector *c = NeovimConnector::spawn(args);
Shell *s = new Shell(c, ShellOptions());
QSignalSpy onOptionSet(s, &Shell::neovimExtTablineSet);
QVERIFY(onOptionSet.isValid());
QVERIFY(SPYWAIT(onOptionSet));
}

void guiShimCommands() {
// This function needs to be able to find the GUI runtime
// plugin or this test WILL FAIL
Expand Down Expand Up @@ -113,6 +123,11 @@ private slots:
checkCommand(c, "GuiFont DejaVu Sans Mono:h14:b:l", false);
QCOMPARE(s->shell()->fontDesc(), QString("DejaVu Sans Mono:h14:l"));
#endif
QSignalSpy onOptionSet(s->shell(), &Shell::neovimExtTablineSet);
checkCommand(c, "GuiTabline 0");
QVERIFY(onOptionSet.isValid());
QVERIFY(SPYWAIT(onOptionSet));
qDebug() << onOptionSet << onOptionSet.size();
}

protected:
Expand Down

0 comments on commit a250faf

Please sign in to comment.