mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-09 16:19:43 +00:00
Merge branch 'dev' of https://github.com/telegramdesktop/tdesktop into dev
This commit is contained in:
commit
f37159911c
@ -48,28 +48,43 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
class EventFilterForMac : public QObject {
|
||||
class EventFilterForKeys : public QObject {
|
||||
public:
|
||||
|
||||
EventFilterForMac(QObject *parent) : QObject(parent) {
|
||||
EventFilterForKeys(QObject *parent) : QObject(parent) {
|
||||
|
||||
}
|
||||
bool eventFilter(QObject *o, QEvent *e) {
|
||||
if (e->type() == QEvent::KeyPress) {
|
||||
QKeyEvent *ev = static_cast<QKeyEvent*>(e);
|
||||
if (ev->key() == Qt::Key_W && (ev->modifiers() & (Qt::MetaModifier | Qt::ControlModifier))) {
|
||||
if (cWorkMode() == dbiwmTrayOnly || cWorkMode() == dbiwmWindowAndTray) {
|
||||
App::wnd()->minimizeToTray();
|
||||
return true;
|
||||
} else {
|
||||
App::wnd()->hide();
|
||||
App::wnd()->updateIsActive(cOfflineBlurTimeout());
|
||||
App::wnd()->updateGlobalMenu();
|
||||
if (cPlatform() == dbipMac) {
|
||||
if (ev->key() == Qt::Key_W && (ev->modifiers() & (Qt::MetaModifier | Qt::ControlModifier))) {
|
||||
if (cWorkMode() == dbiwmTrayOnly || cWorkMode() == dbiwmWindowAndTray) {
|
||||
App::wnd()->minimizeToTray();
|
||||
return true;
|
||||
} else {
|
||||
App::wnd()->hide();
|
||||
App::wnd()->updateIsActive(cOfflineBlurTimeout());
|
||||
App::wnd()->updateGlobalMenu();
|
||||
return true;
|
||||
}
|
||||
} else if (ev->key() == Qt::Key_M && (ev->modifiers() & (Qt::MetaModifier | Qt::ControlModifier))) {
|
||||
App::wnd()->setWindowState(Qt::WindowMinimized);
|
||||
return true;
|
||||
}
|
||||
} else if (ev->key() == Qt::Key_M && (ev->modifiers() & (Qt::MetaModifier | Qt::ControlModifier))) {
|
||||
App::wnd()->setWindowState(Qt::WindowMinimized);
|
||||
return true;
|
||||
}
|
||||
if (ev->key() == Qt::Key_MediaPlay) {
|
||||
if (App::main()) App::main()->player()->playPressed();
|
||||
} else if (ev->key() == Qt::Key_MediaPause) {
|
||||
if (App::main()) App::main()->player()->pausePressed();
|
||||
} else if (ev->key() == Qt::Key_MediaTogglePlayPause) {
|
||||
if (App::main()) App::main()->player()->playPausePressed();
|
||||
} else if (ev->key() == Qt::Key_MediaStop) {
|
||||
if (App::main()) App::main()->player()->stopPressed();
|
||||
} else if (ev->key() == Qt::Key_MediaPrevious) {
|
||||
if (App::main()) App::main()->player()->prevPressed();
|
||||
} else if (ev->key() == Qt::Key_MediaNext) {
|
||||
if (App::main()) App::main()->player()->nextPressed();
|
||||
}
|
||||
}
|
||||
return QObject::eventFilter(o, e);
|
||||
@ -95,9 +110,8 @@ Application::Application(int &argc, char **argv) : PsApplication(argc, argv),
|
||||
}
|
||||
mainApp = this;
|
||||
|
||||
if (cPlatform() == dbipMac) {
|
||||
installEventFilter(new EventFilterForMac(this));
|
||||
}
|
||||
|
||||
installEventFilter(new EventFilterForKeys(this));
|
||||
|
||||
QFontDatabase::addApplicationFont(qsl(":/gui/art/fonts/OpenSans-Regular.ttf"));
|
||||
QFontDatabase::addApplicationFont(qsl(":/gui/art/fonts/OpenSans-Bold.ttf"));
|
||||
|
@ -128,7 +128,8 @@ int32 FlatTextarea::fakeMargin() const {
|
||||
|
||||
void FlatTextarea::paintEvent(QPaintEvent *e) {
|
||||
QPainter p(viewport());
|
||||
p.fillRect(rect(), _st.bgColor->b);
|
||||
QRect r(rect().intersected(e->rect()));
|
||||
p.fillRect(r, _st.bgColor->b);
|
||||
bool phDraw = _phVisible;
|
||||
if (animating()) {
|
||||
p.setOpacity(a_phAlpha.current());
|
||||
@ -136,7 +137,7 @@ void FlatTextarea::paintEvent(QPaintEvent *e) {
|
||||
}
|
||||
if (phDraw) {
|
||||
p.save();
|
||||
p.setClipRect(rect());
|
||||
p.setClipRect(r);
|
||||
QRect phRect(_st.textMrg.left() - _fakeMargin + _st.phPos.x() + a_phLeft.current(), _st.textMrg.top() - _fakeMargin + _st.phPos.y(), width() - _st.textMrg.left() - _st.textMrg.right(), height() - _st.textMrg.top() - _st.textMrg.bottom());
|
||||
p.setFont(_st.font->f);
|
||||
p.setPen(a_phColor.current());
|
||||
|
@ -149,26 +149,12 @@ void PlayerWidget::mousePressEvent(QMouseEvent *e) {
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
_down = OverNone;
|
||||
if (_song && _over == OverPlay) {
|
||||
SongMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
audioPlayer()->currentState(&playing, &playingState);
|
||||
if (playing == _song && !(playingState & AudioPlayerStoppedMask)) {
|
||||
audioPlayer()->pauseresume(OverviewDocuments);
|
||||
} else {
|
||||
audioPlayer()->play(_song);
|
||||
if (App::main()) App::main()->documentPlayProgress(_song);
|
||||
}
|
||||
playPausePressed();
|
||||
return;
|
||||
} else if (_over == OverPrev) {
|
||||
const History::MediaOverview *o = _history ? &_history->_overview[OverviewAudioDocuments] : 0;
|
||||
if (audioPlayer() && o && _index > 0 && _index <= o->size() && !o->isEmpty()) {
|
||||
startPlay(o->at(_index - 1));
|
||||
}
|
||||
prevPressed();
|
||||
} else if (_over == OverNext) {
|
||||
const History::MediaOverview *o = _history ? &_history->_overview[OverviewAudioDocuments] : 0;
|
||||
if (audioPlayer() && o && _index >= 0 && _index < o->size() - 1) {
|
||||
startPlay(o->at(_index + 1));
|
||||
}
|
||||
nextPressed();
|
||||
} else if (_over == OverClose) {
|
||||
_down = OverClose;
|
||||
} else if (_over == OverVolume) {
|
||||
@ -411,14 +397,79 @@ void PlayerWidget::mouseReleaseEvent(QMouseEvent *e) {
|
||||
}
|
||||
update();
|
||||
} else if (_down == OverClose && _over == OverClose) {
|
||||
if (_song) {
|
||||
audioPlayer()->stop(OverviewDocuments);
|
||||
if (App::main()) App::main()->hidePlayer();
|
||||
}
|
||||
stopPressed();
|
||||
}
|
||||
_down = OverNone;
|
||||
}
|
||||
|
||||
void PlayerWidget::playPressed() {
|
||||
if (!_song || isHidden()) return;
|
||||
|
||||
SongMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
audioPlayer()->currentState(&playing, &playingState);
|
||||
if (playing == _song && !(playingState & AudioPlayerStoppedMask)) {
|
||||
if (playingState == AudioPlayerPausing || playingState == AudioPlayerPaused || playingState == AudioPlayerPausedAtEnd) {
|
||||
audioPlayer()->pauseresume(OverviewDocuments);
|
||||
}
|
||||
} else {
|
||||
audioPlayer()->play(_song);
|
||||
if (App::main()) App::main()->documentPlayProgress(_song);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerWidget::pausePressed() {
|
||||
if (!_song || isHidden()) return;
|
||||
|
||||
SongMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
audioPlayer()->currentState(&playing, &playingState);
|
||||
if (playing == _song && !(playingState & AudioPlayerStoppedMask)) {
|
||||
if (playingState == AudioPlayerStarting || playingState == AudioPlayerResuming || playingState == AudioPlayerPlaying || playingState == AudioPlayerFinishing) {
|
||||
audioPlayer()->pauseresume(OverviewDocuments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerWidget::playPausePressed() {
|
||||
if (!_song || isHidden()) return;
|
||||
|
||||
SongMsgId playing;
|
||||
AudioPlayerState playingState = AudioPlayerStopped;
|
||||
audioPlayer()->currentState(&playing, &playingState);
|
||||
if (playing == _song && !(playingState & AudioPlayerStoppedMask)) {
|
||||
audioPlayer()->pauseresume(OverviewDocuments);
|
||||
} else {
|
||||
audioPlayer()->play(_song);
|
||||
if (App::main()) App::main()->documentPlayProgress(_song);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerWidget::prevPressed() {
|
||||
if (isHidden() || !_prevAvailable) return;
|
||||
|
||||
const History::MediaOverview *o = _history ? &_history->_overview[OverviewAudioDocuments] : 0;
|
||||
if (audioPlayer() && o && _index > 0 && _index <= o->size() && !o->isEmpty()) {
|
||||
startPlay(o->at(_index - 1));
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerWidget::nextPressed() {
|
||||
if (isHidden() || !_nextAvailable) return;
|
||||
|
||||
const History::MediaOverview *o = _history ? &_history->_overview[OverviewAudioDocuments] : 0;
|
||||
if (audioPlayer() && o && _index >= 0 && _index < o->size() - 1) {
|
||||
startPlay(o->at(_index + 1));
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerWidget::stopPressed() {
|
||||
if (!_song || isHidden()) return;
|
||||
|
||||
audioPlayer()->stop(OverviewDocuments);
|
||||
if (App::main()) App::main()->hidePlayer();
|
||||
}
|
||||
|
||||
void PlayerWidget::resizeEvent(QResizeEvent *e) {
|
||||
int32 availh = (height() - st::playerLineHeight);
|
||||
int32 ch = st::playerPlay.pxHeight() + st::playerSkip, ct = (availh - ch) / 2;
|
||||
|
@ -33,6 +33,13 @@ public:
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
|
||||
void playPressed();
|
||||
void pausePressed();
|
||||
void playPausePressed();
|
||||
void prevPressed();
|
||||
void nextPressed();
|
||||
void stopPressed();
|
||||
|
||||
bool progressStep(float64 ms);
|
||||
bool stateStep(float64 ms);
|
||||
|
||||
|
@ -41,7 +41,7 @@ namespace {
|
||||
Window *wnd = Application::wnd();
|
||||
if (!wnd) return false;
|
||||
|
||||
return false;
|
||||
return wnd->psFilterNativeEvent(message);
|
||||
}
|
||||
};
|
||||
_PsEventFilter *_psEventFilter = 0;
|
||||
@ -460,6 +460,10 @@ void PsMainWindow::psActivateNotify(NotifyWindow *w) {
|
||||
objc_activateWnd(w->winId());
|
||||
}
|
||||
|
||||
bool PsMainWindow::psFilterNativeEvent(void *event) {
|
||||
return _private.filterNativeEvent(event);
|
||||
}
|
||||
|
||||
namespace {
|
||||
QRect _monitorRect;
|
||||
uint64 _monitorLastGot = 0;
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
void darkModeChanged();
|
||||
void notifyClicked(unsigned long long peer, int msgid);
|
||||
void notifyReplied(unsigned long long peer, int msgid, const char *str);
|
||||
|
||||
|
||||
};
|
||||
|
||||
class NotifyWindow;
|
||||
@ -72,6 +72,8 @@ public:
|
||||
return posInited;
|
||||
}
|
||||
|
||||
bool psFilterNativeEvent(void *event);
|
||||
|
||||
void psActivateNotify(NotifyWindow *w);
|
||||
void psClearNotifies(PeerId peerId = 0);
|
||||
void psNotifyShown(NotifyWindow *w);
|
||||
|
@ -33,7 +33,9 @@ public:
|
||||
void clearNotifies(uint64 peer = 0);
|
||||
|
||||
void enableShadow(WId winId);
|
||||
|
||||
|
||||
bool filterNativeEvent(void *event);
|
||||
|
||||
virtual void activeSpaceChanged() {
|
||||
}
|
||||
virtual void darkModeChanged() {
|
||||
|
@ -19,6 +19,7 @@ Copyright (c) 2014 John Preston, https://desktop.telegram.org
|
||||
#include "pspecific_mac_p.h"
|
||||
|
||||
#include "window.h"
|
||||
#include "mainwidget.h"
|
||||
#include "application.h"
|
||||
|
||||
#include "lang.h"
|
||||
@ -27,6 +28,8 @@ Copyright (c) 2014 John Preston, https://desktop.telegram.org
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#include <CoreFoundation/CFURL.h>
|
||||
|
||||
#include <IOKit/hidsystem/ev_keymap.h>
|
||||
|
||||
@interface qVisualize : NSObject {
|
||||
}
|
||||
|
||||
@ -304,6 +307,41 @@ void PsMacWindowPrivate::enableShadow(WId winId) {
|
||||
// [[(NSView*)winId window] setHasShadow:YES];
|
||||
}
|
||||
|
||||
bool PsMacWindowPrivate::filterNativeEvent(void *event) {
|
||||
NSEvent *e = static_cast<NSEvent*>(event);
|
||||
if (e && [e type] == NSSystemDefined && [e subtype] == 8) {
|
||||
int keyCode = (([e data1] & 0xFFFF0000) >> 16);
|
||||
int keyFlags = ([e data1] & 0x0000FFFF);
|
||||
int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA;
|
||||
int keyRepeat = (keyFlags & 0x1);
|
||||
|
||||
switch (keyCode) {
|
||||
case NX_KEYTYPE_PLAY:
|
||||
if (keyState == 0) { // Play pressed and released
|
||||
if (App::main()) App::main()->player()->playPausePressed();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case NX_KEYTYPE_FAST:
|
||||
if (keyState == 0) { // Next pressed and released
|
||||
if (App::main()) App::main()->player()->nextPressed();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case NX_KEYTYPE_REWIND:
|
||||
if (keyState == 0) { // Previous pressed and released
|
||||
if (App::main()) App::main()->player()->prevPressed();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void PsMacWindowPrivate::clearNotifies(unsigned long long peer) {
|
||||
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
|
||||
if (peer) {
|
||||
|
Loading…
Reference in New Issue
Block a user