Shortcuts: provide some default actions for mute, increment and decrement volume media keys

Works for HID-aware devices (USB & PS/2).

Change-Id: I45e9ededaab1699f30e55fb644ec0e3ceebeb191
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5937
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
This commit is contained in:
Jérôme Duval 2022-12-16 19:49:18 +01:00 committed by Adrien Destugues
parent c44b267fb3
commit d9f90ce7f3
4 changed files with 22 additions and 7 deletions

View File

@ -289,3 +289,8 @@ AddDirectoryToHaikuImage home config settings printers "Save as PDF"
# padblocker
AddDirectoryToHaikuImage home config settings touchpad ;
# shortcuts defaults
local shortcutsSettingsFile = <settings>shortcuts_settings ;
SEARCH on $(shortcutsSettingsFile) = [ FDirName $(HAIKU_TOP) data settings ] ;
AddFilesToHaikuImage home config settings : $(shortcutsSettingsFile) ;

Binary file not shown.

View File

@ -40,6 +40,8 @@
#include <ScrollView.h>
#include <String.h>
#include <SupportDefs.h>
#include <usb/USB_hid.h>
#include <usb/USB_hid_page_consumer.h>
#include "EditWindow.h"
#include "KeyInfos.h"
@ -215,6 +217,12 @@ ShortcutsWindow::ShortcutsWindow()
message.AddString("startupRef", "please");
PostMessage(&message);
// tell ourselves to load this file if it exists
} else {
_AddNewSpec("/bin/setvolume -m", (B_HID_USAGE_PAGE_CONSUMER << 16) | B_HID_UID_CON_MUTE);
_AddNewSpec("/bin/setvolume -i", (B_HID_USAGE_PAGE_CONSUMER << 16) | B_HID_UID_CON_VOLUME_INCREMENT);
_AddNewSpec("/bin/setvolume -d", (B_HID_USAGE_PAGE_CONSUMER << 16) | B_HID_UID_CON_VOLUME_DECREMENT);
fLastSaved = BEntry(&keySetRef);
PostMessage(SAVE_KEYSET);
}
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
@ -315,11 +323,9 @@ ShortcutsWindow::_GetSettingsFile(entry_ref* eref)
return false;
else
path.Append(SHORTCUTS_SETTING_FILE_NAME);
if (BEntry(path.Path(), true).GetRef(eref) == B_OK)
return true;
else
return false;
BEntry entry(path.Path(), true);
entry.GetRef(eref);
return entry.Exists();
}
@ -435,7 +441,7 @@ ShortcutsWindow::_LoadWindowSettings(const BMessage& loadMessage)
// Creates a new entry and adds it to the GUI. (defaultCommand) will be the
// text in the entry, or NULL if no text is desired.
void
ShortcutsWindow::_AddNewSpec(const char* defaultCommand)
ShortcutsWindow::_AddNewSpec(const char* defaultCommand, uint32 keyCode)
{
_MarkKeySetModified();
@ -454,6 +460,10 @@ ShortcutsWindow::_AddNewSpec(const char* defaultCommand)
fColumnListView->ScrollTo(spec);
if (defaultCommand)
spec->SetCommand(defaultCommand);
if (keyCode != 0) {
spec->ProcessColumnTextString(ShortcutsSpec::KEY_COLUMN_INDEX,
GetFallbackKeyName(keyCode).String());
}
}

View File

@ -57,7 +57,7 @@ public:
private:
BMenuItem* _CreateActuatorPresetMenuItem(const char* label)
const;
void _AddNewSpec(const char* defaultCommand);
void _AddNewSpec(const char* defaultCommand, uint32 keyCode = 0);
void _MarkKeySetModified();
bool _LoadKeySet(const BMessage& loadMessage);
bool _SaveKeySet(BEntry& saveEntry);