~handlerug/TelegramSwift

da639a3bdb6990e19e52cff8274f9b369825ca45 — handlerug 4 years ago 4a29ace
Make popovers open by click instead of on hover

Patch by s0ph0s
2 files changed, 11 insertions(+), 69 deletions(-)

M Telegram-Mac/ChatInputActionsView.swift
M submodules/TGUIKit/TGUIKit/Popover.swift
M Telegram-Mac/ChatInputActionsView.swift => Telegram-Mac/ChatInputActionsView.swift +10 -22
@@ 96,8 96,7 @@ class ChatInputActionsView: View, Notifable {

        entertaiments.highlightHovered = true
        addSubview(entertaiments)
        
        addHoverObserver()

        addClickObserver()
        entertaiments.canHighlight = false
        muteChannelMessages.hideAnimated = false


@@ 151,22 150,6 @@ class ChatInputActionsView: View, Notifable {
        return chatInteraction.context.sharedContext.bindings.entertainment()
    }
    
    private func addHoverObserver() {
        
        entertaiments.set(handler: { [weak self] (state) in
            guard let `self` = self else {return}
            let chatInteraction = self.chatInteraction
            var enabled = false
            
            if let sidebarEnabled = chatInteraction.presentation.sidebarEnabled {
                enabled = sidebarEnabled
            }
            if !((mainWindow.frame.width >= 1100 && chatInteraction.context.sharedContext.layout == .dual) || (mainWindow.frame.width >= 880 && chatInteraction.context.sharedContext.layout == .minimisize)) || !enabled {
                self.showEntertainment()
            }
        }, for: .Hover)
    }
    
    private func showEntertainment() {
        let rect = NSMakeRect(0, 0, 350, max(mainWindow.frame.height - 400, 300))
        entertaimentsPopover._frameRect = rect


@@ 178,10 161,15 @@ class ChatInputActionsView: View, Notifable {
        entertaiments.set(handler: { [weak self] (state) in
            if let strongSelf = self {
                let chatInteraction = strongSelf.chatInteraction
                if let sidebarEnabled = chatInteraction.presentation.sidebarEnabled, sidebarEnabled {
                    if mainWindow.frame.width >= 1100 && chatInteraction.context.sharedContext.layout == .dual || mainWindow.frame.width >= 880 && chatInteraction.context.sharedContext.layout == .minimisize {
                        
                        chatInteraction.toggleSidebar()
                if let sidebarEnabled = chatInteraction.presentation.sidebarEnabled {
                    if sidebarEnabled {
                        if mainWindow.frame.width >= 1100 && chatInteraction.context.sharedContext.layout == .dual || mainWindow.frame.width >= 880 && chatInteraction.context.sharedContext.layout == .minimisize {
                            chatInteraction.toggleSidebar()
                        } else {
                            strongSelf.showEntertainment()
                        }
                    } else {
                        strongSelf.showEntertainment()
                    }
                }
            }

M submodules/TGUIKit/TGUIKit/Popover.swift => submodules/TGUIKit/TGUIKit/Popover.swift +1 -47
@@ 233,38 233,7 @@ open class Popover: NSObject {
                            
                            
                        }
                        
                        let nHandler:(Control) -> Void = { [weak strongSelf] control in
                            if let strongSelf = strongSelf {
                                let s = Signal<Void,NoError>.single(Void()) |> delay(0.2, queue: Queue.mainQueue()) |> then(Signal<Void,NoError>.single(Void()) |> delay(0.2, queue: Queue.mainQueue()) |> restart)
                                
                                strongSelf.disposable.set(s.start(next: { [weak strongSelf] () in
                                    if let strongSelf = strongSelf {
                                        if !strongSelf.inside() && !control.mouseInside() {
                                            if (NSEvent.pressedMouseButtons & (1 << 0)) == 0 {
                                                strongSelf.hide()
                                            }
                                        }
                                    }
                                    
                                }))
                            }
                            
                            
                        }
                        
                        var first: Bool = true
                        
                        control.kitWindow?.set(mouseHandler: { [weak strongSelf, weak control] _ -> KeyHandlerResult in
                            if let strongSelf = strongSelf, first, let control = control, !strongSelf.static {
                                if !strongSelf.inside() && !control.mouseInside() {
                                    first = false
                                    nHandler(control)
                                }
                            }
                            return .invokeNext
                        },  with: strongSelf, for: .mouseMoved, priority: .high)
                        

                        control.kitWindow?.set(mouseHandler: { [weak strongSelf] event -> KeyHandlerResult in
                            if let strongSelf = strongSelf, !strongSelf.inside() && (!control.mouseInside() || control.continuesAction) {
                                strongSelf.hide()


@@ 273,21 242,6 @@ open class Popover: NSObject {
                                return .rejected
                            }
                        }, with: strongSelf, for: .leftMouseDown, priority: .high)
                        
                        let hHandler:(Control) -> Void = { [weak strongSelf] _ in
                            
                            strongSelf?.disposable.set(nil)
                            
                        }
                        
                        strongSelf.background.set(handler: nHandler, for: .Normal)
                        strongSelf.background.set(handler: hHandler, for: .Hover)
                        
                        
                        control.set(handler: nHandler, for: .Normal)
                        control.set(handler: hHandler, for: .Hover)
                        
                        
                    }
                } else if let strongSelf = self {
                    controller?.viewWillDisappear(false)