- The Linux kernel usb system detects a new device
- From the device properties it is determined as an HID device, and therefore a new input device is created by the evdev module (which is loaded if it was not before)
- Event info about a new device is sent to udev
- Udev parses its rules and creates a new file in /dev for this new device
- Udev transmits the info of a new device to listeners such as DeviceKit and Hal
- Hal parses its rules, one of which is the distro script which set the default layout to the device
- Hal transmits the info of a new device to its listeners, such as Xorg
- Xorg add the new device to the children of the Xkb core keyboard
- Hal transmits the options for this new device to Xorg via Xkb
- Xorg, via the Xkb extension, transmits the info that the Xkb config has be modified to listeners such as xklavier
- xklavier transmits the info of a change in config to its listeners, such as libgnomekdb
- libgnomekdb reloads the configuration of the keyboard and update the status icon in the system tray
- Xorg, via the XINPUT extension, transmits the info that a new device is present to the listeners, like xklavier
- xklavier transmits the info of a new device to its listeners, such as gnome-settings-daemon (g-s-d)
- g-s-d changes this new device's layout to the user preferences via libgnomekdb.
Note that it depends a bit on your system, and in particular in very modern Xorg's (xserver >= 1.8) the Hal part is removed and udev and Xorg communicate together directly. It might also contain some mistakes, don't hesitate to mention it in the comments.