Commits

equalsraf  committed 7de9c6a

Support fullscreen mode

- This commit adds support for fullscreen mode
as in MacVim/Writeroom mode. When the window is placed
in this mode, the shell widget can be resized(lines/columns)
and it will remain centered in the window.
- Enable fullscreen with :set (no)fu
- Added 'fuoptions' option - currently does nothing
- Good support is dependant on the Window Manager, some X11
window managers are known to ignore the fullscreen hint.
* Issue#50

  • Participants
  • Parent commits 5e4ec7c

Comments (0)

Files changed (11)

File src/CMakeLists.txt

 		qt/vimaction.cpp 
 		qt/vimscrollbar.cpp 
 		qt/vimwrapper.cpp 
-		qt/fontdialog.cpp)
+		qt/fontdialog.cpp
+		qt/scrollarea.cpp)
 
 set(QVIM_RCS qt/icons.qrc)
 QT4_ADD_RESOURCES( QVIM_RC_SRCS ${QVIM_RCS} )

File src/Makefile

 MOC		= $(QT_MOC)
 QT_LIBS1	= $(QT_LIBS)
 QT_SRC	= gui.c gui_qt.cpp pty.c gui_beval.c \
-			qt/qvimshell.cpp qt/mainwindow.cpp qt/vimaction.cpp qt/vimscrollbar.cpp \
+			qt/qvimshell.cpp qt/mainwindow.cpp qt/vimaction.cpp qt/scrollarea.cpp \
 			qt/fontdialog.cpp \
-			qt/vimwrapper.cpp qt/tabbar.cpp
+			qt/vimwrapper.cpp qt/tabbar.cpp qt/vimscrollbar.cpp
 QT_OBJ	= objects/gui.o objects/gui_qt.o \
 			objects/pty.o objects/gui_beval.o \
 			objects/mainwindow.o objects/qvimshell.o objects/vimaction.o objects/qtresources.o \
-			objects/vimscrollbar.o objects/fontdialog.o objects/vimwrapper.o \
-			objects/tabbar.o
+			objects/scrollarea.o objects/fontdialog.o objects/vimwrapper.o \
+			objects/tabbar.o objects/vimscrollbar.o
 
 QT_DEFS	= -DFEAT_GUI_QT $(NARROW_PROTO) -Iqt -I. $(QT_INCPATH)
 QT_IPATH	= $(GUI_INC_LOC)
 	$(MOC) qt/vimscrollbar.h > vimscrollbar.moc
 	$(CXX) $(ALL_CFLAGS) -o $@ -c qt/vimscrollbar.cpp
 
+objects/scrollarea.o: qt/scrollarea.cpp
+	$(MOC) qt/scrollarea.h > scrollarea.moc
+	$(CXX) $(ALL_CFLAGS) -o $@ -c qt/scrollarea.cpp
+
 objects/vimgui.o: qt/vimgui.cpp
 	$(MOC) qt/vimgui.h > vimgui.moc
 	$(CXX) $(ALL_CFLAGS) -o $@ -c qt/vimgui.cpp

File src/gui_qt.cpp

 	window->setWindowState( window->windowState() & ~Qt::WindowFullScreen );
 }
 
+void gui_mch_update_fuoptions(char_u *optstr)
+{
+	//
+	// FIXME: We don't support fuopts at this point
+	// set fuoptions=maxvert,maxhoriz
+
+}
+
 /**
  * Raise application window
  */
 		new_height = desktopSize.height() - decoHeight;
 	}
 
-	window->resize( new_width, new_height );
+	if (window->windowState() & Qt::WindowFullScreen ) {
+		// In fullscreen mode, resize the widget
+		vimshell->setMaximumSize(width, height);
+	} else {
+		window->resize( new_width, new_height );
+	}
 	gui_resize_shell(vimshell->size().width(), vimshell->size().height());
 
 	// SHOCKING: it seems gui_get_shellsize() updates the proper values for

File src/option.c

 #endif
 			    SCRIPTID_INIT},
 
+    {"fuoptions",  "fuopt", P_STRING|P_COMMA|P_NODUP|P_VI_DEF,
+#ifdef FEAT_FULLSCREEN
+			    (char_u *)&p_fuoptions, PV_NONE,
+			    {(char_u *)"", (char_u *)0L}
+#else
+			    (char_u *)NULL, PV_NONE,
+			    {(char_u *)NULL, (char_u *)0L}
+#endif
+			    SCRIPTID_INIT},
+
+
     {"gdefault",    "gd",   P_BOOL|P_VI_DEF|P_VIM,
 			    (char_u *)&p_gd, PV_NONE,
 			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
     }
 #endif
 
+#ifdef FEAT_FULLSCREEN
+    /* 'fuoptions' */
+    else if (varp == &p_fuoptions)
+    {
+        gui_mch_update_fuoptions(p_fuoptions);
+    }
+#endif
+
 #ifdef FEAT_VIRTUALEDIT
     /* 'virtualedit' */
     else if (varp == &p_ve)

File src/option.h

 #endif
 #ifdef FEAT_FULLSCREEN
 EXTERN int	p_fullscreen;	/* fullscreen gui window */
+EXTERN char_u	*p_fuoptions;	/* fullscreen options */
 #endif
 EXTERN int	p_gd;		/* 'gdefault' */
 #ifdef FEAT_PRINTER

File src/qt/mainwindow.cpp

 	toolbar->setObjectName("toolbar");
 
 	// Vim shell
-	vimshell = new QVimShell();
-	setCentralWidget(vimshell);
+	vimshell = new QVimShell(this);
+
+	scrollarea = new ScrollArea(this);
+	scrollarea->setWidget(vimshell);
+	connect(vimshell, SIGNAL(backgroundColorChanged(QColor)),
+		scrollarea, SLOT(setBackgroundColor(QColor)) );
+
+	setCentralWidget(scrollarea);
 
 	// TabLine
 	tabtoolbar = addToolBar("tabline");
 {
 	if (ev->type() == QEvent::WindowStateChange) {
 		VimWrapper::setFullscreen( windowState() & Qt::WindowFullScreen );
+
+		if ( ! (windowState() & Qt::WindowFullScreen) ) {
+			// Reset vimshell size policy when leaving fullscreen
+			vimshell->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
+			vimshell->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+			vimshell->updateGeometry();
+		}
 	}
 	QMainWindow::changeEvent(ev);
 }

File src/qt/mainwindow.h

 #include <QtGui>
 #include "qvimshell.h"
 #include "tabbar.h"
+#include "scrollarea.h"
+
 
 class MainWindow: public QMainWindow
 {
 private:
 	QToolBar *toolbar;
 
+	ScrollArea *scrollarea;
 	QVimShell *vimshell;
 	QToolBar *tabtoolbar;
 	TabBar *tabbar;

File src/qt/qvimshell.cpp

 	m_lastClickEvent(-1), m_tooltip(0), m_slowStringDrawing(false),
 	m_mouseHidden(false)
 {
-
+	setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 	// IM Tooltip
 	m_tooltip = new QLabel(this);
 	m_tooltip->setVisible(false);
 void QVimShell::setBackground(const QColor color)
 {
 	m_background = color;
+	emit backgroundColorChanged(m_background);
 }
 
 void QVimShell::switchTab(int idx)

File src/qt/qvimshell.h

 	void switchTab(int idx);
 	void closeTab(int idx);
 
+signals:
+	void backgroundColorChanged(const QColor&);
+
 protected:
 	void flushPaintOps();
 

File src/qt/scrollarea.cpp

+#include "scrollarea.moc"
+
+#include <QtGui>
+
+ScrollArea::ScrollArea(QWidget *parent)
+:QWidget(parent), m_widget(NULL)
+{
+	setAutoFillBackground(true);
+	m_layout = new QGridLayout(this);
+	m_layout->setSpacing(0);
+	m_layout->setContentsMargins(0,0,0,0);
+	m_layout->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
+}
+
+void ScrollArea::setWidget(QWidget *w)
+{
+	if ( w == m_widget || !w ) {
+		return;
+	}
+
+	m_widget = w;
+	m_layout->addWidget(m_widget, 0, 1);
+}
+
+void ScrollArea::setBackgroundColor(const QColor& c)
+{
+	QPalette p = palette();
+	p.setColor(QPalette::Window, c);
+	setPalette(p);
+}
+

File src/qt/scrollarea.h

+#ifndef VIM_GUI_QT_SCROLLAREA
+#define VIM_GUI_QT_SCROLLAREA
+
+#include <QWidget>
+#include <QGridLayout>
+
+class ScrollArea: public QWidget
+{
+	Q_OBJECT
+public:
+	ScrollArea(QWidget *parent=0);
+	void setWidget(QWidget *widget);
+
+public slots:
+	void setBackgroundColor(const QColor&);
+
+private:
+	QWidget *m_widget;
+	QGridLayout *m_layout;
+
+};
+
+#endif