Skip to content

Commit 012b388

Browse files
fix(open-dialog): don't use xdotool on Wayland
Ref: #16
1 parent d03dde5 commit 012b388

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

open-dialog/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ If you're on KDE, you should download
3030
If not, you should download
3131
[zenity.lua](zenity.lua) which uses [Zenity][zenity].
3232

33-
[xdotool][xdotool] is required for both scripts.
34-
3533
### Windows
3634

3735
Download [powershell.lua](powershell.lua).
@@ -42,4 +40,3 @@ Download [osascript.lua](osascript.lua).
4240

4341
[kdialog]: https://github.com/KDE/kdialog
4442
[zenity]: https://github.com/GNOME/zenity
45-
[xdotool]: https://github.com/jordansissel/xdotool

open-dialog/kdialog.lua

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
local utils = require 'mp.utils'
66

7+
local xorg = os.getenv('XDG_SESSION_TYPE') == 'x11'
8+
79
local MULTIMEDIA = table.concat({
810
'*.aac',
911
'*.avi',
@@ -52,20 +54,24 @@ local function KDialog(opts)
5254
path = path == nil and '' or utils.split_path(
5355
utils.join_path(utils.getcwd(), path)
5456
)
57+
local args = {
58+
'kdialog', opts.default or path,
59+
'--title', opts.title,
60+
'--icon', ICON,
61+
'--multiple', '--separate-output',
62+
opts.type or '--getopenfilename', opts.text,
63+
}
5564
local ontop = mp.get_property_native('ontop')
56-
local focus = utils.subprocess {
57-
args = {'xdotool', 'getwindowfocus'}
58-
}.stdout:gsub('\n$', '')
65+
if xorg then
66+
local focus = utils.subprocess {
67+
args = {'xdotool', 'getwindowfocus'}
68+
}.stdout:gsub('\n$', '')
69+
table.insert(args, 5, '--attach')
70+
table.insert(args, 6, focus)
71+
end
5972
mp.set_property_native('ontop', false)
6073
local kdialog = utils.subprocess {
61-
args = {
62-
'kdialog', opts.default or path,
63-
'--title', opts.title,
64-
'--attach', focus,
65-
'--icon', ICON,
66-
'--multiple', '--separate-output',
67-
opts.type or '--getopenfilename', opts.text,
68-
}, cancellable = false,
74+
args = args, cancellable = false
6975
}
7076
mp.set_property_native('ontop', ontop)
7177
if kdialog.status ~= 0 then return end

open-dialog/zenity.lua

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
local utils = require 'mp.utils'
66

7+
local xorg = os.getenv('XDG_SESSION_TYPE') == 'x11'
8+
79
local MULTIMEDIA = table.concat({
810
'*.aac',
911
'*.avi',
@@ -65,23 +67,31 @@ local function Zenity(opts)
6567
utils.join_path(utils.getcwd(), path)
6668
)
6769
}
68-
local ontop = mp.get_property_native('ontop')
69-
local focus = utils.subprocess {
70-
args = {'xdotool', 'getwindowfocus'}
71-
}.stdout:gsub('\n$', '')
72-
mp.set_property_native('ontop', false)
73-
local zenity = utils.subprocess {
74-
args = merge({
70+
local args = merge(
71+
{
7572
'zenity', '--modal',
7673
'--title', opts.title,
77-
'--attach', focus,
7874
'--window-icon', ICON,
79-
}, opts.default or path,
80-
opts.text, opts.type or {
75+
},
76+
opts.default or path,
77+
opts.text,
78+
opts.type or {
8179
'--file-selection',
8280
'--separator', '\n',
8381
'--multiple',
84-
}), cancellable = false,
82+
}
83+
)
84+
local ontop = mp.get_property_native('ontop')
85+
if xorg then
86+
local focus = utils.subprocess {
87+
args = {'xdotool', 'getwindowfocus'}
88+
}.stdout:gsub('\n$', '')
89+
table.insert(args, 5, '--attach')
90+
table.insert(args, 6, focus)
91+
end
92+
mp.set_property_native('ontop', false)
93+
local zenity = utils.subprocess {
94+
args = args, cancellable = false
8595
}
8696
mp.set_property_native('ontop', ontop)
8797
if zenity.status ~= 0 then return end

0 commit comments

Comments
 (0)