import { execAsync, Variable } from 'astal'; import { Gdk, Gtk, Widget } from 'astal/gtk3'; import Brightness from '../../services/brightness'; import Separator from '../misc/separator'; /* Types */ interface Key { keytype: string label: string labelShift?: string labelAltGr?: string shape: string keycode: number } const display = Gdk.Display.get_default(); const brightness = Brightness.get_default(); const SPACING = 4; const LSHIFT_CODE = 42; const LALT_CODE = 56; const LCTRL_CODE = 29; // Keep track of when a non modifier key // is clicked to release all modifiers const NormalClick = Variable(false); // Keep track of modifier statuses const Super = Variable(false); const LAlt = Variable(false); const LCtrl = Variable(false); const AltGr = Variable(false); const RCtrl = Variable(false); const Caps = Variable(false); brightness.connect('notify::caps-level', (_, state) => { Caps.set(state); }); // Assume both shifts are the same for key.labelShift const LShift = Variable(false); const RShift = Variable(false); const Shift = Variable(false); LShift.subscribe(() => { Shift.set(LShift.get() || RShift.get()); }); RShift.subscribe(() => { Shift.set(LShift.get() || RShift.get()); }); const ModKey = (key: Key) => { let Mod: Variable; if (key.label === 'Super') { Mod = Super; } // Differentiate left and right mods else if (key.label === 'Shift' && key.keycode === LSHIFT_CODE) { Mod = LShift; } else if (key.label === 'Alt' && key.keycode === LALT_CODE) { Mod = LAlt; } else if (key.label === 'Ctrl' && key.keycode === LCTRL_CODE) { Mod = LCtrl; } else if (key.label === 'Shift') { Mod = RShift; } else if (key.label === 'AltGr') { Mod = AltGr; } else if (key.label === 'Ctrl') { Mod = RCtrl; } const label = (