Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add note about Custom Role Preventer addon. Ignore url query and anchor
  • Loading branch information
AlexVallat committed Mar 21, 2019
1 parent dfcc396 commit 11bfaa2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
29 changes: 23 additions & 6 deletions KeyLayoutAutoSwitch/Program.cs
Expand Up @@ -169,7 +169,24 @@ private void OnConfigure(object sender, EventArgs e)


private string mLastFocusedUrl; private string mLastFocusedUrl;
private readonly Dictionary<int, IntPtr> mPreviousUrlLayouts = new Dictionary<int, IntPtr>(); private readonly Dictionary<int, IntPtr> mPreviousUrlLayouts = new Dictionary<int, IntPtr>();


private bool TryGetPreviousUrlLayout(string url, out IntPtr layout)
{
var result = mPreviousUrlLayouts.TryGetValue(url.GetHashCode(), out layout);
if (result)
{
Debug.WriteLine($"Restoring previous layout for {url}: {layout}");
}

return result;
}

private void SetPreviousUrlLayout(string url, IntPtr layout)
{
mPreviousUrlLayouts[url.GetHashCode()] = layout;
Debug.WriteLine($"Stored previous layout for {url}: {layout}");
}

private void OnFocusChanged(IntPtr hwnd, uint idObject, uint idChild) private void OnFocusChanged(IntPtr hwnd, uint idObject, uint idChild)
{ {
var className = NativeMethods.GetWindowClassName(hwnd); var className = NativeMethods.GetWindowClassName(hwnd);
Expand All @@ -188,7 +205,9 @@ private void OnFocusChanged(IntPtr hwnd, uint idObject, uint idChild)
var accessibleObject = NativeMethods.GetAccessibleFromEvent(hwnd, idObject, idChild); var accessibleObject = NativeMethods.GetAccessibleFromEvent(hwnd, idObject, idChild);
if (accessibleObject != null) if (accessibleObject != null)
{ {
var focusType = browser.GetFocusType(accessibleObject, out var url); var focusType = browser.GetFocusType(accessibleObject, out var fullUrl);
var url = new Uri(fullUrl).GetLeftPart(UriPartial.Path); // Ignore query and anchor parts of the URL

Debug.WriteLine($"Focus on {focusType} with url {url}"); Debug.WriteLine($"Focus on {focusType} with url {url}");
//Debug.WriteLine($"Focus on accessible object: {accessibleObject.accName[0]} ({AccessibleObjectHelper.GetRole(accessibleObject)})"); //Debug.WriteLine($"Focus on accessible object: {accessibleObject.accName[0]} ({AccessibleObjectHelper.GetRole(accessibleObject)})");


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


// Attempt to look up the previous layout for this url // Attempt to look up the previous layout for this url
if (url != null && Rules.Instance.RestorePreviouslyVisitedPageLayouts && if (url != null && Rules.Instance.RestorePreviouslyVisitedPageLayouts &&
mPreviousUrlLayouts.TryGetValue(url.GetHashCode(), out var previousLayout)) TryGetPreviousUrlLayout(url, out var previousLayout))
{ {
mPreviousUrlLayouts.Remove(url.GetHashCode()); mPreviousUrlLayouts.Remove(url.GetHashCode());
Debug.WriteLine($"Restoring previous layout for {url}: {previousLayout}");
NativeMethods.SwitchKeyboardLayout(hwnd, previousLayout); NativeMethods.SwitchKeyboardLayout(hwnd, previousLayout);
} }
else else
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -16,6 +16,8 @@ KeyLayoutAutoSwitch is not an Add-on. Firefox no longer supports the technical r


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


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.

## Usage ## Usage
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. 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.


Expand Down

0 comments on commit 11bfaa2

Please sign in to comment.