Skip to content

Commit

Permalink
On Screen Keyboard preferences (#28)
Browse files Browse the repository at this point in the history
* Added preferences for OSK

* #15 Functional setting of osk based on orientation
  • Loading branch information
shyzus authored Apr 19, 2024
1 parent c7d95ab commit 462ad5b
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 6 deletions.
39 changes: 34 additions & 5 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import { Extension, gettext as _ } from 'resource:///org/gnome/shell/extensions/extension.js';
import { QuickMenuToggle, QuickSettingsMenu, SystemIndicator } from 'resource:///org/gnome/shell/ui/quickSettings.js';

import Gio from 'gi://Gio';
import GObject from 'gi://GObject';
Expand All @@ -25,11 +26,12 @@ import * as SystemActions from 'resource:///org/gnome/shell/misc/systemActions.j
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as Rotator from './rotator.js'
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
import * as KeyboardUI from 'resource:///org/gnome/shell/ui/keyboard.js';

const ORIENTATION_LOCK_SCHEMA = 'org.gnome.settings-daemon.peripherals.touchscreen';
const ORIENTATION_LOCK_KEY = 'orientation-lock';

import { QuickMenuToggle, QuickSettingsMenu, SystemIndicator } from 'resource:///org/gnome/shell/ui/quickSettings.js';
const A11Y_APPLICATIONS_SCHEMA = 'org.gnome.desktop.a11y.applications';
const SHOW_KEYBOARD = 'screen-keyboard-enabled';

// Orientation names must match those provided by net.hadess.SensorProxy
const Orientation = Object.freeze({
Expand Down Expand Up @@ -197,6 +199,7 @@ class ScreenAutorotate {
this._settings = settings;
this._system_actions_backup = null;
this._override_system_actions();
this._a11yApplicationsSettings = new Gio.Settings({schema_id: A11Y_APPLICATIONS_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 @@ -238,6 +241,7 @@ class ScreenAutorotate {
destroy() {
this._sensor_proxy.destroy();
this._orientation_settings = null;
this._a11yApplicationsSettings = null;
this._restore_system_actions();
}

Expand All @@ -249,15 +253,39 @@ class ScreenAutorotate {
}
}
enable() {
this._originala11yKeyboardSetting = this._a11yApplicationsSettings.get_boolean(SHOW_KEYBOARD);
this._sensor_proxy.enable();
this._state = true;
}

disable() {
this._a11yApplicationsSettings.set_boolean(SHOW_KEYBOARD, this._originala11yKeyboardSetting);
this._originala11yKeyboardSetting = null;
this._sensor_proxy.disable();
this._state = false;
}

_handle_osk(target) {
const landscapeOsk = this._settings.get_boolean('landscape-osk');
const portraitRightOsk = this._settings.get_boolean('portrait-right-osk');
const portraitLeftOsk = this._settings.get_boolean('portrait-left-osk');
const landscapeFlippedOsk = this._settings.get_boolean('landscape-flipped-osk');
switch (target) {
case 0:
this._a11yApplicationsSettings.set_boolean(SHOW_KEYBOARD, landscapeOsk);
break;
case 1:
this._a11yApplicationsSettings.set_boolean(SHOW_KEYBOARD, portraitLeftOsk);
break;
case 2:
this._a11yApplicationsSettings.set_boolean(SHOW_KEYBOARD, landscapeFlippedOsk);
break;
case 3:
this._a11yApplicationsSettings.set_boolean(SHOW_KEYBOARD, portraitRightOsk);
break;
}
}

rotate_to(orientation) {
const sensor = Orientation[orientation];
const invert_horizontal_direction = this._settings.get_boolean('invert-horizontal-rotation-direction');
Expand Down Expand Up @@ -294,11 +322,12 @@ class ScreenAutorotate {

target = (target + offset) % 4;
if (this._settings.get_boolean('debug-logging')) {
console.debug(`sensor=${Orientation[orientation]}`);
console.debug(`offset=${offset}`);
console.debug(`target=${target}`);
console.log(`sensor=${Orientation[orientation]}`);
console.log(`offset=${offset}`);
console.log(`target=${target}`);
}
Rotator.rotate_to(target);
this._handle_osk(target);
}
}

Expand Down
68 changes: 68 additions & 0 deletions [email protected]/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export default class MyExtensionPreferences extends ExtensionPreferences {
shellMenuGroup.set_title('GNOME Shell Menu Settings');
page.add(shellMenuGroup);

const oskSettingsGroup = new Adw.PreferencesGroup();
oskSettingsGroup.set_title('On-Screen-Keyboard Settings');
page.add(oskSettingsGroup);

const debugGroup = new Adw.PreferencesGroup();
debugGroup.set_title('Debug Settings');
page.add(debugGroup);
Expand Down Expand Up @@ -77,6 +81,26 @@ export default class MyExtensionPreferences extends ExtensionPreferences {
});
shellMenuGroup.add(hideLockRotateRow);

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

const portraitRightOskRow = new Adw.ActionRow({
title: 'Show OSK in portrait (right) orientation'
});
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 toggleLoggingRow = new Adw.ActionRow({
title: 'Enable debug logging',
subtitle: 'Use "journalctl /usr/bin/gnome-shell -f" to see log output.'
Expand Down Expand Up @@ -111,6 +135,26 @@ export default class MyExtensionPreferences extends ExtensionPreferences {
valign: Gtk.Align.CENTER,
});

const landscapeOskCheckButton = new Gtk.CheckButton({
active: window._settings.get_boolean('landscape-osk'),
valign: Gtk.Align.CENTER
});

const portraitRightOskCheckButton = new Gtk.CheckButton({
active: window._settings.get_boolean('portrait-right-osk'),
valign: Gtk.Align.CENTER
});

const portraitLeftOskCheckButton = new Gtk.CheckButton({
active: window._settings.get_boolean('portrait-left-osk'),
valign: Gtk.Align.CENTER
});

const landscapeFlippedOskCheckButton = new Gtk.CheckButton({
active: window._settings.get_boolean('landscape-flipped-osk'),
valign: Gtk.Align.CENTER
});

const toggleLoggingSwitch = new Gtk.Switch({
active: window._settings.get_boolean('debug-logging'),
valign: Gtk.Align.CENTER
Expand All @@ -134,6 +178,18 @@ export default class MyExtensionPreferences extends ExtensionPreferences {
window._settings.bind('hide-lock-rotate',
hideLockRotateSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);

window._settings.bind('landscape-osk',
landscapeOskCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);

window._settings.bind('portrait-right-osk',
portraitRightOskCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);

window._settings.bind('portrait-left-osk',
portraitLeftOskCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);

window._settings.bind('landscape-flipped-osk',
landscapeFlippedOskCheckButton, 'active', Gio.SettingsBindFlags.DEFAULT);

window._settings.bind('debug-logging',
toggleLoggingSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);

Expand All @@ -155,6 +211,18 @@ export default class MyExtensionPreferences extends ExtensionPreferences {
hideLockRotateRow.add_suffix(hideLockRotateSwitch);
hideLockRotateRow.activatable_widget = hideLockRotateSwitch;

landscapeOskRow.add_suffix(landscapeOskCheckButton);
landscapeOskRow.activatable_widget = landscapeOskCheckButton;

portraitRightOskRow.add_suffix(portraitRightOskCheckButton);
portraitRightOskRow.activatable_widget = portraitRightOskCheckButton;

portraitLeftOskRow.add_suffix(portraitLeftOskCheckButton);
portraitLeftOskRow.activatable_widget = portraitLeftOskCheckButton;

landscapeFlippedOskRow.add_suffix(landscapeFlippedOskCheckButton);
landscapeFlippedOskRow.activatable_widget = landscapeFlippedOskCheckButton;

toggleLoggingRow.add_suffix(toggleLoggingSwitch);
toggleLoggingRow.activatable_widget = toggleLoggingSwitch;
}
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 @@ -40,10 +40,27 @@
<key type="b" name="manual-flip">
<default>false</default>
<description>Enable a toggle in the GNOME Shell System Menu to manually flip between landscape and portrait.</description>
</key><key type="b" name="hide-lock-rotate">
</key>
<key type="b" name="hide-lock-rotate">
<default>false</default>
<description>Hide the 'Auto Rotate' quick toggle.</description>
</key>
<key type="b" name="landscape-osk">
<default>false</default>
<description>Enable the use of the On-Screen-Keyboard for the landscape orientation.</description>
</key>
<key type="b" name="portrait-right-osk">
<default>false</default>
<description>Enable the use of the On-Screen-Keyboard for the portrait (right) orientation.</description>
</key>
<key type="b" name="portrait-left-osk">
<default>false</default>
<description>Enable the use of the On-Screen-Keyboard for the portrait (left) orientation.</description>
</key>
<key type="b" name="landscape-flipped-osk">
<default>false</default>
<description>Enable the use of the On-Screen-Keyboard for the landscape (flipped) orientation.</description>
</key>
<key type="b" name="debug-logging">
<default>false</default>
<description>Toggle debug logging.</description>
Expand Down

0 comments on commit 462ad5b

Please sign in to comment.