Journey of a Touch
What happens when you touch the screen of your mobile device? Quite a lot. A touch triggers a chain of hardware and software events that wreaks havoc within your device. And this happens every time you do it.
To begin with, the touch of your finger leads to a disruption in the screen’s electrostatic field. This disruption is detected by the screen’s controller, a bit of hardware that acts like a spider, waiting for the subtle signals that indicate your presence within its domain. The controller then sends an electrical signal called an interrupt to the processor.
Upon receiving this interrupt, the processor stops what it was doing and saves the current state of the program it was running to an area of memory called the stack. It then proceeds to run an interrupt handler, which is a piece of software associated with the specific device that caused the interrupt. The handler then gathers information about the touch from the controller, and produces a data record containing the time and location of the touch, along with any other relevant information provided by the device (such as pressure).
This data record then gets passed to the device’s operating system, which works out which application should respond to the touch. This involves looking up which application is responsible for the part of screen real estate where the touch landed. It then asks another part of the operating system, the scheduler, to activate the relevant program and ask it to deal with the user’s interaction. The interrupt handler then finishes running and the processor retrieves its previous state from the stack and continues what it was doing before the user rudely interrupted.
At this point, you might expect the program to deal with the user’s interaction straightaway, but things are not quite this simple. Most devices run a large number of programs at once, including both the program you prodded, programs associated with the device’s hardware and operating system, and numerous programs that are running in the background — for example, the one that checks for incoming text messages. However, the number of programs a device can actually run at once is limited by how many processors it has, and in practice it has to use time-sharing. This involves the processors continually switching between different programs, allowing each to run for a few milliseconds before another one takes its place. This all happens under the watchful eye of the operating system’s scheduler.
Now, at this point, the scheduler knows that you’re waiting for a response, and so it assigns the handling of this response a high priority. This means that even if the program is not currently running, it soon will, and other programs will be forced to sit around and wait for the user’s interaction to be dealt with. And so, the relevant program gets allocated a processor, and it then immediately switches to a part of the program known as an event handler — a bit of code that the programmer wrote to deal with a particular kind of user interaction. There are usually lots of these in a program, and the one that gets called will depend exactly where and how you touched the screen. The event handler then does whatever’s required to handle your touch and, once this is done, things can get back to normal within your device.
So, that’s what happens every time you touch your screen. Now you know, perhaps you’ll be more considerate in the future.