Skip to content

Commit

Permalink
Merge pull request #177 from equalsraf/tb-mousehide
Browse files Browse the repository at this point in the history
Implement mousehide
  • Loading branch information
equalsraf authored Sep 25, 2016
2 parents 390cbce + 59acaaf commit 2831d3f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/gui/runtime/doc/neovim_gui_shim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ g:GuiFont holds the current GUI font name, the same value used by
g:GuiLinespace holds the extra vertical space (in pixels) added to
each line.

*g:GuiMousehide*
g:GuiMousehide is 1 if mouse hiding is in effect, 0 otherwise.

==============================================================================
3. Functions
Expand Down Expand Up @@ -114,6 +116,11 @@ GuiDrop(...) is a wrapper around |:drop| it escapes all given arguments
using |fnameescape()| and then passes them to :drop. This is useful if
the GUI is requesting Neovim to open additional files.

*GuiMousehide()*
GuiMousehide(enabled) enables mouse hiding while typing. If enabled is
1, as soon as the user types the mouse cursor is concealed. When the
user moves the mouse, the cursor becomes visible. Replaces |'mousehide'|.

==============================================================================
4. Internals

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 @@ -30,6 +30,11 @@ function! GuiLinespace(height) abort
call rpcnotify(0, 'Gui', 'Linespace', a:height)
endfunction

" Configure mouse hide behaviour (1 is enabled, 0 disabled)
function! GuiMousehide(enabled) abort
call rpcnotify(0, 'Gui', 'Mousehide', a:enabled)
endfunction

" The GuiFont command. For compatibility there is also Guifont
function s:GuiFontCommand(fname, bang) abort
if a:fname ==# ''
Expand Down
15 changes: 12 additions & 3 deletions src/gui/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace NeovimQt {
Shell::Shell(NeovimConnector *nvim, QWidget *parent)
:ShellWidget(parent), m_attached(false), m_nvim(nvim),
m_font_bold(false), m_font_italic(false), m_font_underline(false), m_font_undercurl(false),
m_mouseHide(true),
m_hg_foreground(Qt::black), m_hg_background(Qt::white), m_hg_special(QColor()),
m_cursor_color(Qt::white), m_cursor_pos(0,0), m_insertMode(false),
m_resizing(false),
Expand Down Expand Up @@ -399,9 +400,9 @@ void Shell::handleRedraw(const QByteArray& name, const QVariantList& opargs)
} else if (name == "set_scroll_region"){
handleSetScrollRegion(opargs);
} else if (name == "mouse_on"){
this->unsetCursor();
// See :h mouse
} else if (name == "mouse_off"){
this->setCursor(Qt::ForbiddenCursor);
// See :h mouse
} else if (name == "mode_change"){
if (opargs.size() != 1) {
qWarning() << "Unexpected argument for change_mode:" << opargs;
Expand Down Expand Up @@ -499,6 +500,10 @@ void Shell::handleNeovimNotification(const QByteArray &name, const QVariantList&
setLineSpace(val);
m_nvim->neovimObject()->vim_set_var("GuiLinespace", val);
resizeNeovim(size());
} else if (guiEvName == "Mousehide" && args.size() == 2) {
m_mouseHide = variant_not_zero(args.at(1));
int val = m_mouseHide ? 1 : 0;
m_nvim->neovimObject()->vim_set_var("GuiMousehide", val);
}
return;
} else if (name != "redraw") {
Expand Down Expand Up @@ -567,7 +572,10 @@ void Shell::keyPressEvent(QKeyEvent *ev)
return;
}

// FIXME mousehide - conceal mouse pointer when typing
// conceal mouse pointer when typing
if (m_mouseHide) {
this->setCursor(Qt::BlankCursor);
}

QString inp = Input.convertKey(ev->text(), ev->key(), ev->modifiers());
if (inp.isEmpty()) {
Expand Down Expand Up @@ -643,6 +651,7 @@ void Shell::mouseReleaseEvent(QMouseEvent *ev)
}
void Shell::mouseMoveEvent(QMouseEvent *ev)
{
unsetCursor();
QPoint pos(ev->x()/cellSize().width(),
ev->y()/cellSize().height());
if (pos != m_mouse_pos) {
Expand Down
1 change: 1 addition & 0 deletions src/gui/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ private slots:

QRect m_scroll_region;
bool m_font_bold, m_font_italic, m_font_underline, m_font_undercurl;
bool m_mouseHide;

// highlight fg/bg - from redraw:highlightset - by default we
// use the values from above
Expand Down

0 comments on commit 2831d3f

Please sign in to comment.