-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix keyboard switching on Ubuntu 18.04 (fixes #887)
Ubuntu 18.04 changed the way how to switch keyboards. The previous method of setting a dconf value is deprecated and no longer works. Instead this is done by a DBus method call. This change also adds a property to detect if the program runs in a Gnome Shell, and fixes a bug where the wrong keyboard adaptor was used in Ubuntu 18.04.
- Loading branch information
1 parent
f4e3d62
commit 296705f
Showing
10 changed files
with
131 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
SIL.Windows.Forms.Keyboarding/Linux/GnomeShellIbusKeyboardRetrievingAdaptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) 2020 SIL International | ||
// This software is licensed under the MIT License (http://opensource.org/licenses/MIT) | ||
|
||
using SIL.PlatformUtilities; | ||
|
||
namespace SIL.Windows.Forms.Keyboarding.Linux | ||
{ | ||
/// <summary> | ||
/// This class handles initializing the list of keyboards on Ubuntu versions >= 18.04. | ||
/// The keyboard retrieving part is identical to previous versions but switching keyboards | ||
/// changed with 18.04. | ||
/// </summary> | ||
public class GnomeShellIbusKeyboardRetrievingAdaptor: UnityIbusKeyboardRetrievingAdaptor | ||
{ | ||
protected override IKeyboardSwitchingAdaptor CreateSwitchingAdaptor() | ||
{ | ||
return new GnomeShellIbusKeyboardSwitchingAdaptor(IbusCommunicator); | ||
} | ||
|
||
public override bool IsApplicable => _helper.IsApplicable && Platform.IsGnomeShell; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
SIL.Windows.Forms.Keyboarding/Linux/GnomeShellIbusKeyboardSwitchingAdaptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) 2020 SIL International | ||
// This software is licensed under the MIT License (http://opensource.org/licenses/MIT) | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using SIL.Reporting; | ||
|
||
namespace SIL.Windows.Forms.Keyboarding.Linux | ||
{ | ||
/// <summary> | ||
/// Class for dealing with ibus keyboards on Gnome Shell (as found in Ubuntu Bionic >= 18.04) | ||
/// </summary> | ||
public class GnomeShellIbusKeyboardSwitchingAdaptor: UnityIbusKeyboardSwitchingAdaptor, IUnityKeyboardSwitchingAdaptor | ||
{ | ||
public GnomeShellIbusKeyboardSwitchingAdaptor(IIbusCommunicator ibusCommunicator) | ||
: base(ibusCommunicator) | ||
{ | ||
} | ||
|
||
void IUnityKeyboardSwitchingAdaptor.SelectKeyboard(uint index) | ||
{ | ||
var okay = false; | ||
// https://askubuntu.com/a/1039964 | ||
try | ||
{ | ||
using (var proc = new Process { | ||
EnableRaisingEvents = false, | ||
StartInfo = { | ||
FileName = "/usr/bin/gdbus", | ||
Arguments = "call --session --dest org.gnome.Shell --object-path /org/gnome/Shell " + | ||
"--method org.gnome.Shell.Eval " + | ||
$"\"imports.ui.status.keyboard.getInputSourceManager().inputSources[{index}].activate()\"", | ||
UseShellExecute = false | ||
} | ||
}) | ||
{ | ||
proc.Start(); | ||
proc.WaitForExit(); | ||
okay = proc.ExitCode == 0; | ||
} | ||
} | ||
finally | ||
{ | ||
if (!okay) | ||
{ | ||
var msg = $"GnomeShellIbusKeyboardSwitchingAdaptor.SelectKeyboard({index}) failed"; | ||
Console.WriteLine(msg); | ||
Logger.WriteEvent(msg); | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
SIL.Windows.Forms.Keyboarding/Linux/IUnityKeyboardSwitchingAdaptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) 2020 SIL International | ||
// This software is licensed under the MIT License (http://opensource.org/licenses/MIT) | ||
|
||
namespace SIL.Windows.Forms.Keyboarding.Linux | ||
{ | ||
internal interface IUnityKeyboardSwitchingAdaptor | ||
{ | ||
void SelectKeyboard(uint index); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters