Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
petitstrawberry committed Aug 23, 2024
2 parents 6ecf1ba + 1846e16 commit f3e068e
Show file tree
Hide file tree
Showing 20 changed files with 494 additions and 221 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TARGETS = common trackpointerd keyboardd tabletmoded
TARGETS = common moused keyboardd tabletmoded

.PHONY: all clean install uninstall $(TARGETS)

Expand Down
95 changes: 71 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,93 @@
# minibook-support
Softwares for CHUWI MiniBook (8-inch UMPC)
Softwares for CHUWI MiniBook (8-inch) / MiniBook X (10-inch) running Linux

## Softwares
- Enable the tablet mode of the MiniBook / MiniBook X automatically when the MiniBook is folded.
- Calibrate the trackpointer of the MiniBook (8-inch).

- [x] trackpointerd
- [x] keyboardd
- [x] tabletmoded
## Requirements

### trackpointerd
- CHUWI MiniBook / MiniBook X
- Linux 6.9 or later
- Needed for MiniBook X

Trackpointerd is a daemon that manages the trackpointer of the MiniBook.
### Dependencies

- Calibrate the trackpointer
- Switch enable/disable the trackpointer
- base-devel
- for Arch Linux
- build-essential
- for Debian-based Linux

### keyboardd
For other Linux distributions, please install the equivalent packages.

Keyboardd is a daemon that manages the keyboard of the MiniBook.
### Tested on

- Switch enable/disable the keyboard
- MiniBook (8-inch)
- Arch Linux
- Linux 6.10.5-arch1-1
- MiniBook X (10-inch)
- Ubuntu 24.04
- Linux 6.10.6

## Installation

```bash
git clone https://github.com/petitstrawberry/minibook-support.git
cd minibook-support
make
sudo make install
```

## Softwares

- [x] tabletmoded
- [x] moused
- [x] keyboardd

### tabletmoded

Tabletmoded is a daemon that triggers the tablet mode of the MiniBook.
tabletmoded is a daemon that triggers the tablet mode of the MiniBook.

- Auto detect the tablet mode
- Switch enable/disable the tablet mode
- Trigger the tablet mode when the MiniBook is folded
- Untrigger the tablet mode when the MiniBook is unfolded
- Disable the keyboard using keyboardd when the tablet mode is triggered and enable the keyboard when the tablet mode is untriggered
- Disable the trackpointer using trackpointerd when the tablet mode is triggered and enable the trackpointer when the tablet mode is untriggered
- Disable the mouse using moused when the tablet mode is triggered and enable the mouse when the tablet mode is untriggered

## Requirements
### moused

- CHUWI MiniBook (8-inch UMPC)
- Linux
moused is a daemon that manages the trackpointer / trackpad of the MiniBook.

## Installation
- Calibrate the trackpointer / trackpad
- Switch enable/disable the trackpointer / trackpad

```bash
git clone https://github.com/petitstrawberry/minibook-support.git
cd minibook-support
make
sudo make install
```
### keyboardd

keyboardd is a daemon that manages the keyboard of the MiniBook.

- Switch enable/disable the keyboard

## Mechanism

mousedd / keyboardd create virtual devices that pass through input events received from the moused / keyboard. By enabling and disabling this pass-through functionality, you can stop and enable these devices. It is also possible to process the values if necessary (e.g. calibration of the track pointer with moused).

tabletmoded calculates the open/close angle of the screen based on the values of the two accelerometers built into the main unit, and determines whether the PC is in tablet mode or not based on the angle. When it is determined that the PC is in tablet mode, it disables the mouse and keyboard devices using moused and keyboardd. Furthermore, it issues an event (SW_TABLET_MODE) to enable the tablet mode by the created virtual device, and notifies the whole system that the PC is in the tablet mode. Depending on the desktop environment, the behavior will change for tablets (e.g., GNOME will enable the on-screen keyboard).

This mechanism can be abused by keyloggers, etc., but of course we do not do any such processing, and you can check the source code if necessary.


## License

MIT License

Copyright (c) 2024 petitstrawberry

Please see [LICENSE](LICENSE) for more information.

## Credits

Debugging and testing on MiniBook X.

Thanks to:
- [8796n](https://github.com/8796n)
- [kat0h](https://github.com/kat0h)
8 changes: 8 additions & 0 deletions common/include/device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _DEVICE_H_
#define _DEVICE_H_

#include <stdio.h>

void get_device_model(char *device_model, size_t size);

#endif
3 changes: 3 additions & 0 deletions common/include/vdevice.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
// Emit the event
void emit(int fd, int type, int code, int value);

// Clone the enabled event types and codes of the device
void clone_enabled_event_types_and_codes(int fd, int fd_clone);
10 changes: 10 additions & 0 deletions common/src/device.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdio.h>

void get_device_model(char *device_model, size_t size) {
FILE *fp = fopen("/sys/devices/virtual/dmi/id/product_name", "r");
if (fp == NULL) {
return;
}
fgets(device_model, size, fp);
fclose(fp);
}
69 changes: 69 additions & 0 deletions common/src/vdevice.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include <fcntl.h>
#include <linux/uinput.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "debug.h"

// Emit the event
void emit(int fd, int type, int code, int value) {
struct input_event event = {.type = type, .code = code, .value = value};
Expand All @@ -9,3 +14,67 @@ void emit(int fd, int type, int code, int value) {
event.time.tv_usec = 0;
write(fd, &event, sizeof(event));
}

// Check if the bit is enabled
int is_enabled_bit(u_int8_t *bits, int bit) {
return (bits[bit / 8] & (1 << (bit % 8))) > 0;
}

// Clone the enabled event types and codes of the device
void clone_enabled_event_types_and_codes(int fd, int fd_clone) {
debug_printf("Making the clone of the device\n");
// Get the event types
u_int8_t event_types[EV_MAX / 8 + 1];
memset(event_types, 0, sizeof(event_types));
ioctl(fd, EVIOCGBIT(0, sizeof(event_types)), event_types);

for (int event_type = 1; event_type < EV_MAX; event_type++) {
if (is_enabled_bit(event_types, event_type)) {
debug_printf("event_type: %d\n", event_type);
ioctl(fd_clone, UI_SET_EVBIT, event_type);

// Get the event codes
u_int8_t event_codes[KEY_MAX / 8 + 1];
memset(event_codes, 0, sizeof(event_codes));
ioctl(fd, EVIOCGBIT(event_type, sizeof(event_codes)), event_codes);

for (int event_code = 0; event_code < KEY_MAX; event_code++) {
if (is_enabled_bit(event_codes, event_code)) {
debug_printf(" code: %d\n", event_code);

ioctl(fd_clone,
_IOW(UINPUT_IOCTL_BASE, 100 + event_type, int),
event_code);
// Setup the abs values
if (event_type == EV_ABS) {
// Get the abs info
struct input_absinfo absinfo;
memset(&absinfo, 0, sizeof(absinfo));
if (ioctl(fd, EVIOCGABS(event_code), &absinfo) < 0) {
perror("ioctl: EVIOCGABS");
}

// Print the abs info
debug_printf(" absinfo: \n");
debug_printf(" value: %d\n", absinfo.value);
debug_printf(" minimum: %d\n", absinfo.minimum);
debug_printf(" maximum: %d\n", absinfo.maximum);
debug_printf(" fuzz: %d\n", absinfo.fuzz);
debug_printf(" flat: %d\n", absinfo.flat);
debug_printf(" resolution: %d\n",
absinfo.resolution);

struct uinput_abs_setup abs_setup = {
.code = event_code,
.absinfo = absinfo,
};

if (ioctl(fd_clone, UI_ABS_SETUP, &abs_setup) < 0) {
perror("ioctl: UI_ABS_SETUP");
}
}
}
}
}
}
}
6 changes: 3 additions & 3 deletions keyboardd/install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fi
cd "$(dirname "$0")"

# Copy the keyboardd to /usr/bin
echo "Copying trackpointerd to /usr/bin"
echo "Copying moused to /usr/bin"
install -Dm755 ../bin/keyboardd /usr/bin/keyboardd

# Copy the keyboardd.service file to /etc/systemd/system
Expand All @@ -24,8 +24,8 @@ install -Dm644 ./keyboardd.service /etc/systemd/system/keyboardd.service
echo "Reloading systemd"
systemctl daemon-reload

# Start the trackpointerd service
# Enable the trackpointerd service to start on boot
# Start the moused service
# Enable the moused service to start on boot

echo "Starting keyboardd service"
systemctl enable keyboardd
Expand Down
4 changes: 2 additions & 2 deletions keyboardd/install/keyboardd.service
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[Unit]
Description=Daemon for the keyboardd of the MiniBook
ConditionPathExists=/usr/bin/
# /dev/input/by-path/platform-i8042-serio-0-event-kbd
After=dev-input-by\x2dpath-platform\x2di8042\x2dserio\x2d0\x2devent\x2dkbd.device
Requires=sysinit.target
After=sysinit.target basic.target

[Service]

Expand Down
2 changes: 1 addition & 1 deletion keyboardd/install/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ echo "Stopping keyboardd service"
systemctl stop keyboardd
systemctl disable keyboardd

# Remove the trackpointerd script from /usr/bin
# Remove the moused script from /usr/bin
echo "Removing keyboardd from /usr/bin"
rm /usr/bin/keyboardd

Expand Down
Loading

0 comments on commit f3e068e

Please sign in to comment.