changeset 27281:0915fec3d3a9

prevent gui from catching focus when its desktop workspace becomes active * file-editor.cc (focus): renamed into activate and make use of octave_dock_widget::activate; (set_focus): use qt setFocus instead of own old octave_dock_widget::focus; (request_new_file, request_close_file, active_tab_changed, handle_visibility, request_open_file): call new method activate instead of old focus; * file-editor.h: removed method focus and added new method activate * main-window.cc (focus_command_window): activate instead of focus; (editor_tabs_changed, construct_documentation_menu): use activate slot instead of focus; * octave-dock-widget.cc (make_window, make_widget, set_focus_predecessor): use qt setFocus instead of removed focus method; (activate): implementation of renamed method; (handle_visibility): moved implementation from header to here * octave-dock-widget.h: renamed focus into activate, moved implementation from here to cc-file, use setFocus in handle_visibility, moved implementation for handle_visibility from here to cc-file * terminal-dock-widget.cc (focus): removed virtual implementation * terminal-dock-widget.h: removed focus method
author Torsten Lilge <ttl-octave@mailbox.org>
date Mon, 22 Jul 2019 22:20:56 +0200
parents 8d30dc86e5d9
children 49c60d16866f
files libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/main-window.cc libgui/src/octave-dock-widget.cc libgui/src/octave-dock-widget.h libgui/src/terminal-dock-widget.cc libgui/src/terminal-dock-widget.h
diffstat 7 files changed, 35 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc	Mon Jul 22 20:05:55 2019 +0200
+++ b/libgui/src/m-editor/file-editor.cc	Mon Jul 22 22:20:56 2019 +0200
@@ -317,12 +317,12 @@
                          s_data.at (n).line);
   }
 
-  void file_editor::focus (void)
+  void file_editor::activate (void)
   {
     if (m_no_focus)
       return;  // No focus for the editor if external open/close request
 
-    octave_dock_widget::focus ();
+    octave_dock_widget::activate ();
 
     // set focus to current tab
     QWidget *fileEditorTab = m_tab_widget->currentWidget ();
@@ -332,7 +332,7 @@
 
   void file_editor::set_focus (QWidget *fet)
   {
-    octave_dock_widget::focus ();
+    setFocus ();
 
     // set focus to desired tab
     if (fet)
@@ -469,7 +469,7 @@
     file_editor_tab *fileEditorTab = new file_editor_tab (m_ced);
     add_file_editor_tab (fileEditorTab, "");  // new tab with empty title
     fileEditorTab->new_file (commands);       // title is updated here
-    focus ();                                 // focus editor and new tab
+    activate ();                              // focus editor and new tab
   }
 
   void file_editor::request_close_file (bool)
@@ -820,7 +820,7 @@
       }
     check_actions ();
 
-    focus ();     // focus stays in editor when tab is closed
+    activate ();     // focus stays in editor when tab is closed
 
   }
 
@@ -836,7 +836,7 @@
   void file_editor::active_tab_changed (int index)
   {
     emit fetab_change_request (m_tab_widget->widget (index));
-    focus ();
+    activate ();
   }
 
   void file_editor::handle_editor_state_changed (bool copy_available,
@@ -1293,7 +1293,7 @@
     empty_script (false, visible);
 
     if (visible && ! isFloating ())
-      focus ();
+      setFocus ();
 
   }
 
@@ -1382,7 +1382,7 @@
             if (show_dbg_file && ! ((breakpoint_marker || debug_pointer) && is_editor_console_tabbed ()))
               {
                 emit fetab_set_focus (tab);
-                focus ();
+                activate ();
               }
           }
         else
@@ -1515,7 +1515,7 @@
                 // and the current editor tab
                 if (fileEditorTab)
                   fileEditorTab->update_breakpoints ();
-                focus ();
+                activate ();
                 emit file_loaded_signal ();
               }
           }
--- a/libgui/src/m-editor/file-editor.h	Mon Jul 22 20:05:55 2019 +0200
+++ b/libgui/src/m-editor/file-editor.h	Mon Jul 22 22:20:56 2019 +0200
@@ -184,7 +184,7 @@
 
     void toplevel_change (bool);
 
-    void focus (void);
+    void activate (void);
     void set_focus (QWidget *fet);
     void enable_menu_shortcuts (bool);
     bool check_closing (void);
--- a/libgui/src/main-window.cc	Mon Jul 22 20:05:55 2019 +0200
+++ b/libgui/src/main-window.cc	Mon Jul 22 22:20:56 2019 +0200
@@ -247,7 +247,7 @@
 
   void main_window::focus_command_window (void)
   {
-    m_command_window->focus ();
+    m_command_window->activate ();
   }
 
   // catch focus changes and determine the active dock widget
@@ -2518,7 +2518,7 @@
         else
           {
             // action for focus of dock widget
-            connect (action, SIGNAL (triggered (void)), widget, SLOT (focus (void)));
+            connect (action, SIGNAL (triggered (void)), widget, SLOT (activate (void)));
           }
       }
     else
@@ -2614,7 +2614,7 @@
     QMenu *doc_menu = p->addMenu (tr ("Documentation"));
 
     m_ondisk_doc_action = add_action (doc_menu, QIcon (),
-                                      tr ("On Disk"), SLOT (focus ()), m_doc_browser_window);
+                                      tr ("On Disk"), SLOT (activate ()), m_doc_browser_window);
 
     m_online_doc_action = add_action (doc_menu, QIcon (),
                                       tr ("Online"), SLOT (open_online_documentation_page ()));
--- a/libgui/src/octave-dock-widget.cc	Mon Jul 22 20:05:55 2019 +0200
+++ b/libgui/src/octave-dock-widget.cc	Mon Jul 22 22:20:56 2019 +0200
@@ -299,7 +299,7 @@
     if (vis)
     {
       show ();
-      focus ();
+      setFocus ();
       set_style (true);
     }
 
@@ -347,7 +347,7 @@
     if (vis)
       {
         show ();
-        focus ();
+        setFocus ();
         set_style (true);
       }
   }
@@ -566,7 +566,23 @@
     emit active_changed (false);
   }
 
-  void
+  void octave_dock_widget::activate (void)
+  {
+    if (! isVisible ())
+      setVisible (true);
+
+    setFocus ();
+    activateWindow ();
+    raise ();
+  }
+
+  void octave_dock_widget::handle_visibility (bool visible)
+  {
+    if (visible && ! isFloating ())
+      setFocus ();
+  }
+
+ void
   octave_dock_widget::toplevel_change (bool toplevel)
   {
     QObject *dockobj;
@@ -710,7 +726,7 @@
   {
     // only != 0 if widget was tabbed
     if (m_predecessor_widget && m_predecessor_widget->isVisible ())
-      m_predecessor_widget->focus ();
+      m_predecessor_widget->setFocus ();
 
     m_predecessor_widget = nullptr;
     // FIXME: Until cset bda0c5b38bda, the wrong keys "Dockwidget/..." were used
--- a/libgui/src/octave-dock-widget.h	Mon Jul 22 20:05:55 2019 +0200
+++ b/libgui/src/octave-dock-widget.h	Mon Jul 22 22:20:56 2019 +0200
@@ -108,21 +108,9 @@
 
   public slots:
 
-    virtual void focus (void)
-    {
-      if (! isVisible ())
-        setVisible (true);
+    virtual void activate (void);
 
-      setFocus ();
-      activateWindow ();
-      raise ();
-    }
-
-    virtual void handle_visibility (bool visible)
-    {
-      if (visible && ! isFloating ())
-        focus ();
-    }
+    virtual void handle_visibility (bool visible);
 
     virtual void notice_settings (const QSettings*) { }
 
--- a/libgui/src/terminal-dock-widget.cc	Mon Jul 22 20:05:55 2019 +0200
+++ b/libgui/src/terminal-dock-widget.cc	Mon Jul 22 22:20:56 2019 +0200
@@ -97,17 +97,6 @@
     return w->hasFocus ();
   }
 
-  void terminal_dock_widget::focus (void)
-  {
-    octave_dock_widget::focus ();
-
-    QWidget *w = widget ();
-
-    w->setFocus ();
-    w->activateWindow ();
-    w->raise ();
-  }
-
   void terminal_dock_widget::terminal_interrupt (void)
   {
     // FIXME: Protect with mutex?
--- a/libgui/src/terminal-dock-widget.h	Mon Jul 22 20:05:55 2019 +0200
+++ b/libgui/src/terminal-dock-widget.h	Mon Jul 22 22:20:56 2019 +0200
@@ -43,8 +43,6 @@
 
     bool has_focus (void) const;
 
-    void focus (void);
-
   signals:
 
     void interrupt_signal (void);