From 836a55cebd0cfe0d290396a7a3a094273eefc7e0 Mon Sep 17 00:00:00 2001 From: SimplestStudio Date: Tue, 12 Dec 2023 14:11:03 +0200 Subject: [PATCH 1/2] [linux] add feature 63817: display of recent files --- .../cascapplicationmanagerwrapper_private.h | 2 -- win-linux/src/ceditortools.cpp | 2 -- win-linux/src/components/cdownloadwidget.cpp | 2 -- win-linux/src/platform_linux/gtkutils.cpp | 7 ++++++ win-linux/src/platform_linux/gtkutils.h | 1 + win-linux/src/utils.cpp | 22 +++++++++++++------ win-linux/src/utils.h | 2 +- win-linux/src/windows/cmainwindow.cpp | 2 -- 8 files changed, 24 insertions(+), 16 deletions(-) diff --git a/win-linux/src/cascapplicationmanagerwrapper_private.h b/win-linux/src/cascapplicationmanagerwrapper_private.h index 4bed14c7c..098643792 100644 --- a/win-linux/src/cascapplicationmanagerwrapper_private.h +++ b/win-linux/src/cascapplicationmanagerwrapper_private.h @@ -232,9 +232,7 @@ class CAscApplicationManagerWrapper_Private CMessage::error(m_appmanager.mainWindow()->handle(), QObject::tr("File %1 cannot be opened or doesn't exists.").arg(_info.fileName())); } -#ifdef _WIN32 else Utils::addToRecent(file_path); -#endif } } diff --git a/win-linux/src/ceditortools.cpp b/win-linux/src/ceditortools.cpp index 33b851d04..fa833b9a1 100644 --- a/win-linux/src/ceditortools.cpp +++ b/win-linux/src/ceditortools.cpp @@ -394,9 +394,7 @@ namespace CEditorTools AscAppManager::GetFileFormatByExtentionForSave(pSaveData->get_Path()); pSaveData->put_FileType(format > -1 ? format : 0); -#ifdef _WIN32 Utils::addToRecent(_full_path.toStdWString()); -#endif } } diff --git a/win-linux/src/components/cdownloadwidget.cpp b/win-linux/src/components/cdownloadwidget.cpp index d408cdea5..8a96dcde6 100644 --- a/win-linux/src/components/cdownloadwidget.cpp +++ b/win-linux/src/components/cdownloadwidget.cpp @@ -343,9 +343,7 @@ void CDownloadWidget::downloadProcess(void * info) CMessage::error(parentWidget(), tr("Can't open file: ") + path); } else { AscAppManager::handleInputCmd({path.toStdWString()}); -#ifdef _WIN32 Utils::addToRecent(path.toStdWString()); -#endif } }); diff --git a/win-linux/src/platform_linux/gtkutils.cpp b/win-linux/src/platform_linux/gtkutils.cpp index fb3836e14..e01d080b8 100644 --- a/win-linux/src/platform_linux/gtkutils.cpp +++ b/win-linux/src/platform_linux/gtkutils.cpp @@ -72,6 +72,13 @@ void set_parent(GtkWidget *dialog, gpointer data) } } +void add_to_recent(const gchar *uri) +{ + gtk_init(NULL, NULL); + GtkRecentManager *rm = gtk_recent_manager_get_default(); + gtk_recent_manager_add_item(rm, uri); +} + GtkWidget *find_widget_by_path(GtkWidget *parent, const gchar *widget_path) { if (!parent) diff --git a/win-linux/src/platform_linux/gtkutils.h b/win-linux/src/platform_linux/gtkutils.h index c6b1c9ac7..9b85b4da6 100644 --- a/win-linux/src/platform_linux/gtkutils.h +++ b/win-linux/src/platform_linux/gtkutils.h @@ -44,6 +44,7 @@ typedef struct DialogTag { gboolean set_focus(GtkWidget *dialog); gboolean focus_out(gpointer data); void set_parent(GtkWidget *dialog, gpointer data); +void add_to_recent(const gchar *uri); GtkWidget *find_widget_by_path(GtkWidget *parent, const gchar *widget_path); #endif // GTKUTILS_H diff --git a/win-linux/src/utils.cpp b/win-linux/src/utils.cpp index 5bacb475c..4bb4ca642 100644 --- a/win-linux/src/utils.cpp +++ b/win-linux/src/utils.cpp @@ -30,6 +30,9 @@ * */ +#ifdef __linux__ +# include "platform_linux/gtkutils.h" +#endif #include "utils.h" #include "defines.h" #include @@ -710,6 +713,18 @@ bool Utils::updatesAllowed() return false; } +void Utils::addToRecent(const std::wstring &path) +{ + QString _path = QString::fromStdWString(path); +#ifdef _WIN32 + QString appPath = qApp->applicationDirPath(); + QProcess::startDetached(appPath + "/" + QString(REG_APP_NAME), {"--add-to-recent", QDir::toNativeSeparators(_path)}, appPath); +#else + std::string uri = "file://" + _path.toStdString(); + add_to_recent(uri.c_str()); +#endif +} + #ifdef _WIN32 Utils::WinVer Utils::getWinVersion() { @@ -750,13 +765,6 @@ Utils::WinVer Utils::getWinVersion() return WinVer::Undef; } -void Utils::addToRecent(const std::wstring &path) -{ - QString _path = QString::fromStdWString(path); - QString appPath = qApp->applicationDirPath(); - QProcess::startDetached(appPath + "/" + QString(REG_APP_NAME), {"--add-to-recent", QDir::toNativeSeparators(_path)}, appPath); -} - std::atomic_bool sessionInProgress{true}; bool Utils::isSessionInProgress() diff --git a/win-linux/src/utils.h b/win-linux/src/utils.h index 14bd584b7..cb35ea1eb 100644 --- a/win-linux/src/utils.h +++ b/win-linux/src/utils.h @@ -118,13 +118,13 @@ class Utils { static QJsonObject parseJsonString(const std::wstring&); static QJsonObject parseJsonFile(const QString&); static bool updatesAllowed(); + static void addToRecent(const std::wstring&); #ifdef _WIN32 enum class WinVer : uchar { Undef, WinXP, WinVista, Win7, Win8, Win8_1, Win10, Win11 }; static WinVer getWinVersion(); - static void addToRecent(const std::wstring&); static bool isSessionInProgress(); static void setSessionInProgress(bool); #endif diff --git a/win-linux/src/windows/cmainwindow.cpp b/win-linux/src/windows/cmainwindow.cpp index 8ed8b34a8..c509c1b90 100644 --- a/win-linux/src/windows/cmainwindow.cpp +++ b/win-linux/src/windows/cmainwindow.cpp @@ -749,9 +749,7 @@ void CMainWindow::doOpenLocalFile(COpenOptions& opts) int result = m_pTabs->openLocalDocument(opts, true); if ( !(result < 0) ) { toggleButtonMain(false, true); -#ifdef _WIN32 Utils::addToRecent(opts.wurl); -#endif } else if (result == -255) { QTimer::singleShot(0, this, [=] { From 05e594e1d9a8e47dc7a77d20dc95a08374fc630b Mon Sep 17 00:00:00 2001 From: SimplestStudio Date: Tue, 12 Dec 2023 14:13:42 +0200 Subject: [PATCH 2/2] [linux] refactoring: hide dialog box icon on taskbar --- win-linux/src/platform_linux/gtkfilechooser.cpp | 1 + win-linux/src/platform_linux/gtkprintdialog.cpp | 1 + win-linux/src/platform_linux/updatedialog.cpp | 1 + win-linux/src/platform_linux/xcbutils.cpp | 9 +++++++++ 4 files changed, 12 insertions(+) diff --git a/win-linux/src/platform_linux/gtkfilechooser.cpp b/win-linux/src/platform_linux/gtkfilechooser.cpp index 42b5e18f0..f268233c0 100755 --- a/win-linux/src/platform_linux/gtkfilechooser.cpp +++ b/win-linux/src/platform_linux/gtkfilechooser.cpp @@ -93,6 +93,7 @@ static void nativeFileDialog(const Window &parent_xid, GTK_RESPONSE_ACCEPT, NULL); + gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE); //g_signal_connect(G_OBJECT(dialog), "destroy", G_CALLBACK(gtk_main_quit), NULL); g_signal_connect(G_OBJECT(dialog), "realize", G_CALLBACK(set_parent), (gpointer)&parent_xid); g_signal_connect(G_OBJECT(dialog), "map_event", G_CALLBACK(set_focus), NULL); diff --git a/win-linux/src/platform_linux/gtkprintdialog.cpp b/win-linux/src/platform_linux/gtkprintdialog.cpp index bbd7a34f7..27bd99c1a 100644 --- a/win-linux/src/platform_linux/gtkprintdialog.cpp +++ b/win-linux/src/platform_linux/gtkprintdialog.cpp @@ -372,6 +372,7 @@ QDialog::DialogCode GtkPrintDialog::exec() GtkWidget *dialog; dialog = gtk_print_unix_dialog_new(m_title.toUtf8().data(), NULL); gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG); + gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE); GtkEntry *page_ranges_entry = NULL; g_signal_connect(G_OBJECT(dialog), "map", G_CALLBACK(get_page_ranges_entry), (gpointer)&page_ranges_entry); diff --git a/win-linux/src/platform_linux/updatedialog.cpp b/win-linux/src/platform_linux/updatedialog.cpp index d46226be6..157d687da 100644 --- a/win-linux/src/platform_linux/updatedialog.cpp +++ b/win-linux/src/platform_linux/updatedialog.cpp @@ -85,6 +85,7 @@ int WinDlg::showDialog(QWidget *parent, "%s", primaryText.toLocal8Bit().data()); + gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE); g_signal_connect(G_OBJECT(dialog), "realize", G_CALLBACK(set_parent), (gpointer)&parent_xid); g_signal_connect(G_OBJECT(dialog), "map_event", G_CALLBACK(set_focus), NULL); DialogTag tag; // unable to send parent_xid via g_signal_connect and "focus_out_event" diff --git a/win-linux/src/platform_linux/xcbutils.cpp b/win-linux/src/platform_linux/xcbutils.cpp index 27646464e..99cbb8d66 100644 --- a/win-linux/src/platform_linux/xcbutils.cpp +++ b/win-linux/src/platform_linux/xcbutils.cpp @@ -70,6 +70,14 @@ void XcbUtils::setNativeFocusTo(xcb_window_t window) } } +static void SetSkipTaskbar(Display* disp, Window win) +{ + Atom wm_state = XInternAtom(disp, "_NET_WM_STATE", True); + Atom wm_state_skip_taskbar = XInternAtom(disp, "_NET_WM_STATE_SKIP_TASKBAR", True); + if (wm_state != None && wm_state_skip_taskbar != None) + XChangeProperty(disp, win, wm_state, XA_ATOM, 32, PropModeReplace, (const unsigned char*)&wm_state_skip_taskbar, 1); +} + static void GetWindowName(Display* disp, Window win, char **name) { XClassHint* class_hint = NULL; class_hint = XAllocClassHint(); @@ -135,6 +143,7 @@ void XcbUtils::findWindowAsync(const char *window_name, if (strstr(name, window_name) != NULL) { if (IsVisible(disp, win_list[i])) { win_found = win_list[i]; + SetSkipTaskbar(disp, win_found); callback((xcb_window_t)win_found); } free(name);