Skip to content

Commit

Permalink
LanguageView": Offer to switch to left-handed setup if right clicking…
Browse files Browse the repository at this point in the history
… "Next" (#133)
  • Loading branch information
meisenzahl committed Jan 11, 2022
1 parent 1fa94d9 commit 013a76b
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 6 deletions.
7 changes: 7 additions & 0 deletions data/io.elementary.initial-setup.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
<binary>io.elementary.initial-setup</binary>
</provides>
<releases>
<release version="6.2.0" date="2022-01-11" urgency="medium">
<p>Improvements:</p>
<ul>
<li>Offer to switch to right-click primary mouse button</li>
<li>Updated translations</li>
</ul>
</release>
<release version="6.1.1" date="2021-08-26" urgency="medium">
<p>Improvements:</p>
<ul>
Expand Down
1 change: 1 addition & 0 deletions src/Helpers/AccountsServiceInterface.vala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public interface Installer.AccountsService : Object {

public abstract KeyboardLayout[] keyboard_layouts { owned get; set; }
public abstract uint active_keyboard_layout { get; set; }
public abstract bool left_handed { get; set; }
}

[DBus (name = "org.freedesktop.Accounts")]
Expand Down
16 changes: 10 additions & 6 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public class Installer.MainWindow : Hdy.Window {

private void on_finish () {
if (account_view.created != null) {
set_keyboard_and_locale.begin ((obj, res) => {
set_keyboard_and_locale.end (res);
set_settings.begin ((obj, res) => {
set_settings.end (res);
destroy ();
});
} else {
Expand All @@ -95,9 +95,12 @@ public class Installer.MainWindow : Hdy.Window {

}

private async void set_keyboard_and_locale () {
yield set_keyboard_layout ();
private async void set_settings () {
yield set_accounts_service_settings ();
yield set_locale ();
}

private async void set_locale () {
string lang = Configuration.get_default ().lang;
string? locale = null;
bool success = yield LocaleHelper.language2locale (lang, out locale);
Expand All @@ -110,7 +113,7 @@ public class Installer.MainWindow : Hdy.Window {
}
}

private async void set_keyboard_layout () {
private async void set_accounts_service_settings () {
AccountsService accounts_service = null;

try {
Expand All @@ -124,7 +127,7 @@ public class Installer.MainWindow : Hdy.Window {
user_path,
GLib.DBusProxyFlags.GET_INVALIDATED_PROPERTIES);
} catch (Error e) {
warning ("Unable to get AccountsService proxy, keyboard layout on new user may be incorrect: %s", e.message);
warning ("Unable to get AccountsService proxy, settings on new user may be incorrect: %s", e.message);
}

if (accounts_service != null) {
Expand All @@ -134,6 +137,7 @@ public class Installer.MainWindow : Hdy.Window {
}

accounts_service.keyboard_layouts = layouts;
accounts_service.left_handed = Configuration.get_default ().left_handed;
}
}
}
1 change: 1 addition & 0 deletions src/Objects/Configuration.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ public class Configuration : GLib.Object {
public string? country { get; set; default = null; }
public InitialSetup.KeyboardLayout keyboard_layout { get; set; }
public InitialSetup.KeyboardVariant? keyboard_variant { get; set; default = null; }
public bool left_handed { get; set; }
}
65 changes: 65 additions & 0 deletions src/Views/LanguageView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ public class Installer.LanguageView : AbstractInstallerView {
lang_variant_widget.main_listbox.row_activated.connect (row_activated);

next_button.clicked.connect (on_next_button_clicked);
next_button.button_press_event.connect ((event) => {
if (event.button == Gdk.BUTTON_SECONDARY) {
on_next_button_secondary_clicked ();
}

return base.button_press_event (event);
});

destroy.connect (() => {
// We need to disconnect the signal otherwise it's called several time when destroying the window…
Expand Down Expand Up @@ -229,6 +236,64 @@ public class Installer.LanguageView : AbstractInstallerView {
next_step ();
}

private void on_next_button_secondary_clicked () {
var mouse_settings = new GLib.Settings ("org.gnome.desktop.peripherals.mouse");

string primary_label = _("Use the right mouse button for primary click?");
string secondary_label = _("The right mouse button was used where a primary click was expected. You can choose to always use the right mouse button for primary click.");
string suggested_action_label = _("Right-Click as Primary");
string cancel_action_label = _("Left-Click as Primary");

if (mouse_settings.get_boolean ("left-handed")) {
primary_label = _("Use the left mouse button for primary click?");
secondary_label = _("The left mouse button was used where a primary click was expected. You can choose to always use the left mouse button for primary click.");
suggested_action_label = _("Left-Click as Primary");
cancel_action_label = _("Right-Click as Primary");
}

var dialog = new Granite.MessageDialog.with_image_from_icon_name (
primary_label,
secondary_label,
"input-mouse",
Gtk.ButtonsType.NONE
) {
transient_for = (Gtk.Window) get_toplevel ()
};
var cancel_action_button = dialog.add_button (cancel_action_label, Gtk.ResponseType.CANCEL);

var suggested_action_button = dialog.add_button (suggested_action_label, Gtk.ResponseType.ACCEPT);
suggested_action_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);

suggested_action_button.button_press_event.connect ((event) => {
if (event.button == Gdk.BUTTON_SECONDARY) {
suggested_action_button.activate ();
}

return base.button_press_event (event);
});

cancel_action_button.button_press_event.connect ((event) => {
if (event.button == Gdk.BUTTON_SECONDARY) {
cancel_action_button.activate ();
}

return base.button_press_event (event);
});

var result = dialog.run ();
dialog.destroy ();

if (!mouse_settings.get_boolean ("left-handed") && result == Gtk.ResponseType.ACCEPT) {
mouse_settings.set_boolean ("left-handed", true);
Configuration.get_default ().left_handed = true;
} else if (mouse_settings.get_boolean ("left-handed") && result == Gtk.ResponseType.ACCEPT) {
mouse_settings.set_boolean ("left-handed", false);
Configuration.get_default ().left_handed = false;
}

next_step ();
}

private bool timeout () {
var row = lang_variant_widget.main_listbox.get_row_at_index (select_number);
if (row == null) {
Expand Down

0 comments on commit 013a76b

Please sign in to comment.