Download raw body.
akbd(4) fn/special keys behavior
Hello. I found the need to get an older ibook G4 (A1054, or
PowerBook 6,5) to set the behavior of fn vs special keys directly
from OpenBSD.
In OSX, this is easily changed in system preferences, but I don't
have an easy way to do that (I have no battery and the setting
is reset when power is completely cut).
Therefore, I decided to implement it in akbd(4). I am not sure if
it would be desirable to create a sysctl for this, at the moment
I just hardcoded during attach. I followed setleds above, along
with pbbuttonsd.
I also in passing tried to make setleds work, but it seems perhaps
it was meant for other keyboards different than this powerbook's
I'd just like to share it here on the list, not really sure
everyone want or need this, but if you don't have an OSX install,
it might come in handy.
All the best
P.S. In my opinion the last check in setleds is wrong, it should
check the last 3 bits and it does the opposite. Rather irrelevant
as this is not compiled anyways.
P.S.2 Would there be any interest to bring hidkbd to akbd?
Index: dev/adb/akbd.c
===================================================================
RCS file: /cvs/src/sys/dev/adb/akbd.c,v
retrieving revision 1.16
diff -u -p -r1.16 akbd.c
--- dev/adb/akbd.c 21 Oct 2022 22:42:36 -0000 1.16
+++ dev/adb/akbd.c 25 Jun 2024 05:42:22 -0000
@@ -93,6 +93,7 @@ u_char getleds(int);
int setleds(struct akbd_softc *, u_char);
void blinkleds(struct akbd_softc *);
#endif
+int setfnmode(struct akbd_softc *, int);
int
akbdmatch(struct device *parent, void *vcf, void *aux)
@@ -226,6 +227,7 @@ akbdattach(struct device *parent, struct
break;
case ADB_PBG4KBD:
printf("PowerBook G4 keyboard (Inverted T)\n");
+ setfnmode(sc, 1);
break;
case ADB_IBITISOKBD:
printf("iBook keyboard with inverted T (ISO layout)\n");
@@ -373,6 +375,41 @@ blinkleds(struct akbd_softc *sc)
sc->sc_leds |= WSKBD_LED_SCROLL;
}
#endif
+
+/*
+ * Set the behavior of the fn keys. By default, they act
+ * as special keys e.g. brightness, not as f1-f7 keys.
+ */
+int
+setfnmode(struct akbd_softc *sc, int on)
+{
+ int addr;
+ short cmd;
+ u_char buffer[9];
+
+ addr = sc->adbaddr;
+ buffer[0] = 0;
+
+ cmd = ADBTALK(addr, 1);
+ if (adb_op_sync((Ptr)buffer, cmd) || buffer[0] == 0)
+ return (EIO);
+
+ on = (on == 0) ? 0 : 1; /* make sure on is either 0 or 1 */
+ buffer[2] &= 0xfe;
+ buffer[2] |= on;
+
+ cmd = ADBLISTEN(addr, 1);
+ adb_op_sync((Ptr)buffer, cmd);
+
+ cmd = ADBTALK(addr, 1);
+ if (adb_op_sync((Ptr)buffer, cmd) || buffer[0] == 0)
+ return (EIO);
+
+ if ((buffer[2] & 0x1) != on)
+ return (EIO);
+ else
+ return (0);
+}
int
akbd_enable(void *v, int on)
akbd(4) fn/special keys behavior