Skip to content

Commit b3a540a

Browse files
authored
Middle click paste: add Wayland support (#253)
1 parent c1da29c commit b3a540a

1 file changed

Lines changed: 43 additions & 31 deletions

File tree

src/Views/Clicking.vala

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
*/
1919

2020
public class MouseTouchpad.ClickingView : Switchboard.SettingsPage {
21+
private GLib.Settings? xsettings;
22+
private GLib.Settings interface_settings;
23+
2124
public ClickingView () {
2225
Object (
2326
header: _("Behavior"),
@@ -161,35 +164,40 @@ public class MouseTouchpad.ClickingView : Switchboard.SettingsPage {
161164
"org.gnome.settings-daemon.plugins.xsettings",
162165
true
163166
);
164-
165167
if (xsettings_schema != null) {
166-
var primary_paste_switch = new Gtk.Switch () {
167-
halign = Gtk.Align.END,
168-
valign = Gtk.Align.CENTER
169-
};
170-
171-
var primary_paste_header = new Granite.HeaderLabel (_("Middle Click Paste")) {
172-
mnemonic_widget = primary_paste_switch,
173-
secondary_text = _("Middle or three-finger click on an input to paste selected text")
174-
};
175-
176-
content_area.attach (primary_paste_header, 0, 8);
177-
content_area.attach (primary_paste_switch, 1, 8);
178-
179-
var xsettings = new GLib.Settings ("org.gnome.settings-daemon.plugins.xsettings");
180-
primary_paste_switch.notify["active"].connect (() => {
181-
on_primary_paste_switch_changed (primary_paste_switch, xsettings);
182-
});
183-
184-
var current_value = xsettings.get_value ("overrides").lookup_value (
185-
"Gtk/EnablePrimaryPaste",
186-
VariantType.INT32
187-
);
188-
if (current_value != null) {
189-
primary_paste_switch.active = current_value.get_int32 () == 1;
168+
xsettings = new GLib.Settings ("org.gnome.settings-daemon.plugins.xsettings");
169+
}
170+
171+
interface_settings = new GLib.Settings ("org.gnome.desktop.interface");
172+
173+
var primary_paste_switch = new Gtk.Switch () {
174+
halign = Gtk.Align.END,
175+
valign = Gtk.Align.CENTER
176+
};
177+
178+
var primary_paste_header = new Granite.HeaderLabel (_("Middle Click Paste")) {
179+
mnemonic_widget = primary_paste_switch,
180+
secondary_text = _("Middle or three-finger click on an input to paste selected text")
181+
};
182+
183+
content_area.attach (primary_paste_header, 0, 8);
184+
content_area.attach (primary_paste_switch, 1, 8);
185+
186+
primary_paste_switch.notify["active"].connect (() => {
187+
on_primary_paste_switch_changed (primary_paste_switch);
188+
});
189+
190+
var current_x_value = false;
191+
if (xsettings != null) {
192+
var value = xsettings.get_value ("overrides").lookup_value ("Gtk/EnablePrimaryPaste", VariantType.INT32);
193+
if (value != null) {
194+
current_x_value = value.get_int32 () == 1;
190195
}
191196
}
192197

198+
var current_wayland_value = interface_settings.get_boolean ("gtk-enable-primary-paste");
199+
primary_paste_switch.active = current_wayland_value || current_x_value;
200+
193201
var a11y_mouse_settings = new GLib.Settings ("org.gnome.desktop.a11y.mouse");
194202
a11y_mouse_settings.bind (
195203
"secondary-click-enabled",
@@ -244,12 +252,16 @@ public class MouseTouchpad.ClickingView : Switchboard.SettingsPage {
244252
});
245253
}
246254

247-
private void on_primary_paste_switch_changed (Gtk.Switch switch, GLib.Settings xsettings) {
248-
var overrides = xsettings.get_value ("overrides");
249-
var dict = new VariantDict (overrides);
250-
dict.insert_value ("Gtk/EnablePrimaryPaste", new Variant.int32 (switch.active ? 1 : 0));
255+
private void on_primary_paste_switch_changed (Gtk.Switch switch) {
256+
if (xsettings != null) {
257+
var overrides = xsettings.get_value ("overrides");
258+
var dict = new VariantDict (overrides);
259+
dict.insert_value ("Gtk/EnablePrimaryPaste", new Variant.int32 (switch.active ? 1 : 0));
260+
261+
overrides = dict.end ();
262+
xsettings.set_value ("overrides", overrides);
263+
}
251264

252-
overrides = dict.end ();
253-
xsettings.set_value ("overrides", overrides);
265+
interface_settings.set_boolean ("gtk-enable-primary-paste", switch.active);
254266
}
255267
}

0 commit comments

Comments
 (0)