head7 avatar head7 committed ea7d0e5

Add blinking cursor support

Comments (0)

Files changed (5)

  * Start the cursor blinking.  If it was already blinking, this restarts the
  * waiting time and shows the cursor.
  *
- * FIXME: We dont blink, we simply update the cursor
  */
 void
 gui_mch_start_blink()
 {
-	gui_update_cursor(TRUE, FALSE);
+	vimshell->startBlinking();
 }
 
 /**
  * Start the cursor blinking.
  *
- * FIXME: We dont blink, we simply update the cursor
  */
 void
 gui_mch_stop_blink()
 {
+	vimshell->stopBlinking();
 	gui_update_cursor(TRUE, FALSE);
 }
 
 }
 
 /**
+ * Set blinking time duration 
  *
- * FIXME: We dont blink
  */
 void
 gui_mch_set_blinking(long waittime, long on, long off)
 {
+	vimshell->setBlinkTime(waittime, on, off);
 }
 
 /**

src/qt/qvimshell.cpp

 #include <QApplication>
 #include <QDebug>
 #include <QFile>
+#include <QTimer>
 
 extern "C" {
 #include "proto/gui.pro"
 	m_mouseHidden(false)
 {
 	setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+
+	// cursor blinking
+	timer_cursorBlinkOn = new QTimer();
+	timer_cursorBlinkOff = new QTimer();
+	timer_firstOff = new QTimer();
+	timer_firstOn = new QTimer();
+	timer_firstOn->setSingleShot(true);
+	timer_firstOff->setSingleShot(true);
+	blinkState = BLINK_NONE;
+	connect(timer_cursorBlinkOn, SIGNAL(timeout()), this, SLOT(cursorOn()));
+	connect(timer_firstOn, SIGNAL(timeout()), this, SLOT(startBlinkOnTimer()));
+	connect(timer_firstOff, SIGNAL(timeout()), this, SLOT(startBlinkOffTimer()));
+	connect(timer_cursorBlinkOff, SIGNAL(timeout()), this, SLOT(cursorOff()));
+
 	// IM Tooltip
 	m_tooltip = new QLabel(this);
 	m_tooltip->setVisible(false);
 	}
 }
 
+
+void QVimShell::setBlinkTime(const long waittime, const long ontime, const long offtime)
+{
+	m_blinkWaitTime = waittime;
+	m_blinkOnTime = ontime;
+	m_blinkOffTime = offtime;
+}
+
+/*
+ * start blinking: show cursor for waitingtime then blink
+ */
+void QVimShell::startBlinking()
+{
+	if (m_blinkWaitTime && m_blinkOnTime && m_blinkOffTime && hasFocus())
+	{
+		// wait waitTime before starting the blink
+		timer_cursorBlinkOn->stop();
+		timer_cursorBlinkOff->stop();
+		timer_firstOff->stop();
+		timer_firstOn->stop();
+
+		timer_firstOff->start(m_blinkWaitTime);
+		cursorOn();
+	}
+}
+
+void QVimShell::startBlinkOnTimer()
+{
+	if (blinkState == BLINK_OFF) // if blinkstate == NONE do nothing
+	{
+		timer_cursorBlinkOn->start(m_blinkOnTime+m_blinkOffTime);
+		cursorOn();
+	}
+}
+
+void QVimShell::startBlinkOffTimer()
+{
+	if (blinkState == BLINK_ON) // if blinkstate == NONE do nothing
+	{
+		timer_firstOn->start(m_blinkOffTime);
+		timer_cursorBlinkOff->start(m_blinkOnTime+m_blinkOffTime);
+		cursorOff();
+	}
+}
+
+
+/*
+ * Stop cursor blinking
+ */
+void QVimShell::stopBlinking()
+{
+	blinkState = BLINK_NONE;
+	timer_cursorBlinkOn->stop();
+	timer_cursorBlinkOff->stop();
+	timer_firstOn->stop();
+	timer_firstOff->stop();
+}
+
+void QVimShell::cursorOff()
+{
+	blinkState = BLINK_OFF;
+	vim.undrawCursor();
+}
+
+void QVimShell::cursorOn()
+{
+	blinkState = BLINK_ON;
+	vim.updateCursor(true, false);
+}

src/qt/qvimshell.h

 	virtual QVariant inputMethodQuery(Qt::InputMethodQuery);
 	void setSlowStringDrawing(bool slow) {m_slowStringDrawing = slow;}
 
+	void setBlinkTime(const long waittime, const long ontime, const long offtime);
+
+	void stopBlinking();
+	void startBlinking();
+
+
 public slots:
 	void setBackground(const QColor);
 	void setCharWidth(int);
 	virtual void leaveEvent(QEvent *ev);
 	virtual void enterEvent(QEvent *ev);
 	bool focusNextPrevChild(bool next);
+
+private slots:
+	void cursorOff();
+	void cursorOn();
+	void startBlinkOffTimer();
+	void startBlinkOnTimer();
+
 private:
 	QColor m_background;
 	int m_charWidth;
 	QFont m_font;
 
+	QTimer * timer_cursorBlinkOn ;
+	QTimer * timer_cursorBlinkOff ;
+	QTimer * timer_firstOff;
+	QTimer * timer_firstOn;
+
+
 	long m_blinkWaitTime, m_blinkOnTime, m_blinkOffTime;
 
 	enum blink_state{BLINK_NONE, BLINK_ON, BLINK_OFF};

src/qt/vimwrapper.cpp

 	send_tabline_event(ev);
 }
 
+void VimWrapper::updateCursor(bool force, bool clearsel)
+{
+	gui_update_cursor( force ? TRUE: FALSE,
+				clearsel ? TRUE: FALSE);
+}
+
+void VimWrapper::undrawCursor()
+{
+	gui_undraw_cursor();
+}
+
 void VimWrapper::sendTablineMenuEvent(int idx, int ev)
 {
 	send_tabline_menu_event(idx, ev);

src/qt/vimwrapper.h

 	void sendTablineEvent(int);
 	void sendTablineMenuEvent(int, int);
 
+	void updateCursor(bool force, bool clearsel);
+	void undrawCursor();
+
 	static void setFullscreen(bool on);
 
 protected:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.