Skip to content

Commit

Permalink
Hotkeys support.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggarra13 committed Oct 16, 2023
1 parent 9004ba6 commit 9158d41
Show file tree
Hide file tree
Showing 11 changed files with 321 additions and 273 deletions.
9 changes: 9 additions & 0 deletions mrv2/docs/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ v0.8.0
after it was shown once.
- Fixed pixel zooming and panning on timeline viewport on network connections
when the pixels per unit was not 1 (like macOS Retina).
- Added a Reset Hotkeys to default in the Hotkeys Window. This will reset
*all* your hotkeys to the default values of mrv2 (no need to mess with
mrv2.keys.prefs).
- Added a Reload Hotkeys to the Hotkeys Window. This will reload the last saved
hotkeys (ie. $HOME/.filmaura/mrv2.keys.prefs).
- Fixed Annotations Clear Frame and Annotations Clear All Frames hotkeys being
the same.
- Hotkeys are now compared properly when they are uppercase and shift was not
used while another hotkey had shift and a the same lowercase letter.
- Some UI fixes and improvements:
* The Zoom factor in the Pixel Toolbar keeps its value when selecting
it from the pulldown.
Expand Down
3 changes: 3 additions & 0 deletions mrv2/lib/mrvApp/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace py = pybind11;
#include "mrvCore/mrvOS.h" // do not move up
#include "mrvCore/mrvMemory.h"
#include "mrvCore/mrvHome.h"
#include "mrvCore/mrvHotkey.h"
#include "mrvCore/mrvUtil.h"
#include "mrvCore/mrvRoot.h"
#include "mrvCore/mrvSignalHandler.h"
Expand Down Expand Up @@ -509,6 +510,8 @@ namespace mrv

LOG_INFO(msg);

store_default_hotkeys();

std_any value;

Preferences prefs(
Expand Down
345 changes: 189 additions & 156 deletions mrv2/lib/mrvCore/mrvHotkey.cpp

Large diffs are not rendered by default.

17 changes: 15 additions & 2 deletions mrv2/lib/mrvCore/mrvHotkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ namespace mrv
*/
struct HotkeyEntry
{
/**
* Default constructor.
*
*/
HotkeyEntry() :
force(false),
hotkey(nullptr){};

/**
* HotkeyEntry constructor.
*
Expand All @@ -303,14 +311,16 @@ namespace mrv
* @param f whether to force its use.
*
*/
HotkeyEntry(const std::string n, Hotkey& h, bool f = false) :
HotkeyEntry(const std::string n, Hotkey* h, bool f = false) :
force(f),
name(n),
hotkey(h){};

~HotkeyEntry() {}

bool force;
std::string name;
Hotkey& hotkey;
Hotkey* hotkey;
};

/**
Expand All @@ -325,4 +335,7 @@ namespace mrv

extern struct TableText table[];
extern HotkeyEntry hotkeys[];

void store_default_hotkeys();
void reset_hotkeys();
} // namespace mrv
108 changes: 53 additions & 55 deletions mrv2/lib/mrvFl/mrvHotkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ namespace mrv
// Labels
b->add(_("@B12@C7@[email protected]\t@B12@C7@[email protected]"));

for (int i = 0; hotkeys[i].name != "END"; ++i)
for (int i = 0; hotkeys[i].hotkey; ++i)
{
HotkeyEntry& h = hotkeys[i];
const HotkeyEntry& h = hotkeys[i];
const std::string hotkey = h.hotkey->to_s();

std::string row(_(h.name.c_str()));
const std::string hotkey = h.hotkey.to_s();
row += "\t" + hotkey;

b->add(row.c_str());
Expand All @@ -73,9 +74,9 @@ namespace mrv
return;

const std::string& name = hotkeys[idx].name;
Hotkey& hk = hotkeys[idx].hotkey;
Hotkey* hotkey = hotkeys[idx].hotkey;

ChooseHotkey* h = new ChooseHotkey(hk);
ChooseHotkey* h = new ChooseHotkey(hotkey);
h->make_window(name);
h->fill();

Expand All @@ -86,11 +87,11 @@ namespace mrv
while (window->visible())
Fl::check();

for (int i = 0; hotkeys[i].name != "END"; ++i)
for (int i = 0; hotkeys[i].hotkey; ++i)
{
if (h->hk == hotkeys[i].hotkey && idx != i &&
hotkeys[i].hotkey.to_s() != "[" &&
hotkeys[i].hotkey.to_s() != "]")
if (h->hk == *(hotkeys[i].hotkey) && idx != i &&
hotkeys[i].hotkey->to_s() != "[" &&
hotkeys[i].hotkey->to_s() != "]")
{
int ok = fl_choice(
_("Hotkey \"%s\" already used in \"%s\".\n"
Expand All @@ -104,12 +105,12 @@ namespace mrv
}
else
{
hotkeys[i].hotkey.clear();
hotkeys[i].hotkey->clear();
}
}
}

hk = h->hk;
*hotkey = h->hk;

delete h;

Expand Down Expand Up @@ -184,99 +185,102 @@ namespace mrv
void save_hotkeys(Fl_Preferences& keys)
{
keys.set("version", 11);
for (int i = 0; hotkeys[i].name != "END"; ++i)
for (int i = 0; hotkeys[i].hotkey; ++i)
{
keys.set(
(hotkeys[i].name + " ctrl").c_str(), hotkeys[i].hotkey.ctrl);
keys.set((hotkeys[i].name + " alt").c_str(), hotkeys[i].hotkey.alt);
(hotkeys[i].name + " ctrl").c_str(), hotkeys[i].hotkey->ctrl);
keys.set(
(hotkeys[i].name + " alt").c_str(), hotkeys[i].hotkey->alt);
keys.set(
(hotkeys[i].name + " meta").c_str(), hotkeys[i].hotkey.meta);
(hotkeys[i].name + " meta").c_str(), hotkeys[i].hotkey->meta);
keys.set(
(hotkeys[i].name + " shift").c_str(), hotkeys[i].hotkey.shift);
(hotkeys[i].name + " shift").c_str(), hotkeys[i].hotkey->shift);
keys.set(
(hotkeys[i].name + " key").c_str(), (int)hotkeys[i].hotkey.key);
(hotkeys[i].name + " key").c_str(),
(int)hotkeys[i].hotkey->key);
keys.set(
(hotkeys[i].name + " text").c_str(),
hotkeys[i].hotkey.text.c_str());
hotkeys[i].hotkey->text.c_str());
}
}

void load_hotkeys(ViewerUI* ui, Fl_Preferences* keys)
void load_hotkeys(Fl_Preferences* keys)
{
int version = 0;
keys->get("version", version, 11);
int tmp = 0;
char tmpS[2048];

for (int i = 0; hotkeys[i].name != "END"; ++i)
for (int i = 0; hotkeys[i].hotkey; ++i)
{
if (hotkeys[i].force == false)
continue;
hotkeys[i].hotkey.shift = hotkeys[i].hotkey.ctrl =
hotkeys[i].hotkey.alt = hotkeys[i].hotkey.meta = false;
hotkeys[i].hotkey.key = 0;
hotkeys[i].hotkey.text.clear();
hotkeys[i].hotkey->shift = hotkeys[i].hotkey->ctrl =
hotkeys[i].hotkey->alt = hotkeys[i].hotkey->meta = false;
hotkeys[i].hotkey->key = 0;
hotkeys[i].hotkey->text.clear();
}

for (int i = 0; hotkeys[i].name != "END"; ++i)
for (int i = 0; hotkeys[i].hotkey; ++i)
{
Hotkey saved = hotkeys[i].hotkey;
Hotkey* saved = new Hotkey(*hotkeys[i].hotkey);

keys->get(
(hotkeys[i].name + " key").c_str(), tmp,
(int)hotkeys[i].hotkey.key);
(int)hotkeys[i].hotkey->key);
if (tmp)
hotkeys[i].force = false;
hotkeys[i].hotkey.key = unsigned(tmp);
hotkeys[i].hotkey->key = unsigned(tmp);

keys->get(
(hotkeys[i].name + " text").c_str(), tmpS,
hotkeys[i].hotkey.text.c_str(), 16);
hotkeys[i].hotkey->text.c_str(), 16);
if (strlen(tmpS) > 0)
{
hotkeys[i].force = false;
hotkeys[i].hotkey.text = tmpS;
hotkeys[i].hotkey->text = tmpS;
}
else
hotkeys[i].hotkey.text.clear();
hotkeys[i].hotkey->text.clear();

if (hotkeys[i].force)
{
delete hotkeys[i].hotkey;
hotkeys[i].hotkey = saved;
continue;
}
keys->get(
(hotkeys[i].name + " ctrl").c_str(), tmp,
(int)hotkeys[i].hotkey.ctrl);
(int)hotkeys[i].hotkey->ctrl);
if (tmp)
hotkeys[i].hotkey.ctrl = true;
hotkeys[i].hotkey->ctrl = true;
else
hotkeys[i].hotkey.ctrl = false;
hotkeys[i].hotkey->ctrl = false;
keys->get(
(hotkeys[i].name + " alt").c_str(), tmp,
(int)hotkeys[i].hotkey.alt);
(int)hotkeys[i].hotkey->alt);
if (tmp)
hotkeys[i].hotkey.alt = true;
hotkeys[i].hotkey->alt = true;
else
hotkeys[i].hotkey.alt = false;
hotkeys[i].hotkey->alt = false;

keys->get(
(hotkeys[i].name + " meta").c_str(), tmp,
(int)hotkeys[i].hotkey.meta);
(int)hotkeys[i].hotkey->meta);
if (tmp)
hotkeys[i].hotkey.meta = true;
hotkeys[i].hotkey->meta = true;
else
hotkeys[i].hotkey.meta = false;
hotkeys[i].hotkey->meta = false;

keys->get(
(hotkeys[i].name + " shift").c_str(), tmp,
(int)hotkeys[i].hotkey.shift);
(int)hotkeys[i].hotkey->shift);
if (tmp)
hotkeys[i].hotkey.shift = true;
hotkeys[i].hotkey->shift = true;
else
hotkeys[i].hotkey.shift = false;
hotkeys[i].hotkey->shift = false;

for (int j = 0; hotkeys[j].name != "END"; ++j)
for (int j = 0; hotkeys[j].hotkey; ++j)
{
if (j != i && hotkeys[j].hotkey == hotkeys[i].hotkey)
{
Expand All @@ -285,33 +289,27 @@ namespace mrv
std::string err =
tl::string::Format(
_("Corruption in hotkeys preferences. "
"Hotkey {0} for {1} will not be "
"Hotkey '{0}' for {1} will not be "
"available. "
"Already used in {2}."))
.arg(hotkeys[j].hotkey.to_s())
.arg(hotkeys[j].hotkey->to_s())
.arg(_(hotkeys[j].name.c_str()))
.arg(_(hotkeys[i].name.c_str()));
LOG_ERROR(err);
}
hotkeys[j].hotkey = Hotkey();
hotkeys[j].hotkey = new Hotkey();
}
}
}

HotkeyUI* h = ui->uiHotkey;
fill_ui_hotkeys(h->uiFunction);
}

void load_hotkeys(ViewerUI* ui)
void load_hotkeys()
{
Fl_Preferences* keys = new Fl_Preferences(
prefspath().c_str(), "filmaura", Preferences::hotkeys_file.c_str(),
Fl_Preferences::C_LOCALE);
load_hotkeys(ui, keys);
load_hotkeys(keys);
delete keys;

HotkeyUI* h = ui->uiHotkey;
fill_ui_hotkeys(h->uiFunction);
}

} // namespace mrv
2 changes: 1 addition & 1 deletion mrv2/lib/mrvFl/mrvHotkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace mrv
void fill_ui_hotkeys(mrv::Browser* o);
void select_hotkey(HotkeyUI* m);

void load_hotkeys(ViewerUI* ui);
void load_hotkeys();
void save_hotkeys(Fl_Preferences& keys);

} // namespace mrv
23 changes: 12 additions & 11 deletions mrv2/lib/mrvFl/mrvPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace fs = std::filesystem;
#include "mrvApp/App.h"

#include "mrvPreferencesUI.h"
#include "mrvHotkeyUI.h"

#include "mrvFl/mrvIO.h"
#include "mrvCore/mrvOS.h"
Expand Down Expand Up @@ -773,24 +774,24 @@ namespace mrv
//
// Hotkeys
//
std::string fullhotkeysPath = prefspath() + hotkeys_file + ".prefs";
if (resetHotkeys)
{
if (file::isReadable(fullhotkeysPath))
{
fs::remove(fullhotkeysPath);
}
}
else
reset_hotkeys();
if (!resetHotkeys)
{
msg =
tl::string::Format(_("Loading hotkeys from \"{0}{1}.prefs\"."))
.arg(prefspath())
.arg(hotkeys_file);
LOG_INFO(msg);
load_hotkeys();
}
else
{
msg = tl::string::Format(_("Reseting hotkeys to default."));
}
LOG_INFO(msg);

load_hotkeys(ui);
// Fill the hotkeys window
HotkeyUI* h = ui->uiHotkey;
fill_ui_hotkeys(h->uiFunction);

std_any value;

Expand Down
Loading

0 comments on commit 9158d41

Please sign in to comment.