Skip to content

Commit 11bfaa2

Browse files
author
AlexVallat
committed
Add note about Custom Role Preventer addon. Ignore url query and anchor
1 parent dfcc396 commit 11bfaa2

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

KeyLayoutAutoSwitch/Program.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,24 @@ private void OnConfigure(object sender, EventArgs e)
169169

170170
private string mLastFocusedUrl;
171171
private readonly Dictionary<int, IntPtr> mPreviousUrlLayouts = new Dictionary<int, IntPtr>();
172-
172+
173+
private bool TryGetPreviousUrlLayout(string url, out IntPtr layout)
174+
{
175+
var result = mPreviousUrlLayouts.TryGetValue(url.GetHashCode(), out layout);
176+
if (result)
177+
{
178+
Debug.WriteLine($"Restoring previous layout for {url}: {layout}");
179+
}
180+
181+
return result;
182+
}
183+
184+
private void SetPreviousUrlLayout(string url, IntPtr layout)
185+
{
186+
mPreviousUrlLayouts[url.GetHashCode()] = layout;
187+
Debug.WriteLine($"Stored previous layout for {url}: {layout}");
188+
}
189+
173190
private void OnFocusChanged(IntPtr hwnd, uint idObject, uint idChild)
174191
{
175192
var className = NativeMethods.GetWindowClassName(hwnd);
@@ -188,7 +205,9 @@ private void OnFocusChanged(IntPtr hwnd, uint idObject, uint idChild)
188205
var accessibleObject = NativeMethods.GetAccessibleFromEvent(hwnd, idObject, idChild);
189206
if (accessibleObject != null)
190207
{
191-
var focusType = browser.GetFocusType(accessibleObject, out var url);
208+
var focusType = browser.GetFocusType(accessibleObject, out var fullUrl);
209+
var url = new Uri(fullUrl).GetLeftPart(UriPartial.Path); // Ignore query and anchor parts of the URL
210+
192211
Debug.WriteLine($"Focus on {focusType} with url {url}");
193212
//Debug.WriteLine($"Focus on accessible object: {accessibleObject.accName[0]} ({AccessibleObjectHelper.GetRole(accessibleObject)})");
194213

@@ -206,17 +225,15 @@ private void OnFocusChanged(IntPtr hwnd, uint idObject, uint idChild)
206225
Debug.Assert(currentLayout != IntPtr.Zero, "Unable to get current keyboard layout");
207226
if (currentLayout != IntPtr.Zero && currentLayout != ruleLayoutForLastUrl)
208227
{
209-
Debug.WriteLine($"Stored previous layout for {mLastFocusedUrl}: {currentLayout}");
210-
mPreviousUrlLayouts[mLastFocusedUrl.GetHashCode()] = currentLayout;
228+
SetPreviousUrlLayout(mLastFocusedUrl, currentLayout);
211229
}
212230
}
213231

214232
// Attempt to look up the previous layout for this url
215233
if (url != null && Rules.Instance.RestorePreviouslyVisitedPageLayouts &&
216-
mPreviousUrlLayouts.TryGetValue(url.GetHashCode(), out var previousLayout))
234+
TryGetPreviousUrlLayout(url, out var previousLayout))
217235
{
218236
mPreviousUrlLayouts.Remove(url.GetHashCode());
219-
Debug.WriteLine($"Restoring previous layout for {url}: {previousLayout}");
220237
NativeMethods.SwitchKeyboardLayout(hwnd, previousLayout);
221238
}
222239
else

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ KeyLayoutAutoSwitch is not an Add-on. Firefox no longer supports the technical r
1616

1717
[Download Installer](https://github.com/AlexVallat/KeyLayoutAutoSwitch/releases/latest)
1818

19+
Some web sites, notably Google Docs, set a custom Aria document role on their pages. This prevents Firefox from reporting the URL for them through accessibility services. Most sites do not exhibit this problem, but if the ones you use do, then you can install the [Prevent Custom Document Role](https://addons.mozilla.org/firefox/addon/prevent-custom-document-role/) addon to work around the issue.
20+
1921
## Usage
2022
Running KeyLayoutAutoSwitch will show the main configuration window. This can also be shown by double clicking on the icon in the notification area of the taskbar. In this window, the keyboard layout to use for each browser element can be set by selecting the relevant entry in the list and clicking the Edit button.
2123

0 commit comments

Comments
 (0)