Hi everyone! I wanted to turn one of my apps into a watchface but this requires touch to be enabled on watchfaces. By default, the PebbleOS AppLib restricts watchfaces from subscribing to the touch service to preserve battery life, and the kernel aggressively drops touch events that don’t trigger native UI scrolling. If you’re building a watchface for the Pebble Time 2 and want to utilize the touchscreen, you’ll need to bypass these restrictions.
I was able to patch the OS and my watchface works with touchscreen now! But I thought I could share here what I did so others can try developing watchfaces with touch capability. Below is a complete guide on how to fork the OS, apply the necessary kernel patches, compile the firmware in our Nix environment, and safely sideload it to your watch via Recovery Mode.
I forked PebbleOS on my own github and also provided the flashable OS I built there too. But if you want to do it yourself you can follow these instructions. Not that I’m developing in Linux, I’m not sure if these instructions will apply 1:1 with Mac/Windows so if you use these, YMMV.
TL;DR, if you don’t want to patch PebbloOS yourself, you can download the build from my github repo and flash it.
DISCLAIMER: Please be aware that the changes to this code may break your system! This new touch interface modification has not been thoroughly tested for watchfaces or OS stability. Because we are intentionally bypassing the idle wake-gate, the touch digitizer will remain fully powered while your watchface is active. Potential issues that may arise include:
-
Severe Battery Drain: The watch will not be able to enter its deepest sleep states.
-
Kernel Panics: Unexpected touch inputs during system modal transitions (like incoming calls or alarms) could cause memory faults.
-
AppLib Routing Conflicts: Other background workers or system services may intercept your touch payloads unexpectedly. Please proceed with caution and flash at your own risk!
Step 1: Fork and Clone the Repository
Since PebbleOS is fully open-source (Apache 2 / GPL3), the best way to develop is by creating your own fork. This allows you to safely modify, compile, and distribute your custom firmware.
-
Navigate to the official repository at
https://github.com/coredevices/PebbleOSand click the Fork button. -
Open your terminal, clone your new fork, and initialize the nested third-party dependencies (like CMSIS and Moddable):
git clone https://github.com/YOUR_USERNAME/PebbleOS.git
cd PebbleOS
git submodule update --init --recursive
git checkout -b feature/touchscreen-watchfaces
Step 2: Keep Your Fork Updated (Upstream Synchronization)
Before making your own modifications, ensure you are tracking the original Core Devices repository so you can easily pull in the latest OS changes in the future.
- Add the official repository as a remote named
upstream:
Bash
git remote add upstream https://github.com/coredevices/PebbleOS.git
- When you want to pull the latest changes, fetch and merge them into your local
mainbranch:
Bash
git checkout main
git fetch upstream
git merge upstream/main
- Critical: Always update your submodules after syncing, as third-party dependencies like Moddable or CMSIS often update:
Bash
git submodule update --init --recursive
Step 3: Create a Feature Branch
Isolate your modifications in a dedicated branch rather than committing directly to main.
Bash
git checkout -b feature/touchscreen-watchfaces
Step 4: Apply the OS Kernel and AppLib C Patches
We need to modify three files in the OS source to route raw touch coordinate data to your watchface.
Below are the unabridged patches in our virtual Canvas workspace. Open these files in your preferred text editor and replace the target functions with the code below.
Canvas Workspace: src/fw/applib/touch_service.c
Purpose: Removes the application-level restriction preventing watchfaces from requesting touch data.
static TouchServiceState *prv_get_state(void) {
PebbleTask task = pebble_task_get_current();
switch (task) {
case PebbleTask_App:
// Touch is reserved for watchapps; watchfaces must not consume it.
// --- PATCH BEGIN ---
// if (sys_app_is_watchface()) {
// return NULL;
// }
// --- PATCH END ---
return app_state_get_touch_service_state();
case PebbleTask_KernelMain:
return kernel_applib_get_touch_service_state();
case PebbleTask_Worker:
// Touch is not available to background workers — they have no UI.
return NULL;
default:
WTF;
}
}
Canvas Workspace: src/fw/services/touch/touch_session.c
Purpose: Bypasses strict idle-timeout management, ensuring the touch sensor remains powered while your watchface is actively displayed.
bool touch_session_is_active(void) {
#ifdef CONFIG_RECOVERY_FW
// PRF has no touch navigation; keep the mfg touch test's touch-follows-light
// behavior unconditional.
return true;
#else
// --- PATCH BEGIN ---
// Unconditionally keep the touch session active for custom watchfaces
return true;
// --- PATCH END ---
/* ORIGINAL CODE DISABLED:
if (rtc_get_ticks() < s_armed_until) {
return true;
}
// Any UI the user deliberately entered is not guarded; only the idle
// watchface needs arming.
if (!app_manager_is_watchface_running()) {
return true;
}
// A focused modal just demanded attention (notification, alarm): the
// immediate touch response is intentional.
if (modal_manager_get_enabled() && !(modal_manager_get_properties() & ModalProperty_Unfocused)) {
return true;
}
// A lit backlight means something (button, shake, wake gesture) already
// signalled engagement.
return light_is_on();
*/
#endif
}
Canvas Workspace: src/fw/services/touch/touch.c
Purpose: Protects the non_navigational flag so the kernel does not discard raw coordinate data before it reaches the watchface layer.
void touch_wake_gate_stamp(TouchEvent *event, TouchWakeGateResult gate) {
if (event->type == TouchEvent_Touchdown) {
s_wake_gate_latch = gate.latch;
}
// --- PATCH BEGIN ---
// Force non_navigational to true if we have raw subscriber tasks listening
if (s_raw_subscriber_tasks != 0) {
event->non_navigational = true;
} else {
event->non_navigational = s_wake_gate_latch;
}
// --- PATCH END ---
}
Once applied, commit and push your changes to your fork:
git add src/fw/applib/touch_service.c src/fw/services/touch/touch_session.c src/fw/services/touch/touch.c
git commit -m "Enable raw touchscreen events for custom watchfaces"
git push origin feature/touchscreen-watchfaces
Step 5: Configure the Local Build Environment
Before entering the Nix build environment, Linux users need to strip an outdated -latomic flag from the Moddable JS engine makefiles. This prevents a Clang wrapper linker panic.
Note: Do not commit these changes to GitHub, as removing this flag breaks compilation for older 32-bit architectures.
find third_party/moddable/moddable/xs/makefiles/lin/ -name "*.mk" -exec sed -i 's/-latomic//g' {} +
find third_party/moddable/moddable/build/makefiles/lin/ -name "*.mk" -exec sed -i 's/-latomic//g' {} +
Step 6: Compile the Firmware
We use a Nix Flake development shell to ensure our toolchains are perfectly consistent. Enter the shell, configure your environment variables to prevent Waf threading hangs, and build for the obelix@pvt target.
# 1. Enter the Nix sandbox
nix --extra-experimental-features "nix-command flakes" develop --impure
# 2. Set build variables for Waf and Python parsing
export WAF_NO_PREFORK=1
export LC_ALL=C
export LANG=en_US.UTF-8
# 3. Clean, configure, and compile the firmware
pbl clean
pbl configure --board=obelix@pvt
pbl build
pbl bundle
Your compiled firmware will be generated at build/normal_obelix_pvt-*.pbz.
Step 7: Sideloading the OS via Recovery Mode
The safest method is sideloading directly from your smartphone to the watch in Recovery Mode.
-
Enter Recovery Mode: Press and hold the Back, Up, and Select buttons simultaneously on your Pebble Time 2 until the screen turns off and the Pebble logo appears. The watch will boot into PRF (Pebble Recovery Firmware), creating a safe fallback sandbox to receive the new OS.
-
Transfer the Firmware: Send the
build/normal_obelix_pvt-*.pbzfile from your PC to your smartphone (via email, Google Drive, or a direct cable transfer). -
Sideload: Open your phone’s file manager, tap the
normal_obelix_pvt-*.pbzfile, and select Open with Pebble (or share it directly to the Pebble app). -
Install: The Pebble app will recognize the payload as a firmware update. Approve the prompt.
Once the Bluetooth transfer finishes, the watch will reboot into your newly patched firmware.
Step 8: Implementing Touch in Your Watchface (SDK Usage)
Now that your hardware routing is unlocked, implementing it in your C app is straightforward. Here is how you interact with the API:
-
Subscribe: Use
touch_service_subscribeto register your callback handler, which will keep the touch sensor enabled while your watchface is subscribed. -
Handle Data: The callback you register will receive a
TouchEventstruct containing thexandycoordinates of the user’s finger. -
Detect Interaction Type: You can evaluate the
TouchEventTypewithin that struct to trigger different logic forTouchEvent_Touchdown,TouchEvent_Liftoff, andTouchEvent_PositionUpdateevents. -
Graceful Degradation: To ensure your UI still looks great on older non-touch Pebble models, you should poll
touch_service_is_enabled()before trying to initialize any touch-specific elements. -
Cleanup: When your watchface exits, always call
touch_service_unsubscribeto disable the touch sensor and conserve battery (provided no other subscribers remain active)
Now it’s time to create a touch-enabled watchface and see your PT2 operate in all its unfettered glory!