Skip to content

Commit

Permalink
Allow usage of hot keys on Linux & Unix
Browse files Browse the repository at this point in the history
See the wiki for details

Closes #19
  • Loading branch information
Rookiestyle committed Sep 18, 2024
1 parent 8312c88 commit dd63807
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 90 deletions.
35 changes: 35 additions & 0 deletions src/AdvancedAutoType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace AdvancedAutoType
{
public sealed class AdvancedAutoTypeExt : Plugin
{
private const string m_sIpcEventName_AAT = "advanced-auto-type";
private const string m_sIpcEventName_UsernameOnly = "auto-type-username";
#region class members
private IPluginHost m_host = null;
ToolStripMenuItem m_menuItem = null;
Expand Down Expand Up @@ -83,9 +85,41 @@ public override bool Initialize(IPluginHost host)

m_host.MainWindow.FormLoadPost += MainWindow_FormLoadPost;

IpcUtilEx.IpcEvent += OnIpcEvent;

return true;
}

private void OnIpcEvent(object sender, IpcEventArgs ipcEventArgs)
{
if (ipcEventArgs.Name.Equals(m_sIpcEventName_AAT, StringComparison.InvariantCultureIgnoreCase))
{
m_host.MainWindow.BeginInvoke(new Action(Ipc_DoAAT));
}
if (ipcEventArgs.Name.Equals(m_sIpcEventName_UsernameOnly, StringComparison.InvariantCultureIgnoreCase))
{
m_host.MainWindow.BeginInvoke(new Action(Ipc_DoUsernameOnly));
}
}

private void Ipc_DoAAT()
{
bool bForceAATHotkeyForUnix = Config.AATHotkeyID == 0 && KeePassLib.Native.NativeLib.IsUnix();
if (bForceAATHotkeyForUnix) Config.AATHotkeyID = -1;
var e = new HotKeyEventArgs(IntPtr.Zero, (IntPtr)Config.AATHotkeyID);
HotKeyPressed(null, e);
if (bForceAATHotkeyForUnix) Config.AATHotkeyID = 0;
}

private void Ipc_DoUsernameOnly()
{
bool bForceUsernameOnlyHotkeyForUnix = Config.UsernameOnlyHotkeyID == 0 && KeePassLib.Native.NativeLib.IsUnix();
if (bForceUsernameOnlyHotkeyForUnix) Config.UsernameOnlyHotkeyID = -1;
var e = new HotKeyEventArgs(IntPtr.Zero, (IntPtr)Config.UsernameOnlyHotkeyID);
HotKeyPressed(null, e);
if (bForceUsernameOnlyHotkeyForUnix) Config.UsernameOnlyHotkeyID = 0;
}

private void MainWindow_FormLoadPost(object sender, EventArgs e)
{
var p = Tools.GetPluginInstance("AlternateAutoType") as Plugin;
Expand All @@ -107,6 +141,7 @@ private void WndProcHandler(object sender, WndProcEventArgs e)
public override void Terminate()
{
if (m_host == null) return;
IpcUtilEx.IpcEvent -= OnIpcEvent;
m_aww.Disable();
WndProcHook.RemoveHandler(m_host.MainWindow);
HotkeysDeactivate();
Expand Down
184 changes: 99 additions & 85 deletions src/Options.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion src/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,15 @@ private void cbSpecialColumns_CheckedChanged(object sender, System.EventArgs e)

private void Options_Load(object sender, System.EventArgs e)
{
tpAlternateAutotypeHotkeys.Enabled = !KeePassLib.Native.NativeLib.IsUnix();
if (KeePassLib.Native.NativeLib.IsUnix())
{
foreach(Control c in tpAlternateAutotypeHotkeys.Controls)
{
if (c == cbUsernameEnter || c == llHotKeyUnix) continue;
c.Enabled = false;
}
}
//tpAlternateAutotypeHotkeys.Enabled = !KeePassLib.Native.NativeLib.IsUnix();
if (!tpAlternateAutotypeHotkeys.Enabled) tcAlternateAutoType.SelectedTab = tpAlternateAutotypeIntegration;
cbSpecialColumns_CheckedChanged(null, null);
}
Expand All @@ -120,6 +128,14 @@ internal void OptionsForm_Shown(object sender, EventArgs e)
//Move all controls from UserControl in TabPage to TabPage
//Make UserControl invisible (do NOT remove: OptionsForm_Closed won't work otherwise)
m_ParentForm = ParentForm;

llHotKeyUnix.Visible = KeePassLib.Native.NativeLib.IsUnix();
llHotKeyUnix.Links.Clear();
Control m_linkHotKeyHelp = Tools.GetControl("m_linkHotKeyHelp", m_ParentForm);
string sText = m_linkHotKeyHelp != null ? m_linkHotKeyHelp.Text : "Create system-wide hot keys";
llHotKeyUnix.Links.Add(0, sText.Length);
llHotKeyUnix.Text = sText;

while (Controls.Count > 0) Parent.Controls.Add(Controls[0]);
Height = Width = 0;
Visible = false;
Expand Down Expand Up @@ -164,5 +180,10 @@ private void cbKeepATOpen_CheckedChanged(object sender, EventArgs e)
{
if (cbKeepATOpen.Checked) cbSpecialColumns.Checked = true;
}

private void llHotKeyUnix_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Tools.OpenUrl("https://github.com/Rookiestyle/AdvancedAutoType/wiki/Unix-Linux-%E2%80%90-Create-system%E2%80%90wide-hot-keys");
}
}
}
6 changes: 3 additions & 3 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ KeePass types EITHER everything before OR everything after {AAT}.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("rookiestyle")]
[assembly: AssemblyProduct("KeePass Plugin")]
[assembly: AssemblyCopyright("Copyright 2020-2023")]
[assembly: AssemblyCopyright("Copyright 2020-2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// This sets the default COM visibility of types in the assembly to invisible.
Expand All @@ -27,7 +27,7 @@ KeePass types EITHER everything before OR everything after {AAT}.
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion("2.1.2")]
[assembly: AssemblyFileVersion("2.1.2")]
[assembly: AssemblyVersion("2.2")]
[assembly: AssemblyFileVersion("2.2")]
[assembly: Guid("78C152F3-EAF8-4FFC-9BE3-F5DC0CD66E5D")]

Loading

0 comments on commit dd63807

Please sign in to comment.