aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-26 16:28:04 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-26 16:51:53 +0200
commit48122df00c55d314fe59eb2d5c32dad8455696ca (patch)
tree162a112f259cf443566de943d1ad0e98928d3ab4 /src
parent5809819063c7822ba197297090b304fb905ad89c (diff)
downloadjwm-48122df00c55d314fe59eb2d5c32dad8455696ca.tar.gz
Don't keep menu open after release unless arrow keys are set
I am personally partial to this Mac-like behavior, as it avoids introducing a modality to the user interface, which is almost always annoying. If menus are kept open after button release, then the user is left in a different mode than earlier, in which key presses are not sent to the active window, but to the active menu. This is sometimes useful, but more often than not annoying.
Diffstat (limited to 'src')
-rw-r--r--src/key.c24
-rw-r--r--src/key.h2
-rw-r--r--src/menu.c12
3 files changed, 33 insertions, 5 deletions
diff --git a/src/key.c b/src/key.c
index 5cedd3d..4f0f146 100644
--- a/src/key.c
+++ b/src/key.c
@@ -485,6 +485,30 @@ ValidateKeys()
}
+/** Return true if arrow keys are defined. */
+int
+HasArrowKeys()
+{
+ KeyNode *kp;
+ static int r = -1;
+
+ if(r != -1) {
+ return r;
+ }
+
+ for(kp = bindings; kp; kp = kp->next) {
+ if((kp->key & 0xFF) == KEY_UP
+ || (kp->key & 0xFF) == KEY_DOWN
+ || (kp->key & 0xFF) == KEY_RIGHT
+ || (kp->key & 0xFF) == KEY_LEFT) {
+ r = 1;
+ return 1;
+ }
+ }
+ r = 0;
+ return 0;
+}
+
/** Return true if the key event matches any switching key or its modifiers. */
int
Switching(const XKeyEvent *event)
diff --git a/src/key.h b/src/key.h
index 985d7bc..8add1e2 100644
--- a/src/key.h
+++ b/src/key.h
@@ -58,6 +58,8 @@ void ShowKeyMenu(const XKeyEvent *event);
void ValidateKeys();
+int HasArrowKeys();
+
int Switching(const XKeyEvent *event);
#endif
diff --git a/src/menu.c b/src/menu.c
index f65e2c4..997111c 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -281,13 +281,15 @@ MenuLoop(Menu *menu)
if(event.xbutton.button == Button5) {
break;
}
- if(!hadMotion) {
- break;
- }
- if(abs(event.xbutton.x_root - pressx) < doubleClickDelta) {
- if(abs(event.xbutton.y_root - pressy) < doubleClickDelta) {
+ if(HasArrowKeys()) {
+ if(!hadMotion) {
break;
}
+ if(abs(event.xbutton.x_root - pressx) < doubleClickDelta) {
+ if(abs(event.xbutton.y_root - pressy) < doubleClickDelta) {
+ break;
+ }
+ }
}
if(menu->currentIndex >= 0) {