diff --git a/README.md b/README.md index 99a882c..6862a9b 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,9 @@ To install this, just run `git clone https://github.com/qwerty12/mpv-taskbar-but If you instead download the zipped version of this repo, just copy the mpv-taskbar-buttons folder as-is into your mpv scripts folder. The files **must** be in a subfolder of your mpv scripts folder for this script to load. To get rid of this, just delete the folder. -Requests to add more buttons to this script will be ignored. If you have the code to perform a custom action already written but need help with adding a button to your own copy of the script to call it, make an issue. If you want to change what happens when one of the existing buttons are clicked, look at the `callbacks` table in hook.lua. +If you want to change what happens when one of the existing buttons are clicked, look at the `callbacks` table in hook.lua. + +Requests to add more buttons to this script will be ignored. If you have code to perform a custom action already written but need help with adding a button to your own copy of this script to call it, make an issue. Windows allows up to seven buttons. ## Known issues diff --git a/hook.lua b/hook.lua index 51524fd..0c57d0e 100644 --- a/hook.lua +++ b/hook.lua @@ -70,7 +70,7 @@ ffi.cdef [[ local WH_GETMESSAGE = 3 local WM_COMMAND = 0x0111 local MSGFLT_ADD = 1 -local INFINITE = 0xFFFFFFFF +local INFINITE, WAIT_OBJECT_0 = 0xFFFFFFFF, 0x00000000 local GPTR = 0x0040 local PAGE_EXECUTE_READWRITE = 0x40 local SetEvent = C.GetProcAddress(C.GetModuleHandleA("kernel32.dll"), "SetEvent") @@ -85,7 +85,6 @@ local lpCompiledCallback, lpGetMsgProc local hHook = nil local function generate_hook_callback() - -- Taken from https://github.com/nucular/tcclua ffi.cdef [[ struct TCCState; @@ -156,7 +155,7 @@ local function generate_hook_callback() ["SetEvent"] = SetEvent, ["CallNextHookEx"] = C.GetProcAddress(C.GetModuleHandleA("user32.dll"), "CallNextHookEx") }) do - value = type(value) == "cdata" and tostring(value):match("^cdata<.+>: (.+)") or tostring(value) + value = type(value) == "cdata" and tostring(value):match("^cdata<.+>: (0x.+)") or tostring(value) hook = hook:gsub("#" .. name .. "#", value) end @@ -211,10 +210,9 @@ _G.mp_event_loop = function() while mp.keep_running do local dwStatus = C.WaitForMultipleObjects(nEventCount, hEvents, false, dwTimeout - dwElapsed) - if dwStatus == 0 then --hMpvWakeupEvent signalled + if dwStatus == WAIT_OBJECT_0 then --hMpvWakeupEvent signalled mp.dispatch_events(false) - end - if dwStatus == 1 then -- hCommandReceivedEvent signalled + elseif dwStatus == 1 then -- hCommandReceivedEvent signalled local wmId = last_button_hit[0] if callbacks[wmId] then callbacks[wmId]()