-
Notifications
You must be signed in to change notification settings - Fork 57
Global hotkeys #354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Global hotkeys #354
Conversation
Added hotkey for mute ALT+M Added hotkey for deafen ALT+D
interesting i havent seen that library before. i dont really like the low level keyboard hook on win32 (theres a reason msys disables it) but tbh if it works then i dont really mind. id probably make GlobalHotkeyManager not a singleton and just move it to live in the |
src/misc/GlobalHotkeyManager.cpp
Outdated
// Run hook in separate thread to not block gtk | ||
std::thread([this]() { | ||
if (hook_run() != UIOHOOK_SUCCESS) { | ||
std::cerr << "Failed to start libuiohook" << std::endl; |
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.
should use spdlog. the "ui" logger is probably fine for this
src/misc/GlobalHotkeyManager.cpp
Outdated
m_callbacks[id] = { | ||
.keycode = keycode, | ||
.modifiers = modifiers, | ||
.callback = callback | ||
}; |
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.
the .a = b
syntax is c++20 but this is a c++17 project
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.
C++20 sneaked in while I wasn’t looking!
} | ||
|
||
GlobalHotkeyManager::Hotkey* GlobalHotkeyManager::find_hotkey(uint16_t keycode, uint32_t modifiers) { | ||
auto it = std::find_if(m_callbacks.begin(), m_callbacks.end(), |
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.
shouldnt m_mutex be locked here too ?
src/misc/GlobalHotkeyManager.cpp
Outdated
Hotkey *hk = find_hotkey(event->data.keyboard.keycode, event->mask); | ||
if (hk != nullptr) { | ||
std::lock_guard<std::mutex> lock(m_mutex); | ||
hk->callback(); |
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 assume this will still execute the callback on the thread created above which does the hook stuff
since the callbacks are doing stuff to the ui from the wrong thread there will invariably be crashes. Glib::Dispatcher
exists to synchronize back to the main thread. heres an example of using dispatcher+queue+mutex to synchronize from websocket thread back to main thread
https://github.com/uowuo/abaddon/blob/ba15622a751b8e67b8b62d512ad713bc408f090d/src/remoteauth/remoteauthclient.cpp
src/windows/voice/voicewindow.cpp
Outdated
// TODO: Load shortcuts from config file | ||
m_mute_hotkey = GlobalHotkeyManager::instance().registerHotkey(VC_M, MASK_ALT, [this]() { | ||
// This is probably stupid there is for sure some way to call event | ||
// but I'm not really familiar with gtk and this works well. | ||
m_mute.set_active( !m_mute.get_active() ); | ||
}); | ||
m_deafen_hotkey = GlobalHotkeyManager::instance().registerHotkey(VC_D, MASK_ALT, [this]() { | ||
m_deafen.set_active( !m_deafen.get_active() ); | ||
}); | ||
|
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.
im not entirely sure where the best place to do this would be (maybe just in the main Abaddon
singleton, but theres gonna need to be some other changes to actually propagate that to the right places) but here definitely wont work. for example this window is intended to be able to be closed without disconnecting from vc in which case the hotkey is unregistered
Added `ENABLE_GLOBAL_HOTKEY` option in cmake (ON by default) Removed designated initializer from struct Replaced `std::cerr` with `spdlog::get("ui")->error` Added missing mutex lock Used `Glib::Dispatcher` for executing callbacks (Hope done correctly) For now mute/deafen hotkey are still placed in voicewindow
My ideas for shortcuts configuration. Human-Readable ParserParse shortcuts like Numerical values in configExpose keycode and mask directly in settings. |
ideally both (config + ui helper) but for now just config is fine. GTK has |
I might have added a bit to much but it might be useful later with ui helper
Would it be alright if I add public functions to void SetMute( bool is_mute );
void SetDeaf( bool is_deaf );
bool GetMute();
bool GetDeaf(); Then register hotkey inside m_mute_hotkey_id = m_HotkeyManager.registerHotkey("<Alt>M", [this]() {
if (m_voice_window != nullptr) {
auto voice_window = dynamic_cast<VoiceWindow*>(m_voice_window);
if (voice_window) {
m_is_mute = !voice_window->GetMute();
voice_window->SetMute( m_is_mute );
return;
}
}
m_is_mute = !m_is_mute;
m_discord.SetVoiceMuted( m_is_mute );
m_audio.SetCapture( !m_is_mute );
}); And in function |
yeah thats fine. i should definitely rethink how i do muting and stuff but thats out of scope here so ill take care of it some other time. |
Moved hotkeys from `VoiceWindow` into `Abaddon` class Added getters and setters in `VoiceWindow`
Hotkeys can now be assigned in `abaddon.ini` under `[hotkeys]` Moved GDK keyval mapping to bottom of file Added hotkeys to readme file
You can now use for example `<Control><Alt>M`
I think base hotkey support is done. The last commit was pushed by mistake it broke support for a single modifier. |
sorry for the delay ill test this out and look over it again in a bit |
Simple Hotkey Support
For now only support:
Alt+M
Alt+D
This feature uses libUIOHook, which has been added as a submodule.
For now shortcuts are hardcoded in
src/windows/voice/voicewindow.cpp
Addresses a request from this comment in issue #30
Closes #322
TODO
libuiohook
an optional dependency.Glib::Dispatcher
to synchronize callbacks to the main thread.voicewindow
.libuihooks
keycodesGlobalHotkeyManager
toAbaddon
singleton.