Skip to content

Commit

Permalink
fixed os x mouse input, window icon, qt os x build-from-source
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Nov 13, 2014
1 parent 8422663 commit 85285d9
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ void History::clear(bool leaveItems) {
_overview[i].clear();
_overviewIds[i].clear();
}
if (App::wnd()) App::wnd()->mediaOverviewUpdated(peer);
if (App::wnd() && !App::quiting()) App::wnd()->mediaOverviewUpdated(peer);
for (Parent::const_iterator i = cbegin(), e = cend(); i != e; ++i) {
if (leaveItems) {
(*i)->clear(true);
Expand Down
5 changes: 4 additions & 1 deletion Telegram/SourceFiles/mtproto/mtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ namespace MTP {
void initdc(int32 dc);
template <typename TRequest>
inline mtpRequestId send(const TRequest &request, RPCResponseHandler callbacks = RPCResponseHandler(), int32 dc = 0, uint64 msCanWait = 0, mtpRequestId after = 0) {
return _mtp_internal::getSession(dc)->send(request, callbacks, msCanWait, _mtp_internal::getLayer(), !dc, after);
MTProtoSessionPtr session = _mtp_internal::getSession(dc);
if (!session) return 0;

return session->send(request, callbacks, msCanWait, _mtp_internal::getLayer(), !dc, after);
}
template <typename TRequest>
inline mtpRequestId send(const TRequest &request, RPCDoneHandlerPtr onDone, RPCFailHandlerPtr onFail = RPCFailHandlerPtr(), int32 dc = 0, uint64 msCanWait = 0, mtpRequestId after = 0) {
Expand Down
39 changes: 22 additions & 17 deletions Telegram/SourceFiles/mtproto/mtpFileLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace {
mtpFileLoader::mtpFileLoader(int32 dc, const int64 &volume, int32 local, const int64 &secret, int32 size) : prev(0), next(0),
priority(0), inQueue(false), complete(false), skippedBytes(0), nextRequestOffset(0), lastComplete(false),
dc(dc), locationType(0), volume(volume), local(local), secret(secret),
id(0), access(0), size(size), type(MTP_storage_fileUnknown()) {
id(0), access(0), fileIsOpen(false), size(size), type(MTP_storage_fileUnknown()) {
LoaderQueues::iterator i = queues.find(dc);
if (i == queues.cend()) {
i = queues.insert(dc, mtpFileLoaderQueue());
Expand All @@ -57,7 +57,7 @@ id(0), access(0), size(size), type(MTP_storage_fileUnknown()) {
mtpFileLoader::mtpFileLoader(int32 dc, const uint64 &id, const uint64 &access, mtpTypeId locType, const QString &to, int32 size) : prev(0), next(0),
priority(0), inQueue(false), complete(false), skippedBytes(0), nextRequestOffset(0), lastComplete(false),
dc(dc), locationType(locType),
id(id), access(access), file(to), duplicateInData(false), size(size), type(MTP_storage_fileUnknown()) {
id(id), access(access), file(to), fname(to), fileIsOpen(false), duplicateInData(false), size(size), type(MTP_storage_fileUnknown()) {
LoaderQueues::iterator i = queues.find(MTP::dld[0] + dc);
if (i == queues.cend()) {
i = queues.insert(MTP::dld[0] + dc, mtpFileLoaderQueue());
Expand All @@ -68,7 +68,7 @@ id(id), access(access), file(to), duplicateInData(false), size(size), type(MTP_s
mtpFileLoader::mtpFileLoader(int32 dc, const uint64 &id, const uint64 &access, mtpTypeId locType, const QString &to, int32 size, bool todata) : prev(0), next(0),
priority(0), inQueue(false), complete(false), skippedBytes(0), nextRequestOffset(0), lastComplete(false),
dc(dc), locationType(locType),
id(id), access(access), file(to), duplicateInData(todata), size(size), type(MTP_storage_fileUnknown()) {
id(id), access(access), file(to), fname(to), fileIsOpen(false), duplicateInData(todata), size(size), type(MTP_storage_fileUnknown()) {
LoaderQueues::iterator i = queues.find(MTP::dld[0] + dc);
if (i == queues.cend()) {
i = queues.insert(MTP::dld[0] + dc, mtpFileLoaderQueue());
Expand All @@ -77,7 +77,7 @@ id(id), access(access), file(to), duplicateInData(todata), size(size), type(MTP_
}

QString mtpFileLoader::fileName() const {
return file.fileName();
return fname;
}

bool mtpFileLoader::done() const {
Expand All @@ -99,16 +99,16 @@ float64 mtpFileLoader::currentProgress() const {
}

int32 mtpFileLoader::currentOffset(bool includeSkipped) const {
return (file.isOpen() ? file.size() : data.size()) - (includeSkipped ? 0 : skippedBytes);
return (fileIsOpen ? file.size() : data.size()) - (includeSkipped ? 0 : skippedBytes);
}

int32 mtpFileLoader::fullSize() const {
return size;
}

void mtpFileLoader::setFileName(const QString &fname) {
if (duplicateInData && file.fileName().isEmpty()) {
file.setFileName(fname);
void mtpFileLoader::setFileName(const QString &fileName) {
if (duplicateInData && fname.isEmpty()) {
file.setFileName(fname = fileName);
}
}

Expand All @@ -132,13 +132,14 @@ void mtpFileLoader::finishFail() {
cancelRequests();
type = MTP_storage_fileUnknown();
complete = true;
if (file.isOpen()) {
if (fileIsOpen) {
file.close();
fileIsOpen = false;
file.remove();
}
data = QByteArray();
emit failed(this, started);
file.setFileName(QString());
file.setFileName(fname = QString());
loadNext();
}

Expand Down Expand Up @@ -198,7 +199,7 @@ void mtpFileLoader::partLoaded(int32 offset, const MTPupload_File &result, mtpRe
const MTPDupload_file &d(result.c_upload_file());
const string &bytes(d.vbytes.c_string().v);
if (bytes.size()) {
if (file.isOpen()) {
if (fileIsOpen) {
int64 fsize = file.size();
if (offset < fsize) {
skippedBytes -= bytes.size();
Expand Down Expand Up @@ -230,8 +231,9 @@ void mtpFileLoader::partLoaded(int32 offset, const MTPupload_File &result, mtpRe
lastComplete = true;
}
if (requests.isEmpty() && (lastComplete || (size && nextRequestOffset >= size))) {
if (duplicateInData && !file.fileName().isEmpty()) {
if (!file.open(QIODevice::WriteOnly)) {
if (!fname.isEmpty() && duplicateInData) {
if (!fileIsOpen) fileIsOpen = file.open(QIODevice::WriteOnly);
if (!fileIsOpen) {
return finishFail();
}
if (file.write(data) != qint64(data.size())) {
Expand All @@ -240,8 +242,9 @@ void mtpFileLoader::partLoaded(int32 offset, const MTPupload_File &result, mtpRe
}
type = d.vtype;
complete = true;
if (file.isOpen()) {
if (fileIsOpen) {
file.close();
fileIsOpen = false;
psPostprocessFile(QFileInfo(file).absoluteFilePath());
}
removeFromQueue();
Expand Down Expand Up @@ -286,8 +289,9 @@ void mtpFileLoader::pause() {
void mtpFileLoader::start(bool loadFirst, bool prior) {
if (complete) return;

if (!file.fileName().isEmpty() && !duplicateInData) {
if (!file.open(QIODevice::WriteOnly)) {
if (!fname.isEmpty() && !duplicateInData && !fileIsOpen) {
fileIsOpen = file.open(QIODevice::WriteOnly);
if (!fileIsOpen) {
finishFail();
return;
}
Expand Down Expand Up @@ -385,8 +389,9 @@ void mtpFileLoader::cancel() {
cancelRequests();
type = MTP_storage_fileUnknown();
complete = true;
if (file.isOpen()) {
if (fileIsOpen) {
file.close();
fileIsOpen = false;
file.remove();
}
data = QByteArray();
Expand Down
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/mtproto/mtpFileLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class mtpFileLoader : public QObject, public RPCSender {
uint64 id; // for other locations
uint64 access;
QFile file;
QString fname;
bool fileIsOpen;
bool duplicateInData;

QByteArray data;
Expand Down
29 changes: 10 additions & 19 deletions Telegram/SourceFiles/overviewwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,14 @@ QPixmap OverviewInner::genPix(PhotoData *photo, int32 size) {
if (!photo->full->loaded() && !photo->medium->loaded()) {
img = imageBlur(img);
}
if (img.width() > img.height()) {
img = img.scaled(img.width() * size / img.height(), size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
if (img.width() == img.height()) {
if (img.width() != size) {
img = img.scaled(size, size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
}
} else if (img.width() > img.height()) {
img = img.copy((img.width() - img.height()) / 2, 0, img.height(), img.height()).scaled(size, size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
} else {
img = img.scaled(size, img.height() * size / img.width(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
img = img.copy(0, (img.height() - img.width()) / 2, img.width(), img.width()).scaled(size, size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
}
img.setDevicePixelRatio(cRetinaFactor());
photo->forget();
Expand Down Expand Up @@ -625,26 +629,13 @@ void OverviewInner::paintEvent(QPaintEvent *e) {
it->vsize = _vsize;
it->pix = genPix(photo, _vsize);
}
QPixmap &pix(it->pix);
QPoint pos(int32(i * w + st::overviewPhotoSkip), _addToY + row * (_vsize + st::overviewPhotoSkip) + st::overviewPhotoSkip);
int32 w = pix.width(), h = pix.height(), size;
if (w == h) {
p.drawPixmap(pos, pix);
size = w;
} else if (w > h) {
p.drawPixmap(pos, pix, QRect((w - h) / 2, 0, h, h));
size = h;
} else {
p.drawPixmap(pos, pix, QRect(0, (h - w) / 2, w, w));
size = w;
}
size /= cIntRetinaFactor();

p.drawPixmap(pos, it->pix);
if (!quality) {
uint64 dt = itemAnimations().animate(item, getms());
int32 cnt = int32(st::photoLoaderCnt), period = int32(st::photoLoaderPeriod), t = dt % period, delta = int32(st::photoLoaderDelta);

int32 x = pos.x() + (size - st::overviewLoader.width()) / 2, y = pos.y() + (size - st::overviewLoader.height()) / 2;
int32 x = pos.x() + (_vsize - st::overviewLoader.width()) / 2, y = pos.y() + (_vsize - st::overviewLoader.height()) / 2;
p.fillRect(x, y, st::overviewLoader.width(), st::overviewLoader.height(), st::photoLoaderBg->b);
x += (st::overviewLoader.width() - cnt * st::overviewLoaderPoint.width() - (cnt - 1) * st::overviewLoaderSkip) / 2;
y += (st::overviewLoader.height() - st::overviewLoaderPoint.height()) / 2;
Expand All @@ -671,7 +662,7 @@ void OverviewInner::paintEvent(QPaintEvent *e) {
}
}
if (sel == FullItemSel) {
p.fillRect(QRect(pos.x(), pos.y(), size, size), st::msgInSelectOverlay->b);
p.fillRect(QRect(pos.x(), pos.y(), _vsize, _vsize), st::msgInSelectOverlay->b);
}
} break;
}
Expand Down
4 changes: 3 additions & 1 deletion Telegram/SourceFiles/pspecific_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace {
};

PsMainWindow::PsMainWindow(QWidget *parent) : QMainWindow(parent),
posInited(false), trayIcon(0), trayIconMenu(0), icon256(qsl(":/gui/art/iconround256.png")) {
posInited(false), trayIcon(0), trayIconMenu(0), icon256(qsl(":/gui/art/iconround256.png")), wndIcon(QPixmap::fromImage(icon256)) {
connect(&psIdleTimer, SIGNAL(timeout()), this, SLOT(psIdleTimeout()));
psIdleTimer.setSingleShot(false);
}
Expand Down Expand Up @@ -115,6 +115,8 @@ void PsMainWindow::psUpdateWorkmode() {
}

void PsMainWindow::psUpdateCounter() {
setWindowIcon(myIcon);

int32 counter = App::histories().unreadFull;

setWindowTitle((counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram"));
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/pspecific_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public slots:
QSystemTrayIcon *trayIcon;
QMenu *trayIconMenu;
QImage icon256;
QIcon wndIcon;

virtual void setupTrayIcon() = 0;
virtual QImage iconWithCounter(int size, int count, style::color bg, bool smallIcon) = 0;
Expand Down
4 changes: 3 additions & 1 deletion Telegram/SourceFiles/pspecific_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void MacPrivate::notifyReplied(unsigned long long peer, const char *str) {
}

PsMainWindow::PsMainWindow(QWidget *parent) : QMainWindow(parent),
posInited(false), trayIcon(0), trayIconMenu(0), icon256(qsl(":/gui/art/iconround256.png")) {
posInited(false), trayIcon(0), trayIconMenu(0), icon256(qsl(":/gui/art/iconround256.png")), wndIcon(QPixmap(qsl(":/gui/art/iconbig128.png"))) {
QImage tray(qsl(":/gui/art/osxtray.png"));
trayImg = tray.copy(0, cRetina() ? 0 : tray.width() / 2, tray.width() / (cRetina() ? 2 : 4), tray.width() / (cRetina() ? 2 : 4));
trayImgSel = tray.copy(tray.width() / (cRetina() ? 2 : 4), cRetina() ? 0 : tray.width() / 2, tray.width() / (cRetina() ? 2 : 4), tray.width() / (cRetina() ? 2 : 4));
Expand Down Expand Up @@ -141,6 +141,7 @@ void PsMainWindow::psUpdateWorkmode() {
}
trayIcon = 0;
}
setWindowIcon(wndIcon);
}

void _placeCounter(QImage &img, int size, int count, style::color bg, style::color color) {
Expand Down Expand Up @@ -182,6 +183,7 @@ void PsMainWindow::psUpdateCounter() {
int32 counter = App::histories().unreadFull;

setWindowTitle((counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram"));
setWindowIcon(wndIcon);

QString cnt = (counter < 1000) ? QString("%1").arg(counter) : QString("..%1").arg(counter % 100, 2, 10, QChar('0'));
_private.setWindowBadge(counter ? cnt : QString());
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/pspecific_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public slots:
QSystemTrayIcon *trayIcon;
QMenu *trayIconMenu;
QImage icon256;
QIcon wndIcon;

QImage trayImg, trayImgSel;

Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/pspecific_wnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ namespace {

};

PsMainWindow::PsMainWindow(QWidget *parent) : QMainWindow(parent), ps_hWnd(0), ps_menu(0), icon256(qsl(":/gui/art/iconround256.png")),
PsMainWindow::PsMainWindow(QWidget *parent) : QMainWindow(parent), ps_hWnd(0), ps_menu(0), icon256(qsl(":/gui/art/iconround256.png")), wndIcon(QPixmap::fromImage(icon256)),
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()));
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/pspecific_wnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public slots:
QSystemTrayIcon *trayIcon;
ContextMenu *trayIconMenu;
QImage icon256;
QIcon wndIcon;

virtual void setupTrayIcon() = 0;
virtual QImage iconWithCounter(int size, int count, style::color bg, bool smallIcon) = 0;
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/telegram.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<file>art/emoji_200x.png</file>
<file>art/blank.gif</file>
<file>art/iconround256.png</file>
<file>art/iconbig128.png</file>
<file>art/fonts/DejaVuSans.ttf</file>
<file>art/osxtray.png</file>
</qresource>
Expand Down
5 changes: 2 additions & 3 deletions Telegram/SourceFiles/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ NotifyWindow::~NotifyWindow() {

Window::Window(QWidget *parent) : PsMainWindow(parent),
intro(0), main(0), settings(0), layerBG(0), _topWidget(0),
_connecting(0), _tempDeleter(0), _tempDeleterThread(0), myIcon(QPixmap::fromImage(icon256)), dragging(false), _inactivePress(false), _mediaView(0) {
_connecting(0), _tempDeleter(0), _tempDeleterThread(0), dragging(false), _inactivePress(false), _mediaView(0) {

icon16 = icon256.scaledToWidth(16, Qt::SmoothTransformation);
icon32 = icon256.scaledToWidth(32, Qt::SmoothTransformation);
Expand Down Expand Up @@ -380,7 +380,7 @@ void Window::onInactiveTimer() {

void Window::init() {
psInitFrameless();
setWindowIcon(myIcon);
setWindowIcon(wndIcon);

App::app()->installEventFilter(this);
connect(windowHandle(), SIGNAL(activeChanged()), this, SLOT(checkHistoryActivation()));
Expand Down Expand Up @@ -875,7 +875,6 @@ void Window::noTopWidget(QWidget *w) {
void Window::showFromTray(QSystemTrayIcon::ActivationReason reason) {
if (reason != QSystemTrayIcon::Context) {
activate();
setWindowIcon(myIcon);
psUpdateCounter();
if (App::main()) App::main()->setOnline(windowState());
QTimer::singleShot(1, this, SLOT(updateTrayMenu()));
Expand Down
2 changes: 0 additions & 2 deletions Telegram/SourceFiles/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,6 @@ public slots:

void clearWidgets();

QIcon myIcon;

bool dragging;
QPoint dragStart;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ - (void)handleWindowEvent:(NSEvent *)theEvent
if (!self.window.delegate)
return; // Already detached, pending NSAppKitDefined event

if (pw && pw->frameStrutEventsEnabled() && pw->m_synchedWindowState != Qt::WindowMinimized && isMouseEvent(theEvent)) {
if (pw && pw->frameStrutEventsEnabled() && pw->m_synchedWindowState != Qt::WindowMinimized && pw->m_isExposed && isMouseEvent(theEvent)) {
NSPoint loc = [theEvent locationInWindow];
NSRect windowFrame = [self.window legacyConvertRectFromScreen:[self.window frame]];
NSRect contentFrame = [[self.window contentView] frame];
Expand Down Expand Up @@ -903,6 +903,14 @@ - (void)dealloc
[m_nsWindow setRepresentedFilename: fi.exists() ? QCFString::toNSString(filePath) : @""];
}

qreal _win_devicePixelRatio() {
qreal result = 1.0;
foreach (QScreen *screen, QGuiApplication::screens()) {
result = qMax(result, screen->devicePixelRatio());
}
return result;
}

void QCocoaWindow::setWindowIcon(const QIcon &icon)
{
QCocoaAutoReleasePool pool;
Expand All @@ -918,7 +926,8 @@ - (void)dealloc
if (icon.isNull()) {
[iconButton setImage:nil];
} else {
QPixmap pixmap = icon.pixmap(QSize(22, 22));
CGFloat hgt = 16. * _win_devicePixelRatio();
QPixmap pixmap = icon.pixmap(QSize(hgt, hgt));
NSImage *image = static_cast<NSImage *>(qt_mac_create_nsimage(pixmap));
[iconButton setImage:image];
[image release];
Expand Down

0 comments on commit 85285d9

Please sign in to comment.