Skip to content

Commit

Permalink
#31 Untested disable on rotate touchpad feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
shyzus committed Jun 16, 2024
1 parent 532c7f4 commit 376092f
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 1 deletion.
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
105 changes: 105 additions & 0 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 @@ -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 376092f

Please sign in to comment.