From 2a0ffb0cf59554bbfa981e17cd91f8507b2c6e0d Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Fri, 12 Feb 2021 10:21:53 +0200 Subject: [PATCH 1/3] [crosscode] add a mod for binding mouse buttons to actions --- crosscode/btw-i-use-arch-mod/prestart.js | 154 +++++++++++++++++++++++ 1 file changed, 154 insertions(+) diff --git a/crosscode/btw-i-use-arch-mod/prestart.js b/crosscode/btw-i-use-arch-mod/prestart.js index bc03b9a..9be33fe 100644 --- a/crosscode/btw-i-use-arch-mod/prestart.js +++ b/crosscode/btw-i-use-arch-mod/prestart.js @@ -5,3 +5,157 @@ sc.OPTIONS_DEFINITION['keys-btw-i-use-arch.open-map-menu'] = { hasDivider: true, header: 'btw-i-use-arch', }; + +ig.KEY.MOUSE_LEFT = ig.KEY.MOUSE1; +ig.KEY.MOUSE_RIGHT = ig.KEY.MOUSE2; +ig.KEY.MOUSE_MIDDLE = -6; +ig.KEY.MOUSE_BACK = -7; +ig.KEY.MOUSE_FORWARD = -8; + +// As for the copied implementations of ig.Input#keydown and ig.Input#keyup: +// there is probably a way to avoid copying, most notably by abusing the logic +// of the keyCode check. See, in both methods it is basically the same, just +// with differing event names, but the logic is as follows: if the event is a +// keyboard event, get the `keyCode` property, otherwise check if +// `event.button` is 2, then assume the key is `ig.KEY.MOUSE2`, otherwise +// `ig.KEY.MOUSE1`. This means that I could replace the value of the `MOUSE1` +// constant to the keyCode determined with my custom logic, and so the fallback +// path will read my value, but ultimately I didn't do that because I figured +// there might be other parts of these functions which can use some +// refactoring. +ig.Input.inject({ + keydown(event) { + if ( + ig.system.crashed || + this.isInIframeAndUnfocused() || + (this.ignoreKeyboard && event.type !== 'mousedown') + ) { + return; + } + + if (ig.system.hasFocusLost()) { + if (event.type === 'mousedown') { + ig.system.regainFocus(); + } + return; + } + + if (event.type === 'mousedown') { + this.mouseGuiActive = true; + } + this.currentDevice = ig.INPUT_DEVICES.KEYBOARD_AND_MOUSE; + + if (event.target.type === 'text') { + return; + } + + let keyCode = this.getKeyCodeFromEvent(event); + + if ( + // It's quite interesting that the game kinda supports touch events, but + // they are never actually used in practice. + event.type === 'touchstart' || + event.type === 'mousedown' + ) { + this.mousemove(event); + } + + let action = this.bindings[keyCode]; + if (action != null) { + this.actions[action] = true; + // Not sure what are locks supposed to do. Oh wait, I figured it out: + // this is so that if a button is detected to be pressed in a frame, but + // if an un-press event is caught during the processing of the frame, the + // button... Hmmm, still not sure. Entirety of the game logic blocks the + // main thread, so it's impossible to catch two events during processing + // of the frame. + if (!this.locks[action]) { + this.presses[action] = true; + this.locks[action] = true; + } + event.stopPropagation(); + event.preventDefault(); + } + }, + + keyup(event) { + if ( + ig.system.crashed || + this.isInIframeAndUnfocused() || + (this.ignoreKeyboard && event.type !== 'mouseup') || + event.target.type === 'text' || + (ig.system.hasFocusLost() && event.type === 'mouseup') + ) { + return; + } + + this.currentDevice = ig.INPUT_DEVICES.KEYBOARD_AND_MOUSE; + + let keyCode = this.getKeyCodeFromEvent(event); + + let action = this.bindings[keyCode]; + if (action != null) { + this.keyups[action] = true; + this.delayedKeyup.push(action); + event.stopPropagation(); + event.preventDefault(); + } + }, + + getKeyCodeFromEvent(event) { + switch (event.type) { + case 'keyup': + case 'keydown': + return event.keyCode; + + case 'mouseup': + case 'mousedown': + switch (event.button) { + case 0: + return ig.KEY.MOUSE_LEFT; + case 1: + return ig.KEY.MOUSE_MIDDLE; + case 2: + return ig.KEY.MOUSE_RIGHT; + case 3: + return ig.KEY.MOUSE_BACK; + case 4: + return ig.KEY.MOUSE_FORWARD; + } + } + + // idk, fall back to the left mouse button. That's kind of what the default + // implementation does though. + return ig.KEY.MOUSE_LEFT; + }, +}); + +// Finally, some nice injection places. +sc.KeyBinderGui.inject({ + show(...args) { + this.parent(...args); + window.addEventListener('mousedown', this.bindedKeyCheck, false); + }, + + hide(...args) { + this.parent(...args); + window.removeEventListener('mousedown', this.bindedKeyCheck); + }, + + onKeyCheck(event) { + event.preventDefault(); + + let keyCode = ig.input.getKeyCodeFromEvent(event); + if (ig.interact.isBlocked() || this._isBlackedListed(keyCode)) return; + + // This call was added by me. Just in case. Because the `stopPropagation` + // call in `ig.Input` saved me from re-binds of left/right mouse buttons to + // whatever else other than interactions with menus. + event.stopPropagation(); + + if (this.finishCallback != null) { + this.finishCallback(keyCode, this.isAlternative, false); + } + this.hide(); + }, +}); From b0eef7960236b686f6ac562f569402c7caac583b Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Fri, 12 Feb 2021 10:43:39 +0200 Subject: [PATCH 2/3] [nvim] disable ESLint integration for Prettier, sync configs --- nvim/coc-languages/javascript.vim | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nvim/coc-languages/javascript.vim b/nvim/coc-languages/javascript.vim index e6b8c5a..98b3f26 100644 --- a/nvim/coc-languages/javascript.vim +++ b/nvim/coc-languages/javascript.vim @@ -5,10 +5,18 @@ let g:coc_user_config['eslint'] = { \ 'filetypes': s:filetypes, \ 'autoFixOnSave': v:true, \ } +" See let g:coc_user_config['prettier'] = { +\ 'printWidth': 100, +\ 'tabWidth': 2, +\ 'useTabs': v:false, +\ 'semi': v:true, \ 'singleQuote': v:true, +\ 'quoteProps': 'as-needed', +\ 'jsxSingleQuote': v:false, \ 'trailingComma': 'all', +\ 'bracketSpacing': v:true, \ 'jsxBracketSameLine': v:true, -\ 'eslintIntegration': v:true, -\ 'disableSuccessMessage': v:true +\ 'arrowParens': 'always', +\ 'disableSuccessMessage': v:true, \ } From 6fc06191a5dbd93b90bc84b496d6df49323a7cfc Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Fri, 12 Feb 2021 10:51:34 +0200 Subject: [PATCH 3/3] [scripts/discord-stream-desktop-audio] allow specifying the audio device --- scripts/discord-stream-desktop-audio | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/discord-stream-desktop-audio b/scripts/discord-stream-desktop-audio index dd82faa..0161def 100755 --- a/scripts/discord-stream-desktop-audio +++ b/scripts/discord-stream-desktop-audio @@ -6,6 +6,7 @@ import os guild_id = int(sys.argv[1]) voice_channel_id = int(sys.argv[2]) +pulseaudio_device = sys.argv[3] with open(os.path.expanduser("~/.config/dotfiles/discord-tools-user-token.txt")) as f: bot_token = f.read().strip() @@ -28,7 +29,7 @@ async def on_ready(): voice_client = await voice_channel.connect() print("connected to {0} ({0.id}) in {1} ({1.id})".format(voice_channel, guild)) - source = discord.FFmpegPCMAudio("default", before_options="-f pulse") + source = discord.FFmpegPCMAudio(pulseaudio_device, before_options="-f pulse") voice_client.play( source, after=lambda e: print("Player error: %s" % e) if e else None )