Commit 2a0c538c authored by Peter Hutterer's avatar Peter Hutterer
Browse files

gitlab CI: check for new XF86 keysyms in the xorgproto repo

xorgproto 2021.2 and later has a recognizable pattern for adding new keysyms
to XF86keysym.h based on the Linux kernel input-event-codes.h. Use this to
detect any keysyms that are present in the header file but not yet in
symbols/inet.

This is merely a gitlab CI job as we only have to do an actual update once
every few months or so. A git diff is sufficient here too, it contains all the
information we will need to understand what is missing from the updated file.

We check xorgproto master because that gives us some heads-up on what will
come. There is a minor chance that we are mapping keycodes that change before
the release but it's minor and fixable anyway.

Requires: xorg/proto/xorgproto!23

Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
parent 5ca9f8ae
......@@ -178,6 +178,27 @@ evdev keycode check:
- keycodes/evdev
needs: ['container-prep']
# Checks for new keysyms to be added to symbols/inet (using xorgproto master)
evdev keysym check (xorgproto master):
extends:
- .default_setup
stage: test
script:
# Check out the latest xorgproto tag
- git clone https://gitlab.freedesktop.org/xorg/proto/xorgproto
- .gitlab-ci/generate-evdev-keysyms.py --header xorgproto/include/X11/XF86keysym.h
- git diff --exit-code || (echo "New keysyms available, please update symbols/inet" && false)
allow_failure: true
artifacts:
when: on_failure
name: Updated inet keysyms
expire_in: 2 weeks
paths:
- symbols/inet
needs: ['container-prep']
xmllint:
extends:
- .default_setup
......
#!/usr/bin/env python3
#
# Usage: generate-evdev-keysyms.py symbols/inet.in > symbols/inet
#
# Generate the symbols/inet file from the names defined in
# linux/input-event-codes.h
#
# Note that this script relies on libevdev to provide the key names and
# those are compiled in. Ensure you have a recent-enough libevdev to
# generate this list.
#
import contextlib
import argparse
import re
import sys
# The marker to search for in the template file, replaced with our generated
# codes.
replacement_marker = "@evdevsyms@"
# These markers are put into the result file and are used to detect
# the section that we added when parsing an existing file.
section_header = "Key symbol mappings below are autogenerated"
section_footer = "End of autogenerated key symbol mappings"
def existing_keysyms(template):
"""
Return an iterator of type (keycode, [keysym, keysym]) with the strings
representing the internal keycode (e.g. I123) and the assigned keysyms.
Only the "evdev" xkb_symbols section is parsed.
"""
start_pattern = re.compile(r"xkb_symbols \"evdev\" {")
end_pattern = re.compile(r"^};")
# This does not handle multiline keysyms
keysym_pattern = re.compile(
r"\s+key \<(?P<keycode>\w+)\>\s+{\s+\[(?P<keysyms>[^]]+)\s*\]\s*};"
)
in_evdev = False
template.seek(0)
for line in template.readlines():
if re.match(start_pattern, line):
in_evdev = True
continue
if in_evdev:
if re.match(end_pattern, line):
break
match = re.match(keysym_pattern, line)
if match:
keycode = match.group("keycode")
keysyms = [k.strip() for k in match.group("keysyms").split(",")]
yield keycode, keysyms
def xorgproto_evdev_keysyms(header):
"""
Return an iterator of type ('XF86Foo', xkeycode, kernelname) for the keysyms in the
given header file (usually XF86keysym.h).
The returned xkeycode is the X keycode value (i.e. kernel value + 8)
"""
# The two allowed formats in the proto header are:
# #define XF86XK_FooBar _EVDEVK(0x123) ... KEY_FOOBAR
# /* Use: XF86XK_FooBar _EVDEVK(0x123) ... KEY_FOOBAR
# The keysym may not start with XF86XK_ (e.g. "dollar" or "euro")
pattern = re.compile(
r"(#define|/\* Use:)\s(?P<keyname>\w+)\s+_EVDEVK\(0x(?P<keycode>[0-9A-Fa-f]+)\).*(?P<kernelname>KEY_\w+)"
)
for line in header:
match = re.match(pattern, line)
if match:
kernelname = match.group("kernelname")
keyname = match.group("keyname").replace("XK_", "")
keycode = int(match.group("keycode"), 16)
xkeycode = keycode + 8
yield keyname, xkeycode, kernelname
def generate_symbols_file(template, header):
"""
Generate a new symbols/inet file with line containing @evdevsyms@
replaced by the full list of evdev keysym mappings, including our
section_header/footer. Expected output: ::
// $section_header
key <I$keycode> { [ XF86Foo ] }; // KEY_FOO
// key <I$keycode> { if assignment already exists }; // KEY_FOO
...
// $section_footer
Assignments that already exist in the file are commented out.
"""
# We only care about the I123-style keysyms here
keysyms = {
int(kc[1:])
for kc, _ in existing_keysyms(template)
if re.match(r"I[0-9]{3}", kc)
}
output = []
template.seek(0)
for line in template.readlines():
if replacement_marker not in line:
output.append(line)
continue
output.append(f" // {section_header}\n")
for name, xkeycode, kernelname in xorgproto_evdev_keysyms(header):
if xkeycode in keysyms:
prefix = "//"
else:
prefix = " "
output.append(
f"{prefix} key <I{xkeycode}> {{ [ {name:30s} ] }}; // {kernelname}\n"
)
output.append(f" // {section_footer}\n")
return output
def main():
parser = argparse.ArgumentParser(description="Generate the evdev symbol lists.")
parser.add_argument(
"--template",
type=argparse.FileType("r"),
default="symbols/inet.in",
help="The template file, usually symbols/inet.in",
)
parser.add_argument(
"--header",
type=argparse.FileType("r"),
help="Path to the XF86keysym.h header file",
default="/usr/include/X11/XF86keysym.h",
)
parser.add_argument(
"--output",
type=str,
help="The file to be written to, usually symbols/inet",
default="symbols/inet",
)
ns = parser.parse_args()
with contextlib.ExitStack() as stack:
if ns.output == "-":
fd = sys.stdout
else:
fd = stack.enter_context(open(ns.output, "w"))
output = generate_symbols_file(ns.template, ns.header)
fd.write("".join(output))
if __name__ == "__main__":
main()
......@@ -230,6 +230,201 @@ xkb_symbols "evdev" {
key <FK16> { [ XF86Launch7 ] };
key <FK17> { [ XF86Launch8 ] };
key <FK18> { [ XF86Launch9 ] };
// Key symbol mappings below are autogenerated
// key <I170> { [ XF86Eject ] }; // KEY_EJECTCLOSECD
// key <I189> { [ XF86New ] }; // KEY_NEW
// key <I190> { [ Redo ] }; // KEY_REDO
// key <I212> { [ XF86LaunchB ] }; // KEY_DASHBOARD
key <I235> { [ XF86Display ] }; // KEY_SWITCHVIDEOMODE
key <I236> { [ XF86KbdLightOnOff ] }; // KEY_KBDILLUMTOGGLE
key <I237> { [ XF86KbdBrightnessDown ] }; // KEY_KBDILLUMDOWN
key <I238> { [ XF86KbdBrightnessUp ] }; // KEY_KBDILLUMUP
// key <I239> { [ XF86Send ] }; // KEY_SEND
// key <I240> { [ XF86Reply ] }; // KEY_REPLY
// key <I241> { [ XF86MailForward ] }; // KEY_FORWARDMAIL
// key <I242> { [ XF86Save ] }; // KEY_SAVE
// key <I243> { [ XF86Documents ] }; // KEY_DOCUMENTS
// key <I244> { [ XF86Battery ] }; // KEY_BATTERY
// key <I245> { [ XF86Bluetooth ] }; // KEY_BLUETOOTH
// key <I246> { [ XF86WLAN ] }; // KEY_WLAN
key <I247> { [ XF86UWB ] }; // KEY_UWB
key <I249> { [ XF86Next_VMode ] }; // KEY_VIDEO_NEXT
key <I250> { [ XF86Prev_VMode ] }; // KEY_VIDEO_PREV
// key <I251> { [ XF86MonBrightnessCycle ] }; // KEY_BRIGHTNESS_CYCLE
key <I252> { [ XF86BrightnessAuto ] }; // KEY_BRIGHTNESS_AUTO
key <I253> { [ XF86DisplayOff ] }; // KEY_DISPLAY_OFF
// key <I254> { [ XF86WWAN ] }; // KEY_WWAN
// key <I255> { [ XF86RFKill ] }; // KEY_RFKILL
key <I256> { [ XF86AudioMicMute ] }; // KEY_MICMUTE
key <I366> { [ XF86Info ] }; // KEY_INFO
key <I379> { [ XF86CycleAngle ] }; // KEY_ANGLE
// key <I380> { [ XF86FullScreen ] }; // KEY_FULL_SCREEN
key <I383> { [ XF86AspectRatio ] }; // KEY_ASPECT_RATIO
key <I397> { [ XF86DVD ] }; // KEY_DVD
key <I400> { [ XF86Audio ] }; // KEY_AUDIO
key <I401> { [ XF86Video ] }; // KEY_VIDEO
key <I405> { [ XF86Calendar ] }; // KEY_CALENDAR
key <I410> { [ XF86ChannelUp ] }; // KEY_CHANNELUP
key <I411> { [ XF86ChannelDown ] }; // KEY_CHANNELDOWN
key <I418> { [ XF86AudioRandomPlay ] }; // KEY_SHUFFLE
key <I419> { [ XF86Break ] }; // KEY_BREAK
key <I424> { [ XF86VideoPhone ] }; // KEY_VIDEOPHONE
key <I425> { [ XF86Game ] }; // KEY_GAMES
key <I426> { [ XF86ZoomIn ] }; // KEY_ZOOMIN
key <I427> { [ XF86ZoomOut ] }; // KEY_ZOOMOUT
key <I428> { [ XF86ZoomReset ] }; // KEY_ZOOMRESET
key <I429> { [ XF86Word ] }; // KEY_WORDPROCESSOR
key <I430> { [ XF86Editor ] }; // KEY_EDITOR
key <I431> { [ XF86Excel ] }; // KEY_SPREADSHEET
key <I432> { [ XF86GraphicsEditor ] }; // KEY_GRAPHICSEDITOR
key <I433> { [ XF86Presentation ] }; // KEY_PRESENTATION
key <I434> { [ XF86Database ] }; // KEY_DATABASE
key <I435> { [ XF86News ] }; // KEY_NEWS
key <I436> { [ XF86Voicemail ] }; // KEY_VOICEMAIL
key <I437> { [ XF86Addressbook ] }; // KEY_ADDRESSBOOK
key <I438> { [ XF86Messenger ] }; // KEY_MESSENGER
key <I439> { [ XF86DisplayToggle ] }; // KEY_DISPLAYTOGGLE
key <I440> { [ XF86SpellCheck ] }; // KEY_SPELLCHECK
key <I441> { [ XF86LogOff ] }; // KEY_LOGOFF
// key <I442> { [ dollar ] }; // KEY_DOLLAR
// key <I443> { [ EuroSign ] }; // KEY_EURO
key <I444> { [ XF86FrameBack ] }; // KEY_FRAMEBACK
key <I445> { [ XF86FrameForward ] }; // KEY_FRAMEFORWARD
key <I446> { [ XF86ContextMenu ] }; // KEY_CONTEXT_MENU
key <I447> { [ XF86MediaRepeat ] }; // KEY_MEDIA_REPEAT
key <I448> { [ XF8610ChannelsUp ] }; // KEY_10CHANNELSUP
key <I449> { [ XF8610ChannelsDown ] }; // KEY_10CHANNELSDOWN
key <I450> { [ XF86Images ] }; // KEY_IMAGES
key <I452> { [ XF86NotificationCenter ] }; // KEY_NOTIFICATION_CENTER
key <I453> { [ XF86PickupPhone ] }; // KEY_PICKUP_PHONE
key <I454> { [ XF86HangupPhone ] }; // KEY_HANGUP_PHONE
key <I472> { [ XF86Fn ] }; // KEY_FN
key <I473> { [ XF86Fn_Esc ] }; // KEY_FN_ESC
key <I493> { [ XF86FnRightShift ] }; // KEY_FN_RIGHT_SHIFT
key <I505> { [ braille_dot_1 ] }; // KEY_BRL_DOT1
key <I506> { [ braille_dot_2 ] }; // KEY_BRL_DOT2
key <I507> { [ braille_dot_3 ] }; // KEY_BRL_DOT3
key <I508> { [ braille_dot_4 ] }; // KEY_BRL_DOT4
key <I509> { [ braille_dot_5 ] }; // KEY_BRL_DOT5
key <I510> { [ braille_dot_6 ] }; // KEY_BRL_DOT6
key <I511> { [ braille_dot_7 ] }; // KEY_BRL_DOT7
key <I512> { [ braille_dot_8 ] }; // KEY_BRL_DOT8
key <I513> { [ braille_dot_9 ] }; // KEY_BRL_DOT9
key <I514> { [ braille_dot_1 ] }; // KEY_BRL_DOT10
key <I520> { [ XF86Numeric0 ] }; // KEY_NUMERIC_0
key <I521> { [ XF86Numeric1 ] }; // KEY_NUMERIC_1
key <I522> { [ XF86Numeric2 ] }; // KEY_NUMERIC_2
key <I523> { [ XF86Numeric3 ] }; // KEY_NUMERIC_3
key <I524> { [ XF86Numeric4 ] }; // KEY_NUMERIC_4
key <I525> { [ XF86Numeric5 ] }; // KEY_NUMERIC_5
key <I526> { [ XF86Numeric6 ] }; // KEY_NUMERIC_6
key <I527> { [ XF86Numeric7 ] }; // KEY_NUMERIC_7
key <I528> { [ XF86Numeric8 ] }; // KEY_NUMERIC_8
key <I529> { [ XF86Numeric9 ] }; // KEY_NUMERIC_9
key <I530> { [ XF86NumericStar ] }; // KEY_NUMERIC_STAR
key <I531> { [ XF86NumericPound ] }; // KEY_NUMERIC_POUND
key <I532> { [ XF86NumericA ] }; // KEY_NUMERIC_A
key <I533> { [ XF86NumericB ] }; // KEY_NUMERIC_B
key <I534> { [ XF86NumericC ] }; // KEY_NUMERIC_C
key <I535> { [ XF86NumericD ] }; // KEY_NUMERIC_D
key <I536> { [ XF86CameraFocus ] }; // KEY_CAMERA_FOCUS
key <I537> { [ XF86WPSButton ] }; // KEY_WPS_BUTTON
key <I538> { [ XF86TouchpadToggle ] }; // KEY_TOUCHPAD_TOGGLE
key <I539> { [ XF86TouchpadOn ] }; // KEY_TOUCHPAD_ON
key <I540> { [ XF86TouchpadOff ] }; // KEY_TOUCHPAD_OFF
key <I541> { [ XF86CameraZoomIn ] }; // KEY_CAMERA_ZOOMIN
key <I542> { [ XF86CameraZoomOut ] }; // KEY_CAMERA_ZOOMOUT
key <I543> { [ XF86CameraUp ] }; // KEY_CAMERA_UP
key <I544> { [ XF86CameraDown ] }; // KEY_CAMERA_DOWN
key <I545> { [ XF86CameraLeft ] }; // KEY_CAMERA_LEFT
key <I546> { [ XF86CameraRight ] }; // KEY_CAMERA_RIGHT
key <I547> { [ XF86AttendantOn ] }; // KEY_ATTENDANT_ON
key <I548> { [ XF86AttendantOff ] }; // KEY_ATTENDANT_OFF
key <I549> { [ XF86AttendantToggle ] }; // KEY_ATTENDANT_TOGGLE
key <I550> { [ XF86LightsToggle ] }; // KEY_LIGHTS_TOGGLE
key <I568> { [ XF86ALSToggle ] }; // KEY_ALS_TOGGLE
// key <I569> { [ XF86RotationLockToggle ] }; // KEY_ROTATE_LOCK_TOGGLE
key <I584> { [ XF86Buttonconfig ] }; // KEY_BUTTONCONFIG
key <I585> { [ XF86Taskmanager ] }; // KEY_TASKMANAGER
key <I586> { [ XF86Journal ] }; // KEY_JOURNAL
key <I587> { [ XF86ControlPanel ] }; // KEY_CONTROLPANEL
key <I588> { [ XF86AppSelect ] }; // KEY_APPSELECT
key <I589> { [ XF86Screensaver ] }; // KEY_SCREENSAVER
key <I590> { [ XF86VoiceCommand ] }; // KEY_VOICECOMMAND
key <I591> { [ XF86Assistant ] }; // KEY_ASSISTANT
key <I592> { [ ISO_Next_Group ] }; // KEY_KBD_LAYOUT_NEXT
key <I600> { [ XF86BrightnessMin ] }; // KEY_BRIGHTNESS_MIN
key <I601> { [ XF86BrightnessMax ] }; // KEY_BRIGHTNESS_MAX
key <I616> { [ XF86KbdInputAssistPrev ] }; // KEY_KBDINPUTASSIST_PREV
key <I617> { [ XF86KbdInputAssistNext ] }; // KEY_KBDINPUTASSIST_NEXT
key <I618> { [ XF86KbdInputAssistPrevgroup ] }; // KEY_KBDINPUTASSIST_PREVGROUP
key <I619> { [ XF86KbdInputAssistNextgroup ] }; // KEY_KBDINPUTASSIST_NEXTGROUP
key <I620> { [ XF86KbdInputAssistAccept ] }; // KEY_KBDINPUTASSIST_ACCEPT
key <I621> { [ XF86KbdInputAssistCancel ] }; // KEY_KBDINPUTASSIST_CANCEL
key <I622> { [ XF86RightUp ] }; // KEY_RIGHT_UP
key <I623> { [ XF86RightDown ] }; // KEY_RIGHT_DOWN
key <I624> { [ XF86LeftUp ] }; // KEY_LEFT_UP
key <I625> { [ XF86LeftDown ] }; // KEY_LEFT_DOWN
key <I626> { [ XF86RootMenu ] }; // KEY_ROOT_MENU
key <I627> { [ XF86MediaTopMenu ] }; // KEY_MEDIA_TOP_MENU
key <I628> { [ XF86Numeric11 ] }; // KEY_NUMERIC_11
key <I629> { [ XF86Numeric12 ] }; // KEY_NUMERIC_12
key <I630> { [ XF86AudioDesc ] }; // KEY_AUDIO_DESC
key <I631> { [ XF863DMode ] }; // KEY_3D_MODE
key <I632> { [ XF86NextFavorite ] }; // KEY_NEXT_FAVORITE
key <I633> { [ XF86StopRecord ] }; // KEY_STOP_RECORD
key <I634> { [ XF86PauseRecord ] }; // KEY_PAUSE_RECORD
key <I635> { [ XF86VOD ] }; // KEY_VOD
key <I636> { [ XF86Unmute ] }; // KEY_UNMUTE
key <I637> { [ XF86FastReverse ] }; // KEY_FASTREVERSE
key <I638> { [ XF86SlowReverse ] }; // KEY_SLOWREVERSE
key <I639> { [ XF86Data ] }; // KEY_DATA
key <I640> { [ XF86OnScreenKeyboard ] }; // KEY_ONSCREEN_KEYBOARD
key <I641> { [ XF86PrivacyScreenToggle ] }; // KEY_PRIVACY_SCREEN_TOGGLE
key <I642> { [ XF86SelectiveScreenshot ] }; // KEY_SELECTIVE_SCREENSHOT
key <I664> { [ XF86Macro1 ] }; // KEY_MACRO1
key <I665> { [ XF86Macro2 ] }; // KEY_MACRO2
key <I666> { [ XF86Macro3 ] }; // KEY_MACRO3
key <I667> { [ XF86Macro4 ] }; // KEY_MACRO4
key <I668> { [ XF86Macro5 ] }; // KEY_MACRO5
key <I669> { [ XF86Macro6 ] }; // KEY_MACRO6
key <I670> { [ XF86Macro7 ] }; // KEY_MACRO7
key <I671> { [ XF86Macro8 ] }; // KEY_MACRO8
key <I672> { [ XF86Macro9 ] }; // KEY_MACRO9
key <I673> { [ XF86Macro10 ] }; // KEY_MACRO10
key <I674> { [ XF86Macro11 ] }; // KEY_MACRO11
key <I675> { [ XF86Macro12 ] }; // KEY_MACRO12
key <I676> { [ XF86Macro13 ] }; // KEY_MACRO13
key <I677> { [ XF86Macro14 ] }; // KEY_MACRO14
key <I678> { [ XF86Macro15 ] }; // KEY_MACRO15
key <I679> { [ XF86Macro16 ] }; // KEY_MACRO16
key <I680> { [ XF86Macro17 ] }; // KEY_MACRO17
key <I681> { [ XF86Macro18 ] }; // KEY_MACRO18
key <I682> { [ XF86Macro19 ] }; // KEY_MACRO19
key <I683> { [ XF86Macro20 ] }; // KEY_MACRO20
key <I684> { [ XF86Macro21 ] }; // KEY_MACRO21
key <I685> { [ XF86Macro22 ] }; // KEY_MACRO22
key <I686> { [ XF86Macro23 ] }; // KEY_MACRO23
key <I687> { [ XF86Macro24 ] }; // KEY_MACRO24
key <I688> { [ XF86Macro25 ] }; // KEY_MACRO25
key <I689> { [ XF86Macro26 ] }; // KEY_MACRO26
key <I690> { [ XF86Macro27 ] }; // KEY_MACRO27
key <I691> { [ XF86Macro28 ] }; // KEY_MACRO28
key <I692> { [ XF86Macro29 ] }; // KEY_MACRO29
key <I693> { [ XF86Macro30 ] }; // KEY_MACRO30
key <I696> { [ XF86MacroRecordStart ] }; // KEY_MACRO_RECORD_START
key <I697> { [ XF86MacroRecordStop ] }; // KEY_MACRO_RECORD_STOP
key <I698> { [ XF86MacroPresetCycle ] }; // KEY_MACRO_PRESET_CYCLE
key <I699> { [ XF86MacroPreset1 ] }; // KEY_MACRO_PRESET1
key <I700> { [ XF86MacroPreset2 ] }; // KEY_MACRO_PRESET2
key <I701> { [ XF86MacroPreset3 ] }; // KEY_MACRO_PRESET3
key <I704> { [ XF86KbdLcdMenu1 ] }; // KEY_KBD_LCD_MENU1
key <I705> { [ XF86KbdLcdMenu2 ] }; // KEY_KBD_LCD_MENU2
key <I706> { [ XF86KbdLcdMenu3 ] }; // KEY_KBD_LCD_MENU3
key <I707> { [ XF86KbdLcdMenu4 ] }; // KEY_KBD_LCD_MENU4
key <I708> { [ XF86KbdLcdMenu5 ] }; // KEY_KBD_LCD_MENU5
// End of autogenerated key symbol mappings
};
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment