diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index ce7b615f69..4fe8a07bbd 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -891,6 +891,8 @@ PRIVATE platform/mac/specific_mac_p.h platform/mac/window_title_mac.mm platform/mac/window_title_mac.h + platform/mac/touchbar/mac_touchbar_common.h + platform/mac/touchbar/mac_touchbar_common.mm platform/win/audio_win.cpp platform/win/audio_win.h platform/win/file_utilities_win.cpp diff --git a/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_common.h b/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_common.h new file mode 100644 index 0000000000..52b54de127 --- /dev/null +++ b/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_common.h @@ -0,0 +1,32 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#import +#import + +namespace TouchBar { + +constexpr auto kCircleDiameter = 30; + +template +void CustomEnterToCocoaEventLoop(Callable callable) { + id block = [^{ callable(); } copy]; // Don't forget to -release. + [block + performSelectorOnMainThread:@selector(invoke) + withObject:nil + waitUntilDone:true]; + // [block performSelector:@selector(invoke) withObject:nil afterDelay:d]; + [block release]; +} + +int WidthFromString(NSString *s); + +NSImage *CreateNSImageFromStyleIcon(const style::icon &icon, int size); + +} // namespace TouchBar diff --git a/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_common.mm b/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_common.mm new file mode 100644 index 0000000000..4c44b79ac9 --- /dev/null +++ b/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_common.mm @@ -0,0 +1,30 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "platform/mac/touchbar/mac_touchbar_common.h" + +#import + +NSImage *qt_mac_create_nsimage(const QPixmap &pm); + +namespace TouchBar { + +int WidthFromString(NSString *s) { + return (int)ceil( + [[NSTextField labelWithString:s] frame].size.width) * 1.2; +} + +NSImage *CreateNSImageFromStyleIcon(const style::icon &icon, int size) { + const auto instance = icon.instance(QColor(255, 255, 255, 255), 100); + auto pixmap = QPixmap::fromImage(instance); + pixmap.setDevicePixelRatio(cRetinaFactor()); + NSImage *image = [qt_mac_create_nsimage(pixmap) autorelease]; + [image setSize:NSMakeSize(size, size)]; + return image; +} + +} // namespace TouchBar