2016-06-16 12:59:54 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-06-16 12:59:54 +00:00
|
|
|
*/
|
|
|
|
#include "platform/linux/main_window_linux.h"
|
|
|
|
|
2016-11-04 08:23:50 +00:00
|
|
|
#include "styles/style_window.h"
|
2020-01-30 18:41:24 +00:00
|
|
|
#include "platform/linux/specific_linux.h"
|
2021-05-13 02:38:30 +00:00
|
|
|
#include "platform/linux/linux_wayland_integration.h"
|
2018-01-25 14:19:14 +00:00
|
|
|
#include "history/history.h"
|
2020-03-04 05:45:44 +00:00
|
|
|
#include "history/history_widget.h"
|
|
|
|
#include "history/history_inner_widget.h"
|
|
|
|
#include "main/main_account.h" // Account::sessionChanges.
|
2020-06-26 08:27:54 +00:00
|
|
|
#include "main/main_session.h"
|
2016-06-16 12:59:54 +00:00
|
|
|
#include "mainwindow.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2021-05-27 19:45:52 +00:00
|
|
|
#include "core/core_settings.h"
|
2020-01-31 06:34:37 +00:00
|
|
|
#include "core/sandbox.h"
|
2020-03-04 05:45:44 +00:00
|
|
|
#include "boxes/peer_list_controllers.h"
|
|
|
|
#include "boxes/about_box.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2020-06-24 07:56:16 +00:00
|
|
|
#include "window/window_controller.h"
|
2020-03-04 05:45:44 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2020-10-16 03:02:05 +00:00
|
|
|
#include "base/platform/base_platform_info.h"
|
2021-05-13 12:51:16 +00:00
|
|
|
#include "base/event_filter.h"
|
2022-01-21 16:51:43 +00:00
|
|
|
#include "base/unique_qptr.h"
|
2020-12-27 17:59:57 +00:00
|
|
|
#include "ui/widgets/popup_menu.h"
|
2020-03-04 05:45:44 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2021-05-07 14:33:53 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2019-09-08 20:15:42 +00:00
|
|
|
|
2021-02-28 02:34:41 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2021-03-02 04:01:04 +00:00
|
|
|
#include "base/platform/linux/base_linux_glibmm_helper.h"
|
2021-02-28 02:34:41 +00:00
|
|
|
#include "base/platform/linux/base_linux_dbus_utilities.h"
|
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
|
|
|
2021-02-22 13:41:25 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
|
|
|
#include "base/platform/linux/base_linux_xcb_utilities.h"
|
|
|
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
|
|
|
|
2020-02-06 11:34:28 +00:00
|
|
|
#include <QtCore/QSize>
|
2021-11-25 05:19:16 +00:00
|
|
|
#include <QtCore/QMimeData>
|
2020-03-04 05:45:44 +00:00
|
|
|
#include <QtGui/QWindow>
|
2022-01-21 17:25:44 +00:00
|
|
|
#include <QtWidgets/QMenuBar>
|
2020-02-06 11:34:28 +00:00
|
|
|
|
2022-01-21 17:25:44 +00:00
|
|
|
#include <private/qguiapplication_p.h>
|
|
|
|
#include <private/qaction_p.h>
|
2020-10-16 03:02:05 +00:00
|
|
|
|
2022-01-21 17:25:44 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2021-02-28 02:34:41 +00:00
|
|
|
#include <glibmm.h>
|
|
|
|
#include <giomm.h>
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2016-06-16 12:59:54 +00:00
|
|
|
|
|
|
|
namespace Platform {
|
|
|
|
namespace {
|
|
|
|
|
2021-05-13 02:38:30 +00:00
|
|
|
using internal::WaylandIntegration;
|
2021-05-27 22:11:16 +00:00
|
|
|
using WorkMode = Core::Settings::WorkMode;
|
2021-05-13 02:38:30 +00:00
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
constexpr auto kPanelTrayIconName = "telegram-panel"_cs;
|
|
|
|
constexpr auto kMutePanelTrayIconName = "telegram-mute-panel"_cs;
|
|
|
|
constexpr auto kAttentionPanelTrayIconName = "telegram-attention-panel"_cs;
|
2020-12-29 12:13:53 +00:00
|
|
|
|
2020-02-21 15:35:22 +00:00
|
|
|
bool TrayIconMuted = true;
|
|
|
|
int32 TrayIconCount = 0;
|
|
|
|
base::flat_map<int, QImage> TrayIconImageBack;
|
|
|
|
QIcon TrayIcon;
|
|
|
|
QString TrayIconThemeName, TrayIconName;
|
2020-01-21 12:51:39 +00:00
|
|
|
|
2021-02-22 13:41:25 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
2021-05-13 02:38:30 +00:00
|
|
|
void XCBSkipTaskbar(QWindow *window, bool skip) {
|
2020-10-16 03:02:05 +00:00
|
|
|
const auto connection = base::Platform::XCB::GetConnectionFromQt();
|
|
|
|
if (!connection) {
|
2021-05-13 02:38:30 +00:00
|
|
|
return;
|
2020-10-16 03:02:05 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 01:31:30 +00:00
|
|
|
const auto root = base::Platform::XCB::GetRootWindow(connection);
|
2020-10-16 03:02:05 +00:00
|
|
|
if (!root.has_value()) {
|
2021-05-13 02:38:30 +00:00
|
|
|
return;
|
2020-10-16 03:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto stateAtom = base::Platform::XCB::GetAtom(
|
|
|
|
connection,
|
|
|
|
"_NET_WM_STATE");
|
|
|
|
|
|
|
|
if (!stateAtom.has_value()) {
|
2021-05-13 02:38:30 +00:00
|
|
|
return;
|
2020-10-16 03:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto skipTaskbarAtom = base::Platform::XCB::GetAtom(
|
|
|
|
connection,
|
|
|
|
"_NET_WM_STATE_SKIP_TASKBAR");
|
|
|
|
|
|
|
|
if (!skipTaskbarAtom.has_value()) {
|
2021-05-13 02:38:30 +00:00
|
|
|
return;
|
2020-10-16 03:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
xcb_client_message_event_t xev;
|
|
|
|
xev.response_type = XCB_CLIENT_MESSAGE;
|
|
|
|
xev.type = *stateAtom;
|
|
|
|
xev.sequence = 0;
|
|
|
|
xev.window = window->winId();
|
|
|
|
xev.format = 32;
|
2021-05-13 02:38:30 +00:00
|
|
|
xev.data.data32[0] = skip ? 1 : 0;
|
2020-10-16 03:02:05 +00:00
|
|
|
xev.data.data32[1] = *skipTaskbarAtom;
|
|
|
|
xev.data.data32[2] = 0;
|
|
|
|
xev.data.data32[3] = 0;
|
|
|
|
xev.data.data32[4] = 0;
|
|
|
|
|
|
|
|
xcb_send_event(
|
|
|
|
connection,
|
|
|
|
false,
|
|
|
|
*root,
|
|
|
|
XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT
|
|
|
|
| XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY,
|
|
|
|
reinterpret_cast<const char*>(&xev));
|
|
|
|
}
|
2021-05-30 11:05:07 +00:00
|
|
|
|
|
|
|
void XCBSetDesktopFileName(QWindow *window) {
|
|
|
|
const auto connection = base::Platform::XCB::GetConnectionFromQt();
|
|
|
|
if (!connection) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto desktopFileAtom = base::Platform::XCB::GetAtom(
|
|
|
|
connection,
|
|
|
|
"_KDE_NET_WM_DESKTOP_FILE");
|
|
|
|
|
|
|
|
const auto utf8Atom = base::Platform::XCB::GetAtom(
|
|
|
|
connection,
|
|
|
|
"UTF8_STRING");
|
|
|
|
|
|
|
|
if (!desktopFileAtom.has_value() || !utf8Atom.has_value()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto filename = QGuiApplication::desktopFileName()
|
|
|
|
.chopped(8)
|
|
|
|
.toUtf8();
|
|
|
|
|
|
|
|
xcb_change_property(
|
|
|
|
connection,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
window->winId(),
|
|
|
|
*desktopFileAtom,
|
|
|
|
*utf8Atom,
|
|
|
|
8,
|
|
|
|
filename.size(),
|
|
|
|
filename.data());
|
|
|
|
}
|
2021-02-22 13:41:25 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
2020-10-16 03:02:05 +00:00
|
|
|
|
2021-05-13 02:38:30 +00:00
|
|
|
void SkipTaskbar(QWindow *window, bool skip) {
|
|
|
|
if (const auto integration = WaylandIntegration::Instance()) {
|
|
|
|
integration->skipTaskbar(window, skip);
|
|
|
|
}
|
|
|
|
|
2021-02-22 13:41:25 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
2021-02-24 16:45:15 +00:00
|
|
|
if (IsX11()) {
|
2021-05-13 02:38:30 +00:00
|
|
|
XCBSkipTaskbar(window, skip);
|
2020-10-16 03:02:05 +00:00
|
|
|
}
|
2021-02-22 13:41:25 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
2020-10-16 03:02:05 +00:00
|
|
|
}
|
|
|
|
|
2020-03-03 01:24:13 +00:00
|
|
|
QString GetPanelIconName(int counter, bool muted) {
|
2020-01-31 06:34:37 +00:00
|
|
|
return (counter > 0)
|
|
|
|
? (muted
|
|
|
|
? kMutePanelTrayIconName.utf16()
|
|
|
|
: kAttentionPanelTrayIconName.utf16())
|
|
|
|
: kPanelTrayIconName.utf16();
|
|
|
|
}
|
2016-06-16 17:20:58 +00:00
|
|
|
|
2020-03-03 01:24:13 +00:00
|
|
|
QString GetTrayIconName(int counter, bool muted) {
|
2020-02-26 11:38:31 +00:00
|
|
|
const auto iconName = GetIconName();
|
2020-03-03 01:24:13 +00:00
|
|
|
const auto panelIconName = GetPanelIconName(counter, muted);
|
2020-02-20 01:13:15 +00:00
|
|
|
|
2020-11-04 07:35:02 +00:00
|
|
|
if (QIcon::hasThemeIcon(panelIconName)) {
|
2020-02-20 01:13:15 +00:00
|
|
|
return panelIconName;
|
2020-02-26 11:38:31 +00:00
|
|
|
} else if (QIcon::hasThemeIcon(iconName)) {
|
|
|
|
return iconName;
|
2020-02-20 01:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2020-03-05 19:46:46 +00:00
|
|
|
int GetCounterSlice(int counter) {
|
|
|
|
return (counter >= 1000)
|
|
|
|
? (1000 + (counter % 100))
|
|
|
|
: counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsIconRegenerationNeeded(
|
|
|
|
int counter,
|
|
|
|
bool muted,
|
|
|
|
const QString &iconThemeName = QIcon::themeName()) {
|
|
|
|
const auto iconName = GetTrayIconName(counter, muted);
|
|
|
|
const auto counterSlice = GetCounterSlice(counter);
|
|
|
|
|
|
|
|
return TrayIcon.isNull()
|
|
|
|
|| iconThemeName != TrayIconThemeName
|
|
|
|
|| iconName != TrayIconName
|
|
|
|
|| muted != TrayIconMuted
|
|
|
|
|| counterSlice != TrayIconCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateIconRegenerationNeeded(
|
|
|
|
const QIcon &icon,
|
|
|
|
int counter,
|
|
|
|
bool muted,
|
|
|
|
const QString &iconThemeName) {
|
|
|
|
const auto iconName = GetTrayIconName(counter, muted);
|
|
|
|
const auto counterSlice = GetCounterSlice(counter);
|
|
|
|
|
|
|
|
TrayIcon = icon;
|
|
|
|
TrayIconMuted = muted;
|
|
|
|
TrayIconCount = counterSlice;
|
|
|
|
TrayIconThemeName = iconThemeName;
|
|
|
|
TrayIconName = iconName;
|
|
|
|
}
|
|
|
|
|
2020-03-03 01:24:13 +00:00
|
|
|
QIcon TrayIconGen(int counter, bool muted) {
|
2020-02-21 15:35:22 +00:00
|
|
|
const auto iconThemeName = QIcon::themeName();
|
2020-03-05 19:46:46 +00:00
|
|
|
|
|
|
|
if (!IsIconRegenerationNeeded(counter, muted, iconThemeName)) {
|
|
|
|
return TrayIcon;
|
|
|
|
}
|
|
|
|
|
2020-03-03 01:24:13 +00:00
|
|
|
const auto iconName = GetTrayIconName(counter, muted);
|
2021-01-15 10:02:48 +00:00
|
|
|
const auto panelIconName = GetPanelIconName(counter, muted);
|
|
|
|
|
|
|
|
if (iconName == panelIconName) {
|
|
|
|
const auto result = QIcon::fromTheme(iconName);
|
|
|
|
UpdateIconRegenerationNeeded(result, counter, muted, iconThemeName);
|
|
|
|
return result;
|
|
|
|
}
|
2020-02-21 15:35:22 +00:00
|
|
|
|
2020-03-05 19:46:46 +00:00
|
|
|
QIcon result;
|
|
|
|
QIcon systemIcon;
|
|
|
|
|
2020-11-09 23:09:16 +00:00
|
|
|
static const auto iconSizes = {
|
2020-11-19 15:34:32 +00:00
|
|
|
16,
|
2020-03-05 19:46:46 +00:00
|
|
|
22,
|
|
|
|
24,
|
|
|
|
32,
|
|
|
|
48,
|
|
|
|
};
|
|
|
|
|
2020-12-24 14:32:26 +00:00
|
|
|
static const auto dprSize = [](const QImage &image) {
|
|
|
|
return image.size() / image.devicePixelRatio();
|
|
|
|
};
|
|
|
|
|
2020-03-05 19:46:46 +00:00
|
|
|
for (const auto iconSize : iconSizes) {
|
|
|
|
auto ¤tImageBack = TrayIconImageBack[iconSize];
|
|
|
|
const auto desiredSize = QSize(iconSize, iconSize);
|
|
|
|
|
|
|
|
if (currentImageBack.isNull()
|
2020-02-21 15:35:22 +00:00
|
|
|
|| iconThemeName != TrayIconThemeName
|
|
|
|
|| iconName != TrayIconName) {
|
2020-03-05 19:46:46 +00:00
|
|
|
if (!iconName.isEmpty()) {
|
2020-03-17 19:13:11 +00:00
|
|
|
if (systemIcon.isNull()) {
|
2020-03-05 19:46:46 +00:00
|
|
|
systemIcon = QIcon::fromTheme(iconName);
|
|
|
|
}
|
2020-02-21 15:35:22 +00:00
|
|
|
|
2020-12-24 14:32:26 +00:00
|
|
|
// We can't use QIcon::actualSize here
|
|
|
|
// since it works incorrectly with svg icon themes
|
|
|
|
currentImageBack = systemIcon
|
|
|
|
.pixmap(desiredSize)
|
|
|
|
.toImage();
|
|
|
|
|
|
|
|
const auto firstAttemptSize = dprSize(currentImageBack);
|
|
|
|
|
|
|
|
// if current icon theme is not a svg one, Qt can return
|
|
|
|
// a pixmap that less in size even if there are a bigger one
|
|
|
|
if (firstAttemptSize.width() < desiredSize.width()) {
|
2020-03-16 11:43:15 +00:00
|
|
|
const auto availableSizes = systemIcon.availableSizes();
|
2020-02-21 15:35:22 +00:00
|
|
|
|
2020-03-05 19:46:46 +00:00
|
|
|
const auto biggestSize = ranges::max_element(
|
|
|
|
availableSizes,
|
|
|
|
std::less<>(),
|
|
|
|
&QSize::width);
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2021-01-10 12:27:12 +00:00
|
|
|
if (biggestSize->width() > firstAttemptSize.width()) {
|
2020-12-24 14:32:26 +00:00
|
|
|
currentImageBack = systemIcon
|
|
|
|
.pixmap(*biggestSize)
|
|
|
|
.toImage();
|
|
|
|
}
|
2020-02-21 15:35:22 +00:00
|
|
|
}
|
2020-03-05 19:46:46 +00:00
|
|
|
} else {
|
2021-11-02 13:10:40 +00:00
|
|
|
currentImageBack = Window::Logo();
|
2020-03-05 19:46:46 +00:00
|
|
|
}
|
2020-02-06 11:34:28 +00:00
|
|
|
|
2020-12-24 14:32:26 +00:00
|
|
|
if (dprSize(currentImageBack) != desiredSize) {
|
2020-03-05 19:46:46 +00:00
|
|
|
currentImageBack = currentImageBack.scaled(
|
2020-11-09 23:09:16 +00:00
|
|
|
desiredSize * currentImageBack.devicePixelRatio(),
|
2020-03-05 19:46:46 +00:00
|
|
|
Qt::IgnoreAspectRatio,
|
|
|
|
Qt::SmoothTransformation);
|
2020-02-06 11:34:28 +00:00
|
|
|
}
|
2020-03-05 19:46:46 +00:00
|
|
|
}
|
2020-02-06 11:34:28 +00:00
|
|
|
|
2020-03-05 19:46:46 +00:00
|
|
|
auto iconImage = currentImageBack;
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2020-11-12 12:29:44 +00:00
|
|
|
if (counter > 0) {
|
2020-05-18 14:24:20 +00:00
|
|
|
const auto &bg = muted
|
2020-03-05 19:46:46 +00:00
|
|
|
? st::trayCounterBgMute
|
|
|
|
: st::trayCounterBg;
|
2020-05-18 14:24:20 +00:00
|
|
|
const auto &fg = st::trayCounterFg;
|
|
|
|
if (iconSize >= 22) {
|
2021-11-02 13:10:40 +00:00
|
|
|
const auto layerSize = (iconSize >= 48)
|
|
|
|
? 32
|
|
|
|
: (iconSize >= 36)
|
|
|
|
? 24
|
|
|
|
: (iconSize >= 32)
|
|
|
|
? 20
|
|
|
|
: 16;
|
|
|
|
const auto layer = Window::GenerateCounterLayer({
|
|
|
|
.size = layerSize,
|
|
|
|
.count = counter,
|
|
|
|
.bg = bg,
|
|
|
|
.fg = fg,
|
|
|
|
});
|
2020-05-18 14:24:20 +00:00
|
|
|
|
|
|
|
QPainter p(&iconImage);
|
|
|
|
p.drawImage(
|
|
|
|
iconImage.width() - layer.width() - 1,
|
|
|
|
iconImage.height() - layer.height() - 1,
|
|
|
|
layer);
|
|
|
|
} else {
|
2021-11-02 13:10:40 +00:00
|
|
|
iconImage = Window::WithSmallCounter(std::move(iconImage), {
|
|
|
|
.size = 16,
|
|
|
|
.count = counter,
|
|
|
|
.bg = bg,
|
|
|
|
.fg = fg,
|
|
|
|
});
|
2020-05-18 14:24:20 +00:00
|
|
|
}
|
2016-10-19 12:24:39 +00:00
|
|
|
}
|
2020-02-21 15:35:22 +00:00
|
|
|
|
2021-05-07 14:33:53 +00:00
|
|
|
result.addPixmap(Ui::PixmapFromImage(std::move(iconImage)));
|
2016-10-19 12:24:39 +00:00
|
|
|
}
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2020-03-05 19:46:46 +00:00
|
|
|
UpdateIconRegenerationNeeded(result, counter, muted, iconThemeName);
|
|
|
|
|
|
|
|
return result;
|
2016-06-16 17:20:58 +00:00
|
|
|
}
|
|
|
|
|
2021-06-27 15:07:45 +00:00
|
|
|
void SendKeySequence(
|
|
|
|
Qt::Key key,
|
|
|
|
Qt::KeyboardModifiers modifiers = Qt::NoModifier) {
|
|
|
|
const auto focused = QApplication::focusWidget();
|
|
|
|
if (qobject_cast<QLineEdit*>(focused)
|
|
|
|
|| qobject_cast<QTextEdit*>(focused)
|
2022-03-01 00:32:12 +00:00
|
|
|
|| dynamic_cast<HistoryInner*>(focused)) {
|
2021-06-27 15:07:45 +00:00
|
|
|
QApplication::postEvent(
|
|
|
|
focused,
|
|
|
|
new QKeyEvent(QEvent::KeyPress, key, modifiers));
|
|
|
|
|
|
|
|
QApplication::postEvent(
|
|
|
|
focused,
|
|
|
|
new QKeyEvent(QEvent::KeyRelease, key, modifiers));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForceDisabled(QAction *action, bool disabled) {
|
|
|
|
if (action->isEnabled()) {
|
|
|
|
if (disabled) action->setDisabled(true);
|
|
|
|
} else if (!disabled) {
|
|
|
|
action->setDisabled(false);
|
2022-01-21 17:25:44 +00:00
|
|
|
|
|
|
|
const auto privateAction = QActionPrivate::get(action);
|
|
|
|
privateAction->setShortcutEnabled(
|
|
|
|
false,
|
|
|
|
QGuiApplicationPrivate::instance()->shortcutMap);
|
2021-06-27 15:07:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-08 12:07:13 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-28 03:34:13 +00:00
|
|
|
bool UseUnityCounter() {
|
2021-03-02 04:01:04 +00:00
|
|
|
static const auto Result = [&] {
|
|
|
|
try {
|
|
|
|
const auto connection = Gio::DBus::Connection::get_sync(
|
|
|
|
Gio::DBus::BusType::BUS_TYPE_SESSION);
|
|
|
|
|
|
|
|
return base::Platform::DBus::NameHasOwner(
|
|
|
|
connection,
|
|
|
|
"com.canonical.Unity");
|
|
|
|
} catch (...) {
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}();
|
2020-03-28 03:34:13 +00:00
|
|
|
|
2020-06-01 10:20:51 +00:00
|
|
|
return Result;
|
2020-03-28 03:34:13 +00:00
|
|
|
}
|
2020-01-31 06:34:37 +00:00
|
|
|
|
2021-03-02 04:01:04 +00:00
|
|
|
uint djbStringHash(const std::string &string) {
|
|
|
|
uint hash = 5381;
|
2021-03-07 05:51:21 +00:00
|
|
|
for (const auto &curChar : string) {
|
|
|
|
hash = (hash << 5) + hash + curChar;
|
2020-01-02 11:25:52 +00:00
|
|
|
}
|
|
|
|
return hash;
|
2018-12-07 17:59:14 +00:00
|
|
|
}
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-04 05:45:44 +00:00
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
} // namespace
|
|
|
|
|
2022-03-01 00:33:10 +00:00
|
|
|
class MainWindow::Private {
|
2021-02-28 02:34:41 +00:00
|
|
|
public:
|
2022-01-21 16:51:43 +00:00
|
|
|
base::unique_qptr<Ui::PopupMenu> trayIconMenuXEmbed;
|
2021-02-28 02:34:41 +00:00
|
|
|
};
|
|
|
|
|
2019-06-06 11:20:21 +00:00
|
|
|
MainWindow::MainWindow(not_null<Window::Controller*> controller)
|
2021-02-28 02:34:41 +00:00
|
|
|
: Window::MainWindow(controller)
|
2022-03-01 00:33:10 +00:00
|
|
|
, _private(std::make_unique<Private>()) {
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2020-03-03 01:24:13 +00:00
|
|
|
void MainWindow::initHook() {
|
2021-06-27 15:09:02 +00:00
|
|
|
base::install_event_filter(windowHandle(), [=](not_null<QEvent*> e) {
|
|
|
|
if (e->type() == QEvent::Expose) {
|
|
|
|
auto ee = static_cast<QExposeEvent*>(e.get());
|
|
|
|
if (ee->region().isNull()) {
|
|
|
|
return base::EventFilterResult::Continue;
|
|
|
|
}
|
|
|
|
if (!windowHandle()
|
|
|
|
|| windowHandle()->parent()
|
|
|
|
|| !windowHandle()->isVisible()) {
|
|
|
|
return base::EventFilterResult::Continue;
|
|
|
|
}
|
|
|
|
handleNativeSurfaceChanged(true);
|
|
|
|
} else if (e->type() == QEvent::Hide) {
|
|
|
|
if (!windowHandle() || windowHandle()->parent()) {
|
|
|
|
return base::EventFilterResult::Continue;
|
|
|
|
}
|
|
|
|
handleNativeSurfaceChanged(false);
|
|
|
|
}
|
|
|
|
return base::EventFilterResult::Continue;
|
|
|
|
});
|
|
|
|
|
2021-01-04 10:18:48 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-03 01:24:13 +00:00
|
|
|
if (UseUnityCounter()) {
|
|
|
|
LOG(("Using Unity launcher counter."));
|
|
|
|
} else {
|
|
|
|
LOG(("Not using Unity launcher counter."));
|
|
|
|
}
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-04-25 04:43:19 +00:00
|
|
|
|
2021-05-30 11:05:07 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
|
|
|
XCBSetDesktopFileName(windowHandle());
|
|
|
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
|
|
|
|
2022-01-21 16:51:43 +00:00
|
|
|
LOG(("System tray available: %1").arg(Logs::b(TrayIconSupported())));
|
2020-03-03 01:24:13 +00:00
|
|
|
}
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
bool MainWindow::hasTrayIcon() const {
|
2017-08-07 11:57:34 +00:00
|
|
|
return trayIcon;
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2021-01-22 12:16:18 +00:00
|
|
|
bool MainWindow::isActiveForTrayMenu() {
|
|
|
|
updateIsActive();
|
|
|
|
return Platform::IsWayland() ? isVisible() : isActive();
|
|
|
|
}
|
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
void MainWindow::psShowTrayMenu() {
|
2022-01-21 16:51:43 +00:00
|
|
|
_private->trayIconMenuXEmbed->popup(QCursor::pos());
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
void MainWindow::psTrayMenuUpdated() {
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::psSetupTrayIcon() {
|
2021-10-19 13:00:21 +00:00
|
|
|
if (!trayIcon) {
|
|
|
|
trayIcon = new QSystemTrayIcon(this);
|
2022-01-21 16:51:43 +00:00
|
|
|
trayIcon->setContextMenu(trayIconMenu);
|
|
|
|
trayIcon->setIcon(TrayIconGen(
|
|
|
|
Core::App().unreadBadge(),
|
|
|
|
Core::App().unreadBadgeMuted()));
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2021-10-19 13:00:21 +00:00
|
|
|
attachToTrayIcon(trayIcon);
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
2021-10-19 13:00:21 +00:00
|
|
|
updateIconCounters();
|
|
|
|
|
|
|
|
trayIcon->show();
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2021-05-27 22:11:16 +00:00
|
|
|
void MainWindow::workmodeUpdated(Core::Settings::WorkMode mode) {
|
2022-01-21 16:51:43 +00:00
|
|
|
if (!TrayIconSupported()) {
|
2020-07-22 12:10:17 +00:00
|
|
|
return;
|
2021-05-27 22:11:16 +00:00
|
|
|
} else if (mode == WorkMode::WindowOnly) {
|
2020-03-10 10:17:19 +00:00
|
|
|
if (trayIcon) {
|
|
|
|
trayIcon->setContextMenu(0);
|
|
|
|
trayIcon->deleteLater();
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
2020-03-10 10:17:19 +00:00
|
|
|
trayIcon = nullptr;
|
2016-06-16 12:59:54 +00:00
|
|
|
} else {
|
2020-01-31 06:34:37 +00:00
|
|
|
psSetupTrayIcon();
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
2020-10-16 03:02:05 +00:00
|
|
|
|
2021-05-27 22:11:16 +00:00
|
|
|
SkipTaskbar(windowHandle(), mode == WorkMode::TrayOnly);
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2016-11-11 07:51:53 +00:00
|
|
|
void MainWindow::unreadCounterChangedHook() {
|
|
|
|
updateIconCounters();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::updateIconCounters() {
|
2020-03-03 01:24:13 +00:00
|
|
|
const auto counter = Core::App().unreadBadge();
|
|
|
|
const auto muted = Core::App().unreadBadgeMuted();
|
|
|
|
|
2017-05-12 15:27:19 +00:00
|
|
|
updateWindowIcon();
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2020-08-08 12:07:13 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-02-20 03:00:26 +00:00
|
|
|
if (UseUnityCounter()) {
|
2021-03-02 04:01:04 +00:00
|
|
|
const auto launcherUrl = Glib::ustring(
|
2021-03-12 04:55:31 +00:00
|
|
|
"application://"
|
|
|
|
+ QGuiApplication::desktopFileName().toStdString());
|
2021-03-02 04:01:04 +00:00
|
|
|
const auto counterSlice = std::min(counter, 9999);
|
|
|
|
std::map<Glib::ustring, Glib::VariantBase> dbusUnityProperties;
|
2021-01-04 10:39:19 +00:00
|
|
|
|
|
|
|
if (counterSlice > 0) {
|
2021-03-02 04:01:04 +00:00
|
|
|
// According to the spec, it should be of 'x' D-Bus signature,
|
2021-03-23 14:27:13 +00:00
|
|
|
// which corresponds to gint64 type with glib
|
2021-03-02 04:01:04 +00:00
|
|
|
// https://wiki.ubuntu.com/Unity/LauncherAPI#Low_level_DBus_API:_com.canonical.Unity.LauncherEntry
|
2021-03-23 14:27:13 +00:00
|
|
|
dbusUnityProperties["count"] = Glib::Variant<gint64>::create(
|
2021-03-02 04:01:04 +00:00
|
|
|
counterSlice);
|
|
|
|
dbusUnityProperties["count-visible"] =
|
|
|
|
Glib::Variant<bool>::create(true);
|
2016-06-16 12:59:54 +00:00
|
|
|
} else {
|
2021-03-04 15:29:01 +00:00
|
|
|
dbusUnityProperties["count-visible"] =
|
2021-03-02 04:01:04 +00:00
|
|
|
Glib::Variant<bool>::create(false);
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
2021-01-04 10:39:19 +00:00
|
|
|
|
2021-03-02 04:01:04 +00:00
|
|
|
try {
|
2022-03-01 01:49:09 +00:00
|
|
|
const auto connection = Gio::DBus::Connection::get_sync(
|
|
|
|
Gio::DBus::BusType::BUS_TYPE_SESSION);
|
|
|
|
|
|
|
|
connection->emit_signal(
|
|
|
|
"/com/canonical/unity/launcherentry/"
|
|
|
|
+ std::to_string(djbStringHash(launcherUrl)),
|
|
|
|
"com.canonical.Unity.LauncherEntry",
|
|
|
|
"Update",
|
|
|
|
{},
|
|
|
|
base::Platform::MakeGlibVariant(std::tuple{
|
|
|
|
launcherUrl,
|
|
|
|
dbusUnityProperties,
|
|
|
|
}));
|
2021-03-02 04:01:04 +00:00
|
|
|
} catch (...) {
|
|
|
|
}
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-10 10:17:19 +00:00
|
|
|
|
|
|
|
if (trayIcon && IsIconRegenerationNeeded(counter, muted)) {
|
2020-03-03 01:24:13 +00:00
|
|
|
trayIcon->setIcon(TrayIconGen(counter, muted));
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-12 08:09:17 +00:00
|
|
|
void MainWindow::initTrayMenuHook() {
|
2022-01-21 16:51:43 +00:00
|
|
|
_private->trayIconMenuXEmbed.emplace(nullptr, trayIconMenu);
|
|
|
|
_private->trayIconMenuXEmbed->deleteOnHide(false);
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 05:45:44 +00:00
|
|
|
void MainWindow::createGlobalMenu() {
|
2021-02-03 01:17:03 +00:00
|
|
|
const auto ensureWindowShown = [=] {
|
|
|
|
if (isHidden()) {
|
|
|
|
showFromTray();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-01-21 17:25:44 +00:00
|
|
|
psMainMenu = new QMenuBar(this);
|
|
|
|
psMainMenu->hide();
|
2020-03-04 05:45:44 +00:00
|
|
|
|
|
|
|
auto file = psMainMenu->addMenu(tr::lng_mac_menu_file(tr::now));
|
|
|
|
|
2021-02-03 02:49:26 +00:00
|
|
|
psLogout = file->addAction(
|
|
|
|
tr::lng_mac_menu_logout(tr::now),
|
|
|
|
this,
|
|
|
|
[=] {
|
|
|
|
ensureWindowShown();
|
|
|
|
controller().showLogoutConfirmation();
|
|
|
|
});
|
2020-03-04 05:45:44 +00:00
|
|
|
|
|
|
|
auto quit = file->addAction(
|
|
|
|
tr::lng_mac_menu_quit_telegram(tr::now, lt_telegram, qsl("Telegram")),
|
2021-02-25 15:12:51 +00:00
|
|
|
this,
|
|
|
|
[=] { quitFromTray(); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Quit);
|
|
|
|
|
|
|
|
quit->setMenuRole(QAction::QuitRole);
|
|
|
|
|
|
|
|
auto edit = psMainMenu->addMenu(tr::lng_mac_menu_edit(tr::now));
|
|
|
|
|
|
|
|
psUndo = edit->addAction(
|
|
|
|
tr::lng_linux_menu_undo(tr::now),
|
2021-11-25 05:19:38 +00:00
|
|
|
[] { SendKeySequence(Qt::Key_Z, Qt::ControlModifier); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Undo);
|
|
|
|
|
|
|
|
psRedo = edit->addAction(
|
|
|
|
tr::lng_linux_menu_redo(tr::now),
|
2021-11-25 05:19:38 +00:00
|
|
|
[] {
|
|
|
|
SendKeySequence(
|
|
|
|
Qt::Key_Z,
|
|
|
|
Qt::ControlModifier | Qt::ShiftModifier);
|
|
|
|
},
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Redo);
|
|
|
|
|
|
|
|
edit->addSeparator();
|
|
|
|
|
|
|
|
psCut = edit->addAction(
|
|
|
|
tr::lng_mac_menu_cut(tr::now),
|
2021-11-25 05:19:38 +00:00
|
|
|
[] { SendKeySequence(Qt::Key_X, Qt::ControlModifier); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Cut);
|
2021-11-25 05:19:38 +00:00
|
|
|
|
2020-03-04 05:45:44 +00:00
|
|
|
psCopy = edit->addAction(
|
|
|
|
tr::lng_mac_menu_copy(tr::now),
|
2021-11-25 05:19:38 +00:00
|
|
|
[] { SendKeySequence(Qt::Key_C, Qt::ControlModifier); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Copy);
|
|
|
|
|
|
|
|
psPaste = edit->addAction(
|
|
|
|
tr::lng_mac_menu_paste(tr::now),
|
2021-11-25 05:19:38 +00:00
|
|
|
[] { SendKeySequence(Qt::Key_V, Qt::ControlModifier); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Paste);
|
|
|
|
|
|
|
|
psDelete = edit->addAction(
|
|
|
|
tr::lng_mac_menu_delete(tr::now),
|
2021-11-25 05:19:38 +00:00
|
|
|
[] { SendKeySequence(Qt::Key_Delete); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence(Qt::ControlModifier | Qt::Key_Backspace));
|
|
|
|
|
|
|
|
edit->addSeparator();
|
|
|
|
|
|
|
|
psBold = edit->addAction(
|
|
|
|
tr::lng_menu_formatting_bold(tr::now),
|
2021-11-25 05:19:38 +00:00
|
|
|
[] { SendKeySequence(Qt::Key_B, Qt::ControlModifier); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Bold);
|
|
|
|
|
|
|
|
psItalic = edit->addAction(
|
|
|
|
tr::lng_menu_formatting_italic(tr::now),
|
2021-11-25 05:19:38 +00:00
|
|
|
[] { SendKeySequence(Qt::Key_I, Qt::ControlModifier); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Italic);
|
|
|
|
|
|
|
|
psUnderline = edit->addAction(
|
|
|
|
tr::lng_menu_formatting_underline(tr::now),
|
2021-11-25 05:19:38 +00:00
|
|
|
[] { SendKeySequence(Qt::Key_U, Qt::ControlModifier); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Underline);
|
|
|
|
|
|
|
|
psStrikeOut = edit->addAction(
|
|
|
|
tr::lng_menu_formatting_strike_out(tr::now),
|
2021-11-25 05:19:38 +00:00
|
|
|
[] {
|
|
|
|
SendKeySequence(
|
|
|
|
Qt::Key_X,
|
|
|
|
Qt::ControlModifier | Qt::ShiftModifier);
|
|
|
|
},
|
2020-03-04 05:45:44 +00:00
|
|
|
Ui::kStrikeOutSequence);
|
|
|
|
|
|
|
|
psMonospace = edit->addAction(
|
|
|
|
tr::lng_menu_formatting_monospace(tr::now),
|
2021-11-25 05:19:38 +00:00
|
|
|
[] {
|
|
|
|
SendKeySequence(
|
|
|
|
Qt::Key_M,
|
|
|
|
Qt::ControlModifier | Qt::ShiftModifier);
|
|
|
|
},
|
2020-03-04 05:45:44 +00:00
|
|
|
Ui::kMonospaceSequence);
|
|
|
|
|
|
|
|
psClearFormat = edit->addAction(
|
|
|
|
tr::lng_menu_formatting_clear(tr::now),
|
2021-11-25 05:19:38 +00:00
|
|
|
[] {
|
|
|
|
SendKeySequence(
|
|
|
|
Qt::Key_N,
|
|
|
|
Qt::ControlModifier | Qt::ShiftModifier);
|
|
|
|
},
|
2020-03-04 05:45:44 +00:00
|
|
|
Ui::kClearFormatSequence);
|
|
|
|
|
|
|
|
edit->addSeparator();
|
|
|
|
|
|
|
|
psSelectAll = edit->addAction(
|
|
|
|
tr::lng_mac_menu_select_all(tr::now),
|
2021-11-25 05:19:38 +00:00
|
|
|
[] { SendKeySequence(Qt::Key_A, Qt::ControlModifier); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::SelectAll);
|
|
|
|
|
|
|
|
edit->addSeparator();
|
|
|
|
|
|
|
|
auto prefs = edit->addAction(
|
|
|
|
tr::lng_mac_menu_preferences(tr::now),
|
2021-02-03 01:58:27 +00:00
|
|
|
this,
|
|
|
|
[=] {
|
|
|
|
ensureWindowShown();
|
|
|
|
controller().showSettings();
|
|
|
|
},
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence(Qt::ControlModifier | Qt::Key_Comma));
|
|
|
|
|
|
|
|
prefs->setMenuRole(QAction::PreferencesRole);
|
|
|
|
|
|
|
|
auto tools = psMainMenu->addMenu(tr::lng_linux_menu_tools(tr::now));
|
|
|
|
|
|
|
|
psContacts = tools->addAction(
|
|
|
|
tr::lng_mac_menu_contacts(tr::now),
|
|
|
|
crl::guard(this, [=] {
|
|
|
|
if (isHidden()) {
|
2021-02-25 15:12:51 +00:00
|
|
|
showFromTray();
|
2020-03-04 05:45:44 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 07:51:05 +00:00
|
|
|
if (!sessionController()) {
|
2020-03-04 05:45:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-13 07:37:52 +00:00
|
|
|
sessionController()->show(
|
|
|
|
PrepareContactsBox(sessionController()));
|
2020-03-04 05:45:44 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
psAddContact = tools->addAction(
|
|
|
|
tr::lng_mac_menu_add_contact(tr::now),
|
2021-02-03 01:17:03 +00:00
|
|
|
this,
|
|
|
|
[=] {
|
|
|
|
Expects(sessionController() != nullptr);
|
|
|
|
ensureWindowShown();
|
|
|
|
sessionController()->showAddContact();
|
|
|
|
});
|
2020-03-04 05:45:44 +00:00
|
|
|
|
|
|
|
tools->addSeparator();
|
|
|
|
|
|
|
|
psNewGroup = tools->addAction(
|
|
|
|
tr::lng_mac_menu_new_group(tr::now),
|
2021-02-03 01:17:03 +00:00
|
|
|
this,
|
|
|
|
[=] {
|
|
|
|
Expects(sessionController() != nullptr);
|
|
|
|
ensureWindowShown();
|
|
|
|
sessionController()->showNewGroup();
|
|
|
|
});
|
2020-03-04 05:45:44 +00:00
|
|
|
|
|
|
|
psNewChannel = tools->addAction(
|
|
|
|
tr::lng_mac_menu_new_channel(tr::now),
|
2021-02-03 01:17:03 +00:00
|
|
|
this,
|
|
|
|
[=] {
|
|
|
|
Expects(sessionController() != nullptr);
|
|
|
|
ensureWindowShown();
|
|
|
|
sessionController()->showNewChannel();
|
|
|
|
});
|
2020-03-04 05:45:44 +00:00
|
|
|
|
|
|
|
auto help = psMainMenu->addMenu(tr::lng_linux_menu_help(tr::now));
|
|
|
|
|
|
|
|
auto about = help->addAction(
|
|
|
|
tr::lng_mac_menu_about_telegram(
|
|
|
|
tr::now,
|
|
|
|
lt_telegram,
|
|
|
|
qsl("Telegram")),
|
2021-02-03 02:55:01 +00:00
|
|
|
[=] {
|
|
|
|
ensureWindowShown();
|
|
|
|
controller().show(Box<AboutBox>());
|
2020-03-04 05:45:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
about->setMenuRole(QAction::AboutQtRole);
|
|
|
|
|
2022-01-21 17:25:44 +00:00
|
|
|
// avoid shadowing actual shortcuts by the menubar
|
|
|
|
for (const auto &child : psMainMenu->children()) {
|
|
|
|
const auto action = qobject_cast<QAction*>(child);
|
|
|
|
if (action) {
|
|
|
|
const auto privateAction = QActionPrivate::get(action);
|
|
|
|
privateAction->setShortcutEnabled(
|
|
|
|
false,
|
|
|
|
QGuiApplicationPrivate::instance()->shortcutMap);
|
|
|
|
}
|
2021-07-05 16:16:09 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 05:45:44 +00:00
|
|
|
updateGlobalMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::updateGlobalMenuHook() {
|
2021-02-25 15:12:51 +00:00
|
|
|
if (!positionInited()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-03-04 05:45:44 +00:00
|
|
|
|
|
|
|
const auto focused = QApplication::focusWidget();
|
|
|
|
auto canUndo = false;
|
|
|
|
auto canRedo = false;
|
|
|
|
auto canCut = false;
|
|
|
|
auto canCopy = false;
|
|
|
|
auto canPaste = false;
|
|
|
|
auto canDelete = false;
|
|
|
|
auto canSelectAll = false;
|
2021-11-25 05:19:16 +00:00
|
|
|
const auto mimeData = QGuiApplication::clipboard()->mimeData();
|
|
|
|
const auto clipboardHasText = mimeData ? mimeData->hasText() : false;
|
2020-03-04 05:45:44 +00:00
|
|
|
auto markdownEnabled = false;
|
|
|
|
if (const auto edit = qobject_cast<QLineEdit*>(focused)) {
|
|
|
|
canCut = canCopy = canDelete = edit->hasSelectedText();
|
|
|
|
canSelectAll = !edit->text().isEmpty();
|
|
|
|
canUndo = edit->isUndoAvailable();
|
|
|
|
canRedo = edit->isRedoAvailable();
|
|
|
|
canPaste = clipboardHasText;
|
|
|
|
} else if (const auto edit = qobject_cast<QTextEdit*>(focused)) {
|
|
|
|
canCut = canCopy = canDelete = edit->textCursor().hasSelection();
|
|
|
|
canSelectAll = !edit->document()->isEmpty();
|
|
|
|
canUndo = edit->document()->isUndoAvailable();
|
|
|
|
canRedo = edit->document()->isRedoAvailable();
|
|
|
|
canPaste = clipboardHasText;
|
|
|
|
if (canCopy) {
|
2022-03-01 00:32:12 +00:00
|
|
|
if (const auto inputField = dynamic_cast<Ui::InputField*>(
|
2020-03-04 05:45:44 +00:00
|
|
|
focused->parentWidget())) {
|
|
|
|
markdownEnabled = inputField->isMarkdownEnabled();
|
|
|
|
}
|
|
|
|
}
|
2022-03-01 00:32:12 +00:00
|
|
|
} else if (const auto list = dynamic_cast<HistoryInner*>(focused)) {
|
2020-03-04 05:45:44 +00:00
|
|
|
canCopy = list->canCopySelected();
|
|
|
|
canDelete = list->canDeleteSelected();
|
|
|
|
}
|
2021-02-25 15:12:51 +00:00
|
|
|
updateIsActive();
|
2020-06-26 07:51:05 +00:00
|
|
|
const auto logged = (sessionController() != nullptr);
|
2020-06-24 07:56:16 +00:00
|
|
|
const auto inactive = !logged || controller().locked();
|
2020-03-04 05:45:44 +00:00
|
|
|
const auto support = logged && account().session().supportMode();
|
2020-06-24 07:56:16 +00:00
|
|
|
ForceDisabled(psLogout, !logged && !Core::App().passcodeLocked());
|
2020-03-04 05:45:44 +00:00
|
|
|
ForceDisabled(psUndo, !canUndo);
|
|
|
|
ForceDisabled(psRedo, !canRedo);
|
|
|
|
ForceDisabled(psCut, !canCut);
|
|
|
|
ForceDisabled(psCopy, !canCopy);
|
|
|
|
ForceDisabled(psPaste, !canPaste);
|
|
|
|
ForceDisabled(psDelete, !canDelete);
|
|
|
|
ForceDisabled(psSelectAll, !canSelectAll);
|
|
|
|
ForceDisabled(psContacts, inactive || support);
|
|
|
|
ForceDisabled(psAddContact, inactive);
|
|
|
|
ForceDisabled(psNewGroup, inactive || support);
|
|
|
|
ForceDisabled(psNewChannel, inactive || support);
|
|
|
|
|
|
|
|
ForceDisabled(psBold, !markdownEnabled);
|
|
|
|
ForceDisabled(psItalic, !markdownEnabled);
|
|
|
|
ForceDisabled(psUnderline, !markdownEnabled);
|
|
|
|
ForceDisabled(psStrikeOut, !markdownEnabled);
|
|
|
|
ForceDisabled(psMonospace, !markdownEnabled);
|
|
|
|
ForceDisabled(psClearFormat, !markdownEnabled);
|
|
|
|
}
|
|
|
|
|
2022-03-01 00:33:10 +00:00
|
|
|
bool MainWindow::eventFilter(QObject *obj, QEvent *evt) {
|
|
|
|
QEvent::Type t = evt->type();
|
|
|
|
if (t == QEvent::MouseButtonPress
|
|
|
|
&& obj->objectName() == qstr("QSystemTrayIconSys")) {
|
|
|
|
const auto ee = static_cast<QMouseEvent*>(evt);
|
|
|
|
if (ee->button() == Qt::RightButton) {
|
|
|
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
|
|
|
handleTrayIconActication(QSystemTrayIcon::Context);
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (t == QEvent::FocusIn || t == QEvent::FocusOut) {
|
|
|
|
if (qobject_cast<QLineEdit*>(obj)
|
|
|
|
|| qobject_cast<QTextEdit*>(obj)
|
|
|
|
|| dynamic_cast<HistoryInner*>(obj)) {
|
|
|
|
updateGlobalMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Window::MainWindow::eventFilter(obj, evt);
|
|
|
|
}
|
|
|
|
|
2021-05-13 12:51:16 +00:00
|
|
|
void MainWindow::handleNativeSurfaceChanged(bool exist) {
|
|
|
|
if (exist) {
|
|
|
|
SkipTaskbar(
|
|
|
|
windowHandle(),
|
2021-05-27 22:11:16 +00:00
|
|
|
(Core::App().settings().workMode() == WorkMode::TrayOnly)
|
2022-01-21 16:51:43 +00:00
|
|
|
&& TrayIconSupported());
|
2020-10-16 03:02:05 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-14 12:13:33 +00:00
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
MainWindow::~MainWindow() {
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Platform
|