From ce6d31e658911dddba58499bc4cab6267804b800 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Sat, 14 Dec 2024 19:36:54 -0500 Subject: [PATCH] feat(ags osk): add input detection --- flake.lock | Bin 55624 -> 56242 bytes flake.nix | Bin 11402 -> 11582 bytes inputs/default.nix | 5 ++ nixosModules/ags/config/configurations/wim.ts | 37 ++++++++++++++ nixosModules/ags/config/services/tablet.ts | 47 ++++++++++++++++-- .../ags/config/widgets/bar/_index.scss | 3 +- nixosModules/ags/config/widgets/bar/wim.tsx | 21 +++++++- nixosModules/ags/default.nix | 15 ++++++ nixosModules/ags/hyprland.nix | 3 +- nixosModules/ags/packages.nix | 32 +++++++----- 10 files changed, 141 insertions(+), 22 deletions(-) diff --git a/flake.lock b/flake.lock index f7634dc2f42281e15880c8df54b53a37d01f62c9..e72c998dcc09f8d84864787f0014ea731777b8fa 100644 GIT binary patch delta 276 zcmX@HiFwm@<_*nTjLI^LN=g%RvQsOQ@)L_vbQ4n&3rbRpl&ln#a7b+~-(n#vjzerW28Muao zmxL7*IJr7bei$r1dA^gpY+7<=Nrf&B8zz1f)-X0rF)*}9vM@GCOinUPNwhRJu`o7G pHZe9dGB-|2H8wR$Gcz|xN}hZ%!UtrcG#(Qt9}F?ty#C@$b^ygrX7~UA delta 19 bcmdnAo%zHj<_*nTHXq!gBfDAh%1m|uWg`iK diff --git a/flake.nix b/flake.nix index 1d9edbe447ed8e7ad1dfee2cea4215bfdf6daca7..3bc8e042661eac0d7da98def37979ea5b1d8f0a0 100644 GIT binary patch delta 74 zcmeB*+!wXMP+PPtv#6vrF(*5 { @@ -48,6 +49,42 @@ export default () => { popup_osd(request.replace('popup ', '')); respond('osd popped up'); } + + else if (request.startsWith('show-osk')) { + const tablet = Tablet.get_default(); + + if (tablet.currentMode === 'tablet') { + if (tablet.oskState) { + respond('osk state was unchanged'); + } + else { + tablet.oskState = true; + tablet.oskAutoChanged = true; + respond('osk was shown'); + } + } + else { + respond('osk state was unchanged'); + } + } + + else if (request.startsWith('hide-osk')) { + const tablet = Tablet.get_default(); + + if (tablet.currentMode === 'tablet') { + if (tablet.oskState && tablet.oskAutoChanged) { + tablet.oskState = false; + tablet.oskAutoChanged = true; + respond('osd was hidden'); + } + else { + respond('osk state was unchanged'); + } + } + else { + respond('osk state was unchanged'); + } + } }, main: () => { diff --git a/nixosModules/ags/config/services/tablet.ts b/nixosModules/ags/config/services/tablet.ts index 350ce60c..01b1f14a 100644 --- a/nixosModules/ags/config/services/tablet.ts +++ b/nixosModules/ags/config/services/tablet.ts @@ -31,7 +31,7 @@ export default class Tablet extends GObject.Object { declare inputsChanged: (blocked: boolean) => void; - private _currentMode = 'laptop'; + private _currentMode: 'laptop' | 'tablet' = 'laptop'; @property(String) get currentMode() { @@ -42,18 +42,19 @@ export default class Tablet extends GObject.Object { this._currentMode = val; if (this._currentMode === 'tablet') { - execAsync(['brightnessctl', '-d', 'tpacpi::kbd_backlight', 's', '0']) - .catch(print); + execAsync(['brightnessctl', '-d', 'tpacpi::kbd_backlight', 's', '0']).catch(print); this.startAutorotate(); this._blockInputs(); + this._startInputDetection(); } else if (this._currentMode === 'laptop') { - execAsync(['brightnessctl', '-d', 'tpacpi::kbd_backlight', 's', '2']) - .catch(print); + execAsync(['brightnessctl', '-d', 'tpacpi::kbd_backlight', 's', '2']).catch(print); this.killAutorotate(); this._unblockInputs(); + this._stopInputDetection(); + this.oskState = false; } this.notify('current-mode'); @@ -69,6 +70,8 @@ export default class Tablet extends GObject.Object { set oskState(val) { this._oskState = val; + // this is set to true after this setter in the request. + this.oskAutoChanged = false; this.notify('osk-state'); } @@ -77,6 +80,40 @@ export default class Tablet extends GObject.Object { } + private _oskAutoChanged = false; + + @property(Boolean) + get oskAutoChanged() { + return this._oskAutoChanged; + } + + set oskAutoChanged(val) { + this._oskAutoChanged = val; + } + + + private _inputDetection = null as AstalIO.Process | null; + + private _startInputDetection() { + if (this._inputDetection) { + return; + } + + this._inputDetection = subprocess([ + 'fcitx5', + '--disable', 'all', + '--enable', 'keyboard,virtualkeyboardadapter,wayland,waylandim', + ]); + } + + private _stopInputDetection() { + if (this._inputDetection) { + this._inputDetection.kill(); + this._inputDetection = null; + } + } + + private _autorotate = null as AstalIO.Process | null; get autorotateState() { diff --git a/nixosModules/ags/config/widgets/bar/_index.scss b/nixosModules/ags/config/widgets/bar/_index.scss index 68f4308f..7bdbcd34 100644 --- a/nixosModules/ags/config/widgets/bar/_index.scss +++ b/nixosModules/ags/config/widgets/bar/_index.scss @@ -19,8 +19,9 @@ background-color: color.adjust(colors.$window_bg_color, $lightness: 3%); } + &.bluetooth icon, &.network icon, - &.bluetooth icon { + &.tablet-mode icon { min-width: 30px; } diff --git a/nixosModules/ags/config/widgets/bar/wim.tsx b/nixosModules/ags/config/widgets/bar/wim.tsx index 869c1759..e6846c0f 100644 --- a/nixosModules/ags/config/widgets/bar/wim.tsx +++ b/nixosModules/ags/config/widgets/bar/wim.tsx @@ -1,3 +1,4 @@ +import { bind } from 'astal'; import { Astal, Gtk } from 'astal/gtk3'; import Audio from './items/audio'; @@ -13,9 +14,9 @@ import Workspaces from './items/workspaces'; import BarRevealer from './fullscreen'; import Separator from '../misc/separator'; +import Tablet from '../../services/tablet'; -// TODO: add Bluetooth export default () => ( ( - {/* */} + + + diff --git a/nixosModules/ags/default.nix b/nixosModules/ags/default.nix index b9ab1750..a636af51 100644 --- a/nixosModules/ags/default.nix +++ b/nixosModules/ags/default.nix @@ -1,8 +1,10 @@ self: { config, lib, + pkgs, ... }: let + inherit (self.inputs) virtualkeyboard-adapter; inherit (lib) hasPrefix mkIf removePrefix; # Configs @@ -50,6 +52,19 @@ in { security.pam.services.astal-auth = {}; services.upower.enable = true; + i18n.inputMethod = mkIf cfgDesktop.isTouchscreen { + enable = true; + type = "fcitx5"; + + fcitx5 = { + waylandFrontend = true; + plasma6Support = true; + addons = [ + virtualkeyboard-adapter.packages.${pkgs.system}.default + ]; + }; + }; + home-manager.users.${cfgDesktop.user}.imports = [ hmOpts (import ./packages.nix self) diff --git a/nixosModules/ags/hyprland.nix b/nixosModules/ags/hyprland.nix index 75fd022b..af2852d9 100644 --- a/nixosModules/ags/hyprland.nix +++ b/nixosModules/ags/hyprland.nix @@ -1,5 +1,4 @@ -self: {lib, ...}: let - inherit (lib) map; +self: {...}: let inherit (self.lib.hypr) mkAnimation mkBezier mkBind mkLayerRule; in { config.wayland.windowManager.hyprland = { diff --git a/nixosModules/ags/packages.nix b/nixosModules/ags/packages.nix index d43e1acd..86031e3d 100644 --- a/nixosModules/ags/packages.nix +++ b/nixosModules/ags/packages.nix @@ -7,12 +7,24 @@ self: { }: let inherit (self.inputs) ags gtk-session-lock; - inherit (lib) attrValues boolToString optionals removeAttrs; + inherit (lib) attrValues boolToString getExe optionalAttrs optionals removeAttrs; inherit (osConfig.networking) hostName; cfg = config.programs.ags; cfgDesktop = osConfig.roles.desktop; + + mainPkg = pkgs.writeShellApplication { + name = "ags"; + runtimeInputs = [cfg.package]; + text = '' + if [ "$#" == 0 ]; then + exec ags run ~/${cfg.configDir} -a ${hostName} + else + exec ags "$@" + fi + ''; + }; in { config = { # Make these accessible outside these files @@ -50,17 +62,7 @@ in { home = { packages = [ - (pkgs.writeShellApplication { - name = "ags"; - runtimeInputs = [cfg.package]; - text = '' - if [ "$#" == 0 ]; then - exec ags run ~/${cfg.configDir} -a ${hostName} - else - exec ags "$@" - fi - ''; - }) + mainPkg (pkgs.writeShellApplication { name = "agsConf"; runtimeInputs = [cfg.package]; @@ -131,6 +133,12 @@ in { }; ''; } + // optionalAttrs cfgDesktop.isTouchscreen { + ".config/fcitx5/conf/virtualkeyboardadapter.conf".text = '' + ActivateCmd="${getExe mainPkg} request 'show-osk'" + DeactivateCmd="${getExe mainPkg} request 'hide-osk'" + ''; + } ); }; };