1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-11 02:34:08 +02:00

Add forward/back mouse button handling to notifications (skip/close function)

This commit is contained in:
chylex 2017-04-21 23:21:02 +02:00
parent 39e0dedf27
commit 6e78ba1e7b
2 changed files with 38 additions and 9 deletions

View File

@ -46,6 +46,7 @@ private static int BaseClientHeight{
private readonly NativeMethods.HookProc mouseHookDelegate;
private IntPtr mouseHook;
private bool blockXButtonUp;
private bool? prevDisplayTimer;
private int? prevFontSize;
@ -79,7 +80,7 @@ public FormNotificationMain(FormBrowser owner, PluginManager pluginManager, bool
browser.FrameLoadEnd += Browser_FrameLoadEnd;
mouseHookDelegate = MouseHookProc;
Disposed += (sender, args) => StopMouseHook();
Disposed += (sender, args) => StopMouseHook(true);
}
// mouse wheel hook
@ -90,17 +91,44 @@ private void StartMouseHook(){
}
}
private void StopMouseHook(){
if (mouseHook != IntPtr.Zero){
private void StopMouseHook(bool force){
if (mouseHook != IntPtr.Zero && (force || !blockXButtonUp)){
NativeMethods.UnhookWindowsHookEx(mouseHook);
mouseHook = IntPtr.Zero;
blockXButtonUp = false;
}
}
private IntPtr MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam){
if (nCode == 0 && wParam.ToInt32() == NativeMethods.WM_MOUSEWHEEL && browser.Bounds.Contains(PointToClient(Cursor.Position)) && !ContainsFocus && !owner.ContainsFocus){
browser.SendMouseWheelEvent(0, 0, 0, NativeMethods.GetHookWheelDelta(lParam), CefEventFlags.None);
return NativeMethods.HOOK_HANDLED;
if (nCode == 0){
int eventType = wParam.ToInt32();
if (eventType == NativeMethods.WM_MOUSEWHEEL && browser.Bounds.Contains(PointToClient(Cursor.Position)) && !ContainsFocus && !owner.ContainsFocus){
browser.SendMouseWheelEvent(0, 0, 0, NativeMethods.GetMouseHookData(lParam), CefEventFlags.None);
return NativeMethods.HOOK_HANDLED;
}
else if (eventType == NativeMethods.WM_XBUTTONDOWN && DesktopBounds.Contains(Cursor.Position)){
int extraButton = NativeMethods.GetMouseHookData(lParam);
if (extraButton == 2){ // forward button
this.InvokeAsyncSafe(FinishCurrentNotification);
}
else if (extraButton == 1){ // back button
this.InvokeAsyncSafe(Close);
}
blockXButtonUp = true;
return NativeMethods.HOOK_HANDLED;
}
else if (eventType == NativeMethods.WM_XBUTTONUP && blockXButtonUp){
blockXButtonUp = false;
if (!Visible){
StopMouseHook(false);
}
return NativeMethods.HOOK_HANDLED;
}
}
return NativeMethods.CallNextHookEx(mouseHook, nCode, wParam, lParam);
@ -179,7 +207,7 @@ public override void HideNotification(bool loadBlank){
timerProgress.Stop();
totalTime = 0;
StopMouseHook();
StopMouseHook(false);
}
public override void FinishCurrentNotification(){
@ -190,7 +218,7 @@ public override void PauseNotification(){
if (!IsPaused){
pausedDuringNotification = IsNotificationVisible;
timerProgress.Stop();
StopMouseHook();
StopMouseHook(true);
}
base.PauseNotification();

View File

@ -20,6 +20,7 @@ static class NativeMethods{
public const int WM_MOUSE_LL = 14;
public const int WM_MOUSEWHEEL = 0x020A;
public const int WM_XBUTTONDOWN = 0x020B;
public const int WM_XBUTTONUP = 0x020C;
public const int WM_PARENTNOTIFY = 0x0210;
[StructLayout(LayoutKind.Sequential)]
@ -86,7 +87,7 @@ public static void SetFormPos(Form form, int hWndOrder, uint flags){
SetWindowPos(form.Handle.ToInt32(), hWndOrder, form.Left, form.Top, form.Width, form.Height, flags);
}
public static int GetHookWheelDelta(IntPtr ptr){
public static int GetMouseHookData(IntPtr ptr){
return Marshal.PtrToStructure<MSLLHOOKSTRUCT>(ptr).mouseData >> 16;
}