Skip to content

Commit

Permalink
Fix the issue with language ID-based unloading
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuubari committed Mar 17, 2021
1 parent 38dd044 commit cbc0f3c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions LayOff/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ private string GetCultureInfoName(ushort cultureId)
}
}

[DllImport("user32.dll")]
private static extern bool UnloadKeyboardLayout(uint hkl);

public bool Equals(KeyboardLayout other)
{
return Id == other.Id;
return MatchLanguage ? Id == (other.Id & 0xFFFF) : Id == other.Id;
}

public override string ToString()
Expand All @@ -74,6 +77,14 @@ public void PrintLayoutInfo()
KeyboardId);
}
}

public bool Unload()
{
#if DEBUG
Console.WriteLine("Unloading {0}.", ToString());
#endif
return UnloadKeyboardLayout(Id);
}
}

class Program
Expand Down Expand Up @@ -221,10 +232,13 @@ static int Main(string[] args)

foreach (var layout in klList)
{
#if DEBUG
layout.PrintLayoutInfo();
#endif
if (layoutList.Contains(layout))
{
Console.WriteLine("Found a layout to lay off: {0}.", layout);
if (!UnloadKeyboardLayout(layout.Id))
if (!layout.Unload())
{
Console.WriteLine("Failed to unload {0}.", layout);
}
Expand Down

0 comments on commit cbc0f3c

Please sign in to comment.