AlexVallat / KeyLayoutAutoSwitch

An automatic keyboard layout switcher for web browsers
GNU General Public License v3.0
13 stars 1 forks source link

[feature req] Remember layouts for tabs #1

Closed Yamato-ua closed 5 years ago

Yamato-ua commented 5 years ago

If I understand correctly KeyLayoutAutoSwitch doesn't remember layouts for separate tabs (apart from the ones set via domain). Say, I need to switch between 2 or more layouts on one webpage and I need that tab to stay in the selected layout until next manual switching. That was the main feature I needed TabLang for, and my only alternatives are older Firefox or IE.

Are there plans to implement it here? Could this work via browser access function?

AlexVallat commented 5 years ago

Hmm, it's tricky, as it's going to have to read the current keyboard layout - the current implementation only needs to set it, not read it.

However, thank you for raising this issue. I was unaware that this was an important feature of TabLang, so I will do my best to implement it here.

If I've understood correctly, the behaviour should be that, when a tab loses focus, I record the current layout at that time. Then, if that tab regains the focus, rather than applying the normal rules, it should restore whichever layout it had when it was last used?

Yamato-ua commented 5 years ago

Thanks for your reply!

If I've understood correctly, the behaviour should be that, when a tab loses focus, I record the current layout at that time. Then, if that tab regains the focus, rather than applying the normal rules, it should restore whichever layout it had when it was last used?

Correct. So that a user can have 3 open tabs in 3 layouts (even within the same domain) and doesn't need to switch to the correct layout after every tab switch. It helps a lot when you work with multiple texts in different languages, so you can have 2 tabs with texts and 3rd tab with a dictionary.

AlexVallat commented 5 years ago

I can see a possible limitation here - I can detect the URL, but I'm not sure I can detect a unique tab. If two tabs shared the same URL, then they would be treated identically, and have the same layout set or restored for them. Is that going to make this unworkable?

I'm also considering the correct behaviour from the point of view of whether changing the layout should affect other tabs. Normally, if I'm on a tab, and change the language to, say, English, then it stays as English when I switch to other tabs too (unless there is a rule set up that applies to one of the other tabs). I'm not sure if it would be preferable to have the change apply only to the current tab, so switching to another tab would restore the previous layout. The problem would be, if done like that, it might be very irritating for someone who does just want to change their current keyboard layout, not make a change for only one specific tab.

Yamato-ua commented 5 years ago

Being able to work in 2 tabs within 1 domain (let's say, two open documents from docs.google.com) with different layouts would be nice too, but not the most important thing for me.

As for the browser-wide layout switching, yes, it would make sense to make it optional via a tick box. Though for me this principle in TabLang was ideal: every open tab remembers its layout and any new tab is set to the default English. Too bad FF doesn't support it natively like IE.

AlexVallat commented 5 years ago

OK, so here is where we are. I can't get a unique ID for a tab, so this all has to be based on URLs. It doesn't have to be just the domain, it can be the entire domain.

The best I have been able to come up with is to have it record the current layout and URL before making any change. Then, if the same URL returns, it can restore the last layout it saw for that URL.

The behaviour would be:

The big problem with this scheme is, of course, that it involves storing your browsing history (at least those URLs where custom layouts have been set), which I'm not very happy about.

Yamato-ua commented 5 years ago

By custom layout you mean tabs that have been manually switched to non-default layout?

Storing history locally is not a problem, but it would make sense to delete it when the application (or browser) is closed, unless someone needs more long-term layout settings. In that case you could set it to, say, delete it after a week from the last time the tab was focused. Yes, that would be ideal: if someone works on a long-term project with the same URLs, the week delay allows to store settings over a long weekend with no activity on tabs.

AlexVallat commented 5 years ago

Yes, I think if I store it in-memory only, and hashed, it's probably OK, privacy-wise. I'll have it off by default too.

Could you give the attached candidate build a try and see if the proposed behaviour is suitable for your workflow? If so, I will release it as v1.1

KeyLayoutAutoSwitch.zip

Yamato-ua commented 5 years ago

It wont start. Win10 64bit.

AlexVallat commented 5 years ago

Did you copy it over the existing install? I didn't create a new installer, this just should just replace the existing KeyLayoutAutoSwitch.exe. If it still doesn't start, does it give any error message?

Yamato-ua commented 5 years ago

Oh. My bad. It works now.

It works great on regular web pages, but it wont remember layouts on tabs with Google Doc documents. Could it be because they're not pages as such, but rather web apps? I remember having some other FF addon that worked on regular pages but not on Gdocs.

Here are couple of sample docs I've created for testing: https://docs.google.com/document/d/1Q2JRnqcLMj84XuXxgIwaOer7GmIQhY7uQBfLXLdR6C8/edit?usp=sharing https://docs.google.com/spreadsheets/d/1rosndqra1ahnu3l9CjZIKrPQMH-t2i-4cN4D7MwluGI/edit?usp=sharing

Unfortunately it wont replace TabLang for me personally. My work involves at least one Gdoc constantly open and even with the rest of tabs switching fine that would break the flow.

But nonetheless that would be a great replacement that should suit fine the vast majority of previous TabLang users. It's an enormous improvement over the first version. Suitable for release, I think.

AlexVallat commented 5 years ago

Yeah, it seems Google are setting a custom document role on those pages, which prevents Firefox from reporting the URL via accessibility. It's not ideal, but a workaround for this is to install the firefox addon: https://addons.mozilla.org/firefox/addon/prevent-custom-document-role/

Yamato-ua commented 5 years ago

Great! That solves it.

AlexVallat commented 5 years ago

Great, I'll release like this then. Thanks for letting me know.