Skip to content

Commit

Permalink
Added feature to set kbdlight_timeout to 1s when in fullscreen mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
egormanga committed Oct 24, 2022
1 parent 51223f0 commit 2d83cae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const _ = Gettext.gettext;

const ByteArray = imports.byteArray;

const Display = global.display;

const BPM_PROFILES = {
"Home": [40, 70],
"Work": [70, 90],
Expand Down Expand Up @@ -75,6 +77,8 @@ class HuaweiWmiIndicator extends PanelMenu.Button { // TODO: move to system batt
if (this._bpm.sensitive) this._bpm.activate();
});

this._fullscreen_changed_s = Display.connect('in-fullscreen-changed', this._fullscreen_changed.bind(this));

this._fn_led_timeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT_IDLE, 1000, () => this._update_fn_led() || true);

this._bind_keys();
Expand All @@ -84,6 +88,7 @@ class HuaweiWmiIndicator extends PanelMenu.Button { // TODO: move to system batt

_destroy() {
this._unbind_keys();
if (this._fullscreen_changed_s !== null) Display.disconnect(this._fullscreen_changed_s);
if (this._fn_led_timeout !== null) GLib.timeout_remove(this._fn_led_timeout);
}

Expand All @@ -99,6 +104,23 @@ class HuaweiWmiIndicator extends PanelMenu.Button { // TODO: move to system batt
Main.wm.removeKeybinding('hwmi-power-unlock');
}

_fullscreen_changed() {
let file = Gio.File.new_for_path("/sys/devices/platform/huawei-wmi/kbdlight_timeout");

try {
if (Main.layoutManager.primaryMonitor.inFullscreen) {
this._fullscreen_changed_timeout = Number(ByteArray.toString(file.load_contents(null)[1]));
file.replace_contents("1", null, false, 0, null);
} else {
file.replace_contents(`${this._fullscreen_changed_timeout || 300}`, null, false, 0, null);
}
} catch (e) {
Display.disconnect(this._fullscreen_changed_s);
this._fullscreen_changed_s = null;
return;
}
}

_key_power_unlock() {
let icon, text;

Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"uuid": "huawei-wmi@apps.sdore.me",
"name": "Huawei WMI controls",
"description": "Control various Huawei and Honor laptops WMI functions, such as battery protection, Fn-lock, power unlock and keyboard backlight.",
"version": 6,
"version": 8,
"shell-version": ["40", "41", "42"],
"url": "https://apps.sdore.me/gnome-extension-huawei-wmi"
}

0 comments on commit 2d83cae

Please sign in to comment.