1#!/usr/local/bin/python3.8
2
3import gi
4gi.require_version("Gtk", "3.0")
5from gi.repository import Gtk, Gdk, GLib
6
7from SettingsWidgets import SidePage
8from xapp.GSettingsWidgets import *
9
10
11class Module:
12    comment = _("Control mouse and touchpad settings")
13    name = "mouse"
14    category = "hardware"
15
16    def __init__(self, content_box):
17        keywords = _("mouse, touchpad, synaptic, double-click")
18        sidePage = SidePage(_("Mouse and Touchpad"), "cs-mouse", keywords, content_box, module=self)
19        self.sidePage = sidePage
20
21    def on_module_selected(self):
22        if not self.loaded:
23            print("Loading Mouse module")
24
25            self.sidePage.stack = SettingsStack()
26            self.sidePage.add_widget(self.sidePage.stack)
27
28            # Mouse
29
30            page = SettingsPage()
31
32            settings = page.add_section(_("General"))
33
34            switch = GSettingsSwitch(_("Left handed (mouse buttons inverted)"), "org.cinnamon.settings-daemon.peripherals.mouse", "left-handed")
35            settings.add_row(switch)
36
37            switch = GSettingsSwitch(_("Reverse scrolling direction"), "org.cinnamon.settings-daemon.peripherals.mouse", "natural-scroll")
38            settings.add_row(switch)
39
40            switch = GSettingsSwitch(_("Show position of pointer when the Control key is pressed"), "org.cinnamon.settings-daemon.peripherals.mouse", "locate-pointer")
41            settings.add_row(switch)
42
43            switch = GSettingsSwitch(_("Emulate middle click by clicking both left and right buttons"), "org.cinnamon.settings-daemon.peripherals.mouse", "middle-button-enabled")
44            settings.add_row(switch)
45
46            spin = GSettingsSpinButton(_("Drag-and-drop threshold"), "org.cinnamon.settings-daemon.peripherals.mouse", "drag-threshold", _("pixels"), 1, 400)
47            settings.add_row(spin)
48
49            settings = page.add_section(_("Pointer size and speed"))
50
51            widget = GSettingsRange(_("Size"), "org.cinnamon.desktop.interface", "cursor-size", _("Smaller"), _("Larger"), 5, 50, show_value=False)
52            widget.add_mark(24.0, Gtk.PositionType.TOP, None)
53            settings.add_row(widget)
54
55            widget = GSettingsSwitch(_("Custom Acceleration"), "org.cinnamon.settings-daemon.peripherals.mouse", "custom-acceleration")
56            settings.add_row(widget)
57
58            slider = GSettingsRange(_("Acceleration"), "org.cinnamon.settings-daemon.peripherals.mouse", "motion-acceleration", _("Slow"), _("Fast"), 1, 10, show_value=False)
59            settings.add_reveal_row(slider, "org.cinnamon.settings-daemon.peripherals.mouse", "custom-acceleration")
60
61            widget = GSettingsSwitch(_("Custom Sensitivity"), "org.cinnamon.settings-daemon.peripherals.mouse", "custom-threshold")
62            settings.add_row(widget)
63
64            slider = GSettingsRange(_("Sensitivity"), "org.cinnamon.settings-daemon.peripherals.mouse", "motion-threshold", _("Low"), _("High"), 1, 10, show_value=False, flipped=True)
65            settings.add_reveal_row(slider, "org.cinnamon.settings-daemon.peripherals.mouse", "custom-threshold")
66
67            settings = page.add_section(_("Double-Click timeout"))
68
69            slider = GSettingsRange(_("Timeout"), "org.cinnamon.settings-daemon.peripherals.mouse", "double-click", _("Short"), _("Long"), 100, 1000, show_value=False)
70            settings.add_row(slider)
71
72            box = SettingsWidget()
73            widget = Gtk.Button.new_with_label(_("Double-click test"))
74            widget.connect("button-press-event", self.test_button_clicked)
75            box.pack_start(widget, True, True, 0)
76            settings.add_row(box)
77
78            self.sidePage.stack.add_titled(page, "mouse", _("Mouse"))
79
80            # Touchpad
81
82            page = SettingsPage()
83
84            switch = GSettingsSwitch("", "org.cinnamon.settings-daemon.peripherals.touchpad", "touchpad-enabled")
85            switch.label.set_markup("<b>%s</b>" % _("Enable touchpad"))
86            switch.fill_row()
87            page.pack_start(switch, False, True, 0)
88
89            revealer = SettingsRevealer("org.cinnamon.settings-daemon.peripherals.touchpad", "touchpad-enabled")
90            page.pack_start(revealer, False, True, 0)
91
92            settings = SettingsSection(_("General"))
93            revealer.add(settings)
94
95            switch = GSettingsSwitch(_("Tap to click"), "org.cinnamon.settings-daemon.peripherals.touchpad", "tap-to-click")
96            settings.add_row(switch)
97
98            switch = GSettingsSwitch(_("Disable touchpad when a mouse is attached"), "org.cinnamon.settings-daemon.peripherals.touchpad", "disable-with-external-mouse")
99            settings.add_row(switch)
100
101            switch = GSettingsSwitch(_("Disable touchpad while typing"), "org.cinnamon.settings-daemon.peripherals.touchpad", "disable-while-typing")
102            settings.add_row(switch)
103
104            clickpad_list = [[0, _("Left click only")], [3, _("Automatic")], [1, _("Emulate mouse buttons")], [2, _("Use multiple fingers for right and middle click")]]
105
106            combo = GSettingsComboBox(_("Click actions"), "org.cinnamon.settings-daemon.peripherals.touchpad", "clickpad-click", clickpad_list, valtype=int)
107            settings.add_row(combo)
108
109            settings = SettingsSection(_("Scrolling"))
110            revealer.add(settings)
111
112            switch = GSettingsSwitch(_("Reverse scrolling direction"), "org.cinnamon.settings-daemon.peripherals.touchpad", "natural-scroll")
113            settings.add_row(switch)
114
115            clickpad_list = [[0, _("No scrolling")], [3, _("Automatic")], [1, _("Two-finger scrolling")], [2, _("Edge scrolling")]]
116            combo = GSettingsComboBox(_("Scrolling method"), "org.cinnamon.settings-daemon.peripherals.touchpad", "scrolling-method", clickpad_list, valtype=int)
117            settings.add_row(combo)
118            switch = GSettingsSwitch(_("Horizontal scrolling"), "org.cinnamon.settings-daemon.peripherals.touchpad", "horizontal-scrolling")
119            settings.add_row(switch)
120
121            settings = SettingsSection(_("Pointer speed"))
122            revealer.add(settings)
123
124            switch = GSettingsSwitch(_("Custom Acceleration"), "org.cinnamon.settings-daemon.peripherals.touchpad", "custom-acceleration")
125            settings.add_row(switch)
126
127            slider = GSettingsRange(_("Acceleration"), "org.cinnamon.settings-daemon.peripherals.touchpad", "motion-acceleration", _("Slow"), _("Fast"), 1, 10, show_value=False)
128            settings.add_reveal_row(slider, "org.cinnamon.settings-daemon.peripherals.touchpad", "custom-acceleration")
129
130            switch = GSettingsSwitch(_("Custom Sensitivity"), "org.cinnamon.settings-daemon.peripherals.touchpad", "custom-threshold")
131            settings.add_row(switch)
132
133            slider = GSettingsRange(_("Sensitivity"), "org.cinnamon.settings-daemon.peripherals.touchpad", "motion-threshold", _("Low"), _("High"), 1, 10, show_value=False, flipped=True)
134            settings.add_reveal_row(slider, "org.cinnamon.settings-daemon.peripherals.touchpad", "custom-threshold")
135
136            self.sidePage.stack.add_titled(page, "touchpad", _("Touchpad"))
137
138    def test_button_clicked(self, widget, event):
139        if event.type == Gdk.EventType._2BUTTON_PRESS:
140            widget.set_label(_("Success!"))
141            GLib.timeout_add(1000, self.reset_test_button, widget)
142        return True
143
144    def reset_test_button(self, widget):
145        widget.set_label(_("Double-click test"))
146        return False
147