Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Because Wayland forbids processes from listening to system-wide keypresses, Discord and WebCord are unable to listen for a push-to-talk key. This commit hacks onto WebCord's socket server and allows for sending a payload to activate and deactivate push-to-talk. The delay between sending the packet and push-to-talk state changing appears to be low enough for daily use. You could activate push-to-talk like so: `echo '{"pttAction": "activate"}' | websocat --origin https://127.0.0.1 ws://127.0.0.1:6463` The two "actions" that are supported are `activate` and `deactivate`. The "hack" part of this commit also refers to the activation method - the F12 key is used to trigger push-to-talk. Make sure that F12 is bound before triggering actions, otherwise nothing will happen.
- Loading branch information
e6c05a0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking for this actually, cool to see you hacked it in ahaha. Now I can use push to talk with swhkd.
e6c05a0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funny coincidence, I literally just came across swhkd as a way to get this working, since Gnome shortcuts aren't quite the right solution. swhkd would be perfect for my setup if it had mouse bind support, but the fact that it exists as-is is a godsend.
e6c05a0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤣 your profile showed up on our internal webhook (star) and that led me here. I'm working on experimental mouse support but I must mention that the patch is still in heavy development 😁.
e6c05a0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shinyzenith @epetousis I think throught it would be better to use Electron API (i.e. global shortcuts) that should be supported across all platforms and work out-of-the-box when configured/set in WebCord. If that is not the case for Wayland, at least regular UNIX socket should be used for e.g. security reasons (WebSockets are also available to websites, where UNIX sockets shouldn't be). Probably packets could also be smaller when properly encoded (not as text, binary data can be represented by JS, AFAIK as part of ECMAScript specifications, with ArrayBuffers or Buffers in case of Node.js).
e6c05a0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SpacingBat3 this hack was literally just something I whipped up in an hour to get feature parity from Windows Discord, so I figured there would be a better way to go about it. Appreciate you commenting on this.
I agree that the global shortcuts API should be the best way to go about this, but trying to use this API in Wayland simply fails. After taking a look, global Wayland shortcuts seem to be entirely unimplemented in Chromium's codebase, likely due to the aforementioned limitations on Wayland. So this API is unfortunately a non-starter, and I think all that can be done for now is a method of communicating with WebCord to trigger shortcuts manually.
Also agree that this should be using UNIX sockets or even D-Bus rather than websockets. Ideally, I'd like to get a solution that works with all Discord shortcuts implemented and merged into WebCord, but I'd need to research Discord's shortcut mechanism a bit more.
e6c05a0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@epetousis You can also research a bit of WebCord's code, mostly the preload script of the main window (
sources/code/renderer/preload/main.ts
), it shows the way to actually access and modify the Discord'slocalStorage
before Discord will remove access to it... You can find there the binded key for push-to-talk, so it won't have to be hard-coded (ideally, key press would just be passed to Discord with the global shortcuts for those who support it and probably use UNIX socket in other cases).I may work on global push-to-talk for non-Wayland users if I'll have a time for that.
e6c05a0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SpacingBat3 hi! As epetousis already mentioned, this isn't a proper implementation but just a hack we're trying out. I believe there's an official xdg portal spec being made for global hotkeys, once that's out you can properly have global hotkeys on linux ( maybe with a os check in the source code ? This impl won't depend on wlroots / gnome / kde specific code )
e6c05a0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shinyzenith if I'm reading the comments on that spec issue correctly (this one, right?), it's not quite clear whether push-to-talk-style shortcuts are going to be implemented as part of it. Would be great if it did, though.
e6c05a0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! that's the protocol spec I'm talking about. I haven't looked too deep into it so you're probably correct.
I guess we'll find out when the api is finalized. Worst case scenario, I'll propose changes upstream because this is a really basic functionality for the modern desktop.