Sehlophisi sa sebopeho sa Xswitcher bakeng sa Linux: mohato oa bobeli

ho tloha ka phatlalatso e fetileng (xswitcher sethaleng sa "bopaki ba mohopolo") e fumane maikutlo a mangata a hahang (e ntle), Ke ile ka tsoela pele ho qeta nako ea ka ea mahala ke ntšetsa pele morero oo. Joale ke batla ho sebelisa chelete ea hau hanyane... Mohato oa bobeli o ke ke oa tloaeleha: tlhahiso / puisano ea moralo oa tlhophiso.

Sehlophisi sa sebopeho sa Xswitcher bakeng sa Linux: mohato oa bobeli

Ka tsela e itseng hoa fumaneha hore baetsi ba mananeo ba tloaelehileng ba fumana e le ntho e tenang haholo ho theha litsamaiso tsena kaofela.

E le hore ke se ke ka hloka motheo, ka hare ke mohlala oa seo ke sebetsanang le sona.
Ka kakaretso e qapiloe hantle (mme e kentsoe tšebetsong hantle) Apache Kafka & ZooKeeper.
- Tlhophiso? Empa hoa tena! Semumu xml (hobane "e tsoa ka lebokoseng").
- Oh, na le uena u batla ACL? Empa hoa tena! Tap-blooper ... Ntho e kang eo.

Empa mosebetsing oa ka ho hlile ho fapane. Ho lokile (oho, hoo e batlang e se lekhetlo la pele) mohlala o hahiloeng o u lumella ho tsoela pele habonolo le ka tlhaho (Hoo e ka bang) kopanya setšoantšo.

Haufinyane tjena ke fumane sengoloa se buang ka Habré mabapi le mosebetsi o boima oa bo-ramahlale ba data ...
Hoa etsahala hore motsotso ona o phethahala ka ho feletseng bakeng sa bona. 'Me ts'ebetsong ea ka, joalo ka ha ba re, "light version". Mefuta e mengata ea li-volume tse ngata, baetsi ba mananeo a khale ba nang le OOP ba itokisitse, joalo-joalo. — sena sohle se tla hlaha hamorao ha/haeba se tloha. Empa moqapi o hloka ho qala kae-kae mona le hona joale.

Fumana ntlha. Ke nkile TOML e le motheo oa syntactic ho tsoa ho moahi enoa.

Hobane eena (TOML) ka lehlakoreng le leng, e ka fetoleloa ke batho. Ka lehlakoreng le leng, e fetoletsoe 1:1 ho e 'ngoe ea li-syntaxes tse tloaelehileng: XML, JSON, YAML.
Ho feta moo, ts'ebetsong eo ke e sebelisitseng ho tloha "github.com/BurntSushi/toml", le hoja e se feshene ka ho fetisisa (e ntse e le 1.4 syntax), e lumellana ka mokhoa o ts'oanang le JSON ("built-in").

Ka mantsoe a mang, haeba u lakatsa, u ka re feela "tsamaea ka morung ka TOML ea hau, ke batla XXX" 'me u "pake" khoutu ka mola o le mong feela.

Kahoo, haeba u batla ho ngola lifensetere tse ling ho lokisa xswitcher (Ha ke na bonnete) Ha ho na mathata a lebelletsoeng "ka tlhophiso ena e mpe ea hau."

Bakeng sa tse ling kaofela, syntax e thehiloe ho "key = value" (le likhetho tse 'maloa tse rarahaneng, joalo ka = [tse ling, tse, tse ngata]) kea kholoa
intuitively loketseng.
Se khahlisang ke hore "chesitse" ka nako e ts'oanang (ho pota 2013). Feela, ho fapana le nna, sengoli sa TOML se kene ka tekanyo e nepahetseng.

Ka hona, joale ho bonolo ho 'na ho fetola ts'ebetsong ea eona hore e lumellane le' na, eseng ka tsela e fapaneng.

Ka kakaretso, re nka TOML (e ts'oanang haholo le ea khale ea Windows INI). 'Me re na le tlhophiso eo ho eona re hlalosang mokhoa oa ho hokela letoto la li-hook ho latela sete ea likhoutu tsa morao-rao tse tsoang ho keyboard. Ka tlase, sengoathoana ka sengoathoana, ke se etsahetseng ho fihlela joale. Le tlhaloso ea hore na ke hobane'ng ha ke entse qeto ka tsela ena.

0. Lintlha tsa motheo

  • Skena mabitso a khoutu. Ho na le ho hong ho lokelang ho etsoa mabapi le sena, kaha likhoutu tsa dijithale ho hang ha li balehe ke batho (ke 'na feela. loloswitcher).
    Ke ile ka sisinya "ecodes.go" ho "golang-evdev" (ke ne ke le botsoa haholo ho sheba mohloli oa pele, le hoja mongoli a e bontšitse ka setso). Ke ile ka lokisa hanyane (hajoale) ntho e neng e tšosa haholo. Joalo ka "LEFTBRACE" → "L_BRACE".
  • Ho phaella moo, o ile a hlahisa khopolo ea "linotlolo tsa naha". Kaha sebōpeho-puo se tloaelehileng se sebelisoang ha se lumelle litemana tse telele. (Empa e u fa monyetla oa ho sheba ka mokhoa o fokolang. Haeba u sebelisa "rekoto e tobileng" feela.)
  • Ho tla ba le "deduplicator" e hahelletsoeng ka har'a se hatisitsoeng. Kahoo, boemo "pheta" =2 bo tla ngoloa один linako.

1. Karolo ea li-templates

[Templates] # "@name@" to simplify expressions
 # Words can consist of these chars (regex)
 "WORD" = "([0-9A-Z`;']|[LR]_BRACE|COMMA|DOT|SLASH|KP[0-9])"

Lentsoe la puo ea batho le nang le mantsoe a fonotiki le na le eng? (ebang ke taba ea graphemes aka "hieroglyphs")? Mofuta o mong oa "lakane" e tšabehang. Ka hona, hang-hang ke kenyelletsa mohopolo oa "template".

2. Seo u lokelang ho se etsa ha ntho e 'ngoe e tobetse (ho fihlile khoutu e' ngoe ea scan ninete)

[ActionKeys]
 # Collect key and do the test for command sequence
 # !!! Repeat codes (code=2) must be collected once per key!
 Add = ["1..0", "=", "BS", "Q..]", "L_CTRL..CAPS", "N_LOCK", "S_LOCK",
        "KP7..KPDOT", "R_CTRL", "KPSLASH", "R_ALT", "KPEQUAL..PAUSE",
        "KPCOMMA", "L_META..COMPOSE", "KPLEFTPAREN", "KPRIGHTPAREN"]

 # Drop all collected keys, including this.  This is default action.
 Drop = ["ESC", "-", "TAB", "ENTER", "KPENTER", "LINEFEED..POWER"]
 # Store extra map for these keys, when any is in "down" state.
 # State is checked via "OFF:"|"ON:" conditions in action.
 # (Also, state of these keys must persist between buffer drops.)
 # ??? How to deal with CAPS and "LOCK"-keys ???
 StateKeys = ["L_CTRL", "L_SHIFT", "L_ALT", "L_META", "CAPS", "N_LOCK", "S_LOCK",
              "R_CTRL", "R_SHIFT", "R_ALT", "R_META"]

 # Test only, but don't collect.
 # E.g., I use F12 instead of BREAK on dumb laptops whith shitty keyboards (new ThinkPads)
 Test = ["F1..F10", "ZENKAKUHANKAKU", "102ND", "F11", "F12",
          "RO..KPJPCOMMA", "SYSRQ", "SCALE", "HANGEUL..YEN",
          "STOP..SCROLLDOWN", "NEW..MAX"]

Ho na le likhoutu tse 768 ka kakaretso. (Empa "feela ha ho ka etsahala" ke kentse ho ts'oara "limakatso" ho khoutu ea xswitcher).
Ka hare ke hlalositse ho tlatsa sehlopha ka lihokela tsa mesebetsi "seo u lokelang ho se etsa". Ho golang ke hona (ka tšohanyetso) E ile ea bonahala e le bonolo ebile e hlakile.

  • Ke rera ho fokotsa "Drop" bonyane sebakeng sena. Bakeng sa ts'ebetso e bonolo haholoanyane (ke tla e bontša ka tlase).

3. Tafole e nang le lihlopha tsa lifensetere

# Some behaviour can depend on application currently doing the input.
[[WindowClasses]]
 # VNC, VirtualBox, qemu etc. emulates there input independently, so never intercept.
 # With the exception of some stupid VNC clients, which does high-level (layout-based) keyboard input.
 Regex = "^VirtualBox"
 Actions = "" # Do nothing while focus stays in VirtualBox

[[WindowClasses]]
 Regex = "^konsole"
 # In general, mouse clicks leads to unpredictable (at the low-level where xswitcher resides) cursor jumps.
 # So, it's good choise to drop all buffers after click.
 # But some windows, e.g. terminals, can stay out of this problem.
 MouseClickDrops = 0
 Actions = "Actions"

[[WindowClasses]] # Default behaviour: no Regex (or wildcard like ".")
 MouseClickDrops = 1
 Actions = "Actions"

Mela ea tafole e ka har'a masakana a lisekoere tse peli tse nang le lebitso la eona. Ho ka be ho bile bonolo ho tloha qalong feela. Ho ipapisitse le fensetere e sebetsang hajoale, o ka khetha likhetho tse latelang:

  • Sete ea hau ea "hot keys" "Actions = ...". Haeba ha ho joalo/e se na letho, u se ke ua etsa letho.
  • Fetola "MouseClickDrops" - seo u lokelang ho se etsa ha ho fumanoa toeba. Kaha nakong eo xswitcher e buloang ha ho na lintlha tse mabapi le "moo ba tobetsang teng," re seta buffer ka boiketsetso. Empa ho li-terminals (mohlala) ha ua tlameha ho etsa sena (hangata).

4. Tatelano e le 'ngoe (kapa tse' maloa) ea ho tobetsa e etsa hore hook e le 'ngoe

# action = [ regex1, regex2, ... ]
# "CLEAN" state: all keys are released
[Actions]
# Inverse regex is hard to understand, so extract negation to external condition.
# Expresions will be checked in direct order, one-by-one. Condition succceds when ALL results are True.
 # Maximum key sequence length, extra keys will be dropped. More length - more CPU.
 SeqLength = 8
 # Drop word buffer and start collecting new one
 NewWord = [ "OFF:(CTRL|ALT|META)  SEQ:(((BACK)?SPACE|[LR]_SHIFT):[01],)*(@WORD@:1)", # "@WORD@:0" then collects the char
             "SEQ:(@WORD@:2,@WORD@:0)", # Drop repeated char at all: unlikely it needs correction
             "SEQ:((KP)?MINUS|(KP)?ENTER|ESC|TAB)" ] # Be more flexible: chars line "-" can start new word, but must not completelly invalidate buffer!
 # Drop all buffers
 NewSentence = [ "SEQ:(ENTER:0)" ]

 # Single char must be deleted by single BS, so there is need in compose sequence detector.
 Compose = [ "OFF:(CTRL|L_ALT|META|SHIFT)  SEQ:(R_ALT:1,(R_ALT:2,)?(,@WORD@:1,@WORD@:0){2},R_ALT:0)" ]

 "Action.RetypeWord" = [ "OFF:(CTRL|ALT|META|SHIFT)  SEQ:(PAUSE:0)" ]
 "Action.CyclicSwitch" = [ "OFF:(R_CTRL|ALT|META|SHIFT)  SEQ:(L_CTRL:1,L_CTRL:0)" ] # Single short LEFT CONTROL
 "Action.Respawn" = [ "OFF:(CTRL|ALT|META|SHIFT)  SEQ:(S_LOCK:2,S_LOCK:0)" ] # Long-pressed SCROLL LOCK

 "Action.Layout0" = [ "OFF:(CTRL|ALT|META|R_SHIFT)  SEQ:(L_SHIFT:1,L_SHIFT:0)" ] # Single short LEFT SHIFT
 "Action.Layout1" = [ "OFF:(CTRL|ALT|META|L_SHIFT)  SEQ:(R_SHIFT:1,R_SHIFT:0)" ] # Single short RIGHT SHIFT

 "Action.Hook1" = [ "OFF:(CTRL|R_ALT|META|SHIFT)  SEQ:(L_ALT:1,L_ALT:0)" ]

Li-hook li arotsoe ka mefuta e 'meli. E hahelletsoeng ka hare, e nang le mabitso a itlhalosang (NewWord, NewSentence, Compose) le e ka hlophisehang.

Mabitso a ka reroang a qala ka "Ketso." Hobane TOML v1.4, mabitso a nang le matheba a tlameha ho ba ka mantsoe a qotsitsoeng.

Karolo ka 'ngoe e lokela ho hlalosoa ka tlase ka lebitso le le leng.

E le hore u se ke ua otla likelello tsa batho ka "feela" kamehla (ho tloha phihlelo, ea bona ho ngolamohlomong a le mong ho ba leshome litsebi), hang-hang ke kenya tšebetsong syntax e eketsehileng.

  • "OFF:" (kapa "ON:") pele regexp (polelo e tloaelehileng) e hloka hore likonopo tse latelang li lokolloe (kapa li hatelle).
    Ka mor'a moo, ke tla etsa polelo e tloaelehileng e "sa lokang". Ka ho hlahloba ka thoko likotoana pakeng tsa liphaephe "|". Bakeng sa ho fokotsa palo ea lirekoto tse kang "[LR]_SHIFT" (moo ho hlakileng hore ha ho hlokahale).
  • "SEQ:" Haeba boemo bo fetileng bo kopane (kapa bo le sieo), joale re hlahloba khahlanong le polelo e tloaelehileng ea "tloaelehileng". Ho fumana lintlha, hang-hang ke romela ho ^W laeborari ea "regexp". Hobane ha ke e-s'o khathatsehe ho fumana tekanyo ea ho lumellana le pcre eo ke e ratang haholo ("perl compatible").
  • Polelo e ngotsoe ka mokhoa "BUTTON_1: CODE1, BUTTON_2: CODE2" joalo-joalo, ka tatellano eo likhoutu tsa scan li amoheloang ka eona.
  • Cheke e lula e "snugged" ho fihlela qetellong ea tatellano, kahoo ha ho hlokahale ho eketsa "$" ho mohatla.
  • Licheke tsohle moleng o le mong li etsoa ka ho latellana mme di kopantswe ke “I”. Empa kaha boleng bo hlalosoa e le sehlopha, u ka ngola cheke e 'ngoe ka mor'a phegelwana. Haeba sena se hlokahala ka lebaka le itseng.
  • boleng "SeqLength = 8" e beha meedi ya boholo ba buffer eo ho hlahlobjwang kaofela ho yona. Hobane Ha ke na (ho fihlela joale) ha ke so kopane le lisebelisoa tse sa feleng bophelong ba ka.

5. Ho beha li-hook tse hlalositsoeng karolong e fetileng

# Action is the array, so actions could be chained (m.b., infinitely... Have I to check this?).
# For each action type, extra named parameters could be collected. Invalid parameters will be ignored(?).
[Action.RetypeWord] # Switch layout, drop last word and type it again
 Action = [ "Action.CyclicSwitch", "RetypeWord" ] # Call Switch() between layouts tuned below, then RetypeWord()

[Action.CyclicSwitch] # Cyclic layout switching
 Action = [ "Switch" ] # Internal layout switcher func
 Layouts = [0, 1]

[Action.Layout0] # Direct layout selection
 Action = [ "Layout" ] # Internal layout selection func
 Layout = 0

[Action.Layout1] # Direct layout selection
 Action = [ "Layout" ] # Internal layout selection func
 Layout = 1

[Action.Respawn] # Completely respawn xswitcher. Reload config as well
 Action = [ "Respawn" ]

[Action.Hook1] # Run external commands
  Action = [ "Exec" ]
  Exec = "/path/to/exec -a -b --key_x"
  Wait = 1
  SendBuffer = "Word" # External hook can process collected buffer by it's own means.

Ntho e ka sehloohong mona ke "Ketso = [Sehlopha]". Ho tšoana le karolo e fetileng, ho na le sete e lekanyelitsoeng ea liketso tse hahiloeng. 'Me monyetla oa ho emisa ha o felle ka molao-motheo (ngola "Action.XXX" 'me u se ke ua tsoafa ho ngola karolo e 'ngoe bakeng sa eona).
Haholo-holo, ho thaepa bocha ha lentsoe sebopehong se lokisitsoeng ho arotsoe likarolo tse peli: "fetola sebopeho joalo ka ha ho boletsoe moo" и “tlapa hape” (“RetypeWord”).

Lintlha tse setseng li ngoletsoe "dictionary" ("mapa" ka golang) bakeng sa ketso e fanoeng, lenane la bona le itšetlehile ka se ngotsoeng "Ketso".

Liketso tse ngata tse fapaneng li ka hlalosoa ka qubu e le 'ngoe (likarolo). Kapa u ka e arola. Joalokaha ke bontšitse ka holimo.

Hang-hang ke ile ka beha ketso ea "Exec" ho phethahatsa script e ka ntle. Ka khetho ea ho sutumelletsa buffer e rekotiloeng ho stdin.

  • "Ema = 1" - emela hore ts'ebetso e phethehe.
  • Mohlomong, "ho isa qubung" u tla batla ho beha batho ba eketsehileng tikolohong. tlhahisoleseling joalo ka lebitso la sehlopha sa lifensetere seo e ntšitsoeng ho sona.
    "Na u batla ho hokela sebatli sa hau? Mona ke moo o lokelang ho ea teng. ”

Phew (ea phefumoloha). Ho bonahala eka ha kea lebala letho.

Oops! Ee, ha kea lebala...
Tokiso ea ho qala e hokae? Ka khoutu e thata? Joalo ka:

[ScanDevices]
 # Must exist on start. Self-respawn in case it is younger then 30s
 Test = "/dev/input/event0"
 Respawn = 30
 # Search mask
 Search = "/dev/input/event*"
 # In my thinkPads there are such a pseudo-keyboards whith tons of unnecessary events
 Bypass = "(?i)Video|Camera" # "(?i)" obviously differs from "classic" pcre's.

Ke lebetse/ke entse phoso kae? (ha ho tsela ntle le sena), Ka sebele ke tšepa hore babali ba mamelang ba ke ke ba ba botsoa haholo ho phunya linko tsa bona.

Mahlohonolo!

Source: www.habr.com

Eketsa ka tlhaloso