Skip to content

Commit

Permalink
31 feature request touchpad toggle (#37)
Browse files Browse the repository at this point in the history
* #31 Untested disable on rotate touchpad feature.

* Update README.md

Added sponsors section

* Create sponsors.yml

Add sponsors action to automatically add name/icon of sponsors

* Deploying to main from @ f79faa5 🚀

* Update README.md

Fix layout of sponsors tag

* Deploying to main from @ 5f730ea 🚀

* Update prefs.js

Adjust order to be consistent with Orientation constant

* Update sponsors.yml

Add active-only=false option should show one time sponsorships and previous sponorships

---------

Co-authored-by: shyzus <[email protected]>
  • Loading branch information
shyzus and shyzus authored Aug 22, 2024
1 parent 702531f commit 21402a6
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 6 deletions.
50 changes: 49 additions & 1 deletion [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const ORIENTATION_LOCK_SCHEMA = 'org.gnome.settings-daemon.peripherals.touchscre
const ORIENTATION_LOCK_KEY = 'orientation-lock';
const A11Y_APPLICATIONS_SCHEMA = 'org.gnome.desktop.a11y.applications';
const SHOW_KEYBOARD = 'screen-keyboard-enabled';
const PERIPHERAL_TOUCHPAD_SCHEMA = 'org.gnome.desktop.peripherals.touchpad';
const TOUCHPAD_EVENTS = 'send-events';

export default class ScreenAutoRotateExtension extends Extension {
enable() {
Expand All @@ -38,7 +40,8 @@ export default class ScreenAutoRotateExtension extends Extension {
this._system_actions_backup = null;
this._override_system_actions();

this._a11yApplicationsSettings = new Gio.Settings({schema_id: A11Y_APPLICATIONS_SCHEMA});
this._a11yApplicationsSettings = new Gio.Settings({ schema_id: A11Y_APPLICATIONS_SCHEMA });
this._peripheralTouchpadSettings = new Gio.Settings({ schema_id: PERIPHERAL_TOUCHPAD_SCHEMA });
this._orientation_settings = new Gio.Settings({ schema_id: ORIENTATION_LOCK_SCHEMA });
this._orientation_settings.connect('changed::' + ORIENTATION_LOCK_KEY, this._orientation_lock_changed.bind(this));

Expand Down Expand Up @@ -165,6 +168,50 @@ export default class ScreenAutoRotateExtension extends Extension {
}
}

_handle_dor_touchpad(target) {
const dorLandscape = this._settings.get_boolean('dor-touchpad-landscape');
const dorPortraitRight = this._settings.get_boolean('dor-touchpad-portrait-right');
const dorPortraitLeft = this._settings.get_boolean('dor-touchpad-portrait-left');
const dorLandscapeFlipped = this._settings.get_boolean('dor-touchpad-landscape-flipped');

let setting_value = undefined;

switch (target) {
case 0:
if (dorLandscape) {
setting_value = "disabled";
} else {
setting_value = "enabled";
}
this._peripheralTouchpadSettings.set_string(TOUCHPAD_EVENTS, setting_value);
break;
case 1:
if (dorPortraitLeft) {
setting_value = "disabled";
} else {
setting_value = "enabled";
}
this._peripheralTouchpadSettings.set_string(TOUCHPAD_EVENTS, setting_value);
break;
case 2:
if (dorLandscapeFlipped) {
setting_value = "disabled";
} else {
setting_value = "enabled";
}
this._peripheralTouchpadSettings.set_string(TOUCHPAD_EVENTS, setting_value);
break;
case 3:
if (dorPortraitRight) {
setting_value = "disabled";
} else {
setting_value = "enabled";
}
this._peripheralTouchpadSettings.set_string(TOUCHPAD_EVENTS, setting_value);
break;
}
}

rotate_to(orientation) {
const sensor = Orientation[orientation];
const invert_horizontal_direction = this._settings.get_boolean('invert-horizontal-rotation-direction');
Expand Down Expand Up @@ -207,6 +254,7 @@ export default class ScreenAutoRotateExtension extends Extension {
}
Rotator.rotate_to(target);
this._handle_osk(target);
this._handle_dor_touchpad(target);
}

disable() {
Expand Down
115 changes: 110 additions & 5 deletions [email protected]/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import Adw from 'gi://Adw';

import { ExtensionPreferences } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';

import { Orientation } from './orientation.js';

export default class MyExtensionPreferences extends ExtensionPreferences {

fillPreferencesWindow(window) {
Expand All @@ -41,6 +43,10 @@ export default class MyExtensionPreferences extends ExtensionPreferences {
oskSettingsGroup.set_title('On-Screen-Keyboard Settings');
page.add(oskSettingsGroup);

const disableOnRotateGroup = new Adw.PreferencesGroup();
disableOnRotateGroup.set_title('Disable-On-Rotation Settings');
page.add(disableOnRotateGroup);

const debugGroup = new Adw.PreferencesGroup();
debugGroup.set_title('Debug Settings');
page.add(debugGroup);
Expand Down Expand Up @@ -92,16 +98,16 @@ export default class MyExtensionPreferences extends ExtensionPreferences {
});
oskSettingsGroup.add(portraitRightOskRow);

const portraitLeftOskRow = new Adw.ActionRow({
title: 'Show OSK in portrait (left) orientation'
});
oskSettingsGroup.add(portraitLeftOskRow);

const landscapeFlippedOskRow = new Adw.ActionRow({
title: 'Show OSK in landscape (flipped) orientation'
});
oskSettingsGroup.add(landscapeFlippedOskRow);

const portraitLeftOskRow = new Adw.ActionRow({
title: 'Show OSK in portrait (left) orientation'
});
oskSettingsGroup.add(portraitLeftOskRow);

const toggleLoggingRow = new Adw.ActionRow({
title: 'Enable debug logging',
subtitle: 'Use "journalctl /usr/bin/gnome-shell -f" to see log output.'
Expand Down Expand Up @@ -156,6 +162,105 @@ export default class MyExtensionPreferences extends ExtensionPreferences {
valign: Gtk.Align.CENTER
});

const dorNotebook = new Gtk.Notebook();

const dorKeyboardPage = new Gtk.ListBox();
dorKeyboardPage.set_visible(false); // Keep hidden until feature can be implemented.
dorKeyboardPage.set_selection_mode(Gtk.SelectionMode.NONE);

for (let orientation in Orientation) {
let actionRowTitle = undefined;
let checkButtonBoolId = undefined;

switch (orientation) {
case 'normal':
actionRowTitle = "Landscape";
checkButtonBoolId = "dor-keyboard-landscape";
break;
case 'left-up':
actionRowTitle = "Portrait (Left)";
checkButtonBoolId = "dor-keyboard-portrait-left";
break;
case 'bottom-up':
actionRowTitle = "Landscape Flipped";
checkButtonBoolId = "dor-keyboard-landscape-flipped";
break;
case 'right-up':
actionRowTitle = "Portrait (Right)";
checkButtonBoolId = "dor-keyboard-portrait-right";
break;
}

const dorActionRow = new Adw.ActionRow({
title: actionRowTitle
});

const dorCheckButton = new Gtk.CheckButton({
active: window._settings.get_boolean(checkButtonBoolId),
valign: Gtk.Align.CENTER
});

window._settings.bind(checkButtonBoolId,
dorCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);

dorActionRow.add_suffix(dorCheckButton);
dorActionRow.activatable_widget = dorCheckButton;

dorKeyboardPage.append(dorActionRow);
}

const dorTouchpadPage = new Gtk.ListBox();
dorTouchpadPage.set_selection_mode(Gtk.SelectionMode.NONE);

for (let orientation in Orientation) {
let actionRowTitle = undefined;
let checkButtonBoolId = undefined;

switch (orientation) {
case 'normal':
actionRowTitle = "Landscape";
checkButtonBoolId = "dor-touchpad-landscape";
break;
case 'left-up':
actionRowTitle = "Portrait (Left)";
checkButtonBoolId = "dor-touchpad-portrait-left";
break;
case 'bottom-up':
actionRowTitle = "Landscape Flipped";
checkButtonBoolId = "dor-touchpad-landscape-flipped";
break;
case 'right-up':
actionRowTitle = "Portrait (Right)";
checkButtonBoolId = "dor-touchpad-portrait-right";
break;
}

const dorActionRow = new Adw.ActionRow({
title: actionRowTitle
});

const dorCheckButton = new Gtk.CheckButton({
active: window._settings.get_boolean(checkButtonBoolId),
valign: Gtk.Align.CENTER
});

window._settings.bind(checkButtonBoolId,
dorCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);

dorActionRow.add_suffix(dorCheckButton);
dorActionRow.activatable_widget = dorCheckButton;

dorTouchpadPage.append(dorActionRow);
}

const dorKeyboardLabel = Gtk.Label.new('Keyboard');
dorNotebook.append_page(dorKeyboardPage, dorKeyboardLabel);

const dorTouchpadLabel = Gtk.Label.new('Touchpad');
dorNotebook.append_page(dorTouchpadPage, dorTouchpadLabel)

disableOnRotateGroup.add(dorNotebook);

const toggleLoggingSwitch = new Gtk.Switch({
active: window._settings.get_boolean('debug-logging'),
valign: Gtk.Align.CENTER
Expand Down
Binary file modified [email protected]/schemas/gschemas.compiled
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,38 @@
<default>false</default>
<description>Enable the use of the On-Screen-Keyboard for the landscape (flipped) orientation.</description>
</key>
<key type="b" name="dor-keyboard-landscape">
<default>false</default>
<description>Toggle disabling the keyboard when the orientation is landscape.</description>
</key>
<key type="b" name="dor-keyboard-portrait-left">
<default>false</default>
<description>Toggle disabling the keyboard when the orientation is portrait left.</description>
</key>
<key type="b" name="dor-keyboard-landscape-flipped">
<default>false</default>
<description>Toggle disabling the keyboard when the orientation is landscape-flipped.</description>
</key>
<key type="b" name="dor-keyboard-portrait-right">
<default>false</default>
<description>Toggle disabling the keyboard when the orientation is portrait right.</description>
</key>
<key type="b" name="dor-touchpad-landscape">
<default>false</default>
<description>Toggle disabling the touchpad when the orientation is landscape.</description>
</key>
<key type="b" name="dor-touchpad-portrait-left">
<default>false</default>
<description>Toggle disabling the touchpad when the orientation is portrait left.</description>
</key>
<key type="b" name="dor-touchpad-landscape-flipped">
<default>false</default>
<description>Toggle disabling the touchpad when the orientation is landscape-flipped.</description>
</key>
<key type="b" name="dor-touchpad-portrait-right">
<default>false</default>
<description>Toggle disabling the touchpad when the orientation is portrait right.</description>
</key>
<key type="b" name="debug-logging">
<default>false</default>
<description>Toggle debug logging.</description>
Expand Down

0 comments on commit 21402a6

Please sign in to comment.