Fix hidden dialogs.

This commit is contained in:
Nuno Cruces 2021-01-05 15:20:42 +00:00
parent 4a39a18f0a
commit 3770f9924a
5 changed files with 39 additions and 9 deletions

View file

@ -54,6 +54,7 @@ func selectColor(options []Option) (color.Color, error) {
defer unhook() defer unhook()
} }
activate()
s, _, _ := chooseColor.Call(uintptr(unsafe.Pointer(&args))) s, _, _ := chooseColor.Call(uintptr(unsafe.Pointer(&args)))
if opts.ctx != nil && opts.ctx.Err() != nil { if opts.ctx != nil && opts.ctx.Err() != nil {
return nil, opts.ctx.Err() return nil, opts.ctx.Err()

View file

@ -54,6 +54,7 @@ func selectFile(options []Option) (string, error) {
defer unhook() defer unhook()
} }
activate()
s, _, _ := getOpenFileName.Call(uintptr(unsafe.Pointer(&args))) s, _, _ := getOpenFileName.Call(uintptr(unsafe.Pointer(&args)))
if opts.ctx != nil && opts.ctx.Err() != nil { if opts.ctx != nil && opts.ctx.Err() != nil {
return "", opts.ctx.Err() return "", opts.ctx.Err()
@ -101,6 +102,7 @@ func selectFileMutiple(options []Option) ([]string, error) {
defer unhook() defer unhook()
} }
activate()
s, _, _ := getOpenFileName.Call(uintptr(unsafe.Pointer(&args))) s, _, _ := getOpenFileName.Call(uintptr(unsafe.Pointer(&args)))
if opts.ctx != nil && opts.ctx.Err() != nil { if opts.ctx != nil && opts.ctx.Err() != nil {
return nil, opts.ctx.Err() return nil, opts.ctx.Err()
@ -179,6 +181,7 @@ func selectFileSave(options []Option) (string, error) {
defer unhook() defer unhook()
} }
activate()
s, _, _ := getSaveFileName.Call(uintptr(unsafe.Pointer(&args))) s, _, _ := getSaveFileName.Call(uintptr(unsafe.Pointer(&args)))
if opts.ctx != nil && opts.ctx.Err() != nil { if opts.ctx != nil && opts.ctx.Err() != nil {
return "", opts.ctx.Err() return "", opts.ctx.Err()
@ -253,6 +256,7 @@ func pickFolders(opts options, multi bool) (str string, lst []string, err error)
defer unhook() defer unhook()
} }
activate()
hr, _, _ = dialog.Call(dialog.vtbl.Show, 0) hr, _, _ = dialog.Call(dialog.vtbl.Show, 0)
if opts.ctx != nil && opts.ctx.Err() != nil { if opts.ctx != nil && opts.ctx.Err() != nil {
return "", nil, opts.ctx.Err() return "", nil, opts.ctx.Err()
@ -335,6 +339,7 @@ func browseForFolder(opts options) (string, []string, error) {
defer unhook() defer unhook()
} }
activate()
ptr, _, _ := shBrowseForFolder.Call(uintptr(unsafe.Pointer(&args))) ptr, _, _ := shBrowseForFolder.Call(uintptr(unsafe.Pointer(&args)))
if opts.ctx != nil && opts.ctx.Err() != nil { if opts.ctx != nil && opts.ctx.Err() != nil {
return "", nil, opts.ctx.Err() return "", nil, opts.ctx.Err()

View file

@ -1,6 +1,5 @@
var app = Application.currentApplication() var app = Application.currentApplication()
app.includeStandardAdditions = true app.includeStandardAdditions = true
app.activate()
var opts = {} var opts = {}

View file

@ -53,6 +53,7 @@ func message(kind messageKind, text string, options []Option) (bool, error) {
defer unhook() defer unhook()
} }
activate()
s, _, err := messageBox.Call(0, s, _, err := messageBox.Call(0,
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(text))), uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(text))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(opts.title))), flags) uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(opts.title))), flags)

View file

@ -3,6 +3,7 @@ package zenity
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"sync" "sync"
"syscall" "syscall"
"unsafe" "unsafe"
@ -19,6 +20,7 @@ var (
commDlgExtendedError = comdlg32.NewProc("CommDlgExtendedError") commDlgExtendedError = comdlg32.NewProc("CommDlgExtendedError")
getCurrentThreadId = kernel32.NewProc("GetCurrentThreadId") getCurrentThreadId = kernel32.NewProc("GetCurrentThreadId")
getConsoleWindow = kernel32.NewProc("GetConsoleWindow")
coInitializeEx = ole32.NewProc("CoInitializeEx") coInitializeEx = ole32.NewProc("CoInitializeEx")
coUninitialize = ole32.NewProc("CoUninitialize") coUninitialize = ole32.NewProc("CoUninitialize")
@ -30,11 +32,33 @@ var (
setWindowsHookEx = user32.NewProc("SetWindowsHookExW") setWindowsHookEx = user32.NewProc("SetWindowsHookExW")
unhookWindowsHookEx = user32.NewProc("UnhookWindowsHookEx") unhookWindowsHookEx = user32.NewProc("UnhookWindowsHookEx")
callNextHookEx = user32.NewProc("CallNextHookEx") callNextHookEx = user32.NewProc("CallNextHookEx")
enumWindows = user32.NewProc("EnumWindows")
enumChildWindows = user32.NewProc("EnumChildWindows") enumChildWindows = user32.NewProc("EnumChildWindows")
getDlgCtrlID = user32.NewProc("GetDlgCtrlID") getDlgCtrlID = user32.NewProc("GetDlgCtrlID")
setWindowText = user32.NewProc("SetWindowTextW") setWindowText = user32.NewProc("SetWindowTextW")
setForegroundWindow = user32.NewProc("SetForegroundWindow")
getWindowThreadProcessId = user32.NewProc("GetWindowThreadProcessId")
) )
func activate() {
var hwnd uintptr
enumWindows.Call(syscall.NewCallback(func(wnd, lparam uintptr) uintptr {
var pid uintptr
getWindowThreadProcessId.Call(wnd, uintptr(unsafe.Pointer(&pid)))
if int(pid) == os.Getpid() {
hwnd = wnd
return 0
}
return 1
}), 0)
if hwnd == 0 {
hwnd, _, _ = getConsoleWindow.Call()
}
if hwnd != 0 {
setForegroundWindow.Call(hwnd)
}
}
func commDlgError() error { func commDlgError() error {
s, _, _ := commDlgExtendedError.Call() s, _, _ := commDlgExtendedError.Call()
if s == 0 { if s == 0 {