Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offer to switch to left-handed setup if right clicking "Next" #133

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
31 changes: 29 additions & 2 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,6 +95,11 @@ public class Installer.MainWindow : Hdy.Window {

}

private async void set_settings () {
yield set_keyboard_and_locale ();
yield set_left_handed ();
}

private async void set_keyboard_and_locale () {
yield set_keyboard_layout ();

Expand Down Expand Up @@ -136,4 +141,26 @@ public class Installer.MainWindow : Hdy.Window {
accounts_service.keyboard_layouts = layouts;
}
}

private async void set_left_handed () {
AccountsService accounts_service = null;

try {
var act_service = yield GLib.Bus.get_proxy<FDO.Accounts> (GLib.BusType.SYSTEM,
"org.freedesktop.Accounts",
"/org/freedesktop/Accounts");
var user_path = act_service.find_user_by_name (account_view.created.user_name);

accounts_service = yield GLib.Bus.get_proxy (GLib.BusType.SYSTEM,
"org.freedesktop.Accounts",
user_path,
GLib.DBusProxyFlags.GET_INVALIDATED_PROPERTIES);
} catch (Error e) {
warning ("Unable to get AccountsService proxy, clock format on new user may be incorrect: %s", e.message);
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved
}

if (accounts_service != null) {
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; }
}
47 changes: 47 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,46 @@ public class Installer.LanguageView : AbstractInstallerView {
next_step ();
}

private void on_next_button_secondary_clicked () {
var dialog = new Granite.MessageDialog.with_image_from_icon_name (
_("Use the right mouse button for primary click?"),
_("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."),
"input-mouse",
Gtk.ButtonsType.NONE
);
dialog.transient_for = (Gtk.Window) get_toplevel ();

var left_click_as_primary_button = dialog.add_button (_("Left-Click as Primary"), Gtk.ResponseType.REJECT);
left_click_as_primary_button.button_press_event.connect ((event) => {
if (event.button == Gdk.BUTTON_SECONDARY) {
left_click_as_primary_button.activate ();
}

return base.button_press_event (event);
});

var right_click_as_primary_button = dialog.add_button (_("Right-Click as Primary"), Gtk.ResponseType.ACCEPT);
right_click_as_primary_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
right_click_as_primary_button.grab_focus ();

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

return base.button_press_event (event);
});

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

var left_handed = result == Gtk.ResponseType.ACCEPT;
var mouse_settings = new GLib.Settings ("org.gnome.desktop.peripherals.mouse");
mouse_settings.set_boolean ("left-handed", left_handed);
Configuration.get_default ().left_handed = left_handed;
next_step ();
}

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