Skip to content

Commit

Permalink
Move parsing key definitions to class WMKey.
Browse files Browse the repository at this point in the history
  • Loading branch information
gijsbers committed Aug 1, 2024
1 parent 7aedab7 commit 5ea69e7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
5 changes: 1 addition & 4 deletions src/wmapp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,7 @@ void YWMApp::reparseKeyPrefs() {
extern cfoption icewm_preferences[];
for (cfoption* op = icewm_preferences; op->type; ++op) {
if (op->type == cfoption::CF_KEY) {
WMKey* key = op->v.k.key_value;
if (key->name) {
parseKey(key->name, &key->key, &key->mod);
}
op->v.k.key_value->parse();
}
}
}
Expand Down
8 changes: 1 addition & 7 deletions src/wmpref.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,7 @@ void PrefsMenu::handleMsgBox(YMsgBox* msgbox, int operation) {
if (operation == YMsgBox::mbOK && modify) {
if (modify->type == cfoption::CF_KEY && modify->key()) {
WMKey *wk = modify->key();
if (input.isEmpty() ? (wk->key = wk->mod = 0, true) :
wmapp->parseKey(input, &wk->key, &wk->mod))
{
if (!wk->initial)
delete[] const_cast<char *>(wk->name);
wk->name = newstr(input);
wk->initial = false;
if (wk->set(input)) {
modified(modify);
msg("%s = \"%s\"", modify->name, wk->name);
wmapp->actionPerformed(actionReloadKeys);
Expand Down
10 changes: 1 addition & 9 deletions src/yconfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "ykey.h"
#include "yconfig.h"
#include "yprefs.h"
#include "sysdep.h"
#include "yapp.h"
#include "intl.h"
#include "ascii.h"
Expand Down Expand Up @@ -206,14 +205,7 @@ void YConfig::setOption(char* arg, bool append, cfoption* opt) {
break;
case cfoption::CF_KEY:
if (opt->v.k.key_value) {
WMKey *wk = opt->v.k.key_value;

if (YConfig::parseKey(arg, &wk->key, &wk->mod)) {
if (!wk->initial)
delete[] const_cast<char *>(wk->name);
wk->name = newstr(arg);
wk->initial = false;
}
opt->v.k.key_value->set(arg);
}
break;
case cfoption::CF_FUNC:
Expand Down
2 changes: 2 additions & 0 deletions src/yconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ struct WMKey {
bool eq(KeySym k, unsigned m) const { return key == k && mod == m; }
bool operator==(const WMKey& o) const { return eq(o.key, o.mod); }
bool operator!=(const WMKey& o) const { return !eq(o.key, o.mod); }
bool parse();
bool set(const char* arg);
};

#ifdef CFGDESC
Expand Down
24 changes: 24 additions & 0 deletions src/yxapp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,30 @@ void YXApplication::queryMouse(int* x, int* y) {
*x = *y = 0;
}

bool WMKey::set(const char* arg) {
bool change = false;
if (isEmpty(arg)) {
key = mod = 0;
if (nonempty(name)) {
name = "";
change = true;
initial = true;
}
}
else if (xapp->parseKey(arg, &key, &mod)) {
if (initial == false)
delete[] const_cast<char *>(name);
name = newstr(arg);
initial = false;
change = true;
}
return change;
}

bool WMKey::parse() {
return (nonempty(name) && xapp->parseKey(name, &key, &mod));
}

bool YXApplication::parseKey(const char* arg, KeySym* key, unsigned* mod) {
bool yes = YConfig::parseKey(arg, key, mod);
if (yes)
Expand Down

0 comments on commit 5ea69e7

Please sign in to comment.