mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 02:01:40 -05:00
tray icon by libappindicator with gtk_status_icon fallback added, unity launcher count added
This commit is contained in:
parent
ac5834c863
commit
1a8444740a
15 changed files with 655 additions and 67 deletions
|
@ -30,7 +30,7 @@ or download in ZIP and extract to **/home/user/TBuild** rename **tdesktop-master
|
|||
|
||||
Install dev libraries
|
||||
|
||||
sudo apt-get install libexif-dev liblzma-dev libz-dev libssl-dev
|
||||
sudo apt-get install libexif-dev liblzma-dev libz-dev libssl-dev libappindicator-dev libunity-dev
|
||||
|
||||
Install audio libraries
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ void debugLogWrite(const char *file, int32 line, const QString &v) {
|
|||
#elif defined Q_OS_MAC
|
||||
objc_outputDebugString(msg);
|
||||
#elif defined Q_OS_LINUX && defined _DEBUG
|
||||
std::cout << msg.toUtf8().constData();
|
||||
// std::cout << msg.toUtf8().constData();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,9 +29,356 @@ Copyright (c) 2014 John Preston, https://desktop.telegram.org
|
|||
#include <dirent.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#undef signals
|
||||
extern "C" {
|
||||
#include <libappindicator/app-indicator.h>
|
||||
#include <gtk/gtk.h>
|
||||
}
|
||||
#define signals public
|
||||
|
||||
#include <unity/unity/unity.h>
|
||||
|
||||
namespace {
|
||||
bool frameless = true;
|
||||
bool finished = true;
|
||||
bool useAppIndicator = false, useStatusIcon = false, trayIconChecked = false, useUnityCount = false;
|
||||
|
||||
AppIndicator *_trayIndicator = 0;
|
||||
GtkStatusIcon *_trayIcon = 0;
|
||||
GtkWidget *_trayMenu = 0;
|
||||
GdkPixbuf *_trayPixbuf = 0;
|
||||
QByteArray _trayPixbufData;
|
||||
QList<QPair<GtkWidget*, QObject*> > _trayItems;
|
||||
|
||||
int32 _trayIconSize = 22;
|
||||
bool _trayIconMuted = true;
|
||||
int32 _trayIconCount = 0;
|
||||
QImage _trayIconImageBack, _trayIconImage;
|
||||
|
||||
typedef gboolean (*f_gtk_init_check)(int *argc, char ***argv);
|
||||
f_gtk_init_check ps_gtk_init_check = 0;
|
||||
|
||||
typedef GtkWidget* (*f_gtk_menu_new)(void);
|
||||
f_gtk_menu_new ps_gtk_menu_new = 0;
|
||||
|
||||
typedef GType (*f_gtk_menu_get_type)(void) G_GNUC_CONST;
|
||||
f_gtk_menu_get_type ps_gtk_menu_get_type = 0;
|
||||
|
||||
typedef GtkWidget* (*f_gtk_menu_item_new_with_label)(const gchar *label);
|
||||
f_gtk_menu_item_new_with_label ps_gtk_menu_item_new_with_label = 0;
|
||||
|
||||
typedef void (*f_gtk_menu_item_set_label)(GtkMenuItem *menu_item, const gchar *label);
|
||||
f_gtk_menu_item_set_label ps_gtk_menu_item_set_label = 0;
|
||||
|
||||
typedef void (*f_gtk_menu_shell_append)(GtkMenuShell *menu_shell, GtkWidget *child);
|
||||
f_gtk_menu_shell_append ps_gtk_menu_shell_append = 0;
|
||||
|
||||
typedef GType (*f_gtk_menu_shell_get_type)(void) G_GNUC_CONST;
|
||||
f_gtk_menu_shell_get_type ps_gtk_menu_shell_get_type = 0;
|
||||
|
||||
typedef void (*f_gtk_widget_show)(GtkWidget *widget);
|
||||
f_gtk_widget_show ps_gtk_widget_show = 0;
|
||||
|
||||
typedef GtkWidget* (*f_gtk_widget_get_toplevel)(GtkWidget *widget);
|
||||
f_gtk_widget_get_toplevel ps_gtk_widget_get_toplevel = 0;
|
||||
|
||||
typedef gboolean (*f_gtk_widget_get_visible)(GtkWidget *widget);
|
||||
f_gtk_widget_get_visible ps_gtk_widget_get_visible = 0;
|
||||
|
||||
typedef void (*f_gtk_widget_set_sensitive)(GtkWidget *widget, gboolean sensitive);
|
||||
f_gtk_widget_set_sensitive ps_gtk_widget_set_sensitive = 0;
|
||||
|
||||
typedef GTypeInstance* (*f_g_type_check_instance_cast)(GTypeInstance *instance, GType iface_type);
|
||||
f_g_type_check_instance_cast ps_g_type_check_instance_cast = 0;
|
||||
|
||||
#define _PS_G_TYPE_CIC(ip, gt, ct) ((ct*)ps_g_type_check_instance_cast((GTypeInstance*) ip, gt))
|
||||
#define PS_G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type) (_PS_G_TYPE_CIC((instance), (g_type), c_type))
|
||||
#define PS_GTK_TYPE_MENU (ps_gtk_menu_get_type())
|
||||
#define PS_GTK_MENU(obj) (PS_G_TYPE_CHECK_INSTANCE_CAST((obj), PS_GTK_TYPE_MENU, GtkMenu))
|
||||
#define PS_GTK_TYPE_MENU_SHELL (ps_gtk_menu_shell_get_type())
|
||||
#define PS_GTK_MENU_SHELL(obj) (PS_G_TYPE_CHECK_INSTANCE_CAST((obj), PS_GTK_TYPE_MENU_SHELL, GtkMenuShell))
|
||||
|
||||
typedef gulong (*f_g_signal_connect_data)(gpointer instance, const gchar *detailed_signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags);
|
||||
f_g_signal_connect_data ps_g_signal_connect_data = 0;
|
||||
|
||||
#define ps_g_signal_connect(instance, detailed_signal, c_handler, data) ps_g_signal_connect_data((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags)0)
|
||||
|
||||
typedef AppIndicator* (*f_app_indicator_new)(const gchar *id, const gchar *icon_name, AppIndicatorCategory category);
|
||||
f_app_indicator_new ps_app_indicator_new = 0;
|
||||
|
||||
typedef void (*f_app_indicator_set_status)(AppIndicator *self, AppIndicatorStatus status);
|
||||
f_app_indicator_set_status ps_app_indicator_set_status = 0;
|
||||
|
||||
typedef void (*f_app_indicator_set_menu)(AppIndicator *self, GtkMenu *menu);
|
||||
f_app_indicator_set_menu ps_app_indicator_set_menu = 0;
|
||||
|
||||
typedef void (*f_app_indicator_set_icon)(AppIndicator *self, const gchar *icon_name);
|
||||
f_app_indicator_set_icon ps_app_indicator_set_icon = 0;
|
||||
|
||||
typedef gboolean (*f_gdk_init_check)(gint *argc, gchar ***argv);
|
||||
f_gdk_init_check ps_gdk_init_check = 0;
|
||||
|
||||
typedef GdkPixbuf* (*f_gdk_pixbuf_new_from_data)(const guchar *data, GdkColorspace colorspace, gboolean has_alpha, int bits_per_sample, int width, int height, int rowstride, GdkPixbufDestroyNotify destroy_fn, gpointer destroy_fn_data);
|
||||
f_gdk_pixbuf_new_from_data ps_gdk_pixbuf_new_from_data = 0;
|
||||
|
||||
typedef GtkStatusIcon* (*f_gtk_status_icon_new_from_pixbuf)(GdkPixbuf *pixbuf);
|
||||
f_gtk_status_icon_new_from_pixbuf ps_gtk_status_icon_new_from_pixbuf = 0;
|
||||
|
||||
typedef void (*f_gtk_status_icon_set_from_pixbuf)(GtkStatusIcon *status_icon, GdkPixbuf *pixbuf);
|
||||
f_gtk_status_icon_set_from_pixbuf ps_gtk_status_icon_set_from_pixbuf = 0;
|
||||
|
||||
typedef void (*f_gtk_status_icon_set_title)(GtkStatusIcon *status_icon, const gchar *title);
|
||||
f_gtk_status_icon_set_title ps_gtk_status_icon_set_title = 0;
|
||||
|
||||
typedef void (*f_gtk_status_icon_set_tooltip_text)(GtkStatusIcon *status_icon, const gchar *title);
|
||||
f_gtk_status_icon_set_tooltip_text ps_gtk_status_icon_set_tooltip_text = 0;
|
||||
|
||||
typedef void (*f_gtk_status_icon_set_visible)(GtkStatusIcon *status_icon, gboolean visible);
|
||||
f_gtk_status_icon_set_visible ps_gtk_status_icon_set_visible = 0;
|
||||
|
||||
typedef gboolean (*f_gtk_status_icon_is_embedded)(GtkStatusIcon *status_icon);
|
||||
f_gtk_status_icon_is_embedded ps_gtk_status_icon_is_embedded = 0;
|
||||
|
||||
typedef gboolean (*f_gtk_status_icon_get_geometry)(GtkStatusIcon *status_icon, GdkScreen **screen, GdkRectangle *area, GtkOrientation *orientation);
|
||||
f_gtk_status_icon_get_geometry ps_gtk_status_icon_get_geometry = 0;
|
||||
|
||||
typedef void (*f_gtk_status_icon_position_menu)(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data);
|
||||
f_gtk_status_icon_position_menu ps_gtk_status_icon_position_menu = 0;
|
||||
|
||||
typedef void (*f_gtk_menu_popup)(GtkMenu *menu, GtkWidget *parent_menu_shell, GtkWidget *parent_menu_item, GtkMenuPositionFunc func, gpointer data, guint button, guint32 activate_time);
|
||||
f_gtk_menu_popup ps_gtk_menu_popup = 0;
|
||||
|
||||
typedef guint32 (*f_gtk_get_current_event_time)(void);
|
||||
f_gtk_get_current_event_time ps_gtk_get_current_event_time = 0;
|
||||
|
||||
typedef gpointer (*f_g_object_ref_sink)(gpointer object);
|
||||
f_g_object_ref_sink ps_g_object_ref_sink = 0;
|
||||
|
||||
typedef void (*f_g_object_unref)(gpointer object);
|
||||
f_g_object_unref ps_g_object_unref = 0;
|
||||
|
||||
typedef guint (*f_g_idle_add)(GSourceFunc function, gpointer data);
|
||||
f_g_idle_add ps_g_idle_add = 0;
|
||||
|
||||
typedef void (*f_unity_launcher_entry_set_count)(UnityLauncherEntry* self, gint64 value);
|
||||
f_unity_launcher_entry_set_count ps_unity_launcher_entry_set_count = 0;
|
||||
|
||||
typedef void (*f_unity_launcher_entry_set_count_visible)(UnityLauncherEntry* self, gboolean value);
|
||||
f_unity_launcher_entry_set_count_visible ps_unity_launcher_entry_set_count_visible = 0;
|
||||
|
||||
typedef UnityLauncherEntry* (*f_unity_launcher_entry_get_for_desktop_id)(const gchar* desktop_id);
|
||||
f_unity_launcher_entry_get_for_desktop_id ps_unity_launcher_entry_get_for_desktop_id = 0;
|
||||
|
||||
template <typename TFunction>
|
||||
bool loadFunction(QLibrary &lib, const char *name, TFunction &func) {
|
||||
if (!lib.isLoaded()) return false;
|
||||
|
||||
func = (TFunction)lib.resolve(name);
|
||||
return !!func;
|
||||
}
|
||||
|
||||
void _trayIconPopup(GtkStatusIcon *status_icon, guint button, guint32 activate_time, gpointer popup_menu) {
|
||||
ps_gtk_menu_popup(PS_GTK_MENU(popup_menu), NULL, NULL, ps_gtk_status_icon_position_menu, status_icon, button, activate_time);
|
||||
}
|
||||
|
||||
void _trayIconActivate(GtkStatusIcon *status_icon, gpointer popup_menu) {
|
||||
if (App::wnd()->isActiveWindow() && App::wnd()->isVisible()) {
|
||||
ps_gtk_menu_popup(PS_GTK_MENU(popup_menu), NULL, NULL, ps_gtk_status_icon_position_menu, status_icon, 0, ps_gtk_get_current_event_time());
|
||||
} else {
|
||||
App::wnd()->showFromTray();
|
||||
}
|
||||
}
|
||||
|
||||
gboolean _trayIconResized(GtkStatusIcon *status_icon, gint size, gpointer popup_menu) {
|
||||
std::cerr << "New tray icon size: " << size << "\n";
|
||||
_trayIconSize = size - 2;
|
||||
if (App::wnd()) App::wnd()->psUpdateCounter();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
|
||||
|
||||
#define QT_RED 3
|
||||
#define QT_GREEN 2
|
||||
#define QT_BLUE 1
|
||||
#define QT_ALPHA 0
|
||||
|
||||
#else
|
||||
|
||||
#define QT_RED 0
|
||||
#define QT_GREEN 1
|
||||
#define QT_BLUE 2
|
||||
#define QT_ALPHA 3
|
||||
|
||||
#endif
|
||||
|
||||
#define GTK_RED 2
|
||||
#define GTK_GREEN 1
|
||||
#define GTK_BLUE 0
|
||||
#define GTK_ALPHA 3
|
||||
|
||||
QImage _trayIconImageGen() {
|
||||
int32 counter = App::histories().unreadFull, counterSlice = (counter >= 1000) ? (1000 + (counter % 100)) : counter;
|
||||
bool muted = (App::histories().unreadMuted >= counter);
|
||||
if (_trayIconImage.isNull() || _trayIconImage.width() != _trayIconSize || muted != _trayIconMuted || counterSlice != _trayIconCount) {
|
||||
if (_trayIconImageBack.isNull() || _trayIconImageBack.width() != _trayIconSize) {
|
||||
_trayIconImageBack = App::wnd()->iconLarge().scaled(_trayIconSize, _trayIconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
_trayIconImageBack = _trayIconImageBack.convertToFormat(QImage::Format_ARGB32);
|
||||
int w = _trayIconImageBack.width(), h = _trayIconImageBack.height(), perline = _trayIconImageBack.bytesPerLine();
|
||||
uchar *bytes = _trayIconImageBack.bits();
|
||||
for (int32 y = 0; y < h; ++y) {
|
||||
for (int32 x = 0; x < w; ++x) {
|
||||
int32 srcoff = y * perline + x * 4;
|
||||
bytes[srcoff + QT_RED ] = qMax(bytes[srcoff + QT_RED ], uchar(224));
|
||||
bytes[srcoff + QT_GREEN] = qMax(bytes[srcoff + QT_GREEN], uchar(165));
|
||||
bytes[srcoff + QT_BLUE ] = qMax(bytes[srcoff + QT_BLUE ], uchar(44));
|
||||
}
|
||||
}
|
||||
}
|
||||
_trayIconImage = _trayIconImageBack;
|
||||
if (counter > 0) {
|
||||
QPainter p(&_trayIconImage);
|
||||
int32 layerSize = -16;
|
||||
if (_trayIconSize >= 48) {
|
||||
layerSize = -32;
|
||||
} else if (_trayIconSize >= 36) {
|
||||
layerSize = -24;
|
||||
} else if (_trayIconSize >= 32) {
|
||||
layerSize = -20;
|
||||
}
|
||||
QImage layer = App::wnd()->iconWithCounter(layerSize, counter, (muted ? st::counterMuteBG : st::counterBG), false);
|
||||
p.drawImage(_trayIconImage.width() - layer.width(), _trayIconImage.height() - layer.height(), layer);
|
||||
}
|
||||
}
|
||||
return _trayIconImage;
|
||||
}
|
||||
|
||||
QString _trayIconImageFile() {
|
||||
int32 counter = App::histories().unreadFull, counterSlice = (counter >= 1000) ? (1000 + (counter % 100)) : counter;
|
||||
bool muted = (App::histories().unreadMuted >= counter);
|
||||
|
||||
QString name = cWorkingDir() + qsl("tdata/ticons/ico%1_%2_%3.png").arg(muted ? "mute" : "").arg(_trayIconSize).arg(counterSlice);
|
||||
QFileInfo info(name);
|
||||
if (info.exists()) return name;
|
||||
|
||||
QImage img = _trayIconImageGen();
|
||||
if (img.save(name, "PNG")) return name;
|
||||
|
||||
QDir dir(info.absoluteDir());
|
||||
if (!dir.exists()) {
|
||||
dir.mkpath(dir.absolutePath());
|
||||
if (img.save(name, "PNG")) return name;
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
void loadPixbuf(QImage image) {
|
||||
int w = image.width(), h = image.height(), perline = image.bytesPerLine(), s = image.byteCount();
|
||||
_trayPixbufData.resize(w * h * 4);
|
||||
uchar *result = (uchar*)_trayPixbufData.data(), *bytes = image.bits();
|
||||
for (int32 y = 0; y < h; ++y) {
|
||||
for (int32 x = 0; x < w; ++x) {
|
||||
int32 offset = (y * w + x) * 4, srcoff = y * perline + x * 4;
|
||||
result[offset + GTK_RED ] = bytes[srcoff + QT_RED ];
|
||||
result[offset + GTK_GREEN] = bytes[srcoff + QT_GREEN];
|
||||
result[offset + GTK_BLUE ] = bytes[srcoff + QT_BLUE ];
|
||||
result[offset + GTK_ALPHA] = bytes[srcoff + QT_ALPHA];
|
||||
}
|
||||
}
|
||||
|
||||
if (_trayPixbuf) ps_g_object_unref(_trayPixbuf);
|
||||
_trayPixbuf = ps_gdk_pixbuf_new_from_data(result, GDK_COLORSPACE_RGB, true, 8, w, h, w * 4, 0, 0);
|
||||
}
|
||||
|
||||
void _trayMenuCallback(GtkMenu *menu, gpointer data) {
|
||||
for (int32 i = 0, l = _trayItems.size(); i < l; ++i) {
|
||||
if ((void*)_trayItems.at(i).first == (void*)menu) {
|
||||
QMetaObject::invokeMethod(_trayItems.at(i).second, "triggered");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean _trayIconCheck(gpointer/* pIn*/) {
|
||||
if (useStatusIcon && !trayIconChecked) {
|
||||
if (ps_gtk_status_icon_is_embedded(_trayIcon)) {
|
||||
trayIconChecked = true;
|
||||
cSetSupportTray(true);
|
||||
if (App::wnd()) {
|
||||
App::wnd()->psUpdateWorkmode();
|
||||
App::wnd()->psUpdateCounter();
|
||||
App::wnd()->updateTrayMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
class _PsInitializer {
|
||||
public:
|
||||
_PsInitializer() {
|
||||
setupGTK();
|
||||
setupUnity();
|
||||
}
|
||||
void setupGTK() {
|
||||
QLibrary lib_gtk(QLatin1String("gtk-x11-2.0"), 0, 0), lib_indicator(QLatin1String("appindicator"));
|
||||
if (!lib_gtk.load()) return;
|
||||
|
||||
if (!loadFunction(lib_gtk, "gtk_init_check", ps_gtk_init_check)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_menu_new", ps_gtk_menu_new)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_menu_get_type", ps_gtk_menu_get_type)) return;
|
||||
|
||||
if (!loadFunction(lib_gtk, "gtk_menu_item_new_with_label", ps_gtk_menu_item_new_with_label)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_menu_item_set_label", ps_gtk_menu_item_set_label)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_menu_shell_append", ps_gtk_menu_shell_append)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_menu_shell_get_type", ps_gtk_menu_shell_get_type)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_widget_show", ps_gtk_widget_show)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_widget_get_toplevel", ps_gtk_widget_get_toplevel)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_widget_get_visible", ps_gtk_widget_get_visible)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_widget_set_sensitive", ps_gtk_widget_set_sensitive)) return;
|
||||
|
||||
if (!loadFunction(lib_gtk, "g_type_check_instance_cast", ps_g_type_check_instance_cast)) return;
|
||||
if (!loadFunction(lib_gtk, "g_signal_connect_data", ps_g_signal_connect_data)) return;
|
||||
|
||||
if (lib_indicator.load()) setupAppIndicator(lib_indicator);
|
||||
|
||||
if (!loadFunction(lib_gtk, "gdk_init_check", ps_gdk_init_check)) return;
|
||||
if (!loadFunction(lib_gtk, "gdk_pixbuf_new_from_data", ps_gdk_pixbuf_new_from_data)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_status_icon_new_from_pixbuf", ps_gtk_status_icon_new_from_pixbuf)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_status_icon_set_from_pixbuf", ps_gtk_status_icon_set_from_pixbuf)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_status_icon_set_title", ps_gtk_status_icon_set_title)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_status_icon_set_tooltip_text", ps_gtk_status_icon_set_tooltip_text)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_status_icon_set_visible", ps_gtk_status_icon_set_visible)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_status_icon_is_embedded", ps_gtk_status_icon_is_embedded)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_status_icon_get_geometry", ps_gtk_status_icon_get_geometry)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_status_icon_position_menu", ps_gtk_status_icon_position_menu)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_menu_popup", ps_gtk_menu_popup)) return;
|
||||
if (!loadFunction(lib_gtk, "gtk_get_current_event_time", ps_gtk_get_current_event_time)) return;
|
||||
if (!loadFunction(lib_gtk, "g_object_ref_sink", ps_g_object_ref_sink)) return;
|
||||
if (!loadFunction(lib_gtk, "g_object_unref", ps_g_object_unref)) return;
|
||||
if (!loadFunction(lib_gtk, "g_idle_add", ps_g_idle_add)) return;
|
||||
useStatusIcon = true;
|
||||
}
|
||||
void setupAppIndicator(QLibrary &lib_indicator) {
|
||||
if (!loadFunction(lib_indicator, "app_indicator_new", ps_app_indicator_new)) return;
|
||||
if (!loadFunction(lib_indicator, "app_indicator_set_status", ps_app_indicator_set_status)) return;
|
||||
if (!loadFunction(lib_indicator, "app_indicator_set_menu", ps_app_indicator_set_menu)) return;
|
||||
if (!loadFunction(lib_indicator, "app_indicator_set_icon", ps_app_indicator_set_icon)) return;
|
||||
useAppIndicator = true;
|
||||
}
|
||||
void setupUnity() {
|
||||
QLibrary lib_unity("unity");
|
||||
if (!lib_unity.load()) return;
|
||||
|
||||
if (!loadFunction(lib_unity, "unity_launcher_entry_get_for_desktop_id", ps_unity_launcher_entry_get_for_desktop_id)) return;
|
||||
if (!loadFunction(lib_unity, "unity_launcher_entry_set_count", ps_unity_launcher_entry_set_count)) return;
|
||||
if (!loadFunction(lib_unity, "unity_launcher_entry_set_count_visible", ps_unity_launcher_entry_set_count_visible)) return;
|
||||
useUnityCount = true;
|
||||
}
|
||||
};
|
||||
_PsInitializer _psInitializer;
|
||||
|
||||
class _PsEventFilter : public QAbstractNativeEventFilter {
|
||||
public:
|
||||
|
@ -47,12 +394,19 @@ namespace {
|
|||
};
|
||||
_PsEventFilter *_psEventFilter = 0;
|
||||
|
||||
UnityLauncherEntry *_psUnityLauncherEntry = 0;
|
||||
};
|
||||
|
||||
PsMainWindow::PsMainWindow(QWidget *parent) : QMainWindow(parent),
|
||||
posInited(false), trayIcon(0), trayIconMenu(0), icon256(qsl(":/gui/art/icon256.png")), iconbig256(icon256), wndIcon(QPixmap::fromImage(icon256, Qt::ColorOnly)) {
|
||||
posInited(false), trayIcon(0), trayIconMenu(0), icon256(qsl(":/gui/art/icon256.png")), iconbig256(icon256), wndIcon(QPixmap::fromImage(icon256, Qt::ColorOnly)), _psCheckStatusIconLeft(100), _psLastIndicatorUpdate(0) {
|
||||
connect(&psIdleTimer, SIGNAL(timeout()), this, SLOT(psIdleTimeout()));
|
||||
psIdleTimer.setSingleShot(false);
|
||||
|
||||
connect(&_psCheckStatusIconTimer, SIGNAL(timeout()), this, SLOT(psStatusIconCheck()));
|
||||
_psCheckStatusIconTimer.setSingleShot(false);
|
||||
|
||||
connect(&_psUpdateIndicatorTimer, SIGNAL(timeout()), this, SLOT(psUpdateIndicator()));
|
||||
_psUpdateIndicatorTimer.setSingleShot(true);
|
||||
}
|
||||
|
||||
void PsMainWindow::psNotIdle() const {
|
||||
|
@ -64,6 +418,18 @@ void PsMainWindow::psNotIdle() const {
|
|||
}
|
||||
}
|
||||
|
||||
bool PsMainWindow::psHasTrayIcon() const {
|
||||
return trayIcon || ((useAppIndicator || (useStatusIcon && trayIconChecked)) && (cWorkMode() != dbiwmWindowOnly));
|
||||
}
|
||||
|
||||
void PsMainWindow::psStatusIconCheck() {
|
||||
_trayIconCheck(0);
|
||||
if (cSupportTray() || !--_psCheckStatusIconLeft) {
|
||||
_psCheckStatusIconTimer.stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void PsMainWindow::psIdleTimeout() {
|
||||
int64 idleTime = 0;//objc_idleTime();
|
||||
if (idleTime >= 0) {
|
||||
|
@ -111,7 +477,61 @@ bool PsMainWindow::psIsActive(int state) const {
|
|||
void PsMainWindow::psRefreshTaskbarIcon() {
|
||||
}
|
||||
|
||||
void PsMainWindow::psTrayMenuUpdated() {
|
||||
if (useAppIndicator || useStatusIcon) {
|
||||
const QList<QAction*> &actions = trayIconMenu->actions();
|
||||
if (_trayItems.isEmpty()) {
|
||||
for (int32 i = 0, l = actions.size(); i != l; ++i) {
|
||||
GtkWidget *item = ps_gtk_menu_item_new_with_label(actions.at(i)->text().toUtf8());
|
||||
ps_gtk_menu_shell_append(PS_GTK_MENU_SHELL(_trayMenu), item);
|
||||
ps_g_signal_connect(item, "activate", G_CALLBACK(_trayMenuCallback), this);
|
||||
ps_gtk_widget_show(item);
|
||||
ps_gtk_widget_set_sensitive(item, actions.at(i)->isEnabled());
|
||||
|
||||
_trayItems.push_back(qMakePair(item, actions.at(i)));
|
||||
}
|
||||
} else {
|
||||
for (int32 i = 0, l = actions.size(); i != l; ++i) {
|
||||
if (i < _trayItems.size()) {
|
||||
ps_gtk_menu_item_set_label(reinterpret_cast<GtkMenuItem*>(_trayItems.at(i).first), actions.at(i)->text().toUtf8());
|
||||
ps_gtk_widget_set_sensitive(_trayItems.at(i).first, actions.at(i)->isEnabled());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PsMainWindow::psSetupTrayIcon() {
|
||||
if (!cSupportTray()) return;
|
||||
psUpdateCounter();
|
||||
}
|
||||
|
||||
void PsMainWindow::psUpdateWorkmode() {
|
||||
if (!cSupportTray()) return;
|
||||
|
||||
if (cWorkMode() == dbiwmWindowOnly) {
|
||||
if (useAppIndicator) {
|
||||
ps_app_indicator_set_status(_trayIndicator, APP_INDICATOR_STATUS_PASSIVE);
|
||||
} else if (useStatusIcon) {
|
||||
ps_gtk_status_icon_set_visible(_trayIcon, false);
|
||||
}
|
||||
} else {
|
||||
if (useAppIndicator) {
|
||||
ps_app_indicator_set_status(_trayIndicator, APP_INDICATOR_STATUS_ACTIVE);
|
||||
} else if (useStatusIcon) {
|
||||
ps_gtk_status_icon_set_visible(_trayIcon, true);
|
||||
}
|
||||
}
|
||||
setWindowIcon(wndIcon);
|
||||
}
|
||||
|
||||
void PsMainWindow::psUpdateIndicator() {
|
||||
_psUpdateIndicatorTimer.stop();
|
||||
_psLastIndicatorUpdate = getms();
|
||||
QByteArray f = _trayIconImageFile().toUtf8();
|
||||
if (!f.isEmpty()) {
|
||||
ps_app_indicator_set_icon(_trayIndicator, f.constData());
|
||||
}
|
||||
}
|
||||
|
||||
void PsMainWindow::psUpdateCounter() {
|
||||
|
@ -120,9 +540,25 @@ void PsMainWindow::psUpdateCounter() {
|
|||
int32 counter = App::histories().unreadFull;
|
||||
|
||||
setWindowTitle((counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram"));
|
||||
if (_psUnityLauncherEntry) {
|
||||
if (counter > 0) {
|
||||
ps_unity_launcher_entry_set_count(_psUnityLauncherEntry, (counter > 9999) ? 9999 : counter);
|
||||
ps_unity_launcher_entry_set_count_visible(_psUnityLauncherEntry, TRUE);
|
||||
} else {
|
||||
ps_unity_launcher_entry_set_count_visible(_psUnityLauncherEntry, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
QString cnt = (counter < 1000) ? QString("%1").arg(counter) : QString("..%1").arg(counter % 100, 2, 10, QChar('0'));
|
||||
//_private.setWindowBadge(counter ? cnt : QString());
|
||||
if (useAppIndicator) {
|
||||
if (getms() > _psLastIndicatorUpdate + 1000) {
|
||||
psUpdateIndicator();
|
||||
} else if (!_psUpdateIndicatorTimer.isActive()) {
|
||||
_psUpdateIndicatorTimer.start(100);
|
||||
}
|
||||
} else if (useStatusIcon && trayIconChecked) {
|
||||
loadPixbuf(_trayIconImageGen());
|
||||
ps_gtk_status_icon_set_from_pixbuf(_trayIcon, _trayPixbuf);
|
||||
}
|
||||
}
|
||||
|
||||
void PsMainWindow::psUpdateDelegate() {
|
||||
|
@ -229,8 +665,76 @@ void PsMainWindow::psStateChanged(Qt::WindowState state) {
|
|||
psSavePosition(state);
|
||||
}
|
||||
|
||||
void PsMainWindow::psCreateTrayIcon() {
|
||||
if (useAppIndicator) {
|
||||
if (ps_gtk_init_check(0, 0)) {
|
||||
_trayMenu = ps_gtk_menu_new();
|
||||
if (_trayMenu) {
|
||||
QByteArray f = _trayIconImageFile().toUtf8();
|
||||
if (f.isEmpty()) {
|
||||
useAppIndicator = false;
|
||||
} else {
|
||||
_trayIndicator = ps_app_indicator_new("Telegram Desktop", f.constData(), APP_INDICATOR_CATEGORY_COMMUNICATIONS);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_trayMenu && _trayIndicator) {
|
||||
ps_app_indicator_set_status(_trayIndicator, APP_INDICATOR_STATUS_ACTIVE);
|
||||
ps_app_indicator_set_menu(_trayIndicator, PS_GTK_MENU(_trayMenu));
|
||||
useStatusIcon = false;
|
||||
} else {
|
||||
useAppIndicator = false;
|
||||
}
|
||||
}
|
||||
if (useStatusIcon) {
|
||||
if (ps_gtk_init_check(0, 0) && ps_gdk_init_check(0, 0)) {
|
||||
if (!_trayMenu) _trayMenu = ps_gtk_menu_new();
|
||||
if (_trayMenu) {
|
||||
loadPixbuf(_trayIconImageGen());
|
||||
_trayIcon = ps_gtk_status_icon_new_from_pixbuf(_trayPixbuf);
|
||||
if (_trayIcon) {
|
||||
ps_g_signal_connect(_trayIcon, "popup-menu", GCallback(_trayIconPopup), _trayMenu);
|
||||
ps_g_signal_connect(_trayIcon, "activate", GCallback(_trayIconActivate), _trayMenu);
|
||||
ps_g_signal_connect(_trayIcon, "size-changed", GCallback(_trayIconResized), _trayMenu);
|
||||
|
||||
ps_gtk_status_icon_set_title(_trayIcon, "Telegram Desktop");
|
||||
ps_gtk_status_icon_set_tooltip_text(_trayIcon, "Telegram Desktop");
|
||||
ps_gtk_status_icon_set_visible(_trayIcon, true);
|
||||
} else {
|
||||
useStatusIcon = false;
|
||||
}
|
||||
} else {
|
||||
useStatusIcon = false;
|
||||
}
|
||||
} else {
|
||||
useStatusIcon = false;
|
||||
}
|
||||
}
|
||||
if (!useStatusIcon && !useAppIndicator) {
|
||||
if (_trayMenu) {
|
||||
ps_g_object_ref_sink(_trayMenu);
|
||||
ps_g_object_unref(_trayMenu);
|
||||
_trayMenu = 0;
|
||||
}
|
||||
}
|
||||
cSetSupportTray(useAppIndicator);
|
||||
if (useStatusIcon) {
|
||||
ps_g_idle_add((GSourceFunc)_trayIconCheck, 0);
|
||||
_psCheckStatusIconTimer.start(100);
|
||||
} else {
|
||||
psUpdateWorkmode();
|
||||
}
|
||||
}
|
||||
|
||||
void PsMainWindow::psFirstShow() {
|
||||
finished = false;
|
||||
psCreateTrayIcon();
|
||||
|
||||
if (useUnityCount) {
|
||||
_psUnityLauncherEntry = ps_unity_launcher_entry_get_for_desktop_id("telegramdesktop.desktop");
|
||||
if (!_psUnityLauncherEntry) _psUnityLauncherEntry = ps_unity_launcher_entry_get_for_desktop_id("Telegram.desktop");
|
||||
}
|
||||
|
||||
finished = false;
|
||||
|
||||
psUpdateMargins();
|
||||
|
||||
|
@ -278,7 +782,20 @@ void PsMainWindow::psFlash() {
|
|||
}
|
||||
|
||||
PsMainWindow::~PsMainWindow() {
|
||||
finished = true;
|
||||
if (_trayIcon) {
|
||||
ps_g_object_unref(_trayIcon);
|
||||
_trayIcon = 0;
|
||||
}
|
||||
if (_trayPixbuf) {
|
||||
ps_g_object_unref(_trayPixbuf);
|
||||
_trayPixbuf = 0;
|
||||
}
|
||||
if (_trayMenu) {
|
||||
ps_g_object_ref_sink(_trayMenu);
|
||||
ps_g_object_unref(_trayMenu);
|
||||
_trayMenu = 0;
|
||||
}
|
||||
finished = true;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -83,9 +83,13 @@ public slots:
|
|||
void psIdleTimeout();
|
||||
void psShowTrayMenu();
|
||||
|
||||
void psStatusIconCheck();
|
||||
void psUpdateIndicator();
|
||||
|
||||
protected:
|
||||
|
||||
void psNotIdle() const;
|
||||
bool psHasTrayIcon() const;
|
||||
|
||||
bool posInited;
|
||||
QSystemTrayIcon *trayIcon;
|
||||
|
@ -93,13 +97,22 @@ protected:
|
|||
QImage icon256, iconbig256;
|
||||
QIcon wndIcon;
|
||||
|
||||
virtual void setupTrayIcon() = 0;
|
||||
void psTrayMenuUpdated();
|
||||
void psSetupTrayIcon();
|
||||
|
||||
QTimer psUpdatedPositionTimer;
|
||||
|
||||
private:
|
||||
void psCreateTrayIcon();
|
||||
|
||||
mutable bool psIdle;
|
||||
mutable QTimer psIdleTimer;
|
||||
|
||||
QTimer _psCheckStatusIconTimer;
|
||||
int _psCheckStatusIconLeft;
|
||||
|
||||
QTimer _psUpdateIndicatorTimer;
|
||||
uint64 _psLastIndicatorUpdate;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -140,8 +140,29 @@ bool PsMainWindow::psIsActive(int state) const {
|
|||
void PsMainWindow::psRefreshTaskbarIcon() {
|
||||
}
|
||||
|
||||
void PsMainWindow::psTrayMenuUpdated() {
|
||||
}
|
||||
|
||||
void PsMainWindow::psSetupTrayIcon() {
|
||||
if (!trayIcon) {
|
||||
trayIcon = new QSystemTrayIcon(this);
|
||||
|
||||
QIcon icon(QPixmap::fromImage(psTrayIcon(), Qt::ColorOnly));
|
||||
icon.addPixmap(QPixmap::fromImage(psTrayIcon(true), Qt::ColorOnly), QIcon::Selected);
|
||||
|
||||
trayIcon->setIcon(icon);
|
||||
trayIcon->setToolTip(QString::fromStdWString(AppName));
|
||||
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleTray(QSystemTrayIcon::ActivationReason)), Qt::UniqueConnection);
|
||||
App::wnd()->updateTrayMenu();
|
||||
}
|
||||
psUpdateCounter();
|
||||
|
||||
trayIcon->show();
|
||||
psUpdateDelegate();
|
||||
}
|
||||
|
||||
void PsMainWindow::psUpdateWorkmode() {
|
||||
setupTrayIcon();
|
||||
psSetupTrayIcon();
|
||||
if (cWorkMode() == dbiwmWindowOnly) {
|
||||
if (trayIcon) {
|
||||
trayIcon->setContextMenu(0);
|
||||
|
|
|
@ -94,7 +94,7 @@ public slots:
|
|||
void psUpdateDelegate();
|
||||
void psSavePosition(Qt::WindowState state = Qt::WindowActive);
|
||||
void psIdleTimeout();
|
||||
void psShowTrayMenu();
|
||||
void psShowTrayMenu();
|
||||
|
||||
void psMacUndo();
|
||||
void psMacRedo();
|
||||
|
@ -108,6 +108,9 @@ protected:
|
|||
|
||||
void psNotIdle() const;
|
||||
QImage psTrayIcon(bool selected = false) const;
|
||||
bool psHasTrayIcon() const {
|
||||
return trayIcon;
|
||||
}
|
||||
|
||||
void psMacUpdateMenu();
|
||||
|
||||
|
@ -119,7 +122,8 @@ protected:
|
|||
|
||||
QImage trayImg, trayImgSel;
|
||||
|
||||
virtual void setupTrayIcon() = 0;
|
||||
void psTrayMenuUpdated();
|
||||
void psSetupTrayIcon();
|
||||
virtual void placeSmallCounter(QImage &img, int size, int count, style::color bg, const QPoint &shift, style::color color) = 0;
|
||||
|
||||
QTimer psUpdatedPositionTimer;
|
||||
|
|
|
@ -861,7 +861,7 @@ namespace {
|
|||
};
|
||||
|
||||
PsMainWindow::PsMainWindow(QWidget *parent) : QMainWindow(parent), ps_hWnd(0), ps_menu(0), icon256(qsl(":/gui/art/icon256.png")), iconbig256(qsl(":/gui/art/iconbig256.png")), wndIcon(QPixmap::fromImage(icon256, Qt::ColorOnly)),
|
||||
ps_iconBig(0), ps_iconSmall(0), ps_iconOverlay(0), trayIcon(0), trayIconMenu(0), posInited(false), ps_tbHider_hWnd(createTaskbarHider()), psIdle(false) {
|
||||
ps_iconBig(0), ps_iconSmall(0), ps_iconOverlay(0), trayIcon(0), trayIconMenu(0), posInited(false), ps_tbHider_hWnd(createTaskbarHider()), psIdle(false) {
|
||||
tbCreatedMsgId = RegisterWindowMessage(L"TaskbarButtonCreated");
|
||||
connect(&psIdleTimer, SIGNAL(timeout()), this, SLOT(psIdleTimeout()));
|
||||
psIdleTimer.setSingleShot(false);
|
||||
|
@ -939,10 +939,31 @@ void PsMainWindow::psRefreshTaskbarIcon() {
|
|||
delete w;
|
||||
}
|
||||
|
||||
void PsMainWindow::psTrayMenuUpdated() {
|
||||
}
|
||||
|
||||
void PsMainWindow::psSetupTrayIcon() {
|
||||
if (!trayIcon) {
|
||||
trayIcon = new QSystemTrayIcon(this);
|
||||
|
||||
QIcon icon(QPixmap::fromImage(App::wnd()->iconLarge(), Qt::ColorOnly));
|
||||
|
||||
trayIcon->setIcon(icon);
|
||||
trayIcon->setToolTip(QString::fromStdWString(AppName));
|
||||
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleTray(QSystemTrayIcon::ActivationReason)), Qt::UniqueConnection);
|
||||
connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(showFromTray()));
|
||||
App::wnd()->updateTrayMenu();
|
||||
}
|
||||
psUpdateCounter();
|
||||
|
||||
trayIcon->show();
|
||||
psUpdateDelegate();
|
||||
}
|
||||
|
||||
void PsMainWindow::psUpdateWorkmode() {
|
||||
switch (cWorkMode()) {
|
||||
case dbiwmWindowAndTray: {
|
||||
setupTrayIcon();
|
||||
psSetupTrayIcon();
|
||||
HWND psOwner = (HWND)GetWindowLong(ps_hWnd, GWL_HWNDPARENT);
|
||||
if (psOwner) {
|
||||
SetWindowLong(ps_hWnd, GWL_HWNDPARENT, 0);
|
||||
|
@ -951,7 +972,7 @@ void PsMainWindow::psUpdateWorkmode() {
|
|||
} break;
|
||||
|
||||
case dbiwmTrayOnly: {
|
||||
setupTrayIcon();
|
||||
psSetupTrayIcon();
|
||||
HWND psOwner = (HWND)GetWindowLong(ps_hWnd, GWL_HWNDPARENT);
|
||||
if (!psOwner) {
|
||||
SetWindowLong(ps_hWnd, GWL_HWNDPARENT, (LONG)ps_tbHider_hWnd);
|
||||
|
|
|
@ -80,11 +80,14 @@ public slots:
|
|||
void psUpdateDelegate();
|
||||
void psSavePosition(Qt::WindowState state = Qt::WindowActive);
|
||||
void psIdleTimeout();
|
||||
void psShowTrayMenu();
|
||||
void psShowTrayMenu();
|
||||
|
||||
protected:
|
||||
|
||||
void psNotIdle() const;
|
||||
bool psHasTrayIcon() const {
|
||||
return trayIcon;
|
||||
}
|
||||
|
||||
bool posInited;
|
||||
QSystemTrayIcon *trayIcon;
|
||||
|
@ -92,7 +95,8 @@ protected:
|
|||
QImage icon256, iconbig256;
|
||||
QIcon wndIcon;
|
||||
|
||||
virtual void setupTrayIcon() = 0;
|
||||
void psTrayMenuUpdated();
|
||||
void psSetupTrayIcon();
|
||||
|
||||
QTimer psUpdatedPositionTimer;
|
||||
|
||||
|
|
|
@ -42,6 +42,11 @@ bool gSendToMenu = false;
|
|||
bool gAutoUpdate = true;
|
||||
TWindowPos gWindowPos;
|
||||
bool gFromAutoStart = false;
|
||||
#if defined Q_OS_WIN || defined Q_OS_MAC
|
||||
bool gSupportTray = true;
|
||||
#else
|
||||
bool gSupportTray = false;
|
||||
#endif
|
||||
DBIWorkMode gWorkMode = dbiwmWindowAndTray;
|
||||
DBIConnectionType gConnectionType = dbictAuto;
|
||||
ConnectionProxy gConnectionProxy;
|
||||
|
|
|
@ -84,6 +84,7 @@ struct TWindowPos {
|
|||
int32 x, y, w, h;
|
||||
};
|
||||
DeclareSetting(TWindowPos, WindowPos);
|
||||
DeclareSetting(bool, SupportTray);
|
||||
DeclareSetting(DBIWorkMode, WorkMode);
|
||||
DeclareSetting(DBIConnectionType, ConnectionType);
|
||||
DeclareSetting(DBIDefaultAttach, DefaultAttach);
|
||||
|
|
|
@ -128,6 +128,7 @@ SettingsInner::SettingsInner(SettingsWidget *parent) : QWidget(parent),
|
|||
_checkNow(this, lang(lng_settings_check_now)),
|
||||
_restartNow(this, lang(lng_settings_update_now)),
|
||||
|
||||
_supportTray(cSupportTray()),
|
||||
_workmodeTray(this, lang(lng_settings_workmode_tray), (cWorkMode() == dbiwmTrayOnly || cWorkMode() == dbiwmWindowAndTray)),
|
||||
_workmodeWindow(this, lang(lng_settings_workmode_window), (cWorkMode() == dbiwmWindowOnly || cWorkMode() == dbiwmWindowAndTray)),
|
||||
|
||||
|
@ -413,7 +414,7 @@ void SettingsInner::paintEvent(QPaintEvent *e) {
|
|||
top += _startMinimized.height() + st::setSectionSkip;
|
||||
|
||||
top += _sendToMenu.height();
|
||||
} else if (cPlatform() == dbipMac) {
|
||||
} else if (_supportTray) {
|
||||
top += _workmodeTray.height();
|
||||
}
|
||||
|
||||
|
@ -580,7 +581,7 @@ void SettingsInner::resizeEvent(QResizeEvent *e) {
|
|||
_startMinimized.move(_left, top); top += _startMinimized.height() + st::setSectionSkip;
|
||||
|
||||
_sendToMenu.move(_left, top); top += _sendToMenu.height();
|
||||
} else if (cPlatform() == dbipMac) {
|
||||
} else if (_supportTray) {
|
||||
_workmodeTray.move(_left, top); top += _workmodeTray.height();
|
||||
}
|
||||
if (!cRetina()) {
|
||||
|
@ -789,7 +790,7 @@ void SettingsInner::showAll() {
|
|||
|
||||
_sendToMenu.show();
|
||||
} else {
|
||||
if (cPlatform() == dbipMac) {
|
||||
if (_supportTray) {
|
||||
_workmodeTray.show();
|
||||
} else {
|
||||
_workmodeTray.hide();
|
||||
|
|
|
@ -185,6 +185,7 @@ private:
|
|||
LinkButton _changeLanguage;
|
||||
FlatCheckbox _autoUpdate;
|
||||
LinkButton _checkNow, _restartNow;
|
||||
bool _supportTray; // cSupportTray() value on settings create
|
||||
FlatCheckbox _workmodeTray, _workmodeWindow;
|
||||
FlatCheckbox _autoStart, _startMinimized, _sendToMenu;
|
||||
FlatCheckbox _dpiAutoScale;
|
||||
|
|
|
@ -394,13 +394,19 @@ void Window::init() {
|
|||
|
||||
void Window::firstShow() {
|
||||
#ifdef Q_OS_WIN
|
||||
trayIconMenu = new ContextMenu(this);
|
||||
trayIconMenu = new ContextMenu(this);
|
||||
#else
|
||||
trayIconMenu = new QMenu(this);
|
||||
trayIconMenu->setFont(QFont("Tahoma"));
|
||||
#endif
|
||||
trayIconMenu->addAction(lang(lng_minimize_to_tray), this, SLOT(minimizeToTray()))->setEnabled(true);
|
||||
trayIconMenu->addAction(lang(lng_quit_from_tray), this, SLOT(quitFromTray()))->setEnabled(true);
|
||||
if (cPlatform() == dbipWindows || cPlatform() == dbipMac) {
|
||||
trayIconMenu->addAction(lang(lng_minimize_to_tray), this, SLOT(minimizeToTray()))->setEnabled(true);
|
||||
trayIconMenu->addAction(lang(lng_quit_from_tray), this, SLOT(quitFromTray()))->setEnabled(true);
|
||||
} else {
|
||||
trayIconMenu->addAction(lang(lng_open_from_tray), this, SLOT(showFromTray()))->setEnabled(true);
|
||||
trayIconMenu->addAction(lang(lng_minimize_to_tray), this, SLOT(minimizeToTray()))->setEnabled(true);
|
||||
trayIconMenu->addAction(lang(lng_quit_from_tray), this, SLOT(quitFromTray()))->setEnabled(true);
|
||||
}
|
||||
|
||||
psFirstShow();
|
||||
|
||||
|
@ -708,7 +714,7 @@ void Window::checkHistoryActivation(int state) {
|
|||
if (main && MTP::authedId() && historyIsActive(state)) {
|
||||
main->historyWasRead();
|
||||
}
|
||||
QTimer::singleShot(1, this, SLOT(updateTrayMenu()));
|
||||
QTimer::singleShot(1, this, SLOT(updateTrayMenu()));
|
||||
}
|
||||
|
||||
void Window::layerHidden() {
|
||||
|
@ -786,7 +792,7 @@ QRect Window::iconRect() const {
|
|||
bool Window::eventFilter(QObject *obj, QEvent *evt) {
|
||||
if (obj == App::app() && (evt->type() == QEvent::ApplicationActivate)) {
|
||||
QTimer::singleShot(1, this, SLOT(checkHistoryActivation()));
|
||||
} else if (obj == App::app() && (evt->type() == QEvent::FileOpen)) {
|
||||
} else if (obj == App::app() && (evt->type() == QEvent::FileOpen)) {
|
||||
QString url = static_cast<QFileOpenEvent*>(evt)->url().toEncoded();
|
||||
if (!url.trimmed().midRef(0, 5).compare(qsl("tg://"), Qt::CaseInsensitive)) {
|
||||
cSetStartUrl(url);
|
||||
|
@ -829,10 +835,10 @@ void Window::mouseReleaseEvent(QMouseEvent *e) {
|
|||
}
|
||||
|
||||
bool Window::minimizeToTray() {
|
||||
if (App::quiting() || !trayIcon) return false;
|
||||
if (App::quiting() || !psHasTrayIcon()) return false;
|
||||
|
||||
hide();
|
||||
if (cPlatform() != dbipMac && !cSeenTrayTooltip()) {
|
||||
if (cPlatform() == dbipWindows && trayIcon && !cSeenTrayTooltip()) {
|
||||
trayIcon->showMessage(QString::fromStdWString(AppName), lang(lng_tray_icon_text), QSystemTrayIcon::Information, 10000);
|
||||
cSetSeenTrayTooltip(true);
|
||||
App::writeConfig();
|
||||
|
@ -843,44 +849,26 @@ bool Window::minimizeToTray() {
|
|||
return true;
|
||||
}
|
||||
|
||||
void Window::setupTrayIcon() {
|
||||
if (!trayIcon) {
|
||||
if (trayIcon) trayIcon->deleteLater();
|
||||
trayIcon = new QSystemTrayIcon(this);
|
||||
#ifdef Q_OS_MAC
|
||||
QIcon icon(QPixmap::fromImage(psTrayIcon(), Qt::ColorOnly));
|
||||
icon.addPixmap(QPixmap::fromImage(psTrayIcon(true), Qt::ColorOnly), QIcon::Selected);
|
||||
#else
|
||||
QIcon icon(QPixmap::fromImage(iconLarge(), Qt::ColorOnly));
|
||||
#endif
|
||||
|
||||
trayIcon->setIcon(icon);
|
||||
trayIcon->setToolTip(QString::fromStdWString(AppName));
|
||||
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleTray(QSystemTrayIcon::ActivationReason)), Qt::UniqueConnection);
|
||||
if (cPlatform() != dbipMac) {
|
||||
connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(showFromTray()));
|
||||
}
|
||||
updateTrayMenu();
|
||||
}
|
||||
updateCounter();
|
||||
|
||||
trayIcon->show();
|
||||
psUpdateDelegate();
|
||||
}
|
||||
|
||||
void Window::updateTrayMenu(bool force) {
|
||||
if (!trayIconMenu || (cPlatform() == dbipWindows && !force) || cPlatform() == dbipLinux32 || cPlatform() == dbipLinux64) return;
|
||||
if (!trayIconMenu || (cPlatform() == dbipWindows && !force)) return;
|
||||
|
||||
bool active = psIsActive();
|
||||
QAction *first = trayIconMenu->actions().at(0);
|
||||
first->setText(lang(active ? lng_minimize_to_tray : lng_open_from_tray));
|
||||
disconnect(first, SIGNAL(triggered(bool)), 0, 0);
|
||||
connect(first, SIGNAL(triggered(bool)), this, active ? SLOT(minimizeToTray()) : SLOT(showFromTray()));
|
||||
bool active = psIsActive();
|
||||
if (cPlatform() == dbipWindows || cPlatform() == dbipMac) {
|
||||
QAction *first = trayIconMenu->actions().at(0);
|
||||
first->setText(lang(active ? lng_minimize_to_tray : lng_open_from_tray));
|
||||
disconnect(first, SIGNAL(triggered(bool)), 0, 0);
|
||||
connect(first, SIGNAL(triggered(bool)), this, active ? SLOT(minimizeToTray()) : SLOT(showFromTray()));
|
||||
#ifndef Q_OS_WIN
|
||||
if (trayIcon) {
|
||||
trayIcon->setContextMenu((active || cPlatform() != dbipMac) ? trayIconMenu : 0);
|
||||
}
|
||||
if (trayIcon) {
|
||||
trayIcon->setContextMenu((active || cPlatform() != dbipMac) ? trayIconMenu : 0);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
QAction *second = trayIconMenu->actions().at(1);
|
||||
second->setDisabled(!isVisible());
|
||||
}
|
||||
|
||||
psTrayMenuUpdated();
|
||||
}
|
||||
|
||||
void Window::onShowAddContact() {
|
||||
|
@ -980,11 +968,11 @@ void Window::noTopWidget(QWidget *w) {
|
|||
|
||||
void Window::showFromTray(QSystemTrayIcon::ActivationReason reason) {
|
||||
if (reason != QSystemTrayIcon::Context) {
|
||||
QTimer::singleShot(1, this, SLOT(updateTrayMenu()));
|
||||
QTimer::singleShot(1, this, SLOT(updateGlobalMenu()));
|
||||
activate();
|
||||
updateCounter();
|
||||
if (App::main()) App::main()->setOnline(windowState());
|
||||
QTimer::singleShot(1, this, SLOT(updateTrayMenu()));
|
||||
QTimer::singleShot(1, this, SLOT(updateGlobalMenu()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -218,7 +218,7 @@ public:
|
|||
void notifyUpdateAll();
|
||||
void notifyActivateAll();
|
||||
|
||||
QImage iconLarge() const;
|
||||
QImage iconLarge() const;
|
||||
|
||||
void sendPaths();
|
||||
|
||||
|
@ -262,10 +262,6 @@ signals:
|
|||
void tempDirCleared(int task);
|
||||
void tempDirClearFailed(int task);
|
||||
|
||||
protected:
|
||||
|
||||
void setupTrayIcon();
|
||||
|
||||
private:
|
||||
|
||||
void placeSmallCounter(QImage &img, int size, int count, style::color bg, const QPoint &shift, style::color color);
|
||||
|
|
|
@ -270,6 +270,22 @@ INCLUDEPATH += ./../../Libraries/QtStatic/qtbase/include/QtGui/5.3.1/QtGui\
|
|||
/usr/local/include/opus\
|
||||
./SourceFiles\
|
||||
./GeneratedFiles
|
||||
|
||||
INCLUDEPATH += "/usr/include/libappindicator-0.1"
|
||||
INCLUDEPATH += "/usr/include/gtk-2.0"
|
||||
INCLUDEPATH += "/usr/include/glib-2.0"
|
||||
INCLUDEPATH += "/usr/lib/x86_64-linux-gnu/glib-2.0/include"
|
||||
INCLUDEPATH += "/usr/lib/i386-linux-gnu/glib-2.0/include"
|
||||
INCLUDEPATH += "/usr/include/cairo"
|
||||
INCLUDEPATH += "/usr/include/pango-1.0"
|
||||
INCLUDEPATH += "/usr/lib/x86_64-linux-gnu/gtk-2.0/include"
|
||||
INCLUDEPATH += "/usr/lib/i386-linux-gnu/gtk-2.0/include"
|
||||
INCLUDEPATH += "/usr/include/gdk-pixbuf-2.0"
|
||||
INCLUDEPATH += "/usr/include/atk-1.0"
|
||||
|
||||
INCLUDEPATH += "/usr/include/dee-1.0"
|
||||
INCLUDEPATH += "/usr/include/libdbusmenu-glib-0.4"
|
||||
|
||||
LIBS += -lcrypto -lssl -lz -ldl -llzma -lexif -lopus -lopusfile -logg -lopenal
|
||||
LIBS += ./../../../Libraries/QtStatic/qtbase/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.a
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue