Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d13f3f0

Browse files
committedFeb 8, 2024··
keymap: Add option "unlockOnPress" for LockMods action
This is an extensions to XKB. It intends to allow to deactivate CapsLock on press rather than on release, as in other platforms such as Windows.
1 parent a6057c4 commit d13f3f0

File tree

6 files changed

+32
-8
lines changed

6 files changed

+32
-8
lines changed
 

‎src/keymap.h

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ enum xkb_action_flags {
152152
ACTION_ACCEL = (1 << 8),
153153
ACTION_SAME_SCREEN = (1 << 9),
154154
ACTION_LOCK_ON_RELEASE = (1 << 10),
155+
ACTION_UNLOCK_ON_PRESS = (1 << 11),
155156
};
156157

157158
enum xkb_action_controls {

‎src/state.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,17 @@ xkb_filter_mod_lock_new(struct xkb_state *state, struct xkb_filter *filter)
395395
{
396396
filter->priv = (state->components.locked_mods &
397397
filter->action.mods.mods.mask);
398-
state->set_mods |= filter->action.mods.mods.mask;
399-
if (!(filter->action.mods.flags & ACTION_LOCK_NO_LOCK))
400-
state->components.locked_mods |= filter->action.mods.mods.mask;
398+
if (filter->priv && (filter->action.mods.flags & ACTION_UNLOCK_ON_PRESS)) {
399+
/* XKB extension: Unlock on second press */
400+
state->clear_mods |= filter->action.mods.mods.mask;
401+
if (!(filter->action.mods.flags & ACTION_LOCK_NO_UNLOCK))
402+
state->components.locked_mods &= ~filter->priv;
403+
filter->priv = 0;
404+
} else {
405+
state->set_mods |= filter->action.mods.mods.mask;
406+
if (!(filter->action.mods.flags & ACTION_LOCK_NO_LOCK))
407+
state->components.locked_mods |= filter->action.mods.mods.mask;
408+
}
401409
}
402410

403411
static bool

‎src/xkbcomp/action.c

+11-4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ enum action_field {
101101
ACTION_FIELD_KEYCODE,
102102
ACTION_FIELD_MODS_TO_CLEAR,
103103
ACTION_FIELD_LOCK_ON_RELEASE,
104+
ACTION_FIELD_UNLOCK_ON_PRESS,
104105
};
105106

106107
ActionsInfo *
@@ -168,6 +169,7 @@ static const LookupEntry fieldStrings[] = {
168169
{ "clearmods", ACTION_FIELD_MODS_TO_CLEAR },
169170
{ "clearmodifiers", ACTION_FIELD_MODS_TO_CLEAR },
170171
{ "lockOnRelease", ACTION_FIELD_LOCK_ON_RELEASE },
172+
{ "unlockOnPress", ACTION_FIELD_UNLOCK_ON_PRESS },
171173
{ NULL, 0 }
172174
};
173175

@@ -334,10 +336,15 @@ HandleSetLatchLockMods(struct xkb_context *ctx, const struct xkb_mod_set *mods,
334336
return CheckBooleanFlag(ctx, action->type, field,
335337
ACTION_LATCH_TO_LOCK, array_ndx, value,
336338
&act->flags);
337-
if (type == ACTION_TYPE_MOD_LOCK &&
338-
field == ACTION_FIELD_AFFECT)
339-
return CheckAffectField(ctx, action->type, array_ndx, value,
340-
&act->flags);
339+
if (type == ACTION_TYPE_MOD_LOCK) {
340+
if (field == ACTION_FIELD_AFFECT)
341+
return CheckAffectField(ctx, action->type, array_ndx, value,
342+
&act->flags);
343+
if (field == ACTION_FIELD_UNLOCK_ON_PRESS)
344+
return CheckBooleanFlag(ctx, action->type, field,
345+
ACTION_UNLOCK_ON_PRESS, array_ndx, value,
346+
&act->flags);
347+
}
341348

342349
return ReportIllegal(ctx, action->type, field);
343350
}

‎src/xkbcomp/keymap-dump.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,11 @@ write_action(struct xkb_keymap *keymap, struct buf *buf,
316316
else
317317
args = ModMaskText(keymap->ctx, &keymap->mods,
318318
action->mods.mods.mods);
319-
write_buf(buf, "%s%s(modifiers=%s%s%s%s)%s", prefix, type, args,
319+
write_buf(buf, "%s%s(modifiers=%s%s%s%s%s)%s", prefix, type, args,
320320
(action->type != ACTION_TYPE_MOD_LOCK && (action->mods.flags & ACTION_LOCK_CLEAR)) ? ",clearLocks" : "",
321321
(action->type != ACTION_TYPE_MOD_LOCK && (action->mods.flags & ACTION_LATCH_TO_LOCK)) ? ",latchToLock" : "",
322322
(action->type == ACTION_TYPE_MOD_LOCK) ? affect_lock_text(action->mods.flags, false) : "",
323+
(action->type == ACTION_TYPE_MOD_LOCK && (action->mods.flags & ACTION_UNLOCK_ON_PRESS)) ? ",unlockOnPress" : "",
323324
suffix);
324325
break;
325326

‎test/data/compat/caps

+6
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ partial xkb_compatibility "caps_lock" {
99
action = LockMods(modifiers = Lock);
1010
};
1111
};
12+
13+
partial xkb_compatibility "caps_lock_unlock_on_press" {
14+
interpret Caps_Lock {
15+
action = LockMods(modifiers = Lock, unlockOnPress);
16+
};
17+
};

‎test/data/rules/evdev

+1
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,7 @@
11601160
mod_led:compose = +ledcompose(compose)
11611161
japan:kana_lock = +japan(kana_lock)
11621162
caps:shiftlock = +ledcaps(shift_lock)
1163+
caps:unlock_on_press = +caps(caps_lock_unlock_on_press)
11631164
grab:break_actions = +xfree86(grab_break)
11641165

11651166

0 commit comments

Comments
 (0)
Please sign in to comment.