diff --git a/flake.lock b/flake.lock index f7634dc2..e72c998d 100644 Binary files a/flake.lock and b/flake.lock differ diff --git a/flake.nix b/flake.nix index 1d9edbe4..3bc8e042 100644 Binary files a/flake.nix and b/flake.nix differ diff --git a/inputs/default.nix b/inputs/default.nix index ea723e08..20e25164 100644 --- a/inputs/default.nix +++ b/inputs/default.nix @@ -169,6 +169,11 @@ let owner = "Cu3PO42"; repo = "gtk-session-lock"; }; + + virtualkeyboard-adapter = mkDep { + owner = "horriblename"; + repo = "fcitx-virtualkeyboard-adapter"; + }; }; }; diff --git a/nixosModules/ags/config/configurations/wim.ts b/nixosModules/ags/config/configurations/wim.ts index b7b44f56..e3041366 100644 --- a/nixosModules/ags/config/configurations/wim.ts +++ b/nixosModules/ags/config/configurations/wim.ts @@ -21,6 +21,7 @@ import Screenshot from '../widgets/screenshot/main'; import { closeAll, perMonitor } from '../lib'; import Brightness from '../services/brightness'; import MonitorClicks from '../services/monitor-clicks'; +import Tablet from '../services/tablet'; export default () => { @@ -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'" + ''; + } ); }; };