Fix Scoundrel softkey handling and ignore spurious MBHC jack keys in Xorg
This commit is contained in:
1 parent
c017c0037a
commit
a36b908faf
4 files changed
+125
-59
No files matched your search
@@ -50,3 +50,10 @@ Section "InputClass"
|
|||||||
Driver "libinput"
|
Driver "libinput"
|
||||||
EndSection
|
EndSection
|
||||||
|
|
||||||
|
Section "InputClass"
|
||||||
|
Identifier "Ignore Headset Jack MBHC buttons"
|
||||||
|
MatchProduct "Headset Jack"
|
||||||
|
Option "Ignore" "true"
|
||||||
|
EndSection
|
||||||
|
|
||||||
|
|
||||||
Binary file not shown.
Binary file not shown.
+118
-59
@@ -206,6 +206,7 @@ class ScoundrelGame {
|
|||||||
int pendingMonsterSlot = -1;
|
int pendingMonsterSlot = -1;
|
||||||
int pendingMonsterLevel = 0;
|
int pendingMonsterLevel = 0;
|
||||||
int weaponChoiceIdx = 0; // 0 = Use Weapon, 1 = Barehanded
|
int weaponChoiceIdx = 0; // 0 = Use Weapon, 1 = Barehanded
|
||||||
|
int menuChoiceIdx = 0; // 0 = Resume, 1 = New Game, 2 = Rules, 3 = Quit
|
||||||
UiModal modal = UiModal::Idle;
|
UiModal modal = UiModal::Idle;
|
||||||
std::string statusLine1;
|
std::string statusLine1;
|
||||||
std::string statusLine2;
|
std::string statusLine2;
|
||||||
@@ -615,7 +616,7 @@ int main() {
|
|||||||
|
|
||||||
NeoWindow neo;
|
NeoWindow neo;
|
||||||
if (!neo.create("scoundrel", "Scoundrel", "Scoundrel",
|
if (!neo.create("scoundrel", "Scoundrel", "Scoundrel",
|
||||||
0, 24, 240, 296, false)) {
|
0, 24, 240, 296, true)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -631,8 +632,8 @@ int main() {
|
|||||||
Atom wmDelete = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
Atom wmDelete = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
||||||
XSetWMProtocols(dpy, win, &wmDelete, 1);
|
XSetWMProtocols(dpy, win, &wmDelete, 1);
|
||||||
|
|
||||||
XMapRaised(dpy, win);
|
neo.bindAsActiveContext();
|
||||||
XFlush(dpy);
|
neoui_show();
|
||||||
|
|
||||||
ScoundrelGame game;
|
ScoundrelGame game;
|
||||||
|
|
||||||
@@ -898,21 +899,36 @@ int main() {
|
|||||||
}
|
}
|
||||||
neo.drawSoftbar("Resume", "OK", "Close", &theme.colYellow);
|
neo.drawSoftbar("Resume", "OK", "Close", &theme.colYellow);
|
||||||
} else if (game.modal == UiModal::QuitConfirm) {
|
} else if (game.modal == UiModal::QuitConfirm) {
|
||||||
int mx = 20, my = 84, mw = W - 40, mh = 116;
|
int mx = 20, my = 62, mw = W - 40, mh = 152;
|
||||||
XSetForeground(dpy, gc, theme.spec.bgHeader);
|
XSetForeground(dpy, gc, theme.spec.bgHeader);
|
||||||
XFillRectangle(dpy, pix, gc, mx, my, mw, mh);
|
XFillRectangle(dpy, pix, gc, mx, my, mw, mh);
|
||||||
XSetForeground(dpy, gc, theme.spec.accent);
|
XSetForeground(dpy, gc, theme.spec.accent);
|
||||||
XDrawRectangle(dpy, pix, gc, mx, my, mw - 1, mh - 1);
|
XDrawRectangle(dpy, pix, gc, mx, my, mw - 1, mh - 1);
|
||||||
|
|
||||||
neo.drawPango(layoutMain, &theme.colYellow, mx + 8, my + 12, 22,
|
neo.drawPango(layoutMain, &theme.colYellow, mx + 8, my + 8, 22,
|
||||||
"Scoundrel Menu", mw - 16, 1);
|
"Scoundrel Menu", mw - 16, 1);
|
||||||
neo.drawPango(layoutSmall, &theme.colWhite, mx + 12, my + 42, 18,
|
static const char* kMenuItems[4] = {
|
||||||
"[1 / L-Soft] New Game", mw - 24);
|
"[1] Resume Game",
|
||||||
neo.drawPango(layoutSmall, &theme.colRed, mx + 12, my + 64, 18,
|
"[2] New Game",
|
||||||
"[2 / OK] Quit to Desktop", mw - 24);
|
"[3] Rules & Help",
|
||||||
neo.drawPango(layoutSmall, &theme.colMuted, mx + 12, my + 86, 18,
|
"[4] Quit Game"
|
||||||
"[R-Soft / Back] Cancel", mw - 24);
|
};
|
||||||
neo.drawSoftbar("New Game", "Quit", "Cancel", &theme.colYellow);
|
for (int mi = 0; mi < 4; ++mi) {
|
||||||
|
int ry = my + 34 + mi * 27;
|
||||||
|
bool isSel = (game.menuChoiceIdx == mi);
|
||||||
|
if (isSel) {
|
||||||
|
XSetForeground(dpy, gc, theme.spec.selBg);
|
||||||
|
XFillRectangle(dpy, pix, gc, mx + 8, ry, mw - 16, 25);
|
||||||
|
XSetForeground(dpy, gc, theme.spec.accent);
|
||||||
|
XFillRectangle(dpy, pix, gc, mx + 8, ry, 3, 25);
|
||||||
|
}
|
||||||
|
XftColor* itemCol = (mi == 3)
|
||||||
|
? &theme.colRed
|
||||||
|
: (isSel ? &theme.colWhite : &theme.colLight);
|
||||||
|
neo.drawPango(layoutSmall, itemCol, mx + 16, ry + 3, 19,
|
||||||
|
kMenuItems[mi], mw - 28);
|
||||||
|
}
|
||||||
|
neo.drawSoftbar("Select", "OK", "Back", &theme.colYellow);
|
||||||
} else if (game.modal == UiModal::GameOver) {
|
} else if (game.modal == UiModal::GameOver) {
|
||||||
int mx = 14, my = 52, mw = W - 28, mh = 188;
|
int mx = 14, my = 52, mw = W - 28, mh = 188;
|
||||||
XSetForeground(dpy, gc, theme.spec.bgHeader);
|
XSetForeground(dpy, gc, theme.spec.bgHeader);
|
||||||
@@ -958,7 +974,6 @@ int main() {
|
|||||||
|
|
||||||
render();
|
render();
|
||||||
|
|
||||||
int xfd = ConnectionNumber(dpy);
|
|
||||||
while (gRunning) {
|
while (gRunning) {
|
||||||
if (gReloadTheme) {
|
if (gReloadTheme) {
|
||||||
gReloadTheme = 0;
|
gReloadTheme = 0;
|
||||||
@@ -966,44 +981,63 @@ int main() {
|
|||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (XPending(dpy) > 0) {
|
int evType = neoui_poll_event(250);
|
||||||
XEvent ev;
|
if (evType == NEO_EV_NONE) {
|
||||||
XNextEvent(dpy, &ev);
|
continue;
|
||||||
if (ev.type == ClientMessage &&
|
}
|
||||||
static_cast<Atom>(ev.xclient.data.l[0]) == wmDelete) {
|
if (evType == NEO_EV_CLOSE_REQ) {
|
||||||
gRunning = 0;
|
gRunning = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (ev.type == Expose && ev.xexpose.count == 0) {
|
if (evType == NEO_EV_THEME_RELOAD) {
|
||||||
|
render();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (evType == NEO_EV_EXPOSE) {
|
||||||
neo.present();
|
neo.present();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (ev.type != KeyPress) {
|
if (evType == NEO_EV_SOFTKEY_CHORD) {
|
||||||
|
::usleep(80000);
|
||||||
|
while (::access("/run/user/10000/xdrawer.pid", F_OK) == 0 ||
|
||||||
|
::access("/tmp/xdrawer.pid", F_OK) == 0) {
|
||||||
|
::usleep(50000);
|
||||||
|
}
|
||||||
|
neoui_raise_and_grab();
|
||||||
|
render();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (evType != NEO_EV_KEY_PRESS &&
|
||||||
|
evType != NEO_EV_SOFTKEY_LEFT &&
|
||||||
|
evType != NEO_EV_SOFTKEY_RIGHT) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeySym ks = XLookupKeysym(&ev.xkey, 0);
|
int nkey = neoui_event_key();
|
||||||
bool isLeftSoft = (ks == XK_F1 || ks == XK_Menu ||
|
KeySym ks = static_cast<KeySym>(neoui_event_keysym());
|
||||||
ks == _EVDEVK(0x08b) || ev.xkey.keycode == 147);
|
bool isLeftSoft = (evType == NEO_EV_SOFTKEY_LEFT || nkey == NEO_KEY_SOFT_LEFT);
|
||||||
bool isRightSoft = (ks == XK_F2 || ks == XK_BackSpace ||
|
bool isRightSoft = (evType == NEO_EV_SOFTKEY_RIGHT ||
|
||||||
ks == XF86XK_Back || ks == _EVDEVK(0x09e) ||
|
nkey == NEO_KEY_SOFT_RIGHT || nkey == NEO_KEY_BACK);
|
||||||
ev.xkey.keycode == 166 || ev.xkey.keycode == 22);
|
bool isOk = (nkey == NEO_KEY_OK || ks == XK_Return ||
|
||||||
bool isOk = (ks == XK_Return || ks == XK_KP_Enter || ks == XK_space);
|
ks == XK_KP_Enter || ks == XK_space);
|
||||||
bool isEnd = (ks == XK_Escape || ks == XF86XK_AudioLowerVolume ||
|
bool isEnd = (nkey == NEO_KEY_END || ks == XK_Escape);
|
||||||
ks == XF86XK_PowerOff || ks == _EVDEVK(0x197));
|
bool isUp = (nkey == NEO_KEY_UP || ks == XK_Up);
|
||||||
|
bool isDown = (nkey == NEO_KEY_DOWN || ks == XK_Down);
|
||||||
|
bool isLeft = (nkey == NEO_KEY_LEFT || ks == XK_Left);
|
||||||
|
bool isRight = (nkey == NEO_KEY_RIGHT || ks == XK_Right);
|
||||||
|
|
||||||
if (game.modal == UiModal::WeaponPrompt) {
|
if (game.modal == UiModal::WeaponPrompt) {
|
||||||
if (ks == XK_Up || ks == XK_Down || ks == XK_Left || ks == XK_Right) {
|
if (isUp || isDown || isLeft || isRight) {
|
||||||
game.weaponChoiceIdx = 1 - game.weaponChoiceIdx;
|
game.weaponChoiceIdx = 1 - game.weaponChoiceIdx;
|
||||||
} else if (ks == XK_1) {
|
} else if (nkey == NEO_KEY_1 || ks == XK_1) {
|
||||||
game.modal = UiModal::Idle;
|
game.modal = UiModal::Idle;
|
||||||
game.resolveMonsterCombat(game.pendingMonsterSlot,
|
game.resolveMonsterCombat(game.pendingMonsterSlot,
|
||||||
game.pendingMonsterLevel, true);
|
game.pendingMonsterLevel, true);
|
||||||
} else if (ks == XK_2) {
|
} else if (nkey == NEO_KEY_2 || ks == XK_2) {
|
||||||
game.modal = UiModal::Idle;
|
game.modal = UiModal::Idle;
|
||||||
game.resolveMonsterCombat(game.pendingMonsterSlot,
|
game.resolveMonsterCombat(game.pendingMonsterSlot,
|
||||||
game.pendingMonsterLevel, false);
|
game.pendingMonsterLevel, false);
|
||||||
} else if (isOk || ks == XK_5 || isLeftSoft) {
|
} else if (isOk || nkey == NEO_KEY_5 || ks == XK_5 || isLeftSoft) {
|
||||||
bool useWpn = (game.weaponChoiceIdx == 0);
|
bool useWpn = (game.weaponChoiceIdx == 0);
|
||||||
game.modal = UiModal::Idle;
|
game.modal = UiModal::Idle;
|
||||||
game.resolveMonsterCombat(game.pendingMonsterSlot,
|
game.resolveMonsterCombat(game.pendingMonsterSlot,
|
||||||
@@ -1016,7 +1050,8 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (game.modal == UiModal::RulesHelp) {
|
if (game.modal == UiModal::RulesHelp) {
|
||||||
if (isOk || isLeftSoft || isRightSoft || isEnd || ks == XK_numbersign) {
|
if (isOk || isLeftSoft || isRightSoft || isEnd ||
|
||||||
|
nkey == NEO_KEY_HASH || ks == XK_numbersign) {
|
||||||
game.modal = UiModal::Idle;
|
game.modal = UiModal::Idle;
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
@@ -1024,12 +1059,40 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (game.modal == UiModal::QuitConfirm) {
|
if (game.modal == UiModal::QuitConfirm) {
|
||||||
if (ks == XK_1 || isLeftSoft) {
|
auto execMenuOption = [&](int opt) {
|
||||||
|
if (opt == 0) {
|
||||||
|
game.modal = UiModal::Idle;
|
||||||
|
} else if (opt == 1) {
|
||||||
game.startNewGame();
|
game.startNewGame();
|
||||||
render();
|
} else if (opt == 2) {
|
||||||
} else if (ks == XK_2 || isOk || ks == XK_5 || ks == XK_q || ks == XK_Q) {
|
game.modal = UiModal::RulesHelp;
|
||||||
|
} else if (opt == 3) {
|
||||||
gRunning = 0;
|
gRunning = 0;
|
||||||
break;
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isUp) {
|
||||||
|
game.menuChoiceIdx = (game.menuChoiceIdx + 3) % 4;
|
||||||
|
render();
|
||||||
|
} else if (isDown) {
|
||||||
|
game.menuChoiceIdx = (game.menuChoiceIdx + 1) % 4;
|
||||||
|
render();
|
||||||
|
} else if (nkey == NEO_KEY_1 || ks == XK_1) {
|
||||||
|
execMenuOption(0);
|
||||||
|
render();
|
||||||
|
} else if (nkey == NEO_KEY_2 || ks == XK_2) {
|
||||||
|
execMenuOption(1);
|
||||||
|
render();
|
||||||
|
} else if (nkey == NEO_KEY_3 || ks == XK_3) {
|
||||||
|
execMenuOption(2);
|
||||||
|
render();
|
||||||
|
} else if (nkey == NEO_KEY_4 || ks == XK_4 || ks == XK_q || ks == XK_Q) {
|
||||||
|
execMenuOption(3);
|
||||||
|
} else if (isOk || nkey == NEO_KEY_5 || ks == XK_5 || isLeftSoft) {
|
||||||
|
execMenuOption(game.menuChoiceIdx);
|
||||||
|
if (gRunning) {
|
||||||
|
render();
|
||||||
|
}
|
||||||
} else if (isRightSoft || isEnd) {
|
} else if (isRightSoft || isEnd) {
|
||||||
game.modal = UiModal::Idle;
|
game.modal = UiModal::Idle;
|
||||||
render();
|
render();
|
||||||
@@ -1038,7 +1101,8 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (game.modal == UiModal::GameOver) {
|
if (game.modal == UiModal::GameOver) {
|
||||||
if (isOk || ks == XK_5 || ks == XK_1 || isLeftSoft) {
|
if (isOk || nkey == NEO_KEY_5 || ks == XK_5 ||
|
||||||
|
nkey == NEO_KEY_1 || ks == XK_1 || isLeftSoft) {
|
||||||
game.startNewGame();
|
game.startNewGame();
|
||||||
render();
|
render();
|
||||||
} else if (isRightSoft || isEnd || ks == XK_q || ks == XK_Q) {
|
} else if (isRightSoft || isEnd || ks == XK_q || ks == XK_Q) {
|
||||||
@@ -1049,7 +1113,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Normal gameplay state
|
// Normal gameplay state
|
||||||
if (ks == XK_Left) {
|
if (isLeft) {
|
||||||
for (int step = 1; step <= 4; ++step) {
|
for (int step = 1; step <= 4; ++step) {
|
||||||
int cand = (game.selectedSlot + 4 - step) % 4;
|
int cand = (game.selectedSlot + 4 - step) % 4;
|
||||||
if (game.room[cand] != 0) {
|
if (game.room[cand] != 0) {
|
||||||
@@ -1057,7 +1121,7 @@ int main() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ks == XK_Right) {
|
} else if (isRight) {
|
||||||
for (int step = 1; step <= 4; ++step) {
|
for (int step = 1; step <= 4; ++step) {
|
||||||
int cand = (game.selectedSlot + step) % 4;
|
int cand = (game.selectedSlot + step) % 4;
|
||||||
if (game.room[cand] != 0) {
|
if (game.room[cand] != 0) {
|
||||||
@@ -1065,25 +1129,26 @@ int main() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ks == XK_Up) {
|
} else if (isUp) {
|
||||||
game.selectedSlot = (game.selectedSlot + 3) % 4;
|
game.selectedSlot = (game.selectedSlot + 3) % 4;
|
||||||
} else if (ks == XK_Down) {
|
} else if (isDown) {
|
||||||
game.selectedSlot = (game.selectedSlot + 1) % 4;
|
game.selectedSlot = (game.selectedSlot + 1) % 4;
|
||||||
} else if (ks == XK_1 || ks == XK_a || ks == XK_A) {
|
} else if (nkey == NEO_KEY_1 || ks == XK_1 || ks == XK_a || ks == XK_A) {
|
||||||
game.playSlot(0);
|
game.playSlot(0);
|
||||||
} else if (ks == XK_2 || ks == XK_b || ks == XK_B) {
|
} else if (nkey == NEO_KEY_2 || ks == XK_2 || ks == XK_b || ks == XK_B) {
|
||||||
game.playSlot(1);
|
game.playSlot(1);
|
||||||
} else if (ks == XK_3 || ks == XK_c || ks == XK_C) {
|
} else if (nkey == NEO_KEY_3 || ks == XK_3 || ks == XK_c || ks == XK_C) {
|
||||||
game.playSlot(2);
|
game.playSlot(2);
|
||||||
} else if (ks == XK_4 || ks == XK_d || ks == XK_D) {
|
} else if (nkey == NEO_KEY_4 || ks == XK_4 || ks == XK_d || ks == XK_D) {
|
||||||
game.playSlot(3);
|
game.playSlot(3);
|
||||||
} else if (isOk || ks == XK_5) {
|
} else if (isOk || nkey == NEO_KEY_5 || ks == XK_5) {
|
||||||
game.playSlot(game.selectedSlot);
|
game.playSlot(game.selectedSlot);
|
||||||
} else if (ks == XK_asterisk || ks == XK_r || ks == XK_R) {
|
} else if (nkey == NEO_KEY_STAR || ks == XK_asterisk || ks == XK_r || ks == XK_R) {
|
||||||
game.runFromRoom();
|
game.runFromRoom();
|
||||||
} else if (ks == XK_0) {
|
} else if (nkey == NEO_KEY_0 || ks == XK_0) {
|
||||||
|
game.menuChoiceIdx = 0;
|
||||||
game.modal = UiModal::QuitConfirm;
|
game.modal = UiModal::QuitConfirm;
|
||||||
} else if (ks == XK_numbersign || ks == XK_h || ks == XK_H) {
|
} else if (nkey == NEO_KEY_HASH || ks == XK_numbersign || ks == XK_h || ks == XK_H) {
|
||||||
game.modal = UiModal::RulesHelp;
|
game.modal = UiModal::RulesHelp;
|
||||||
} else if (isLeftSoft) {
|
} else if (isLeftSoft) {
|
||||||
if (game.canRun && game.engaged == 0 && !game.lastRoom) {
|
if (game.canRun && game.engaged == 0 && !game.lastRoom) {
|
||||||
@@ -1092,20 +1157,14 @@ int main() {
|
|||||||
game.modal = UiModal::RulesHelp;
|
game.modal = UiModal::RulesHelp;
|
||||||
}
|
}
|
||||||
} else if (isRightSoft || isEnd || ks == XK_q || ks == XK_Q) {
|
} else if (isRightSoft || isEnd || ks == XK_q || ks == XK_Q) {
|
||||||
|
game.menuChoiceIdx = 0;
|
||||||
game.modal = UiModal::QuitConfirm;
|
game.modal = UiModal::QuitConfirm;
|
||||||
}
|
}
|
||||||
|
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gRunning) {
|
neoui_hide();
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct pollfd pfd { xfd, POLLIN, 0 };
|
|
||||||
::poll(&pfd, 1, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
neo.destroy();
|
neo.destroy();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user