Strange behaviour of Target Display Mode with iMac, Mac mini and Thunderbolt display I bought a 27" iMac and hooked it up to my Thunderbolt display. The iMac is also thunderbolted to my Mac mini.

When I press meta-(fn-)F2, the following happens:


The iMac screen goes dark.
The Thunderbolt display shows the Mac mini's (locked) screen.
I can move the mouse on the Thunderbolt display but not click at anything.
The keyboard doesn't work (except meta-F2).


When I press meta-F2 again, this happens:


Both screens go back to being screens of the iMac.
The screens switch places and the Thunderbolt display becomes the primary display with the Dock.


I am at a loss as to how I am supposed to use this feature.

Are mouse and keyboard supposed to travel with the screen?

Why does the Mac mini screen appear on the secondary display?

Why do the screens switch places when I switch back from TDM?

Update: The iMac is a late 2013 iMac running 10.9 (no updates). The Mac mini was new a few months ago and came with (and still runs) 10.8(.6 I think).
This Apple KB article will help answer some of your questions:

Target Display Mode: Frequently Asked Questions (FAQ)

From what you're describing, I think what is happening is that the Thunderbolt Display is acting like a regular display for the iMac, while the iMac is acting as a TDM for mini. Thus, the signal for the mini ends up on the Thunderbolt Display (since it's considered "part of" the iMac).

At first glance, I'd say that TDM isn't intended for multiple screens, though I'm not sure...

To specifically answer 1. and 2. (from list item 14 in the link above): 


  [...]Other keyboard and mouse input is disabled on the iMac while it is in TDM[...]


This means that the keyboard and mouse need to be connected to the mini in order to work beyond presssing Cmd+F2 to exit TDM.

In regards to what happens when you exit TDM, that's probably just a side effect of the Thunderbolt Display being the last active display (Remember, 10.9 moves the dock to the display on which you're interacting. Makes the menu bar opaque, too).