[vlc-devel] [RFC PATCH 1/1] qt: provide option to put Qt interface on top of other windows

Pierre Lamot pierre at videolabs.io
Tue Nov 7 11:43:42 CET 2017


  The main use case is to keep UI on top while playing audio.

  - add UI on top in simple pref
  - add UI on top in "view" menu
  - remove video on top from simple pref
  - remove video on top from "video" menu
---
 modules/gui/qt/components/simple_preferences.cpp |  2 +-
 modules/gui/qt/main_interface.cpp                | 24 +++++++++++++
 modules/gui/qt/main_interface.hpp                |  3 ++
 modules/gui/qt/menus.cpp                         |  7 ++--
 modules/gui/qt/qt.cpp                            |  4 +++
 modules/gui/qt/ui/sprefs_interface.ui            | 17 ++++++---
 modules/gui/qt/ui/sprefs_video.ui                | 44 +++++++++---------------
 7 files changed, 66 insertions(+), 35 deletions(-)

diff --git a/modules/gui/qt/components/simple_preferences.cpp b/modules/gui/qt/components/simple_preferences.cpp
index 218630896f..d3b8ce67ba 100644
--- a/modules/gui/qt/components/simple_preferences.cpp
+++ b/modules/gui/qt/components/simple_preferences.cpp
@@ -351,7 +351,6 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
                      ui.videoZone, setEnabled( bool ) );
 
             CONFIG_BOOL( "fullscreen", fullscreen );
-            CONFIG_BOOL( "video-on-top", alwaysOnTop );
             CONFIG_BOOL( "video-deco", windowDecorations );
             CONFIG_GENERIC( "vout", StringList, ui.voutLabel, outputModule );
 
@@ -741,6 +740,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
 
             CONFIG_BOOL( "embedded-video", embedVideo );
             CONFIG_BOOL( "qt-video-autoresize", resizingBox );
+            CONFIG_BOOL( "qt-always-on-top", alwaysOnTop );
             CONNECT( ui.embedVideo, toggled( bool ), ui.resizingBox, setEnabled( bool ) );
             ui.resizingBox->setEnabled( ui.embedVideo->isChecked() );
 
diff --git a/modules/gui/qt/main_interface.cpp b/modules/gui/qt/main_interface.cpp
index fc49683777..29d495c15d 100644
--- a/modules/gui/qt/main_interface.cpp
+++ b/modules/gui/qt/main_interface.cpp
@@ -149,6 +149,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /* */
     b_plDocked = getSettings()->value( "MainWindow/pl-dock-status", true ).toBool();
 
+    /* Should the UI stays on top of other windows */
+    b_interfaceOnTop = var_InheritBool( p_intf, "qt-always-on-top" );
 
     /**************************
      *  UI and Widgets design
@@ -521,6 +523,9 @@ void MainInterface::createMainWidget( QSettings *creationSettings )
             CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
                      this, handleKeyPress( QKeyEvent * ) );
         }
+
+    if ( b_interfaceOnTop )
+        setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
 }
 
 inline void MainInterface::initSystray()
@@ -906,6 +911,10 @@ void MainInterface::setHideMouse( bool hide )
  * Emit askVideoOnTop() to invoke this from other thread. */
 void MainInterface::setVideoOnTop( bool on_top )
 {
+    //don't apply changes if user has already sets its interface on top
+    if ( b_interfaceOnTop )
+        return;
+
     Qt::WindowFlags oldflags = windowFlags(), newflags;
 
     if( on_top )
@@ -913,7 +922,22 @@ void MainInterface::setVideoOnTop( bool on_top )
     else
         newflags = oldflags & ~Qt::WindowStaysOnTopHint;
     if( newflags != oldflags && !b_videoFullScreen )
+    {
+        setWindowFlags( newflags );
+        show(); /* necessary to apply window flags */
+    }
+}
 
+void MainInterface::setInterfaceAlwaysOnTop( bool on_top )
+{
+    b_interfaceOnTop = on_top;
+    Qt::WindowFlags oldflags = windowFlags(), newflags;
+
+    if( on_top )
+        newflags = oldflags | Qt::WindowStaysOnTopHint;
+    else
+        newflags = oldflags & ~Qt::WindowStaysOnTopHint;
+    if( newflags != oldflags && !b_videoFullScreen )
     {
         setWindowFlags( newflags );
         show(); /* necessary to apply window flags */
diff --git a/modules/gui/qt/main_interface.hpp b/modules/gui/qt/main_interface.hpp
index fe8a4b61f0..b9a078bb72 100644
--- a/modules/gui/qt/main_interface.hpp
+++ b/modules/gui/qt/main_interface.hpp
@@ -94,6 +94,7 @@ public:
     int getControlsVisibilityStatus();
     bool isPlDocked() { return ( b_plDocked != false ); }
     bool isInterfaceFullScreen() { return b_interfaceFullScreen; }
+    bool isInterfaceAlwaysOnTop() { return b_interfaceOnTop; }
     StandardPLPanel* getPlaylistView();
 
 protected:
@@ -177,6 +178,7 @@ protected:
     bool                 b_hideAfterCreation;
     bool                 b_minimalView;         ///< Minimal video
     bool                 b_interfaceFullScreen;
+    bool                 b_interfaceOnTop;      ///keep UI on top
     bool                 b_pauseOnMinimize;
     bool                 b_maximizedView;
     bool                 b_isWindowTiled;
@@ -203,6 +205,7 @@ public slots:
     void toggleAdvancedButtons();
     void toggleInterfaceFullScreen();
     void toggleFSC();
+    void setInterfaceAlwaysOnTop( bool );
 
     void setStatusBarVisibility(bool b_visible);
     void setPlaylistVisibility(bool b_visible);
diff --git a/modules/gui/qt/menus.cpp b/modules/gui/qt/menus.cpp
index a73d91157c..c40e6e5bfa 100644
--- a/modules/gui/qt/menus.cpp
+++ b/modules/gui/qt/menus.cpp
@@ -238,7 +238,6 @@ static int VideoAutoMenuBuilder( playlist_t *pl, input_thread_t *p_input,
 
     PUSH_INPUTVAR( "video-es" );
     PUSH_PLVAR( "fullscreen" );
-    PUSH_PLVAR( "video-on-top" );
     PUSH_PLVAR( "video-wallpaper" );
     PUSH_VAR( "video-snapshot" );
     PUSH_VAR( "zoom" );
@@ -533,6 +532,11 @@ QMenu *VLCMenuBar::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterfac
     if( visual_selector_enabled ) adv->setChecked( true );
 #endif
 
+    action = menu->addAction( qtr( "Interface on &top" ) );
+    action->setCheckable( true );
+    action->setChecked( mi->isInterfaceAlwaysOnTop() );
+    CONNECT( action, triggered( bool ), mi, setInterfaceAlwaysOnTop( bool ) );
+
     menu->addSeparator();
 
     InterfacesMenu( p_intf, menu );
@@ -678,7 +682,6 @@ QMenu *VLCMenuBar::VideoMenu( intf_thread_t *p_intf, QMenu *current )
         /* Surface modifiers */
         addActionWithCheckbox( current, "fullscreen", qtr( "&Fullscreen" ) );
         addActionWithCheckbox( current, "autoscale", qtr( "Always Fit &Window" ) );
-        addActionWithCheckbox( current, "video-on-top", qtr( "Always &on Top" ) );
         addActionWithCheckbox( current, "video-wallpaper", qtr( "Set as Wall&paper" ) );
 
         current->addSeparator();
diff --git a/modules/gui/qt/qt.cpp b/modules/gui/qt/qt.cpp
index 834c137fc3..94f99968dd 100644
--- a/modules/gui/qt/qt.cpp
+++ b/modules/gui/qt/qt.cpp
@@ -119,6 +119,8 @@ static void ShowDialog   ( intf_thread_t *, int, int, intf_dialog_args_t * );
                              " This option only works with Windows and " \
                              "X11 with composite extensions." )
 
+#define ALWAYS_ON_TOP_TEXT N_( "Keep interface always on top" )
+#define ALWAYS_ON_TOP_LONTEXT N_( "Always place the interface window on top of other windows" )
 
 #define ERROR_TEXT N_( "Show unimportant error and warnings dialogs" )
 
@@ -244,6 +246,8 @@ vlc_module_begin ()
     add_float_with_range( "qt-fs-opacity", 0.8, 0.1, 1., OPACITY_FS_TEXT,
                           OPACITY_FS_LONGTEXT, false )
 
+    add_bool( "qt-always-on-top", false, ALWAYS_ON_TOP_TEXT, ALWAYS_ON_TOP_LONTEXT, false );
+
     add_bool( "qt-video-autoresize", true, KEEPSIZE_TEXT,
               KEEPSIZE_LONGTEXT, false )
     add_bool( "qt-name-in-title", true, TITLE_TEXT,
diff --git a/modules/gui/qt/ui/sprefs_interface.ui b/modules/gui/qt/ui/sprefs_interface.ui
index fe937d1b5a..84b3497d33 100644
--- a/modules/gui/qt/ui/sprefs_interface.ui
+++ b/modules/gui/qt/ui/sprefs_interface.ui
@@ -8,7 +8,7 @@
     <x>0</x>
     <y>0</y>
     <width>700</width>
-    <height>757</height>
+    <height>785</height>
    </rect>
   </property>
   <property name="sizePolicy">
@@ -30,7 +30,7 @@
       <item>
        <widget class="QLabel" name="label">
         <property name="text">
-         <string>Menus language:</string>
+         <string>&Menus language:</string>
         </property>
         <property name="buddy">
          <cstring>langCombo</cstring>
@@ -55,7 +55,7 @@
       <item row="0" column="4">
        <widget class="QRadioButton" name="skins">
         <property name="text">
-         <string>Use custom skin</string>
+         <string>&Use custom skin</string>
         </property>
        </widget>
       </item>
@@ -91,7 +91,7 @@
          <string>This is VLC's default interface, with a native look and feel.</string>
         </property>
         <property name="text">
-         <string>Use native style</string>
+         <string>Use &native style</string>
         </property>
         <property name="checked">
          <bool>true</bool>
@@ -295,6 +295,13 @@
              <item row="11" column="2" colspan="2">
               <widget class="QComboBox" name="autoRaiseComboBox"/>
              </item>
+             <item row="4" column="2">
+              <widget class="QCheckBox" name="alwaysOnTop">
+               <property name="text">
+                <string>Start with interface always on top</string>
+               </property>
+              </widget>
+             </item>
             </layout>
            </widget>
           </item>
@@ -602,7 +609,7 @@
          </sizepolicy>
         </property>
         <property name="text">
-         <string>File extensions association</string>
+         <string>File e&xtensions association</string>
         </property>
         <property name="buddy">
          <cstring>assoButton</cstring>
diff --git a/modules/gui/qt/ui/sprefs_video.ui b/modules/gui/qt/ui/sprefs_video.ui
index 1becb97d5c..6c691f34ab 100644
--- a/modules/gui/qt/ui/sprefs_video.ui
+++ b/modules/gui/qt/ui/sprefs_video.ui
@@ -53,48 +53,41 @@
            </property>
           </widget>
          </item>
-         <item row="1" column="0">
-          <widget class="QCheckBox" name="overlay">
-           <property name="text">
-            <string>Accelerated video output (Overlay)</string>
+         <item row="3" column="1">
+          <widget class="QComboBox" name="outputModule">
+           <property name="maxVisibleItems">
+            <number>15</number>
            </property>
           </widget>
          </item>
-         <item row="1" column="1">
-          <widget class="QCheckBox" name="hwYUVBox">
+         <item row="3" column="0">
+          <widget class="QLabel" name="voutLabel">
            <property name="text">
-            <string>Use hardware YUV->RGB conversions</string>
+            <string>O&utput</string>
+           </property>
+           <property name="buddy">
+            <cstring>outputModule</cstring>
            </property>
           </widget>
          </item>
-         <item row="2" column="0">
-          <widget class="QCheckBox" name="alwaysOnTop">
+         <item row="1" column="0">
+          <widget class="QCheckBox" name="overlay">
            <property name="text">
-            <string>Always on top</string>
+            <string>Accelerated video output (Overlay)</string>
            </property>
           </widget>
          </item>
-         <item row="2" column="1">
+         <item row="2" column="0">
           <widget class="QCheckBox" name="windowDecorations">
            <property name="text">
             <string>Window decorations</string>
            </property>
           </widget>
          </item>
-         <item row="3" column="0">
-          <widget class="QLabel" name="voutLabel">
+         <item row="0" column="1">
+          <widget class="QCheckBox" name="hwYUVBox">
            <property name="text">
-            <string>Output</string>
-           </property>
-           <property name="buddy">
-            <cstring>outputModule</cstring>
-           </property>
-          </widget>
-         </item>
-         <item row="3" column="1">
-          <widget class="QComboBox" name="outputModule">
-           <property name="maxVisibleItems">
-            <number>15</number>
+            <string>Use hardware YUV->RGB conversions</string>
            </property>
           </widget>
          </item>
@@ -324,9 +317,6 @@
   <tabstop>enableVideo</tabstop>
   <tabstop>fullscreen</tabstop>
   <tabstop>overlay</tabstop>
-  <tabstop>hwYUVBox</tabstop>
-  <tabstop>alwaysOnTop</tabstop>
-  <tabstop>windowDecorations</tabstop>
   <tabstop>outputModule</tabstop>
   <tabstop>dXdisplayDevice</tabstop>
   <tabstop>kvaFixT23</tabstop>
-- 
2.14.2



More information about the vlc-devel mailing list