diff --git a/rtgui/editwindow.cc b/rtgui/editwindow.cc index 7782de87c..65e26275f 100644 --- a/rtgui/editwindow.cc +++ b/rtgui/editwindow.cc @@ -28,11 +28,11 @@ // Check if the system has more than one display and option is set bool EditWindow::isMultiDisplayEnabled() { - return options.multiDisplayMode > 0 && Gdk::Screen::get_default()->get_n_monitors () > 1; + return options.multiDisplayMode > 0 && Gdk::Screen::get_default()->get_n_monitors() > 1; } // Should only be created once, auto-creates window on correct display -EditWindow* EditWindow::getInstance(RTWindow* p) +EditWindow* EditWindow::getInstance(RTWindow* p, bool restore) { struct EditWindowInstance { @@ -40,23 +40,17 @@ EditWindow* EditWindow::getInstance(RTWindow* p) explicit EditWindowInstance(RTWindow* p) : editWnd(p) { - // Determine the other display and maximize the window on that - const Glib::RefPtr< Gdk::Window >& wnd = p->get_window(); - int monNo = p->get_screen()->get_monitor_at_window (wnd); - - Gdk::Rectangle lMonitorRect; - editWnd.get_screen()->get_monitor_geometry(isMultiDisplayEnabled() ? (monNo == 0 ? 1 : 0) : monNo, lMonitorRect); - editWnd.move(lMonitorRect.get_x(), lMonitorRect.get_y()); - editWnd.maximize(); } }; static EditWindowInstance instance_(p); - instance_.editWnd.show_all(); + if(restore) { + instance_.editWnd.restoreWindow(); + } return &instance_.editWnd; } -EditWindow::EditWindow (RTWindow* p) : parent(p) , isFullscreen(false) +EditWindow::EditWindow (RTWindow* p) : parent(p) , isFullscreen(false), isClosed(true) { Glib::ustring fName = "rt-logo-tiny.png"; @@ -71,9 +65,9 @@ EditWindow::EditWindow (RTWindow* p) : parent(p) , isFullscreen(false) set_title_decorated(""); set_modal(false); set_resizable(true); + set_default_size(options.meowWidth, options.meowHeight); property_destroy_with_parent().set_value(false); - //signal_window_state_event().connect( sigc::mem_fun(*this, &EditWindow::on_window_state_event) ); mainNB = Gtk::manage (new Gtk::Notebook ()); mainNB->set_scrollable (true); @@ -85,7 +79,46 @@ EditWindow::EditWindow (RTWindow* p) : parent(p) , isFullscreen(false) mainBox->pack_start (*mainNB); add (*mainBox); - show_all (); + +} + +void EditWindow::restoreWindow() { + + if(isClosed) { + int meowMonitor = 0; + if(isMultiDisplayEnabled()) { + if(options.meowMonitor >= 0) { // use display from last session if available + meowMonitor = std::min(options.meowMonitor, Gdk::Screen::get_default()->get_n_monitors()); + } else { // Determine the other display + const Glib::RefPtr< Gdk::Window >& wnd = parent->get_window(); + meowMonitor = parent->get_screen()->get_monitor_at_window(wnd) == 0 ? 1 : 0; + } + } + + Gdk::Rectangle lMonitorRect; + get_screen()->get_monitor_geometry(meowMonitor, lMonitorRect); + if(options.meowMaximized) { + move(lMonitorRect.get_x(), lMonitorRect.get_y()); + maximize(); + } else { + resize(options.meowWidth, options.meowHeight); + if(options.meowX <= lMonitorRect.get_x() + lMonitorRect.get_width() && options.meowY <= lMonitorRect.get_y() + lMonitorRect.get_height()) { + move(options.meowX, options.meowY); + } else { + move(lMonitorRect.get_x(), lMonitorRect.get_y()); + } + } + show_all(); + + isFullscreen = options.meowFullScreen; + + if(isFullscreen) { + fullscreen(); + } + + isClosed = false; + } + } void EditWindow::on_realize () @@ -95,6 +128,19 @@ void EditWindow::on_realize () editWindowCursorManager.init (get_window()); } +bool EditWindow::on_configure_event(GdkEventConfigure* event) +{ + if (get_realized() && is_visible()) { + if(!is_maximized()) { + get_position(options.meowX, options.meowY); + get_size(options.meowWidth, options.meowHeight); + } + options.meowMaximized = is_maximized(); + } + + return Gtk::Widget::on_configure_event(event); +} + /* HOMBRE: Disabling this since it's maximized when opened anyway. * Someday, the EditorWindow migh save it own position and state, so it'll have to be uncommented bool EditWindow::on_window_state_event(GdkEventWindowState* event) @@ -189,6 +235,14 @@ bool EditWindow::selectEditorPanel(const std::string &name) return false; } +void EditWindow::toFront () +{ + // when using the secondary window on the same monitor as the primary window we need to present the secondary window. + // If we don't, it will stay in background when opening 2nd, 3rd... editor, which is annoying + // It will also deiconify the window + present(); +} + bool EditWindow::keyPressed (GdkEventKey* event) { bool ctrl = event->state & GDK_CONTROL_MASK; @@ -216,22 +270,70 @@ bool EditWindow::keyPressed (GdkEventKey* event) void EditWindow::toggleFullscreen () { isFullscreen ? unfullscreen() : fullscreen(); - isFullscreen = !isFullscreen; + options.meowFullScreen = isFullscreen = !isFullscreen; } +void EditWindow::writeOptions() { + + if(is_visible()) { + if(isMultiDisplayEnabled()) { + options.meowMonitor = get_screen()->get_monitor_at_window(get_window()); + } + + options.meowMaximized = is_maximized(); + get_position(options.meowX, options.meowY); + get_size(options.meowWidth,options.meowHeight); + } +} bool EditWindow::on_delete_event(GdkEventAny* event) { - // Check if any editor is still processing, and do NOT quit if so. Otherwise crashes and inconsistent caches - bool isProcessing = false; - for ( std::set ::iterator iter = filesEdited.begin(); iter != filesEdited.end() && !isProcessing; ++iter ) { + if (!closeOpenEditors()) { + return true; + } + + writeOptions(); + hide(); + isClosed = true; + + return false; +} + +bool EditWindow::isProcessing () +{ + for ( std::set ::iterator iter = filesEdited.begin(); iter != filesEdited.end(); ++iter ) { if (epanels[*iter]->getIsProcessing()) { - isProcessing = true; + return true; } } - if (isProcessing) { - return true; + return false; +} + +bool EditWindow::closeOpenEditors() +{ + // Check if any editor is still processing, and do NOT quit if so. Otherwise crashes and inconsistent caches + if (isProcessing()) { + return false; + } + + if (epanels.size()) { + int page = mainNB->get_current_page(); + Gtk::Widget *w = mainNB->get_nth_page(page); + bool optionsWritten = false; + + for (std::map::iterator i = epanels.begin(); i != epanels.end(); ++i) { + if (i->second == w) { + i->second->writeOptions(); + optionsWritten = true; + } + } + + if (!optionsWritten) { + // fallback solution: save the options of the first editor panel + std::map::iterator i = epanels.begin(); + i->second->writeOptions(); + } } for ( std::set ::iterator iter = filesEdited.begin(); iter != filesEdited.end(); ++iter ) { @@ -239,12 +341,10 @@ bool EditWindow::on_delete_event(GdkEventAny* event) } epanels.clear(); - filesEdited.clear(); parent->fpanel->refreshEditedState (filesEdited); - hide (); - return false; + return true; } void EditWindow::set_title_decorated(Glib::ustring fname) diff --git a/rtgui/editwindow.h b/rtgui/editwindow.h index 320b47b40..8cf93dbf8 100644 --- a/rtgui/editwindow.h +++ b/rtgui/editwindow.h @@ -33,27 +33,33 @@ private: std::map epanels; bool isFullscreen; + bool isClosed; void toggleFullscreen (); + void restoreWindow(); public: // Check if the system has more than one display and option is set static bool isMultiDisplayEnabled(); // Should only be created once, auto-creates window on correct display - static EditWindow* getInstance(RTWindow* p); + static EditWindow* getInstance(RTWindow* p, bool restore = true); explicit EditWindow (RTWindow* p); + void writeOptions(); void addEditorPanel (EditorPanel* ep, const std::string &name); void remEditorPanel (EditorPanel* ep); bool selectEditorPanel(const std::string &name); + bool closeOpenEditors(); + bool isProcessing(); + void toFront(); bool keyPressed (GdkEventKey* event); + bool on_configure_event(GdkEventConfigure* event); bool on_delete_event(GdkEventAny* event); //bool on_window_state_event(GdkEventWindowState* event); void on_mainNB_switch_page(Gtk::Widget* page, guint page_num); void set_title_decorated(Glib::ustring fname); - void on_realize (); }; diff --git a/rtgui/history.cc b/rtgui/history.cc index 8e7adfab7..72c61b678 100644 --- a/rtgui/history.cc +++ b/rtgui/history.cc @@ -54,7 +54,6 @@ History::History (bool bookmarkSupport) : historyVPaned(nullptr), blistener(null hTreeView->set_hscroll_policy(Gtk::SCROLL_MINIMUM); hTreeView->set_vscroll_policy(Gtk::SCROLL_NATURAL); hTreeView->set_size_request(80, -1); - hTreeView->set_resize_mode(Gtk::RESIZE_QUEUE); Gtk::CellRendererText *changecrt = Gtk::manage (new Gtk::CellRendererText()); changecrt->property_ellipsize() = Pango::ELLIPSIZE_END; diff --git a/rtgui/options.cc b/rtgui/options.cc index 1f29264b8..66bef0a4f 100644 --- a/rtgui/options.cc +++ b/rtgui/options.cc @@ -295,6 +295,13 @@ void Options::setDefaults () windowX = 0; windowY = 0; windowMaximized = true; + meowMonitor = -1; + meowFullScreen = false; + meowMaximized = true; + meowWidth = 1200; + meowHeight = 680; + meowX = 0; + meowY = 0; saveAsDialogWidth = 920; saveAsDialogHeight = 680; savesParamsAtExit = true; @@ -1258,6 +1265,34 @@ int Options::readFromFile (Glib::ustring fname) windowY = keyFile.get_integer ("GUI", "WindowY"); } + if (keyFile.has_key ("GUI", "MeowMonitor")) { + meowMonitor = keyFile.get_integer ("GUI", "MeowMonitor"); + } + + if (keyFile.has_key ("GUI", "MeowFullScreen")) { + meowFullScreen = keyFile.get_boolean ("GUI", "MeowFullScreen"); + } + + if (keyFile.has_key ("GUI", "MeowMaximized")) { + meowMaximized = keyFile.get_boolean ("GUI", "MeowMaximized"); + } + + if (keyFile.has_key ("GUI", "MeowWidth")) { + meowWidth = keyFile.get_integer ("GUI", "MeowWidth"); + } + + if (keyFile.has_key ("GUI", "MeowHeight")) { + meowHeight = keyFile.get_integer ("GUI", "MeowHeight"); + } + + if (keyFile.has_key ("GUI", "MeowX")) { + meowX = keyFile.get_integer ("GUI", "MeowX"); + } + + if (keyFile.has_key ("GUI", "MeowY")) { + meowY = keyFile.get_integer ("GUI", "MeowY"); + } + if (keyFile.has_key ("GUI", "WindowMaximized")) { windowMaximized = keyFile.get_boolean ("GUI", "WindowMaximized"); } @@ -2009,6 +2044,13 @@ int Options::saveToFile (Glib::ustring fname) keyFile.set_integer ("GUI", "WindowHeight", windowHeight); keyFile.set_integer ("GUI", "WindowX", windowX); keyFile.set_integer ("GUI", "WindowY", windowY); + keyFile.set_integer ("GUI", "MeowMonitor", meowMonitor); + keyFile.set_boolean ("GUI", "MeowFullScreen", meowFullScreen); + keyFile.set_boolean ("GUI", "MeowMaximized", meowMaximized); + keyFile.set_integer ("GUI", "MeowWidth", meowWidth); + keyFile.set_integer ("GUI", "MeowHeight", meowHeight); + keyFile.set_integer ("GUI", "MeowX", meowX); + keyFile.set_integer ("GUI", "MeowY", meowY); keyFile.set_boolean ("GUI", "WindowMaximized", windowMaximized); keyFile.set_integer ("GUI", "DetailWindowWidth", detailWindowWidth); keyFile.set_integer ("GUI", "DetailWindowHeight", detailWindowHeight); diff --git a/rtgui/options.h b/rtgui/options.h index 46a6d67ee..e98ac4d2b 100644 --- a/rtgui/options.h +++ b/rtgui/options.h @@ -132,11 +132,18 @@ public: bool browserDirPanelOpened; bool editorFilmStripOpened; int historyPanelWidth; - int windowWidth; - int windowHeight; int windowX; int windowY; + int windowWidth; + int windowHeight; bool windowMaximized; + int meowMonitor; + bool meowFullScreen; + bool meowMaximized; + int meowWidth; + int meowHeight; + int meowX; + int meowY; int detailWindowWidth; int detailWindowHeight; int dirBrowserWidth; diff --git a/rtgui/rtwindow.cc b/rtgui/rtwindow.cc index a94fafa36..174d6ba2e 100644 --- a/rtgui/rtwindow.cc +++ b/rtgui/rtwindow.cc @@ -124,7 +124,6 @@ RTWindow::RTWindow () set_title_decorated(""); set_resizable(true); - set_resize_mode(Gtk::ResizeMode::RESIZE_QUEUE); set_decorated(true); set_default_size(options.windowWidth, options.windowHeight); set_modal(false); @@ -339,12 +338,21 @@ void RTWindow::on_realize () } } +bool RTWindow::on_configure_event(GdkEventConfigure* event) +{ + if (!is_maximized() && is_visible()) { + get_size(options.windowWidth, options.windowHeight); + get_position (options.windowX, options.windowY); + } + + return Gtk::Widget::on_configure_event(event); +} + bool RTWindow::on_window_state_event(GdkEventWindowState* event) { if (event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED) { options.windowMaximized = event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED; } - return Gtk::Widget::on_window_state_event(event); } @@ -385,6 +393,7 @@ void RTWindow::addEditorPanel (EditorPanel* ep, const std::string &name) EditWindow * wndEdit = EditWindow::getInstance(this); wndEdit->show(); wndEdit->addEditorPanel(ep, name); + wndEdit->toFront(); } else { ep->setParent (this); ep->setParentWindow(this); @@ -462,6 +471,7 @@ bool RTWindow::selectEditorPanel(const std::string &name) if (wndEdit->selectEditorPanel(name)) { set_title_decorated(name); + wndEdit->toFront(); return true; } } else { @@ -585,9 +595,17 @@ bool RTWindow::on_delete_event(GdkEventAny* event) // Check if any editor is still processing, and do NOT quit if so. Otherwise crashes and inconsistent caches bool isProcessing = false; + EditWindow* editWindow = nullptr; + if (isSingleTabMode() || simpleEditor) { isProcessing = epanel->getIsProcessing(); + } else if (options.multiDisplayMode > 0) { + editWindow = EditWindow::getInstance(this, false); + + if (editWindow->isProcessing ()) { + return true; + } } else { int pageCount = mainNB->get_n_pages(); @@ -613,10 +631,15 @@ bool RTWindow::on_delete_event(GdkEventAny* event) if ((isSingleTabMode() || simpleEditor) && epanel->isRealized()) { epanel->saveProfile(); epanel->writeOptions (); - } else { + } + else { + if (options.multiDisplayMode > 0) { + editWindow->closeOpenEditors(); + editWindow->writeOptions(); + } // Storing the options of the last EditorPanel before Gtk destroys everything // Look at the active panel first, if any, otherwise look at the first one (sorted on the filename) - if (epanels.size()) { + else if (epanels.size()) { int page = mainNB->get_current_page(); Gtk::Widget *w = mainNB->get_nth_page(page); bool optionsWritten = false; @@ -826,7 +849,7 @@ void RTWindow::set_title_decorated(Glib::ustring fname) set_title(versionStr + subtitle); } -void RTWindow::CloseOpenEditors() +void RTWindow::closeOpenEditors() { std::map::const_iterator itr; itr = epanels.begin(); @@ -850,7 +873,7 @@ bool RTWindow::isEditorPanel(guint pageNum) void RTWindow::setEditorMode(bool tabbedUI) { MoveFileBrowserToMain(); - CloseOpenEditors(); + closeOpenEditors(); SetMainCurrent(); if(tabbedUI) { diff --git a/rtgui/rtwindow.h b/rtgui/rtwindow.h index a57f7b4a3..faad5f849 100644 --- a/rtgui/rtwindow.h +++ b/rtgui/rtwindow.h @@ -80,6 +80,7 @@ public: void addBatchQueueJobs (std::vector &entries); bool keyPressed (GdkEventKey* event); + bool on_configure_event(GdkEventConfigure* event); bool on_delete_event(GdkEventAny* event); bool on_window_state_event(GdkEventWindowState* event); void on_mainNB_switch_page(Gtk::Widget* widget, guint page_num); @@ -115,7 +116,7 @@ public: return is_fullscreen; } void set_title_decorated(Glib::ustring fname); - void CloseOpenEditors(); + void closeOpenEditors(); void setEditorMode(bool tabbedUI); void createSetmEditor(); };