New build option: without GTK and appindicator

Signed-off-by: Egor Y. Egorov <egor.y.egorov@gmail.com> (github: eegorov)
This commit is contained in:
eegorov 2017-08-07 17:57:34 +06:00 committed by John Preston
parent 08e3a54a58
commit 8bfe407610
14 changed files with 101 additions and 11 deletions

View file

@ -82,6 +82,10 @@ GOTO:EOF
set TDESKTOP_BUILD_DEFINES=%TDESKTOP_BUILD_DEFINES%,TDESKTOP_DISABLE_UNITY_INTEGRATION set TDESKTOP_BUILD_DEFINES=%TDESKTOP_BUILD_DEFINES%,TDESKTOP_DISABLE_UNITY_INTEGRATION
) )
echo %BUILD_VERSION% | findstr /C:"disable_gtk_integration">nul && (
set TDESKTOP_BUILD_DEFINES=%TDESKTOP_BUILD_DEFINES%,TDESKTOP_DISABLE_GTK_INTEGRATION
)
if not "%TDESKTOP_BUILD_DEFINES%" == "" ( if not "%TDESKTOP_BUILD_DEFINES%" == "" (
set "TDESKTOP_BUILD_DEFINES=%TDESKTOP_BUILD_DEFINES:~1%" set "TDESKTOP_BUILD_DEFINES=%TDESKTOP_BUILD_DEFINES:~1%"
) )

View file

@ -16,6 +16,7 @@ env:
- BUILD_VERSION="disable_network_proxy" - BUILD_VERSION="disable_network_proxy"
- BUILD_VERSION="disable_desktop_file_generation" - BUILD_VERSION="disable_desktop_file_generation"
- BUILD_VERSION="disable_unity_integration" - BUILD_VERSION="disable_unity_integration"
- BUILD_VERSION="disable_gtk_integration"
matrix: matrix:
fast_finish: true fast_finish: true

View file

@ -118,6 +118,10 @@ build() {
GYP_DEFINES+=",TDESKTOP_DISABLE_UNITY_INTEGRATION" GYP_DEFINES+=",TDESKTOP_DISABLE_UNITY_INTEGRATION"
fi fi
if [[ $BUILD_VERSION == *"disable_gtk_integration"* ]]; then
GYP_DEFINES+=",TDESKTOP_DISABLE_GTK_INTEGRATION"
fi
info_msg "Build defines: ${GYP_DEFINES}" info_msg "Build defines: ${GYP_DEFINES}"
buildTelegram buildTelegram

View file

@ -95,6 +95,7 @@ void UnsafeShowInFolder(const QString &filepath) {
namespace FileDialog { namespace FileDialog {
namespace { namespace {
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
// GTK file chooser image preview: thanks to Chromium // GTK file chooser image preview: thanks to Chromium
@ -105,9 +106,11 @@ namespace {
// be preserved. // be preserved.
constexpr auto kPreviewWidth = 256; constexpr auto kPreviewWidth = 256;
constexpr auto kPreviewHeight = 512; constexpr auto kPreviewHeight = 512;
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
using Type = ::FileDialog::internal::Type; using Type = ::FileDialog::internal::Type;
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
bool NativeSupported() { bool NativeSupported() {
return Platform::internal::GdkHelperLoaded() return Platform::internal::GdkHelperLoaded()
&& (Libs::gtk_widget_hide_on_delete != nullptr) && (Libs::gtk_widget_hide_on_delete != nullptr)
@ -191,16 +194,20 @@ bool GetNative(QStringList &files, QByteArray &remoteContent, const QString &cap
remoteContent = QByteArray(); remoteContent = QByteArray();
return false; return false;
} }
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} // namespace } // namespace
bool Get(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, Type type, QString startFile) { bool Get(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, Type type, QString startFile) {
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
if (NativeSupported()) { if (NativeSupported()) {
return GetNative(files, remoteContent, caption, filter, type, startFile); return GetNative(files, remoteContent, caption, filter, type, startFile);
} }
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
return ::FileDialog::internal::GetDefault(files, remoteContent, caption, filter, type, startFile); return ::FileDialog::internal::GetDefault(files, remoteContent, caption, filter, type, startFile);
} }
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
namespace internal { namespace internal {
QGtkDialog::QGtkDialog(GtkWidget *gtkWidget) : gtkWidget(gtkWidget) { QGtkDialog::QGtkDialog(GtkWidget *gtkWidget) : gtkWidget(gtkWidget) {
@ -302,6 +309,7 @@ void QGtkDialog::onParentWindowDestroyed() {
// The Gtk*DialogHelper classes own this object. Make sure the parent doesn't delete it. // The Gtk*DialogHelper classes own this object. Make sure the parent doesn't delete it.
setParent(nullptr); setParent(nullptr);
} }
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
namespace { namespace {
@ -321,6 +329,7 @@ QStringList cleanFilterList(const QString &filter) {
} // namespace } // namespace
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
GtkFileDialog::GtkFileDialog(QWidget *parent, const QString &caption, const QString &directory, const QString &filter) : QDialog(parent) GtkFileDialog::GtkFileDialog(QWidget *parent, const QString &caption, const QString &directory, const QString &filter) : QDialog(parent)
, _windowTitle(caption) , _windowTitle(caption)
, _initialDirectory(directory) { , _initialDirectory(directory) {
@ -624,5 +633,6 @@ void GtkFileDialog::setNameFilters(const QStringList &filters) {
} }
} // namespace internal } // namespace internal
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} // namespace FileDialog } // namespace FileDialog
} // namespace Platform } // namespace Platform

View file

@ -24,8 +24,10 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
extern "C" { extern "C" {
#undef signals #undef signals
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gdk/gdk.h> #include <gdk/gdk.h>
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
#define signals public #define signals public
} // extern "C" } // extern "C"
@ -69,6 +71,7 @@ inline void InitLastPath() {
} }
namespace internal { namespace internal {
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
// This is a patched copy of qgtk2 theme plugin. // This is a patched copy of qgtk2 theme plugin.
// We need to use our own gtk file dialog instead of // We need to use our own gtk file dialog instead of
@ -173,6 +176,7 @@ private:
QHash<GtkFileFilter*, QString> _filterNames; QHash<GtkFileFilter*, QString> _filterNames;
QScopedPointer<QGtkDialog> d; QScopedPointer<QGtkDialog> d;
}; };
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} // namespace internal } // namespace internal
} // namespace FileDialog } // namespace FileDialog

View file

@ -18,6 +18,7 @@ to link the code of portions of this program with the OpenSSL library.
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/ */
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
#include "platform/linux/linux_gdk_helper.h" #include "platform/linux/linux_gdk_helper.h"
#include "platform/linux/linux_libs.h" #include "platform/linux/linux_libs.h"
@ -111,3 +112,4 @@ void XSetTransientForHint(GdkWindow *window, quintptr winId) {
} // namespace internal } // namespace internal
} // namespace Platform } // namespace Platform
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION

View file

@ -22,6 +22,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include <QtCore/QObject> #include <QtCore/QObject>
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
extern "C" { extern "C" {
#undef signals #undef signals
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -38,3 +39,4 @@ void XSetTransientForHint(GdkWindow *window, quintptr winId);
} // namespace internal } // namespace internal
} // namespace Platform } // namespace Platform
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION

View file

@ -44,6 +44,7 @@ bool loadLibrary(QLibrary &lib, const char *name, int version) {
} // namespace } // namespace
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
f_notify_init notify_init = nullptr; f_notify_init notify_init = nullptr;
f_notify_uninit notify_uninit = nullptr; f_notify_uninit notify_uninit = nullptr;
f_notify_is_initted notify_is_initted = nullptr; f_notify_is_initted notify_is_initted = nullptr;
@ -116,6 +117,7 @@ void startLibNotify() {
load(lib_notify, "notify_notification_close", notify_notification_close); load(lib_notify, "notify_notification_close", notify_notification_close);
load(lib_notify, "notify_notification_get_closed_reason", notify_notification_get_closed_reason); load(lib_notify, "notify_notification_get_closed_reason", notify_notification_get_closed_reason);
} }
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} // namespace Libs } // namespace Libs
} // namespace Platform } // namespace Platform

View file

@ -20,6 +20,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/ */
#pragma once #pragma once
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
extern "C" { extern "C" {
#undef signals #undef signals
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -129,3 +130,4 @@ extern f_notify_notification_get_closed_reason notify_notification_get_closed_re
} // namespace Libs } // namespace Libs
} // namespace Platform } // namespace Platform
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION

View file

@ -44,6 +44,7 @@ bool loadLibrary(QLibrary &lib, const char *name, int version) {
return false; return false;
} }
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
bool setupGtkBase(QLibrary &lib_gtk) { bool setupGtkBase(QLibrary &lib_gtk) {
if (!load(lib_gtk, "gtk_init_check", gtk_init_check)) return false; if (!load(lib_gtk, "gtk_init_check", gtk_init_check)) return false;
if (!load(lib_gtk, "gtk_menu_new", gtk_menu_new)) return false; if (!load(lib_gtk, "gtk_menu_new", gtk_menu_new)) return false;
@ -142,9 +143,11 @@ bool setupAppIndicator(QLibrary &lib_indicator) {
DEBUG_LOG(("Library appindicator functions loaded!")); DEBUG_LOG(("Library appindicator functions loaded!"));
return true; return true;
} }
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} // namespace } // namespace
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
f_gtk_init_check gtk_init_check = nullptr; f_gtk_init_check gtk_init_check = nullptr;
f_gtk_menu_new gtk_menu_new = nullptr; f_gtk_menu_new gtk_menu_new = nullptr;
f_gtk_menu_get_type gtk_menu_get_type = nullptr; f_gtk_menu_get_type gtk_menu_get_type = nullptr;
@ -235,9 +238,11 @@ f_unity_launcher_entry_set_count unity_launcher_entry_set_count = nullptr;
f_unity_launcher_entry_set_count_visible unity_launcher_entry_set_count_visible = nullptr; f_unity_launcher_entry_set_count_visible unity_launcher_entry_set_count_visible = nullptr;
f_unity_launcher_entry_get_for_desktop_id unity_launcher_entry_get_for_desktop_id = nullptr; f_unity_launcher_entry_get_for_desktop_id unity_launcher_entry_get_for_desktop_id = nullptr;
#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION #endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
void start() { void start() {
DEBUG_LOG(("Loading libraries")); DEBUG_LOG(("Loading libraries"));
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
bool gtkLoaded = false; bool gtkLoaded = false;
bool indicatorLoaded = false; bool indicatorLoaded = false;
@ -310,6 +315,7 @@ void start() {
if (gtkLoaded) { if (gtkLoaded) {
startLibNotify(); startLibNotify();
} }
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} }
} // namespace Libs } // namespace Libs

View file

@ -20,6 +20,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/ */
#pragma once #pragma once
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
extern "C" { extern "C" {
#undef signals #undef signals
#include <libappindicator/app-indicator.h> #include <libappindicator/app-indicator.h>
@ -31,6 +32,7 @@ extern "C" {
#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION #ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION
#include <unity/unity/unity.h> #include <unity/unity/unity.h>
#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION #endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
namespace Platform { namespace Platform {
namespace Libs { namespace Libs {
@ -52,6 +54,7 @@ bool load(QLibrary &lib, const char *name, Function &func) {
return false; return false;
} }
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
typedef gboolean (*f_gtk_init_check)(int *argc, char ***argv); typedef gboolean (*f_gtk_init_check)(int *argc, char ***argv);
extern f_gtk_init_check gtk_init_check; extern f_gtk_init_check gtk_init_check;
@ -381,6 +384,7 @@ extern f_unity_launcher_entry_set_count_visible unity_launcher_entry_set_count_v
typedef UnityLauncherEntry* (*f_unity_launcher_entry_get_for_desktop_id)(const gchar* desktop_id); typedef UnityLauncherEntry* (*f_unity_launcher_entry_get_for_desktop_id)(const gchar* desktop_id);
extern f_unity_launcher_entry_get_for_desktop_id unity_launcher_entry_get_for_desktop_id; extern f_unity_launcher_entry_get_for_desktop_id unity_launcher_entry_get_for_desktop_id;
#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION #endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} // namespace Libs } // namespace Libs
} // namespace Platform } // namespace Platform

View file

@ -36,18 +36,21 @@ namespace {
bool noQtTrayIcon = false, tryAppIndicator = false; bool noQtTrayIcon = false, tryAppIndicator = false;
bool useGtkBase = false, useAppIndicator = false, useStatusIcon = false, trayIconChecked = false, useUnityCount = false; bool useGtkBase = false, useAppIndicator = false, useStatusIcon = false, trayIconChecked = false, useUnityCount = false;
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
AppIndicator *_trayIndicator = 0; AppIndicator *_trayIndicator = 0;
GtkStatusIcon *_trayIcon = 0; GtkStatusIcon *_trayIcon = 0;
GtkWidget *_trayMenu = 0; GtkWidget *_trayMenu = 0;
GdkPixbuf *_trayPixbuf = 0; GdkPixbuf *_trayPixbuf = 0;
QByteArray _trayPixbufData; QByteArray _trayPixbufData;
QList<QPair<GtkWidget*, QObject*> > _trayItems; QList<QPair<GtkWidget*, QObject*> > _trayItems;
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
int32 _trayIconSize = 22; int32 _trayIconSize = 22;
bool _trayIconMuted = true; bool _trayIconMuted = true;
int32 _trayIconCount = 0; int32 _trayIconCount = 0;
QImage _trayIconImageBack, _trayIconImage; QImage _trayIconImageBack, _trayIconImage;
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
void _trayIconPopup(GtkStatusIcon *status_icon, guint button, guint32 activate_time, gpointer popup_menu) { void _trayIconPopup(GtkStatusIcon *status_icon, guint button, guint32 activate_time, gpointer popup_menu) {
Libs::gtk_menu_popup(Libs::gtk_menu_cast(popup_menu), NULL, NULL, Libs::gtk_status_icon_position_menu, status_icon, button, activate_time); Libs::gtk_menu_popup(Libs::gtk_menu_cast(popup_menu), NULL, NULL, Libs::gtk_status_icon_position_menu, status_icon, button, activate_time);
} }
@ -65,16 +68,19 @@ gboolean _trayIconResized(GtkStatusIcon *status_icon, gint size, gpointer popup_
if (Global::started()) Notify::unreadCounterUpdated(); if (Global::started()) Notify::unreadCounterUpdated();
return FALSE; return FALSE;
} }
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
#define QT_RED 0 #define QT_RED 0
#define QT_GREEN 1 #define QT_GREEN 1
#define QT_BLUE 2 #define QT_BLUE 2
#define QT_ALPHA 3 #define QT_ALPHA 3
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
#define GTK_RED 2 #define GTK_RED 2
#define GTK_GREEN 1 #define GTK_GREEN 1
#define GTK_BLUE 0 #define GTK_BLUE 0
#define GTK_ALPHA 3 #define GTK_ALPHA 3
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
QImage _trayIconImageGen() { QImage _trayIconImageGen() {
int32 counter = App::histories().unreadBadge(), counterSlice = (counter >= 1000) ? (1000 + (counter % 100)) : counter; int32 counter = App::histories().unreadBadge(), counterSlice = (counter >= 1000) ? (1000 + (counter % 100)) : counter;
@ -133,6 +139,7 @@ QString _trayIconImageFile() {
return QString(); return QString();
} }
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
void loadPixbuf(QImage image) { void loadPixbuf(QImage image) {
int w = image.width(), h = image.height(), perline = image.bytesPerLine(), s = image.byteCount(); int w = image.width(), h = image.height(), perline = image.bytesPerLine(), s = image.byteCount();
@ -180,6 +187,7 @@ static gboolean _trayIconCheck(gpointer/* pIn*/) {
#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION #ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION
UnityLauncherEntry *_psUnityLauncherEntry = nullptr; UnityLauncherEntry *_psUnityLauncherEntry = nullptr;
#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION #endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} // namespace } // namespace
@ -192,11 +200,17 @@ MainWindow::MainWindow() {
} }
bool MainWindow::hasTrayIcon() const { bool MainWindow::hasTrayIcon() const {
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
return trayIcon || ((useAppIndicator || (useStatusIcon && trayIconChecked)) && (Global::WorkMode().value() != dbiwmWindowOnly)); return trayIcon || ((useAppIndicator || (useStatusIcon && trayIconChecked)) && (Global::WorkMode().value() != dbiwmWindowOnly));
#else
return trayIcon;
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} }
void MainWindow::psStatusIconCheck() { void MainWindow::psStatusIconCheck() {
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
_trayIconCheck(0); _trayIconCheck(0);
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
if (cSupportTray() || !--_psCheckStatusIconLeft) { if (cSupportTray() || !--_psCheckStatusIconLeft) {
_psCheckStatusIconTimer.stop(); _psCheckStatusIconTimer.stop();
return; return;
@ -207,6 +221,7 @@ void MainWindow::psShowTrayMenu() {
} }
void MainWindow::psTrayMenuUpdated() { void MainWindow::psTrayMenuUpdated() {
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
if (noQtTrayIcon && (useAppIndicator || useStatusIcon)) { if (noQtTrayIcon && (useAppIndicator || useStatusIcon)) {
const QList<QAction*> &actions = trayIconMenu->actions(); const QList<QAction*> &actions = trayIconMenu->actions();
if (_trayItems.isEmpty()) { if (_trayItems.isEmpty()) {
@ -230,6 +245,7 @@ void MainWindow::psTrayMenuUpdated() {
} }
} }
} }
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} }
void MainWindow::psSetupTrayIcon() { void MainWindow::psSetupTrayIcon() {
@ -273,11 +289,13 @@ void MainWindow::workmodeUpdated(DBIWorkMode mode) {
if (mode == dbiwmWindowOnly) { if (mode == dbiwmWindowOnly) {
if (noQtTrayIcon) { if (noQtTrayIcon) {
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
if (useAppIndicator) { if (useAppIndicator) {
Libs::app_indicator_set_status(_trayIndicator, APP_INDICATOR_STATUS_PASSIVE); Libs::app_indicator_set_status(_trayIndicator, APP_INDICATOR_STATUS_PASSIVE);
} else if (useStatusIcon) { } else if (useStatusIcon) {
Libs::gtk_status_icon_set_visible(_trayIcon, false); Libs::gtk_status_icon_set_visible(_trayIcon, false);
} }
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} else { } else {
if (trayIcon) { if (trayIcon) {
trayIcon->setContextMenu(0); trayIcon->setContextMenu(0);
@ -287,11 +305,13 @@ void MainWindow::workmodeUpdated(DBIWorkMode mode) {
} }
} else { } else {
if (noQtTrayIcon) { if (noQtTrayIcon) {
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
if (useAppIndicator) { if (useAppIndicator) {
Libs::app_indicator_set_status(_trayIndicator, APP_INDICATOR_STATUS_ACTIVE); Libs::app_indicator_set_status(_trayIndicator, APP_INDICATOR_STATUS_ACTIVE);
} else if (useStatusIcon) { } else if (useStatusIcon) {
Libs::gtk_status_icon_set_visible(_trayIcon, true); Libs::gtk_status_icon_set_visible(_trayIcon, true);
} }
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} else { } else {
psSetupTrayIcon(); psSetupTrayIcon();
} }
@ -299,6 +319,7 @@ void MainWindow::workmodeUpdated(DBIWorkMode mode) {
} }
void MainWindow::psUpdateIndicator() { void MainWindow::psUpdateIndicator() {
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
_psUpdateIndicatorTimer.stop(); _psUpdateIndicatorTimer.stop();
_psLastIndicatorUpdate = getms(); _psLastIndicatorUpdate = getms();
QFileInfo iconFile(_trayIconImageFile()); QFileInfo iconFile(_trayIconImageFile());
@ -309,6 +330,7 @@ void MainWindow::psUpdateIndicator() {
} else { } else {
useAppIndicator = false; useAppIndicator = false;
} }
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} }
void MainWindow::unreadCounterChangedHook() { void MainWindow::unreadCounterChangedHook() {
@ -321,7 +343,7 @@ void MainWindow::updateIconCounters() {
auto counter = App::histories().unreadBadge(); auto counter = App::histories().unreadBadge();
#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION #if !defined(TDESKTOP_DISABLE_GTK_INTEGRATION) && !defined(TDESKTOP_DISABLE_UNITY_INTEGRATION)
if (_psUnityLauncherEntry) { if (_psUnityLauncherEntry) {
if (counter > 0) { if (counter > 0) {
Libs::unity_launcher_entry_set_count(_psUnityLauncherEntry, (counter > 9999) ? 9999 : counter); Libs::unity_launcher_entry_set_count(_psUnityLauncherEntry, (counter > 9999) ? 9999 : counter);
@ -330,9 +352,10 @@ void MainWindow::updateIconCounters() {
Libs::unity_launcher_entry_set_count_visible(_psUnityLauncherEntry, FALSE); Libs::unity_launcher_entry_set_count_visible(_psUnityLauncherEntry, FALSE);
} }
} }
#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION #endif // !TDESKTOP_DISABLE_GTK_INTEGRATION && !TDESKTOP_DISABLE_UNITY_INTEGRATION
if (noQtTrayIcon) { if (noQtTrayIcon) {
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
if (useAppIndicator) { if (useAppIndicator) {
if (getms() > _psLastIndicatorUpdate + 1000) { if (getms() > _psLastIndicatorUpdate + 1000) {
psUpdateIndicator(); psUpdateIndicator();
@ -349,6 +372,7 @@ void MainWindow::updateIconCounters() {
Libs::gtk_status_icon_set_from_pixbuf(_trayIcon, _trayPixbuf); Libs::gtk_status_icon_set_from_pixbuf(_trayIcon, _trayPixbuf);
} }
} }
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} else if (trayIcon) { } else if (trayIcon) {
QIcon icon; QIcon icon;
QFileInfo iconFile(_trayIconImageFile()); QFileInfo iconFile(_trayIconImageFile());
@ -370,12 +394,15 @@ void MainWindow::updateIconCounters() {
void MainWindow::LibsLoaded() { void MainWindow::LibsLoaded() {
noQtTrayIcon = !DesktopEnvironment::TryQtTrayIcon(); noQtTrayIcon = !DesktopEnvironment::TryQtTrayIcon();
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
tryAppIndicator = DesktopEnvironment::PreferAppIndicatorTrayIcon(); tryAppIndicator = DesktopEnvironment::PreferAppIndicatorTrayIcon();
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
LOG(("Tray Icon: Try Qt = %1, Prefer appindicator = %2").arg(Logs::b(!noQtTrayIcon)).arg(Logs::b(tryAppIndicator))); LOG(("Tray Icon: Try Qt = %1, Prefer appindicator = %2").arg(Logs::b(!noQtTrayIcon)).arg(Logs::b(tryAppIndicator)));
if (noQtTrayIcon) cSetSupportTray(false); if (noQtTrayIcon) cSetSupportTray(false);
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
useGtkBase = (Libs::gtk_init_check != nullptr) useGtkBase = (Libs::gtk_init_check != nullptr)
&& (Libs::gtk_menu_new != nullptr) && (Libs::gtk_menu_new != nullptr)
&& (Libs::gtk_menu_get_type != nullptr) && (Libs::gtk_menu_get_type != nullptr)
@ -430,6 +457,7 @@ void MainWindow::LibsLoaded() {
DEBUG_LOG(("Unity count api loaded!")); DEBUG_LOG(("Unity count api loaded!"));
} }
#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION #endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} }
void MainWindow::psCreateTrayIcon() { void MainWindow::psCreateTrayIcon() {
@ -439,6 +467,7 @@ void MainWindow::psCreateTrayIcon() {
return; return;
} }
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
if (useAppIndicator) { if (useAppIndicator) {
DEBUG_LOG(("Trying to create AppIndicator")); DEBUG_LOG(("Trying to create AppIndicator"));
_trayMenu = Libs::gtk_menu_new(); _trayMenu = Libs::gtk_menu_new();
@ -516,12 +545,13 @@ void MainWindow::psCreateTrayIcon() {
} else { } else {
workmodeUpdated(Global::WorkMode().value()); workmodeUpdated(Global::WorkMode().value());
} }
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} }
void MainWindow::psFirstShow() { void MainWindow::psFirstShow() {
psCreateTrayIcon(); psCreateTrayIcon();
#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION #if !defined(TDESKTOP_DISABLE_GTK_INTEGRATION) && !defined(TDESKTOP_DISABLE_UNITY_INTEGRATION)
if (useUnityCount) { if (useUnityCount) {
_psUnityLauncherEntry = Libs::unity_launcher_entry_get_for_desktop_id("telegramdesktop.desktop"); _psUnityLauncherEntry = Libs::unity_launcher_entry_get_for_desktop_id("telegramdesktop.desktop");
if (_psUnityLauncherEntry) { if (_psUnityLauncherEntry) {
@ -537,7 +567,7 @@ void MainWindow::psFirstShow() {
} else { } else {
LOG(("Not using Unity Launcher count.")); LOG(("Not using Unity Launcher count."));
} }
#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION #endif // !TDESKTOP_DISABLE_GTK_INTEGRATION && !TDESKTOP_DISABLE_GTK_INTEGRATION
psUpdateMargins(); psUpdateMargins();
@ -572,6 +602,7 @@ void MainWindow::psUpdateMargins() {
} }
MainWindow::~MainWindow() { MainWindow::~MainWindow() {
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
if (_trayIcon) { if (_trayIcon) {
Libs::g_object_unref(_trayIcon); Libs::g_object_unref(_trayIcon);
_trayIcon = nullptr; _trayIcon = nullptr;
@ -594,7 +625,8 @@ MainWindow::~MainWindow() {
Libs::g_object_unref(_psUnityLauncherEntry); Libs::g_object_unref(_psUnityLauncherEntry);
_psUnityLauncherEntry = nullptr; _psUnityLauncherEntry = nullptr;
} }
#endif #endif // ! TDESKTOP_DISABLE_UNITY_INTEGRATION
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} }
} // namespace Platform } // namespace Platform

View file

@ -28,6 +28,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
namespace Platform { namespace Platform {
namespace Notifications { namespace Notifications {
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
namespace { namespace {
bool LibNotifyLoaded() { bool LibNotifyLoaded() {
@ -269,8 +270,10 @@ QString GetServerName() {
auto LibNotifyServerName = QString(); auto LibNotifyServerName = QString();
} // namespace } // namespace
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
bool Supported() { bool Supported() {
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
static auto Checked = false; static auto Checked = false;
if (!Checked) { if (!Checked) {
Checked = true; Checked = true;
@ -278,23 +281,31 @@ bool Supported() {
} }
return !LibNotifyServerName.isEmpty(); return !LibNotifyServerName.isEmpty();
#else
return false;
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} }
std::unique_ptr<Window::Notifications::Manager> Create(Window::Notifications::System *system) { std::unique_ptr<Window::Notifications::Manager> Create(Window::Notifications::System *system) {
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
if (Global::NativeNotifications() && Supported()) { if (Global::NativeNotifications() && Supported()) {
return std::make_unique<Manager>(system); return std::make_unique<Manager>(system);
} }
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
return nullptr; return nullptr;
} }
void Finish() { void Finish() {
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
if (Libs::notify_is_initted && Libs::notify_uninit) { if (Libs::notify_is_initted && Libs::notify_uninit) {
if (Libs::notify_is_initted()) { if (Libs::notify_is_initted()) {
Libs::notify_uninit(); Libs::notify_uninit();
} }
} }
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} }
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
class Manager::Private { class Manager::Private {
public: public:
using Type = Window::Notifications::CachedUserpics::Type; using Type = Window::Notifications::CachedUserpics::Type;
@ -347,7 +358,9 @@ private:
std::shared_ptr<Manager*> _guarded; std::shared_ptr<Manager*> _guarded;
}; };
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
void Manager::Private::init(Manager *manager) { void Manager::Private::init(Manager *manager) {
_guarded = std::make_shared<Manager*>(manager); _guarded = std::make_shared<Manager*>(manager);
@ -543,6 +556,7 @@ void Manager::doClearAllFast() {
void Manager::doClearFromHistory(History *history) { void Manager::doClearFromHistory(History *history) {
_private->clearFromHistory(history); _private->clearFromHistory(history);
} }
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
} // namespace Notifications } // namespace Notifications
} // namespace Platform } // namespace Platform

View file

@ -20,6 +20,7 @@
{ {
'conditions': [[ 'build_linux', { 'conditions': [[ 'build_linux', {
'variables': { 'variables': {
'not_need_gtk%': '<!(python -c "print(\'TDESKTOP_DISABLE_GTK_INTEGRATION\' in \'<(build_defines)\')")',
'pkgconfig_libs': [ 'pkgconfig_libs': [
# In order to work libxkbcommon must be linked statically, # In order to work libxkbcommon must be linked statically,
# PKGCONFIG links it like "-L/usr/local/lib -lxkbcommon" # PKGCONFIG links it like "-L/usr/local/lib -lxkbcommon"
@ -73,12 +74,14 @@
'libz.a', 'libz.a',
# '<!(pkg-config 2> /dev/null --libs <@(pkgconfig_libs))', # '<!(pkg-config 2> /dev/null --libs <@(pkgconfig_libs))',
], ],
'cflags_cc': [ 'conditions': [['not_need_gtk!="True"', {
'<!(pkg-config 2> /dev/null --cflags appindicator-0.1)', 'cflags_cc': [
'<!(pkg-config 2> /dev/null --cflags gtk+-2.0)', '<!(pkg-config 2> /dev/null --cflags appindicator-0.1)',
'<!(pkg-config 2> /dev/null --cflags glib-2.0)', '<!(pkg-config 2> /dev/null --cflags gtk+-2.0)',
'<!(pkg-config 2> /dev/null --cflags dee-1.0)', '<!(pkg-config 2> /dev/null --cflags glib-2.0)',
], '<!(pkg-config 2> /dev/null --cflags dee-1.0)',
],
}]],
'configurations': { 'configurations': {
'Release': { 'Release': {
'cflags': [ 'cflags': [