Skip to content

Commit

Permalink
deploy: 7fb455e
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Nov 21, 2024
1 parent 8e0d9cd commit c09979d
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 45 deletions.
6 changes: 3 additions & 3 deletions catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,13 @@
"published": 1646604429000,
"rating": 10,
"ratingUsers": 57,
"updated": 1672509589000,
"updated": 1732217907000,
"users": 4510
},
"featured": true,
"metadata": {
"author": "m417z",
"compilerOptions": "-lcomctl32",
"compilerOptions": "-lcomctl32 -lgdi32",
"description": "Use the mouse wheel while hovering over the tab bar to switch between tabs",
"github": "https://github.com/m417z",
"homepage": "https://m417z.com/",
Expand All @@ -283,7 +283,7 @@
],
"name": "Chrome/Edge scroll tabs with mouse wheel",
"twitter": "https://twitter.com/m417z",
"version": "1.0.3"
"version": "1.1"
}
},
"classic-browser-fix": {
Expand Down
5 changes: 5 additions & 0 deletions changelogs/chrome-wheel-scroll-tabs.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.1 ([Nov 21, 2024](https://github.com/ramensoftware/windhawk-mods/blob/7fb455e856a1d5067bae96a727cd1e27a6af9ff3/mods/chrome-wheel-scroll-tabs.wh.cpp))

* Added an option to switch between tabs when the mouse's horizontal scroll wheel is tilted or rotated.
* Fixed the border around the web content in Edge triggering the tab scrolling.

## 1.0.3 ([Dec 31, 2022](https://github.com/ramensoftware/windhawk-mods/blob/c323dbab16d3ed2e63b923a87b325278ff43e767/mods/chrome-wheel-scroll-tabs.wh.cpp))

* Fix scrolling in Edge with the find bar open.
Expand Down
140 changes: 112 additions & 28 deletions mods/chrome-wheel-scroll-tabs.wh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// @id chrome-wheel-scroll-tabs
// @name Chrome/Edge scroll tabs with mouse wheel
// @description Use the mouse wheel while hovering over the tab bar to switch between tabs
// @version 1.0.3
// @version 1.1
// @author m417z
// @github https://github.com/m417z
// @twitter https://twitter.com/m417z
Expand All @@ -11,9 +11,17 @@
// @include msedge.exe
// @include opera.exe
// @include brave.exe
// @compilerOptions -lcomctl32
// @compilerOptions -lcomctl32 -lgdi32
// ==/WindhawkMod==

// Source code is published under The GNU General Public License v3.0.
//
// For bug reports and feature requests, please open an issue here:
// https://github.com/ramensoftware/windhawk-mods/issues
//
// For pull requests, development takes place here:
// https://github.com/m417z/my-windhawk-mods

// ==WindhawkModReadme==
/*
# Chrome/Edge scroll tabs with mouse wheel
Expand All @@ -30,15 +38,23 @@ Currently supported browsers: Google Chrome, Microsoft Edge, Opera, Brave.
/*
- reverseScrollingDirection: false
$name: Reverse Scrolling Direction
- horizontalScrolling: false
$name: Horizontal scrolling
$description: >-
Switch between tabs when the mouse's horizontal scroll wheel is tilted or
rotated
*/
// ==/WindhawkModSettings==

#include <commctrl.h>
#include <windowsx.h>

struct {
bool reverseScrollingDirection;
bool horizontalScrolling;
} g_settings;

bool g_isEdge;
DWORD g_uiThreadId;
DWORD g_lastScrollTime;
HWND g_lastScrollWnd;
Expand All @@ -56,6 +72,32 @@ struct SET_WINDOW_SUBCLASS_FROM_ANY_THREAD_PARAM {
BOOL result;
};

UINT GetDpiForWindowWithFallback(HWND hWnd) {
using GetDpiForWindow_t = UINT(WINAPI*)(HWND hwnd);
static GetDpiForWindow_t pGetDpiForWindow = []() {
HMODULE hUser32 = GetModuleHandle(L"user32.dll");
if (hUser32) {
return (GetDpiForWindow_t)GetProcAddress(hUser32,
"GetDpiForWindow");
}

return (GetDpiForWindow_t) nullptr;
}();

UINT dpi = 96;
if (pGetDpiForWindow) {
dpi = pGetDpiForWindow(hWnd);
} else {
HDC hdc = GetDC(nullptr);
if (hdc) {
dpi = GetDeviceCaps(hdc, LOGPIXELSX);
ReleaseDC(nullptr, hdc);
}
}

return dpi;
}

LRESULT CALLBACK CallWndProcForWindowSubclass(int nCode,
WPARAM wParam,
LPARAM lParam) {
Expand Down Expand Up @@ -97,26 +139,56 @@ BOOL SetWindowSubclassFromAnyThread(HWND hWnd,
param.uIdSubclass = uIdSubclass;
param.dwRefData = dwRefData;
param.result = FALSE;
SendMessage(hWnd, g_subclassRegisteredMsg, TRUE, (WPARAM)&param);
SendMessage(hWnd, g_subclassRegisteredMsg, TRUE, (LPARAM)&param);

UnhookWindowsHookEx(hook);

return param.result;
}

bool OnMouseWheel(HWND hWnd, short delta) {
bool OnMouseWheel(HWND hWnd, WORD keys, short delta, int xPos, int yPos) {
if (keys) {
return false;
}

switch (SendMessage(hWnd, WM_NCHITTEST, 0, MAKELPARAM(xPos, yPos))) {
case HTCLIENT:
case HTCAPTION:
case HTSYSMENU:
case HTMINBUTTON:
case HTMAXBUTTON:
case HTCLOSE:
break;

default:
return false;
}

HWND hForegroundWnd = GetForegroundWindow();
if (!hForegroundWnd || GetAncestor(hForegroundWnd, GA_ROOTOWNER) != hWnd) {
g_lastScrollWnd = nullptr;
return false;
}

if (GetKeyState(VK_CONTROL) < 0 || GetKeyState(VK_MENU) < 0 ||
GetKeyState(VK_SHIFT) < 0 || GetKeyState(VK_PRIOR) < 0 ||
if (GetKeyState(VK_MENU) < 0 || GetKeyState(VK_LWIN) < 0 ||
GetKeyState(VK_RWIN) < 0 || GetKeyState(VK_PRIOR) < 0 ||
GetKeyState(VK_NEXT) < 0) {
return false;
}

// Edge has a thin border around the web content which triggers the tab
// scrolling. Ignore events which are very close to the window borders.
if (g_isEdge) {
UINT dpi = GetDpiForWindowWithFallback(hWnd);
RECT rect{};
GetWindowRect(hWnd, &rect);
if (MulDiv(xPos - rect.left, 96, dpi) <= 15 ||
MulDiv(rect.right - xPos, 96, dpi) <= 15 ||
MulDiv(rect.bottom - yPos, 96, dpi) <= 15) {
return false;
}
}

if (hWnd == g_lastScrollWnd &&
GetTickCount() - g_lastScrollTime < 1000 * 5) {
delta += g_lastScrollDeltaRemainder;
Expand All @@ -125,18 +197,14 @@ bool OnMouseWheel(HWND hWnd, short delta) {
int clicks = delta / WHEEL_DELTA;
Wh_Log(L"%d clicks (delta=%d)", clicks, delta);

if (g_settings.reverseScrollingDirection) {
clicks = -clicks;
}

WORD key = VK_PRIOR;
WORD key = VK_NEXT;
if (clicks < 0) {
clicks = -clicks;
key = VK_NEXT;
key = VK_PRIOR;
}

INPUT* input = new INPUT[clicks * 2 + 2];
for (size_t i = 0; i < clicks * 2 + 2; i++) {
for (int i = 0; i < clicks * 2 + 2; i++) {
input[i].type = INPUT_KEYBOARD;
input[i].ki.wScan = 0;
input[i].ki.time = 0;
Expand All @@ -146,7 +214,7 @@ bool OnMouseWheel(HWND hWnd, short delta) {
input[0].ki.wVk = VK_CONTROL;
input[0].ki.dwFlags = 0;

for (size_t i = 0; i < clicks; i++) {
for (int i = 0; i < clicks; i++) {
input[1 + i * 2].ki.wVk = key;
input[1 + i * 2].ki.dwFlags = 0;
input[1 + i * 2 + 1].ki.wVk = key;
Expand All @@ -173,26 +241,39 @@ LRESULT CALLBACK BrowserWindowSubclassProc(_In_ HWND hWnd,
_In_ LPARAM lParam,
_In_ UINT_PTR uIdSubclass,
_In_ DWORD_PTR dwRefData) {
if (uMsg == WM_NCDESTROY || (uMsg == g_subclassRegisteredMsg && !wParam)) {
RemoveWindowSubclass(hWnd, BrowserWindowSubclassProc, 0);
}

switch (uMsg) {
case WM_MOUSEWHEEL:
switch (SendMessage(hWnd, WM_NCHITTEST, 0, lParam)) {
case HTCLIENT:
case HTCAPTION:
case HTSYSMENU:
case HTMINBUTTON:
case HTMAXBUTTON:
case HTCLOSE:
if (OnMouseWheel(hWnd, GET_WHEEL_DELTA_WPARAM(wParam))) {
return 0;
}
case WM_MOUSEHWHEEL: {
WORD fwKeys = GET_KEYSTATE_WPARAM(wParam);
short zDelta = GET_WHEEL_DELTA_WPARAM(wParam);
int xPos = GET_X_LPARAM(lParam);
int yPos = GET_Y_LPARAM(lParam);

if (uMsg == WM_MOUSEHWHEEL) {
if (!g_settings.horizontalScrolling) {
break;
}

// For horizontal scrolling, a large delta value might be posted
// for a single click (e.g. 480). Limit the value to 120.
if (zDelta < -120) {
zDelta = -120;
} else if (zDelta > 120) {
zDelta = 120;
}
} else if (!g_settings.reverseScrollingDirection) {
zDelta = -zDelta;
}
break;

default:
if (uMsg == g_subclassRegisteredMsg && !wParam)
RemoveWindowSubclass(hWnd, BrowserWindowSubclassProc, 0);
if (OnMouseWheel(hWnd, fwKeys, zDelta, xPos, yPos)) {
return 0;
}
break;
}
}

return DefSubclassProc(hWnd, uMsg, wParam, lParam);
Expand Down Expand Up @@ -289,13 +370,16 @@ HWND WINAPI CreateWindowExWHook(DWORD dwExStyle,
void LoadSettings() {
g_settings.reverseScrollingDirection =
Wh_GetIntSetting(L"reverseScrollingDirection");
g_settings.horizontalScrolling = Wh_GetIntSetting(L"horizontalScrolling");
}

BOOL Wh_ModInit() {
Wh_Log(L">");

LoadSettings();

g_isEdge = !!GetModuleHandle(L"msedge.exe");

Wh_SetFunctionHook((void*)CreateWindowExW, (void*)CreateWindowExWHook,
(void**)&pOriginalCreateWindowExW);

Expand Down
29 changes: 15 additions & 14 deletions updates.atom
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@
<feed xmlns="http://www.w3.org/2005/Atom">
<id>https://windhawk.net/</id>
<title>Windhawk Mod Updates</title>
<updated>2024-11-21T11:02:33.000Z</updated>
<updated>2024-11-21T19:38:27.000Z</updated>
<generator>https://github.com/jpmonette/feed</generator>
<link rel="alternate" href="https://windhawk.net/"/>
<subtitle>Updates in the official collection of Windhawk mods</subtitle>
<icon>https://windhawk.net/favicon.ico</icon>
<rights>Ramen Software</rights>
<entry>
<title type="html"><![CDATA[Chrome/Edge scroll tabs with mouse wheel 1.1]]></title>
<id>https://windhawk.net/mods/chrome-wheel-scroll-tabs#7fb455e856a1d5067bae96a727cd1e27a6af9ff3</id>
<link href="https://windhawk.net/mods/chrome-wheel-scroll-tabs"/>
<updated>2024-11-21T19:38:27.000Z</updated>
<content type="html"><![CDATA[<ul>
<li>Added an option to switch between tabs when the mouse's horizontal scroll wheel is tilted or rotated.</li>
<li>Fixed the border around the web content in Edge triggering the tab scrolling.</li>
</ul>]]></content>
<author>
<name>m417z</name>
<uri>https://github.com/m417z</uri>
</author>
</entry>
<entry>
<title type="html"><![CDATA[Fix browsers for Windows Classic theme 1.2.1]]></title>
<id>https://windhawk.net/mods/classic-browser-fix#f646116532b0fbd44766c91c0c4d9ca824647ee6</id>
Expand Down Expand Up @@ -265,19 +279,6 @@ center, etc. to another monitor.</p>
<updated>2024-11-08T23:35:10.000Z</updated>
<content type="html"><![CDATA[<ul>
<li>Added an option to mix files and folders when sorting by size.</li>
</ul>]]></content>
<author>
<name>m417z</name>
<uri>https://github.com/m417z</uri>
</author>
</entry>
<entry>
<title type="html"><![CDATA[Better file sizes in Explorer details 1.3]]></title>
<id>https://windhawk.net/mods/explorer-details-better-file-sizes#404f046ed97d3f4f50c777b774419268c318de7a</id>
<link href="https://windhawk.net/mods/explorer-details-better-file-sizes"/>
<updated>2024-11-08T18:05:33.000Z</updated>
<content type="html"><![CDATA[<ul>
<li>The integration with Everything was rewritten and is now faster (about x6 speedup), more stable (occasional hangs were fixed), and more robust overall.</li>
</ul>]]></content>
<author>
<name>m417z</name>
Expand Down

0 comments on commit c09979d

Please sign in to comment.